Relaunch waits for predecessor gone
## 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 C2 — Relaunch waits for predecessor gone
## Scope (this child)
Epic item 1, bullet 2 (PRD R1b; Architecture §C2, decision D3). Verbatim ask: "Lease drain relaunches into a held slot only after the node reports the predecessor gone."
PRD R1b (verbatim): The lease drain relaunches a task into the slot it already holds only after the node has reported that slot's predecessor session gone (`session = false` / no live pid for the predecessor launch) since the predecessor's stop/settle. Until then the relaunch waits; it is not spent as an attempt.
- Decided: if the node never reports (node stale > existing `OBSERVATION_FRESH_SECONDS`), the existing node-staleness handling applies; this requirement adds no new timeout. Waiting must not block other tasks' dispatch.
## Approach (Architecture, settled)
- D3: "Predecessor gone" = the slot's newest `kill_runner` intent is retired, AND a node observation newer than that intent's `created_at` reports `session` not true. Checked in the one redispatch predicate `fleet_decide.dispatch_is_redispatchable` (`apps/api/app/fleet_decide.py:110-135`), which decides held-slot redispatch for both the fleet pass and the drain (`routes/fleet.py:1047-1066`). No new timeout.
- New helper `fleet_verdicts.predecessor_gone(session, slot_keys) -> dict[slot_key, bool]`, one query per pass. Per slot, newest `kill_runner` `SlotIntent` (`apps/api/app/models/worktrees.py:256-331`): no kill row → True; newest kill still pending (`still_pending`, `fleet_verdicts.py:913-916`) → False; otherwise `worktrees.observed_at > kill.created_at AND worktrees.session IS NOT TRUE`.
- `dispatch_is_redispatchable` gains keyword `predecessor_gone: bool = True`, returns False when False. Caller `routes/fleet.py:1059-1065` passes the helper's answer. The task stays `ready`, no attempt charged; other tasks unaffected.
- Reads only `SlotIntent.created_at`/`outcome` of kill intents; independent of C1's payload change.
- Risk (deadlock): a kill refused forever keeps its intent pending — the existing intent-rail refusal/backoff retires it; add a test that a refused-then-retired kill unblocks.
## Credentials & reach
| Oracle | Credential / identity / environment | Status |
|---|---|---|
| AC1b (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 kill payload/node enact fence (C1) or add a new timeout.
Done means:
- AC1b: With the predecessor still reported live on S, the drain does not relaunch the task into S and charges no attempt; after the node reports it gone, the next drain pass relaunches. — New API test in `apps/api/tests/test_lease_drain_dispatch.py` (or sibling): `./dc test -q tests/<file> -k predecessor` → pass (red on develop first). Use `_hold_this_slot_for_its_own_task` / `_observe_this_slot_reporting_no_account`; plus a unit case in `test_fleet_decide.py` and the refused-then-retired-kill unblock case. Also: kill retired but the only `session=false` observation is older than `kill.created_at` → no relaunch; and a waiting task does not block another task's dispatch in the same pass.
- 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
Own-slot relaunch now waits (uncharged, non-blocking) until the node reports the predecessor gone; plan + take-time gate, 7 new tests red on develop first, quick gate green. PR #6765 queued to merge lane. AC-D2 deferred to Finish. Memory: none applied.
Artifacts
Activity
- Draft
- Ready
- Runner started
- Runner ended (done)