<!-- informative -->

# Reviewer Brief: Phase 2 General Target and the Patch Boundary — Adversarial Review

## Mandate

Independently falsify the general-target change set before Phase 3 (the
project-owned oracle) builds on it. Two commits are under review:

1. **`4ffd1c4` — Fix the Axis 1 patch path** (`patch.py`, `patch_executor.py`,
   `model_adapter.py`, the patch-model subject derivation in
   `experiment_spec.py`, verification-only commands via `NodeCommands` in
   `experiment_target.py`/`trial_driver.py`, and the rewritten
   `tests/test_axis1_patch_producer.py`). This commit **changes grading
   semantics**: unified-diff hunks now apply with strict preimage
   verification and hunk-faithful content assembly (the previous
   implementation truncated files to their hunk lines and replaced content
   blindly), the base snapshot is taken **before** the patch so the model's
   changes are imported as candidate changes (previously they were snapshotted
   as base and silently dropped — a working patch graded worse than a broken
   one), and a patch-producing attempt's commands are verification-only (the
   synthetic BUILD write is a candidate fixture and it masked whatever the
   model produced).
2. **`2f3f521` — Phase 2: freeze an arbitrary target repository**
   (`experiment_target.build_target` with `TargetSnapshot` contract fields,
   the target-derived root contract and trial scripts in `trial_driver.py`,
   target-criteria coverage in `freeze_manifest`, probe-name binding in
   `hidden_oracle.py`, and the exit gate `tests/test_phase2_general_target.py`).
   This commit introduces the **probe-based oracle seam**: a general oracle's
   checks carry Python probes that execute candidate code against held-out
   assertions, and the R12 binding hashes probe identity by stable name.

The exit gates claim honest differentials (working reply → correct grade,
broken reply → not) on both the fixed target and a non-self calculator
repository. A green suite blessed the *previous* patch semantics for months
while they inverted the differential, so the exit-gate claims are exactly the
kind of claim a green suite can carry while being semantically wrong. Assume
the happy path is covered and attack the seams — especially where a change
moved grading semantics rather than preserving them.

