<!-- informative -->

# Re-review 2: bounded recursive-planning pilot — admission guard

Revision reviewed: **`ec46486`** (detached worktree `/tmp/kilo/pilot-rr2`), the fix
for [re-review 1](phase4-recursive-planning-pilot-re-review.md).
Verdict: **GO for the producer on the guard.** RR1–RR4 are closed, the earlier
findings (F2, F3, F6, F8) still hold, and the one remaining structural issue (F1,
single-layer containment) stays an accepted, pinned decision. Residuals below are
non-blocking.

Baseline on `ec46486` (confirmed independently): **844 passed**;
`scripts/check-tests --fast` **814 passed, 30 deselected**; `scripts/check-docs`
rc 0; `scripts/check-static` rc 0; working tree clean.

## RR1–RR4: verified closed

- **RR1 — closed.** `_node_depth_from_state` now calls
  `Controller._node_depth` (`planning_pilot.py:202-215`) instead of re-implementing
  the walk, so the class of bug is removed rather than this instance. Probe on a
  `root→mid0→…→p` chain: the guard and the controller agree for every node.
  Boundary is correct: a parent at controller depth 1 is admitted, a parent at
  depth **2** (a grandchild) is refused ("parent is at depth 2 …"). The regression
  test the re-review asked for exists and compares against the controller, not the
  guard: `test_derived_depth_agrees_with_the_controller` and
  `test_a_root_child_reads_depth_one_not_zero`.
- **RR2 — closed.** Spec P2 now names the reducer child shape (`node_id`,
  `mandatory`, `criterion_ids`, `contract.owned_scope`,
  `contract.acceptance_criteria`, `contract.budget_id`, `budget_allocation`) and
  says it is "the shape `validate_decomposition` consumes"
  (`phase4-recursive-planning-pilot-spec.md:63-69`). The commit-message explanation
  (a discarded heredoc edit) is consistent with the diff.
- **RR3 — closed.** `parent_budget=None` now falls through to the ledger
  (`planning_pilot.py:304-312`): a child within the registered limit is admitted, a
  child over it is refused, and a parent with no registered budget is refused
  ("is not registered"). A stated budget still goes through the validated
  per-dimension checks, so the falsy/`NaN`/non-mapping refusals persist.
