# Phase 1 refactor review — frozen snapshot review

<!-- mixed: the review-procedure sections are informative; findings and the
     per-handler census are normative claims about the reviewed snapshot. -->

## Verdict

**GO** for Axis 1 self-hosting, with non-blocking follow-ups.

The reviewed snapshot:

- **Snapshot commit** `8441ee25b13196e80c723d1c0c91b21513edc972` (frozen
  `git worktree add --detach` from the working tree, including untracked files,
  taken 2026-09-24; base `HEAD` = `34d6adab7a0a65fcccba023d5625e02ea33dc8c2`).
- Baseline in the frozen tree: **701 passed in 156.14 s** (`pytest -q`).
- `scripts/check-static` → exit 0; `scripts/check-docs` → exit 0.

None of the eight guarantees is falsified in a way that changes dispatch
completeness/equivalence, replay determinism, single-flight, or the fail-closed
target binding as stated. Four P2 and two P3 issues remain; all are inert for
current consumers and none blocks Axis 1.

Reviewed files (Phase 1 scope): `src/orchestrator/{reducer,executor,
command_executor,model_adapter,numeric}.py`, the six migrated validator sites
(`schemas`, `spend`, `controller`, `model`, `executor_protocol`, plus the
reducer's `_payload_amount`), and the `experiment.py` split into
`{experiment,experiment_spec,experiment_target,hidden_oracle,trial_driver,
experiment_phases,hashing,git_ops}.py`.

## Normalisation and method (informative)

- The frozen tree is a detached worktree at the snapshot commit. The original
  working tree was **not** edited (only read); all probes live under `/tmp/kilo`.
- The pre-refactor comparison tree is a second detached worktree at
  `34d6ada`, with the same interpreter/venv. Differential probes run one side
  per interpreter (base worktree vs snapshot worktree) and diff JSON.
- No network, no real credentials, no paid calls: all model calls used the
  in-tree scripted/stub clients.
- Residual host effect: two temporary worktrees and one dangling snapshot
  commit object (removed/pruned at the end; no ref changed).

Probes used (all under `/tmp/kilo`):

| Guarantee | Probe | Result |
| --- | --- | --- |
| G2 catalogue/table | `probe_catalogue.py`, `drift_census.py`, `drift_funcs.py` | pass |
| G2/G3 differential | `gen_corpus.py` + `diff_reducer_probe.py` | pass |
| G3 replay | `probe_replay_equivalence.py` | pass |
| G4 single-flight | `probe_singleflight.py` | pass |
| G5 numeric | `probe_grid.py` | message-only drifts |
| G1/G7 split/facade | `probe_facade.py`, `exp_audit.py`, `facade_reach.py` | findings |
| G6 binding | `probe_binding.py` | refused as stated; deeper echo gap |
| G8 guard rails | `guard_rail_probe.py`, `pin_compare.py`, both-tree pytest | pass |

## Conversion-drift census (normative)

### Dispatch table (G2)

`events.EVENT_CATALOGUE` has 65 entries; `reducer._HANDLERS` has 65 keys.
Set difference is **empty both ways**: every catalogued event has a handler and
no handler exists without a catalogue entry.

Per-event normalised AST comparison of each `_on_*` handler against the
corresponding branch of the old `reduce` chain (`drift_census.py`):

- **60/65 events: byte-identical** handler bodies (including effect order).
- **5/65 events** (`ARTEFACT_INTEGRATED`, `ARTEFACT_PUBLISHED`,
  `ARTEFACT_REJECTED`, `ARTEFACT_SUPERSEDED`, `ARTEFACT_VALIDATED`, all served
  by `_on_artefact_integrated`) differ by exactly one block — the documented
  `Exec F2` attempt-state guard:
  `reducer.py:923-933`. That is an already-reviewed Phase 0 fix pinned by
  `tests/test_cancel_interleavings.py:229-254` (out of scope). No other branch
  condition, membership, or effect was altered.
- Helper functions (`_apply_node_event`, `_apply_attempt_event`,
  `_apply_accounting_event`, `_apply_freshness_event`, `_payload_amount`, …) are
  byte-identical except `_payload_amount`, which now delegates to
  `numeric.amount` with identical decision and message text.

### Differential behaviour (G2)

`diff_reducer_probe.py` reduces, on both trees:

- all 65 baseline catalogue payloads against an empty `RunState`;
- 9 captured runs / 181 real events (8 seeded controller walks + one real
  `run_trial`).

**Zero differences**: identical exception types/messages, effects (kind+data),
and final state.

### Replay equivalence (G3)

`probe_replay_equivalence.py`: `store.state(run_id)` vs
`store.replay_fresh(run_id)` after 8 seeded walks and one real trial — all PASS
byte-for-byte (including `graph_version`). The replay path uses the same
dispatch table, so late-event decisions reproduce.

### Single-flight (G4)

`probe_singleflight.py` races two barrier-synchronised deliveries of the same
`(attempt_id, token)` with a ≥0.6 s delegate, for all three executors:

- `ScriptedExecutor` (`executor.py:86` lock): 1 script run, identical responses.
- `ModelAdapter` (`model_adapter.py:500` lock): 1 priced-client call,
  identical responses.
- `CommandExecutor` (`command_executor.py:99`): 1 sandbox run, identical
  responses.

Token lifecycle also holds: duplicate `issue_token` raises, unissued token
raises `UnknownAttemptToken`, dispatch-after-cancel raises `AttemptCancelled`.

## Findings

### P2-1 — `IntegrationTree` lost `integrated` and `advance()`'s return

`trial_driver.py:122-142` dropped `self.integrated` (init) and
`self.integrated.extend(attempt_ids)`/`return self.head` (advance), which exist
in the pre-refactor `experiment.py:1240,1257-1258`.

Reproducer (base vs snapshot):

```
advance(['a','b']) -> 'NEWHEAD' (HEAD)   vs   None (snapshot)
hasattr(tree, 'integrated') -> True (HEAD) vs False (snapshot)
```

No live consumer reads `integrated` or `advance()`'s result
(`trial_driver.py:1103,1201` ignore the return), so there is no functional
impact today, but it falsifies "the split moved behaviour verbatim" for an
exported class (the façade re-exports `IntegrationTree`). Regression test:
assert `IntegrationTree.advance` returns the new head and appends to
`integrated`.

### P2-2 — Façade no longer exposes five defined names and `snapshot`

Guarantee 1 says every name reachable as `orchestrator.experiment.X` before the
split is reachable after. Direct attribute access (not just `dir`) fails for:

```
MISSING _commands_for, _node_commands, _target_contract_hash, _write_script,
        _ROOT_OBLIGATIONS  (all defined in experiment_target.py)
MISSING snapshot            (re-exported from worktree at HEAD)
```

`_commands_for` is explicitly named in the brief as a pinned private name.
`experiment.py:158-166`'s `__getattr__` delegates only `_MUTABLE_BINDINGS` and
raises otherwise. No source/test/script reads any of these through the façade
(grep), so the gap is latent; fix by adding them to the façade import list.

### P2-3 — Message-contract drift at the controller's numeric forks

Guarantee 5 requires the message contract to be kept, explicitly including the
controller's declared-charge and commitment forks. `probe_grid.py` (base vs
snapshot) shows decision and exception type identical but message text split:

- `controller._commitment_amount` (negative/±inf/nan): `"commitment amount must
  be finite and non-negative, got X"` → `"…must be non-negative, got X"` /
  `"…must be finite, got X"`.
- The declared-charge fork (`controller.py:1006`) matches: combined message →
  split.
- `spend._require_amount` is the same split and is already listed as a known
  residual; the controller forks are not.

No test pins the combined strings. Reproducer: `probe_grid.py` in both trees.

### P2-4 — The binding does not close the label-echo variant; `calibrate_oracle` skips it

`probe_binding.py`:

- unbound manifest (empty `target_binding`) → refused **before** any spend
  reservation or trial directory exists;
- genuine foreign binding → refused likewise;
- control bound manifest → runs.

So guarantee 6 as written holds. Two deeper gaps:

1. `run_trial` (`trial_driver.py:661`) compares only `target_binding`; an
   `OracleManifest` carries no suite hash, so a manifest with a matching
   binding but a suite descriptor computed from another target (or an altered
   check set) is accepted on the bare `run_trial`/`run_pilots` path. Only
   `_require_frozen_binding` (`experiment_phases.py:394`) recomputes the suite
   hash, and only for the comparison path against a frozen manifest.
   `freeze_manifest` also accepts an unbound oracle (the binding is not part of
   the freeze descriptor).
2. `calibrate_oracle` (`experiment_phases.py:82`) grades a supplied manifest
   with no binding check; a foreign `target_binding` ran all five cases
   unrefused.

In-process forgery is inside the trust boundary, so this is P2, not P1; fix by
adding the binding check to `calibrate_oracle` and, if the threat model
includes it, verifying the suite hash in `run_trial`.

### P3-1 — Leftover conversion artifacts

- `reducer.py:375-380` is a **dead duplicate `reduce` stub** (the old header
  with four unused locals); the live definition is `reducer.py:1241`
  (`reduce.__code__.co_firstlineno == 1241`). Inert because Python binds the
  last definition, but it is exactly a leaked group-header fragment and a
  static check (`ruff --select F811`) is not gated.
- Unused imports left by the numeric/dispatch unification:
  `math` (reducer, schemas, model, model_adapter, executor_protocol),
  `threading`/`uuid` (command_executor), `uuid` (model_adapter).
- `git_ops.py:15-16` imports `WorktreeManager` twice (`ruff F811`).
- Redundant re-init of `_cancelled`/`_dispatch_lock` after
  `_init_dispatch_state()` in `ScriptedExecutor.__init__` (`executor.py:74`),
  `CommandExecutor.__init__`, `ModelAdapter.__init__`.

### P3-2 — `dir(experiment)` omits the delegated bindings

`experiment.MODEL_PROFILE` / `MODEL_CLIENT_FACTORY` / `SECRETS_SOURCE` resolve
through PEP 562 `__getattr__`, so `hasattr` is true but `dir()` does not list
them (there is no `__dir__`). Introspection/completion based on `dir()` would
miss them; no live consumer does.

## Guard rails (G8) — no blind spot

The fixture-fidelity, open-defect, counterexample, guard-mutation and
verifier-coverage scanners all scan flat `tests/*.py`; the refactor added only
flat files, so shallow == recursive and no fake/pin moved into a subpackage.
The interleave harness is new (no HEAD counterpart); the old F2/F3 windows in
`test_batch3_execution.py` are body-identical. `check-static`/`check-docs` and
`test_static_gates.py` are byte-identical base↔snapshot and still scan the 38
flat `src/orchestrator/*.py`. Guard-rail suites: 131 passed in the snapshot; 60
passed on the subset present at base. `skip`→`fail` conversions are
strengthening. No test was weakened to green.

## Intentional deviations (not findings)

- `hidden_runner` now calls `_require_check_script_coverage()`
  (`hidden_oracle.py:172-198`) on every grading call, replacing the HEAD
  import-time `assert`; the docstring states it deliberately survives
  `python -O`. Strengthens the guard, changes timing only.
- `_TrialRecorder`/`_model_review` are keyed to the trial's `model_profile`
  (`test_phase0_defects.py:274`), `_execute_leaf_batch` degrades a failed batch
  review to the single-leaf path (`test_axis2_robustness.py:373`), and
  `run_trial` recovers/settles and swallows axis-2 provider errors — Phase 0 /
  step-2 fixes, out of scope.
- Brief parenthetical "the smoke runner's probe … calls run_trial" is
  inaccurate: `smoke_run.probe` issues a direct model call
  (`smoke_run.py:1192`), and `stress_run.py` has no `run_trial`; only
  `run_pilots` and `run_measured_comparison` call it. The binding is still
  enforced inside `run_trial`, so coverage of actual trial paths is complete.

## Residuals / open questions

- Axis 1 self-hosting starts from a tree whose Axis 1 code is itself the diff;
  the refactor is self-referential, so a semantic drift that the suite also
  encodes cannot be found by a green suite. The differential base-vs-snapshot
  probes are the independent check here.
- The label-echo gap (P2-4) is the only guarantee-adjacent item where the
  brief's stronger reading ("the binding must close") is not met.
- The `Exec F2` guard is the sole reducer semantic change and should be cited as
  an out-of-scope Phase 0 fix in the final assessment, not as refactor drift.
