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: freshJudgeState starts it undefined and pendingFor makes it on first use (packages/pi-modes/judge-wiring.ts:423, :532). Nothing writes it to the session.

  • Every entry is an action: approve grants a one-time pass, humanSaid appends each typed line to every entry, actions() counts all but the two guard entries toward PENDING_CAPACITY (6).

  • /pending (judge-wiring.ts:656, pendingCommand) knows approve, always, deny, clear. What the human did reaches the model through pi.sendUserMessage, steered when a run is in flight (:870, :937).

  • The blocking ask puts a pick-or-own-words dialog to the desk and every paired phone at once (askHuman, packages/pi-modes/command-wiring.ts:151, over askAny).

  • 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 clear as prompts.

  • Monitor records show the durable pattern: pi.appendEntry custom entries, replayed from ctx.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:

  • PendingKind gains "question"; PendingEntry gains question?: QuestionBody. QUESTION_CAPACITY = 8.

  • enqueueQuestion(body, restored?: { id?: number; createdAt: number }): PendingEntry. The key is "\u0000question\n" + body.question. shown is question: ` and the question cut at `SHOWN_CHARS; reason is questionWhy(body); full is questionFull(body). With restored the entry takes the recorded time; with restored.id it takes that id, and nextId becomes at least id + 1; without one it takes the next fresh id. Which ids are kept is the restore’s decision (Design 2). nextFreeId(): number returns nextId. It throws PendingFullError when QUESTION_CAPACITY questions wait.

  • findQuestion(question: string), roomForQuestion(), dropQuestions(): PendingEntry[] (removes every question; one onChange when any went).

  • actions() leaves questions out, so a question takes none of the six step places.

  • humanSaid appends 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 returns undefined, removes nothing and keeps no pass.

  • clear() removes and returns the entries that are not questions; questions stay.

  • withdraw is unchanged: a question is the agent’s own entry.

  • snapshot() adds question: true to a question’s step. PendingStepView (pending-event.ts) gains question?: 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 | undefined parses, never trusts: an asked body goes through checkQuestion, and anything malformed is undefined.

  • branchQuestionRecords(entries: readonly unknown[]): QuestionRecord[] takes the custom entries of that type, in order.

  • openQuestions(records): replayed in order, asked opens an id (a later asked of the same id replaces it, since ids restart with the process) and closed removes it. Returns the open asked records, 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:

  1. ctx.hasUI !== true: return NO_HUMAN_QUESTION as text, nothing queued (as ask does, command-wiring.ts:93).

  2. checkQuestion refused: throw Error("not queued: " + refused).

  3. findQuestion(body.question) finds one: throw not queued: this question already waits as #N.

  4. roomForQuestion() is false: throw questionFullText().

  5. enqueueQuestion(body), append({ kind: "asked", id, at: now(), body }), return queuedQuestionText(entry, others) with details: { 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-empty typed, 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") and interpretAnswer: anything but answered notifies Question #N left open. and ends. Then, if the entry no longer waits (withdrawn or answered elsewhere while the dialog was open), notify Question #N is no longer open; your answer was not sent. and end. Otherwise tell(answeredText(entry, outcome), ctx.isIdle() ? {} : { deliverAs: "steer" }), settle(id), append({ kind: "closed", id, how: "answered" }), notify Answered #N..

  • dismissQuestion(deps, tell, ctx, entry): tell(dismissedText(entry), …), settle, append(… how: "dismissed"), notify Dismissed 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…]: N must name a question, else #N is a step, not a question: approve or deny it.; then answerQuestion with the words joined by single spaces, or the dialog when there are none.

  • approve N on a question: answerQuestion with the dialog. deny N on a question: dismissQuestion. Both are decided before actOnStep. 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 N on a question: standingRefusal (standing-approval.ts:46) returns a question is answered, not approved for kind === "question", checked first.

  • clear: clearQueue notifies Cleared N waiting step(s); M question(s) still wait. (the second half only when M > 0), and tells the model of the steps only, as today.

  • chooseAction (a host’s second select) offers answer, dismiss, leave it for a question.

  • actOnNewest (:850), the two keys, acts on the newest entry that is not a question.

  • PENDING_USAGE, the command’s description and pendingCompletions (pending-pane.ts:77: answer ` in `COMPLETION_VERBS and STEP_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. or Meanwhile: the item is parked until you answer.

  • queuedQuestionText(entry, others): Queued as question #N for the human, who answers whenever: «Q». then Meanwhile, proceed on your recommendation «R». or Meanwhile this item is parked: do not do it, and work on something else. then Their 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, for proceed: ` 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, for proceed: ` 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

packages/pi-modes/pending-question.ts

new: Design 1 (type, check) and Design 6

packages/pi-modes/question-records.ts

new: Design 2

packages/pi-modes/question-wiring.ts

new: Designs 2 to 4 (restore, the tool, answer, dismiss)

packages/pi-modes/ask-dialog.ts, packages/pi-modes/command-wiring.ts

askHuman moved and exported (Design 4)

packages/pi-modes/pending-queue.ts, packages/pi-modes/pending-event.ts

Design 1

packages/pi-modes/session-wiring.ts

waitingSteps (Design 1)

packages/pi-modes/judge-wiring.ts

Designs 2, 4, 5: onSessionStart, JudgeDeps.appendQuestion, executeWithdraw, pendingCommand, chooseAction, clearQueue, actOnNewest, the usage text

packages/pi-modes/standing-approval.ts, packages/pi-modes/pending-pane.ts

Design 5

packages/pi-modes/modes.json

Design 3

packages/pi-modes/test/pending-question.test.ts, question-records.test.ts, question-wiring.test.ts

new: T1 to T12

packages/pi-modes/test/pending-queue.test.ts, pending-pane.test.ts, pending-wiring.test.ts, pending-withdraw.test.ts, session-wiring.test.ts, config.test.ts, wiring-lifecycle.test.ts

T5, T13 to T18

packages/pi-remote/test/units.test.ts

T5 (a test only; no source change in pi-remote)

docs/modules/ROOT/pages/judge.adoc

the canonical page: a subsection "Questions that do not block" under "Waiting on you: the pending queue"

docs/modules/ROOT/pages/plan-mode.adoc, remote.adoc, public-surface.adoc

ask or queue_question, in one paragraph; how a question shows on the phone and what its two buttons do; the tool’s row, and gadhs-question-record and gadhs-question-renumbered among the session’s entry and message types

docs/modules/ROOT/pages/plans/queue-question.adoc, docs/modules/ROOT/nav.adoc

this plan, last under Active

CHANGELOG.adoc

== Unreleased, one entry

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

  1. Branch feat/queue-question from main; commit this plan and its nav line, Status In progress.

  2. Design 1, 2 and 6 with T1 to T5, T13, T14 (pure files and the queue).

  3. Design 3 and 4 with T6 to T12, T16 to T18; then Design 5 with T15.

  4. The docs and the CHANGELOG entry; Status Done (date) — ….

  5. node tools/task.mjs check, the whole packages/pi-modes suite with coverage (bars 97 / 90), push, MR, merge train.

Tests

Test Asserts

T1 unit pending-question.test.ts

checkQuestion: each refusal of Design 1 by its field; a valid body comes back trimmed, its question on one line

T2 property (fast-check)

checkQuestion and questionRecordOf over arbitrary values do not throw; questionRecordOf(r) equals r for every record built from a checked body (roundtrip)

T3 unit

each text of Design 6, whole strings: proceed and park, picked and own words, answer equal to R and not

T4 unit question-records.test.ts

openQuestions: asked then closed is not open; a later asked of a closed id is open with the later body; entries of another type and malformed data are skipped; order is oldest first

T5 contract (wire)

in pending-queue.test.ts: a question’s snapshot() step has the keys id, shown, why, full, question and no other. In packages/pi-remote/test/units.test.ts, beside the existing "a pending queue as the wire’s steps" case: pendingStepsOf on a step carrying question: true gives exactly { id, shown, why, full, approved: false }

T6 unit question-wiring.test.ts

the tool: no UI returns NO_HUMAN_QUESTION and queues nothing; a refused check, a duplicate and a ninth question each throw with nothing queued and nothing appended; a queued one appends asked and returns queuedQuestionText naming the others

T7 unit

answer #N words: the model is told answeredText once, the entry is gone, closed/answered is appended; an answer equal to an option in another case is a picked option

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 {}, a run in flight with { deliverAs: "steer" }; the tell happens before the closed record (call order)

T11 unit

dismissQuestion: dismissedText for proceed and for park (the parked text holds "stays parked"), closed/dismissed appended

T12 unit

restoreQuestions: from a branch with two open and one closed, the queue holds the two with their ids and times, and the next step queued takes a higher id; called twice it holds two, not four; a branch with none makes no queue, and with no number taken nothing is noted. Into a queue that already holds a step #2, a recorded question #2 takes a fresh id above every kept one: /pending approve #2 still names the step alone, closed/renumbered then asked are appended, a replay of the branch after that holds each question once, and renumberedText is noted once

T13 unit pending-queue.test.ts

six steps and eight questions wait together and a seventh step is refused; humanSaid leaves a question’s replies empty and counts only steps; approve on a question returns undefined and takeApproved finds no pass; clear returns the steps and leaves the questions; the three widget lines

T14 regression

with no question queued, snapshot(), widgetLines and listLines are byte-for-byte what they were (the existing assertions, unedited)

T15 unit pending-pane.test.ts, pending-wiring.test.ts

a question’s row draws [answer] [dismiss] and a click on each hits it at its own width; a on a question closes with { verb: "approve", id } and d acts in place; approve #N on a question opens the dialog and grants no pass; always #N is refused with the reason; clear with one step and one question tells the model of one step and notifies that one question waits; the keys' actOnNewest skips a newest question; a host’s select for a question offers answer, dismiss, leave it

T16 unit pending-withdraw.test.ts

withdrawing a question traces target: "question" and appends closed/withdrawn

T17 unit session-wiring.test.ts

waitingSteps counts one for a step beside a question, and none for questions alone

T18 unit config.test.ts, wiring-lifecycle.test.ts

queue_question is allowed by rule in auto, plan and manual, and is among plan’s tools

Windows: pi-win runs the suite after the merge; nothing here is platform-specific.

Risks

Risk Kind Mitigation

The agent says proceed for something that cannot be undone

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

dismissedText for park says it stays parked (T11)

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 closed

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)

/pending clear, or the phone’s clear, drops a written question

silent

clear leaves questions and says how many wait (T13, T15)

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 /pending approve #N acts on the step

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).

Edit this page · latest