Skip to content

fix(tui): keep shared conversations synchronized and streaming bounded - #114443

Merged
steipete merged 1 commit into
mainfrom
codex/tui-stability-sweep
Jul 27, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/tui-stability-sweep

Conversation

@steipete

@steipete steipete commented Jul 27, 2026 •

Copy link
Copy Markdown
Contributor

Closes #38829

What Problem This Solves

Fixes an issue where users watching a conversation in the terminal UI would not see messages sent to the same session by another Gateway client until they restarted. Also fixes dropped visible responses during transcript-persistence races, accidental refreshes across agent boundaries, and unbounded memory growth when streaming runs never receive a terminal event.

Why This Change Was Made

Consumes the Gateway's existing session.message event through the TUI's canonical serialized, agent-scoped history reload path. Refreshes are coalesced and held until visible responses are durably persisted. Stream assembly retains at most 200 recently active runs using the existing shared bounded-map helper; late finals cannot evict live streams. Adds explicit handler disposal and an isolated real two-client Gateway PTY scenario. No new config, provider, protocol, database, or plugin API surface.

User Impact

Terminal conversations stay synchronized with other clients without restarting, visible streamed responses survive cross-client update and persistence races, sessions do not leak across agents, and long-running terminals remain memory-bounded.

Evidence

  • Linux: complete TUI unit suite, 743 passed across 32 files.
  • Linux: full terminal PTY harness, 29 passed.
  • Linux: complete real local/Gateway PTY suite, 16 passed, including actual two-client Gateway delivery, restart/reconnect, fresh-session adoption, followup collection, cancellation, and validation-loop diagnostics.
  • Stress coverage: 250 simultaneous transcript invalidations are coalesced; 2,000 orphaned stream runs keep memory bounded while preserving the live run.
  • Regression coverage for both transcript/final persistence orders, updates arriving during optimistic submission, repeated updates before persistence, stale metadata, global sessions, and unqualified aliases belonging to another agent.
  • Full Linux pnpm check:changed: formatting, core and test type checks, lint, dependency/API/plugin-boundary guards, native state, database-first storage, and zero runtime import cycles.
  • Fresh independent autoreview: clean; no actionable findings.

Inspectable real two-client Gateway proof

Reviewed and tested commit: 26ea312c07da95119d0f25eeb60d42f9e58bb721.

Exact two-client Gateway PTY scenario and live-terminal assertions. The test creates a separate, authenticated Gateway connection, sends EXTERNAL_GATEWAY_SESSION_MESSAGE using sessions.send, and waits for both that exact message and FOLLOWUP_RUN_COMPLETE to appear in the existing terminal before it exits.

Remote Linux terminal transcript from the complete real-backend run:

$ OPENCLAW_TUI_PTY_INCLUDE_LOCAL=1 \
  node scripts/run-vitest.mjs run \
    --config test/vitest/vitest.tui-pty.config.ts \
    src/tui/tui-pty-local.e2e.test.ts --reporter=verbose

✓ preserves a disconnected draft across a real Gateway restart
✓ renders messages sent by another real Gateway client without restarting
✓ creates and adopts a fresh session through the real Gateway backend
✓ preserves a running session when /reset is typed against the real Gateway
✓ forwards an active-run prompt through the real Gateway followup queue
✓ renders a non-deliverable direct reply failure through the real Gateway and TUI
✓ cancels an admitted followup with Esc before it reaches the model
✓ collects two TUI-client prompts into one real Gateway followup turn
✓ renders safe validation-loop abort diagnostics through the real gateway backend

Test Files  1 passed (1)
     Tests  16 passed (16)
blacksmith run summary ... exit=0

Successful full GitHub CI for the exact reviewed head, including security, all four QA smoke profiles, all Node shards, build artifacts, documentation, lint, production and test type checks, and openclaw/ci-gate.

The branch intentionally retains the green, reviewed commit rather than rebasing solely because main advanced: the PR is mergeable, the complete CI and real Gateway proof are for this exact head, and the native maintainer prepare/merge workflow checks the current merge result.

Credit

Reported by @galen2017 in #38829. Builds on the earlier cross-client investigation by @harjothkhara in #96252 and bounded-stream investigation by @ZengWen-DT in #109492; both contributors are credited in the commit.

Fix cross-client terminal history synchronization without letting stale snapshots erase in-flight responses. Bound orphaned stream assembly, preserve session and agent ownership, and cover real Gateway delivery, persistence races, reconnects, and stress bursts.

Closes #38829.

Credits prior issue investigation in #96252 and bounded-stream work in #109492.

