Plan: a question that does not block, queued in /pending and answered whenever
Closes: #929. Relates to: #249 (the queue), #259 (/pending), #471 (pending_withdraw), #140 (the ask broker), #544 (the pending screen). Branch: feat/queue-question. Status: Done (2026-11-29) — implemented in @gadhs/pi-modes
Context
Told to keep going, an agent avoids the blocking ask because it stops the work. Its questions then pile up in the conversation and reach the human many at a time, if at all (#929). The operator’s rulings (2026-11-29): the question lives in the session file, as monitor records do; it carries no issue reference and nothing is posted to GitLab.
What the code does today:
-
PendingQueue(packages/pi-modes/pending-queue.ts) holds the steps that wait on the human. It is process memory:freshJudgeStatestarts itundefinedandpendingFormakes it on first use (packages/pi-modes/judge-wiring.ts:423,:532). Nothing writes it to the session. -
Every entry is an action:
approvegrants a one-time pass,humanSaidappends each typed line to every entry,actions()counts all but the two guard entries towardPENDING_CAPACITY(6). -
/pending(judge-wiring.ts:656,pendingCommand) knowsapprove,always,deny,clear. What the human did reaches the model throughpi.sendUserMessage, steered when a run is in flight (:870,:937). -
The blocking
askputs a pick-or-own-words dialog to the desk and every paired phone at once (askHuman,packages/pi-modes/command-wiring.ts:151, overaskAny). -
The phone is sent each step as
{ id, shown, why?, full? }:pendingStepsOf(packages/pi-remote/mirror.ts:295) rebuilds a step from those four fields and drops any other. Its buttons send/pending approve #<id>,/pending deny #<id>and/pending clearas prompts. -
Monitor records show the durable pattern:
pi.appendEntrycustom entries, replayed fromctx.sessionManager.getBranch()at session start (packages/pi-modes/monitor-records.ts).
Design
1. A question is an entry of the queue
New pure file packages/pi-modes/pending-question.ts holds the type, the check and every text of Design 6.
export interface QuestionBody {
question: string; // one line
context: string; // what the human needs to decide
options: string[]; // none, or two to four
recommendation?: string; // one of `options` when there are options
meanwhile: "proceed" | "park";
}
checkQuestion(params): QuestionBody | { refused: string } trims every field and folds line breaks in question to spaces. It refuses: an empty question or one over 300 characters; an empty context or one over 4,000; options that, trimmed, de-duplicated and without OWN_WORDS, number one or more than four; a recommendation that is not one of the options when options are given; meanwhile: "proceed" with no recommendation. Each refusal names the field and the fix.
pending-queue.ts:
-
PendingKindgains"question";PendingEntrygainsquestion?: QuestionBody.QUESTION_CAPACITY = 8. -
enqueueQuestion(body, restored?: { id?: number; createdAt: number }): PendingEntry. The key is"\u0000question\n" + body.question.shownisquestion: ` and the question cut at `SHOWN_CHARS;reasonisquestionWhy(body);fullisquestionFull(body). Withrestoredthe entry takes the recorded time; withrestored.idit takes that id, andnextIdbecomes at leastid + 1; without one it takes the next fresh id. Which ids are kept is the restore’s decision (Design 2).nextFreeId(): numberreturnsnextId. It throwsPendingFullErrorwhenQUESTION_CAPACITYquestions wait. -
findQuestion(question: string),roomForQuestion(),dropQuestions(): PendingEntry[](removes every question; oneonChangewhen any went). -
actions()leaves questions out, so a question takes none of the six step places. -
humanSaidappends to entries that are not questions and returns how many it reached: a question open for days would otherwise collect every line the human types. -
approve(id)on a question returnsundefined, removes nothing and keeps no pass. -
clear()removes and returns the entries that are not questions; questions stay. -
withdrawis unchanged: a question is the agent’s own entry. -
snapshot()addsquestion: trueto a question’s step.PendingStepView(pending-event.ts) gainsquestion?: true. -
widgetLines: with steps only, the line as today; with questions only,N question(s) for you · …; with both,N pending and M question(s) for you · ….
waitingSteps (packages/pi-modes/session-wiring.ts:273) counts the steps whose question is not true, so an open question does not hold the tab’s attention as a blocked step does. The status line’s count (stats.waiting, the queue’s size) includes questions.
2. The record that survives
New pure file packages/pi-modes/question-records.ts, after monitor-records.ts:
export const QUESTION_RECORD_TYPE = "gadhs-question-record";
export type QuestionRecord =
| { kind: "asked"; id: number; at: number; body: QuestionBody }
| { kind: "closed"; id: number; how: "answered" | "dismissed" | "withdrawn" | "renumbered" };
-
questionRecordOf(data: unknown): QuestionRecord | undefinedparses, never trusts: anaskedbody goes throughcheckQuestion, and anything malformed isundefined. -
branchQuestionRecords(entries: readonly unknown[]): QuestionRecord[]takes thecustomentries of that type, in order. -
openQuestions(records): replayed in order,askedopens an id (a lateraskedof the same id replaces it, since ids restart with the process) andclosedremoves it. Returns the openaskedrecords, oldest first.
restoreQuestions(deps, branch) in question-wiring.ts (Design 3): when the queue exists, dropQuestions(); then enqueueQuestion(body, { id, createdAt: at }) for the open records, making the queue only when there is one to restore. registerJudge’s `onSessionStart(ctx) (judge-wiring.ts:1729) calls it with ctx.sessionManager.getBranch().
A reload and a restart start with no queue, so every question keeps its number. A session switched in the same process keeps the queue (onSessionStart does not clear state.pending), and its steps keep their numbers; a restored question whose number is taken there would make /pending approve #N name two entries. So the restore reads floor = nextFreeId() once (1 when it has just made the queue) and runs in two passes: first the open records whose id is floor or higher, oldest first, each passed with its id; then the rest, oldest first, passed without one, so they take fresh ids above every kept one. An id below floor is a number this process has already given out, which a step still waiting may hold. For each renumbered question it appends { kind: "closed", id: from, how: "renumbered" } and then { kind: "asked", id: to, at, body }, and restoreQuestions returns the { from, to } pairs. When there are any, the agent is told once, as tellLost tells of lost monitors: deps.note(renumberedText(pairs)), which is pi.sendMessage({ customType: "gadhs-question-renumbered", content, display: true }, { triggerTurn: false }). Otherwise nothing is told at restore: the widget shows the human what waits, and the answer message is self-contained (Design 6).
3. The tool
New file packages/pi-modes/question-wiring.ts. It imports types only from judge-wiring.ts (TellModel, PendingCommandCtx), so there is no import cycle; judge-wiring.ts imports its functions.
export interface QuestionDeps {
queue(): PendingQueue; // pendingFor(deps)
existing(): PendingQueue | undefined; // deps.state.pending
append(record: QuestionRecord): void; // pi.appendEntry(QUESTION_RECORD_TYPE, record)
note(content: string): void; // pi.sendMessage(…, { triggerTurn: false }), Design 2
modeId(): string;
now(): number;
}
registerQuestionTool(pi, deps) is called in registerJudge beside registerWithdrawTool (judge-wiring.ts:1721). The tool is queue_question, label Queue question. Parameters: question (string), context (string), options (optional array of strings), recommendation (optional string), meanwhile (Type.Union([Type.Literal("proceed"), Type.Literal("park")]), as memory-wiring.ts:808 writes an enum). Description: "Put a question to the human without stopping: it waits in their /pending queue with its context, options and your recommendation, and their answer arrives later as a message. Say what you do meanwhile: proceed on your recommendation when that can be undone, park the item when it cannot." promptSnippet: "Queue a question for the human and keep working; the answer arrives later". promptGuidelines:
-
"When a decision is the human’s and the work can go on meanwhile, queue it with queue_question rather than ending a turn with a list of open questions; use ask only when nothing useful can happen until the answer."
-
"meanwhile is a promise: proceed only when what you do on your recommendation can be undone; park what cannot."
-
"Do not repeat a queued question in your messages; withdraw it with pending_withdraw when it becomes moot."
executeQueueQuestion(deps, params, ctx), in this order:
-
ctx.hasUI !== true: returnNO_HUMAN_QUESTIONas text, nothing queued (asaskdoes,command-wiring.ts:93). -
checkQuestionrefused: throwError("not queued: " + refused). -
findQuestion(body.question)finds one: thrownot queued: this question already waits as #N. -
roomForQuestion()is false: throwquestionFullText(). -
enqueueQuestion(body),append({ kind: "asked", id, at: now(), body }), returnqueuedQuestionText(entry, others)withdetails: { id }.
packages/pi-modes/modes.json: "queue_question" after "pending_withdraw" in allowedByRule (:122) and in plan’s tools (:545). The shipped agent files (packages/pi-agents/agents/*.md) each list their tools by name and none lists this one; a session with no UI that does have it is refused at step 1 (T6).
4. Answering, dismissing, withdrawing
askHuman and its Reply type move from command-wiring.ts to a new file packages/pi-modes/ask-dialog.ts, exported, with a last parameter origin: AskOrigin = "ask"; command-wiring.ts imports it. Behaviour of ask is unchanged.
In question-wiring.ts:
-
answerQuestion(deps, tell, ctx, entry, typed?: string). With non-emptytyped, that is the answer; it is a picked option when it equals one ignoring case, else the human’s own words. Without it,askHuman({ question: drawnWhole(entry.full ?? entry.shown), options: body.options }, ctx.ui, undefined, deps.modeId(), undefined, "pending")andinterpretAnswer: anything butanswerednotifiesQuestion #N left open.and ends. Then, if the entry no longer waits (withdrawn or answered elsewhere while the dialog was open), notifyQuestion #N is no longer open; your answer was not sent.and end. Otherwisetell(answeredText(entry, outcome), ctx.isIdle() ? {} : { deliverAs: "steer" }),settle(id),append({ kind: "closed", id, how: "answered" }), notifyAnswered #N.. -
dismissQuestion(deps, tell, ctx, entry):tell(dismissedText(entry), …),settle,append(… how: "dismissed"), notifyDismissed question #N.. -
Tell before record, in both: a process that dies between the two leaves the question open, and it shows again after the restart.
PendingCommandCtx.ui (judge-wiring.ts:614) gains input(title, placeholder, opts?), which pi’s command context has.
executeWithdraw (judge-wiring.ts:1643): for a question the trace’s target is "question", the text is Withdrew question #N («…»); it no longer waits on the human., and { kind: "closed", id, how: "withdrawn" } is appended. JudgeDeps gains appendQuestion: (record: QuestionRecord) ⇒ void, set in judgeDeps (:1610) to pi.appendEntry(QUESTION_RECORD_TYPE, record); it is what QuestionDeps.append calls. The tool’s description and its id parameter say "step or question".
5. /pending, the screen, a host, the phone
pendingCommand (judge-wiring.ts:656):
-
answer N [words…]:Nmust name a question, else#N is a step, not a question: approve or deny it.; thenanswerQuestionwith the words joined by single spaces, or the dialog when there are none. -
approve Non a question:answerQuestionwith the dialog.deny Non a question:dismissQuestion. Both are decided beforeactOnStep. This is what an unchanged phone’s two buttons do: approve opens the answer sheet on the desk and on the phone through the broker, deny dismisses. -
always Non a question:standingRefusal(standing-approval.ts:46) returnsa question is answered, not approvedforkind === "question", checked first. -
clear:clearQueuenotifiesCleared N waiting step(s); M question(s) still wait.(the second half only whenM > 0), and tells the model of the steps only, as today. -
chooseAction(a host’s second select) offersanswer,dismiss,leave itfor a question. -
actOnNewest(:850), the two keys, acts on the newest entry that is not a question. -
PENDING_USAGE, the command’s description andpendingCompletions(pending-pane.ts:77:answer ` in `COMPLETION_VERBSandSTEP_VERBS) name the new verb.
pending-pane.ts: rowButtons(entry) gives [approve] [deny], or [answer] [dismiss] for a question; hitPendingPane takes the entries instead of their count and measures each row’s own labels; the legend for a selected question reads a answer · d dismiss; act("approve") on a question closes the pane with the pick (as always does), because the dialog needs the screen; d on a question runs in place. The hub’s Waiting tab is built by the same buildPendingPane (packages/pi-modes/hub-pane.ts:383) and changes with it.
No change in packages/pi-remote and none on the wire: the phone shows a question as a step whose shown, why and full say what it is.
6. What is said
All in pending-question.ts; Q is the question, R the recommendation.
-
questionWhy(body):recommends «R»; proceeding on it meanwhile|recommends «R»; parked until you answer|parked until you answer. -
questionFull(body): the question; a blank line; the context; with options,Options:and one numbered line each,(recommended)after R; without options and with R,Recommendation: R; last,Meanwhile: the agent proceeds on the recommendation.orMeanwhile: the item is parked until you answer. -
queuedQuestionText(entry, others):Queued as question #N for the human, who answers whenever: «Q».thenMeanwhile, proceed on your recommendation «R».orMeanwhile this item is parked: do not do it, and work on something else.thenTheir answer arrives as a message naming #N. Do not repeat the question in your messages. If it becomes moot, withdraw it with pending_withdraw (id N) and say why.and, when others wait,Also open: #A «…», #B «…». -
answeredText(entry, outcome):The human answered question #N («Q»): they chose "X".or… in their own words: X. Then, forproceed: ` That is the recommendation you proceeded on.` when X is R, else ` You were proceeding on «R»: bring the work in line with their answer.; for `park: ` The item was parked: take it up now.` -
dismissedText(entry):The human dismissed question #N («Q») without answering. Do not ask it again.then, forproceed: ` Carry on with «R», and say in your next message that you assumed it.; for `park: ` The item stays parked: do not do it on your own judgement, and say in your next message that it is parked.` -
renumberedText(pairs):The queue’s numbers restarted with this session: question #3 is now #9.(one clause per pair, joined by; `) then ` Use the new number to withdraw it; its answer will name it. -
NO_HUMAN_QUESTION:queue_question needs a human and this session has no interactive UI. Nothing was queued and nobody will answer. Decide using your own judgement and state the assumption you made in your final answer. -
questionFullText():NOT queued: 8 questions already wait on the human. Withdraw one that is moot (pending_withdraw), or say in your message that their /pending queue holds 8 open questions.
Scope
| File | Change |
|---|---|
|
new: Design 1 (type, check) and Design 6 |
|
new: Design 2 |
|
new: Designs 2 to 4 (restore, the tool, answer, dismiss) |
|
|
|
Design 1 |
|
|
|
Designs 2, 4, 5: |
|
Design 5 |
|
Design 3 |
|
new: T1 to T12 |
|
T5, T13 to T18 |
|
T5 (a test only; no source change in |
|
the canonical page: a subsection "Questions that do not block" under "Waiting on you: the pending queue" |
|
|
|
this plan, last under Active |
|
|
Not in scope: a question card with option buttons on the phone (it needs @gadhs/pivot-wire; a follow-up issue); issue references and GitLab notes (operator ruling); any timer, reminder or automatic answer; a question from a helper; carrying open questions into a new session; any change to ask.
Order of work
-
Branch
feat/queue-questionfrommain; commit this plan and its nav line, StatusIn progress. -
Design 1, 2 and 6 with T1 to T5, T13, T14 (pure files and the queue).
-
Design 3 and 4 with T6 to T12, T16 to T18; then Design 5 with T15.
-
The docs and the CHANGELOG entry; Status
Done (date) — …. -
node tools/task.mjs check, the wholepackages/pi-modessuite with coverage (bars 97 / 90), push, MR, merge train.
Tests
| Test | Asserts |
|---|---|
T1 unit |
|
T2 property (fast-check) |
|
T3 unit |
each text of Design 6, whole strings: |
T4 unit |
|
T5 contract (wire) |
in |
T6 unit |
the tool: no UI returns |
T7 unit |
|
T8 unit |
the dialog path: a picked option, own words, and a dismissed dialog (nothing told, nothing appended, the question still waits) |
T9 concurrency |
the question is withdrawn while its dialog is open: on the dialog’s answer nothing is told and nothing appended, and the human is notified. Two dialogs open on one question: the first answer is told once, the second is notified and tells nothing |
T10 unit |
delivery: idle sends with |
T11 unit |
|
T12 unit |
|
T13 unit |
six steps and eight questions wait together and a seventh step is refused; |
T14 regression |
with no question queued, |
T15 unit |
a question’s row draws |
T16 unit |
withdrawing a question traces |
T17 unit |
|
T18 unit |
|
Windows: pi-win runs the suite after the merge; nothing here is platform-specific.
Risks
| Risk | Kind | Mitigation |
|---|---|---|
The agent says |
silent |
the harness cannot know; the human reads "proceeding on it meanwhile" on the row (T3), and a question authorizes nothing: every action still goes through the gate as before |
A dismissed question about a parked item is read as consent |
fail-open |
|
The human’s answer gives the judge no extra weight, so the answered action may be queued for approval |
fail-closed |
intended: an answer is a message, not a pass (T15: no pass is granted) |
The process dies between telling the model and writing |
fail-closed |
the question shows again after the restart and is answered again (T10 pins the order) |
An answer lands on a question the agent withdrew meanwhile |
silent |
checked after the dialog; the human is told it was not sent (T9) |
An agent floods the human with questions |
fail-closed |
eight at most, each refusal naming the way out (T6, T13) |
|
silent |
|
An approve hotkey answers or a deny hotkey dismisses a question unread |
silent |
the keys skip questions (T15) |
A session file edited by hand, or written by a later version, holds a malformed record |
fail-closed |
parsed, not trusted; a bad record is skipped (T2, T4) |
A session switched in the same process shows the previous session’s questions |
silent |
dropped before the restore (T12) |
A restored question takes a number a waiting step holds, and |
fail-open |
such a question is renumbered above every number in use, recorded, and the agent told once (T12) |
Moving along the session tree without a session start leaves another branch’s question on show |
silent |
accepted, as monitors do; the next start replays the branch |
An unchanged phone shows approve and deny on a question |
silent |
approve opens the answer sheet, deny dismisses; the card’s text says it is a question (T5, T15); the native card is the follow-up |
The desk’s dialog stays open while the phone answers |
fail-closed |
the broker closes the other side when one answers (#689, existing); a cancelled dialog leaves the question open (T8) |
A question does not ring the tab and goes unseen |
silent |
the widget line, the status count and the hub’s tab show it (T13, T17) |
After a compaction the agent no longer remembers the question |
silent |
the answer and the dismissal each carry the question, the recommendation and what was happening meanwhile (T3) |
Delivery
The canonical page is docs/modules/ROOT/pages/judge.adoc (the new subsection); the release note is one entry in CHANGELOG.adoc == Unreleased. The MR carries Closes #929. After the merge: the merge SHA on the issue, a follow-up issue for the phone’s question card naming @gadhs/pivot-wire, and a post on pi-feedback/feedback to pi-win (the Windows run) and pivot (the card).