Skip to content

fix(tui): handle live session message updates - #96252

Closed
harjothkhara wants to merge 7 commits into
openclaw:mainfrom
harjothkhara:codex/38829-tui-session-message-live
Closed

harjothkhara wants to merge 7 commits into
openclaw:mainfrom
harjothkhara:codex/38829-tui-session-message-live

Conversation

@harjothkhara

@harjothkhara harjothkhara commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #38829. The Gateway already broadcasts session.message when another client appends a displayable transcript entry, but the running TUI ignored that event. The selected transcript therefore stayed stale until a manual reload or session switch.

Why This Change Was Made

  • Dispatches the existing event through a typed TUI handler; no Gateway protocol or subscription surface changes.
  • Routes idle external invalidations through the TUI's one canonical serialized history queue instead of adding a second reload coordinator.
  • Defers invalidations during active, pending, or optimistic local runs until both local execution is idle and the terminal persistence event has arrived. Either event ordering is supported.
  • Captures the selected session and agent across async history and session-info loads, so an old response cannot repaint a newly selected session.
  • Coalesces bursts into at most one follow-up reload while preserving invalidations that arrive during an in-flight load.

This is a current-shape rewrite of the original contribution. The earlier version handled the event but duplicated newer run-aware reload state and did not fully protect against stale async results after selection changes.

User Impact

Messages sent from another OpenClaw surface appear in an already-running TUI without a restart. Local streaming/final output remains visible until the persisted transcript is authoritative, and switching sessions cannot be undone by a late response from the old selection.

Evidence

Exact rewritten head: b0253c29756bc7fca22a09a7bc495ef5f03de654.

  • Sanitized AWS Crabbox cbx_3c73747f4601, run run_c23cbeab4a86: original event-handler/session-action baseline, 124 tests passed.
  • Blacksmith Testbox tbx_01kwxhf00awefzyke5p0phz686: rewritten event-handler/session-action suites, 141 tests passed.
  • Same Testbox: pnpm check:test-types passed; OPENCLAW_TUI_PTY_INCLUDE_LOCAL=1 pnpm test src/tui/tui-pty-local.e2e.test.ts passed, 9/9.
  • Source-blind live validation: ran the public TUI against an isolated Gateway, used a second public Gateway client to call sessions.send, and observed the unique marker appear in the running transcript without restart, direct state mutation, or test-only event injection.
  • Regression coverage includes event scoping, reload coalescing, active-run deferral, both terminal/persistence orderings, run-less invalidations, and stale session/agent responses.
  • Fresh structured autoreview: clean, no actionable findings, confidence 0.84.

Hosted exact-head CI passed in run 28846887328, and the repo-native OPENCLAW_TESTBOX=1 scripts/pr prepare-run 96252 gate accepted this exact head. The PR is intentionally left unmerged for maintainer review.

Risk / Compatibility

No config, storage, provider, protocol, or plugin SDK changes. Risk is confined to TUI transcript refresh ordering. The rewrite keeps one history-reload owner and makes the run/persistence barrier and selection identity explicit.

AI Assistance

AI-assisted rewrite and review. The maintainer inspected the full event, history-loading, run-terminal, Gateway subscription, and real PTY paths.

@clawsweeper

clawsweeper Bot commented Jun 24, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 7, 2026, 3:00 AM ET / 07:00 UTC.

Summary
The PR routes Gateway session.message events into the TUI serialized history reload path, guards stale async session loads, and adds handler, session-action, and PTY coverage.

PR surface: Source +92, Tests +317. Total +409 across 7 files.

Reproducibility: yes. at source level: current main broadcasts displayable transcript appends as session.message, while the TUI subscribes to session events but does not dispatch that event. I did not run a live terminal reproduction in this read-only review.

Review metrics: none identified.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #38829
Summary: This PR is the active candidate fix for the canonical selected-session TUI live transcript gap; broader cross-channel observer work remains separate.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦞 diamond lobster
Result: blocked until stronger real behavior proof is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Attach redacted terminal output, logs, a recording, or a linked artifact showing an external Gateway message appear in an already-running TUI.
  • Update the PR body after adding proof so ClawSweeper can re-review; if it does not rerun, ask a maintainer to comment @clawsweeper re-review.

Proof guidance:

  • [P1] Needs stronger real behavior proof before merge: The PR body/comment describe a live E2E run, but reviewers still need inspectable redacted terminal output, logs, recording, or a linked artifact showing the after-fix Gateway-to-TUI path. 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.

