Repository navigation
fix(tui): keep shared conversations synchronized and streaming bounded - #114443
Conversation
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]>
|
Codex review: needs real behavior proof before merge. Reviewed July 27, 2026, 4:31 AM ET / 08:31 UTC. ClawSweeper reviewWhat this changesThe 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 Priority: P2 Review scores
Verification
How this fits togetherThe terminal UI receives Gateway events and renders a selected agent session from persisted history. This change feeds cross-client 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
Decision needed
Why: The protected Before merge
Agent review detailsSecurityNone. PR surfaceSource +130, Tests +445, Docs +1. Total +576 across 8 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest 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. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Merged via squash.
|
…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]>
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.messageevent 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
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.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_MESSAGEusingsessions.send, and waits for both that exact message andFOLLOWUP_RUN_COMPLETEto appear in the existing terminal before it exits.Remote Linux terminal transcript from the complete real-backend run:
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
mainadvanced: 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.