Repository navigation
fix(gateway): stop session terminals when resetting an Incognito session - #159207
Conversation
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
Codex review: needs maintainer review before merge. Reviewed September 26, 2026, 9:38 PM ET / September 27, 2026, 01:38 UTC (Revision 2). ClawSweeper reviewWhat this changesThe branch drains an Incognito session’s conversation-owned terminals before deleting its state, adds a Gateway RPC regression test, and documents the behavior. Merge readiness✅ Ready for maintainer review Current main still deletes Incognito sessions without stopping their session-owned terminals, so this PR remains useful. The repository admin has approved the bounded repair; broader lifecycle convergence is tracked separately. Priority: P1 Review scores
Verification
How this fits togetherThe Gateway receives session reset requests and coordinates cleanup with the terminal manager and session store. A successful Incognito reset deletes the session and notifies clients. flowchart LR
A[Incognito reset request] --> B[Gateway reset lifecycle]
B --> C[Exact session terminal drain]
C --> D{Terminals exited?}
D -- Yes --> E[Delete session state]
D -- No --> F[Keep session and report error]
E --> G[Notify clients]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +61, Tests +46, Docs +2. Total +109 across 4 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Keep the exact-session terminal drain in the reset lifecycle and handle the wider controller, worker, and worktree teardown in #159304. Do we have a high-confidence way to reproduce the issue? Yes. Open an Incognito session’s terminal and call Is this the best way to solve the issue? Yes for the terminal leak. The patch uses the existing exact-owner terminal manager and preserves reset hook ordering; broader teardown has its own tracked issue. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 9c2335a2d07e. LabelsLabel changes: No label changes. Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
Incognito reset deleted ephemeral session state without draining its conversation-owned terminals. Reuse the exact-session terminal fence and exit drain before deletion, preserve the row on timeout, and release the fence on every outcome. Extract the deletion phase to respect the reset service line-cap ratchet and document the terminal lifetime. Validation on Blacksmith Testbox: regression failed on unmodified 9883b72 because the PTY was not killed; final 11 owner suites passed 136 tests. Single-worker regression file passed 2 tests in 21.38s (23.61s wrapper wall). check-changed passed. Independent review found no actionable P0-P2 issues.
dc4c1b3 to
87933ba
Compare
|
Merged via squash.
|
…aw#159207) Incognito reset deleted ephemeral session state without draining its conversation-owned terminals. Reuse the exact-session terminal fence and exit drain before deletion, preserve the row on timeout, and release the fence on every outcome. Extract the deletion phase to respect the reset service line-cap ratchet and document the terminal lifetime. Validation on Blacksmith Testbox: regression failed on unmodified 73cbb5d because the PTY was not killed; final 11 owner suites passed 136 tests. Single-worker regression file passed 2 tests in 21.38s (23.61s wrapper wall). check-changed passed. Independent review found no actionable P0-P2 issues. Co-authored-by: Peter Steinberger <[email protected]>
What Problem This Solves
Incognito sessions promise that nothing outlives the conversation. Calling
sessions.reseton an Incognito session deletes it (row, transcript, delivery artifacts), but a terminal opened for that session kept running: the PTY process stayed alive and the existing connection could still send input to it after the session was gone. Delete and archive already stop session-bound terminals; only the Incognito reset branch skipped that.Why This Change Was Made
The Incognito branch of
performGatewaySessionReset(src/gateway/session-reset-service.ts) went straight todeleteSessionEntryLifecyclewithout the terminal drain thatsessions.delete/archive run throughsessions-lifecycle-drain.ts. It now fences the exact session's terminals (beginAgentSessionDrainfor the session key, session id, and agent), waits for them to exit withinSESSION_WORK_ADMISSION_DRAIN_TIMEOUT_MS, then runs thebefore_resetplugin hook and the unchanged deletion, and releases the drain on every path. If terminals do not drain in time, the reset fails with a typedUNAVAILABLEerror and the session is kept. The sequence lives insrc/gateway/session-reset-incognito.tsbecausesession-reset-service.tsis at its line-cap ratchet.Design question for the maintainer
We tried routing Incognito reset through the canonical delete drain instead. It breaks an existing reset contract: that drain clears queues before reset's internal hook can revoke caller authority (one ordering test fails). While comparing the two paths, the Incognito reset turned out to differ from delete in more than terminals:
sessions.deletebefore_reset, keyed notificationOrdinary (non-Incognito) reset keeps its session id, and a control test confirms its terminal stays reachable through the same owner, so no orphan was demonstrated there. Converging Incognito reset with delete (full controller/worker drains, worktree removal) is a lifecycle design change, tracked in #159304.
User Impact
Resetting an Incognito session now also stops its terminals, instead of leaving a live shell attached to a deleted session.
Evidence
src/gateway/server.sessions.archive-terminal.test.ts: new Incognito reset case fails onmain(oldPty.killedstays false) and passes; archive control unchanged.node scripts/check-changed.mjspassed.Production LOC: +90 / −29 (includes moving the Incognito deletion sequence into its own file for the line-cap ratchet). Tests: +112 / −66. Docs: +2.