Risk before merge

  • [P1] The PR changes event-driven TUI transcript/session-state refresh ordering, so durable live proof matters even with focused tests and green CI.
  • [P1] The PR body and maintainer-style comment describe a source-blind live E2E, but no redacted terminal output, logs, recording, or linked artifact is attached for reviewers to inspect.

Maintainer options:

  1. Attach live TUI proof (recommended)
    Provide redacted terminal output, a recording, logs, or a linked artifact showing sessions.send from another Gateway client updating an already-running TUI.
  2. Accept narrative proof
    Maintainers can choose to accept the existing source-blind live-validation statement and green hosted checks as sufficient for this session-state change.
  3. Pause or replace
    Keep this PR paused or replace it only if a fresher branch can preserve the same narrow fix with durable proof.

Next step before merge

  • [P1] No narrow automated code repair remains; the remaining blocker is inspectable real behavior proof or a maintainer proof override before merge.

Maintainer decision needed

  • Question: Should this PR wait for inspectable live Gateway-to-TUI proof, or should a maintainer explicitly override the proof gate based on the existing narrative and CI?
  • Rationale: This is an external non-doc PR and the current live proof is a narrative rather than inspectable output, so automation cannot safely treat it as proof-sufficient without a human override.
  • Likely owner: steipete — They are assigned on the PR and authored the latest rewrite/proof comment on the exact head.
  • Options:
    • Attach inspectable live proof (recommended): Add redacted terminal output, a recording, logs, or a linked artifact showing an external Gateway client message appear in an already-running TUI before merge.
    • Override proof gate: A maintainer may explicitly accept the existing narrative and CI as enough proof, but that leaves no durable artifact for later reviewers.
    • Keep paused: Leave the PR open and out of merge queues until contributor or maintainer proof is attached and ClawSweeper re-reviews the same head.

Security
Cleared: Cleared: the diff is limited to TUI runtime handling and tests, with no workflow, dependency, lockfile, secret, or package execution changes.

Review details

Best possible solution:

Land the narrow TUI session.message consumer after attaching redacted Gateway-to-TUI terminal proof; keep broader cross-channel observe behavior in #40678 separate.

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

Yes, at source level: current main broadcasts displayable transcript appends as session.message, while the TUI subscribes to session events but does not dispatch that event. I did not run a live terminal reproduction in this read-only review.

Is this the best way to solve the issue?

Yes, this is the narrow owner-boundary fix because it consumes the existing Gateway event contract in TUI without adding protocol, config, provider, or plugin surface. It is not merge-ready until inspectable real behavior proof is attached or explicitly overridden.

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

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

Label justifications:

  • P2: This is a normal-priority TUI live transcript bug fix with a restart/reload workaround and limited blast radius.
  • merge-risk: 🚨 session-state: The PR changes how the running TUI refreshes selected-session transcript state from Gateway events.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦞 diamond lobster.
  • 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/comment describe a live E2E run, but reviewers still need inspectable redacted terminal output, logs, recording, or a linked artifact showing the after-fix Gateway-to-TUI path. 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

PR surface:

Source +92, Tests +317. Total +409 across 7 files.

View PR surface stats
Area Files Added Removed Net
Source 4 126 34 +92
Tests 3 318 1 +317
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 7 444 35 +409

What I checked:

  • Repository policy: Root policy and scoped TUI guidance were read; the TUI guide says fake-backend PTY tests do not prove Gateway transport or live streaming, which affected the proof assessment. (src/tui/AGENTS.md:4, e024eacf176c)
  • Current main dispatcher gap: Current main dispatches chat, chat.side_result, agent, and sessions.changed events, but has no session.message branch. (src/tui/tui.ts:1552, e024eacf176c)
  • Gateway event contract exists: Current main broadcasts displayable transcript updates as session.message with session key, optional agent id, message metadata, and session snapshot data. (src/gateway/server-session-events.ts:212, e024eacf176c)
  • PR wires the missing event: The PR head adds handleSessionMessageEvent to the TUI event handler destructuring and dispatches evt.event === "session.message" to it. (src/tui/tui.ts:1567, b0253c29756b)
  • Serialized reload path: The PR queues run-less transcript invalidations through the existing serialized history reload machinery and defers session-message refresh while local run state is active. (src/tui/tui-event-handlers.ts:792, b0253c29756b)
  • Stale selection guard: The PR captures the selected session and agent before history and session-info reads, then drops results if selection changes before the backend response applies. (src/tui/tui-session-actions.ts:125, b0253c29756b)

