Skip to content

fix(tui): prevent unsafe errors and out-of-order streamed replies - #114869

Merged
steipete merged 4 commits into
mainfrom
codex/tui-high-confidence-triage
Jul 28, 2026
Merged

steipete merged 4 commits into
mainfrom
codex/tui-high-confidence-triage

Conversation

@steipete

@steipete steipete commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Related: #104639
Related: #103147

What Problem This Solves

Fixes an issue where TUI users saw raw errors that could expose bearer tokens or terminal control sequences when a Gateway, session, model, shell, or startup operation failed. Fixes an issue where streamed assistant replies appeared above intervening tool calls, duplicated text across multiple tools, or left stale text after cancellations or provider snapshot revisions.

Why This Change Was Made

Routes every affected TUI error through one existing-contract, cause-aware, secret-redacting, terminal-safe formatter. Keeps chronological segmentation in the ChatLog owner without changing Gateway protocol, provider catalogs, TUI verbosity, dependencies, or user configuration. Frozen assistant segments remain owned by their run and safely reconcile revised or retracted provider snapshots.

This independently validated current-main fix is based on the concrete reports in #104639 by @Marnie0415 and #103147 by @Foxy6670. Both contributors are credited in the corresponding git commits. The broader tool-card and verbosity product changes proposed in #103147 are intentionally not bundled.

User Impact

TUI errors retain helpful nested causes without leaking secrets or ANSI/OSC controls. Assistant text appears in the correct order around tool calls; indentation, repeated calls, run cancellation, revised snapshots, empty retractions, and removal of abandoned assistant rows remain correct.

Evidence

  • Red baseline on clean main: seven focused regression assertions fail for raw Gateway/send errors, runtime prewarm formatting, secret leakage, and one/multiple tool chronology.
  • Green exact-head full TUI suite: 890 tests across 35 files on Blacksmith Testbox.
  • Real terminal proof: 58 PTY cases, including a real Gateway WebSocket, real cross-client delivery, Gateway restart, real embedded backend, streaming, cancellation, session isolation, and targeted visible-output regressions for redacted errors and chronological tool rendering; final-head fake-backend PTY recheck: all 42 cases passed.
  • Type-aware TUI lint: all 81 files, zero errors and zero warnings.
  • Production build: CLI, runtime, all 143 plugin SDK subpaths, and Control UI pass.
  • Final committed branch independently reviewed; no accepted findings.
  • AI-assisted; manually traced against current main, the canonical normalization/redaction contract, both contributor PRs, callers, session replay, streaming, cancellation, authoritative snapshot revision, and PTY behavior.

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Jul 28, 2026
@clawsweeper clawsweeper Bot added 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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 28, 2026
@clawsweeper

clawsweeper Bot commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 27, 2026, 10:43 PM ET / July 28, 2026, 02:43 UTC.

ClawSweeper review

What this changes

The branch routes TUI failures through the existing redacting terminal-safe formatter and splits cumulative assistant streams around tool output so rendered replies remain chronological after updates, cancellations, and revisions.

Merge readiness

⚠️ Ready for maintainer review - 3 items remain

Keep this PR open for normal maintainer review. The supplied patch is a focused repair for TUI secret-safe errors and streamed reply ordering, with substantial terminal-oriented proof, but it is protected by the maintainer label and is behind current main, so it should be refreshed and reviewed on the final merge result rather than auto-closed or auto-repaired.

Priority: P1
Reviewed head: b5a85ee3133318279554719283f38158e8541490

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch is focused and backed by concrete terminal-oriented evidence; it needs only a final rebase-aware review because the branch is behind current main and changes live display-state reconciliation.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The PR body documents after-fix real terminal PTY scenarios, including a real Gateway WebSocket and visible redaction/chronology assertions, and the supplied checks include a successful real-behavior-proof run.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The PR body documents after-fix real terminal PTY scenarios, including a real Gateway WebSocket and visible redaction/chronology assertions, and the supplied checks include a successful real-behavior-proof run.
Evidence reviewed 5 items Centralized terminal-safe error path: The branch adds formatTuiErrorMessage, which applies the existing shared error formatter and terminal rendering sanitization, then replaces direct stringification in TUI command, session, shell, embedded-backend, and shutdown paths.
Chronological stream-state repair: The ChatLog patch introduces per-run committed/latest assistant text plus frozen-segment tracking so later cumulative snapshots are rendered after intervening tool components and revised/retracted snapshots can remove stale visible segments.
Focused regression coverage: The branch adds ChatLog cases for one and multiple tool boundaries, revised snapshots, cancellations, retractions, and terminal PTY checks for both redacted nested errors and visible tool chronology.
Findings None None.
Security None None.

