Skip to content

feat(tools)!: ask_user question hold, Interactive effect class, protocol 21 (T8) - #49

Merged
lg2m merged 1 commit into
mainfrom
feat/tool-layer-t8-ask-user
Sep 16, 2026
Merged

lg2m merged 1 commit into
mainfrom
feat/tool-layer-t8-ask-user

Conversation

@lg2m

@lg2m lg2m commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

Closes ENG-779. Tool-layer slice T8 (docs/plans/tool-layer.md § D7, § New effect classes). Stacked on main @ c7fd5c4 (after H22.2).

What changed

ask_user — the model can put 1–4 structured questions to the human (2–6 options each, or free text) and wait for the answers, instead of guessing or ending its turn with a question in prose.

  • Nothing dispatches. Policy classifies the call Interactive (new EffectClass); the session gate holds it exactly like an approval — register the waiter, persist awaiting_approval, publish tool_approval_requested with the parsed question — and every approval mode holds it (a question is never dangerous; read-only may still consult its user). The reviewer is not consulted.
  • The answer is the result. ApprovalDecision::Answer { answers } (one string per question) settles the call completed in the same RespondToolApproval transaction, with the rendered Q/A as result, resolution answered. An empty answer set declines with a fixed "proceed on your judgement" result. Timeout → denied_timeout as today. Second answer → idempotent replay.
  • Malformed arguments never hold: they reach dispatch only to return the contract error (question 1 needs 2-6 options…).
  • TUI: the inline approval block becomes a question block — numbered options, digit keys pick, the composer takes free text (caret shown), Esc declines; multi-question holds accumulate answers and show earlier ones as prompt → answer. y/a/w/n are not live while a question is pending.
  • Headless: qq run has no human, so it cancels at the first question and exits needs_input (5) with the question in outcome.message; the stream already carries the tool_approval_requested event for a supervisor to resume with. A spawned child's question is declined so the child proceeds. Direct gate-less runs answer "no user is available".
  • Prompt v12 adds one line of guidance: ask once, offer concrete options, never ask what a tool could find out.

Protocol 21 (!)

Additive fields, but strict peers reject the new tags, so the version moves:

  • question: Option<Box<QuestionPreview>> on tool_approval_requested (boxed: SessionEvent stays ≤ 336 B — the H22.2 size test caught the unboxed version)
  • ApprovalDecision::Answer, ApprovalResolution::Answered, capabilities approvals advertises answer
  • HeadlessStatus::NeedsInput = exit 5 (exit table pinned by test + headless-contract.md)
  • T12's InputPart::WorkspaceFile.range folded into this bump (as flagged in feat(tui): @ mentions attach workspace files client-side with ranges, dirs, globs, @diff/@sha, and completion (T12) #45)
  • v21 goldens: event_tool_approval_requested_question, command_respond_tool_approval_answer, headless needs_input.jsonl; v20 retained decode-only. Harbor trace fixtures bumped.

Design decisions

  • Answers are option text, not indices — the transcript reads without the schema, and free text and picks are one shape.
  • A question with no options is a free-text prompt (plan implied options were mandatory).
  • Gate returns GateDecision::Answered { result } and the run loop records it as a RetainedResult without dispatch; RuntimeEvent::ToolCallAnswered mirrors ToolCallDenied (session layer already persisted/published).
  • ToolClass::Interactive { question: Option<QuestionPreview> } — classification parses once; evaluate returns PolicyDecision::AskUser for Some, Execute (→ contract error at dispatch) for None.
  • ADR-0021 written for both Interactive (shipped) and Network (T9 amends).

Verification

  • 1439 workspace tests, 12 new: ask bounds/defaults/indexed errors/rendering + clipping; policy every-mode hold + malformed + grants irrelevant; 4 session round trips (read-only hold → exact result text in the next provider request with no start/finish events; decline + idempotent replay; timeout; malformed → error, no hold); TUI keys; TUI render; headless needs_input end-to-end.
  • cargo fmt --check, clippy --all-targets --all-features -D warnings, wasm qq-client, minimal qq-provider profile.

Measurements

tool_dispatch read_tool_loop, pinned core, 5 interleaved pairs after the rebase: base 42.3 → cand 42.5 µs median (noise). Before rebasing I saw a consistent +4 µs; bisected to H22.2 having landed on main between the two builds, not this slice (plan_compile 22.4 → 23.4 µs is the 8th declaration's share of catalog/prefix compile — same order as T2/T7). Evidence target/qq-perf/t8-2026-09-15/ (untracked).

Docs

tools.md § Built-In Tools, new § Asking The User, § Approval Policy decision table · protocol.md v21 note, decision/resolution tables, question preview · headless-contract.md exit table + approval semantics · adr/0021-interactive-and-network-effect-classes.md · ledger T12 → Shipped, T8 → In review + receipt.

Follow-ups (recorded in ledger)

  • Headless --answer/resume-with-answer relay; T13 measures how often models ask.
  • TUI: Backspace on an empty composer could pop the previous answer.
  • ToolCallDisplay for answered calls if the transcript wants a form, not text.

…; Interactive effect class; protocol 21 (T8)

The model gains a cheaper move than guessing when a request is ambiguous:
`ask_user` carries 1-4 questions with 2-6 options each or free text, and
the run holds until the human answers. Nothing dispatches: the call is
classified `Interactive`, held like an approval (register before publish,
same timeout), and settled `completed` with the rendered questions and
answers as its result when the client sends `ApprovalDecision::Answer`.
Every approval mode holds it — a question is never dangerous — and the
reviewer is not consulted. Malformed arguments never hold; they reach
dispatch only to return the contract error naming the failing bound.

Protocol 21 (breaking for strict peers): `question: Option<Box<
QuestionPreview>>` on `tool_approval_requested`, the `answer` decision,
the `answered` resolution, `HeadlessStatus::NeedsInput` (exit 5), and
T12's `InputPart::WorkspaceFile.range` folded into the same bump. `v20`
goldens are retained decode-only; `v21` goldens add the question hold,
the answer command, and a headless `needs_input` stream. `SessionEvent`
stays within its 336-byte bound: the preview is boxed.

`qq run` has no human: it cancels at the first question and exits
`needs_input` with the question in the outcome message, so a supervisor
can resume with the answer instead of the run stalling to the approval
timeout or the model guessing. A spawned child's question is declined on
the spot. Direct runs without a session gate answer "no user is
available".

TUI: the inline approval block becomes a question block for `ask_user` —
numbered options, digits pick, the composer takes free text, Esc
declines; answers accumulate across questions and send together. Prompt
v12 tells the model to ask once, offer concrete options, and never ask
what a tool could find out.

Verification: 1439 workspace tests (12 new: bounds/rendering, every-mode
policy, four session round trips incl. decline + idempotent replay +
timeout, TUI keys and render, headless exit); fmt, clippy -D warnings,
wasm qq-client, minimal qq-provider profile. `tool_dispatch` A/B after
the H22.2 rebase: 42.3 → 42.5 µs median (noise). ADR-0021 written
(shared with T9's `Network`).
@lg2m
lg2m merged commit 7956e8e into main Sep 16, 2026
4 checks passed
@lg2m
lg2m deleted the feat/tool-layer-t8-ask-user branch September 16, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant