IMPLEMENTER BRIEF — phase5-run-entry-fixes-4 (Phase 5: the cancel-race disposal — F29–F32)

GOAL: F29–F32 are disposed and the Phase 5 exit gate is claimable on the next clean review. F29: the mid-run-cancel operator class settles honestly and its log stays replayable — with a second process's documented `stop` landing while a launcher's root execution is live, `start`'s JSON carries the durable fresh outcome (`accepted: false`, `outcome: CANCELLED`), `start`'s exit is non-zero, neither process prints a traceback, the documented `inspect` head runs clean on the produced store and reads the same outcome as a brand-new connection's replay, and every new connection replays the durable log to that outcome with no `ReducerError`. F30: the Guarded-surface shape's three facets are pinned — an accepted lineage settles exactly once (one `NODE_MARKED_INFEASIBLE`), a duplicate `mark_infeasible` dedupes against the shared `infeasible-{node_id}` key (history +0), a late call with a recorded failure on a terminal run is retained with no outcome rewrite — and the behaviour the F27 guard changed is named by a pin (a zero-fingerprint `mark_infeasible` on a terminal run refuses with `WorkflowError`, node and outcome unchanged). F31: the absorbed F28 pin's node id names the property the pin enforces (every documented head is the `python3` form and runs as written; no bare head is documented) with its docstring's meaning unchanged. F32: the prerequisite assertion binds the claim (a mutant naming only `json`, and a deletion of the sentence, both go red at `FINAL`) or is dropped with the reason named.

CONTEXT: The fixes-3 step returned to planning (its review raises F29 as P1); F26–F28 are disposed and F30–F32 ride this continuation. F29's mechanism is two halves, both inside the existing late-event rule — no `docs/tables/*` change, no new event type, no catalogue or conformance entry (the artefact machine is silent on a cancelled attempt's candidate: [artefact-lifecycle.yaml](../tables/artefact-lifecycle.yaml) has no such row, and the Exec F2 guard in `reducer.py` is code). (1) The launcher drives its execution-phase admissions on its in-memory projection, which never observes a second process's `stop` (F20's lesson — already applied at `_settle_executor_refusal`, which reads `controller.store.replay_fresh(run_id).outcome` before deciding, re-reads before emitting, and re-reads after admissions for the returned document). The same discipline belongs at the live `DISPATCH_ACKNOWLEDGED`/observation boundary and at `start_run`/`_bind_acceptance`'s returns: the node-level chain is skipped when the fresh outcome is already terminal, and the returned `StartResult`/CLI JSON keys on the durable fresh outcome (`accepted` is true and the exit zero only when that outcome is `ACCEPTANCE_CLAIMED`). (2) The reducer's own pair makes such a log unwritable-but-unreadable: `_on_artefact_admitted` late-retains a terminal attempt's artefact without creating it (the Exec F2 guard), and `_on_artefact_integrated` then raises `ReducerError: unknown artefact_id` on the id that guard refused to create (`reducer.py:908`) — under the late-event rule the follow-on of a retained admission is itself late. A genuinely unknown `artefact_id` (never admitted anywhere in the log) must still fail closed. The class pin is subprocess-level (the review's shape: a launcher and a second process's documented `stop` — never an in-process double-`stop` alone), and every "no traceback" drive exercises the documented `inspect` head against the produced store, not only the launcher's stderr (the observable failure hides in the second process). F30's three facets are the fixes-3 brief's Guarded-surface shape (named there, left unbuilt behind `SHAPES: none`); that report's "unchanged as measured by the fixes-2 review" is false for the zero-fingerprint terminal call (the F27 guard made it refuse). F31 and F32 are the absorbed F28 pin's claim hygiene (row J: the id is the claim; row I: a presence assertion binds words, not claims). Claim discipline: the pinned threat set is the review's deterministic drives (the stop landing while the visible command runs, and after the observation); a same-instant race beyond the check-before-emit claim is named in `SHAPES`, not hidden. `REV` names the step's base — the parent of this brief commit — and is not claimed to be `FINAL`'s parent (F4's lesson).

INHERITED:

