Skip to content

feat(tui): answer agent questions in gateway and local modes - #143273

Merged
steipete merged 2 commits into
mainfrom
steipete/tui-ask-user-questions
Sep 9, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/tui-ask-user-questions

Conversation

@steipete

@steipete steipete commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Related: #120656 #143238

What Problem This Solves

Fixes an issue where an agent calling ask_user in the terminal UI left the user with nothing to answer: the TUI never rendered the question, only the raw tool call, and in local mode (openclaw chat, openclaw tui --local) the tool's question RPCs went to a Gateway that usually is not running, so the request failed outright. The secrets tool had the same gap, which is part of why the local TUI could only fall back to asking for credentials in chat (#120656). Ordinary answers typed while a question was pending in collect or followup queue mode also waited behind the blocked run.

Why This Change Was Made

Both TUI backends now share one session-scoped question controller. Gateway mode uses the existing question.* RPCs and events under the scopes the TUI already holds. Local mode serves the same five methods in-process through an embedded question broker wrapping the Gateway's QuestionManager, registered like the existing embedded plugin-approval broker, and the question dispatcher routes there only when embedded mode has a broker. A typed reply is claimed by the pending question through the active run's guarded input owner before queue policy runs, which is what removed the collect/followup deadlock. Masked answers keep their exact bytes.

Store-bound secrets requests in local mode return a clear blocker to the model instead of collecting a value the process cannot commit, because the store write and runtime refresh are Gateway-owned. No protocol, schema, config, or Control UI changes.

User Impact

  • ask_user prompts render in the TUI in both modes: one question at a time with a stepper, arrow or number selection, Other… free text, multi-select toggles, Skip, and the time remaining.
  • Esc collapses the prompt and returns the composer with a pending-question status line; /question reopens it; a plain reply still answers the pending question.
  • Pending questions are restored after reconnects and session switches; questions answered elsewhere or expired close automatically.
  • Gateway-connected secrets requests use a masked input that never touches the chat log or input history, showing the entry name, reason, and proposed allowed hosts (accepted as proposed; edit hosts in the Control UI).
  • Local mode: store-bound secrets requests explain that they need a running Gateway; plain masked questions work.

Evidence