How this fits together

OpenClaw’s terminal UI receives operational failures and streamed chat/tool events from its backend, then renders them into the interactive chat log and stderr. This patch normalizes unsafe error inputs before display and changes how assistant stream state is segmented around tool rows.

flowchart LR
  A[Gateway and backend events] --> B[TUI event handlers]
  C[Operational errors] --> D[Shared error formatter]
  B --> E[Chat log state]
  D --> F[System notices and stderr]
  E --> G[Assistant and tool segments]
  G --> H[Terminal UI output]
Loading

Before merge

  • Resolve merge risk (P1) - The head is behind current main; the per-run ChatLog state changes should be rebased and the visible PTY chronology/retraction cases rechecked on the final merge result.
  • Resolve merge risk (P1) - The patch changes cancellation and provider-snapshot reconciliation in the terminal’s per-run display state, so final review should retain coverage for interleaved tools, retractions, and session changes rather than relying only on formatter tests.
  • Complete next step (P2) - The protected maintainer label and behind-base state require a human final review and merge-head proof refresh, not an automated repair lane.
Agent review details

Security

None.

PR surface

Source +128, Tests +271. Total +399 across 13 files.

View PR surface stats
Area Files Added Removed Net
Source 8 170 42 +128
Tests 5 275 4 +271
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 13 445 46 +399

Review metrics

Metric Value Why it matters
Per-run display state 3 added maps The ChatLog now tracks frozen segments, committed text, and latest text per run, which is the core safeguard for tool ordering and snapshot retraction behavior.

Merge-risk options

Maintainer options:

  1. Refresh the final terminal proof (recommended)
    Rebase onto current main and rerun the focused ChatLog plus PTY chronology, cancellation, revision, and retraction scenarios on the resulting head before merge.
  2. Accept the current state-path risk
    Merge with the existing regression and PTY evidence if maintainers judge the behind-base delta cannot affect TUI event ordering.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Rebase onto current main, then rerun focused ChatLog and terminal PTY chronology, cancellation, revision, and retraction proof on the resulting head.

Technical review

Best possible solution:

Rebase this focused repair onto current main, preserve the single shared formatter and ChatLog-owned segmentation approach, and confirm the real terminal cases on the exact merge head before landing.

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

No high-confidence independent reproduction was run in this read-only review. The supplied focused tests and PTY fixture describe concrete current-main failure paths for nested error display and cumulative assistant snapshots around tool events.

Is this the best way to solve the issue?

Yes, provisionally: using the existing shared error formatter and keeping stream segmentation in the ChatLog owner avoids parallel formatting policy or protocol changes. The final merge-head PTY verification remains important because the ordering fix changes live per-run display state.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 4273ca9dbd9b.

Labels

Label changes:

  • add P1: The PR addresses raw terminal errors that may expose bearer tokens and a visible assistant/tool ordering defect affecting active TUI workflows.
  • add merge-risk: 🚨 session-state: The patch changes per-run streamed assistant state across tools, cancellations, revisions, and retractions, so a final exact-head state-path check is warranted.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body documents after-fix real terminal PTY scenarios, including a real Gateway WebSocket and visible redaction/chronology assertions, and the supplied checks include a successful real-behavior-proof run.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The PR body documents after-fix real terminal PTY scenarios, including a real Gateway WebSocket and visible redaction/chronology assertions, and the supplied checks include a successful real-behavior-proof run.

