<!-- informative -->

# Re-review: Bounded Recursive-Planning Pilot — the Model Producer at `8419e7c`

Verification of the corrective commit `8419e7c` ("Close the producer review: F1
(P0), F2/F3, F5, and the concern-1 ruling") against the findings in the
[producer review report](phase4-recursive-planning-pilot-producer-review-report.md)
and the mandate in the
[producer review brief](phase4-recursive-planning-pilot-producer-review-brief.md).
Reviewed revision `8419e7c9f1b15d890e0e34a4828f5a882823aecc` in a detached worktree
at `/tmp/kilo/pilot-fix`. No source edits; probes under `/tmp/kilo/`; scratch copies
discarded.

## Verdict

**The P0 and the P1 blockers are closed. Conditional GO for wiring the producer into
a run**, gated on the two residuals below (R1, R3) and on the concern-2 integration
that was already a forward constraint.

- F1 (P0, provider rewrote its own bounds) — **closed**, verified by the original
  reproducer and by object-identity isolation.
- F2/F3 (P1/P2, lost records) — **closed as a class**; all thirteen enumerated input
  classes now return exactly one record.
- F5 (`depth_reached`) — **fixed**.
- Concern 1 (kernel-bound drift) — **closed**; the parser pin now fails on drift of
  the depth, ceiling, and fan-out.
- F4 (mutable payload / no reducer scope re-check) — **acknowledged as a wiring
  constraint**, but not recorded in the spec's residual section (R3).

Baseline reproduced on `8419e7c`: `scripts/check-tests --fast` **848 passed, 30
deselected**; full `pytest -q` **878 passed**; `scripts/check-docs` **253 links OK**;
`scripts/check-static` rc 0; gated `check`/static rules clean.

## F1 — closed

The provider now receives `copy.deepcopy(state)` and the live state is only read for
derivation. Re-running the original reproducer
(`/tmp/kilo/probe_provider_state.py`) against `8419e7c`:

| provider attempt | before (`853d2a2`) | after (`8419e7c`) |
| --- | --- | --- |
| clear relations + inflate budget to `1e12`, ask `1e9` | **admitted**, ledger `1e12` | refused `BUDGET`, ledger `10.0` |
| clear relations to make depth read 0 | **admitted** at depth 0 | refused `BOUNDS`, `depth_reached` 2 |
| insert `ghost` node, return scope-escaping child | refused, ghost persisted | refused `SCOPE`, no ghost |

Identity check: `provider_state is live_state` and
`provider_state.nodes is live_state.nodes` are both `False`. Deepcopy-failure path:
with an uncopyable object injected into the state (a `threading.Lock`), the provider
is **not called** and a `PROVIDER` record is returned — the claimed
"refusal rather than fallback to live state" holds.

## F2/F3 — closed as a class

Re-running `/tmp/kilo/probe_a3.py` against `8419e7c`, every input class now returns
`(None, record)` instead of raising or returning uninstrumented:

| input | stage | `proposed_children` | `depth_reached` |
| --- | --- | --- | --- |
| provider raises | `PROVIDER` | 0 | 0 |
| generator raises mid-iteration | `PROVIDER` | 0 | 0 |
| non-iterable return (`int`) | `PROVIDER` | 0 | 0 |
| element not a mapping (`int`, `str`) | `PROVIDER` | 0 | 0 |
| empty / `None` proposal | `GUARD` | 0 | 1 |
| parent without owned scope | `GUARD` | 1 | 1 |
| parent budget unregistered | `GUARD` | 1 | 1 |
| `parent_node_id` `None` / unknown | `GUARD` | 1 | 0 |
| child `criterion_ids` bare string / mapping | `COVERAGE` | 1 | 1 |
| child missing `node_id` with `criterion_ids` | `COVERAGE` | 1 | 1 |
| child `contract` not a mapping | `PROVIDER` | 0 | 0 |
| malformed `dependencies` entry | `ASSEMBLY` | 1 | 1 |
| malformed `expected_versions` entry | `ASSEMBLY` | 1 | 1 |

The stage names distinguish a provider fault from a guard pre-check from the three
named checks from assembly, as claimed. `853d2a2`'s one-instance fix is now a
class-level net.

## F5 — fixed

`depth_reached` is `parent_depth + 1` on admission (`planning_pilot.py:524`); the
admitted-control record is `2` for a parent at depth 1, and the unit test pins it.

## Concern 1 — closed

On a scratch copy, changing `MAX_PROPOSAL_DEPTH` 2→7, the per-trial ceiling 32→99,
and `maximum_children_per_node` 6→99 now fails the new
`test_the_kernel_named_bounds_equal_the_enforced_bounds`:

```
assert 2 == 7          # depth drift caught
assert 6 == 99         # fan-out drift caught
```

The kernel text stays a frozen literal and gains the fan-out value ("of 6"), so the
pin binds all three bounds without interpolating module constants into a target's
contract text. Reverting the scratch constants restores green. Scratch discarded.

## Residual findings

### R1 (P2) — the guard admits unhashable identifiers, and the reducer crashes instead of refusing

Not introduced by the fix; surfaced during this verification and not covered by the
first review. `admit_proposal` does not require `node_id` (or `criterion_ids`
elements) to be hashable or even present, and `_criterion_coverage` only reads
`node_id` as a value. A provider can therefore obtain an admitted payload that the
reducer's authority cannot process:

```python
from probe_a3 import child, state
payload, _ = pilot.propose_decomposition(
    state(), "p", lambda s, p: [{**child(), "node_id": ["c1"]}], proposal_id="P")
# payload is not None (record admitted)
reducer._on_decomposition_admitted(state(), payload, "DECOMPOSITION_ADMITTED")
# -> TypeError: unhashable type: 'list'   (ReducerError is False)
```

Same for `criterion_ids=[["AC"]]` → `TypeError: unhashable type: 'list'` inside
`validate_decomposition`. `node_id=None` is handled gracefully by the reducer
(`every child must declare a node_id`), so the gap is specifically non-hashable
identifiers. This violates the seam's contract that the guard bounds what a model
may ask for and the reducer "remains the authority": the producer emits a payload on
which the authority raises an uncaught non-`DecompositionError`. **Proposed
regression test:** a provider returning a child whose `node_id`, or an element of
whose `criterion_ids`, is non-hashable is refused by the producer (or the reducer
raises `DecompositionError`). The cleanest fix is in the guard: require a non-empty
hashable string `node_id` and hashable criterion identifiers, or make
`validate_decomposition` raise `DecompositionError` instead of a bare `TypeError`.

### R2 (P2) — the record's counts under-report on provider faults

`proposed_count` is captured only after the whole normalization comprehension
succeeds, and `parent_depth` only after the provider call. A provider that returns
`[valid, non-mapping]` or a generator that yields two children then raises records
`proposed_children=0` and `depth_reached=0`, because both variables were still at
their initial values. The record exists and the stage is correct — the P8 property
holds — but the counts do not describe the fault. **Proposed fix:** compute
`parent_depth` from the live state *before* invoking the provider (safe now that the
provider cannot touch it) and count normalized children incrementally.

### R3 (P2, process) — F4 is not recorded where the other pilot residuals live

F4 (the admitted payload is mutable; the reducer does not re-check scope
containment) is in the review report but not in the spec's
`## Residual and inherited surface (informative)` section. A future implementer
reading only the spec will not see the wiring constraint "do not mutate a payload
between the guard and event admission". Add it to that list next to the F1
single-layer containment entry.

### R4 (informational) — `RunState.clone()` is the purpose-built isolation primitive

`copy.deepcopy(state)` is correct and strictly isolated, but `RunState.clone()`
exists for exactly this ("unshares every container the reducer can mutate") and its
contract is enforced by `tests/test_state_purity.py`; it is also cheaper. Not a
defect; worth considering for consistency and cost on large states.

## Not covered

R1/R2 were found by targeted follow-up probes of the new net, not by the full
thirteen-class campaign re-run alone. R1's reducer-side impact was demonstrated by
calling `reducer._on_decomposition_admitted` directly, not through a live controller
run; the producer remains unwired, so no end-to-end path exercises it. F4's
integration constraint and the concern-2 scripted-provider arm are still outstanding.

## Reproduce

```
git worktree add --detach /tmp/kilo/pilot-fix 8419e7c
ln -s <repo>/.venv /tmp/kilo/pilot-fix/.venv
cd /tmp/kilo/pilot-fix
PYTHONPATH=src <repo>/.venv/bin/python /tmp/kilo/probe_provider_state.py   # F1
PYTHONPATH=src <repo>/.venv/bin/python /tmp/kilo/probe_a3.py               # F2/F3
PYTHONPATH=src <repo>/.venv/bin/python /tmp/kilo/probe_a4.py               # stages
./scripts/check-tests --fast
./scripts/check-docs && ./scripts/check-static
```

R1/R2 probes are the inline snippets above; the R1 reducer probe calls
`reducer._on_decomposition_admitted` directly with a payload from
`pilot.propose_decomposition`.

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

All four residuals closed. **896 passed**; `scripts/check`, `scripts/check-static`
and `scripts/check-docs` all rc 0 (256 links).

**R1 closed in the guard.** A child must now declare a non-empty hashable string
`node_id`, and each criterion id must be a non-empty string. The re-review is right
about the shape of this defect: the guard admitted a payload the *authority* could
not process, so the seam's promise that what the guard admits is something the
reducer can evaluate was false, and the reducer's crash was the visible symptom of
the guard's gap. Pinning covers a list, dict, `None`, empty string, int and tuple
node ids, and list/dict/`None`/int/empty-string/set criterion ids. The malformed
`criterion_ids` case moved from `COVERAGE` to `GUARD` as a result, which is correct —
it is now caught at the boundary rather than during coverage derivation — and that
test's stage expectation moved with it.

**R2 closed.** `parent_depth` is derived from the live state *before* the provider
runs, which is safe now that the provider cannot reach the live state, so a provider
fault records the depth the proposal was aimed at rather than 0. Children are
counted as they are normalised, so a provider that yields two children and then
raises records 2 proposed rather than 0. Both pinned.

**R3 closed.** F4's wiring constraint — do not mutate a payload between the guard
and event admission — is now in the spec's residual section beside the single-layer
containment entry, where a future implementer reading only the spec will see it.

**R4 declined, with the reasoning recorded.** `RunState.clone()` is cheaper and its
purity contract is enforced by `tests/test_state_purity.py`, but that contract is
scoped to "every container **the reducer can mutate**" — nested values the reducer
never touches are shared deliberately, which is where the saving comes from. A model
provider is not the reducer, so `clone()` optimises against the wrong threat model: it
would share exactly the structures an untrusted caller is most likely to reach for.
`copy.deepcopy` is retained, and the spec says why, so the cheaper primitive is not
adopted later by someone reading only the "it is cheaper" part.

**One further tightening the style gate forced.** R2's incremental count introduced
`for item in (raw or ())`, which the gate flags for the fourth time in this work: a
non-empty `Mapping` iterates its keys and a string iterates per character. A provider
returning either is now a `PROVIDER`-stage refusal rather than a guess, and the
malformed-return pins cover `str`, `bytes` and `Mapping` as well as `int` and
non-mapping elements.
