Skip to content

fix(tui): keep assistant text chronological across tool calls and resume; condense tool cards - #103147

Closed
fluffyxenia wants to merge 9 commits into
openclaw:mainfrom
fluffyxenia:tui-history-ordering-and-bash-persist
Closed

fluffyxenia wants to merge 9 commits into
openclaw:mainfrom
fluffyxenia:tui-history-ordering-and-bash-persist

Conversation

@fluffyxenia

@fluffyxenia fluffyxenia commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Two user-visible TUI rendering defects and one readability problem:

  1. Assistant text rendered out of chronological order around tool calls. The TUI kept one streaming assistant component per run and updated it in place while tool cards appended separately, so text the model produced after a tool call rendered above that tool's card. The same defect corrupted ordering when replaying history on session resume.
  2. Tool cards were tall and noisy, taking several lines each even when collapsed, which made runs with many tool calls hard to scan.
  3. With verbose mode off there was no indication of tool activity at all — the TUI sat silent during long tool-heavy stretches.

Why This Change Was Made

  • Assistant streaming text is now segmented around tool cards: each new burst of assistant text after a tool call gets its own component in true arrival order, both live and on history replay (replay assigns distinct per-turn identities instead of merging a whole run into one block).
  • Tool cards are condensed to one line with middle-ellipsis truncation.
  • When verbose is off, a one-line tool-activity summary shows what the agent is doing instead of nothing.

Scope note: this PR originally also carried persistence for !/!! local shell commands; per review feedback it was split out and now lives in #103648. This PR is purely rendering/display.

User Impact

  • Assistant text and tool cards appear in the order they actually happened, live and after resume.
  • Tool-heavy runs are much more compact and scannable.
  • Verbose-off sessions show a lightweight activity line instead of appearing frozen.

Evidence

  • src/tui/components/chat-log.test.ts — regression tests for chronological segmentation live and on replay.
  • src/tui/tool-activity-summary.test.ts — activity summary behavior.
  • src/tui/tui-event-handlers.test.ts, src/tui/tui-session-actions.test.ts — event wiring and resume-ordering coverage.
  • Full src/tui suite green locally; fake-backend PTY lane green (test/vitest/vitest.tui-pty.config.ts).
  • Real-terminal evidence (real gateway, live inference, no mocks): live compact cards + chronological ordering, verbose-off summaries, and resume replay in both verbose tiers — fix(tui): keep assistant text chronological across tool calls and resume; condense tool cards #103147 (comment). The recording process itself surfaced two replay defects, both fixed in-branch with regression tests (see the comment).

🤖 Generated with Claude Code

@openclaw-barnacle openclaw-barnacle Bot added app: web-ui App: web-ui gateway Gateway runtime size: XL labels Jul 9, 2026
@fluffyxenia
fluffyxenia force-pushed the tui-history-ordering-and-bash-persist branch from 0660aeb to 1eff879 Compare July 10, 2026 00:43
@clawsweeper clawsweeper Bot added rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 10, 2026
@clawsweeper

clawsweeper Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: found issues before merge. Reviewed August 24, 2026, 5:40 PM ET / 21:40 UTC.

ClawSweeper review

What this changes

This PR segments streamed assistant text around tool calls, condenses terminal tool cards, and shows a one-line tool-activity summary when verbose mode is off.

Merge readiness

⚠️ Needs maintainer review before merge - 4 items remain

Keep open for a maintainer product decision: current main already owns the chronology repair, but the compact-card and verbose-off activity proposal remains distinct. The branch cannot land as written because it retains the superseded transcript state model.

Priority: P2
Reviewed head: 3ad39dd13668450fd3b08315af07bb3bf630bf0f
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The prior real behavior proof is strong, but the current branch is not a safe landing vehicle after main replaced its transcript and rendering owners.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The contributor supplied a real Gateway, live-inference, terminal, and resume recording for the changed behavior; the later head commit is test-only according to its commit record.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The contributor supplied a real Gateway, live-inference, terminal, and resume recording for the changed behavior; the later head commit is test-only according to its commit record.
Evidence reviewed 5 items Superseded transcript owner: The branch’s cumulative-prefix maps and global freezing logic are the prior chronology model; current main instead owns segments per run and handles revised snapshots by removing obsolete frozen segments.
Current-main chronology behavior: Current main records frozen/finalized components per assistant run and reconciles a revised snapshot before rendering the replacement text; focused tests cover retracted post-tool output and final ordering.
Merged fix provenance: The history identifies the merged chronology repair as the TUI out-of-order-streamed-replies fix; the maintainer discussion explicitly says it landed the narrow reproducible chronology work from this proposal.
Findings 1 actionable finding [P1] Remove the superseded ChatLog chronology rewrite
Security None None.