Likely related people:

  • steipete: Assigned on the live PR, authored the latest rewrite/stabilization commits on the branch, and current-main blame also touches the surrounding TUI dispatcher/session handler area. (role: likely follow-up owner; confidence: high; commits: b0253c29756b, 42527bbf54b3, e5798e547770; files: src/tui/tui.ts, src/tui/tui-event-handlers.ts, src/tui/tui-session-actions.ts)
  • xialonglee: Authored the merged sessions.changed history reload/dedupe work that shares the serialized TUI history invariant this PR extends. (role: recent adjacent TUI session-state contributor; confidence: medium; commits: 6192b037bbb5; files: src/tui/tui-event-handlers.ts, src/tui/tui-session-actions.ts, src/tui/tui-event-handlers.test.ts)
  • vincentkoc: Authored the earlier closed PR that attempted the same TUI live transcript subscription direction for the canonical issue. (role: prior same-root repair author; confidence: medium; commits: 9421edb6e689; files: src/tui/gateway-chat.ts, src/tui/tui-event-handlers.ts, src/tui/tui.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.
Review history (3 earlier review cycles)
  • reviewed 2026-07-01T03:25:02.192Z sha 3c804a7 :: needs real behavior proof before merge. :: [P2] Guard in-flight live history reload results
  • reviewed 2026-07-07T06:13:24.356Z sha 42527bb :: needs real behavior proof before merge. :: [P2] Return a typed history result from the mock
  • reviewed 2026-07-07T06:51:48.793Z sha b0253c2 :: needs real behavior proof before merge. :: none

@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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jun 24, 2026
@clawsweeper clawsweeper Bot added merge-risk: 🚨 session-state 🚨 May lose, corrupt, stale, or mis-associate session, agent, or context state. and removed merge-risk: 🚨 message-delivery 🚨 May drop, duplicate, misroute, suppress, or wrongly target messages. labels Jun 27, 2026
@steipete steipete self-assigned this Jul 7, 2026
@steipete

steipete commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Rewrite-ready proof — intentionally unmerged

Rewrote this PR on the current TUI architecture instead of landing the original parallel reload coordinator.

Why the rewrite

  • The original event consumer duplicated the newer run-aware history state machine.
  • A history/session-info request started for an old selection could still repaint the next selected session after it completed.
  • A displayable local final needs to remain visible until terminal persistence is authoritative, regardless of whether idle or persistence is observed first.

The rewritten head b0253c29756bc7fca22a09a7bc495ef5f03de654 now has one serialized history queue for run-owned and run-less invalidations, defers external refreshes across active/pending/optimistic local runs, releases only after both idle and terminal persistence, and discards async results whose captured session/agent no longer matches the selection.

Evidence

  • Sanitized AWS Crabbox cbx_3c73747f4601, run run_c23cbeab4a86: original event-handler/session-action baseline, 124 tests passed.
  • Blacksmith Testbox tbx_01kwxhf00awefzyke5p0phz686: rewritten event-handler/session-action suites, 141 tests passed.
  • Same Testbox: pnpm check:test-types passed and the complete real local PTY suite passed, 9/9.
  • Source-blind live E2E: a public TUI ran against an isolated Gateway; a second public Gateway client called sessions.send; the unique marker appeared in the already-running transcript without restart, direct state mutation, or test-only event injection.
  • Regression coverage includes matching/non-matching session and agent scope, burst coalescing, active-run deferral, both idle/persistence orderings, run-less invalidation, and stale selection results.
  • Fresh structured autoreview: clean, no actionable findings, confidence 0.84.
  • Exact-head hosted CI: run 28846887328.
  • Native review artifacts: READY, zero findings. OPENCLAW_TESTBOX=1 scripts/pr prepare-run 96252 passed exact-head hosted gates.

No protocol, subscription, config, storage, provider, or plugin SDK changes. This PR is intentionally left open and unmerged per maintainer request.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. labels Jul 7, 2026
@openclaw-barnacle

Copy link
Copy Markdown

This assigned pull request has been automatically marked as stale after being open for 27 days.
Please add updates or it will be closed.

@openclaw-barnacle openclaw-barnacle Bot added the stale Marked as stale due to inactivity label Jul 21, 2026
steipete added a commit that referenced this pull request Jul 27, 2026
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]>
@steipete

Copy link
Copy Markdown
Contributor

Thank you for tracking down the missing live session-message handling. This is now fixed on main by #114443 (ac6009e), which folds the same Gateway event into the canonical, agent-scoped TUI history path and adds real two-client Gateway PTY coverage. Your investigation is credited in the merged PR and you are recorded as a commit co-author. Closing this PR as superseded by the landed fix.

@steipete steipete closed this Jul 27, 2026
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

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: M stale Marked as stale due to inactivity 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

2 participants