Co-authored-by: Harjoth Khara <[email protected]>
Co-authored-by: Wynne668 <[email protected]>
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation size: L maintainer Maintainer-authored PR labels Jul 27, 2026
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. labels Jul 27, 2026
@clawsweeper

clawsweeper Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 27, 2026, 4:31 AM ET / 08:31 UTC.

ClawSweeper review

What this changes

The PR makes an already-running terminal UI reload the selected conversation when another Gateway client adds a message, while bounding retained streamed-run state to 200 entries.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 5 items remain

Keep this PR open for maintainer review. It is a fresh, mergeable combined fix for the active terminal-session report, but carries the protected maintainer label and changes session-refresh ordering; the supplied PR evidence is promising but does not include an inspectable after-fix terminal transcript or artifact for the claimed two-client Gateway run.

Priority: P2
Reviewed head: 26ea312c07da95119d0f25eeb60d42f9e58bb721
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch has focused implementation and regression coverage in the supplied context, but reviewer confidence is capped until the claimed real two-client terminal behavior is shown with inspectable evidence.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: The PR body describes a real two-client Gateway PTY run and aggregate pass counts, but the supplied context lacks inspectable after-fix terminal output, recording, runtime log, or linked artifact showing the external message appearing in the live TUI; add redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The PR body describes a real two-client Gateway PTY run and aggregate pass counts, but the supplied context lacks inspectable after-fix terminal output, recording, runtime log, or linked artifact showing the external message appearing in the live TUI; add redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 5 items Combined TUI event path: The supplied PR diff adds a typed session-message handler, wires Gateway session.message events into the TUI, and disposes event handlers during TUI shutdown.
Real two-client scenario is covered in the branch: The supplied diff adds a Gateway PTY scenario that connects a second real Gateway client and expects its message to appear in the running TUI without restarting.
Bounded stream-state implementation: The supplied diff caps TuiStreamAssembler tracking at 200 runs and refreshes recently active entries before pruning, with regression coverage for late terminal events and thousands of orphan updates.
Findings None None.
Security None None.

How this fits together

The terminal UI receives Gateway events and renders a selected agent session from persisted history. This change feeds cross-client session.message notifications into the TUI reload coordinator while stream deltas continue through the bounded in-memory assembler before appearing in the transcript.

flowchart LR
  A[Gateway session message event] --> B[TUI event subscription]
  B --> C[Agent-scoped serialized history reload]
  C --> D[Terminal conversation transcript]
  E[Streaming assistant deltas] --> F[Bounded active-run state]
  F --> D
Loading

Decision needed

Question Recommendation
Should this combined implementation replace the overlapping open TUI fixes after its current-main merge result and two-client Gateway behavior are reviewed? Review and land the combined fix: Rebase or refresh against current main, inspect the exact merge result, and accept this branch if the retained-session and persistence-order guarantees hold.

Why: The protected maintainer label and session-state-sensitive ordering change require an explicit maintainer decision even though the branch is cleanly mergeable in the provided context.

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The PR body describes a real two-client Gateway PTY run and aggregate pass counts, but the supplied context lacks inspectable after-fix terminal output, recording, runtime log, or linked artifact showing the external message appearing in the live TUI; add redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The refresh path changes session-state timing around active runs and transcript persistence; maintainers should verify the rebased head still preserves local streaming output while applying external-session updates.
  • Resolve merge risk (P1) - The PR body reports real two-client Gateway validation, but the available context contains only summary claims and pass counts rather than an inspectable redacted terminal transcript, recording, log, or linked artifact.
  • Complete next step (P2) - This protected, session-state-sensitive PR needs a maintainer to choose the consolidated landing path and inspect evidence for the exact rebased head; no narrow automated repair is appropriate.
Agent review details

Security

None.

PR surface

Source +130, Tests +445, Docs +1. Total +576 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 4 158 28 +130
Tests 3 445 0 +445
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 604 28 +576

Review metrics

Metric Value Why it matters
Public compatibility surfaces 0 config, provider, protocol, database, or plugin API additions reported The proposed behavior stays within the existing Gateway event and TUI history-reload seams, limiting upgrade exposure to terminal session-state timing.

Merge-risk options

Maintainer options:

  1. Refresh and prove the integrated session path (recommended)
    Before merge, review the rebased merge result and attach a redacted terminal transcript, recording, log, or linked artifact showing a second Gateway client’s message appearing in the running TUI without erasing local streamed output.
  2. Accept the combined ordering risk
    Maintainers may land the integrated fix based on its focused tests and CI if they explicitly accept that transcript-refresh timing is confined to the TUI session-state path.