Live Verification

Command: node scripts/run-vitest.mjs run --config test/vitest/vitest.tui-pty.config.ts

Result: PASS (completed)

node scripts/run-vitest.mjs run --config test/vitest/vitest.tui-pty.config.ts
runner@runnervm76f27:/tmp/clawsweeper-live-proof-103147-8CqaaJ/target$ node scripts/run-vitest.mjs run --config test/vitest/vitest.tui-pty.config.ts

 RUN  v4.1.9 /tmp/clawsweeper-live-proof-103147-8CqaaJ/target

node scripts/run-vitest.mjs run --config test/vitest/vitest.tui-pty.config.ts
 ✓  tui-pty  src/tui/tui-pty-harness.e2e.test.ts (20 tests) 10913ms
     ✓ shows startup activity while post-connect initialization is pending  3143ms
     ✓ blocks overlapping normal messages while a run is busy  516ms
     ✓ submits a follow-up prompt while a run is streaming  512ms
     ✓ keeps the newer session when a rapid switch's history resolves last  537ms

 Test Files  1 passed (1)
      Tests  20 passed (20)
   Start at  21:41:38
   Duration  11.64s (transform 776ms, setup 496ms, import 31ms, tests 10.91s, environment 0ms)

runner@runnervm76f27:/tmp/clawsweeper-live-proof-103147-8CqaaJ/target$ node scripts/run-vitest.mjs run --config test/vitest/vitest.tui-pty.config.ts

 RUN  v4.1.9 /tmp/clawsweeper-live-proof-103147-8CqaaJ/target































Assertions:

  • PASS expect_output: Test Files

How this fits together

The terminal UI turns agent stream and tool events into the operator’s chat transcript, then rebuilds that transcript from session history on resume. Verbosity controls how much tool activity reaches the terminal view.

flowchart LR
A[Agent stream events] --> B[TUI event routing]
B --> C[Transcript state]
B --> D[Tool activity display]
E[Session history] --> C
C --> F[Terminal renderer]
D --> F
F --> G[Operator view]
Loading

Decision needed

Question Recommendation
Should OpenClaw adopt the remaining presentation policy: one-line condensed tool cards and a coarse activity line while verbose mode is off? Adopt as a focused rebuild: Reimplement the accepted presentation behavior on current main without carrying the old transcript or renderer state model.

Why: The chronology defect is already fixed on main; the remaining behavior changes are intentional terminal-product choices rather than repairs to an established contract.

Before merge

  • Remove the superseded ChatLog chronology rewrite (P1) - Current main now owns chronology through per-run frozen/finalized segments, revised-snapshot handling, and delayed-prompt preservation. This unchanged older map-based rewrite would create a competing transcript model; retain only presentation work rebuilt on the current owner.
  • Resolve merge risk (P1) - Resolving this dirty branch without a rebuild could replace current snapshot/retraction and terminal-sanitization behavior with the older parallel implementation.
  • Complete next step (P2) - A maintainer must choose the remaining presentation policy before any safe focused rebuild can proceed.

Findings

  • [P1] Remove the superseded ChatLog chronology rewrite — src/tui/components/chat-log.ts:321-340
Agent review details

Security

None.

PR surface

Source +244, Tests +395. Total +639 across 14 files.

View PR surface stats
Area Files Added Removed Net
Source 9 353 109 +244
Tests 5 397 2 +395
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 14 750 111 +639

Review metrics

Metric Value Why it matters
Already-shipped verbosity mode 1 existing mode: full Current main already exposes full tool-output verbosity, leaving only the presentation policy for maintainer consideration.

Stored data model

Persistent data-model change detected: serialized state: src/tui/tui-session-actions.ts, serialized state: src/tui/tui-session-info-equality.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Rebuild after product approval
    Port only the accepted card and activity presentation onto the current transcript and safe-renderer owners, with no legacy state model retained.
  2. Pause the branch
    Keep the existing terminal presentation unless a maintainer explicitly chooses the new verbose-off and compact-card policy.

Technical review

Best possible solution:

Decide whether compact cards and verbose-off activity are desired, then rebuild only those presentation behaviors on current main’s transcript and safe-renderer owners with focused PTY proof.

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

No current-main reproduction is needed for the original chronology report: current source and tests show it is fixed. The contributor’s recorded real-terminal run demonstrates the proposed presentation behavior, but this review did not rerun it.

Is this the best way to solve the issue?

