Skip to content

fix(tui): preserve run and session ownership across async events - #130147

Merged
steipete merged 2 commits into
mainfrom
codex/tui-terminal-error-events
Aug 26, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/tui-terminal-error-events

Conversation

@steipete

@steipete steipete commented Aug 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

The TUI could silently discard an embedded provider failure or final response that arrived before its submit acknowledgement after a previous run had completed. That left the editor stuck in sending and hid actionable provider diagnostics such as xAI account spending limits.

Two related asynchronous ownership gaps also allowed an old session to affect a newly selected session: an unnecessary nested session-patch await could apply private model/settings metadata after an agent switch, and a terminal send acknowledgement could overwrite the new session's status or display the previous session's error after history finished loading.

Why This Change Was Made

An embedded backend legitimately emits chat events without the Gateway's per-run payload sequence. The TUI orphan-event fence only recognized acknowledged submissions, overlooking its already-authoritative ownership of the exact provisional local run. Recognize that run only when local mode, pending phase, exact run ID, local ownership, and existing session/agent checks all agree, then preserve that ownership through stream registration.

Move session patching into its single actual owner so one captured session incarnation covers the RPC, immediate setting application, post-patch refresh, and error handling. Revalidate that same incarnation after terminal-ack history loading. This continues the ownership work from #129681 and #129810 while removing the nested helper that created the cross-agent microtask race.

The first hosted run also exposed two existing shard-sensitive CI failures unrelated to the TUI: agent-deletion tests replaced the whole filesystem-safety module while mocking only trash movement, and a Gateway restart test polled lane drainage before the actual delegated approval promise had settled. Preserve the original filesystem exports in both test mocks, and await authoritative approval completion before checking that its lane drains. Both are test-only fixes for the exact failed shards; production behavior is unchanged.

User Impact

  • Embedded provider failures and early final responses remain visible, and the prompt becomes usable again instead of getting stuck in sending.
  • Switching agents or sessions cannot leak another session's private provider/model diagnostic, apply its model/settings metadata, or overwrite the new session's activity state after asynchronous work resumes.
  • Remote unsequenced events, unowned local events, and events from another session remain rejected.
  • Production LOC: +17/-23 (net -6); tests: +190/-7.

Evidence

Red-first owner regressions reproduced all three failure families before the repair: unacknowledged embedded errors/finals remained invisible with a stuck pending submit; terminal error, timeout, and ok acknowledgements mutated a replacement session after history awaited; nested settings patches and delayed refresh failures leaked across agents. Existing xAI real-terminal coverage also failed on unmodified current main.

After the fix:

node scripts/run-vitest.mjs src/tui/tui-command-handlers.test.ts src/tui/tui-event-handlers.test.ts
# 2 files passed; 404 tests passed

node scripts/run-vitest.mjs run --config test/vitest/vitest.tui-pty.config.ts
# 4 files passed; 76 real PTY tests passed
# Includes: preserves xAI account limit errors in terminal output
# Includes: ignores delayed aborts and streamed events from the previously selected session

node scripts/run-vitest.mjs src/commands/agents.delete.test.ts src/commands/agents.delete.workspace.test.ts
# 2 files passed; 27 tests passed

node scripts/run-vitest.mjs src/gateway/server-methods/system-agent.test.ts
# 1 file passed; 26 tests passed

env -u OPENCLAW_TESTBOX node scripts/check-changed.mjs
# full changed-file gate passed

.agents/skills/autoreview/scripts/autoreview --mode uncommitted
# clean; no accepted/actionable findings

Direct production-module replay changed from {"phase":"sending","visible":false,"pending":"sending"} to {"phase":"sending","visible":true,"message":"run error: monthly spending limit","pending":null}. Negative owner regressions separately prove unrelated local runs, remote unsequenced events, and foreign-session events stay fenced.

The affected interface is a terminal, so the running-surface proof is the authenticated real PTY suite and its rendered spending-limit assertion rather than a graphical screenshot.

@clawsweeper

clawsweeper Bot commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Aug 26, 2026
@steipete
steipete marked this pull request as ready for review August 26, 2026 13:45
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime commands Command implementations labels Aug 26, 2026
@steipete
steipete merged commit 67dc607 into main Aug 26, 2026
199 checks passed
@steipete
steipete deleted the codex/tui-terminal-error-events branch August 26, 2026 14:24
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Aug 27, 2026
…nclaw#130147)

* fix(tui): preserve run and session ownership across async events

* test: stabilize filesystem mocks and gateway restart completion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands Command implementations gateway Gateway runtime maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant