Repository navigation
fix(sdk): kill a dead runtime's tool shells before the retry - #449
Open
ChrisKrawczyk wants to merge 5 commits into
Open
ChrisKrawczyk wants to merge 5 commits into
ChrisKrawczyk wants to merge 5 commits into
Conversation
A tool shell runs in its own session and outlives its Copilot runtime. When the runtime exited unexpectedly, the teardown asked the dead runtime for its task list, failed, and left the shells and their daemons running beside the retry. Each warm session now lists its shells again on session.background_tasks_changed while its runtime runs, binding each shell's identity and own session or process group while the runtime still sits between the shell and the worker. At the runtime's exit, SessionManager kills those shells and what is left of their scopes. A teardown of a session whose runtime is gone kills them instead of calling the dead runtime. A shell already bound keeps its binding, so the process table is read only for new shells. Fixes #385 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
- Kill a lost runtime's shells from the exit listener, before the retry, and confirm each kill; an unconfirmed kill is retried at the next teardown. - Bind nothing after the runtime is lost: a list that finishes after the exit cannot rescope a shell to a reused PID or group. - Route workspace release, eviction, dehydrate and destroy through one shell-ending path that kills directly when the runtime is already gone. - Trace the exit report (tracked, ended, unbound, unconfirmed, stale). - Add unit tests for these paths and a real-CLI test that kills the runtime mid-turn with a sync and a detached shell and checks all four writers stop before the retry reaches the model. - Narrow the docs to what is covered. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
A kill is confirmed only when every process it had to check was signalled or proven gone; a partial /proc table, a failed read or signal, or a group signal is no longer proof. A late task list from a teardown or shutdown binds and cancels nothing. Scope tries stay bounded when the process table cannot be read. The exit trace tells an empty listing from none and warns when no retry follows. Opt-in fake process host modes test each case. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
- Every individual signal and scope-leader check reads its target again right before acting (/proc, or ps -p elsewhere), never from an earlier table, so a pid that changed hands since the listing is spared. This covers the new per-member group sweep and the older ps tree kill. - Test the Linux host's /proc error mapping (ENOENT gone, EACCES/EPERM hidden, EIO unknown) and which rows mark a table partial. - A runtime exit during a worker shutdown no longer reports its unconfirmed shells as never retried: the shutdown's own kill also tries them. Docs say the same. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
Every signal now reads its target again, and on macOS/BSD that read runs `ps`, which blocks the event loop. A read must not start once a kill's deadline has passed, and a `ps` read gives up at the deadline. - runPs caps its timeout by the time left and runs no `ps` after the deadline; ProcessHost.snapshot/read take the deadline. - signalProcess, killTree, the scope sweep's leader and table reads and killListedShellsEach check the deadline before each read. - cancelBackgroundTasks reads no tree table once its budget is spent. - The runtime-exit report warns when a listed shell could not be bound: it was not signalled and may still run. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #385.
What
When a Copilot runtime exits unexpectedly, for example after an out-of-memory kill, its sessions' background shells and the daemons they started kept running beside the retry. Teardown asked the runtime to list them, and the runtime was gone.
Now each session lists its shells while its runtime runs (on
session.background_tasks_changed) and records each shell's process scope. When the runtime exits, the worker SIGKILLs those shells and whatever is left in their session or process group, before a retry can start. Each kill is confirmed; an unconfirmed one is retried at the session's next teardown. Teardown of a session whose runtime died uses that list and sends nothing to the dead runtime.Limits
@github/copilot-sdk:stop()or an unexpected exit should end the runtime's process tree.Review
Reviewed by five specialists on different models over three debate rounds. Fixed: the docs promised more than the code covers; a listing after the exit could bind a reused PID; kills were not confirmed; teardown paths differed; no real-CLI test killed the runtime mid-turn. Deferred:
tasks.list.Tests
workflow-child-runtimeR9, whose 4 s window is too short under full-suite load. It passes alone and is fixed in test: widen R9's receive window so a loaded run can't end the parent first #451.npm run lintandnpm run check:privacypass.No TLA+ update: the orchestrations, hydration and dehydration are unchanged. This is worker-side process cleanup at a runtime exit.
The CHANGELOG
## Unreleasedheading conflicts trivially with #447; whichever merges second needs a rebase.