No: retaining the branch is not the best fix because main now has a richer transcript owner. A focused rebuild is appropriate only after the presentation direction is approved.

Full review comments:

  • [P1] Remove the superseded ChatLog chronology rewrite — src/tui/components/chat-log.ts:321-340
    Current main now owns chronology through per-run frozen/finalized segments, revised-snapshot handling, and delayed-prompt preservation. This unchanged older map-based rewrite would create a competing transcript model; retain only presentation work rebuilt on the current owner.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 5f9fda20c930.

Labels

Label changes:

  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🦐 gold shrimp, so this older rating label is no longer current.

Label justifications:

  • P2: The remaining decision is a bounded terminal presentation improvement, while the original ordering bug is already fixed on main.
  • merge-risk: 🚨 compatibility: The stale branch conflicts with the current transcript owner and could regress established streaming and resume behavior if resolved by restoring its older state model.
  • merge-risk: 🚨 security-boundary: The branch modifies the tool renderer that current main subsequently hardened for terminal-safe Markdown and bounded rendering.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action. Sufficient (live_output): The contributor supplied a real Gateway, live-inference, terminal, and resume recording for the changed behavior; the later head commit is test-only according to its commit record.
  • proof: sufficient: Contributor real behavior proof is sufficient. The contributor supplied a real Gateway, live-inference, terminal, and resume recording for the changed behavior; the later head commit is test-only according to its commit record.

Evidence

What I checked:

  • Superseded transcript owner: The branch’s cumulative-prefix maps and global freezing logic are the prior chronology model; current main instead owns segments per run and handles revised snapshots by removing obsolete frozen segments. (src/tui/components/chat-log.ts:321, 3ad39dd13668)
  • Current-main chronology behavior: Current main records frozen/finalized components per assistant run and reconciles a revised snapshot before rendering the replacement text; focused tests cover retracted post-tool output and final ordering. (src/tui/components/chat-log.ts:406, 5f9fda20c930)
  • Merged fix provenance: The history identifies the merged chronology repair as the TUI out-of-order-streamed-replies fix; the maintainer discussion explicitly says it landed the narrow reproducible chronology work from this proposal. (src/tui/components/chat-log.ts:406, eeba5a343317)
  • Safe renderer has changed underneath the branch: Current main sanitizes complete Markdown source and bounds rendered tool-output rows, whereas the branch still uses the earlier direct Markdown renderer; presentation work must preserve this newer boundary. (src/tui/components/tool-execution.ts:28, 5f9fda20c930)
  • Current command contract already includes full verbosity: Current main exposes on/off/full verbosity and distinguishes tool-event visibility from tool-output visibility, so the branch’s full-verbosity addition is no longer a unique change. (src/tui/commands.ts:18, 5f9fda20c930)

Likely related people:

  • steipete: Authored merged TUI chronology fix eeba5a3 and the later current-main transcript refactors. (role: merged chronology-fix author and recent transcript contributor; confidence: high; commits: eeba5a343317, 3cf23294a59d; files: src/tui/components/chat-log.ts, src/tui/tui-event-handlers.ts)
  • vincentkoc: Authored the merged terminal-control hardening that changed the tool-output renderer this branch also modifies. (role: adjacent terminal-rendering safety contributor; confidence: high; commits: 4bdf9ca789b5; files: src/tui/components/tool-execution.ts)

Rank-up moves

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

  • Get a maintainer decision on the remaining presentation behavior.
  • Rebuild only approved presentation code on current main and rerun focused terminal proof.

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 (10 earlier review cycles; latest 8 shown)
  • reviewed 2026-07-10T19:47:17.251Z sha 87340b8ca1e7c0542e6f36ec4dea44154c6deedc :: needs real behavior proof before merge. :: [P1] Preserve hidden tool boundaries during history replay | [P1] Remove shell-history replay from this rendering PR | [P2] Truncate the combined tool header before rendering
  • reviewed 2026-07-12T00:43:10.754Z sha fded082924b8c780b168ea1e3c34f168b77f3ff3 :: needs real behavior proof before merge. :: [P1] Preserve every hidden tool boundary | [P2] Clear activity state when summaries are pruned
  • reviewed 2026-07-15T10:45:30.711Z sha d64018368df0e14a8b65cde56250f5b3fdd90f49 :: needs maintainer review before merge. :: none
  • reviewed 2026-07-16T02:49:41.395Z sha 3ad39dd :: needs maintainer review before merge. :: none
  • reviewed 2026-07-16T03:51:26.968Z sha 3ad39dd :: needs maintainer review before merge. :: none
  • reviewed 2026-07-31T05:56:17.869Z sha 3ad39dd :: needs maintainer review before merge. :: none
  • reviewed 2026-08-01T23:12:36.207Z sha 3ad39dd :: needs maintainer review before merge. :: none
  • reviewed 2026-08-07T22:15:56.340Z sha 3ad39dd :: found issues before merge. :: [P1] Remove the superseded ChatLog chronology rewrite

