<!-- mixed -->
# Phase 2 N1-N7 Remediation — Re-Review

Reviewer: adversarial re-review executed 2026-09-29 of remediation commit `1642482` ("Close the re-review findings
N1-N7"), against my re-review (`07dbce6`, report `phase2-remediation-re-review.md`). Fix worktree detached at
`/tmp/kilo/phase2-fix2`, left unmodified; probes and reproducers under `/tmp/kilo/p2f2/`. Same discipline: no source
edits, no test weakening; whole-trial reproducers for every verdict-changing hit.

Baseline at `1642482`: **736 passed** (728 + 8 new pins) in 184s; `scripts/check-docs` 202 links OK (exit 0);
`scripts/check-static` gated rules clean (exit 0); the new pins and both exit gates pass standalone (14 passed in
18.7s). **No test assertion was removed or weakened** (`git diff 07dbce6 1642482 -- tests/ | grep '^-.*assert'` is
empty).

---

## Verdict

**Accepted.** All seven open findings (N1-N7) are closed as claimed, the F7 pin gap is filled, and the probe-oracle
ruling is now enforced (not merely disclosed). The strongest new evidence is a randomized differential against real
`git apply`: **752 well-formed git-generated diffs (both `-U3` and `-U0`), 0 divergences, 0 fail-opens, 0
git-accepted/boundary-refused**. The boundary is now byte-faithful to `git apply` on conforming diffs.

One residual remains, **R1 (P2)**, newly surfaced by this pass: the insertion-placement rule uses the *old-side*
start, whereas `git apply` positions a zero-count hunk by the *new-side* start. For every conforming diff these
coincide (`new_start == old_start + 1`), so the fuzz is clean; only a self-inconsistent header diverges (both
accept, different content). It is a fail-divergence on malformed input, not a demonstrated fail-open, and it is not
a regression introduced by this commit (the placement formula is older).

| Finding | Severity | Status |
|---|---|---|
| N1 insertion placement (canonical `git diff -U0` forms) | P1 | **closed** |
| N2 absent no-newline marker on an unterminated last line | P0 | **closed** |
| N3 harness-deadline overrun mislabelled as infrastructure | P2 | **closed** |
| N4 `probe_identity` ignores module globals | P2 | **closed** |
| N5 `RAW` probes freezable without an opt-in | P2 | **closed** |
| N6 `_run_probe` raw exception on a missing tree | P2 | **closed** |
| N7 patch mode + batched concurrent dispatch | P2 | **closed**, pin is end-to-end and mutation-checked |
| F7 pin gap (public `calibrate_oracle`/`CalibrationCases`) | — | **closed** |
| **R1** zero-count hunk placed by `old_start`, git uses `new_start` | **P2** | open (non-conforming input only) |

---

## Evidence per finding

**N2 (P0) — closed.** `patch.py:204-216` now makes the end-of-file claim symmetric: whenever a hunk covers the
file's end, `hunk.old_no_newline` must equal `not ends_with_newline`, so an *absent* marker asserts
newline-termination and a mismatch is refused. Re-ran all my rows: `no_marker_on_nonewline_file`,
`no_marker_on_nonewline_lastline`, `two_hunks_second_touches_eof` are now **REJECT** (were fail-open OK). The
whole-trial reproducer (`attack4.py`, an unterminated `calc/core.py` + markerless EOF reply that `git apply`
refuses) is now `outcome=None classification=CORRECTLY_UNRESOLVED` (was `CORRECT_ACCEPTANCE`). The standard
append-to-unterminated representation (`@@ -2 +2,2 @@` with the old marker) still applies byte-identically.

**N1 — closed for conforming diffs.** `_hunk_start_index` (`patch.py:137-149`) returns `old_start` for an empty old
side, `old_start - 1` otherwise, and drives both the apply loop and the EOF-coverage test. Canonical placements all
agree with `git apply --unidiff-zero`: `@@ -2,0 +3 @@` → after line 2, `@@ -4,0 +5 @@` → EOF append, `@@ -0,0 +1 @@`
→ prepend. The whole-trial N1 reproducer is now `CORRECT_ACCEPTANCE` (was `CORRECTLY_UNRESOLVED`). The 752-diff fuzz
confirms no other placement divergence on conforming output.

**N3 — closed.** `_Deadline` is now a `BaseException` subclass, so the sanctioned probe's `except Exception` cannot
swallow it. Re-ran my reproducer (`check.timeout_seconds=0.5`, probe sandbox wall 5s, hanging candidate):
`CANDIDATE_TIMEOUT` (was `ORACLE_INFRASTRUCTURE_ERROR`). Also `CANDIDATE_TIMEOUT` when the harness budget exceeds
the probe's own wall. The shipped pin `test_harness_deadline_beats_the_probe_budget_review_n3` covers exactly this.

**N4 — closed.** `probe_identity` now binds referenced module globals (names from `co_names`, resolved in
`__globals__`; modules by name, callables recursively). Re-ran my reproducer: flipping `module.MODE` from PASS to
FAIL now changes the identity, and reverting restores it. Cross-process reproducibility re-verified: two fresh
processes produce identical identities.

**N5 — closed (enforced).** `freeze_manifest` refuses a `check.probe` that is not `SANDBOXED_DATA_DRIVER` unless
`allow_unverified_probes=True`, and `ExperimentManifest.unverified_probes_allowed` enters `content_hash`. Re-ran my
reproducer: a RAW-probe manifest is now refused (`ExperimentError`), and the opted-in allowance changes the content
hash. The exit-gate and general-target oracles use `sandboxed_probe`, so they freeze with no allowance.

**N6 — closed.** `_run_probe` wraps both the copy/digest block and the after-digest. Re-ran my reproducer: a missing
graded tree now yields `{'h': 'ORACLE_INFRASTRUCTURE_ERROR'}` instead of raising `FileNotFoundError` out of
`grade_manifest`.

**N7 — closed, and the pin is real.** `_process_children` (`trial_driver.py:972-981`) computes `patch_mode` and never
batches under it; each leaf runs its own plan→patch→dispatch cycle. The new `test_patch_mode_never_batches_review_n7`
builds a genuine two-obligation disjoint-scope target (`greet/core.py`, `greet/util.py`) and asserts every arm,
including `RECURSIVE_CONCURRENT`, reaches `CORRECT_ACCEPTANCE`. A code-read check confirms `_execute_leaf_batch` is
unreachable under patch mode.

**F7 pin gap — closed.** `test_phase2_general_target.py::_calibration` now calls
`experiment.calibrate_oracle(..., cases=experiment.CalibrationCases(...))`; `CalibrationCases` is exported via the
façade. Re-ran my independent calibration of the calc target through the public path: the five cases classify
`CORRECT_ACCEPTANCE / CORRECTLY_UNRESOLVED / CORRECTLY_UNRESOLVED / FALSE_SUCCESS / INDETERMINATE`.

---

## Residual finding

### R1 (P2, boundary) — a zero-count hunk is placed by `old_start`; `git apply` places it by `new_start`

**Where:** `patch.py:_hunk_start_index` returns `old_start` for an empty old side. Empirically, `git apply` treats a
zero-count hunk's position as `new_start` (inserted lines occupy new lines starting at `new_start`, so the number of
old lines before the insertion is `new_start - 1`). For every conforming diff the two rules coincide
(`new_start == old_start + 1`), which is why the 752-diff fuzz is clean; for a self-inconsistent header they diverge
(both accept, different bytes):

