Launch-failure node skip and refund
## 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 C4 — Launch-failure node skip and refund
## Scope (this child)
Epic item 2 (PRD R2a, R2b; Architecture §C4, decisions D5, D6). Verbatim asks: "launch_failed counts toward the per-node skip (apps/api/app/launch_failures.py)." and "When one node fails the same task's launch across different accounts, refund the attempt."
PRD (verbatim):
- R2a. A `launch_failed` break counts toward the task's per-node skip exactly like a `launch_unannounced` note. After **2** launch failures (any mix of the two) of one task on node N since its last Reset/Start, that task's next placement excludes N **for as long as those failures are inside the existing 24 h window** — not only for 1 minute.
- Decided: if N is the only node eligible for the task, the exclusion yields (place on N) rather than strand the task — matches the existing "never strand a task" rule (Task 7929).
- R2b. When node N has failed the same task's launch under **≥ 2 distinct accounts** (since the last Reset/Start), the attempt that the latest of those failures charged is refunded (`dispatch_attempts` decremented, never below 0, bounded by the existing `node_fault_refund_cap`). Requires recording the account on each launch-failure note.
- The refund is recorded on the task's activity/notes so an operator sees why the attempt was not charged.
- Constraint: the "2 failures" value lives in one constant (`PER_NODE`).
## Approach (Architecture, settled)
- Notes carry the account: `runner_terminations.record` (`apps/api/app/runner_terminations.py:203`) gains `account: Optional[str]` → `data.account` (the slot's `worktrees.account` config-dir label, never a secret). Pass it from `charge_unannounced_launch` (`runner_settle.py:167-208`) and `end_attempt`'s note (`runner_settle.py:147`, reached by `reclaim_active_task` with `launch_failed`); add `account` to `_VanishedTrace` (C3 edits the same class — file overlap only).
- Counting: `launch_failures._failures` (`apps/api/app/launch_failures.py:80-123`) counts `CAUSE_LAUNCH_FAILED` alongside `CAUSE_LAUNCH_UNANNOUNCED` inside `WINDOW`; `skipping` = `faulted OR count >= PER_NODE`. Delete `SKIP` (`:58`) and its docstring paragraph; update the module docstring and `dispatch_wait.py:157-165` prose (living docs describe the present).
- Never strand: `routes/fleet.py::_AllowedNodeNames.__call__` (`:390-407`) subtracts hard exclusions (lane fault, too small, "Start fresh elsewhere") unconditionally, the per-task launch-failure exclusion only when ≥ 1 live eligible node remains. `launch_failures.excluded_node_ids` returns `ExcludedNodes(hard: dict, launch_failed: dict)`; update both callers (`routes/fleet.py:413`, `lease_drain.py:2558`). "Live" = the pass's live-node set (`live_nodes_for_project`/`DispatchPassFacts`).
- Refund: new `launch_failures.cross_account_refund_due(session, task_id, node_uuid, account) -> bool` (True when this note's account differs from every earlier failure note's account for (task, node) since last Reset/Start and ≥ 1 earlier note exists). Both charge sites call it after writing the note; on True call `_refund_node_fault_attempt(task_id, session, sources=…)` (`(READY,)` for `charge_unannounced_launch`, `(ACTIVE,)` for reclaim; refund before `end_attempt` reads the counter) — reusing its guard and `node_fault_refund_cap` (D6) — and write a note via `runner_terminations.record` with new label-only cause `launch_refunded` plus a `CAUSE_LABELS` label.
- Risk: removing `SKIP` without the live-node yield parks a single-node task 24 h — the yield and its test are mandatory.
## Credentials & reach
| Oracle | Credential / identity / environment | Status |
|---|---|---|
| AC2a, AC2b (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 node-wide loss refund rule (`runner_liveness.py:53-58,375-391`) or add a new refund counter; no h5-3 host investigation.
Done means:
- AC2a: After a second `launch_failed` (or mixed with `launch_unannounced`) for task T on node N, T's next placement is on another eligible node even > 1 min later; with N the only eligible node, T is still placed on N. — New cases in `apps/api/tests/test_launch_failures.py` → pass (red on develop first).
- AC2b: T failing launch on N under two different accounts refunds one attempt (bounded, never < 0); two failures under the same account refund nothing. — API test → pass; `dispatch_attempts` asserted; plus refund stops at the cap and the refund note is present with a readable label. Also: a Reset between two cross-account failures → no refund and no exclusion ("since the last Reset/Start" pinned for both count and account set).
- Epic done-means (item 2): a second launch_failed on node N places the retry on another node — the AC2a test above.
- AC-RC: Full gate green — `./dc check full` (merge lane) → green.
Required checks: ./dc check full
Outcome
PR #6768 queued in merge lane: launch_failed counts toward per-node skip for the 24h window (yields if node is the task's only live one); cross-account launch failure on a node refunds the attempt (capped, noted). Quick gate green; 14 tests red on develop first. No UI surface affected. Memory: none applied.
Artifacts
Activity
- Draft
- Ready
- Runner started
- Runner ended (done)