IMPLEMENTER BRIEF — phase4-recursive-planning-integration-fixes (Phase 4: the continuation fixes — the CHILD_OF depth walk and the full-suite profile leak)

GOAL: F1 fixed: `Controller.node_depth`/`_node_depth` walks CHILD_OF parentward (`from_node_id == current` steps to `to_node_id`, matching the production write `from_node_id=child, to_node_id=parent` at `Controller.propose_decomposition`'s `RELATION_RECORDED` and the reducer's `children_of`), so `MAX_PROPOSAL_DEPTH` and the admission-time `maximum_depth` checks bind in production. F5 fixed: the routing module's shapes hold under the sanctioned full-suite module ordering, with no module leaking a mutated `experiment.MODEL_PROFILE` or `MODEL_CLIENT_FACTORY` binding. The three red shapes in `tests/test_review_depth_walk.py` are absorbed as maintained pins of the enforced property (they pass and stay). F2–F4 change no code in this step; they ride `INHERITED` under owner ruling R6.

CONTEXT: Owner ruling R5 (`docs/record.md`) names this brief and its contents; R6 settles F2's meaning as transit immutability (the shape's re-wording rides the later API-shape brief, not this one), F4's root as range hygiene (`REV` names the step's base and is never claimed to be `FINAL`'s parent; between `REV` and `FINAL` the only planner commit is this brief and it touches only this file), and CLOSEOUT ownership (your report ends at `INHERITED`; the CLOSEOUT stanza is the planner's alone). Red at `REV` under `scripts/check-tests`: 5 failed, 990 passed — F1's three probe shapes and F5's two routing parametrisations (named under Red evidence below). F1's remedy is the walk direction in `src/orchestrator/controller.py` and whatever the pilot's depth read needs beside it (`src/orchestrator/planning_pilot.py`'s `_node_depth_from_state` and its bound refusal); the pilot's own fixtures hand-build relations in the inverse direction (`tests/test_planning_pilot.py:183-184, 560-561, 573-574`) and must be corrected to the production direction. F5's remedy is binding hygiene: the routing fixture pins its profile and resets `MODEL_CLIENT_FACTORY`, and the phase-2 leak's `finally` restores the pre-mutation binding it captured instead of re-reading the mutated delegated `experiment.MODEL_PROFILE`.

INHERITED:

From `docs/research/phase4-recursive-planning-integration-provider-implementer.md`:

F1 | SEVERITY: P1 | ORIGIN: CODE | STATE: carried — `Controller.node_depth` walks CHILD_OF in the wrong direction, so the pilot's depth bound and the controller's maximum_depth limit are vacuous in production (out of scope; see FINDINGS).

From `docs/research/phase4-recursive-planning-integration-provider-review.md`:

F1 | SEVERITY: P1 | ORIGIN: CODE | STATE: carried
  From the implementer's report, verified here with additional reproducing evidence: depth of a node read from CHILD_OF walks the wrong direction (src/orchestrator/controller.py:178-193), never more deeply than one level; `MAX_PROPOSAL_DEPTH=2` and per-admission `maximum_depth` checks are vacuous at proposal time in production (the proposing parent always reads 0), so the pilot's depth guard and the controller's maximum_depth run limit never enforce; the pilot's own tests are blind (hand-built relations are written in the inverse direction; confirmed in tests/test_planning_pilot.py:183-184, 560-561). A depth-unbounded provider would be ADMITTED at any proposal seam (pinned RED: tests/test_review_depth_walk.py::test_the_pilot_depth_guard_never_refuses_a_node_at_depth_two; report's original reproducing evidence as a relation dump matches).
F2 | SEVERITY: P2 | ORIGIN: BRIEF | STATE: carried  (state re-assigned by this review from the implementer's declined)
  The brief's No-mutation shape as written is unsatisfiable: the event's children carry `const parent_proposal` (and the controller's defaults), which the guard's return cannot (verified: tests/test_planning_pilot_routing.py:321-322 vs controller.py:742). The single consistent reading ("the driver forwards the producer payload without editing it; the dependency edges go through the dependencies argument") is implemented and pinned by the delivered test; the literal shape text stands as written in the frozen brief. Closeout: carried, not declined; the wording belongs to an OWNER/planner re-wording, and the next implementer brief at this seam inherits the pinning test and the divergence explanation.
F3 | SEVERITY: P2 | ORIGIN: BRIEF | STATE: carried
  The implementer brief's acceptance note omits the slow-mark convention for new test modules under tests/, on which its own named oracle command's green depends (verified mechanically: pytest.ini's `slow` marker, `check-tests --fast` = `-m "not slow"`, the oracle's internal gate at src/orchestrator/project_oracle.py:731, the deselecting pre-commit hook, and measured-green constructive half on this host). Misfiled as METHOD FRICTION by the implementer; re-filed here as the brief defect it is. The counterfactual half (unmarked module breaks the oracle) is NOT VERIFIED — nested-oracle scratch unfaithful on this host.
F4 | SEVERITY: P2 | ORIGIN: BRIEF | STATE: carried
  The implementer brief's `REV:` field names the pre-brief HEAD (1a4c0a7...) which cannot be this step's base (its brief commit consumes R2 in docs/record.md, so check-scope over that sha fails: "docs/record.md is in the diff and not in IN SCOPE"); the implementer's report propagated the field as its base claim — a claim not declared against its source, which stands (the work's actual base is 2b269fc, afc5316's parent). The next implementer brief's REV must name the revision the implementer builds on, and a copied verbatim field must at least be confirmed to name an ancestor-parent of the work's commit before it is claimed.
F5 | SEVERITY: P1 | ORIGIN: CODE | STATE: carried
  As delivered, the routing module's two parametrised routing-shape tests fail under the full suite on this host, deterministically, 3/3 runs (990 passed/5 failed each), because the fixture reads the session-mutated `experiment.MODEL_PROFILE` global that `test_phase2_general_target.py` leaks (its finally restores by re-reading the mutated delegated binding). Minimal pair repro: 2 failed / 17 passed in 31.40s; enabling path measured from the binding history log and the failed trial stores (empty-patch replies → "path field 'path' must contain non-empty strings" rejections at src/orchestrator/model_adapter.py:306 → trial abort with one instead of two DECOMPOSITION_ADMITTED). Counter-mutant with the profile pinned in the delivered file: 19 passed / 34.53s. Remedy surface: the delivered test file (pin at import/fixture entry, reset `MODEL_CLIENT_FACTORY`) and the pre-existing phase-2 leak; the next implementer brief inherits both.

Residuals selected by `IN SCOPE` per rule 3 and owner ruling R5, copied verbatim from `docs/residuals.md` (fenced so the store's relative evidence links are not re-resolved from this directory; the rows' text, triggers included, is the store's own):

```
| 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) |
| `PILOT-R2` | accepted | `src/orchestrator/decomposition.py`, `src/orchestrator/planning_pilot.py` | single-layer containment (F1): scope, budget and bounds admit exactly one recursive level; deeper proposals are legitimate work the guard will refuse | the pilot's mandate is deliberately one level deeper than FIXED_ONE_LEVEL and no more | [pilot re-review 3](research/phase4-recursive-planning-pilot-re-review-3.md) |
| `PILOT-R3` | accepted | `src/orchestrator/model.py`, `src/orchestrator/planning_pilot.py` | `RunState.clone()` is for replay snapshotting, not authority isolation (deepcopy kept): a future model provider must be handed the isolated `provider_state`, never the live state — if a provider is given the live state it can rewrite its own bounds | the pilot spec's threading warning; the live state was handed over exactly once, at the producer seam | [pilot re-review 3](research/phase4-recursive-planning-pilot-re-review-3.md) |
| `PILOT-R4` | accepted | `src/orchestrator/planning_pilot.py` | `parent_scope` is an assertion, not a restriction: containment is multi-scope and refusal is by comparison with the derived parent, not by trusting the argument. Multi-scope containment reaches only one level — a grandchild of a multi-scope parent may not propose | the contract reads `owned_scope: Sequence[str]` as a plural, and S5.4 in R3 of the option (e) review stands | [pilot re-review 3](research/phase4-recursive-planning-pilot-re-review-3.md), [option (e) review](research/phase4-option-e-review-report.md) |
| `PILOT-R5` | accepted | `src/orchestrator/planning_pilot.py`, `src/orchestrator/decomposition.py` | all-glob parent refused: `scope_contained` treats a bare `**` or `*` parent as a containment failure and refuses every child | conservative rather than unsafe; the fixed target owns `src/**`, so its proposals are unaffected | [pilot re-review 3](research/phase4-recursive-planning-pilot-re-review-3.md), [option (e) review](research/phase4-option-e-review-report.md) |
| `PILOT-R6` | accepted | `src/orchestrator/planning_pilot.py` | proposal content is not derivable (shape only): the checks prove shape, budget, bounds and one level of containment — never that a proposal is the right decomposition. If the future model path validates only shape, a well-formed wrong tree is admitted | the independent oracle and the acceptance grading remain the correctness authority; the guard's job is admissibility, not quality | [pilot re-review 3](research/phase4-recursive-planning-pilot-re-review-3.md) |
| `PILOT-R10` | accepted | `src/orchestrator/controller.py`, `src/orchestrator/planning_pilot.py` | in-process trusted-code circumvention of the admission capability: the capability is not reconstructible from data, but trusted code running in-process can hold or mint one and admit anything — if untrusted code is ever loaded in-process, the capability boundary does not hold | R1's prevention-shape ruling: the capability's threat model is data-only reconstruction, and trusted-code circumvention is recorded here rather than claimed solved | [owner rulings](record.md#owner-rulings) (R1) |
```

R5's re-note on `PILOT-R2`: its "bounds admit exactly one recursive level" enrollment is measured-unenforced until F1 is fixed. F1 is fixed in this step; once the depth pins are green the enrollment is measured-enforced again, and the carried note records the interval.

IN SCOPE: src/orchestrator/controller.py, src/orchestrator/planning_pilot.py, src/orchestrator/experiment_spec.py, src/orchestrator/experiment.py, tests/test_planning_pilot.py, tests/test_review_depth_walk.py, tests/test_planning_pilot_routing.py, tests/test_phase2_general_target.py

OUT OF SCOPE:
- `Controller.propose_decomposition`'s API shape: the admission capability, its two mint points, renaming the unguarded constructor — R1's second brief (the API-shape brief follows on a green base). Call it; do not change its signature or its admission normalisation.
- Re-wording the frozen provider brief's No-mutation shape (F2): R6 settled the meaning as transit immutability — the producer payload reaches controller admission unedited in transit; the controller's deterministic admission normalisation (`parent_proposal`, budget defaults) is admission, not transit, and stays pinned by the delivered test. The API-shape brief re-words the shape; this step edits neither the frozen brief nor that pinning test's intent.
- `src/orchestrator/reducer.py`, `src/orchestrator/model.py`, `src/orchestrator/trial_driver.py`, `src/orchestrator/decomposition.py`, `src/orchestrator/derive_obligations.py`, `src/orchestrator/project_oracle.py`, `src/orchestrator/model_adapter.py`, `src/orchestrator/experiment_target.py`. If one of these must change, stop and report `IN SCOPE` as insufficient.
- Any `docs/` file except your report: no `docs/residuals.md` edit (the planner maintains it), no `docs/record.md` edit, no `docs/event-catalogue.md` change, no new event type.
- 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. The absorbed pins need no open-defect registration: R5 dispositions the probe as evidence and its shapes as maintained pins of a defect this step fixes, so the module header's "registration is left to the next implementer brief" is discharged by absorption, not a registry row. If a registry meta-gate demands a row anyway, stop and report.
- No new `*Executor` or `*ModelClient` class and no provider-registry registration (the fixture-fidelity meta-tests); no new dependencies; no new arm; 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
    pytest tests/test_phase2_general_target.py tests/test_planning_pilot_routing.py
    pytest tests/test_planning_pilot.py tests/test_review_depth_walk.py
    pytest tests/test_phase3_project_oracle.py
    scripts/check-static
    scripts/check-docs
    scripts/check-scope f74a9f0a8b236278f765496b80ec6a8238f9384b <FINAL> docs/research/phase4-recursive-planning-integration-fixes-brief.md

Never put a full run in `ACCEPTANCE`; the reviewer runs `scripts/check-tests`. The phase-2/routing pair is F5's minimal-pair repro at `REV` (2 failed / 17 passed there); it is the named acceptance for the leak.

Slow-mark convention (the acceptance note F3 asked for): any new module under `tests/` slow-marks every case (`@pytest.mark.slow`), because the project oracle's internal gate runs `scripts/check-tests --fast` (`-m "not slow"`, `src/orchestrator/project_oracle.py:731`) and the pre-commit hook deselects the same way; unmarked trial-running cases are executed where the oracle runs them and break `pytest tests/test_phase3_project_oracle.py`, which is therefore named above. `tests/test_review_depth_walk.py` and `tests/test_planning_pilot_routing.py` are already slow-marked; keep them that way.

Red evidence at REV f74a9f0a8b236278f765496b80ec6a8238f9384b (command `scripts/check-tests`; each unit is replayable — cite these node ids and named failing assertions in `FIXED:`):

F1's three shapes (tests/test_review_depth_walk.py):
- `test_a_depth_two_leaf_reads_depth_zero_and_the_root_reads_subtree_height` — `assert Controller.node_depth(state, root) == 0` (assert 2 == 0)
- `test_the_pilot_depth_guard_never_refuses_a_node_at_depth_two` — `assert payload is None` (full ADMITTED payload returned instead of the BOUNDS refusal)
- `test_maximum_depth_run_limit_refuses_decomposition_past_the_limit` — `pytest.raises(RunLimitExhausted)` DID NOT RAISE

F5's two parametrisations (tests/test_planning_pilot_routing.py):
- `test_every_recursive_decomposition_routes_through_the_pilot[RECURSIVE_LAZY]` — `assert len(events) == 2, "the fixed target nests exactly two levels"` (assert 1 == 2)
- `test_every_recursive_decomposition_routes_through_the_pilot[RECURSIVE_CONCURRENT]` — same named assertion (assert 1 == 2)

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

- `Depth-read pin` (absorbed shape 1): the root reads depth 0 and a true depth-2 leaf reads 2 — depth walks parentward along `CHILD_OF`; subtree height is not depth.
- `Pilot depth-bound pin` (absorbed shape 2): a proposal made at a true depth-2 node with a valid provider is refused at BOUNDS — payload `None`, `admitted` false, `refusing_stage` `BOUNDS`, `accepted_children` 0.
- `Run-limit pin` (absorbed shape 3): under `maximum_depth: 1`, admitting a second level is refused with `RunLimitExhausted`.
- `Suite-context pin` (F5): the routing module's shapes hold under the sanctioned full-suite module ordering — no binding a trial reads is left mutated by an earlier module. The phase-2/routing pair is the minimal repro; the reviewer's full run is the whole check.
- The seven routing shapes delivered by the provider step stay enforced unchanged; F2's carried re-word does not change what `test_admitted_payload_is_forwarded_unmutated` pins (transit immutability per R6).

REV: f74a9f0a8b236278f765496b80ec6a8238f9384b
CLOSE OUT: yes
DIVERGENCES: none

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. 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: <base sha>   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>
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.
SHAPES: <shapes probed that the suite does not build, or none with a reason>
TRIPPED: <residual ids, or none>
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.
