Repository navigation
fix(tui): isolate replacement sessions from stale async results - #130227
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed August 26, 2026, 1:13 PM ET / 17:13 UTC. ClawSweeper reviewWhat this changesThe PR prevents stale asynchronous picker, refresh, transcript, and local side-answer results from affecting a replacement terminal session. Merge readinessKeep open: this maintainer-labeled PR makes a focused TUI session-incarnation repair and has no actionable patch defect from review; it still needs exact-head CI completion before merge. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: FAIL (failed) — step 1 Assertions:
How this fits togetherThe terminal UI receives Gateway session/chat events and asynchronous picker or refresh results, then projects them into the selected conversation. This change decides whether each result still belongs to that exact session incarnation before rendering or mutating state. flowchart LR
A[Gateway session and chat events] --> B[TUI event handlers]
C[Async picker and refresh requests] --> D[Session-incarnation check]
B --> D
D -->|current owner| E[Chat log and session state]
D -->|retired owner| F[Discard stale result]
E --> G[Terminal UI]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +6, Tests +170. Total +176 across 7 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Technical reviewBest possible solution: Keep one session-incarnation invariant at the asynchronous TUI owners, with the supplied same-key replacement regressions protecting it, then merge after exact-head checks are green. Do we have a high-confidence way to reproduce the issue? Yes—source inspection shows current main checked only session key and agent for these picker and refresh paths, while the PR’s same-key replacement cases exercise the missing incarnation boundary. Is this the best way to solve the issue? Yes—the generation and opaque-session identity checks are placed at the asynchronous producers before their UI mutations, rather than attempting to clean stale state after it is rendered. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 67a310b2c6ba. 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
|
|
Maintainer validation of The root cause was partial session ownership at deferred UI boundaries: a session key can survive reset while its opaque session ID and lifecycle generation change. This repair uses the existing incarnation owner for picker work, the canonical generation for refreshes, and checks event ownership before transcript projection or local side-answer display. It removes the weaker picker key-only checks and preserves first identity binding, newer authoritative snapshots, same-session out-of-order prompts, and Gateway peer answers. Production LOC is +33/-27 (net +6); tests and fixture support are +179/-9. The small production increase supplies the missing ownership checks without adding a second lifecycle or configuration surface. Each new regression was observed failing against pre-fix source. Seven focused owner/test-support files pass; the complete fake-backend real-PTY suite passes all 76 cases; the full changed-file gate passes; and independent Codex autoreview has no actionable findings. The newer main change in #130263 affects terminal acknowledgement normalization, not these picker/refresh/event ownership decisions; a synthetic merge with current main is conflict-free. Two review-evidence clarifications: the bot's PTY run stopped at its 30-second command budget, not a failing product assertion; the complete local PTY run finished successfully. The reported vector/embedding persistence change is a false positive on synthetic transcript identity metadata in a test. There is no storage, schema, vector, or migration change in this PR. These are real-terminal/fake-backend and owner-boundary proofs, not authenticated provider or Gateway-transport proof; no screenshot or recording is attached. Exact-head CI run 32991074340, attempt 2 is green. Its first attempt failed because |
|
Merged via squash.
|
What Problem This Solves
Fixes an issue where users resetting or replacing a terminal session could see prompts, side answers, picker failures, or model/session selections from the previous session reappear in the replacement. An overlapping session refresh could also resurrect the old opaque session ID, and the existing account-limit PTY check could flake because its fake Gateway emitted an invalid event.
Why This Change Was Made
Session ownership is the exact agent, session key, opaque session ID, and lifecycle generation; a key alone is not sufficient after an in-place reset. Reuse the existing session-incarnation owner for asynchronous model/session picker requests, selections, and failures; fence session-info refreshes with the canonical lifecycle generation; reject retired transcript snapshots before projection or rendering; and accept local side answers only while their locally owned run remains alive. The PTY fake Gateway now includes the sequence required by the actual Gateway chat-event contract.
User Impact
Terminal sessions no longer leak an old conversation's prompt, side answer, or error into its replacement, and stale pickers cannot silently change the replacement session. Legitimate first-session identity binding, newer authoritative session adoption, cross-client Gateway answers, and normal local
/btwreplies remain intact.Evidence
main: same-key model/session picker mutations, stale catalog/session-list openings, delayed picker failure disclosure, retired/btwdisclosure, retired transcript disclosure with older/equal/missing timestamps, and stale refresh success/failure.ChatLog, and an already occupied history-reload coalescer.node scripts/run-vitest.mjs src/tui/tui-command-handlers.test.ts src/tui/tui-event-handlers.test.ts src/tui/tui-session-actions.test.ts src/tui/tui-session-run-coordinator.test.ts src/tui/tui-session-events.test.ts src/tui/tui.submit-handler.test.ts src/tui/tui-pty-harness-assertion-test-support.test.tsnode scripts/run-vitest.mjs run --config test/vitest/vitest.tui-pty.config.ts— four real-PTY files, 76 tests passed.env -u OPENCLAW_TESTBOX node scripts/check-changed.mjs— all changed-file formatting, core/test typecheck, lint, max-line ratchet, dependency, architecture, database, and import-cycle gates passed.Follow-up: task-suggestion and plugin-approval asynchronous notices deserve a separate session-incarnation audit.