<!-- informative -->

# EXECUTION-Gate Adversarial Review — Batch 3

- Repo: `/home/ruben/Projectos/meta-project/orchestrator`
- Revision reviewed: `33945bb` (Batch 3), frozen worktree `/tmp/kilo/execution-review-33945bb`
  (preceded by `5be1c23`, `d24c505`, `9e657e5`).
- Re-verification: `85959ad` (fixes), frozen worktree `/tmp/kilo/execution-review-85959ad`;
  probes re-run from `/tmp/kilo/rerun-85959ad/`; suite **504 passed in 85.95s**. See
  [§7](#7-re-verification-against-85959ad).
- Reviewer independence: not an author of `33945bb` or of any commit adding the EXECUTION test mechanisms.
  Source and normative documents (`docs/report-milestone8-readiness.md` R01/R04/R07/R15/R21, `docs/executors.md`,
  `docs/control-plane.md`, `docs/budgets.md`, `docs/tables/limits.yaml`) were read before the implementer's tests.
  No source was edited; all probes live under `/tmp/kilo/`.
- Baseline: `.venv/bin/python -m pytest -q` → **497 passed in 85.11s**. A green suite is not a verdict.
- No real credentials, no network, no paid calls; synthetic clients and local fixtures only. No host cgroup
  configuration was changed outside the reviewer's own delegated subtree.

### Host layout (recorded for every host-dependent finding)

| Property | Value |
|---|---|
| Kernel | `6.12.96+deb13-amd64` (Debian, x86_64) |
| cgroup | v2 only: `cgroup2 on /sys/fs/cgroup type cgroup2 (rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot)` |
| Delegated parent | `/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service` (owned by `ruben`, euid 1000) |
| Parent controllers | `cpu memory pids`; `cgroup.subtree_control` = `cpu memory pids` |
| `cgroup.kill` | present (writable) |
| Sandbox profile | `NAMESPACE_V1` available; Landlock ABI 6; libseccomp api 7; user namespaces available |
| Session cgroup | `…/app.slice/app-org.gnome.Terminal.slice/tmux-spawn-….scope` |

---

## 1. Verdict

**Initial verdict on `33945bb`: NO-GO** — three reachable P1 falsifications remained: a workload that escapes the
process group survives teardown on the no-cgroup path (R15), a cancellation racing result admission still admits and
integrates the cancelled attempt's candidate artefact (R04/R07), and a cancellation racing dispatch still reconciles
a dispatched charge to zero (R04).

**Re-verdict on `85959ad`: GO for the EXECUTION gate.** All three P1 and all four P2 findings are closed and the
original reproducers now pass; the forced F3 window is no longer constructible. One new **test-only** P2 (F8, a
cgroup leaked by the fix commit's own regression test) is recorded and is non-blocking for the gate. The verdict
below on the individual findings describes `33945bb`; §7 records the `85959ad` re-verification.

---

## 2. Findings

### F1 — P1 — A process-group escape survives teardown when no delegated cgroup is available

- **Invariant (R15, in-scope item 3):** "teardown kills, reaps, closes, and removes on every surviving path."
- **Root cause:** `SandboxRunner._kill` (`src/orchestrator/sandbox.py:868-877`) falls back to
  `os.killpg(os.getpgid(process.pid), SIGKILL)`. The workload is the launcher's grandchild and is deliberately
  re-parented (`sandbox_launcher.py` sets `PR_SET_PDEATHSIG` and `os.setsid` is available to the workload). A
  workload that clears `PR_SET_PDEATHSIG` (via `prctl(PR_SET_PDEATHSIG, 0)`) and calls `setsid()` leaves the
  launcher's process group, so `killpg` misses it. With a delegated cgroup, `_Cgroup.kill()` (writes `cgroup.kill`)
  still catches it; on the documented per-process fallback (`resource_source=RUSAGE_CHILDREN`, no cgroup) nothing
  does, and `_teardown` reports no error.
- **Reproducer** (`/tmp/kilo/ex_sandbox_probe.py`, cases 2 and 3):

  ```bash
  /home/ruben/Projectos/meta-project/orchestrator/.venv/bin/python /tmp/kilo/ex_sandbox_probe.py
  ```

  The workload is:
  ```python
  import ctypes, os, time
  libc = ctypes.CDLL(None, use_errno=True)
  libc.prctl(1, 0, 0, 0, 0)   # clear PDEATHSIG
  os.setsid()                  # leave the launcher's process group
  open('/work/leak.txt','w').write('escaped')
  time.sleep(120)
  ```
  Cancel is requested once `leak.txt` appears. Case 2 runs with `capabilities_override` of
  `dataclasses.replace(caps, cgroup_v2=False, cgroup_parent=None)`.
- **Observed:** `[2 escape/no-cgroup] cancelled in 0.14s` then
  `surviving probe host pids=[1947987, 1948626] alive=[True, True]` → `LEAK: workload survived teardown (BUG)`.
  Case 3 (cgroup enabled) reports `surviving probe host pids=[]` — `cgroup.kill` masks the defect on this host.
- **Expected:** the sandboxed process tree is gone after cancellation/timeout on every path; a surviving process
  is either killed or reported as a teardown error.
- **Impact:** untrusted candidate code persists after the attempt is torn down. Because the worktree bind mount
  stays alive in the escaped process's mount namespace, the process can keep writing to the candidate tree while
  the trusted controller runs `create_candidate` (the rename/symlink TOCTOU in in-scope item 1), consume host
  resources indefinitely, and survive across attempts. It is also the enabling condition for a non-cgroup
  deployment (common in CI/containers).
- **Proposed regression test:** a sandbox test that runs the escape workload with `cgroup_v2=False`, cancels, then
  scans the process table for the workload and asserts it is gone (and that teardown raises if it cannot be killed).
- **Maps to:** R15.

### F2 — P1 — A cancellation landing after the `late` read still admits and integrates the cancelled attempt's candidate

- **Invariant (R04, in-scope item 4):** "Late execution results must not create current results or artefacts."
- **Root cause:** `Controller.admit_observation_and_result` computes
  `late = run_terminal or attempt_terminal` from one state read (`src/orchestrator/controller.py:1241-1248`), then
  emits `RESULT_ADMITTED` and `ARTEFACT_ADMITTED`/`ARTEFACT_INTEGRATED` (`:1276-1310`). `RESULT_ADMITTED` is
  protected by the reducer's terminal-attempt guard, but `ARTEFACT_ADMITTED` has **no attempt-state guard**
  (`src/orchestrator/reducer.py:895-907`), so the stale `late=False` publishes the artefact of an attempt that has
  since been `CANCELLED`.
- **Reproducer** (`/tmp/kilo/ex_late_race_probe.py`):

  ```bash
  /home/ruben/Projectos/meta-project/orchestrator/.venv/bin/python /tmp/kilo/ex_late_race_probe.py
  ```

  The probe wraps `Controller._emit` so that the first `RESULT_ADMITTED` (after `late` was read) triggers
  `cancel_run`, then lets the emission continue — exactly the window between the state read and the artefact emits.
- **Observed:**
  ```
  attempt_state=CANCELLED
  freshness={}
  artefacts={'RUN-LATE-root-attempt-…-artefact': 'INTEGRATED'}
  artefact_…-artefact_present=True
  ARTEFACT_ADMITTED=True ARTEFACT_INTEGRATED=True RESULT_ADMITTED=True
  ```
- **Expected:** `artefacts == {}` and no `ARTEFACT_ADMITTED`/`ARTEFACT_INTEGRATED` events for a `CANCELLED`
  attempt; the candidate must be rejected like a late result.
- **Impact:** the cancelled attempt's candidate is marked `INTEGRATED`, and
  `Controller.get_candidate_reference` (latest `ARTEFACT_ADMITTED`) returns it as the run's candidate — a cancelled
  attempt's output becomes the run's published candidate. The delivered
  `test_cancellation_during_dispatch_does_not_produce_a_result` checks only attempt state (and implicitly the
  result), never the artefact.
- **Proposed regression test:** inject a cancellation between the `late` computation and the artefact emission
  (a barrier in a fake store or an `_emit` hook) and assert no artefact record and no `ARTEFACT_*` events. The
  durable fix is an attempt-state guard on `ARTEFACT_ADMITTED`/`ARTEFACT_INTEGRATED` in the reducer, or
  re-deriving `late` at the artefact decision.
- **Maps to:** R04, R07.

### F3 — P1 — A concurrent dispatch launders a dispatched charge to zero

- **Invariant (R04, in-scope item 4):** "distinguish never-dispatched reclamation from uncertain dispatched
  liability"; "never … charge" for a cancelled attempt is replaced by conservative settlement once dispatched.
- **Root cause:** `Controller._cancel_attempt` captures
  `dispatched = attempt.state in ("DISPATCHED","RUNNING","OBSERVATION_RECEIVED")`
  (`src/orchestrator/controller.py:462`) *before* calling `executor.cancel()` and emitting
  `CANCELLATION_CONFIRMED`. An `ACTION_DISPATCHED` admitted in that window moves the attempt `RESERVED → DISPATCHED`,
  so `CANCELLATION_CONFIRMED` legally transitions `DISPATCHED → CANCELLED`; but the stale `dispatched=False` sends
  the accounting down the never-dispatched branch (`:478-490`) and reclaims the full commitment.
- **Reproducer** (`/tmp/kilo/ex_launder_race_probe.py`) — faithful two-thread version:

  ```bash
  /home/ruben/Projectos/meta-project/orchestrator/.venv/bin/python /tmp/kilo/ex_launder_race_probe.py
  ```

  A cancellation thread reaches `executor.cancel` (after capturing `dispatched=False`) and waits; the real dispatch
  thread then admits `ACTION_DISPATCHED` and is held before `executor.dispatch` returns; the cancellation resumes.
- **Observed (stable over three runs):**
  ```
  before: state=RESERVED accounting=OPEN charged=0.0
  after:  state=CANCELLED accounting=FINALLY_SETTLED actual=0.0 charged=0.0
  dispatch_event=True cancel_event=True errors=[('dispatch', 'AttemptCancelled', '…')]
  VERDICT: dispatched liability laundered to zero (BUG)
  ```
- **Expected:** a dispatched attempt settles conservatively — the commitment (or a durable reported actual) is
  retained, i.e. `charged == 5.0` for the fixture, not `0.0`.
- **Impact:** real spend/liability is erased from the ledger under a legal interleaving; the SPEND gate's
  conservative-settlement invariant is defeated from the EXECUTION path. The delivered cancellation tests run
  dispatch and cancel sequentially, so the interleaving is never exercised.
- **Proposed regression test:** a two-thread test that admits `ACTION_DISPATCHED` inside the cancellation window and
  asserts conservative settlement. The durable fix is to compute liability at reduction time (reducer effect) or
  derive "was dispatched" from the event log under the store lock, not from a pre-`cancel` state snapshot.
- **Maps to:** R04.

### F4 — P2 — Teardown failures on an exceptional path are silently dropped

- **Invariant (R15, in-scope item 3):** fail closed; "removes on every surviving path."
- **Root cause:** `SandboxRunner.run` computes `cleanup_errors = self._teardown(...)` in a `finally`, but the
  `if cleanup_errors: raise SandboxSetupError(...)` check (`src/orchestrator/sandbox.py:772-775`) sits *after* the
  `try/finally`. When the `try` raises, the propagating exception skips that check, so teardown failures
  (unremoved cgroup, unreaped launcher) are discarded.
- **Reproducer** (`/tmp/kilo/ex_setup_probe.py`, case 2): force a real setup failure (a read-only mount whose host
  path does not exist) while `_Cgroup.remove` returns `False`.

  ```bash
  /home/ruben/Projectos/meta-project/orchestrator/.venv/bin/python /tmp/kilo/ex_setup_probe.py
  ```
- **Observed:**
  ```
  [1 setup-failure] SandboxSetupError: sandbox setup failed: mount('/nonexistent-host-path-xyzzy' …); new cgroups=[] probe_procs=[]
  [2 setup+teardown-fail] SandboxSetupError teardown-reported=False: sandbox setup failed: …
  [2 setup+teardown-fail] leaked cgroups=['orchestrator-1951924-1790006485065'] (cleanup failure silently dropped)
  ```
- **Expected:** the leaked cgroup is reported (the run fails closed with a teardown error, or at least records it).
- **Impact:** on any exceptional path a leaked cgroup/process is invisible to the caller and to recovery
  monitoring. The delivered `test_unremoved_cgroup_fails_the_run_closed` covers only the normal path.
- **Proposed regression test:** force setup failure *and* a teardown failure and assert the teardown error is
  reported (e.g. `SandboxSetupError` mentions the unremoved cgroup, or a chained cause).
- **Maps to:** R15.

### F5 — P2 — `limits_verified` is computed but never persisted in executor evidence

- **Invariant (R15, in-scope item 5):** a run whose cgroup limits could not be verified must report
  `cgroup=None`, `limits_verified=False`, and `resource_source=RUSAGE_CHILDREN`.
- **Root cause:** `SandboxObservation` carries `cgroup` and `limits_verified`
  (`src/orchestrator/sandbox.py:225,763`), but `CommandExecutor._dispatch` copies only
  `resource_source` into the durable `COMMAND_RESULT` observation (`src/orchestrator/command_executor.py:175`).
  No event records `limits_verified` or `cgroup`.
- **Reproducer** (`/tmp/kilo/ex_setup_probe.py`, case 3): run the full controller path with a no-cgroup runner.
- **Observed:**
  ```
  [3 honest-fallback] resource_source=RUSAGE_CHILDREN limits_verified_present=False cgroup_present=False
  [3 honest-fallback] events claiming cgroup/enforcement=[]
  ```
- **Expected:** the persisted evidence distinguishes verified limits from the per-process fallback (e.g. carry
  `limits_verified`/`cgroup` in the observation), so the R15 claim is auditable from the log.
- **Impact:** durable evidence does not overstate enforcement, but it cannot substantiate it either; the
  verification is in-process only. The delivered test asserts `observation.limits_verified is False` on the
  `SandboxObservation`, never on the persisted response.
- **Proposed regression test:** with cgroup disabled, assert the admitted `COMMAND_RESULT` observation reports
  `limits_verified=False` (and `resource_source=RUSAGE_CHILDREN`); with cgroup enabled, `limits_verified=True`.
- **Maps to:** R15.

### F6 — P2 — `changed_paths` over-reports mode-only changes that Git normalises away

- **Invariant (R07, in-scope item 2):** "the verified hash and scope describe the committed tree."
- **Root cause:** `create_candidate` records `changed_paths` from the filesystem snapshot `changes`
  (`src/orchestrator/worktree.py:339`), while Git only represents the executable bit. A mode-only change to a
  non-Git-representable mode is reported as changed but produces an empty committed diff.
- **Reproducer** (`/tmp/kilo/ex_import_probe.py`, cases F and G):

  ```bash
  /home/ruben/Projectos/meta-project/orchestrator/.venv/bin/python /tmp/kilo/ex_import_probe.py
  ```
- **Observed:**
  ```
  [F mode-only-chmod444] changed_paths=['src/app.txt']; committed_diff=[]
  [G mode-only-chmod755] changed_paths=['src/app.txt']; committed_diff=['src/app.txt']
  ```
- **Expected:** `changed_paths` equals the committed base-to-candidate diff (the record is the artefact's
  description); a chmod 444 is either reported as unchanged or as a non-Git-representable metadata change.
- **Impact:** the artefact record claims a change absent from the commit. Scope enforcement is unaffected (the
  committed diff is also scope-checked), so this is an evidence-accuracy defect, not an import escape.
- **Proposed regression test:** assert `changed_paths` equals `git diff --name-only base..candidate` for mode-only
  and content changes.
- **Maps to:** R07.

### F7 — P2 — `path_in_scope` treats `..` and absolute paths as in-scope relative paths

- **Invariant (in-scope item 1):** "`..` and absolute paths … cannot … escape the frozen scope."
- **Root cause:** `_segments` (`src/orchestrator/executor_protocol.py:286`) only drops empty and `.` segments; `..`
  is kept, and a leading `/` is ignored. `path_in_scope("src/../../etc/passwd", ["src/**"], [])` therefore returns
  `True`, and `/etc/passwd` matches `**`.
- **Reproducer** (`/tmp/kilo/ex_import_probe.py`, case K): `validate_response` with
  `changed_paths=["src/../../etc/passwd"]` under `include=["src/**"]`.
- **Observed:** `[K dotdot-path-in-scope] ACCEPTED (BUG)`.
- **Expected:** a protocol violation; paths are normalised and rejected if they escape the delegated scope.
- **Impact:** a hostile or compromised executor can report out-of-scope paths as in-scope in its untrusted
  response. No file escape was demonstrated: import and the publication gate use snapshot-derived relative paths,
  which cannot contain `..`. This is a boundary-hygiene defect in the untrusted-response scope check and is latent
  for any caller that passes untrusted paths (e.g. model-output admission).
- **Proposed regression test:** a table of `..`, absolute, double-slash and trailing-slash paths asserting
  rejection (or normalised evaluation) for `path_in_scope` and `validate_response`.
- **Maps to:** R01/R07 (scope gate).

---

## 3. Claims verified

"Verified" means attacked with a reproducer or a deliberate negative; a green suite was not used as evidence.

### Item 1 — Trusted import cannot be steered by candidate content (R01/R07)

| Attack | Result |
|---|---|
| `.git` as a file | rejected `ProtocolViolation` (`_reject_git_metadata`) |
| `.git` as a symlink to `/etc` | rejected |
| nested `src/sub/.git/config` | rejected |
| `.gitattributes` with `filter=evil` | rejected by scope when out of scope; if in scope, a transforming attribute makes the committed blob differ from `_expected_entries`, so verification fails closed. No attribute-only bypass found. |
| file → directory at same path | accepted; committed tree matches (`src/app.txt/inner.txt`) |
| directory → file at same path | accepted; committed tree matches |
| rename `src/a.txt` → `src/b.txt` | accepted; both paths reported; tree matches |
| ignored file (`.gitignore`) | `git add -A -f` commits it (`in_commit=True`) |
| mode-only chmod 755 | committed and reported; chmod 444 over-reported (F6) |
| directory symlink in base | preserved as `120000` |
| `..` / absolute path in untrusted `changed_paths` | accepted (F7); not reachable into import |
| scope glob prefix `src/health/**` vs `src/health-evil/x` | rejected `OutOfScopeError` |
| path normalising onto `hidden-tests/**` / `.orchestrator/**` | rejected by exclude |
| rename/symlink TOCTOU between snapshot and import | not directly reproducible on the cgroup path; enabled by F1 on the no-cgroup path (escaped writer can mutate the tree during `create_candidate`) |

**Conclusion: attacked, not falsified on the cgroup path.** Import cannot be steered by candidate Git metadata;
the committed tree is verified against a fresh recomputation; hidden base content survives. The residual TOCTOU
risk is a consequence of F1, not an independent import defect.

### Item 2 — Verification binds the committed object (R07/R21)

| Attack | Result |
|---|---|
| recompute `tree_digest` from the bundle's `ls-tree` | equal to the recorded digest (`J`) |
| `content_hash` vs committed tree | `record["tree_digest"] == artefact["content_hash"]`; recomputed from the commit, not the worktree |
| present a foreign commit as the artefact reference | rejected (`artefact 'deadbeef' was not imported by the controller`) |
| excluded base content (`hidden-tests/secret.py`) survives an in-scope change | present in the candidate commit |
| mutate the bundle bytes after verification | `git fetch` fails (`rc=1`) — Git content addressing detects it |
| mutate the committed blob after verification | no post-import re-verification is required because the digest is over Git objects; a mutated object fails Git's own hash check on fetch |

**Conclusion: verified.** The verified hash and scope describe the committed tree; the bundle is durable before
`cleanup()`; object mutation is detected by Git. `changed_paths` is the one field that does not describe the commit
(F6).

### Item 3 — Limits and membership are real or honestly absent (R15)

| Attack | Result |
|---|---|
| normal path | `cgroup=True limits_verified=True resource_source=CGROUP`; cgroup directory removed after the run |
| denied limit write | `set_limits` raises; cgroup discarded; fallback `cgroup=None limits_verified=False resource_source=RUSAGE_CHILDREN` |
| limit does not read back | rejected (delivered test + `set_limits` read-back) |
| placement of a pid not in `cgroup.procs` | rejected (`pid … is not a member of … after placement`) |
| placement denial | surfaces as `OSError` → controller `DISPATCH_FAILED` (fail closed) |
| no delegated cgroup | honest fallback; limits are per-process `RUSAGE_CHILDREN` |
| `cpu.max` not written | consistent with the documented residual; no enforcement is claimed |
| cgroup removal while a grandchild is alive | `cgroup.kill` catches it on this host (kernel 6.12); see residuals |
| teardown kills/reaps/removes on every path | **falsified**: F1 (escape survives without cgroup) and F4 (cleanup error dropped on the exceptional path) |

**Conclusion: falsified (F1, F4).** Limits and membership verification themselves are real and fail closed; the
teardown guarantee is not.

### Item 4 — Cancellation stops work and preserves liability (R04)

| Attack | Result |
|---|---|
| never-dispatched cancel | `CANCELLED`, accounting `FINALLY_SETTLED`, `charged=0.0`, reservation reclaimed |
| dispatched cancel during a blocking workload | interrupted promptly; `AttemptCancelled`; `CANCELLED`; `charged=5.0` (conservative); no result/freshness |
| cancel twice | idempotent (one `CANCELLATION_CONFIRMED`) |
| cancel during trusted import (after commands) | `CANCELLED`, `charged=5.0`, no result, no artefact |
| cancel concurrently with acknowledgement | **falsified**: F3 launders a dispatched charge to zero |
| late result vs cancelled attempt | freshness protected by the reducer; **artefact not protected** (F2) |
| runner interrupted promptly | yes (0.5–0.8 s poll) |

**Conclusion: falsified (F2, F3).** The happy-path liability split holds; two interleavings break it.

### Item 5 — One attempt deadline and truthful accounting (R15)

| Attack | Result |
|---|---|
| two commands, first consumes the budget | `AttemptTimedOut` at 1.04 s for a 1.0 s budget; the second command never receives a fresh budget |
| monotonic shared deadline | held across commands |
| `resource_source` honesty | fallback reports `RUSAGE_CHILDREN`; no event claims cgroup enforcement |
| `limits_verified` honesty | correct on `SandboxObservation`; **not persisted** (F5) |

**Conclusion: attacked, not falsified for the deadline; falsified for evidence persistence (F5).**

---

## 4. Residual unknowns

- **Controller death.** Not tested (documented residual). Teardown only runs if the controller survives; no
  independent supervisor exists.
- **Kernels without `cgroup.kill` (pre-5.14) or without a delegated cgroup.** F1's escape also applies with a
  cgroup present when `cgroup.kill` is unavailable; `_teardown` would report an unremoved cgroup (fail closed) but
  would not actually terminate the escaped process. Not reproducible on this host.
- **Read-only `subtree_control` / partial delegation.** Not forced on the real host (would require changing host
  cgroup configuration); reasoned from the code and the delivered monkeypatch test. The fallback is honest.
- **`cpu.max` rejection (host quirk).** Not re-reported; consistent with the documented residual.
- **Import time against the shared deadline.** `create_candidate` is not bounded by `attempt_deadline`; a slow
  trusted import can exceed the wall budget while still producing a result. Not measured (needs an injected slow
  import); low impact.
- **`admit_model_outputs` does not check `late`.** A cancelled attempt with `model_outputs` could still admit
  outputs. R17 territory; noted as an incidental interaction, not scored.
- **Other environments / architectures.** Only this Debian/x86_64 host was tested.

---

## 5. Execution-path audit

| Path | Starts workload | Imports candidate | Releases limits | Verifies | Cleans up |
|---|---|---|---|---|---|
| `Controller.dispatch_attempt` → `CommandExecutor.dispatch` → `SandboxRunner.run` | yes | no | yes (cgroup/limits/placement before Popen config) | limits read-back, placement membership, `tree_digest` vs commit | `_teardown` on all paths, but drops errors on exceptional paths (F4) and misses process-group escapes without cgroup (F1) |
| `CommandExecutor._dispatch` command loop | yes (per command) | no | per command, shared deadline | observation hashes, scope gate | worktree `finally` cleanup; artefact bundle created before cleanup |
| `WorktreeManager.create_candidate` | no | yes | n/a | `_reject_git_metadata`, committed-tree digest, committed-diff scope | integration repo removed by caller cleanup |
| `Controller.admit_observation_and_result` | no | no (admits artefact) | no | protocol, redaction, hashes | n/a; stale `late` publishes cancelled artefacts (F2) |
| `Controller._cancel_attempt` | no | no | no (settles) | none | none; stale `dispatched` launders liability (F3) |
| `Controller.recover` | no | no | no (settles) | event log | idempotent continuations |

---

## 6. Reproduce everything

```bash
cd /home/ruben/Projectos/meta-project/orchestrator
git worktree add --detach /tmp/kilo/execution-review-33945bb 33945bb
/home/ruben/Projectos/meta-project/orchestrator/.venv/bin/python -m pytest -q   # 497 passed

PY=/home/ruben/Projectos/meta-project/orchestrator/.venv/bin/python
$PY /tmp/kilo/ex_import_probe.py       # A–L: metadata, scope, verification (F6, F7)
$PY /tmp/kilo/ex_import_probe2.py      # M–R: file/dir swap, rename, glob prefix, bundle mutation, placement
$PY /tmp/kilo/ex_sandbox_probe.py      # 1–7: limits, escape (F1), teardown-on-error (F4)
$PY /tmp/kilo/ex_setup_probe.py        # 1–3: setup-failure cleanup (F4), evidence honesty (F5)
$PY /tmp/kilo/ex_cancel_probe.py       # A–E: cancellation liability, deadline
$PY /tmp/kilo/ex_late_race_probe.py    # F2: cancelled artefact integrated
$PY /tmp/kilo/ex_launder_race_probe.py # F3: dispatched charge laundered
```

Probe sources live under `/tmp/kilo/` and are the exact scripts used above; no repository source was modified.

---

## 7. Re-verification against `85959ad`

Same independent reviewer, same probes, frozen worktree `/tmp/kilo/execution-review-85959ad`
(probe copies in `/tmp/kilo/rerun-85959ad/`). Baseline `.venv/bin/python -m pytest -q` → **504 passed in 85.95s**.
Fixes were read (`git diff 33945bb 85959ad`) before re-running, so the verdict does not rest on the commit message.
The `_cancel_attempt` admission lock was checked for reentrancy: `EventStore._lock` is a `threading.RLock`
(`src/orchestrator/store.py:130`), so wrapping `_emit` in `store.serialized()` does not deadlock.

### 7.1 Finding-by-finding re-verification

| Finding | Fix under test | Probe | Observed on `85959ad` | Result |
|---|---|---|---|---|
| F1 process-group escape | teardown captures the `/proc` descendant chain before kill and verifies none survive (`sandbox.py:892-967`) | `ex_sandbox_probe.py` cases 2–3 | `[2 escape/no-cgroup] surviving probe host pids=[] alive=[]`; `[3 escape/cgroup] … []` | **closed** |
| F2 cancelled artefact integrated | reducer retains `ARTEFACT_ADMITTED` for `CANCELLED/FAILED/TIMED_OUT`; controller re-derives state before publishing (`reducer.py:899-906`, `controller.py:1298-1310`) | `ex_late_race_probe.py` | `artefacts={}`; `ARTEFACT_ADMITTED=False ARTEFACT_INTEGRATED=False`; `freshness={}` | **closed** |
| F3 dispatched-charge laundering | `_cancel_attempt` holds the admission lock across read-decide-settle and derives `dispatched` from the durable log (`controller.py:444-499`) | `ex_launder_race_verify.py` (legal interleavings; the original forced-window probe is no longer constructible — its dispatch thread cannot admit `ACTION_DISPATCHED` while the cancel holds the lock) | C1 dispatch-then-cancel `charged=5.0` RETAINED; C2 cancel-then-dispatch `charged=0.0` RECLAIMED; C3 8/8 iterations `laundering=[]` | **closed** |
| F4 teardown failure on exceptional path | `run()` tears down in `except BaseException`, reports cleanup errors, and raises `SandboxSetupError` for an unremovable cgroup (`sandbox.py:770-786, 620-627`) | `ex_sandbox_probe.py` case 5, `ex_setup_probe.py` cases 1–2 | `SandboxSetupError: … could not be removed after a limit-setup failure`; `[2 …] teardown-reported=True` | **closed** |
| F5 `limits_verified` not persisted | `limits_verified` and `cgroup` added to the durable `COMMAND_RESULT` observation (`command_executor.py:176-181`) | `ex_setup_probe.py` case 3 | `limits_verified_present=True cgroup_present=True`; fallback still reports `resource_source=RUSAGE_CHILDREN` | **closed** |
| F6 `changed_paths` over-reports mode-only changes | record uses the committed base-to-candidate diff (`worktree.py:339-343`) | `ex_import_probe.py` cases F–G | chmod 444 → `changed_paths=[]` (matches empty committed diff); chmod 755 → `['src/app.txt']` | **closed** |
| F7 `..`/absolute paths in scope | `path_in_scope` rejects absolute and `..` paths (`executor_protocol.py:330-344`) | `ex_import_probe.py` case K | `rejected: changed path 'src/../../etc/passwd' is outside the delegated owned_scope` | **closed** |

All other attacked cases are unchanged and still correct (`.git` variants rejected; hidden content survives; ignored
files committed; dir symlinks preserved; file↔dir swap and rename correct; glob-prefix rejected; bundle mutation
detected by Git; placement membership rejected; cancellation liability A–E correct; shared deadline 1.07 s for a
1.0 s budget).

### 7.2 New finding

**F8 — P2 (test-only) — the fix commit's F4 regression test leaks a delegated cgroup on every run.**

- **Location:** `tests/test_batch3_execution.py:340-356` (`test_teardown_failure_is_reported_after_a_setup_failure`).
- **Cause:** the test monkeypatches `sandbox._Cgroup.remove` to always return `False` (to force the teardown-failure
  path) and its `finally` removes only its temporary directories, never the cgroup it created.
- **Reproducer:**
  ```bash
  P=/sys/fs/cgroup/user.slice/user-1000.slice/user@1000.service
  ls -d $P/orchestrator-* 2>/dev/null | wc -l                       # 0
  /home/ruben/Projectos/meta-project/orchestrator/.venv/bin/python -m pytest -q \
      tests/test_batch3_execution.py -k teardown_failure            # 1 passed
  ls -d $P/orchestrator-* 2>/dev/null | wc -l                       # 1 (leaked)
  ```
- **Observed:** exactly one `orchestrator-*` cgroup per run remains in the delegated subtree (seven had accumulated
  across the author's pre-commit run, the author's full-suite run, and this reviewer's suite run before cleanup).
- **Expected:** the test leaves no cgroup behind — either call the original `remove` then claim failure (as
  `tests/test_fail_closed_harness.py:103-107` does), or remove the created cgroup in `finally`.
- **Impact:** test-only host hygiene; the production path correctly reports the unremovable cgroup and fails closed.
  No gate guarantee is violated.
- **Maps to:** R15 (test mechanism).

### 7.3 Residuals after re-verification

- **Controller death** — unchanged, deliberate scope; needs an external supervisor.
- **Import not bounded by the attempt deadline** — unchanged (`create_candidate` can exceed the wall budget while
  still producing a result). Low impact; not a numbered finding.
- **`_descendants` is a snapshot of the `/proc` parent chain at kill time.** A process that double-forks and whose
  intermediate parent is reaped between the snapshot and the kill could be missed; within the PID namespace the
  namespace init's exit tears the namespace down, so no leak was demonstrated. Not reproducible on this host.
- **Kernels without `cgroup.kill`** — F1's fix no longer relies on `cgroup.kill`, so the older-kernel variant is
  covered by the descendant scan.
- **Other environments / architectures** — only this Debian/x86_64 host was available.

### 7.4 Reproduce the re-verification

```bash
cd /home/ruben/Projectos/meta-project/orchestrator
git worktree add --detach /tmp/kilo/execution-review-85959ad 85959ad
/home/ruben/Projectos/meta-project/orchestrator/.venv/bin/python -m pytest -q   # 504 passed

PY=/home/ruben/Projectos/meta-project/orchestrator/.venv/bin/python
D=/tmp/kilo/rerun-85959ad
$PY $D/ex_import_probe.py           # F6, F7 closed
$PY $D/ex_import_probe2.py          # import/verification unchanged
$PY $D/ex_sandbox_probe.py          # F1, F4 closed
$PY $D/ex_setup_probe.py            # F4, F5 closed
$PY $D/ex_cancel_probe.py           # cancellation liability/deadline unchanged
$PY $D/ex_late_race_probe.py        # F2 closed
$PY $D/ex_launder_race_verify.py    # F3 closed (legal interleavings)
```
