Skip to content

fix(tui): send messages to the correct agent after roster changes - #126820

Merged
steipete merged 1 commit into
mainfrom
codex/autoqa-tui-agent-selection-tuple-20260820
Aug 20, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/autoqa-tui-agent-selection-tuple-20260820

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where Terminal UI users could send their next message to the wrong agent after the selected agent disappeared from a refreshed Gateway roster. The visible agent changed to the replacement, but the selected session key, session ID, active run, pending prompt, and transcript projection still belonged to the removed agent.

Why This Change Was Made

The existing canonical synchronous session transition is now shared by explicit session selection and agent-roster fallback. The replacement agent's canonical session is resolved before any selected identity changes, then the complete previous session lifecycle is retired together. Global sessions retain their literal global key while updating their owner, already-valid agent selections stay untouched, and the existing reconnect path remains the sole history-loading owner.

Production delta is +48/-42 (net +6): most changed lines move the existing transition into its canonical shared owner; the small net increase passes the explicit replacement agent into the existing resolver and avoids a transient mismatched agent/session tuple. No Gateway protocol, authorization, configuration, persistence, or public API changes.

User Impact

When an agent disappears, the Terminal UI selects the surviving agent's actual session before accepting further messages. Stale runs, optimistic drafts, transcript rows, session-specific overrides, and old session IDs cannot bleed into the replacement conversation; global sessions and unchanged agents keep their existing behavior.

Evidence

  • Exact reviewed head: be8e100abe1ede2dd38a21ce78ec32f1acd9e0fd.
  • Regression-first proof: three owner-boundary cases failed on unchanged production (canonical per-agent key, complete per-sender identity, and complete global-session identity), then passed after the shared-owner repair; an unchanged valid selection remains untouched.
  • 320 passing tests across real TUI session actions, canonical resolver behavior, and message-command routing.
  • OPENCLAW_VITEST_MAX_WORKERS=1 OPENCLAW_VITEST_FS_MODULE_CACHE=0 node scripts/run-vitest.mjs src/tui/tui-session-actions.test.ts src/tui/tui.test.ts src/tui/tui-command-handlers.test.ts --configLoader runner
  • Three passing real PTY Terminal UI scenarios cover session mode ownership, reconnect run reconciliation, and approval-before-history ordering; unrelated scenarios were intentionally filtered.
  • OPENCLAW_VITEST_MAX_WORKERS=1 OPENCLAW_VITEST_FS_MODULE_CACHE=0 node scripts/run-vitest.mjs run --config test/vitest/vitest.tui-pty.config.ts --configLoader runner -t 'keeps session modes scoped while trace changes and delivery stays process-owned|reconciles active and terminal runs after reconnect history|refreshes pending approvals before loading history'
  • Max-lines and assertion-safety ratchets, focused lint, formatting, and an independent full-owner review all passed.
  • Fresh authenticated full-branch Codex review: clean, with no accepted or actionable findings.
  • Terminal visual proof: the real PTY run emitted inspected behavior evidence confirming source modes were visible, replacement modes were cleared, reconnect state reconciled, and delivery stayed correctly owned.

AI-assisted.

@clawsweeper

clawsweeper Bot commented Aug 20, 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 20, 2026
@steipete
steipete marked this pull request as ready for review August 20, 2026 19:49
@steipete
steipete merged commit 97c0455 into main Aug 20, 2026
291 checks passed
@steipete
steipete deleted the codex/autoqa-tui-agent-selection-tuple-20260820 branch August 20, 2026 20:04
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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

Labels

maintainer Maintainer-authored PR size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant