<!-- informative -->

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

Revision reviewed: **`e70f2d5`** (detached worktree `/tmp/kilo/pilot-rereview`),
the fix commit for the first review
([report](phase4-recursive-planning-pilot-review-report.md)).
Verdict: **still NO-GO.** Six findings are genuinely closed (F2 in part, F3, F6,
F8, and the F4/F5 *mechanism*), F1's refusal is now substantiated by the corpus
and accepted, but the headline fix — F4, deriving depth from `RunState` — computes
the **wrong depth**: it is off by one against `Controller._node_depth` for every
node below the root, refuses truthful callers, and admits proposals one level
deeper than the spec's two. F9 is claimed fixed but the spec text is unchanged.

Baseline on `e70f2d5` (confirmed): **834 passed**; `scripts/check-tests --fast`
**804 passed, 30 deselected**; `scripts/check-docs` rc 0; `scripts/check-static`
rc 0.

## Findings

### RR1 — P1 — `_node_depth_from_state` disagrees with the controller by one level

Guarantee violated: 2 (depth), and the commit's own claim that "the guard now
computes the same thing". `Controller._node_depth` (`controller.py:166-184`)
increments after stepping to the parent, giving root `0`, its child `1`, its
grandchild `2`. `_node_depth_from_state` (`planning_pilot.py:204-229`) breaks
*before* the increment when the parent is the root:

```python
current = parents[0]
if current == state.root_node_id:
    break          # deeper nodes never get the final +1
depth += 1
```

Reproducer (`/tmp/kilo/pilot-probes/rr_depth.py`, a `root→n0→…→n5` chain):

```
node  controller  guard
root           0      0
  n0           1      0   <<< MISMATCH
  n1           2      1   <<< MISMATCH
  n2           3      2   <<< MISMATCH
```

Two consequences:

1. **Truthful callers are refused.** A parent at controller depth 1:
   `caller stated parent depth 1, but the state places 'n0' at depth 0; the
   derived depth is authoritative`. Only a caller passing the wrong (off-by-one)
   number is admitted.
2. **The bound is one level too loose.** The guard allows proposing while its
   derived depth `< 2`; on the chain that is controller depths `{1, 2}` (plus the
   root), so a *grandchild* at controller depth 2 may propose and reach depth 3 —
   where the spec says "A grandchild may not propose"
   (`phase4-recursive-planning-pilot-spec.md:80-83`).

The new tests do not catch it because they use the guard's own function as the
reference: `test_truthful_arguments_are_accepted` passes
`parent_depth=pilot._node_depth_from_state(state, "p")` and
`test_a_misstated_parent_depth_is_refused` builds `chain_depth=2` and asserts the
state places `p` at `2` — the controller places it at `3`. Expected: reuse
`Controller._node_depth` (or its exact loop), and add a regression test that
asserts `_node_depth_from_state(state, n) == Controller._node_depth(state, n)`
for a chain, not just internal consistency. Note also `parents[0]` vs the
controller's `sorted(parents)[0]`; with one parent they agree, but the guard
should match the controller here too.

### RR2 — P2 — F9 is claimed fixed but the spec is unchanged

The commit message says "the spec's proposal child fields now name the reducer's
child shape". The spec still says the model emits "`child_id`, `scope`,
`criterion_ids`, `depends_on`, and `budget`"
(`phase4-recursive-planning-pilot-spec.md:63-64`), while the guard reads
`node_id`, `contract.owned_scope`, `budget_allocation`. The `e70f2d5` spec diff
adds only the scope-containment and F10 residual bullets; the P2 field list is
untouched. Either update P2 or state explicitly that the advisor/producer must
translate the obligation shape into the reducer child shape before calling the
guard.

### RR3 — P2 — F2 is closed for falsy/non-mapping values but `None` still disables the bound

`check_budget_authority` still begins `if parent_budget is None: return`
(`planning_pilot.py:130-131`), and `None` is the **default** argument. So a caller
that omits `parent_budget` gets no pilot budget bound at all; the reducer remains
the only authority. The commit message lists `None` among the cases whose
"truthiness gate … is gone", which overstates the fix. The behavior is documented
in the docstring ("The reducer's … check remains the authority"), so this may be
intentional; if so, say plainly that the pilot budget bound is opt-in rather than
claim `None` was closed. Falsy and non-mapping values other than `None` are now
correctly refused (verified: `0`, `0.0`, `""`, `[]` → "must be a per-dimension
mapping"; `{}` and an omitted dimension → "unbounded"; `NaN`/`inf`/`-1.0`/`"ten"`
→ refused).

