Fence kill intents on slot generation
## Epic requirement (verbatim, Task 9453 body)
Task 9440 analysed prod's broken sessions for Oct 18–23 (28 breaks, 12 incidents). The attached report has the evidence and code references. Fix these root causes:
1. Relaunch into the task's own held slot dies after an operator Stop or a runner's task_fail (16 breaks: tasks 7456, 7543, 8212, 8683, 9255). The pane log attached to the "vanished" attempt is the predecessor's.
- Fence kill_runner intents on launch_session_id / slot generation, not task id alone (apps/api/app/fleet_verdicts.py build_kill_intent; apps/api/app/routes/tasks/slots.py). An intent minted for a predecessor must never kill a successor launched into the same slot.
- Lease drain relaunches into a held slot only after the node reports the predecessor gone.
- Do not auto-retry a runner's own task_fail when it follows an answered question round; land it system_failed with the runner's reason.
- A vanished incident records the node, the launch id and whether the pane log is the predecessor's.
2. A retry returns to the node that just failed the launch (7 breaks; 7789 failed 4× on h5-3 across 3 accounts).
- launch_failed counts toward the per-node skip (apps/api/app/launch_failures.py).
- When one node fails the same task's launch across different accounts, refund the attempt.
3. Silent stalls are never recorded (8683 sat active 27 h 35 m, 9255 1 h 4 m, after "Runner started" with no session).
- Add a task-level silence detector: an active task with no session attached, heartbeat or transcript write for ~20 min records a break and is reclaimed.
4. The merge lane retries a forge auth rejection ("Invalid username or token", task 7765) until its attempts run out.
- Treat it as a credential blocker: one fresh credential mint and one retry in place, then stop re-dispatching and alert the operator, naming the credential.
5. Misclassified breaks.
- Break classification on the settle/transcript path skips background-subagent task-notification records (apps/jaahd/hooks/break_cause.py), as rs_stopfailure already skips agent_id events.
- Gemini "This client is no longer supported for Gemini Code Assist for individuals" becomes a terminal cause, not auth_expired.
Out of scope: the broken-session collection UI; purge/archival of old incidents; dev control plane; investigating h5-3's hardware/OS beyond what item 2 needs; any other break causes.
Done means:
- Each item ships with a test that reproduces its failure first: a kill minted for launch A does not kill launch B in the same slot; a second launch_failed on node N places the retry on another node; an active task silent past the threshold records a break; a lane auth rejection does not re-dispatch more than once; a subagent limit notification does not classify the session as usage_limit; the Gemini sentence maps to the terminal cause.
- After deploy, `tools/broken_sessions.py list` on prod shows no new held-slot "vanished" incidents following a Stop→Run or task_fail over a 5-day window.
Required checks: ./dc check full
(Item 1c — task_fail after an answered blocker round lands system_failed — already shipped in Task 9264 (`58b8ffd9b`); NOT part of any child.)
Settled inputs: the full PRD (Task 9451) and Architecture (Task 9452) are the epic's `prd` / `architecture` artifacts; this child is the Architecture's section named below. Evidence report: attachment 9076_report.html (Task 9440). Every new test must FAIL on today's develop first — cite the red run in the PR.
---
# Child C1 — Fence kill intents on slot generation
## Scope (this child)
Epic item 1, bullet 1 (PRD R1a; Architecture §C1, decisions D1, D2). Verbatim ask: "Fence kill_runner intents on launch_session_id / slot generation, not task id alone (apps/api/app/fleet_verdicts.py build_kill_intent; apps/api/app/routes/tasks/slots.py). An intent minted for a predecessor must never kill a successor launched into the same slot."
PRD R1a (verbatim): Every `kill_runner` intent carries the identity of the launch it was minted for (the slot's `launch_session_id` and/or `generation` at mint time — Architect picks which; both acceptable). The node enacts it only if the slot's current launch identity equals the intent's; otherwise it retires the intent as stale without signalling any process.
- Assumed: an intent minted while the slot had no launch identity yet (legacy rows in flight during the rollout, `launch_session_id` NULL) is enacted under today's task-id fence, because refusing it could leave a genuinely stray runner alive.
- Applies to every minting site, not only `build_kill_intent` callers in `slots.py`: `end_attempt`, `kill_runner_keeping_hold`, settled-hold sweeps and any other `kill_runner` mint.
## Approach (Architecture, settled)
- Fence on `generation`, not `launch_session_id` (D1: `slot_state.redispatch` keeps `launch_session_id` across a relaunch, `apps/api/app/slot_state.py:349-401`; `generation` is bumped per lease and redispatch).
- CP: `fleet_verdicts.build_kill_intent` (`apps/api/app/fleet_verdicts.py:507-530`) gains `generation: Optional[int]`, added to `payload`. The single mint point `routes/tasks/slots.py::_mint_kill_runner_intents` (`slots.py:194-276`) passes the hold row's `generation` from the same SELECT that reads `launch_session_id`/`pid`. Confirm with Grep that no other `kill_runner` mint bypasses it.
- Projection: add `generation: Optional[int]` to `AgentWorktreeOut` (`apps/api/app/routes/agent/accounts_worktrees.py:223`).
- Node: `apps/jaahd/reconcile/enact_signal.py::_enact_kill_runner` (`:72-154`). After the existing task-id check, if `payload.generation` is an int, apply D2: enact iff some registered live pane of the slot (`runner_registry`, keyed by pane pid — judge the set) carries the intent's generation, OR (no registered pane carries a newer generation AND the CP projection's generation for the slot is not newer than the intent's). Otherwise `OUTCOME_DONE` with reason `stale generation`, no process signalled. No `generation` key → today's task-id fence.
- Pinned seam: `payload = {"task_id": int, "session_id": str|None, "pid": int|None, "generation": int|None}`. A CP must never omit `generation` once this ships.
- Risk pinned by a test: the spawn-before-register window (`fleet_dispatch.py:1111-1115`) — no pane registered yet, projection generation B > A → stale.
## Credentials & reach
| Oracle | Credential / identity / environment | Status |
|---|---|---|
| AC1a (unit and API tests) | Nothing beyond the worktree's own `./dc` stack | verified — runs in any leased worktree, no roster credential needed |
| AC-RC `./dc check full` | Merge lane's worktree, no credential | verified — the lane runs it per project config |
Out of scope (PRD §7, verbatim) — do NOT touch:
- MUST NOT change the broken-session collection UI (console pages listing runner-break incidents) beyond the incident **body text** R1d requires.
- MUST NOT add purge/archival of old incidents or change `tools/broken_sessions.py purge` / `runner_breaks.stale_escalations`.
- MUST NOT change dev control plane config or data; no dev-only behaviour.
- MUST NOT investigate or change h5-3's hardware/OS, node packaging or host setup beyond what item 2's placement/refund needs.
- MUST NOT add or reclassify any other break cause (e.g. `timeout`, `api_error`, `crashed`, `unknown` rules) beyond `stalled` and `client_unsupported`; the unexplained 8569 break is not addressed.
- MUST NOT re-implement 1c (Task 9264 shipped it) or widen it to non-blocker interview rounds.
- MUST NOT change coder-runner push/credential handling (merge lane only for item 4).
Epic out of scope: the broken-session collection UI; purge/archival of old incidents; dev control plane; investigating h5-3's hardware/OS beyond what item 2 needs; any other break causes.
No feature flag, setting or operator toggle may gate the fix (PRD: on by default once deployed).
Architecture boundary: do NOT change the drain/redispatch gate (C2), incident body (C3), or launch-failure counting (C4) here.
Done means:
- AC1a: A kill minted for launch A in slot S does not kill launch B started in S afterwards; the intent is retired stale and B's processes survive. A kill minted for B still kills B. Legacy intent (no launch identity) still enacts under the task fence. — New jaahd test (enact path, `apps/jaahd/tests/`) + API test that every mint site stamps the launch identity: `./dc check quick` runs them; observe pass, and the red run on `develop` showing B killed. Cases: pane at gen B + intent gen A → stale, `_clear_tree` not called; intent gen B → enacted; no generation → enacted under task fence; no pane registered and projection gen B > A → stale; minted payload carries the hold's `generation`. Also: projection still at A, a registered pane at B, intent for A → stale (pins the registry arm, not projection-only).
- Epic done-means (item 1): a kill minted for launch A does not kill launch B in the same slot — the AC1a jaahd test above, red on develop first.
- AC-D2 (epic-level, pointer): the 5-day prod `tools/broken_sessions.py list` check is owned by the epic's Finish stage (deferred — only decidable 5 days after prod deploy); it reads C3's predecessor-pane marker.
- AC-RC: Full gate green — `./dc check full` (merge lane) → green.
Required checks: ./dc check full
Outcome
kill_runner intents now carry the hold's generation; the node retires a predecessor's kill as stale instead of killing the relaunch. Kill suppression is per generation. Tests fail on develop first; quick gate green; PR #6766 queued to the merge lane. Memory: none applied.
Artifacts
Activity
- Draft
- Ready
- Runner started
- Runner ended (done)