Label justifications:

  • P1: The PR addresses raw terminal errors that may expose bearer tokens and a visible assistant/tool ordering defect affecting active TUI workflows.
  • merge-risk: 🚨 session-state: The patch changes per-run streamed assistant state across tools, cancellations, revisions, and retractions, so a final exact-head state-path check is warranted.
  • 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 PR body documents after-fix real terminal PTY scenarios, including a real Gateway WebSocket and visible redaction/chronology assertions, and the supplied checks include a successful real-behavior-proof run.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body documents after-fix real terminal PTY scenarios, including a real Gateway WebSocket and visible redaction/chronology assertions, and the supplied checks include a successful real-behavior-proof run.

Evidence

What I checked:

  • Centralized terminal-safe error path: The branch adds formatTuiErrorMessage, which applies the existing shared error formatter and terminal rendering sanitization, then replaces direct stringification in TUI command, session, shell, embedded-backend, and shutdown paths. (src/tui/tui-formatters.ts:221, b5a85ee31333)
  • Chronological stream-state repair: The ChatLog patch introduces per-run committed/latest assistant text plus frozen-segment tracking so later cumulative snapshots are rendered after intervening tool components and revised/retracted snapshots can remove stale visible segments. (src/tui/components/chat-log.ts:22, b5a85ee31333)
  • Focused regression coverage: The branch adds ChatLog cases for one and multiple tool boundaries, revised snapshots, cancellations, retractions, and terminal PTY checks for both redacted nested errors and visible tool chronology. (src/tui/components/chat-log.test.ts:75, b5a85ee31333)
  • Submitted real-behavior proof: The PR body reports real PTY scenarios including a Gateway WebSocket, cross-client delivery, restart, streaming, cancellation, session isolation, redacted visible failures, and chronological tool rendering; the supplied check state also records a successful Real behavior proof run. (src/tui/tui-pty-harness.e2e.test.ts:454, b5a85ee31333)
  • Related-work provenance: The branch’s four commits explicitly credit the two related TUI reports and separate the shared error-formatting and chronological-stream repairs from the broader unrelated tool-card proposal. (src/tui/components/chat-log.ts:284, 6ea2ee5b287c)

Likely related people:

  • steipete: Authored all four commits in this focused TUI repair series, including the error formatting, chronological stream segmentation, revised snapshot, and retracted-row changes. (role: recent TUI repair contributor; confidence: high; commits: 6ea2ee5b287c, 07243d3f92b0, e01410bca7ef; files: src/tui/components/chat-log.ts, src/tui/tui-formatters.ts, src/tui/tui.ts)
  • Foxy6670: The chronology and revised-stream commits credit this contributor, and the related open pull request contains the broader original analysis of tool/assistant ordering. (role: related TUI chronology contributor; confidence: medium; commits: 07243d3f92b0, e01410bca7ef, b5a85ee31333; files: src/tui/components/chat-log.ts, src/tui/components/chat-log.test.ts)
  • Marnie0415: The first error-formatting commit credits this contributor and the related pull request identified the direct String(err) display pattern that this patch consolidates through the shared formatter. (role: related TUI error-formatting contributor; confidence: medium; commits: 6ea2ee5b287c; files: src/tui/tui-formatters.ts, src/tui/tui-command-handlers.ts)

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Rebase onto current main and repeat the focused terminal chronology/retraction proof on the exact merge head.

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.

@steipete
steipete merged commit eeba5a3 into main Jul 28, 2026
200 of 210 checks passed
@steipete
steipete deleted the codex/tui-high-confidence-triage branch July 28, 2026 02:57
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 28, 2026
…enclaw#114869)

* fix(tui): redact and sanitize terminal errors

Co-authored-by: Marnie0415 <[email protected]>

* fix(tui): keep streamed answers and tools chronological

Co-authored-by: Foxy6670 <[email protected]>

* fix(tui): keep revised answers after tool calls

Co-authored-by: Foxy6670 <[email protected]>

* fix(tui): discard retracted streamed assistant rows

Co-authored-by: Foxy6670 <[email protected]>

---------

Co-authored-by: Marnie0415 <[email protected]>
Co-authored-by: Foxy6670 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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