Repository navigation
fix(core): report removed running shells as killed - #56982
Conversation
There was a problem hiding this comment.
The fix works. I reproduced it with a temporary test against real processes (a plain sleep and one that ignores SIGTERM): removing a running shell gave created → deleted → exited on dev and created → deleted with this change. The core shell, retention, cleanup, session-shell and tool-shell tests pass, and packages/core typechecks cleanly.
The ownership check is the right guard: removeCommand already fails the waiters, stops the timer, deletes the output file and publishes the deletion, so skipping the outcome step loses nothing. It also keeps removed IDs out of the retention queue.
Public API: the event schemas, HTTP API and SDK are unchanged. The only change is the event sequence: a shell removed while running no longer emits shell.exited. Outside subscribers that waited for shell.exited after removing a shell should treat shell.deleted as the final event.
No concerns.
Problem
Removing a running shell published
shell.deleted, and the killed process later produced ashell.exitedfor the same ID. The two raced: in some runsexitedarrived afterdeleted, in others before. The removed ID was also pushed onto the retention queue, where it took one of the 25 exited-shell slots and could evict a real finished shell.Change
Every shell now reports exactly one
shell.exited, always before anyshell.deleted:killedalready exists inShell.Statusand was previously unused.Shell.resultalready reports a removed shell askilled, so the event now matches it.In-repo clients are unaffected: the shared client store drops the shell on either
exitedordeleted, and nothing in core subscribes to these events. External subscribers now seeexited(killed)for removed running shells, in a stable order.Out of scope
&jobs outlive the shell that started them.Verification
Event stream per lifecycle, from a local scratch subscriber against real processes:
devexited, in either orderdev(3499 pass; the same 7 bash-syntax failures on macOS also fail ondev).bun typecheckinpackages/coreis clean.