Skip to content

fix(shell): a kill ends the shell and everything it started, through the one task that owns the child; survivors are recorded and a release re-checks them (card ea06701d, Astra's design A) - #5012

Closed
joelteply wants to merge 2 commits into
canaryfrom
ea06701d/code-shell-kills-only-the-direct-child-s
Closed

joelteply wants to merge 2 commits into
canaryfrom
ea06701d/code-shell-kills-only-the-direct-child-s

Conversation

@joelteply

@joelteply joelteply commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Why

Card ea06701d. A code/shell kill ended only the direct bash -c. A pipeline, a test runner's workers or a backgrounded server outlived it, and stayed running after code/release-hands (#5005) said the context had ended.

The design is Astra's option A (relayed by Codex root, e=8d7a2a42):

  • an incremental, best-effort kill;
  • cancellation goes through the task that owns the child;
  • the competing stored-PID kill paths are removed;
  • delivering a signal is not the same as confirming an exit;
  • descendants are identity-checked and killed deepest first;
  • anything unresolved keeps the eval's ownership.

What

One tree-kill owner, lane_process (commit e28a53a). It was already the one liveness owner.

  • The group/tree kill existed four times: in code/github (kill_gh_tree and TreeKill), as swe_bench's inline killpg, as lane_process::kill9 (a tree on Windows only), and as the shell's kill -9.
  • lane_process now owns TreeKill, kill_tree and lead_own_group. code/github and swe_bench use them, and their copies are deleted. Their behaviour is unchanged, except that swe_bench now reports the tree-kill outcome in its ceiling probe.
  • New identity primitives:
    • ProcessIdentity is a pid plus its start time.
    • descendants(pid) lists them deepest first, from the process table's parent links.
    • still_present matches on the same pid and start time and treats a zombie as gone.
    • kill_if_same never signals a pid that now names another process.

The shell (commit 295da6b):

  • It stays in the core's process group, so continuum stop still ends everything it ran. It is deliberately not made a group leader: that would let a citizen's processes outlive a stop.
  • One kill. Only the execution's own task, which owns the Child, kills it. ShellSession::kill and destroy only set the flag, and the two stored-PID kill -9 paths are deleted.
  • The timed select now has a kill-flag arm. Before, killing a timed execution worked only through the stored-PID path.
  • The task kills the descendants deepest first, then kills and reaps the shell, and records any survivors on the execution (unconfirmed_descendants).

code/release-hands:

Stated limits

  • A process that double-forked or setsid'd away from the shell is not a descendant, so it is not reached.
  • Staying in the core's group is not a full crash guarantee: launchd's AbandonProcessGroup applies, and stop can return before descendants exit.
  • Option B (its own groups, a durable execution record, and a boot sweep that ends and reports leftovers) belongs with the HER-HANDS persistent-shell slice.

Tests

None of these were run locally: IntelMac doesn't compile the core, so CI is the first build. Hygiene exit 0 at 295da6b.

🤖 Generated with Claude Code

https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

joelteply and others added 2 commits October 13, 2026 04:19
…and swe_bench migrate onto it; release-hands says what it does

The group/tree kill existed in four places. code/github had kill_gh_tree and TreeKill, swe_bench an inline killpg, lane_process::kill9 a tree only on Windows, and the shell its own kill -9. lane_process, already the one liveness owner, now owns TreeKill, kill_tree (Unix, the group the pid leads; Windows, taskkill /F /T; outcome kept) and lead_own_group. code/github and swe_bench use them and their private copies are deleted. swe_bench now reports the tree-kill outcome in its ceiling probe. No behaviour change.

code/release-hands DESCRIPTION now matches #5005. It drops a context only once every execution is confirmed gone, and otherwise keeps it and names the unconfirmed pids.

The shell itself is not wired yet: making shell executions group leaders would let them outlive continuum stop, which kills the core group. That design call is with Astra (card ea06701d).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
…the one task that owns the child; survivors are recorded and a release re-checks them (card ea06701d, Astra's design A)

A code/shell kill ended only the direct `bash -c`. A pipeline, a test runner's workers or a
backgrounded server outlived it, and stayed after the context's release said it ended.

- lane_process gains ProcessIdentity (pid plus start time), descendants(pid) (deepest first,
  read from the process table's parent links while the shell lives), still_present (same pid
  and start time, zombies gone) and kill_if_same (never signals a pid that now names
  another process).
- The shell keeps the core's process group, so continuum stop still ends everything it ran.
  It is not made a group leader.
- ONE kill: only the execution's own task, which owns the child, kills. ShellSession::kill
  and destroy just flag it; the two stored-pid `kill -9` paths are deleted. The timed
  select now has a kill-flag arm too: before, a kill on a timed execution worked only
  through the stored-pid path.
- The task kills the descendants deepest first, then the shell, reaps it, and records what
  still survives on the execution.
- begin_release counts an execution with survivors as not ended. release-hands re-kills and
  re-checks them on each call, so the context is kept while any is present and a retry can
  confirm them.
- Stated limits: a process that double-forked or setsid'd away isn't a descendant and isn't
  reached. Staying in the core's group is no full crash guarantee (launchd
  AbandonProcessGroup, and stop returning before descendants exit). Option B (own groups,
  plus durable execution records and a boot sweep) belongs with the persistent-shell slice.
- test_kill_execution now also proves a backgrounded grandchild dies with its shell, and
  that nothing is recorded as surviving.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
joelteply added a commit that referenced this pull request Oct 13, 2026
…rns, past a cancelled waiter (Astra on #5026)

A dispatch cancelled or timed out dropped its admission while the blocking work it started
(git, GitHub's git, the checkout sync) ran on, so a release could remove the workspace
under a still-running operation.

- The dispatcher runs each command as the task's ADMITTED work (code::hands::admitted, a
  task-local scope holding the Arc'd admission).
- code::hands::spawn_blocking is the one owner of blocking work in hands commands: it clones
  the task's admission into the blocking thread and holds it until the work returns. A
  cancelled waiter drops only its own clone; the release waits for the worker.
- Migrated: commands/code/git blocking_git, commands/code/github git_output, and the
  workspace_transfer checkout sync. The card turn's sync runs under the turn's own lease;
  the fork teardown's sync is admitted to the context it then closes.
- Processes stay with their owner: code/run and run_gh already kill_on_drop, and
  termination belongs to lane_process (#5012).

Test: a_release_waits_for_a_blocking_worker_whose_waiter_was_cancelled (the command's
scope ends while its blocking worker runs; the release doesn't complete until the worker
returns).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
joelteply added a commit that referenced this pull request Oct 13, 2026
…n; no unleased sync; nested work keeps its admission (Codex root on #5026)

Stacks #5012 (card ea06701d, the one tree-kill owner), merged here.

- lane_process::end_tree is THE end of an owned child: descendants found while
  it lives, killed deepest first by identity, then the child killed and reaped,
  survivors reported. The shell's execution task and gh's owner both use it;
  the shell's inline copy is gone. recheck() is the one re-kill + re-check,
  used for shell survivors and for these.
- gh: one end path (OwnedGh::end, a spawned task the caller's cancellation
  can't cut short) for a timeout and a dropped waiter alike. What it can't
  confirm gone is kept ON the admission before it drops; close() returns it and
  release-hands re-checks it, keeping the hands while any is present (the
  shell-survivor rule). gh stays in the core's process group, so a stop ends
  it; GH_REAP_BOUND and the TreeKill outcome on TimedOut are deleted, and a
  timeout names what isn't confirmed gone.
- The checkout sync takes its lease as a parameter: an unleased sync can't be
  written. end_acting_context refuses default hands first, and closed hands
  skip the sync by name instead of running it unleased (was admit().ok()).
- hands::spawn_blocking makes the admission current inside the blocking work
  (a thread-local, cleared before the thread is pooled), so work it starts in
  turn keeps it.

Tests: a_dropped_gh_owner_ends_its_tree_and_holds_the_admission_until_it_has
(a descendant is gone and nothing is unconfirmed when the release completes);
a_nested_blocking_worker_keeps_the_admission_of_the_work_that_started_it.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
joelteply added a commit that referenced this pull request Oct 14, 2026
…as its own hands (card fc9e9fd7) (#5026)

* refactor(process): one tree kill, owned by lane_process; code/github and swe_bench migrate onto it; release-hands says what it does

The group/tree kill existed in four places. code/github had kill_gh_tree and TreeKill, swe_bench an inline killpg, lane_process::kill9 a tree only on Windows, and the shell its own kill -9. lane_process, already the one liveness owner, now owns TreeKill, kill_tree (Unix, the group the pid leads; Windows, taskkill /F /T; outcome kept) and lead_own_group. code/github and swe_bench use them and their private copies are deleted. swe_bench now reports the tree-kill outcome in its ceiling probe. No behaviour change.

code/release-hands DESCRIPTION now matches #5005. It drops a context only once every execution is confirmed gone, and otherwise keeps it and names the unconfirmed pids.

The shell itself is not wired yet: making shell executions group leaders would let them outlive continuum stop, which kills the core group. That design call is with Astra (card ea06701d).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

* fix(shell): a kill ends the shell and everything it started, through the one task that owns the child; survivors are recorded and a release re-checks them (card ea06701d, Astra's design A)

A code/shell kill ended only the direct `bash -c`. A pipeline, a test runner's workers or a
backgrounded server outlived it, and stayed after the context's release said it ended.

- lane_process gains ProcessIdentity (pid plus start time), descendants(pid) (deepest first,
  read from the process table's parent links while the shell lives), still_present (same pid
  and start time, zombies gone) and kill_if_same (never signals a pid that now names
  another process).
- The shell keeps the core's process group, so continuum stop still ends everything it ran.
  It is not made a group leader.
- ONE kill: only the execution's own task, which owns the child, kills. ShellSession::kill
  and destroy just flag it; the two stored-pid `kill -9` paths are deleted. The timed
  select now has a kill-flag arm too: before, a kill on a timed execution worked only
  through the stored-pid path.
- The task kills the descendants deepest first, then the shell, reaps it, and records what
  still survives on the execution.
- begin_release counts an execution with survivors as not ended. release-hands re-kills and
  re-checks them on each call, so the context is kept while any is present and a retry can
  confirm them.
- Stated limits: a process that double-forked or setsid'd away isn't a descendant and isn't
  reached. Staying in the core's group is no full crash guarantee (launchd
  AbandonProcessGroup, and stop returning before descendants exit). Option B (own groups,
  plus durable execution records and a boot sweep) belongs with the persistent-shell slice.
- test_kill_execution now also proves a backgrounded grandchild dies with its shell, and
  that nothing is recorded as surviving.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

* refactor(hands): a workspace is bound, never moved; each card claim has its own hands (card fc9e9fd7)

Kimi #11697: her code/* tools acted in the card while code/shell stood at home. One set of
hands (her default context) was re-rooted at the card and restored home by every turn that
worked a card; two concurrent turns interleaved those moves. #5023 put a lock and a
reconcile around the shared mutation; this removes the mutation instead (Joel: every PR
makes the code more elegant). #5023 is closed as superseded.

THE SHAPE
- A card CLAIM has its own hands: HandsContext::for_claim(persona, card, claim), derived,
  so every turn of the claim names the same hands, and a re-acquired card is a NEW claim
  that never inherits the old hands or authority. They are rooted once at the card's
  checkout and never moved.
- Her default hands never move. root_acting_workspace and end_acting_context refuse them.
- A turn is BOUND at admission: Burst::hands (beside its room and cause) carries the
  claim's context; apply_act acts through ToolExecutor::in_hands(context), a non-owning
  executor (in_fresh_hands keeps owning eval/fork contexts, released on drop). Background
  dispatch carries the same hands.
- Admission: code::hands::admit/close/forget. A turn holds a HandsLease; when a claim ends,
  its hands close to new turns, wait out admitted ones, then release (engine, shell).
- ONE binding for every turn: persona_workspace::bind_card (room turn after its board read,
  held-work turn with its focus card), through ONE resolver of where a card's work lives
  (card_staging::checkout_path_for, now holding the benchmark-review rule too).
- Perception follows a focus pointer to the bound hands' fixed place, not a moved root.
- WIP sync runs at the end of each card turn for that turn's own context, serialized per
  checkout inside the blocking git task (two turns of one claim can end together).
- Local identities resolve their claim's hands per call (hands_of), never re-root.
- create-workspace binds hands once: the same root is a no-op, another root is refused.

DELETED
- restore_acting_workspace's move-home path and restore_acting_workspace_at
- the root/restore pairs in service_loop.rs and act_question.rs
- re_root_shell, parked_shells, PARKED_SHELLS_PER_CALLER, ShellSession::has_running
- LAST_CARD_ROOT and ensure_engine's local re-root; card_root_of
- act_question::held_card_workspace (a second card-workspace resolver)
- the 'every caller MUST pair with restore' contract

TESTS
- a_claims_hands_are_its_own_and_her_default_hands_never_move (replaces the #312 restore test)
- closing_a_claims_hands_refuses_new_turns_and_waits_out_the_admitted_one
- create_workspace_binds_hands_once_and_refuses_to_move_them
- a_running_command_stays_reachable_by_its_handle_in_its_own_hands (was the re-root test)

Not compiled here (IntelMac doesn't build the core); hygiene 32/32. The acceptance Astra
named (overlapping turns, focus change, running command, release/re-acquire with stale
cleanup) is partly covered by these tests; the live receipt is a card turn on the 5090.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

* fix(hands): one admitted binding carried through every call, its attribution and its cleanup (Astra on #5026)

Astra's review of 45248a5, each finding fixed at its cause:
- hands_of awaited itself (a sed rewrote its own first line). Resolution and admission are
  now two named steps: resolve_hands (the key, used only by release and handle lookup) and
  hands_of (resolve, then admit for the call's whole life).
- Background and local commands held no admission. Every acting call goes through hands_of,
  so a claim's hands closing waits each call out and refuses calls that start after it (a
  background command first polled after the release included).
- forget deleted a closed gate, so a stale binding could re-open an ended claim. Closed
  gates stay closed (a tombstone per claim worked, for the process's life).
- forget_checkout could drop the sync lock while a timed-out git still ran under it. The lock
  leaves only when nothing holds it.
- A failed binding ran the turn with her default hands at home. It now acts in the card's
  never-rooted stand-in (HandsContext::unbound): code tools refuse by name, others work.
- poll/kill re-resolved her focus, so claim A's handles were unreachable after focus moved
  to B. Handle lookup spans the caller's own hands, never another caller's.
- create-workspace resolved her hands twice (engine, then shell env): one resolution,
  passed to ensure_shell.
- Background work attribution read her current focus: CommandWork captures the card of the
  call's own hands.

Tests added: a_call_after_its_claims_hands_closed_is_refused,
a_checkout_lock_held_by_a_running_sync_is_never_dropped; extended: the gate test (a closed
claim stays closed), the handle test (claim A's handle after focus B), the attribution test
(work stays with the call's claim when focus moves).

Not compiled here; hygiene 32/32.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

* refactor(hands): admission at the dispatcher, release as its own boundary, isolation by context kind (Astra on #5026, 77acf92)

Each finding of e=a78c5cc7, fixed at the owner rather than per helper:
- Admission lived in helpers (hands_of), so engine! and workspace_root_for dropped the
  lease before the git/cargo work. It now lives at the one lifetime boundary every command
  passes through, CommandExecutor::dispatch: a caller bound to a context is admitted for the
  command's whole life, foreground or background. hands_of is the synchronous key of the
  identity's binding again, and the stray brace after it is gone.
- A direct release never closed admission. code/release-hands IS the release boundary: it
  runs only as the kernel's release (CallerIdentity::releasing_hands, never from params; the
  one call the dispatcher doesn't admit), closes the hands to new work, waits out admitted
  work, then ends what still runs. close_acting_context and the drop fallback release through
  the core as a release; close_ended_claims no longer closes separately.
- Caller-wide poll/kill let an eval reach live processes. HandsContext carries its kind
  (Isolated, Claim, Unbound) and map keys carry it, so HandsKey::reaches scopes a handle
  lookup: default and card hands reach each other, an isolated context only itself, and
  nothing of hers reaches into it.
- The unbound stand-in could be provisioned by create-workspace. The owner refuses it.
- Gates are keyed by the context itself; a closed one stays closed.
- Work attribution is captured inside dispatch from the call's own binding.

Scope stated: local identities (operator, agent self-peers) act in their default hands in
this PR; binding them to their claim at the dispatcher, with its board-read cost measured
first, is carded with me as owner.

Tests: a_command_after_its_hands_were_released_is_refused_at_dispatch (new, through the
real dispatcher and production policy); the handle test gains eval isolation both ways; the
gate test is keyed by context.

Not compiled here; hygiene 32/32. Reviewers are asked only after CI's compile and test
lines on this head are read.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

* fix(hands): blocking work keeps its command's admission until IT returns, past a cancelled waiter (Astra on #5026)

A dispatch cancelled or timed out dropped its admission while the blocking work it started
(git, GitHub's git, the checkout sync) ran on, so a release could remove the workspace
under a still-running operation.

- The dispatcher runs each command as the task's ADMITTED work (code::hands::admitted, a
  task-local scope holding the Arc'd admission).
- code::hands::spawn_blocking is the one owner of blocking work in hands commands: it clones
  the task's admission into the blocking thread and holds it until the work returns. A
  cancelled waiter drops only its own clone; the release waits for the worker.
- Migrated: commands/code/git blocking_git, commands/code/github git_output, and the
  workspace_transfer checkout sync. The card turn's sync runs under the turn's own lease;
  the fork teardown's sync is admitted to the context it then closes.
- Processes stay with their owner: code/run and run_gh already kill_on_drop, and
  termination belongs to lane_process (#5012).

Test: a_release_waits_for_a_blocking_worker_whose_waiter_was_cancelled (the command's
scope ends while its blocking worker runs; the release doesn't complete until the worker
returns).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

* fix(github): every gh process is OWNED through exit and reap, holding its command's admission (Astra on #5026)

run_gh ran gh through .output() with no owner and no kill_on_drop, so a cancelled command
left gh (and the git it runs) live while a release removed the workspace under it; that
corrects my claim that every GitHub process already terminated on cancellation.

- run_gh and run_gh_within share ONE owned execution (run_gh_owned, an OwnedGh holding the
  child and the command's admission via code::hands::current()). Dropped before gh exits,
  the owner kills the whole tree (kill_gh_tree, then the parent) and a task keeps the
  admission until gh is reaped. A timeout that can't reap within its bound leaves the reap,
  and the admission, to the owner.
- code::hands::current() is the one reader of the task's admission (spawn_blocking uses it).

Test: a_dropped_gh_owner_holds_the_admission_until_the_process_is_reaped.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

* fix(hands): an unwind-safe blocking admission; an unproven reap and an unwalked tree are held, never confirmed (Codex root on #5026 at f014371)

- hands::spawn_blocking enters the admission through a guard whose drop puts
  the previous one back, so a panicking work() can't leave it on the pooled
  thread.
- lane_process::end_tree keeps the child itself among the survivors while its
  reap is unproven, and a descendant walk that failed to run is reported as
  `unwalked` instead of an empty tree. TreeEnd::confirmed() is the one test.
- The hands gate keeps what an owned process left unconfirmed as Lingering
  {processes, unknown}: release-hands re-checks the processes and holds the
  hands, naming each unknown tree, since no re-check can confirm one. The
  shell folds an unwalked tree into its unproven end.

Tests: a_panicking_blocking_worker_leaves_no_admission_on_its_pooled_thread;
what_an_owned_process_left_unconfirmed_reaches_the_release.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

* fix(hands): an unproven reap is held as unknown on its own, never dropped (Codex root on #5026 at 9986ab2)

keep_unconfirmed returned early when survivors were empty and the walk had
worked, so a failed reap of the child itself reached the release as nothing.
TreeEnd::unknown() now names everything no re-check can confirm (an unproven
reap, an unwalked tree), and the gate holds all of it in Lingering.unknown.
The child-itself survivor (and the identity() lookup it needed) is deleted:
a reap the wait couldn't prove is not something the process table settles.

The test now covers each case alone: an unproven reap, an unwalked tree, a
surviving descendant, and a confirmed end.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
@joelteply

Copy link
Copy Markdown
Contributor Author

Landed through #5026 (squash d546a62 on canary, 2026-10-14T00:00:59Z), never on its own: Codex root approved #5012 at 295da6b only as the parent of the corrected #5026 stack, so an auto-deploy never ran its on-worker process probes without #5026's off-worker end_tree. Evidence kept: #5012's CI at 295da6b was 6/6 green (lib 8829 passed, test_kill_execution with the grandchild case ok). Its content is in canary: lane_process descendants/still_present/kill_if_same/kill_tree, the shell's one-kill path (now through end_tree), release-hands survivor rechecks. Follow-up: card de211a71 (the swe_bench grader onto end_tree, then delete the group kill).

@joelteply joelteply closed this Oct 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant