Skip to content

fix(code): her shell starts where her file engine stands, and a move takes both under one lock (card 2d58192d) - #5023

Closed
joelteply wants to merge 2 commits into
canaryfrom
2d58192d/her-shell-and-her-code-tools-stand-in-di
Closed

joelteply wants to merge 2 commits into
canaryfrom
2d58192d/her-shell-and-her-code-tools-stand-in-di

Conversation

@joelteply

@joelteply joelteply commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Kimi #11697: code/* acted in the card worktree while code/shell's pwd was her citizen
workspace. One root was stored twice (the engine's and the shell session's), moved in
two unlocked steps (engine insert, then re-root), and ensure_shell reused any existing
session without comparing its root, so a divergence persisted until the next move.

  • CodeState::with_current_shell is the one start path. Under a per-key hands lock and
    with no await, the shell is brought to the ENGINE's root (a session elsewhere is set
    aside, its running commands kept), and the caller's closure starts the command on
    that very session, never a re-fetched one.
  • CodeState::move_hands moves engine and shell together under the same lock:
    create-workspace and a local identity's held-card move both go through it.
  • ensure_shell becomes with_shell(state, ctx, f); code/shell and create-workspace's
    PATH prefix use it. finish_release takes the lock and drops it.
  • Lock order: the hands lock is taken before any DashMap guard, never inside one, and
    never held across an await (Codex root confirmed the scope, e=efedb1e2).

SCOPE, stated (Astra's review, e=9a2f4ff8): this fixes AGREEMENT between her engine and
her shell. It does NOT bind each call to the workspace its own turn intended. The engine a
command starts against is the CURRENT one, which may belong to another turn: a room turn and
a held-work turn sharing her default hands can still move them under each other, and each
call then runs consistently (shell = engine) but possibly in the other turn's root.
Per-invocation binding needs each turn on its own acting context: HER-HANDS slice 2 (a
held-work turn's hands are its own context and never move her room hands). That slice is
the real fix for the cause; this change only makes the split roots impossible to observe.

Test: a_command_starts_where_her_engine_stands_whatever_moved_the_shell simulates the
interleave with a command running in the old root.

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

…takes both under one lock (card 2d58192d)

Kimi #11697: code/* acted in the card worktree while code/shell's pwd was her citizen
workspace. One root was stored twice (the engine's and the shell session's), moved in
two unlocked steps (engine insert, then re-root), and ensure_shell reused any existing
session without comparing its root, so a divergence persisted until the next move.

- CodeState::with_current_shell is the one start path. Under a per-key hands lock and
  with no await, the shell is brought to the ENGINE's root (a session elsewhere is set
  aside, its running commands kept), and the caller's closure starts the command on
  that very session, never a re-fetched one.
- CodeState::move_hands moves engine and shell together under the same lock:
  create-workspace and a local identity's held-card move both go through it.
- ensure_shell becomes with_shell(state, ctx, f); code/shell and create-workspace's
  PATH prefix use it. finish_release takes the lock and drops it.
- Lock order: the hands lock is taken before any DashMap guard, never inside one, and
  never held across an await (Codex root confirmed the scope, e=efedb1e2).

Not in this change: HER-HANDS slice 2 (a held-work turn on its own context, so it
never moves her room hands). This makes the divergence unobservable meanwhile.

Test: a_command_starts_where_her_engine_stands_whatever_moved_the_shell simulates the
interleave with a command running in the old root.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01FRQWzgSfo79JtnwZywHKrE
… lock is closed, never duplicated; provisioning never overwrites a move (Astra on #5023)

- create-workspace moved the hands to A, then AWAITED with_shell (which could move them
  to B) and installed A's PATH prefix and PYTHONPATH into B's session. move_hands_then
  does the move and the shell's configuration in ONE hold with no await, so the env
  lands in the session at the root it was computed for.
- finish_release removed the key's lock after unlocking, so a waiter on the old lock and
  a newcomer on a fresh one could both act. The lock now carries a CLOSED flag: the
  release sets it and unlists the lock while still holding it, and `holding` retakes the
  key's current lock when it wakes on a closed one.
- ensure_engine's lazy insert ran outside the lock after awaits. provision_engine
  inserts under the lock, and an engine a mover installed meanwhile wins.

Scope unchanged and stated in the PR: agreement, not per-invocation binding (fc9e9fd7).

Test: a_released_key_never_has_two_locks_and_provisioning_never_overwrites_a_move.

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

Copy link
Copy Markdown
Contributor Author

Superseded by the bound-hands refactor (card fc9e9fd7): instead of locking and reconciling one set of hands that every turn moves, each card claim gets its own hands, bound once and never moved, so this PR's lock/reconcile machinery has nothing left to protect. Closing unmerged.

@joelteply joelteply closed this Oct 13, 2026
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]>
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