From `docs/research/phase5-run-entry-fixes-3-implementer.md`, its `INHERITED` block verbatim:

  INHERITED:
  none — every received INHERITED item (F26, F27, F28) is fixed by this step; nothing is carried.

From `docs/research/phase5-run-entry-fixes-3-review.md` — the report is outside `report.txt`'s shape and has no `INHERITED` block to copy (see `record.md#observations`), so its carried set is moved verbatim from its `FINDINGS` section:

  **F29 (P1, origin: code) — the mid-run-cancel operator class falsifies the exit gate's
  document contract and leaves the durable log unreplayable.** The failure reproduced in
  every drive attempted: the full-gate class-4 drive, two race-driver drives at FINAL
  (delays 2s and 4s), one isolated drive, and twice at `REV 6ad0989` with the same script —
  pre-existing, not a regression of this step's work; the F27 guard is nowhere in the trace.
  Drive: a launcher runs `python3 scripts/orchestrate.py start --spec … --workdir … --store …`
  (visible command `sleep 15`/`sleep 30`, `wall_clock_seconds: 60`);
  while the visible command is running a second process runs the documented `stop`
  (`python3 scripts/orchestrate.py stop --run-id RUN …`): the stop exits 0 and records the
  cancellation (`CANCELLATION_CONFIRMED`, `ATTEMPT_COST_SETTLED_CONSERVATIVELY`,
  `NODE_CANCELLED` — seqs 9–11), and the launcher — whose in-memory projection never observes
  the second process's admissions — continues the live lifecycle on its own stale
  projection: `DISPATCH_ACKNOWLEDGED`, `EXECUTOR_OBSERVATION_ADMITTED`,
  `ATTEMPT_EXECUTION_ENDED_UNRECONCILED`, `ATTEMPT_COST_RECONCILED`, `RESULT_ADMITTED`,
  `ARTEFACT_ADMITTED`, `ARTEFACT_INTEGRATED`, `EVIDENCE_ADMITTED`, `VALIDATION_STARTED`,
  `VALIDATION_PASSED`, `ACCEPTANCE_AUTHORISED` (seqs 12–22) are all admitted; the launcher
  exits **0** with JSON `accepted: true`, outcome `ACCEPTANCE_CLAIMED` — a cancelled run, so
  the documented contract ("`start` exits zero when acceptance was authorised and non-zero
  for every non-accepted class — a recorded refusal, a **cancelled run**, or a timed-out
  attempt") is falsified. Worse: the durable log is **unreplayable** — any new connection
  (`inspect`, a recover, a fresh `EventStore`) raises `ReducerError:
  ARTEFACT_INTEGRATED: unknown artefact_id 'RUN-…-artefact'` (`reducer.py:908`, via
  `store.py:133`'s `_replay_all`), because on the replay the cancellation already reached the
  node and the artefact-registration branch the live (stale-cache) path had taken cannot
  recur. The documented `inspect` head — "It admits no events and is safe against a run
  another process started" — exits 1 with a traceback. So of the exit gate's contract
  sentences: "each a settled terminal outcome, the documented JSON and exit codes, no
  traceback, document == durable fresh outcome" — falsified-with-reproducer (the terminal
  outcome is `ACCEPTED`/claims-accepted instead of cancelled; the exit code is 0 instead of
  1; a documented head traces back — though not the launcher itself; and "document ==
  durable fresh outcome" fails harder: the durable fresh outcome is not computable at all).
  The committed interleave pins cover the settle machinery's cross-connection order;
  this class — the stop of a second process landing against a **purely live exec** — is
  unpinned. Carried: F29 stays P1 until a next brief either orders the launcher's every
  execution-phase admission against a fresh read (the F20 triple-read discipline applied at
  the live `DISPATCH_ACKNOWLEDGED`/observation boundary, not only at the settle seam), or
  re-edges the machine's cancellation-concurrency contract — and pins the class
  (subprocess-level, like the old `cancel-race` drives, never an in-process double-`stop`
  alone).

  **F30 (P2, origin: report) — the implementer report's `SHAPES: none` claims hand
  measurements as covered shapes, and one claimed-unchanged facet actually changed.**
  Evidence: (i) the key mutant — both modules pass 40/40 with the shared key changed at all
  three emit sites — proves no committed test pins the dedup/settle-once/late-retention
  facets of `mark_infeasible`; (ii) the zero-fingerprint terminal-run late call — the
  fixes-2 review's answer-2 drive — now raises under the guard (behaviour changed), so
  "unchanged as measured by the fixes-2 review" is false for that drive; (iii) the brief's
  shape names all three facets and the brief's rule says every named shape needs a test.
  Carried: the three facets' pins — or an honest `SHAPES` naming them unbuilt and naming the
  behaviour change — in the next brief.

  **F31 (P2, origin: code) — the absorbed F28 pin's node id
  `test_review_f28_documented_bare_command_is_executable` misstates the enforced
  property** (the id claims the documented bare command is executable; the pin enforces "no
  bare head documented and the documented `python3` form runs"). The docstring is honest;
    the claim-bearing id is not (and the id's claim is the opposite of the pin's own
    `assert not head.startswith(...)`). Carried: rename the node id in the next brief — the
    id is the claim (F24's honesty rule) — with the docstring unchanged.

  **F32 (P2, origin: code) — the F28 pin's prerequisite sentence assertion binds word
  presence, not the named claim** (row I's vacuous-truth class): `"yaml" in section` and
  `"python3" in section` are already satisfied by the argument shape inside every head
  (`--spec RUN_SPEC.yaml` and the `python3` interpreter), so the pin stays green through both
  mutants (a `json`-naming prerequisite sentence; deletion of the new sentences). Carried:
  bind the claim (e.g. the pin parses the sentences' heads separately from the argument
  shapes), or drop the assertion and rely on the module docstring — but then say so.

IN SCOPE: src/orchestrator/run_entry.py, src/orchestrator/reducer.py, docs/run-entry.md, tests/test_run_entry.py, tests/test_phase5_run_entry_fixes_2_review.py

RESIDUALS:

Rule 3 selection for this brief's `IN SCOPE`, copied verbatim from `docs/residuals.md` and byte-verified against it (fenced so the store's relative evidence links are not re-resolved from this directory): `IN SCOPE` matches `PILOT-R1`'s trigger globs (`src/orchestrator/reducer.py`); `PILOT-R2` and `PILOT-R10` (`planning_pilot.py`, `controller.py`, `decomposition.py`) do not match and do not ride.

```
| ID | State | Trigger | Risk | Rationale | Evidence |
| --- | --- | --- | --- | --- | --- |
| `PILOT-R1` | accepted | `src/orchestrator/planning_pilot.py`, `src/orchestrator/controller.py`, `src/orchestrator/reducer.py` | mutable admitted payload (wiring constraint): the caller holds a mutable reference to the admitted payload, and a post-return mutation of a child's scope survives the reducer's re-validation. Any integration must therefore not mutate a payload between the guard and event admission. | the admitted payload is mutable; the reducer's re-derivation runs at admission and on replay, so the guard's result is only as safe as the wiring keeps it | [pilot re-review 3](research/phase4-recursive-planning-pilot-re-review-3.md) |
```

A tripped trigger is a finding: fixed with red evidence, or carried into the closeout with its reason. `scripts/check-scope` prints the `tripped: <ids>` line your report's `TRIPPED` field copies. `PILOT-R1` stays accepted: this brief admits no decomposition and mutates no admitted payload (the reducer's pair change touches the late-retention branches only).

OUT OF SCOPE:
- Editing this brief file (`docs/research/phase5-run-entry-fixes-4-brief.md`). A committed brief is never modified; a re-cut is a new file.
- The controller stack: `src/orchestrator/controller.py`, `store.py`, `executor.py`, `executor_protocol.py`, `command_executor.py`, `acceptance_checks.py`, `schemas.py`, `glossary.py`, `experiment_target.py`, `derive_obligations.py`, `scripts/orchestrate.py`, and the experiment harness (`experiment.py`, `experiment_spec.py`, `experiment_phases.py`, `trial_driver.py`, `hidden_oracle.py`, `scripts/smoke_run.py`, `scripts/stress_run.py`). If one of these must change, stop and report `IN SCOPE` as insufficient. The fresh reads are the launcher's own between-call reads through `controller.store.replay_fresh` — no new `Controller` surface.
- No `docs/tables/*` change and no table regeneration, no `docs/event-catalogue.md` change and no new event type, no `docs/control-plane.md` edit, no `docs/residuals.md` or `docs/record.md` edit, no `docs/self-host.md` edit, no `docs/method.md` or `docs/templates/` edit. `docs/run-entry.md` may sharpen the `start` contract sentence to name the settled outcome the exit code keys on; it is not otherwise reshaped.
- The Exec F2 guard's purpose stands: a cancelled or failed attempt's candidate is never integrated and never published. Only the retained-admission pair's consistency changes, inside `reducer.py`.
- `mark_infeasible`'s precondition (`state.failure_fingerprints[node_id]` non-empty), `evaluate_repeated_failure`, `record_failure`'s fingerprint material, and the `infeasible-{node_id}` idempotency key stay unchanged (F30's pins bind the behaviour as measured; they do not re-shape it).
- Model-produced candidates and recursive decomposition driving (unchanged): `start` drives the root's execution only.
- Registry and control files: `tests/open_defects.yaml`, `tests/counterexamples.yaml`, `tests/guard_mutation_matrix.yaml`, `tests/fixture_fidelity.yaml`, `tests/verifier_registry.yaml`, `tests/spend_paths.yaml`, `tests/invariants.py`, `tests/helpers.py`, `pytest.ini`, tool configuration.
- No new dependencies, no tooling configuration, no reformatting. No new exception class or `*Executor`/`*ModelClient` class and no provider-registry registration. No new arm and no `docs/tables/limits.yaml` change.
- Name no test `test_bug_*` (the open-defect registry would then own it).
- Do not mutate an admitted payload between the guard and event admission.

ACCEPTANCE: Commands (run every one and paste what each prints into `VERIFIED`; expected result is green, exit 0, for each):

    scripts/check-tests --fast
    .venv/bin/python -m pytest tests/test_run_entry.py tests/test_phase5_run_entry_fixes_2_review.py
    .venv/bin/python -m pytest tests/test_milestone2_conformance.py
    .venv/bin/python -m pytest tests/test_phase3_project_oracle.py
    scripts/check-static
    scripts/check-docs
    scripts/check-scope 5711e48a57dcd9df9184083009be720bd20cd7bf <FINAL> docs/research/phase5-run-entry-fixes-4-brief.md

Every `pytest` line names `.venv/bin/python -m pytest` deliberately (F17's carried correction: the bare `pytest` on PATH has no `pytest-timeout` and `pytest.ini`'s `strict_config = true` rejects it on this host — run these lines exactly as written and claim them under these names). `tests/test_milestone2_conformance.py` is named because the reducer's late-event surface changes. `tests/test_phase3_project_oracle.py` is named under the standing rule for `tests/` changes. Never put a full run in `ACCEPTANCE`; the reviewer runs `scripts/check-tests`. `REV` below names the step's base — the parent of this brief commit — and is not claimed to be `FINAL`'s parent (F4's lesson).

Red evidence at `REV` `5711e48a57dcd9df9184083009be720bd20cd7bf` (command `scripts/check-tests`; each unit must be replayable): the suite is green at `REV` (measured here: `scripts/check-tests --fast` 961 passed, 85 deselected, 70.83s; `scripts/check-tests` 1046 passed, 454.16s; `scripts/check-docs` 352/352 links, 0 errors; `scripts/check-static` exit 0), so each red is written by this step and demonstrated at `REV` against the unfixed code (scratch copy diff-verified against `git show 5711e48a57dcd9df9184083009be720bd20cd7bf:…` before use). `FIXED` names the pin's node id, the command, the named failing assertion, and the delivered file's line numbers or none (F22's lesson). Named reds to produce: the cancel-race class pin (F29 — at `REV` the launcher's `start` exits 0 with `accepted: true` and `outcome: ACCEPTANCE_CLAIMED` while the documented `inspect` head traces back on `ReducerError`; the pin asserts non-zero exit, `accepted: false`, `CANCELLED`, no traceback on either process, and `inspect` clean and equal to a fresh connection's replay); the stale-admission replay pin (F29's log half — at `REV` the race order's replay raises `ReducerError: ARTEFACT_INTEGRATED: unknown artefact_id …`; the pin asserts the same order replays to `CANCELLED` with no `ReducerError` and without integrating the cancelled attempt's candidate, while a genuinely unknown `artefact_id` still raises). F30, F31, and F32 close `no regression test` (green-at-both drift guards): the three facet pins bind behaviour that already holds at `REV` (settle-once, dedup on `infeasible-{node_id}`, the with-fingerprint terminal late retention) plus the zero-fingerprint refusal the F27 guard already enforces; the F28 pin's rename is claim hygiene; the strengthened prerequisite assertion is green at `REV` and its two review mutants go red at `FINAL`.

Slow-mark convention: every case in `tests/test_run_entry.py` and `tests/test_phase5_run_entry_fixes_2_review.py` stays slow-marked by each module's existing `pytestmark = pytest.mark.slow` (`src/orchestrator/project_oracle.py:731`'s internal gate runs `scripts/check-tests --fast`, and the pre-commit hook deselects the same way); no new module is needed — put the pins in the existing ones.

Named shapes to build — the list of shapes, not the number of tests. One shape needs at least one test, and every named shape needs one:

- `Cancel-race class shape` (F29): the subprocess-level class pin — a launcher running the documented `python3 scripts/orchestrate.py start …` form against a real frozen repository with a long visible command, a second process running the documented `stop --run-id …` form mid-run, then: `start`'s JSON carries the durable fresh outcome (`accepted: false`, `outcome: CANCELLED`), its exit is non-zero, no traceback on either process, the documented `inspect` head runs clean on the produced store and its outcome equals a brand-new connection's `replay_fresh`, and every new connection replays the log with no `ReducerError`. The review's deterministic drives (the stop landing while the visible command runs, and after the observation) are the pinned threat set; any same-instant race beyond the check-before-emit claim is named in `SHAPES`, not hidden.
- `Stale-admission replay shape` (F29's log half): a durable log containing the race order (the second process's `CANCELLATION_CONFIRMED`/`NODE_CANCELLED`, then the launcher's execution-phase admissions through `ARTEFACT_ADMITTED`/`ARTEFACT_INTEGRATED`) replays to `CANCELLED` with no `ReducerError` and without integrating the cancelled attempt's candidate (Exec F2's guard intact — retained, the artefact never advances); a genuinely unknown `artefact_id` (never admitted anywhere in the log) still fails closed with `ReducerError`. The existing conformance set stays green.
- `Guarded-surface shape` (F30): `Controller.mark_infeasible`'s three facets as pins beside the absorbed F27 probe: an accepted lineage settles exactly once (one `NODE_MARKED_INFEASIBLE`, `READY → INFEASIBLE` via `any_non_terminal`), a duplicate call dedupes against the shared `infeasible-{node_id}` key (history +0), a late call with a recorded failure on a terminal run is retained with no outcome rewrite — and the behaviour the F27 guard changed is named: a zero-fingerprint call on a terminal run refuses (`WorkflowError`, node and outcome unchanged) instead of retaining late. The precondition and the key are unchanged.
- `Runnable-doc pin shape` (F31, F32): the absorbed F28 pin's node id names the property it enforces (every documented head is the `python3` form and runs as written; no bare head is documented), its docstring's meaning unchanged; the prerequisite sentence's assertion binds the claim (a mutant naming only `json`, and a deletion of the sentence, both go red), not word presence (row I's vacuous-truth class: `"yaml" in section` matches `RUN_SPEC.yaml` inside the heads' own arguments). Either strengthen the assertion (parse the sentence's heads separately from the argument shapes) or drop it and rely on the module docstring — but say which in the report.

REV: 5711e48a57dcd9df9184083009be720bd20cd7bf
CLOSE OUT: yes
DIVERGENCES: none
REVIEW: one session — attack the cancel-race class pin's subprocess drive and the document == durable fresh outcome guarantee (including the documented `inspect` head and the fresh replay), the stale-admission pair's Exec F2 retention and fail-closed unknown-id shape, and F30–F32's pin claims (the three facets' bindings and the F28 pin's id and prerequisite assertion).

You implement one brief. You do not plan, re-scope, or decide what the work is. Read every file
in IN SCOPE before editing it; if what you find contradicts the brief, report that instead of
guessing. Modify only what IN SCOPE names. If you find uncommitted changes in the tree, stop and say
so. Stop and report rather than improvise when IN SCOPE is
insufficient, the brief contradicts the code, you have already failed twice at this goal, or the
requirement is ambiguous and no single reading is consistent with the rest of the brief. If exactly
one reading is consistent, take it and file a FINDING with ORIGIN: BRIEF that names the reading you
took. No new dependencies, no tooling configuration, no reformatting. Run every ACCEPTANCE command;
fix what is in scope and report what is not.

A defect in the brief is a FINDING, never METHOD FRICTION. METHOD FRICTION is only for the method and
its templates: any place you deviated from them, found them ambiguous, or found them silent. Report
friction you worked around — that is the section the method learns from.

Commit your own work. When ACCEPTANCE passes, commit the files you changed, and only those, in one
commit whose message ends with the trailer `Actor: IMPLEMENTER`. That commit's full sha is FINAL.
Then append docs/templates/report.txt verbatim, fill it in, write it to
docs/research/<phase>-<subject>-implementer.md, and commit it in a second commit with the same
trailer. Do not amend the first commit to add the report: FINAL must not change after the report
names it. If you cannot commit, stop and say so; do not leave work uncommitted for someone else to
commit.

# report.txt

REPORT — <phase>-<subject>-<role>
STEP: <implementer brief subject>
REV: <copied from the brief's REV — the step's base, not FINAL's parent>   FINAL: <implementer: sha of your work commit, never the commit that holds this report;
  reviewer: the sha under review, copied from the review brief>
CHANGED: <files, one line each>
VERIFIED: <command, duration, counts>
         Every VERIFIED and ACCEPTANCE claim names the command that actually ran — never a
         substituted interpreter, wrapper, or narrowed form. If the documented form cannot run in
         your environment, record both commands and the documented form's separate check.
NOT VERIFIED: <why, or none>
FINDINGS: none | one block each:
  ID | SEVERITY: P0|P1|P2 | ORIGIN: BRIEF|CODE|DOCUMENT | STATE: fixed|declined|carried
  <root cause, one line>
  FIXED: <node id, command, and the named failing assertion at REV — or "no regression test">
         An error or a collection failure is not red. The assertion has to be the thing that
         failed; a run that merely crashed proves nothing.
  STATE means: fixed (above); declined = not a defect, with the reason; carried = a real defect
  left unfixed, passed on in INHERITED. A defect you will not fix now is carried, never declined.
  An ORIGIN: BRIEF finding is fixed once a later committed brief corrects the text: FIXED: names
  that brief's commit and reads "no regression test". Carried means a future actor has something to
  do with it; at closeout a finding with no possible next action is closed — a defect in an
  already-committed report reads FIXED: recorded in the review that filed it, and an authoring
  lesson from a finished brief goes into record.md's Observations.
SHAPES: <shapes probed that the suite does not build, or none with a reason>
TRIPPED: <copied from check-scope's tripped: line>
PROPOSED ROWS: <ledger rows, or none>
METHOD FRICTION: none | <where you deviated from the method or its templates, misread them, or
  found them silent. A defect in the brief is a FINDING, not friction.>
INHERITED:
<<every INHERITED item you received that is still open, copied verbatim; then each
  finding you marked carried, with its ID>>
Rule 2 governs the planner's copy of this block. What goes in it is yours: an implementer or
reviewer who received an obligation, finding, entry or trigger carries it forward verbatim, and
adds anything new that is still open. A block reading `none` is correct only when nothing came in
and nothing is open. INHERITED never carries residual rows; they are re-selected from the store per
brief.