**The adjudication this review must deliver:** is probe-based grading an
acceptable isolation model, and under what constraints? The R08
evaluator-isolation GO covers the **sandboxed** hidden suite (disposable
per-check copies, tamper digests, expected values controller-side, output
bounds). Probe-based checks are a different model: the probe is trusted code,
but it executes **candidate** code whose containment the probe itself must
provide. Phase 3 (project-owned oracle: the target's own gates as checks) and
the A2 consolidation re-review both hinge on your ruling. State it explicitly,
with the constraints a project-owned oracle must satisfy.

**Independence:** you must not be the author of the two commits under review,
of `tests/test_axis1_patch_producer.py` /
`tests/test_phase2_general_target.py`, or of the
`axis1-patch-producer-design.md` brief. Read the normative documents and the
sources (`git show 4ffd1c4^:…` for every pre-image) before the implementer's
tests and docstrings; treat the new tests as claims to verify, not evidence.

## Target

- Repo: `/home/ruben/Projectos/meta-project/orchestrator`
- Revision reviewed: **`2f3f521`** (the tip; `4ffd1c4` is its parent). Both are
  local commits not yet pushed. Name the exact tree you reviewed in the
  report (`git worktree add --detach /tmp/kilo/phase2-review 2f3f521`).
- Normative documents: `docs/executors.md` (trust boundaries),
  `docs/experiment.md` (independent oracle, calibration, freeze discipline),
  `docs/budgets.md`, `docs/control-plane.md`, `docs/glossary.md` (the reasoner
  output types and artefact media types catalogued for the patch ARTEFACT),
  `docs/research/axis1-patch-producer-design.md` (the patch-boundary rules the
  code claims to enforce), `docs/research/r08-evaluator-isolation-adversarial-review.md`
  (the isolation verdict the probe model must be compared against).
- Context: `docs/self-host.md` Phase 1–3 (the roadmap these phases serve),
  `docs/research/a2-oracle-consolidation-review-brief.md` (the dependent
  adjudication).
- Baseline (none of these is a verdict): `.venv/bin/python -m pytest -q`
  (expect **718 passed**); `scripts/check-docs` (**201** links OK);
  `scripts/check-static` gated rules clean; `tests/test_static_gates.py` green.
- No source edits, no third-party network, no real credentials, no paid calls.
  Probes and reproducers under `/tmp/kilo/`.

## The guarantees under review

Each is a claim made by the two commits. Falsify any of them.

1. **The patch boundary is fail-closed and faithful.** A patch that is not a
   well-formed unified diff, exceeds the 64 KiB bound, touches a path outside
   the node's delegated owned scope or under `.git/`, or whose preimage does
   not match the target file at its declared position is refused **before**
   anything is written, and the attempt fails closed with a `PATCH_REJECTED`
   observation and no artefact. An accepted patch applies with `git apply`
   semantics: content outside the hunks is preserved byte-for-byte, hunks
   apply at their declared offsets, created files arrive whole, deletions
   remove the file, and no accepted patch ever truncates or reorders content
   the diff does not mention.
2. **Import fidelity.** The admitted candidate tree is exactly the base commit
   plus the admitted changes (the patch's effects and the verification
   commands' effects — nothing else). The model's code reaches the graded
   tree; base content outside the candidate view is preserved (never wiped);
   the committed Git tree is verified against the returned tree before
   publication (R07).
3. **The differential is semantic.** On both exit gates, the two runs differ
   only in the model reply, and the grading difference follows the held-out
   semantics of the produced code — not the visible gate, not an artifact of
   what the verification commands write, and not an inversion (a working reply
   graded worse than a broken one is a P0 regardless of what the test asserts).
4. **The general-target builder is fail-closed and bound.** `build_target`
   refuses an unresolvable base commit, an absent repository, empty contract
   pieces, and any criterion/obligation coverage mismatch; the snapshot
   identity hashes every contract piece it later governs (task, kernel, scope,
   criteria, obligations, commands, scripts), so a run's contract cannot drift
   from what was frozen (R12 discipline on the new surface).
5. **Probe-oracle discipline.** Held-out assertions stay controller-side and
   never appear in the candidate tree or in any sandboxed script (R08).
   Candidate code executes only through the probe's own containment, with the
   check's timeout producing `CANDIDATE_TIMEOUT` — never a harness hang and
   never a mislabelled `INFRASTRUCTURE_ERROR`. A candidate cannot, during a
   probe, corrupt the graded tree, the durable grading record, or any other
   trial's state without that being detected or prevented. The binding and
   freeze hashes are reproducible across processes (the probe-identity claim).
6. **Freeze/replay discipline holds on a general target.** The five-case
   calibration classifies known-good, unchanged, known-broken, known-timeout,
   and injected-infrastructure candidates correctly; the freeze refuses
   anything else; identical inputs yield identical manifest content hashes;
   a foreign, unbound, or tampered manifest is refused at
   `run_trial`/`calibrate_oracle`/`freeze_manifest`; and a frozen comparison
   refuses a running profile that is not the frozen one.
7. **Verification-only commands never mask the candidate.** In the patch path
   no command writes candidate code (the model's patch is the only candidate
   source), the acceptance evidence is exactly the command results of the
   target's declared gates, and a gate the candidate cannot satisfy produces
   a refused acceptance and a settled retry path — never a silent success.
8. **The permissive command lookup cannot escalate.** `NodeCommands` resolves
   any node of a run to the target's declared verification commands and
   nothing else: a node cannot reach another node's overrides through its id,
   cannot run commands the target did not declare, and a missing entry cannot
   yield an empty command set that the visible acceptance checker would pass
   vacuously.

## In scope

- `src/orchestrator/patch.py`, `patch_executor.py` (the boundary and its
  executor), `model_adapter.py` (the admission-side patch validation and the
  scope source), `experiment_spec.py` (the patch-model subject derivation),
  `experiment_target.py` (`build_target`, `TargetSnapshot`'s contract fields,
  `NodeCommands`, `verify_commands_for`, the `TRIAL_SCRIPTS` move),
  `trial_driver.py` (the target-derived root contract, target trial scripts,
  patch-mode command selection), `experiment_spec.py`'s
  `freeze_manifest` criteria source, `hidden_oracle.py`'s probe-identity
  binding, `experiment.py`'s re-export set.
- `tests/test_axis1_patch_producer.py` and
  `tests/test_phase2_general_target.py` (as claims to verify).
- The docs-status edits in `docs/self-host.md` Phase 2 (as claims to verify).

## Out of scope

- The Phase 1 refactor, the review-fix round, Axis 2, and Performance Phase A
  (already reviewed and closed, except where these commits touch them).
- A2 oracle consolidation (gated on its own R08 re-review — but your
  probe-oracle ruling is an input to it).
- Model capability, the free-tier provider's behaviour, and the real-model
  measurement (deliberately unclaimed anywhere).
- The `MODEL_CLIENT_FACTORY`/`SECRETS_SOURCE` per-run threading (known
  deferral to the run-spec work).

## Known residuals — acknowledge, do not re-report as novel

- **Known defect, disclosed:** `freeze_manifest`'s
  `model_profile: ModelProfile = MODEL_PROFILE` default binds at **import
  time**, so a caller that swaps the profile afterwards (the documented
  `set_model_profile` flow) freezes a stale profile unless it passes the
  argument explicitly. The exit gate passes it explicitly. Do not re-report
  the instance; do hunt for **siblings** of this class (other def-time
  defaults over mutable module bindings) and report those.
- `apply_patch` normalises the trailing-newline state: the
  `\ No newline at end of file` marker is skipped as metadata and outputs are
  written with a trailing newline. Byte-fidelity at the file tail is not
  claimed; a finding is warranted only where this changes a check's verdict.
- Probe identity in the binding is the probe's `__qualname__`: two distinct
  probes sharing a qualname collide in the hash. Documented trade; report it
  only with a reachable collision under the supported usage.
- The exit gate's broken-reply classification admits two possible labels
  (`CORRECTLY_UNRESOLVED`/`MISSED_SUCCESS`) because the label depends on which
  retry/repair path settles first. If you can pin it exactly, say so.
- The synthetic fixed target's `_commands_for`/`_write_script` fixture is
  unchanged and remains the scripted candidate path for non-patch profiles
  (Phase 4 replaces the hand-authored obligations; not this review).

## Attacks to attempt (minimum)

- **`git apply` differential.** Generate real diffs against real repos
  (`git diff`, multi-hunk, multi-file, new files, deletions, renames refused,
  paths with spaces and unicode, CRLF, missing trailing newlines, mode-bit
  changes) and compare `apply_patch`'s result byte-for-byte to `git apply` +
  checkout. Any patch `git apply` rejects that we accept is fail-open (P0);
  any accepted patch whose result diverges from `git apply`'s is a fidelity
  finding.
- **Boundary fuzz.** Truncated headers, negative/overflow hunk counts,
  overlapping or descending hunks, hunks past EOF, NUL bytes, exactly-over and
  exactly-under the 64 KiB bound, `../` and absolute paths, `.git/hooks/…`
  writes, symlinked paths in the tree, a second `---` mid-hunk. Everything is
  refused or faithfully applied; nothing is half-applied.
- **Import-fidelity probes.** For a corpus of patches (including a patch whose
  content differs from what the verification commands would produce), assert
  the graded tree equals base + the patch's effects. Re-derive the inverted-
  differential failure mode deliberately (patch content that the old
  snapshot-as-base bug dropped) and confirm it is gone **and** that a
  regression pin exists.
- **Exit-gate honesty.** Mutate the fixture replies: a reply that passes the
  visible gate but violates the held-out check; a reply that fails the visible
  gate but satisfies the held-out check (classification must not be
  `CORRECT_ACCEPTANCE`); a no-op patch. The differential must track held-out
  semantics in every case. Confirm the pin cannot pass with an inverted or
  incidental differential (e.g. by making both replies identical).
- **Probe-oracle containment (the adjudication).** Under
  `tests/test_phase2_general_target.py`'s probe shape, drive hostile
  candidates: one that writes outside its tree during the probe (the probe
  subprocess inherits the controller's privileges), one that mutates its own
  graded tree mid-probe, one that spawns a surviving child and returns, one
  that hangs in `__init__`/import (must be `CANDIDATE_TIMEOUT`), one that
  floods stdout/stderr, one that raises `SystemExit`/`TimeoutError`/a bare
  `BaseException` from its module body. State which of these the current model
  prevents, detects, or tolerates — and which constraints Phase 3 must impose.
- **Binding reproducibility.** Freeze a probe-carrying oracle in one process
  and recompute `oracle_target_binding`/`hidden_suite_manifest_hash`/
  `content_hash` in a fresh process: identical or P1. Then construct two
  same-qualname probes and state the collision's effect on freeze-time
  detection.
- **Builder refusals and identity.** Non-repo directories, a bare repo, a
  symlinked repo, `HEAD`/tag/abbreviated commits, a commit from another repo
  grafted in, obligations that are not mappings, negative/NaN budgets inside
  obligations, criteria with empty ids. Then: mutate any frozen contract piece
  after `build_target` (via `dataclasses.replace` or by mutating the kernel
  dict before hashing) and confirm the snapshot identity and the run's
  contract cannot drift silently.
- **Command-lookup escalation.** A node id equal to another node's override
  key, an id with path segments or NUL, and a run whose node ids are crafted
  by a hostile decomposition proposal. Confirm the fallback cannot run
  undeclared commands and cannot make the visible checker pass vacuously
  (no commands ⇒ no acceptance).
- **Five-case discipline on a hostile general target.** A tree that hangs
  every probe (the harness must finish: timeout per check, `INDETERMINATE`
  never `FALSE_SUCCESS`), a tree that crashes the probe process, and a tree
  that returns a verdict-shaped object instead of a boolean (the probe shape
  must classify conservatively).

## Method

- Read the normative documents and the pre-images (`git show 4ffd1c4^:…`) of
  every changed function first; diff each against its new form and list the
  semantic deltas before testing any of them.
- Drive real entry points (`build_target`, `run_trial`,
  `run_measured_comparison`, the two exit gates' shapes) with
  `scripts/provider_stub.py` and `PatchModelClient`; prefer whole-trial
  reproducers for semantics claims and direct boundary calls for parser
  claims. `git apply` is the oracle for fidelity claims.
- Use `EventStore.history`/`state`/`replay_fresh` and the materialised graded
  trees as the source of truth, never runner stdout.
- For each attack: exact commands, the probe (not a source edit), observed vs
  expected, and the guarantee violated. Prefer a failing reproducer.
- Do not weaken or edit tests; report a failing reproducer instead.

## Deliverable

1. **Verdict:** GO / NO-GO for Phase 3 (the project-owned oracle) to build on
   this base.
2. **The probe-oracle ruling:** the isolation model's acceptability and the
   mandatory constraints for project-owned checks (sandboxed vs probe vs
   hybrid), written so the A2 re-review can adopt it as its R08 comparison
   baseline.
3. **Findings** with severity (P0/P1/P2), the guarantee violated, a minimal
   reproducer, observed vs expected, and the proposed permanent regression
   test.
4. **Claims verified:** each of the eight guarantees with its falsification
   attempt and outcome ("attacked, not falsified" is valid with the method
   stated).
5. **`git apply` fidelity census:** accepted/rejected agreement across the
   corpus, with every divergence listed.
6. **Residual unknowns:** what you could not test and why.

## Exit criteria

- Every guarantee is either falsified with a reproducer or explicitly
  "attacked, not falsified" with the method.
- The `git apply` differential corpus exists and its census is stated.
- The probe-oracle containment matrix (the hostile-candidate list above) is
  complete, each cell prevent/detect/tolerate/unaddressed.
- At least one whole-trial reproducer per semantic claim (import fidelity,
  differential honesty, freeze discipline).
- No source edits, no third-party network, no real credentials, no paid calls;
  host state left clean.
- Findings are reproducible from the report alone against the named revision.
- The review states what it did not cover.

## Reproduce everything

List every probe command, corpus generator, stub scenario, and worktree
revision here so the verdict can be re-run against a corrective revision.