@fluffyxenia
fluffyxenia force-pushed the tui-history-ordering-and-bash-persist branch from 408d51b to 87340b8 Compare July 10, 2026 10:54
@openclaw-barnacle openclaw-barnacle Bot added size: L and removed app: web-ui App: web-ui gateway Gateway runtime size: XL labels Jul 10, 2026
@fluffyxenia fluffyxenia changed the title fix(tui): keep chat history in order; persist local shell commands to history fix(tui): keep assistant text chronological across tool calls and resume; condense tool cards Jul 10, 2026
@clawsweeper clawsweeper Bot removed merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 10, 2026
@fluffyxenia

Copy link
Copy Markdown
Contributor Author

Thanks — acting on all three P1s:

Split done. This PR is now rendering-only (chronological ordering fix + tool-card condensing + verbose-off activity summary); the title and body were updated to match. Shell persistence moved to #103648 with its own evidence and a redesigned consent model.

Duplicate-persist finding: confirmed and fixed (in #103648, where the code now lives). A failed spawn emits both error and close; a shared settled-guard now makes completion/persistence once-only, with a regression test covering the error-then-close sequence.

On the maintainer decision (persist-by-default vs explicit sharing): #103648 now implements the review's recommended option. Ordinary ! execution stays local-only by default — the shipped behavior is unchanged unless the operator opts in. The session consent prompt gained an explicit third choice ("Yes, and share with the agent"); only that opt-in enables persistence, with ! = agent-visible next turn and !! = history-only (excludeFromContext: true), both semantics stated in the prompt itself. The rationale for offering sharing at all: operators frequently run ! commands precisely to show the agent something (mirroring Claude Code's own ! semantics), and the BashExecutionMessage/excludeFromContext model already existed unused in packages/agent-core. The security concern is real — which is why model visibility is a per-session explicit consent, never a default.

PTY evidence: rendering behavior is covered by the fake-backend PTY lane plus the chat-log regression tests in this PR; the !/!! model-visibility proof (committed e2e against a real tui --local, asserting on the captured model request body) is posted on #103648.

@clawsweeper re-review

🤖 Generated with Claude Code

@clawsweeper

clawsweeper Bot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@fluffyxenia
fluffyxenia force-pushed the tui-history-ordering-and-bash-persist branch from 87340b8 to fded082 Compare July 12, 2026 00:14
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. labels Jul 12, 2026
fluffyxenia added a commit to fluffyxenia/openclaw that referenced this pull request Jul 12, 2026
A failed spawn emits both 'error' and a subsequent 'close'; both handlers
called persistResult, appending two bashExecution transcript rows for one
command. Add a settled guard so only the first terminal event persists.

Addresses ClawSweeper review finding on PR openclaw#103147.
- record a segment boundary for replayed tool calls even when verbose is
  off, so a turn's later cumulative text cannot rewrite pre-tool text in
  place on the default resume path; replay now routes through the same
  activity-summary path a live verbose-off run uses
- truncate the combined tool-card header to the render width (ANSI-aware)
  instead of letting it wrap and break the condensed card layout
- drop the bashExecution history-replay branch: shell persistence and its
  replay rendering belong to the persistence PR (openclaw#103648)
@steipete

Copy link
Copy Markdown
Contributor

Triage update: the narrowly reproducible assistant/tool chronology and revised-stream snapshot fixes from this proposal have landed on main in #114869 (eeba5a3), with your co-author credit preserved in the landed commit. The changes are independently covered by full TUI, real-terminal, and real-Gateway proof. This PR is intentionally remaining open: its additional tool-card and verbosity/presentation changes are a separate product decision and were not claimed as fixed or superseded. Thank you for the original diagnosis.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 other 🚨 Merging this PR has meaningful risk outside the owned taxonomy. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 31, 2026
@clawsweeper clawsweeper Bot added status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. and removed status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Aug 8, 2026
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Aug 24, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This pull request has been automatically marked as stale due to inactivity.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Sep 8, 2026
@openclaw-barnacle

Copy link
Copy Markdown

Closing due to inactivity.
If you believe this PR should be revived, post in #clawtributors on Discord to talk to a maintainer.
That channel is the escape hatch for high-quality PRs that get auto-closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: L stale Marked as stale due to inactivity status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants