Plan: /pending - the human views, approves, denies and clears queued steps
Closes: #259. Branch: fix/pending-command. Status: Done (2026-09-29) — shipped with this branch
TL;DR
On 2026-09-29 the operator watched queued steps sit in the TUI and never dissipate. The queue has only three exits today: the model retries the exact action after a reply, the queue passes six entries, or the session ends. When the model rewrites a queued command (as it did with an MR poll) or moves on, nothing settles the entry.
/pending gives the human the fourth exit, and a second way to approve:
/pending list the waiting steps, or pick one and act on it /pending approve N approve step N: its next run is allowed, no judge /pending deny N settle step N as declined /pending clear drop every waiting step
Numbers are the widget’s, 1-based. Each action echoes the step it acted on, so a number that moved is visible at once. The model is told what the human did, in its own words, as a user message from the extension.
A slash command is the human’s own act: the model cannot type one, and a
paired phone’s /pending … prompt runs as the command it is (pi-remote
already does that for every / prompt, remote.adoc § What the phone can
send). Typed replies keep working exactly as today.
Design
The queue (packages/pi-modes/pending-queue.ts)
PendingEntry gains approved?: true. New methods:
-
list(): PendingEntry[]- in widget order. -
at(n: number): PendingEntry | undefined- the widget’s 1-based number. -
approve(id: number): PendingEntry | undefined- marks it approved,onChange(); the entry stays until its action runs. -
deny(id: number): PendingEntry | undefined-settleunder a name that says why; returns what it settled. -
clear(): PendingEntry[]- settles every entry, returns them.
widgetLines() shows an approved entry as
` N. <shown> — approved: the agent runs it next`.
The gate (packages/pi-modes/authorize.ts)
In pendingStage, before the replies check: an entry with approved is
settled and answered { kind: "allow", source: "human" } with no judge
call; denials.record("allow"), so the loop guard’s run ends as it does
for any human approval; the review log gets
gadhs_pending.approved_by_command. Everything ahead of the lookup is
unchanged: a rule deny still wins (stage 3 runs first), and the approval is
for the exact key - git push approved does not allow git push 2>&1.
The command (packages/pi-modes/judge-wiring.ts)
Registered in registerJudge, which holds the state the queue lives in
(deps.state.pending), beside the existing input subscription:
pi.registerCommand("pending", {
description: "The steps waiting on you: /pending [approve N | deny N | clear]",
handler: (args, ctx) => pendingCommand(deps, pi, args, ctx),
});
pendingCommand(deps, pi, args, ctx):
-
No argument: nothing queued →
ctx.ui.notify("Nothing is waiting on you."). Otherwisectx.ui.selectover the widget’s lines plusclear all; a chosen step gets a secondselect:approve/deny/leave it. The two dialogs are the human’s own act, so blocking on them is fine. -
approve N/deny N:Nout of range → notifyno step N; /pending lists them. Otherwise act, and tell the model. -
clear: settle all; notify how many; tell the model if any. -
Anything else: notify the usage line.
Telling the model: pi.sendUserMessage(text, options) - pi’s signature,
as packages/pi-remote/commands.ts calls it - with
options = { deliverAs: "steer" } when !ctx.isIdle() (the turn in
flight reads it after its current tool) and {} when idle (it starts a
turn, so the model acts).
The texts, in pending-queue.ts beside the deny texts:
-
approve:
The human approved this step with /pending: «shown». Run exactly that action again; it is allowed once. -
deny:
The human declined this step with /pending: «shown». Do not run it; find another way, or stop and say so. -
clear:
The human cleared N waiting steps with /pending, deciding none; treat each as not approved.
These arrive as source: "extension" input, which humanReplyText does
not read as the human’s (no voucher), so a message about the queue is
never itself a reply to the queue.
The loop guard’s entry
The guard’s entry (enqueueThreshold, key \u0000threshold) is not an
action: find never matches it, and today any typed reply settles it and
ends the consecutive run (pendingStage). Under the command it behaves the
same way: approve N or deny N on that entry settles it, calls
denials.humanIntervened(), and tells the model (approve: The human let
the session go on with /pending; the next steps are judged again.; deny:
The human stopped the session’s run with /pending; stop and say what you
were doing.). clear settles it with the rest and resets the run too.
So the guard entry can never linger approved. pendingCommand asks
queue.threshold() to tell it apart; the queue exposes isThreshold(entry)
rather than the key.
The phone
No pi-remote change: /pending approve 1 typed on the phone is sent as a
prompt beginning with /, which runs as the command. pi-remote vouches
the text first (#249), and the voucher lapses unused, since the command
never reaches the input event as a reply. Headless hosts: select carries
the host’s dialog timeout as every dialog does; the argument forms need no
dialog.
Scope
Code
-
packages/pi-modes/pending-queue.ts-approved,list,at,approve,deny,clear, the widget line, the three texts. -
packages/pi-modes/authorize.ts- the approved branch inpendingStage. -
packages/pi-modes/judge-wiring.ts-pendingCommand, registration.
Tests (vitest)
-
packages/pi-modes/test/pending-queue.test.ts(regression):atfollows the widget’s numbering after a settle;approvemarks and keeps;deny/clearremove; the approved widget line;isThreshold. -
packages/pi-modes/test/authorize.test.ts(regression): an approved entry allows with the forbidden registry (no judge call) and settles, so the same action a second time queues again; an approvedgit pushdoes not allowgit push 2>&1; a rule-denied action stays denied although approved; a reply typed after approval changes nothing (approval wins). -
packages/pi-modes/test/pending-wiring.test.ts(contract, the command):approve 1marks the entry and sends the approve text with nodeliverAswhen idle and"steer"when not;deny 1settles and sends;clearsettles all; out of range and bad usage notify and send nothing; no-argument path drives the two selects;/pendingwith an empty queue notifies;approve/deny/clearon the guard’s entry settle it, reset the consecutive run and send the guard texts. Fakes:ui.select,ui.notify,isIdle,sendUserMessage. -
Coverage bars hold.
Docs and release
-
docs/modules/ROOT/pages/modes.adoc§ Waiting on you: the pending queue ([#pending-queue]): the command, what an approval grants, that entries otherwise stay until settled, and the phone form. -
CHANGELOG.adoc== Unreleased: pi-modes minor (a new command and a new approval path); pi-remote patch to re-pin. -
MR
Closes #259; merge note with the SHA.
Risks
| Risk | Mode | Mitigation |
|---|---|---|
The human approves the wrong step because numbers moved between reading and typing |
fail-open |
The action echoes the step it approved in full; an approval is for one exact key and one run; the widget redraws on every change. |
The model, told of an approval, runs a slightly different command and gets queued again |
silent (friction) |
The approve text says "exactly that action again"; the exact-key rule is the same one typed replies live under. |
An approved entry never runs and lingers approved |
silent |
|
A rule-denied action approved by command runs |
fail-open |
Impossible by order: the rule deny returns before the pending lookup; tested. |
The extension’s message to the model is read as the human’s reply |
fail-open |
|