```
base 'a\nb\nc\nd\n'
@@ -3,0 +3 @@  -> git 'a\nb\nNEW\nc\nd\n'    boundary 'a\nb\nc\nNEW\nd\n'
@@ -2,0 +2 @@  -> git 'a\nNEW\nb\nc\nd\n'    boundary 'a\nb\nNEW\nc\nd\n'
@@ -2,0 +4 @@  -> git 'a\nb\nc\nNEW\nd\n'    boundary 'a\nb\nNEW\nc\nd\n'
@@ -1,0 +5 @@  -> git 'a\nb\nc\nd\nNEW\n'    boundary 'a\nNEW\nb\nc\nd\n'
```

**Why it is not a blocker:** no conforming `git diff`/`git diff -U0` emits such a header; the fix's own pins and my
fuzz cover the canonical forms, and all agree. **Why it is still worth fixing:** an LLM-produced diff can misnumber a
hunk, and since an insertion has no preimage to match, the boundary cannot reject it on content — it accepts and
places it differently from `git apply`, which can flip a held-out verdict. I did not construct a false-acceptance
instance, so I rate it P2.

**Fix (either is fine):** use `max(new_start - 1, 0)` for an empty old side (matching git, verified above); or
refuse a zero-count hunk whose `new_start != old_start + 1` as self-inconsistent (fail-closed). Pin both.

---

## Containment matrix under the sanctioned shape (re-verified)

`oracle._run_probe` + `hidden_oracle.sandboxed_probe`, driven from my own harness:

| Row | Result |
|---|---|
| Writes outside its tree | **Prevented** — grade `FAIL`, no host file created |
| Mutates its own graded copy | **Detected** — `FAIL`; original tree untouched; a later check sees the pristine tree |
| Spawns a surviving child | **Prevented** — child killed at teardown (no host marker 5s after the probe returned) |
| Hangs | **`CANDIDATE_TIMEOUT`** from either budget (harness deadline < or > the sandbox wall) |
| Floods | Bounded capture; a payload drowned by a flood fails closed (shipped pin) |
| Bare `BaseException` | Contained → `INFRASTRUCTURE_ERROR`; `_Deadline` (BaseException) → `CANDIDATE_TIMEOUT` |
| Reads expected values | Controller-side `compare`; the candidate's process sees inputs only (shipped pin) |
| Oracle-side I/O failure (missing tree) | `INFRASTRUCTURE_ERROR`, never a raw exception |