- **RR4 — closed by removing the opt-out.** `state` and `parent_node_id` are
  required: omitting either (or both) raises `DecompositionError` ("the pilot path
  requires the replayable state and the parent node id"), not `TypeError`. Parent
  scope and budget are derived from the node contract and the ledger, and a stated
  value that disagrees is refused ("the declared scope is authoritative" / "the
  derived depth/count is authoritative"). The ceiling is now derived, so the
  under-report and split-call evasions from re-review 1 no longer apply to the
  pilot path.

## Earlier findings: still hold

- **F2/F3** — falsy/non-mapping stated parent budgets are refused; `NaN`/`inf`/
  non-numeric limits are refused. (Verified.)
- **F6** — `copy.deepcopy`; mutating a returned child no longer touches the
  caller's nested objects. (Verified.)
- **F8** — one shared `decomposition.scope_contained`; `..`, empty, and all-glob
  parents are refused; guard and declared validator agree. (Verified.)
- **F1** — still single-layer and still accepted. `validate_decomposition` accepts
  a `src/evil/x.py` child under a `src/good/**` parent (verified directly), the
  corpus claim is true, and `TestContainmentIsSingleLayer` pins it. The
  deep-copy plus the now-derived parent scope mean the guard's one check is
  checked against the parent's real contract rather than a caller's claim.
- **F7 / F10** — recorded, unchanged (record_outcome still unwired by the guard;
  `_nesting_shape` still one level).
- **Guarantees 1, 3, 9, 10** — unchanged; guarantee 10 re-verified end to end
  (patched derivation to nest: rename → no `NESTING`; add/remove/re-parent →
  `NESTING`).

## Residuals (non-blocking)

- **R1 — multi-scope parents use only `owned_scope[0]`.** A parent declaring
  `["src/a/**", "src/b/**"]` refuses a legitimate child in `src/b/**` ("escapes
  its parent's scope 'src/a/**'"). This is conservative (narrows, never widens), so
  it is not a safety hole, but a parent with several scopes loses the others. If
  parents can own more than one scope, check "contained in any", not the first.
- **R2 — a bare `**` parent permits no children.** `scope_contained(child, "**")`
  is `False` by F8's explicit choice ("a parent that owns nothing cannot authorise
  a child"). The fixed target uses `src/**` (which is fine); a run whose root owns
  a bare `**` could not use the pilot. Worth a line in the spec so it is a known
  limitation rather than a surprise.
- **R3 — the depth-boundary test overshoots.** `test_a_parent_at_the_pilot_depth_may_not_propose`
  uses `chain_depth=2`, which the corrected helper places at controller depth **3**,
  not 2. So the exact boundary (`depth == MAX_PROPOSAL_DEPTH` refused) is not pinned
  by a test, though the code is correct (verified: depth 2 is refused). Use
  `chain_depth=1` for the boundary.
- **R4 — diagnosis ordering on an empty proposal.** The scope/budget derivation
  runs before the empty check, so `admit_proposal([], state=…)` against an
  unregistered parent budget reports "is not registered" rather than "at least one
  child". Cosmetic; consider checking `not proposed` first.
- **R5 — private-API coupling.** The guard now calls `Controller._node_depth`
  (a private method). A test pins it, so a rename fails loudly; acceptable, but a
  public `controller.node_depth(state, node_id)` would be cleaner.
- **R6 — minor:** the commit message cites "the same failure mode the first review
  caught in F11"; neither review had an F11 (the first had F1–F10), so the
  reference is off. Cosmetic.

## Verdict

**GO.** Every pilot bound is now derived from replayable state or a table, any
caller-stated bound is checked against the derived value, and the depth matches the
controller by construction and by test. The producer may land on this guard. The
single-layer containment decision (F1) is accepted with the evidence and a pin;
F7 and F10 remain recorded. R1–R2 are worth a spec sentence before the producer
relies on multi-scope or whole-repo parents.

## Reproduce

```
git worktree add --detach /tmp/kilo/pilot-rr2 ec46486

PYTHONPATH=/tmp/kilo/pilot-rr2/src <venv>/python /tmp/kilo/pilot-probes/rr2_probe.py   # RR1-RR4, F2/F3/F6/F8
PYTHONPATH=/tmp/kilo/pilot-rr2/src <venv>/python /tmp/kilo/pilot-probes/p1_nesting.py  # guarantee 10

.venv/bin/python -m pytest -q                                  # 844 passed
.venv/bin/python -m pytest -q tests/test_planning_pilot.py      # 59 passed
scripts/check-docs ; scripts/check-static ; scripts/check-tests --fast
```

The F1 single-layer check is a direct `validate_decomposition` call on a
constructed `RunState` (parent owns `src/good/**`, child owns `src/evil/x.py`,
returns `None`). No model, network, or credentials; the `.venv` symlink only lets
the four oracle tests spawn `ruff`/`python`.

## Implementer's response (2026-09-30)

**GO** accepted for the producer. R1 and R3 are fixed, R2 and R4 are recorded or
ordered, R5 is cleaned up. **848 passed**; `scripts/check`, `scripts/check-static`
and `scripts/check-docs` all rc 0 (250 links).

**R1 fixed.** A parent may own several disjoint scopes, and containment is now
"inside *any* of them" rather than "inside `owned_scope[0]`". The review is right
that the old behaviour was conservative rather than unsafe — it narrowed and never
widened — but it was wrong about a parent that legitimately owns more than one
region, and a proposal into the second region was refused. Pinned both ways: a
child in the parent's second scope is admitted, a child outside every declared
scope is still refused.

**R3 fixed, and the review is right that the boundary was unpinned.** The
boundary test used `chain_depth=2`, which the corrected helper places at controller
depth **3**, so `depth == MAX_PROPOSAL_DEPTH` was never exercised. The overshoot
is corrected and a new test asserts the boundary number explicitly rather than
only the refusal, so an off-by-one in the helper can no longer hide behind a test
that happens to pass.

**R4 fixed.** The empty-proposal check now runs before the scope and budget
derivation, so `admit_proposal([])` reports "a proposal must declare at least one
child" instead of whichever bound happened to fail to resolve first. Pinned with a
parent whose budget is unregistered, which is the case that previously masked the
diagnosis.

**R5 addressed.** `Controller.node_depth(state, node_id)` is now public and
delegates to `_node_depth`; the guard calls the public form. The reviewer called
the private coupling acceptable, and it is now not a coupling to a private name at
all. The existing comparison test still pins the two agree.

**R2 recorded, deliberately not changed.** A run whose root owns a bare `**`
cannot use the pilot, because `scope_contained` refuses an all-glob parent prefix.
Widening the rule to admit `**` would undo the deliberate F8 choice that a parent
owning nothing cannot authorise a child, so this is a known limitation written
into the spec's residual section with the reasoning, rather than a surprise. The
fixed target owns `src/**` and is unaffected.

**R6: the review is right and I cannot fix it in place.** My commit message cited
"the same failure mode the first review caught in F11"; there is no F11 — the
first review ran F1–F10 and the off-by-one self-reference is F11 only in the
option (e) chain, a different document. The commit stands as written; this
response is the correction.