Real-model live run on an isolated state directory and free port (never the operator's Gateway), model anthropic/claude-fable-5-1, driven through tmux; captures are text only and contain no credentials.

Local mode, prompt rendered from a real ask_user call:

 openclaw tui - local embedded - agent main - session main
 ⠧ running • 7s | local ready
 Question pending · 898s · /question to open
───────────────Question 1/1 · Color                                                            ───────────────
               Which color do you prefer?
───────────────Expires in 898s                                                                 ───────────────
               › 1. Blue
                 2. Green
                 3. Other…
                 Confirm answer
                 Skip
               ↑/↓ or numbers select · Enter confirm · Esc collapse

After 1 + Enter: Question: answered. followed by the model's You chose Blue. A second question was collapsed with Esc (status line Question pending · 899s · /question to open), answered by typing Large into the composer, and the model replied You chose Large.

Gateway mode (tui --url ws://127.0.0.1:<port>): same prompt, answered 2 + Enter, model replied You chose Green. Then a real secrets request rendered the masked prompt:

               Question 1/1 · API key
               Provide the secret for LIVE_TEST_TOKEN.
               Secret store entry: LIVE_TEST_TOKEN
               Reason: TUI live test
               Allowed hosts (accept as proposed): example.com
                 1. Other…
               > ••••••••••••••••••••
                 Confirm answer
                 Skip
               Enter next/submit · Tab choices · Esc collapse
               Masked entry · Answer through this prompt, not the composer.

After Enter: Question: answered. and the model replied The credential is stored as LIVE_TEST_TOKEN with allowed host example.com. The typed value did not appear in any capture (checked by grep across all frames).

Automated proof: node --import ./scripts/tsx.mjs scripts/dev/tui-questions-proof.ts runs an isolated Gateway plus TUI and a local TUI with a scripted OpenAI-compatible model, verifying option resolution and the Esc/plain-reply continuation from the model's request bodies.

Tests: 1,893 tests across 62 files in the TUI, infra, harness, tools, runner, and Gateway question suites, plus 102 PTY tests. The exact-secret-byte cases fail on the original QuestionManager and pass with the fix. node scripts/check-changed.mjs passed all selected gates; pnpm build clean; docs mdx, link audit, glossary, and markdownlint pass. Codex autoreview (P0–P2): scoped-clean.

Known limits: the overlay host composites prompts over the chat log, so long background lines show at the overlay margins, the same as the existing plugin-approval overlay; secret input is single-line (use the CLI --value-file route for multiline values); local-mode questions do not survive exiting the TUI.

Overlay update: question prompts now use Pi TUI's supported width: "100%" option, resolving the background-chat margin limitation noted above.

Data-model compatibility evidence

The serialized writes in scripts/dev/tui-questions-proof.ts are isolated proof fixtures and requested evidence artifacts, not a runtime data-model change. The script creates its own temporary state and removes it after verified child cleanup, retaining only terminal frames and answer witnesses in the requested output directory. The repeatable proof passed Gateway selection, local selection, and local Esc/plain-reply continuation.

Runtime questions remain in QuestionManager's in-memory map. The embedded broker reuses that manager and rejects store-bound requests. The diff from the rebased parent leaves packages/gateway-protocol, src/config, src/secrets, and src/gateway/server-methods/question.ts unchanged. Existing persisted formats and the Gateway secret-store write path are preserved; this change requires no data migration or upgrade conversion.

Render session-owned questions with choices, Other, multi-select, a stepper,
Skip, expiry, and /question. Restore pending prompts after reconnect and
session changes, and keep masked input outside the composer and history.

Serve local questions through QuestionManager and claim eligible replies
before queue policy so answers cannot wait behind their blocked run.
Keep local secret-store requests blocked with explicit setup guidance.
Recover uncertain resolutions without replaying input and surface saved
secret refresh failures without exposing submitted values.

Validation: 1,893 focused and sibling tests; 102 PTY tests; isolated Gateway
and local scripted-model round trips; full build; check:changed; docs checks;
independent P0-P2 review. The broader docs anchor audit reports three existing
broken links in untouched generated maturity pages.
@clawsweeper

clawsweeper Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review September 9, 2026 16:50
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime scripts Repository scripts agents Agent runtime and tooling size: XL maintainer Maintainer-authored PR labels Sep 9, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 9, 2026
@clawsweeper

clawsweeper Bot commented Sep 9, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 9, 2026, 1:48 PM ET / 17:48 UTC (Revision 3).

ClawSweeper review

What this changes

Adds interactive agent-question prompts to Gateway-connected and local terminal sessions, including masked Gateway secret entry and plain replies that resume waiting local runs.

Merge readiness

⛔ Blocked before merge - 1 item remains

The PR remains useful and has no supported blocking findings. The prior migration concern is resolved: runtime questions remain in memory, and the added serialized files are isolated proof artifacts. Current main still lacks the terminal question flow.

Priority: P2
Reviewed head: 50e0096b033cd526b041544a3b679cbe8146c7d2

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A coherent implementation with direct terminal behavior evidence and meaningful lifecycle coverage; no actionable blocker remains from this review.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The captured terminal evidence exercises the changed controller and both production backends: local selection and plain reply resume the model, Gateway selection resolves the question, and masked Gateway entry stores a secret without exposing it in captured frames.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The captured terminal evidence exercises the changed controller and both production backends: local selection and plain reply resume the model, Gateway selection resolves the question, and masked Gateway entry stores a secret without exposing it in captured frames.
Evidence reviewed 9 items Pinned introduction and review continuity: Reviewed the merge-base ef37c4f to head delta. Comparing the earlier reviewed head 33d5f0b with this head shows only the proof-command registration in package.json. The previous completed review had no findings; its remaining migration concern is addressed by the supplied body update and source inspection. Base-only channel and MCP changes were excluded.
Current-main and release necessity check: Current main's default question dispatcher still calls the Gateway transport without the embedded broker route. Tree inspection found neither the new terminal question controller nor the embedded question broker on fetched main or v2026.9.3. No verified merged replacement was established.
No persistent data-model transition: QuestionManager retains questions in its existing in-memory map. The introduced delta leaves packages/gateway-protocol, src/config, src/secrets, and the Gateway question RPC handler unchanged. The proof script creates temporary isolated state and retains requested evidence artifacts; these writes do not introduce a runtime database or migration.
Findings None None.
Security None None.

How this fits together

The terminal UI connects either to a Gateway or an embedded local agent. Its question controller presents pending agent questions and returns operator answers to the existing question lifecycle; secret-store writes remain Gateway-owned.

flowchart TD
  A[Agent requests human input] --> B{Terminal mode}
  B -->|Gateway| C[Existing question RPCs]
  B -->|Local| D[In-process question broker]
  C --> E[Session question prompt]
  D --> E
  E --> F[Operator answers or skips]
  F --> C
  F --> D
  C --> G[Resume agent or store secret]
  D --> H[Resume local agent]
Loading

Before merge

  • Add data-model compatibility proof - Confirm migration or upgrade compatibility proof before merge.
Agent review details

Security

None.

PR surface

Source +1231, Tests +1494, Docs +58, Config +1, Other +570. Total +3354 across 29 files.

View PR surface stats
Area Files Added Removed Net
Source 14 1240 9 +1231
Tests 9 1519 25 +1494
Docs 4 68 10 +58
Config 1 1 0 +1
Generated 0 0 0 0
Other 1 570 0 +570
Total 29 3398 44 +3354

Review metrics

Metric Value Why it matters
Implementation and validation growth Production net +1,231 lines; tests net +1,494; proof tooling +570 Growth supports the shared controller, masked editor, and embedded adapter while retaining the existing question manager and secret-store owner.

Stored data model

Persistent data-model change detected: serialized state: scripts/dev/tui-questions-proof.ts, unknown-data-model-change: scripts/dev/tui-questions-proof.ts. Confirm migration or upgrade compatibility proof before merge.

Technical review

Best possible solution:

Use one shared terminal question controller with existing Gateway contracts, process-owned local questions, and Gateway-owned secret storage.

Do we have a high-confidence way to reproduce the issue?

Yes, from source: current main lacks terminal question presentation and sends default local question requests toward the Gateway. This review did not execute a failing runtime case.

Is this the best way to solve the issue?

Yes. Reusing the existing question manager and RPC contracts addresses the missing terminal path without a parallel persistent store, protocol change, or new configuration.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against fc3bb9f5e3a9.

Labels

Label justifications:

  • P2: This is a bounded terminal interaction improvement that lets users answer waiting agents in both supported terminal modes.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The captured terminal evidence exercises the changed controller and both production backends: local selection and plain reply resume the model, Gateway selection resolves the question, and masked Gateway entry stores a secret without exposing it in captured frames.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured terminal evidence exercises the changed controller and both production backends: local selection and plain reply resume the model, Gateway selection resolves the question, and masked Gateway entry stores a secret without exposing it in captured frames.

Evidence

What I checked:

  • Pinned introduction and review continuity: Reviewed the merge-base ef37c4f to head delta. Comparing the earlier reviewed head 33d5f0b with this head shows only the proof-command registration in package.json. The previous completed review had no findings; its remaining migration concern is addressed by the supplied body update and source inspection. Base-only channel and MCP changes were excluded. (package.json:2111, 50e0096b033c)
  • Current-main and release necessity check: Current main's default question dispatcher still calls the Gateway transport without the embedded broker route. Tree inspection found neither the new terminal question controller nor the embedded question broker on fetched main or v2026.9.3. No verified merged replacement was established. (src/agents/harness/gateway-question-dispatch.ts:72, fc3bb9f5e3a9)
  • No persistent data-model transition: QuestionManager retains questions in its existing in-memory map. The introduced delta leaves packages/gateway-protocol, src/config, src/secrets, and the Gateway question RPC handler unchanged. The proof script creates temporary isolated state and retains requested evidence artifacts; these writes do not introduce a runtime database or migration. (src/gateway/question-manager.ts:109, 50e0096b033c)
  • Local lifecycle and authority checks: The broker captures admitted caller identity and live authority, cancels questions when that authority closes, and rejects store-bound requests before publication. The dispatcher rechecks input authority after its awaited module load. Plain replies use the existing guarded V2 injection owner; inspected tests cover replacement, retirement, and uncertain outcomes without queue replay. (src/infra/embedded-question-broker.ts:68, 50e0096b033c)
  • Gateway secret-write boundary: The existing question.resolve handler authorizes the session mutation and synchronously checks question liveness before committing a secret. Only the synthetic stored marker reaches question state and waiting agents. The TUI submits through that unchanged handler, masks input, suppresses raw RPC error text, and displays saved-but-refresh-failed recovery without resubmitting. (src/gateway/server-methods/question.ts:376, 50e0096b033c)
  • Session and recovery coverage: The controller uses the existing explicit session-ownership predicate, reconciles events against in-flight list snapshots, disposes secret drafts after submission, and checks uncertain resolution outcomes before allowing retry. Inspected tests cover session switching, contradictory ownership, expiry, lost acknowledgments, refresh failures, and disposal. (src/tui/tui-questions.ts:42, 50e0096b033c)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • obviyus: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-09T16:59:28.750Z sha 33d5f0b :: blocked before merge. :: none
  • reviewed 2026-09-09T17:21:21.771Z sha 50e0096 :: blocked before merge. :: none

@steipete
steipete merged commit 62ce554 into main Sep 9, 2026
190 checks passed
@steipete
steipete deleted the steipete/tui-ask-user-questions branch September 9, 2026 17:53
@steipete

steipete commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 10, 2026
…w#143273)

* feat(tui): answer agent questions in gateway and local modes

Render session-owned questions with choices, Other, multi-select, a stepper,
Skip, expiry, and /question. Restore pending prompts after reconnect and
session changes, and keep masked input outside the composer and history.

Serve local questions through QuestionManager and claim eligible replies
before queue policy so answers cannot wait behind their blocked run.
Keep local secret-store requests blocked with explicit setup guidance.
Recover uncertain resolutions without replaying input and surface saved
secret refresh failures without exposing submitted values.

Validation: 1,893 focused and sibling tests; 102 PTY tests; isolated Gateway
and local scripted-model round trips; full build; check:changed; docs checks;
independent P0-P2 review. The broader docs anchor audit reports three existing
broken links in untouched generated maturity pages.

* fix(ci): register the TUI question proof command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. scripts Repository scripts size: XL status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant