Skip to content

fix(sdk): never reuse a dead Copilot runtime (#329) - #376

Open
ChrisKrawczyk wants to merge 13 commits into
mainfrom
fix/329-dead-runtime
Open

ChrisKrawczyk wants to merge 13 commits into
mainfrom
fix/329-dead-runtime

Conversation

@ChrisKrawczyk

@ChrisKrawczyk ChrisKrawczyk commented Nov 24, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #329

When the Copilot runtime child behind a pooled client dies (an OOM kill, for example), the turn now settles within moments with a connection-closed error, the dead warm session and the dead client are dropped, and the existing connection-closed retry resumes from the last committed snapshot on a fresh runtime, on any worker. No orchestration version and no migration.

How a dead runtime is detected

@github/copilot-sdk 1.0.34 has no public exit hook or state getter (onDisconnected and state are internal), and a dead runtime emits no session.idle to a running turn. The fix uses only public SDK and Node APIs:

  • copilot-runtime-monitor.ts subscribes to Node's public child_process diagnostics channel. An AsyncLocalStorage context around each client.start() claims the --headless --stdio child that the start spawns, so the monitor binds exactly that runtime to that client.
  • The monitor watches the child's exit and records { pid, code, signal, requested, duringStartup }. An exit after startup that PilotSwarm did not request is logged with the pid, exit code and signal; the client leaves the pool at once and is force-stopped in the background.
  • Every turn races its runtime's exit. The turn returns Copilot runtime exited (pid …, code …, signal …) during the turn: Connection is closed.
  • ensureClient never hands out a lost client, and a warm session whose runtime has exited is dropped at its next turn.
  • A transport-loss turn (runtime exit; closed, disposed or not-connected connection; a session the SDK marked disconnected) carries a typed transportLoss flag; nothing downstream matches message text. It drops its warm session and skips the snapshot commit. The turn sentinel stays dirty and the worker emits session.snapshot_unpublished { reason: "transport_loss" }, so the retry hydrates the last commit.
  • No legacy publish path archives a dir that holds an uncommitted turn. _legacyPublishBlocker runs before the dehydrate activity, the safety checkpoint and the eviction sweep. A blocked dehydrate drops the warm handle, keeps the dir and the store, and records session.snapshot_unpublished { reason: "dirty_turn" } and the unpublished dehydration result; the sweep deletes a blocked dir instead of publishing it.
  • The inline control tools stop before their next external step after the turn's activity attempt ends (control-bridge-fence.ts): sub-agent and agent-session management, cross-session messages, model and context changes, the check_agents memo and the canvas writes. The Workflow tools are not fenced yet. Worker-hosted tool handlers get an at-least-once contract: PilotSwarmToolInvocationContext.turnSignal aborts when the attempt is lost, and a handler must tolerate a retried turn calling it again.
  • A lost or stopped first turn records freshChain with its session.snapshot_unpublished, so the next turn on another worker starts a fresh conversation instead of taking the lossy hand-off.
  • Each unexpected exit increments pilotswarm.copilot_runtime.exits. If the monitor binds no runtime child to a start (Node or the SDK changed how the child is spawned), the worker logs a one-time warning and counts outcome="unclaimed" instead of silently falling back to the 300 s watchdog.
  • shutdown marks its runtimes as stopping, so a requested stop is not reported as a loss.

The points in the issue

Point Outcome
_getOrCreateUnlocked returns a warm entry without checking its client Fixed: a warm session on a lost client is dropped and the session resumes on a fresh client.
isLiveSessionLostErrorMessage matches only "Session not found" Connection is closed., Connection is disposed., a not-connected connection and a disconnected SDK session now invalidate the warm session through the transport-loss check. They keep the connection-closed retry; they do not take the "session lost" path.
runTurnCommit clears the sentinel on a transport-loss error Fixed: the commit is skipped and the sentinel stays dirty, as handleConnectionClosedRetry assumes.
On one worker, the lossy hand-off resets retryCount and may loop Confirmed, not changed here: turn.ts 165-213 resets retryCount to 0 after a lossy hand-off, so a runtime that dies on every attempt is retried without end. Changing it needs an orchestration version; tracked in #384. With this fix a death no longer repeats by itself, because each retry starts a fresh runtime.

Tests

  • test/local/runtime-loss.test.js (the issue's test): one worker, a session with no workspace, SIGKILL of the runtime child mid-turn. The child's pid is read from /proc, not from the monitor, so the test fails on main. The turn settles within seconds, the failed attempt returns a transport loss, the retry commits on a fresh runtime with the committed history, and there is no session.lossy_handoff. A second case kills a pooled runtime while co-tenant warm sessions are idle.
  • test/local/turn-lifecycle.test.js: a lost turn is not committed and its retry hydrates the last commit; the sweep, dehydrate and checkpoint never publish a dirty dir (each fails on deb02556, the code before the guard); an error that only quotes a disconnect phrase still commits.
  • test/local/turn-control-run-turn.test.js: after a lost or a stopped first turn, the next turn on another worker starts fresh with no lossy hand-off. Two controls keep the lossy replay: a record without freshChain, as an older worker writes it, and a failed read of the records. The stopped case fails with its acceptance reverted.
  • test/unit/copilot-runtime-monitor.test.mjs: start claims, deferred exits during a start, requested exits, unclaimed starts, and which errors count as a transport loss (not the inactivity watchdog).
  • inline-control-tools.test.js (a 22-row table: every fenced tool, after the attempt ends), tool-binding-reads.test.js and orchestration-composition-rebuild.test.js: the control-bridge fence, the tool turnSignal, and a capture after the warm parent's runtime died.
  • test/local/pg-migrator-session.test.js: see "Other commits" below.

Formal model

docs/formal/session-orchestration/RuntimeLoss.tla, TLC 2.19:

  • rl1 (bound to f4ef5cd8, CORRESPONDENCE-f4ef5cd8-rl1.md): 15 of 15 as expected. The issue's rules hold, five comparison cases show main violating them, four deliberate faults each break their rule, and three witnesses are reached.
  • rl2 (bound to 0b338528, CORRESPONDENCE-0b338528-rl2.md) adds the store's head before the turn and the legacy publish paths: 8 more cases, 23 of 23 as expected. comparison.rl-pr-sweep-publishes and comparison.rl-pr-publish-dirty reproduce review M1 on the pre-guard code; the guarded code passes Inv_NoDirtyPublish with a first turn, a legacy head and a versioned head.

No PARTIAL, no VOID. Both batches re-ran after the rebase onto 0.8.18 (1f6af957, which changes no modelled code; nor do the fence and stopped-turn commits) with the same 23 results and the same distinct-state counts for every PASS case. Bounds: at most 4 attempts and 3 deaths, a death between turns allowed, at most one move to another worker, one session and one turn after a committed one. Not covered: the orchestration's retry count and lossy hand-off (unchanged; #384), a runtime that hangs without exiting, the bounded destroy of the dropped session, a session that returns to the worker it left.

Merge note: #382 also adds cases to session-orchestration. Whichever merges second re-tables them, regenerates cases.json, cases.tsv, tlc-templates.json, SHA256SUMS and the two READMEs, and re-runs RuntimeLoss and TurnCut on the combined code.

Multi-model review

Three models (Claude Opus 5.5, GPT-6.2 Sol and Gemini 4 Argon) reviewed this PR as five specialists in a threaded debate, then a synthesis kept only findings grounded in the diff. The consensus was 2 must-fix, 15 should-fix and 6 to consider. Every must-fix and should-fix finding is fixed in 0b338528, f82e83bb, 2dc3a11d, dc33612a, bc339020 and a62fc500:

  • M1: the eviction sweep could publish a first turn's dirty dir after the activity had reported it unpublished. Fixed by the legacy publish guard above, modelled in rl2.
  • M2: the SIGKILL test could not fail on main. It now reads the runtime pid from the OS.
  • S1–S3: typed transport loss; the same exit is classified the same way whatever its timing; a settle that rejects before exit still drops the warm session.
  • S4–S5: the control-bridge fence (every inline control tool except the Workflow tools) and the tool turnSignal contract.
  • S6–S7: the exit watch no longer cancels the SDK's own reconnect, and an unbound start is reported.
  • S8: the runtime-exit counter.
  • S9: spawn and workflow capture drop a co-tenant warm session whose runtime died.
  • S11: a retry after a turn-0 transport loss records no false lossy hand-off; the orchestration's yield sequence is unchanged.
  • S10–S13: the tests above.
  • S14–S15: the migrator restores settings by their source and records a migration only after restoring them.
  • C5–C6: fixed as well.

One deviation from the review's remedy: dropping a dead warm session keeps its sessionLastTouchedAt, so the sweep still visits its dirty dir.

Left as follow-ups:

C1–C4 (two drop paths with different bounds, hand-copied wording contracts, the bundled migrator fix, co-tenant failures on one death) are recorded in the review and not changed here.

Other commits in this PR

  • The test fix. copilot-runtime-migration "refuses a resume while another process owns an active turn" (from Move to Copilot SDK 1.0.34 and runtime 1.0.112 #364) is racy on main. Runtime 1.0.112 writes inuse.<pid>.lock but does not stop a second process from resuming a session whose active turn is on disk. The test now records the real behavior, and the migration note says PilotSwarm must keep one owner per session itself. The same two hunks are in test(sdk): record that the runtime does not fence a second owner #399 so that main can take them first; after either merges, the other's copy is a no-op.
  • The migrator fix (a488f4a9 and f82e83bb; not part of Warm session reused after copilot-runtime dies: turns stall ~300 s and same-worker retries fail with 'Connection is closed.' #329, but kept here because the full suite needs it). CMS migrations 0036 and 0070 run a session-level SET lock_timeout = '5s'. 0088's CREATE INDEX CONCURRENTLY then failed with "canceling statement due to lock timeout" whenever an older transaction was open. The runner now records the connection's settings and their sources after taking the advisory lock. After each migration it restores every setting the migration changed, before recording the migration. It does not use RESET ALL, so settings from the pool's connect hook survive. test/local/pg-migrator-session.test.js fails without the fix.

Limits and notes

  • A runtime that stays alive but stops answering still settles at the 300 s inactivity watchdog.
  • Records from a pre-fix(sdk): never reuse a dead Copilot runtime (#329) #376 worker have no freshChain, and a failed CMS read gives no proof, so both still take the lossy replay.
  • Runtime 1.0.112 does not fence a second owner of a session; PilotSwarm relies on its own one-owner rule (duroxide affinity, and fix(sdk): run a turn again when its activity lock was lost #382 for a lost activity lock).
  • SDK 1.0.34 restarts a disconnected client by itself on createSession and resumeSession. That would hide a dead runtime behind a reused client object, which is why a lost client leaves the pool before anything else and is never handed out again.
  • The monitor relies on Node's child_process diagnostics channel and the SDK's --headless --stdio arguments. runtime-loss.test.js must stay green on every SDK or Node upgrade; the migration notes say so.
  • To run the integration tests from inside a Copilot CLI session, unset its COPILOT_* variables: a newer host CLI fails the SDK's protocol check.
  • fix(sdk): stop idle pooled Copilot runtimes; end tool shells on every teardown (#331) #377 (stacked on this PR) moves markStopping into its shared _stopClient; Add renewable GitHub credentials using existing client lifecycle #320 should rebase onto that bookkeeping.
  • What @github/copilot-sdk would need for this monitor to go away: a public exit/disconnect hook with the exit code and signal, a state getter, and settling in-flight sends on disconnect.

Validation

All runs were on Linux (Node 24.22.1, PostgreSQL 16), one suite at a time, at d74443b0, rebased on 0.8.18 (1f6af957).

  • CI steps: lint, privacy (0 findings), deploy-scripts (402 passed, 43 skipped of 445), ci-scripts 152/152, sdk-api 63/63, SDK unit 3089/3089, campaign 57/57 and 3/3, app 99/99, 312 of 315 (3 skipped), 2134/2134 and 3/3.
  • Full run-tests.sh: 443 of 443 files; 4579 passed, 0 failed and 26 skipped of 4605, including runtime-loss.test.js (the SIGKILL test).
  • TLC: see "Formal model" above. check-packet.sh and tlc_cases.py check --all pass.
  • Merge of main (fc898539): brings in fix(sdk): workflow scripts run on Node 26 #375 (workflow scripts on Node 26). Its files are byte-identical to fix(sdk): workflow scripts run on Node 26 #375's squash commit; only the CHANGELOG's Unreleased section conflicted, and both entries are kept. No file this PR changes, and no modelled code, is touched.

chkraw and others added 12 commits November 24, 2026 18:10
When the Copilot runtime child behind a pooled client dies (an OOM kill,
for example), @github/copilot-sdk marks its connection disconnected but
emits no idle to a running turn, and it has no public exit hook. The turn
waited for the 300 s inactivity watchdog, the dead warm session and the
dead client stayed cached, and the connection-closed retry reused them.

- copilot-runtime-monitor.ts binds the runtime spawned inside each
  client.start() through Node's public child_process diagnostics channel
  and watches its exit. An exit after startup is logged with its pid,
  exit code and signal; the client leaves the pool and is force-stopped.
- Every turn races its runtime's exit, so it settles within moments with
  "Copilot runtime exited (...) during the turn: Connection is closed."
- A transport-loss turn (runtime exit, closed, disposed or not-connected
  connection, or a disconnected SDK session) drops its warm session and
  skips the snapshot commit, leaving the turn sentinel dirty
  (snapshot_unpublished reason "transport_loss"). The existing
  connection-closed retry then starts a fresh runtime and resumes from the
  last committed snapshot on any worker.
- A warm session whose runtime has exited is dropped at its next turn.

No orchestration version and no migration: the orchestration's yields
and its retry are unchanged.

Fixes #329

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
RuntimeLoss models a pooled client's Copilot runtime child that dies
during a turn or between turns, with mode "fix" (936bd2a2) and mode
"main" (45a01a8). Batch rl1, TLC 2.19 at -workers 2 -Xmx2g, 300 s per
case: 15 of 15 as expected (3 PASS, 4 main comparisons and 1 liveness
comparison fail as predicted, 4 deliberate faults each break their rule,
3 witnesses reached); no PARTIAL, no VOID. Correspondence to 936bd2a2 and
@github/copilot-sdk 1.0.34 in CORRESPONDENCE-936bd2a2-rl1.md.

Not covered: the orchestration's retry count and single-worker lossy
hand-off (unchanged, reported on #329), a runtime that hangs without
exiting, other sessions on the same client.

Refs #329

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
The migration test "refuses a resume while another process owns an active
turn" failed 3 of 5 runs in isolation. Runtime 1.0.112 writes
inuse.<pid>.lock but does not stop a second process from resuming a session
whose active turn is on disk. The test passed only when the resume beat the
first events.jsonl flush and failed with "Session not found".

The test now waits for assistant.turn_start on disk, checks the lock file,
and asserts that the second resume succeeds, so a runtime that adds fencing
is noticed. The migration note describes the real behavior: PilotSwarm's own
one-handle-per-turn rule is what prevents a second concurrent owner.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
The migration runner applies every pending migration on one connection
and then returns it to the pool. CMS migrations 0036 and 0070 run a
session-level `SET lock_timeout = '5s'`, so the limit reached every
later migration in the same run. 0088's CREATE INDEX CONCURRENTLY waits
for every older transaction in the database; under a loaded test suite
it failed with "canceling statement due to lock timeout" (workspace-turn
B10), and an upgrade with an open older transaction would fail the same
way. The pooled connection also kept the 5 s limit for later catalog
queries.

After taking the advisory lock, the runner records the connection's
user-settable settings. After each migration, and before the unlock, it
puts back every setting a migration changed. RESET ALL is not used: it
would also drop settings the pool's own connect hook made (a REPEATABLE
READ default in workflow-semver-reused SDK3-F2). Previous migrations are
unchanged. The new real-PostgreSQL test fails without the fix (the
second migration stops after 100 ms; the CMS run leaves lock_timeout at
5s on the pooled connection) and checks that a connect-hook setting
survives.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
The rebase onto 0.8.17 (ac86a39) moved the bound lines in
session-lifecycle.ts, session-manager.ts and session-proxy.ts (#367 only;
the modelled paths are unchanged). Re-read every line, bind the fix to
261ea6c and mode "main" to ac86a39, and re-run batch rl1: 15 of 15 as
expected with the same state counts as the first run.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
Review M1: the legacy publish paths no longer write a dir that holds an
uncommitted turn. SessionManager._legacyPublishBlocker returns
"dirty_turn" when the turn sentinel is dirty. Dehydrate and the safety
checkpoint then report the snapshot unpublished, and the eviction sweep
deletes the dir instead of archiving it. The last commit stays
authoritative. A versioned commit is never refused.

Review M2, S10, S12, S13: the SIGKILL test takes the runtime pid from
the OS, not from the runtime monitor, and bounds each wait, so it fails
on the base revision. It asserts the failed attempt's result and the
retry's committed outcome. A new test kills a pooled runtime while
co-tenant sessions are idle.

Review S1-S6, S8, S9, S11:
- typed transport-loss classification replaces substring matching of
  free text;
- the same exit is classified the same way around the native-subagent
  settle;
- a settle rejection before the exit is still classified as a
  transport loss;
- inline control-bridge effects are fenced after a transport-loss
  rollback;
- a worker-hosted tool handler is fenced after the settle;
- the exit watch no longer cancels the SDK's own reconnect start;
- runtime deaths are counted (pilotswarm.copilot_runtime.exits) and
  logged with the in-flight and idle session ids;
- the spawn and workflow capture paths drop a co-tenant warm session
  whose runtime died;
- a retry after a turn-0 transport loss records no false lossy hand-off.
  The orchestration's yield sequence is unchanged.

Review S7: a monitor that binds nothing warns, and is counted as an
unclaimed exit.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
…recording (#376)

Review S14: a session setting that the connection inherited (from the
role, the database or the server) is reset after the migration, not
re-set by value. Setting it by value pinned it as session-sourced on
the pooled connection, so a later configuration reload no longer
reached it.

Review C6: the steps path restores the settings before it records the
migration, so the record is written under the connection's own
settings, as on the autocommit path.

Review S15: the regression test checks each migration's recorded
lock_timeout and the setting's source on the reused connection. It
fails on the previous migrator.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
- CHANGELOG: the runtime-exit metric and its log line. The retry
  resumes the last commit only with a versioned store (review C5). A
  lost first turn is retried fresh. The legacy publish guard (M1),
  at-least-once tool effects and the unclaimed-binding warning (S5,
  S7). The migrator's inherited-setting reset (S14, C6).
- design.md: the publish guard, the typed transport-loss
  classification, the co-tenant drops and the C5 qualifier.
- observability.md: pilotswarm.copilot_runtime.exits, and the
  unpublished lifecycle result.
- sdk-apps.md: turnSignal and at-least-once tool effects after a
  runtime loss.
- copilot-instructions.md and the 1.0.34 migration record:
  runtime-loss must pass on every SDK or Node upgrade (review S7).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
Extend RuntimeLoss with the store's head before the turn (none, legacy,
versioned), the eviction sweep and the legacy publish paths (dehydrate,
checkpoint), with the guard that refuses to publish a dir whose turn
sentinel is dirty. Batch rl2 adds 8 cases; with rl1's 15 all 23 run as
expected (TLC 2.19, tla2tools v1.7.4). comparison.rl-pr-* reproduce the
sweep and the publish of a dirty dir on the code before the guard.

CORRESPONDENCE-dd1029c6-rl2.md re-binds the model to dd1029c6 and lists
the test evidence; the folder README, docs/formal/README.md and
SHA256SUMS are updated.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
The S5 fence checked only spawn_agent, create_agent_session, message_agent,
set_session_model and regenerate_context. Eight other bridge tools with
external effects still took every step after their turn or activity attempt
had ended, so a retried turn could act twice.

Each external step of message_agent_session, manage_agent_session,
send_session_message, reply_session_message, regenerate_agent,
complete_agent, cancel_agent and delete_agent now runs the same synchronous
check first. So do stop_agent_turn, the check_agents memo and the canvas
writes (draw, update, show, canvas_kv put/delete, publish_canvas_app). The
check reads two flags and never awaits a handler. Reads, the Workflow tools
and set_session_workspace's check stay unfenced; bridgeStep's comment lists
them.

A new table-driven test calls each tool through the runTurn activity's real
bridge after the activity returned and asserts that it stops at the named
step and writes nothing. All 23 cases fail on 0b39190a.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
… review)

The turn after a stopped first turn, on a worker without the stopped turn's
local dir, reads the stopped turn's session.snapshot_unpublished record
(freshChain) and starts a fresh conversation: no session.lossy_handoff, no
"worker restart" notice, and snapshot version 1 saved. #376 already does this
in code (unsavedFreshPredecessorRecorded accepts reason "stopped"); only the
runtime-loss case had a test.

- turn-control-run-turn: add the stopped case to the two-worker fleet
  (stopNextTurn), plus two controls that keep the lossy replay: a record
  without freshChain, as an older worker writes it, and a failed read of the
  records. The lossy controls now also assert the "worker restart" notice.
- Rename "another worker: no local evidence" to say it models a missing
  record.
- CHANGELOG, orchestration design and the turn-control proposal: the stopped
  case, and the two residuals (older-worker records, failed reads).

Red with the stopped acceptance reverted: the stopped case fails (worker B
reopens at turn 0, the lossy replay); green on this head.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
The branch was rebased onto main 1f6af95 (#392, 0.8.18). Re-bind batch rl1
to f4ef5cd (was 261ea6c) and batch rl2 to 0b33852 (was dd1029c6). Every
cited line was re-read at those commits. Main's only source change on the
modelled files is an empty customAgents list for a session without native
tasks (session-manager.ts, session configuration), which moves the later
lines by 4; types.ts changes only doc comments. Mode "main" stays bound to
ac86a39, and 1f6af95 changes none of the code it models. The later branch
commits bc33902 (control-bridge fence) and a62fc50 (a test) change no
modelled path. The rl2 comparison notes now name deb0255 (was ce74d92).

TLC 2.19 re-run of the 23 RuntimeLoss cases: 23 of 23 as expected, the same
verdicts and invariants, and the same PASS state counts. Violation and
witness counts vary by a few states with two workers; the README says so.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
ChrisKrawczyk pushed a commit that referenced this pull request Nov 25, 2026
After the rebase onto #376, the warm-first vision lookup skips a runtime
that has exited as well as one being stopped. Say so in design.md.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0
@ChrisKrawczyk
ChrisKrawczyk requested a balanced review from Copilot November 25, 2026 06:46
Take #375 (workflow scripts on Node 26). CHANGELOG.md conflicted only in
the Unreleased section: keep both entries, #375's first.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: cc944a13-3e0b-43de-8040-5863182bbdb0

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Missing fence rechecks after pending operations allow abandoned turns to overwrite retry canvas updates and publish stale canvas data.

2 open issues
What changed in this PR

This PR addresses #329 by detecting dead Copilot runtimes promptly and preventing their reuse. Failed turns retain the last committed snapshot for recovery through the existing retry path, without an orchestration version or schema migration.

Changes:

  • Adds runtime-exit monitoring, transport-loss handling, tool-effect fences, and telemetry.
  • Adds recovery regressions and formal-model evidence, while correcting the runtime ownership test.
  • Restores PostgreSQL connection settings between migrations and documents the new behavior and limits.
File Description
scripts/​test/​sdk-telemetry-package.test.mjs Allows the new runtime-exit counter.
packages/​sdk/​test/​unit/​runtime-metrics.test.mjs Tests runtime counter labels and disabling.
packages/​sdk/​test/​unit/​copilot-runtime-monitor.test.mjs Tests process binding, exits, and loss classification.
packages/​sdk/​test/​local/​turn-lifecycle.test.js Tests unpublished turns and dirty-directory protection.
packages/​sdk/​test/​local/​turn-control-run-turn.test.js Tests fresh-conversation recovery across workers.
packages/​sdk/​test/​local/​tool-binding-reads.test.js Tests capture behavior after parent runtime loss.
packages/​sdk/​test/​local/​session-proxy-events.test.js Checks events for refused dehydration.
packages/​sdk/​test/​local/​runtime-loss.test.js Adds real-runtime kill and recovery regressions.
packages/​sdk/​test/​local/​pg-migrator-session.test.js Tests migration setting restoration.
packages/​sdk/​test/​local/​orchestration-composition-rebuild.test.js Tests tool capture on a replacement runtime.
packages/​sdk/​test/​local/​native-subagents.test.js Tests transport-loss classification during settlement.
packages/​sdk/​test/​local/​inline-control-tools.test.js Tests control-tool fences after turn completion.
packages/​sdk/​test/​local/​copilot-runtime-migration.test.js Records that the runtime permits a second owner.
packages/​sdk/​test/​helpers/​kill-harness.js Finds runtime children through OS process listings.
packages/​sdk/​src/​types.ts Defines transport-loss and tool invocation fields.
packages/​sdk/​src/​session-messages.ts Adds checks before message enqueueing.
packages/​sdk/​src/​session-lifecycle.ts Skips snapshot commits for transport-loss results.
packages/​sdk/​src/​runtime-metrics.ts Adds runtime-exit and unpublished lifecycle outcomes.
packages/​sdk/​src/​pg-migrator.ts Restores connection settings between migrations.
packages/​sdk/​src/​managed-session.ts Watches runtime exits and classifies failed turns.
packages/​sdk/​src/​index.ts Exports the tool invocation context type.
packages/​sdk/​src/​copilot-runtime-monitor.ts Implements runtime-child tracking and exit watches.
packages/​sdk/​src/​control-bridge-fence.ts Adds turn-scoped checks for inline effects.
packages/​sdk/​src/​canvas-operations.ts Adds cancellation checks to canvas operations.
packages/​sdk/​src/​canvas-app-catalog.ts Fences app artifact and catalog publication.
docs/​proposals/​snapshot-store-wins.md Documents transport-loss unpublished snapshots.
docs/​proposals/​session-turn-control.md Documents cross-worker fresh-chain evidence.
docs/​formal/​session-orchestration/​tlc-templates.json Adds runtime-loss model settings.
docs/​formal/​session-orchestration/​SHA256SUMS Updates formal validation checksums.
docs/​formal/​session-orchestration/​README.md Records model coverage, results, and limits.
docs/​formal/​session-orchestration/​CORRESPONDENCE-f4ef5cd8-rl1.md Maps runtime-loss model actions to code.
docs/​formal/​session-orchestration/​cases.tsv Registers runtime-loss model cases.
docs/​formal/​README.md Indexes runtime-loss validation evidence.
docs/​developer/​deploy/​observability.md Documents new metrics and collector filtering.
docs/​developer/​contributing/​copilot-sdk-migration-1.0.34.md Corrects ownership guidance and adds upgrade checks.
docs/​developer/​building/​sdk-apps.md Documents tool cancellation and at-least-once effects.
docs/​architecture/​orchestration/​design.md Explains runtime-loss recovery and its limits.
CHANGELOG.md Summarizes recovery and migration-runner changes.
.github/​copilot-instructions.md Requires runtime-loss checks on SDK or Node upgrades.

Review effort: Balanced

Comment on lines +481 to 482
deps.fence?.("draw_canvas", "drawing the canvas");
const seedRev = await latestCanvasRev(catalog, target, slot);
if (isPatch && !planeAvailable) {
return { error: "this deployment predates the canvas data plane — send data (the whole state) instead of patch" };
}
deps.fence?.("update_canvas", "writing the data");

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warm session reused after copilot-runtime dies: turns stall ~300 s and same-worker retries fail with 'Connection is closed.'

3 participants