### RR4 — P3 — F5's derived count is opt-in and half-honoured

`proposed_children_in_trial` is only consulted when **both** `state` and
`parent_node_id` are passed (`planning_pilot.py:275`). Passing `state` alone, or
neither, silently falls back to the caller-supplied `already_proposed` — under
which the 36-children-across-6-calls evasion still works
(`/tmp/kilo/pilot-probes/p1_ceiling.py`, unchanged). The mechanism is a real
improvement, but it is not mandatory and the spec was not updated to require it.
A producer that omits `state` re-opens F4 and F5. Recommend mandating
`state`+`parent_node_id` for the pilot path (or defaulting them from the
projection) and stating it in P3.

## Verified fixed / accepted

- **F3 — closed.** `parent_budget=10.0` and `[10.0]` now raise
  `DecompositionError` ("must be a per-dimension mapping"), `"ten"` no longer
  raises `ValueError`. The stale scalar in the old test is gone.
- **F6 — closed.** `copy.deepcopy` at `planning_pilot.py:294`; the returned child
  no longer shares `contract`/`budget_allocation` with the caller (probe I now
  shows the caller's child unmutated).
- **F8 — closed.** One shared `decomposition.scope_contained`, delegated to by
  both `planning_pilot.scope_contained` and `experiment_target._scope_contained`;
  it refuses `..`, an empty scope, and an all-glob (`**`) parent prefix. The
  `TestSharedContainment` table passes, including the three divergences from the
  first review. (This does tighten the *declared* nesting validator too; no test
  relied on the previous permissive empty/`**` answers.)
- **F4/F5 mechanism — present but buggy (RR1).** Depth and count are derived from
  state and a disagreeing caller is refused; the count derivation is sound
  (`proposed_children_in_trial`).
- **F1 — refusal accepted.** I verified the corpus: `tests/helpers.py:15` gives
  the run root `src/health/**` and `tests/test_milestone8_readiness.py:374`
  validates a child owning `src/m/**` under it, and
  `scope_contained("src/m/**", "src/health/**")` is `False`. So enforcing
  containment in `validate_decomposition` would reject a proposal the committed
  milestone evidence was measured under; it is a semantic change, not
  defence-in-depth, and declining it is the right call. `TestContainmentIsSingleLayer`
  pins the gap. Recorded residual, not a finding.
- **F7 / F10 — recorded, as stated.** `record_outcome` is still not called by
  `admit_proposal`; `_nesting_shape` is still one level deep.
- **Guarantee 1, 3, 9, 10 — unchanged and hold.** Refusal is still total; fan-out
  is triple-enforced; P1 rename-invariance/structural-sensitivity and the
  end-to-end F2 patch still behave (`/tmp/kilo/pilot-probes/p1_nesting.py`:
  rename → no `NESTING`; add/remove/re-parent → `NESTING`).
- **Pre-existing, unchanged:** `budget_feasibility_conflict` still accepts a
  negative allocation (the guard now refuses negatives, so the guard is
  load-bearing there); the reducer's `validate_decomposition` still accepts an
  escaping child (F1, accepted).

## Claim verification against the commit message

| Claim | Verified? |
| --- | --- |
| F2/F3 falsy/`NaN` budget bound closed; non-mapping refuses | Yes, for all falsy/non-mapping values **except `None`** (RR3). |
| F4/F5 "derived from `RunState`", disagreeing caller refused | Mechanism present; the derived depth is **wrong** (RR1). |
| F6 deep copy | Yes. |
| F8 one shared `scope_contained` refusing `..`/empty/all-glob | Yes. |
| F9 spec names the reducer's child shape | **No** — spec P2 unchanged (RR2). |
| F1 recorded, not fixed | Yes, and the corpus claim is true. |
| F7/F10 recorded | Yes. |
| 834 passed, three gates rc 0 | Yes (834; docs/static/tests-fast rc 0). |

## Updated guarantee status

Guarantees 1, 3, 5, 9, 10 hold; 4 and 6 hold on the opted-in path; **2 is
falsified by RR1** (the guard's depth is not the controller's, and it permits one
level more than the spec); 7 is unchanged from the first review (P4 remains
guard-only, now an accepted documented decision); 8 remains unwired (recorded).

## Verdict

**NO-GO** until RR1 is fixed: reuse the controller's `_node_depth` (do not
re-implement it), and add a regression test comparing the guard's derivation to
`Controller._node_depth` on a chain. RR2/RR3/RR4 are smaller and can land with it.
The single-layer containment decision (F1) is accepted and should stay; the
remaining gate on the producer is the corrected depth derivation, not the
containment question.