Technical review

Best possible solution:

Land one rebased, maintainer-reviewed implementation that keeps the existing serialized agent-scoped reload owner, preserves in-flight local output until persisted history is authoritative, and includes inspectable redacted proof of an external Gateway message appearing in a running TUI.

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

No high-confidence reproduction was personally executed in this read-only review. The linked report provides a concrete two-client path, and the branch adds a matching real Gateway PTY scenario, so the behavior is source-reproducible with medium confidence.

Is this the best way to solve the issue?

Unclear. Routing the existing Gateway event through the canonical serialized, agent-scoped reload path is the right stated boundary, but the exact current-main merge result and live persistence-order behavior need maintainer inspection before calling it the best final fix.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 9b171190f24e.

Labels

Label changes:

  • add P2: This repairs a real terminal conversation synchronization problem with limited blast radius outside the TUI.
  • add merge-risk: 🚨 session-state: The patch changes when selected-session history reloads relative to active streamed runs and persistence, so an ordering regression could stale or overwrite visible terminal state.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body describes a real two-client Gateway PTY run and aggregate pass counts, but the supplied context lacks inspectable after-fix terminal output, recording, runtime log, or linked artifact showing the external message appearing in the live TUI; add redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P2: This repairs a real terminal conversation synchronization problem with limited blast radius outside the TUI.
  • merge-risk: 🚨 session-state: The patch changes when selected-session history reloads relative to active streamed runs and persistence, so an ordering regression could stale or overwrite visible terminal state.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The PR body describes a real two-client Gateway PTY run and aggregate pass counts, but the supplied context lacks inspectable after-fix terminal output, recording, runtime log, or linked artifact showing the external message appearing in the live TUI; add redacted evidence before merge. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Combined TUI event path: The supplied PR diff adds a typed session-message handler, wires Gateway session.message events into the TUI, and disposes event handlers during TUI shutdown. (src/tui/tui-event-handlers.ts, 26ea312c07da)
  • Real two-client scenario is covered in the branch: The supplied diff adds a Gateway PTY scenario that connects a second real Gateway client and expects its message to appear in the running TUI without restarting. (src/tui/tui-pty-local.e2e.test.ts, 26ea312c07da)
  • Bounded stream-state implementation: The supplied diff caps TuiStreamAssembler tracking at 200 runs and refreshes recently active entries before pruning, with regression coverage for late terminal events and thousands of orphan updates. (src/tui/tui-stream-assembler.ts, 26ea312c07da)
  • Canonical user report remains open: The PR is linked to the active report at openclaw tui terminal cannot receive real-time messages #38829, which describes an existing TUI not receiving cross-client messages until restart.
  • Protected maintainer routing: The provided PR context lists the maintainer label. Repository policy requires protected-label items to remain open for explicit maintainer handling. (AGENTS.md, 9b171190f24e)

Likely related people:

  • harjothkhara: The PR credits this contributor’s earlier cross-client TUI session-message investigation and the related open implementation covers the same Gateway-to-TUI refresh invariant. (role: prior related implementation contributor; confidence: medium; commits: b0253c29756b; files: src/tui/tui-event-handlers.ts, src/tui/tui-pty-local.e2e.test.ts)
  • ZengWen-DT: The PR credits this contributor’s bounded-stream work, which overlaps the stream-assembler retention behavior incorporated here. (role: prior related implementation contributor; confidence: medium; commits: 2d2ae7c77093; files: src/tui/tui-stream-assembler.ts, src/tui/tui-stream-assembler.test.ts)

Rank-up moves

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

  • Attach a redacted terminal transcript, recording, runtime log, or linked artifact showing a second Gateway client’s message appear in the running TUI.
  • Refresh the branch against current main and retain proof for the exact reviewed 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 ac6009e into main Jul 27, 2026
150 of 160 checks passed
@steipete
steipete deleted the codex/tui-stability-sweep branch July 27, 2026 08:39
@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
…114443)

Fix cross-client terminal history synchronization without letting stale snapshots erase in-flight responses. Bound orphaned stream assembly, preserve session and agent ownership, and cover real Gateway delivery, persistence races, reconnects, and stress bursts.

Closes openclaw#38829.

Credits prior issue investigation in openclaw#96252 and bounded-stream work in openclaw#109492.

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

Labels

docs Improvements or additions to documentation maintainer Maintainer-authored PR merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: L status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

openclaw tui terminal cannot receive real-time messages

1 participant