---

## Accuracy of the round-3 addendum

The addendum appended to `phase2-remediation-re-review.md` is accurate. Its four corrections to the first
remediation addendum (the F3 residual claim, the F5 hang mapping, the N7 batch note, and the F7 pin claim) match what
I measured, and its per-finding table is supported. The one thing it does not mention is R1, which was not among
N1-N7 as filed. Minor nit: `tests/test_probe_oracle.py` now imports `dataclasses` twice (the module was already
imported at the top); harmless and not gated.

---

## Residual unknowns

- The randomized differential used single-file, line-level edits over a small alphabet; it does not cover multi-file
  patches, binary content, mode/symlink changes, or `..`/absolute paths (all separately fail-closed and unchanged
  from earlier passes). It is a strong differential sample, not a proof.
- R1's false-acceptance direction is argued, not demonstrated.
- The harness deadline still binds the main thread (SIGALRM); a probe run off the main thread relies on the sandbox
  wall budget (documented). No shipped path runs grading off the main thread.
- Real-model measurement remains unclaimed.

---

## Reproduce

From a worktree at `1642482`, with
`/home/ruben/Projectos/meta-project/orchestrator/.venv/bin/python`; scripts under `/tmp/kilo/p2f2/`.

```bash
.venv/bin/python -m pytest -q                 # 736 passed
scripts/check-docs                            # 202 links OK
.venv/bin/python /tmp/kilo/p2f2/fuzz.py       # 752 well-formed diffs: agree 752, diverge 0, failopen 0
.venv/bin/python /tmp/kilo/p2f2/census.py     # 33 rows: 0 fail-open, 0 content mismatch
.venv/bin/python /tmp/kilo/p2f2/attack2b.py   # N2 rows now REJECT/AGREE
.venv/bin/python /tmp/kilo/p2f2/attack4.py    # N2 -> CORRECTLY_UNRESOLVED; N1 -> CORRECT_ACCEPTANCE
.venv/bin/python /tmp/kilo/p2f2/attack3.py    # N3 CANDIDATE_TIMEOUT; N4 identity flips; N5 refused; N6 contained
.venv/bin/python /tmp/kilo/p2f2/honesty2.py   # sanctioned-shape differential + calibrate_oracle(cases=…)
```

Minimal R1 (the P2 residual), from `src/` on the path:

```python
from orchestrator import patch as p
base = "a\nb\nc\nd\n"
text = "--- a/x\n+++ b/x\n@@ -3,0 +3 @@\n+NEW\n"   # self-inconsistent: new_start != old_start + 1
n = p.parse_patch(text, owned_scope_include=["**"])
print(p.apply_patch("x", n.files["x"], base))   # -> 'a\nb\nc\nNEW\nd\n'   (git: 'a\nb\nNEW\nc\nd\n')
```

---

## Closure addendum (R1, 2026-09-29)

R1 is closed with the fidelity option: a zero-count hunk is placed by its
**new** side (`_hunk_start_index` returns `max(new_start - 1, 0)` for an
empty old side; `Hunk` now carries `new_start` from the header). Conforming
`git diff -U0` headers are unchanged (`new_start == old_start + 1` makes the
readings coincide), and a self-inconsistent header an LLM can emit now lands
its lines exactly where `git apply` lands them — the fail-divergence class is
gone in the accept direction as well. The alternative (refusing
`new_start != old_start + 1`) was not taken: the boundary's charter is
`git apply` semantics, and matching git's placement satisfies it outright
rather than adding a stricter-refusal divergence.

Pinned (`test_self_inconsistent_insert_headers_follow_git_review_r1`): all
four of the review's self-inconsistent placements —

```
@@ -3,0 +3 @@  -> 'a\nb\nNEW\nc\nd\n'    (was: after line 3)
@@ -2,0 +2 @@  -> 'a\nNEW\nb\nc\nd\n'    (was: after line 2)
@@ -2,0 +4 @@  -> 'a\nb\nc\nNEW\nd\n'    (was: after line 2)
@@ -1,0 +5 @@  -> 'a\nb\nc\nd\nNEW\n'    (was: after line 1)
```

— plus the conforming forms retained from the N1 pins. The minor nit is
fixed: `tests/test_probe_oracle.py` imports `dataclasses` once.

Residual unknowns stand as filed (the fuzz's single-file scope, the argued
R1 false-acceptance direction now moot in the accept path, the SIGALRM
main-thread binding, unclaimed real-model measurement).
