<!-- informative -->

# Re-review 3: Bounded Recursive-Planning Pilot — the Model Producer at `253f21b`

Third verification pass, of `253f21b` ("Close the producer re-review-2 residuals
R5 and R6") against R5/R6 in the
[second producer re-review](phase4-recursive-planning-pilot-producer-re-review-2.md).
Reviewed revision `253f21bc18a4ecde251df1fc99af2e4aed96f4be` in a detached worktree
at `/tmp/kilo/pilot-fix3`. No source edits.

## Verdict

**R5 and R6 are closed.** The identifier shape class is now validated at the guard
for `node_id`, criterion ids, `contract.budget_id`, and the `acceptance_criteria`
entry ids; dependency endpoints are shape-checked. **One residual of the same
keying class remains: `budget_id` uniqueness.** A provider-chosen `budget_id` that
already exists in the ledger (the parent's own, or a sibling's) passes the guard and
the validator, then `_on_decomposition_admitted` raises a bare `LedgerStateError`
out of `reduce`. Conditional GO is unchanged; this is the last instance of the class.

Baseline reproduced on `253f21b`: `scripts/check-tests --fast` **892 passed, 30
deselected**; full `pytest -q` **922 passed**; `scripts/check-docs` **257 links OK**;
`scripts/check-static` rc 0.

## R5 — closed

`_check_child_contract` requires a mapping contract with a non-empty string
`budget_id` and a non-empty `acceptance_criteria` sequence of mappings with
non-empty string ids. Verified all refused at `GUARD`: `budget_id` as list, dict,
`None`, empty string, `int`, tuple; `contract` as `int`; missing `budget_id`;
`acceptance_criteria` as a string or empty list; entries that are not mappings;
entry ids that are `int` or empty. A well-formed child is still admitted and
accepted by the reducer.

## R6 — closed

`_check_dependencies` shape-checks both endpoints as non-empty strings before
assembly. Verified refused at `ASSEMBLY`: `[{}]` (missing keys), unhashable
endpoint, non-mapping entry, a string, a `Mapping`, and a generator. `[]` and a
well-formed entry pass the guard (the well-formed self-loop is then refused by the
reducer's acyclic check with a `DecompositionError`, which is the authority working).

## `_as_sequence` and the remaining `x or ()` sites

The shared normaliser is correct: `None → ()`, `str`/`bytes`/`Mapping` refused,
non-sequence refused, list/tuple accepted. The two remaining
`contract.get("owned_scope") or ()` sites were checked by hand and are safe —
`check_scope_containment` (`planning_pilot.py:189`) rejects `str`/`bytes` and any
non-`list`/`tuple` explicitly, and `admit_proposal` (`planning_pilot.py:395`) wraps a
string parent scope into a one-tuple deliberately. The payload assembly's
`dependencies or []` at `planning_pilot.py:637` is now safe because
`_check_dependencies` runs first and has already refused every shape that iterates
wrongly. The class distinction the commit states — `x or ()` is right for `None` and
empty containers and wrong for a non-empty string or `Mapping` — holds for every
site.

## Residual finding

### R7 (P2) — provider-chosen `budget_id` uniqueness is not validated; the reducer raises an uncaught `LedgerStateError`

Same family as R1/R5: the guard admits a payload the authority cannot apply. `R5`
validated that `budget_id` is a hashable string, but not that it is *unused*.
`_on_decomposition_admitted` registers each child's budget with
`Ledger.register_budget`, which raises `LedgerStateError` when the id is already
present (`model.py:244-246`). `validate_decomposition` does not check uniqueness, and
`reduce` calls the handler with no exception wrapper (`reducer.py:1241`), so the
error escapes as neither a `DecompositionError` nor a `ReducerError`.

```python
st = state()  # p-budget is registered
kid = {**child(), "contract": {**child()["contract"], "budget_id": "p-budget"}}
payload, record = pilot.propose_decomposition(st, "p", lambda s, p: [kid], proposal_id="P")
# record: admitted True; validate_decomposition: PASSED
st.nodes["p"].state = "READY"
reducer._on_decomposition_admitted(st, payload, "DECOMPOSITION_ADMITTED")
# -> LedgerStateError: budget 'p-budget' already registered  (not DecompositionError, not ReducerError)
```

A sibling collision (two children with the same `budget_id`) fails identically on
the second child. **Proposed fix:** in the guard, require each child's `budget_id` to
be unused in `state.ledger.budgets` and unique within the proposal — the guard
already holds `state` and this is the same "identifier the reducer will key must be
something it can use" rule. Alternatively the reducer converts `LedgerStateError`
into `DecompositionError` in the handler. **Regression test:** a provider returning a
child whose `budget_id` equals the parent's, or a sibling's, is refused at `GUARD`.

## Reproduce

```
git worktree add --detach /tmp/kilo/pilot-fix3 253f21b
ln -s <repo>/.venv /tmp/kilo/pilot-fix3/.venv
cd /tmp/kilo/pilot-fix3
PYTHONPATH=src <repo>/.venv/bin/python /tmp/kilo/probe_a3.py
# R5/R6/R7 inline probes as above
./scripts/check-tests --fast && ./scripts/check-docs && ./scripts/check-static
```

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

R7 closed. **926 passed**; `scripts/check`, `scripts/check-static` and
`scripts/check-docs` all rc 0 (257 links).

**R7 closed in the guard.** A child's `budget_id` must now be *unused* in
`state.ledger.budgets` and unique within the proposal, so a provider reusing the
parent's id or giving two siblings the same one is refused at `GUARD` instead of
producing an admitted payload the reducer cannot apply. Pinned both cases, plus a
well-formed pair that still passes.

The re-review is right that this is the same family one step further, and the
useful generalisation is the distinction the fix turns on: **well-formed is not the
same as usable.** `node_id`, criterion ids and `budget_id` each passed a string check
and each turned out to be a key the reducer could not use — the first two because
they were unhashable, this one because the key was already taken. The spec now says
so, because the next field will have the same shape.

**A gap the fix exposed, which is a finding I am recording against myself.** The
`_check_child_contract` call sat *after* a `continue` in the criterion-id loop, so a
child declaring no `criterion_ids` skipped its contract checks entirely — including
the R5 checks the re-review had just verified. The R7 code reached it only because
R7 reads `child["contract"]["budget_id"]` and raised a `KeyError` on a fixture I
already had. So the R5 fix was narrower than it looked: it held for the shapes its
own tests used and not for a child shaped differently. The `continue` is gone, the
contract is checked for every child, and a pin asserts that a well-formed child
without `criterion_ids` is admitted while the same child with a missing, unhashable,
non-mapping, or empty contract is refused at `GUARD`.

That is the third time in this producer that a check was verified only against the
shapes its own tests constructed — the same lesson as the R3 boundary test one level
up. The pattern is consistent enough to be worth naming as the standing risk in this
work: **a test that exercises a check through one path says nothing about the paths
it did not go through**, and every one of these has been found by a reviewer probing
a shape the test never built.