## Reproduce

```
git worktree add --detach /tmp/kilo/pilot-rereview e70f2d5

PYTHONPATH=/tmp/kilo/pilot-rereview/src <venv>/python /tmp/kilo/pilot-probes/rr_depth.py       # RR1
PYTHONPATH=/tmp/kilo/pilot-rereview/src <venv>/python /tmp/kilo/pilot-probes/p1_budget_edges.py # RR3
PYTHONPATH=/tmp/kilo/pilot-rereview/src <venv>/python /tmp/kilo/pilot-probes/p1_guard.py        # F3/F6/F8
PYTHONPATH=/tmp/kilo/pilot-rereview/src <venv>/python /tmp/kilo/pilot-probes/p1_ceiling.py      # RR4
PYTHONPATH=/tmp/kilo/pilot-rereview/src <venv>/python /tmp/kilo/pilot-probes/p1_nesting.py      # 9/10

grep -n 'src/m' tests/test_milestone8_readiness.py ; grep -n owned_scope tests/helpers.py   # F1 corpus
```

`_node_depth_from_state` is compared against `Controller._node_depth` on a
constructed `CHILD_OF` chain (no real model, no network, no credentials; the
`.venv` symlink only lets the four oracle tests spawn `ruff`/`python`).

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

All four findings closed. **844 passed**; `scripts/check`, `scripts/check-static`
and `scripts/check-docs` all rc 0 (248 links).

**RR1 closed.** `_node_depth_from_state` no longer re-implements the walk — it
calls `Controller._node_depth`. The re-implementation broke *before* the final
increment when the parent was the run root, so a root child read 0 instead of 1,
which refused every truthful caller and let a grandchild propose one level deeper
than the spec allows. Re-implementing a security-relevant quantity and getting it
wrong is the mistake; delegating to the authority removes the class.

The regression test is the one the review asked for and my first attempt lacked: it
compares `_node_depth_from_state` against `Controller._node_depth` on a chain
rather than against itself, and pins the exact off-by-one case (`test_a_root_child_reads_depth_one_not_zero`).

**RR2 closed, and the review is right that my claim was false.** The commit message
said the spec's proposal fields now name the reducer's child shape; the spec was
unchanged. The edit had been written inside a script whose *later* assertion failed,
so the file was never written — the first replace succeeded in memory and was
discarded. P2 now names `node_id`, `mandatory`, `criterion_ids`,
`contract.owned_scope`, `contract.acceptance_criteria`, `contract.budget_id` and
`budget_allocation`, and says plainly that this is the shape
`validate_decomposition` consumes, so there is one interface to settle before the
producer is written.

**RR3 and RR4 closed together, by removing the opt-out.** The review is right that
deriving depth and the count while letting the caller *choose whether to derive*
re-opened both. `state` and `parent_node_id` are now required by policy: omitting
either is a `DecompositionError`, not a `TypeError`, and the fallback to
caller-supplied values is gone. The parent scope and budget are derived from the
node contract and the ledger as well, and when stated they must agree with state —
so `parent_budget=None` no longer disables the budget bound, it falls through to
the ledger. That was the honest reading of RR3: the bound is not opt-out, and my
commit message overstated it by listing `None` among the closed values.

P3 now carries the derivation mandate, and `TestThePilotPathRequiresState` pins
that omitting the state, a parent declaring no scope, a parent with no registered
budget, and a stated scope that disagrees with the contract are each refused.

**One thing the review did not flag, found while making the change mandatory:**
`_state`'s depth accounting. My first rewrite built the test parent at controller
depth 4 while asserting the per-trial ceiling, so the *depth* bound fired first and
the ceiling assertion passed for the wrong reason — the same failure mode the first
review caught in F11. The helper is now documented: a chain of 0 puts the parent at
controller depth 1, because a root child reads 1.
