<!-- informative -->

# Untrusted Model-Reply Boundary — Adversarial Review

- Repo: `/home/ruben/Projectos/meta-project/orchestrator`
- Revision reviewed: `d6b48c9` ("Record rejected model replies, and add an opt-in prompt/reply
  transcript"), frozen worktree `/tmp/kilo/reply-review-d6b48c9`.
- Independence: not an author of `d6b48c9` or `9a63e25`, nor of the reply-boundary tests. The
  sources (`scripts/smoke_run.py`, `model_adapter.py`, `controller.py`, `reducer.py`) and the
  normative documents (`docs/executors.md`, `docs/control-plane.md`, `docs/glossary.md`,
  `docs/tables/model-output-lifecycle.yaml`) were read before the implementer's tests.
- Baseline: `.venv/bin/python -m pytest -q` from the frozen worktree → **545 passed in 96.99s**.
  A green suite is not a verdict.
- No source edits; no third-party network; no real credentials; no paid calls. All probes are
  local (`/tmp/kilo/reply-probes/`) against a stub HTTP server on `127.0.0.1:8799`. The frozen
  worktree is clean (`git status --short` empty).

---

## 1. Verdict

**NO-GO for the untrusted-model-reply boundary as stated.** Strict admission, identity binding,
recorded failures, and no-abort hold, but claim 5 is falsified (a reply is read, parsed, admitted,
and durably stored without any size bound, and a slow reply blocks the run past the wall deadline),
and claim 2 is falsified (untrusted reply bytes are persisted verbatim in trusted rejection/failure
records). *(Verdict against `d6b48c9`; see [§7](#7-re-verification-against-dc4acfd) and
[§8](#8-final-re-verification-against-83f8ae1) for the fix re-verifications.)*

---

## 2. Findings

### F1 — P1 — Reply size is unbounded end to end (memory ≈5× and durable store ≈3× the reply)

- **Claim violated:** claim 5 ("reply size, depth, and structure cannot exhaust memory"). Also
  claim 2 for the stored-content half.
- **Root cause:** `OpenAICompatibleClient._post` reads the whole body with no cap
  (`scripts/smoke_run.py:279`, `response.read().decode()`); `_extract_json_object` copies it
  (`.strip()`, `find`/`rfind`, slice, `json.loads`); a schema-valid reply is admitted and written
  to the event store (three times: `EXECUTOR_OBSERVATION_ADMITTED`, `RESULT_ADMITTED`,
  `MODEL_OUTPUT_ADMITTED`). No field, body, or event-payload limit exists. The only bound in the
  file, `_TRANSCRIPT_FIELD_LIMIT = 8192` (`scripts/smoke_run.py:112`), applies to the debug
  transcript alone.
- **Reproducer (transport):** stub scenario `huge` (a schema-valid `SEMANTIC_EVALUATION` with an
  `N`-byte rationale):
  ```bash
  PY=/home/ruben/Projectos/meta-project/orchestrator/.venv/bin/python
  $PY /tmp/kilo/reply-probes/client_probe.py 8799 "" "/s/huge?size=268435456"
  ```
  Observed client peak RSS (`MAX_RSS_KB`, `resource.getrusage`): `16 MiB → 81,648 KB`,
  `64 MiB → 229,144 KB`, `256 MiB → 818,816 KB` (~3× at the transport layer).
- **Reproducer (end to end, real smoke runner):** `/tmp/kilo/reply-probes/measure_child.py` wraps
  `scripts/smoke_run.py --probe` (env block in §6):
  ```bash
  $PY /tmp/kilo/reply-probes/measure_child.py $PY scripts/smoke_run.py --probe   # path /s/huge?size=…
  ```
  Observed: `64 MiB reply → MAX_RSS_KB 364,104`; `256 MiB reply → MAX_RSS_KB 1,347,284` (~5×), and
  the reply is admitted (`MODEL_OUTPUT_ADMITTED`). The durable event store grows ~3×:
  `64 MiB → events.db 201,560,064 B`; `256 MiB → events.db 806,129,664 B`.
- **Expected:** a reply cannot convert reply volume into host memory or durable state; an oversized
  reply is rejected (recorded as a rejection) rather than read unbounded and admitted.
- **Why it matters:** a real or compromised OpenAI-compatible endpoint (or a model induced to emit
  a long completion) can OOM the runner or fill the authoritative event store. The admitted body is
  attacker-chosen content that replay and observability must then carry.
- **Proposed permanent regression test:** serve an `N`-byte reply from a local stub and assert
  (a) the client raises a recorded rejection rather than returning a completion, (b) peak RSS is
  bounded independently of `N`, and (c) `events.db` does not grow with `N`.

### F2 — P1 — No total wall-clock deadline around the blocking model call; a slow reply overruns `wall_clock_seconds`

- **Claim violated:** claim 5 ("… or hang past the wall deadline").
- **Root cause:** `OpenAICompatibleClient._post` uses `urllib.request.urlopen(..., timeout=self.timeout)`
  (`scripts/smoke_run.py:278`), a per-socket-operation timeout, not a total deadline. The controller
  enforces the run deadline only between actions, in `_enforce_run_deadline` (`controller.py:220-234`,
  called from `_enforce_plan_limits` at `controller.py:310`), never around the synchronous
  `executor.dispatch` call (`controller.py:1088`). The model adapter has no timeout of its own.
- **Reproducer:** stub scenario `slow_drip` drips a small valid body in 8 chunks 1.5 s apart
  (~12 s total), each gap well under the 60 s socket timeout, with `ORCHESTRATOR_WALL_SECONDS=2`:
  ```bash
  ORCHESTRATOR_WALL_SECONDS=2 ORCHESTRATOR_PROVIDER_PATH='/s/slow_drip?drip=1.5' \
  $PY scripts/smoke_run.py --probe     # env block in §6
  ```
- **Observed:** the probe returned **exit 0, "probe OK"** after **12.26 s** (measured), with the
  reply admitted and the attempt `RESULT_PRODUCED`. A continuous drip would block indefinitely.
- **Expected:** the call is bounded by the attempt/run wall deadline; exceeding it fails the
  attempt closed (`CANDIDATE_TIMEOUT`/`RunLimitExhausted`) and settles accounting, never admits the
  late reply.
- **Why it matters:** a provider can pin a worker/run without bound, defeating the frozen
  `wall_clock_seconds` limit. This is transport-level, but claim 5 is explicit and the brief lists
  "a reply that hangs the server past the wall deadline" as a required attack.
- **Proposed permanent regression test:** a stub that drips a valid reply past the configured wall
  deadline; assert the probe/attempt fails within the deadline (plus a small slack) and no output
  is admitted.

### F3 — P2 — Untrusted reply bytes are embedded verbatim in the "trusted" reason and persisted

- **Claim violated:** claim 2 ("a rejected reply produces `MODEL_OUTPUT_REJECTED` with the trusted
  reason only; the untrusted body is never stored").
- **Root cause:** rejection reasons interpolate untrusted field values. `validate_output` raises
  e.g. `f"path {path!r} is outside the delegated owned_scope"` (`model_adapter.py:250-254`), and
  `admit_model_outputs` persists `str(error)` verbatim as `MODEL_OUTPUT_REJECTED.reason`
  (`controller.py:1513-1524`; reducer `reducer.py:948-966` stores `reason=str(payload["reason"])`).
  The shipped HTTP parser also embeds an uncatalogued verdict in its error
  (`scripts/smoke_run.py:199-203`), which `dispatch_attempt` persists as the
  `EXECUTOR_FAILED`/`DISPATCH_FAILED` reason (`controller.py:1168-1188`).
- **Reproducer A (HTTP-reachable, `DISPATCH_FAILED`):** stub scenario
  `bad_verdict_huge?size=20971520` (a 20 MiB uncatalogued verdict). Observed: the
  `DISPATCH_FAILED` event payload is **20,971,941 bytes** and `events.db` is **21,024,768 bytes**;
  the attempt is `FAILED`/`FINALLY_SETTLED`. The 20 MiB untrusted verdict is durable state.
- **Reproducer B (adapter path, `MODEL_OUTPUT_REJECTED`):** `/tmp/kilo/reply-probes/rejected_reason_probe.py`
  submits an `OBSERVATION` whose `paths` field is an 8 MiB out-of-scope value (the schema and
  `_SCOPE_PATH_FIELDS` admit `paths`; the same shape is used by the shipped test
  `test_model_adapter_delegated_scope_is_enforced`). Observed: `state.model_outputs[...].reason`
  length **8,388,707**, `MODEL_OUTPUT_REJECTED` event reason length **8,388,707**, `body == {}`, and
  `db_bytes == 25,223,168`.
- **Reachability caveat:** the shipped smoke parser drops extra fields, so reproducer B requires an
  adapter/client that passes model-supplied `paths` through (the adapter is explicitly designed to
  accept them). Reproducer A is reachable with the shipped client as-is.
- **Expected:** the recorded reason is a trusted, bounded diagnostic; no untrusted byte from the
  reply is persisted.
- **Proposed permanent regression test:** submit an output with a huge out-of-scope `paths` value
  and an uncatalogued huge verdict; assert the persisted `MODEL_OUTPUT_REJECTED` / failure reason
  does not contain the untrusted value (or is truncated to a fixed bound) and the event payload is
  bounded.

### F4 — P2 — On the real path, malformed replies are never `MODEL_OUTPUT_REJECTED` (claim 2's first clause is unmet)

- **Claim violated:** claim 2 ("a rejected reply produces `MODEL_OUTPUT_REJECTED`").
- **Observation:** the shipped client's `parse_provider_completion` refuses every reply that is not
  a catalogued three-field object *before* the adapter produces a typed output, so malformed
  replies never reach `validate_output`. Every malformed reply in the matrix below is recorded as
  `DISPATCH_FAILED` + `ATTEMPT_COST_SETTLED_CONSERVATIVELY` and the attempt is `FAILED`; no
  `MODEL_OUTPUT_REJECTED` is ever emitted. With `CURRENT_POLICY_VERSION == 1` (`events.py:53`) and
  provenance built from the pinned run policy, the model-output `REJECTED` state is unreachable
  from the shipped client.
- **Reproducer:** `run_e2e.py` over `prose empty array scalar truncated deep bad_verdict
  empty_rationale nonstring_part content_dict bad_json_body huge_usage_int inf_usage string_usage
  choices_missing choice_not_dict multi_choices deep_body_raw invalid_utf8` — all `exit 7`,
  `DISPATCH_FAILED`, attempt `FAILED`/`FINALLY_SETTLED`, `model_outputs == {}`.
- **Expected:** either malformed replies are recorded through the model-output rejection path, or
  the claim/audit trail should not assert `MODEL_OUTPUT_REJECTED` for them.
- **Why it matters:** safe (no pass, no live run, settled), but the claim and the audit trail are
  inaccurate: an operator inspecting the store sees a provider/protocol failure, not a model-output
  rejection, and the `REJECTED` catalogue state has no producer on the real path.
- **Proposed permanent regression test:** assert the intended mapping explicitly (either a
  `MODEL_OUTPUT_REJECTED` for schema-invalid typed replies, or a documented assertion that
  parse-layer refusals are `DISPATCH_FAILED`).

### F5 — P3 — Debug transcript hardening gaps

- **Claim:** claim 7 (bounded, redacted, `0600`, disabled by default, never the credential).
- **Observed:** the main properties hold — disabled by default (no `debug/` directory),
  `0600` on creation, response truncated to 8192 chars, and a credential echoed by the reply is
  redacted (`response` contains `redacted:sha256:…`, not `sekret-value`).
- **Gaps:** (a) `transcript_write` does not re-`chmod` an existing file: a pre-existing `0644`
  transcript stays `0644` (`os.open(..., 0o600)` only applies at creation); the enclosing directory
  is `0700`, so exposure is limited. (b) `_record` reads `request["attempt_id"]`/`request["node_id"]`
  (`scripts/smoke_run.py:247-248`), but the adapter passes `call_id`/`call_key`, so the transcript
  lines carry `"attempt_id": null, "node_id": null` — the debug binding is lost.
- **Proposed permanent regression test:** pre-create the transcript with `0644`, call
  `transcript_write`, assert the mode is `0600`; assert a real probe's transcript line carries the
  attempt/node binding.

---

## 3. Claims verified (attempted falsification, not "tests pass")

| # | Claim | Method / probe | Result |
|---|---|---|---|
| 1 | Strict admission: only schema/provenance/authority/scope/version/hash/policy-valid output is admitted | `forged_fields` scenario (reply carries `model_id`, `model_version`, `call_id`, `prompt_hash`, `policy_version`, `output_type`, `paths`, `artefact_hashes`, `input_versions`); direct `validate_output` mutations; `deep_body_raw`, `invalid_utf8` | **Attacked, not falsified.** Forged fields are dropped by the parser; the admitted payload is exactly `{rationale, subject_reference, verdict}` with adapter-built provenance (`call_id == attempt`, `prompt_hash == recorded`). Unknown types/verdicts, bad UTF-8, and out-of-scope paths are rejected. (Extra fields are not rejected by the schema — see F3; unbounded size — see F1.) |
| 2 | Recorded rejection, trusted reason only, untrusted body never stored | `bad_verdict_huge`, `rejected_reason_probe.py`, `run_e2e.py` matrix | **Falsified (F3, F4).** Untrusted bytes are persisted verbatim in rejection/failure reasons; on the real path malformed replies are `DISPATCH_FAILED`, never `MODEL_OUTPUT_REJECTED`. The `body` field itself is empty on rejection (holds). |
| 3 | No abort / no live run; no unsettled attempt | `run_e2e.py` matrix; `concurrency_probe.py`; store inspection | **Attacked, not falsified.** Every malformed reply yields a recorded failure and an attempt in `FAILED`/`CANCELLED` + `FINALLY_SETTLED`; `run_e2e.py` exits 7 (or 2/3), never a pass. 4 concurrent deliveries of one attempt/token invoke the priced client **once** and return one response object; a cancelled attempt raises `AttemptCancelled`. The only abort risk is OOM under F1. |
| 4 | Identity binding: reply cannot choose or forge provenance | `forged_fields`; `overrun_usage`; `echo_secret` | **Attacked, not falsified.** Provenance (`model_id`, `model_version`, `call_id`, `prompt_hash`, `policy_version`) is constructed by the adapter from the frozen request/attempt; the reply cannot set or override it. A model-identity mismatch is rejected by `validate_output` (existing R12 test). |
| 5 | Resource safety: size/depth/structure cannot exhaust memory or hang past the deadline | `huge` (16/64/256 MiB), `measure_child.py`, `slow_drip`, `deep`, `deep_body_raw`, `invalid_utf8` | **Falsified (F1, F2).** Memory ≈5× and durable store ≈3× the reply, unbounded; a drip reply ran 12.26 s against a 2 s wall deadline and was admitted. Deep nesting raises a non-fatal `RecursionError` → recorded failure (no hang, no memory blow-up observed at 200 k depth). |
| 6 | Accounting honesty: reported usage charged without clipping; a billed call not silently lost | `overrun_usage`, `overrun_unparseable`, `negative_usage`, `huge_usage_int`, `inf_usage`, `string_usage` | **Mostly holds.** A 6.0 usage against a 5.0 commitment records `actual=6.0`, `overrun=1.0`, attempt `FAILED`, no outputs (never clipped). Negative usage → `ModelBudgetRefused` → `BUDGET_EXHAUSTION_RECORDED` + `CANCELLED` + conservative settlement. Non-finite/oversized/string usage raises before cost is computed and is settled conservatively (known residual; §4). |
| 7 | Debug data safety: bounded, redacted, `0600`, off by default, never the credential | transcript probes, `echo_secret`, pre-existing-mode probe | **Attacked, not falsified** (main properties). Off by default; `0600` on creation; 8192-char bound; credential redacted. Gaps in F5. |

---

## 4. Accounting assessment

- **Billed-but-unrecorded exposure.** A reply that reports usage but fails to parse raises before
  `cost = …` is computed (`scripts/smoke_run.py:332-356`), so no `actual` is recorded; the attempt
  is settled conservatively at the full commitment (`ATTEMPT_COST_SETTLED_CONSERVATIVELY`).
  Demonstrated with `overrun_unparseable`: the stub reported `prompt_tokens=6,000,000` (true charge
  6.0 at the frozen price) against a 5.0 commitment; the ledger recorded exactly `5.0`
  (`total_charged=5.0`), leaving **1.0 unrecorded exposure**.
- **Does it block?** No. The attempt is `FAILED`/`FINALLY_SETTLED`, no output is admitted, no pass,
  and no live run remains. For a *conforming* provider the declared ceilings bound the true charge
  to `max_input_tokens/1e6·price_in + max_output_tokens/1e6·price_out = 0.004512` (with the probe's
  settings), far below the commitment, so conservative settlement over-covers. Exposure is
  `max(0, true_provider_charge − commitment)` and is unbounded only for a provider that ignores the
  declared `max_tokens`/input ceiling — the acknowledged client-reported-usage residual.
- **Overrun case is honest.** A parseable reply whose usage overruns the commitment is recorded in
  full (`overrun_usage`: `actual=6.0`, `overrun=1.0`, `token_overrun={input: 5,996,000}`), the
  attempt fails, and no output is admitted.

---

## 5. Residual unknowns

- **Pass-through adapters.** F3's `MODEL_OUTPUT_REJECTED` variant and the F1 storage growth for
  non-`SEMANTIC_EVALUATION` output types are demonstrated with the adapter/in-process client, not
  the shipped HTTP parser (which strips extra fields). A future real adapter that passes
  model-supplied `paths`/`artefact_references` through is exposed; the current shipped client is not.
- **Streaming / tool-call / refusal transports.** Out of scope per the brief (different transport =
  adaptation). Not tested.
- **Real provider conformance to declared ceilings.** The accounting exposure depends on a
  provider honouring `max_tokens`; a real provider was not used and cannot be tested offline.
- **Memory measurement environment.** Peak RSS is process `ru_maxrss` on this host; the durable-store
  growth is exact file size. A host without swap or with a lower cgroup limit would OOM earlier.
- **`deep` parse-DoS beyond 200 k depth.** Not exhaustively searched; observed `RecursionError`
  mapped to a recorded failure, but the recursion limit is the only guard.

---

## 6. Reproduce everything

Frozen revision and baseline:
```bash
git worktree add --detach /tmp/kilo/reply-review-d6b48c9 d6b48c9
cd /tmp/kilo/reply-review-d6b48c9
/home/ruben/Projectos/meta-project/orchestrator/.venv/bin/python -m pytest -q   # 545 passed
```

Start the stub (one process serves every scenario via `/s/<scenario>`):
```bash
PY=/home/ruben/Projectos/meta-project/orchestrator/.venv/bin/python
$PY /tmp/kilo/reply-probes/stub_server.py &        # binds 127.0.0.1:8799, prints "stub ready"
```

Shared probe env (end-to-end through `scripts/smoke_run.py --probe`):
```bash
export ORCHESTRATOR_MODE=real ORCHESTRATOR_OWNER=reviewer ORCHESTRATOR_CAP=100
export ORCHESTRATOR_CONFIRM_REAL=yes
export ORCHESTRATOR_PROVIDER_BASE_URL=http://127.0.0.1:8799
export ORCHESTRATOR_PROVIDER_MODEL=stub-model ORCHESTRATOR_PROVIDER_API_KEY=sekret-value
export ORCHESTRATOR_PRICE_INPUT_PER_MTOK=1.0 ORCHESTRATOR_PRICE_OUTPUT_PER_MTOK=1.0
export ORCHESTRATOR_WORKDIR=/tmp/kilo/reply-probes/runs/<name>
# set ORCHESTRATOR_PROVIDER_PATH=/s/<scenario> for each run
```

| Probe | Command | Result |
|---|---|---|
| Transport/parse matrix | `$PY /tmp/kilo/reply-probes/client_probe.py 8799 "" /s/<scenario>` | shape/schema/encoding outcomes |
| End-to-end matrix | `$PY /tmp/kilo/reply-probes/run_e2e.py` | failure mapping, no-abort, settle |
| Inspect a run | `$PY /tmp/kilo/reply-probes/inspect_run.py <workdir>/probe/events.db` | events, payload bytes, states |
| F1 memory (transport) | `client_probe.py 8799 "" '/s/huge?size=268435456'` | `MAX_RSS_KB 818816` |
| F1 memory/store (e2e) | `measure_child.py $PY scripts/smoke_run.py --probe` with `/s/huge?size=…` | 64 MiB→364 MB RSS/201 MB db; 256 MiB→1.35 GB RSS/806 MB db |
| F2 wall deadline | `ORCHESTRATOR_WALL_SECONDS=2` with `/s/slow_drip?drip=1.5` | exit 0 after 12.26 s |
| F3 HTTP reason | `/s/bad_verdict_huge?size=20971520` | `DISPATCH_FAILED` payload 20,971,941 B |
| F3 adapter reason | `$PY /tmp/kilo/reply-probes/rejected_reason_probe.py` | reason_len 8,388,707; db 25,223,168 B |
| Claim 3 concurrency | `$PY /tmp/kilo/reply-probes/concurrency_probe.py` | `client_calls: 1`, `AttemptCancelled` |
| Accounting | `/s/overrun_usage`, `/s/overrun_unparseable`, `/s/negative_usage` | see §4 |
| Transcript | `ORCHESTRATOR_DEBUG_TRANSCRIPT=1` with `/s/huge?size=8388608`, `/s/echo_secret` | 0600, 8192-char bound, redacted |

Stub scenarios: `valid prose empty fenced array scalar truncated parts multi_choices deep huge
bad_verdict bad_verdict_huge empty_rationale nonstring_part content_dict bad_json_body
deep_body deep_body_raw invalid_utf8 null_bytes huge_usage_int inf_usage negative_usage
string_usage usage_missing overrun_usage overrun_unparseable choices_missing choice_not_dict
slow_drip forged_fields echo_secret`.

No paid calls were made; all clients point at the local stub, and no source file was modified.

---

## 7. Re-verification against `dc4acfd`

- Corrective revision: `dc4acfd` ("Fix the untrusted-model-reply review findings (F1-F5)"),
  frozen worktree `/tmp/kilo/reply-review-dc4acfd`. Baseline: `.venv/bin/python -m pytest -q`
  → **551 passed in 93.28s**. Probe scripts were re-pointed with `REVIEW_WORKTREE`; the same local
  stub and scenario matrix were re-run. No source edits.

**Re-verification verdict: still NO-GO.** F2 is not fixed (a real dripping reply still hangs past the
wall deadline, unbounded), and F1's durable-store guarantee is only partially met. F3, F4, and F5
are resolved.

### 7.1 F2 — NOT fixed (P1, open)

- `_post` now checks `time.monotonic() > deadline` only *between* `response.read(65536)` calls, and
  the socket timeout is set once (`remaining = min(self.timeout, deadline - now)`). A single
  `HTTPResponse.read(65536)` blocks until 64 KiB or EOF; each drip block arrives within the socket
  timeout, so no `socket.timeout` fires and the outer loop never iterates. The deadline is therefore
  evaluated only after the whole body has been read.
- **Reproducer (bounded drip):** `/s/slow_drip?drip=1.5`, `ORCHESTRATOR_WALL_SECONDS=2` →
  `[03] probe FAILED: … provider reply exceeded the wall deadline`, but **elapsed 12 s** (fails
  closed only after the reply completes; a `DISPATCH_FAILED` is recorded and the attempt settles).
- **Reproducer (unbounded drip):** `/s/drip_forever?drip=1.0` advertises
  `Content-Length: 100000000` and writes 100 B/s forever. With `ORCHESTRATOR_WALL_SECONDS=2` the
  runner was still blocked when killed by `timeout 20` (**≥20 s, unbounded**).
- **The shipped regression test is non-faithful:** `test_total_deadline_bounds_a_dripping_reply`
  (`tests/test_smoke_run_client.py`) uses a `_FakeResponse.read` that ignores `_size` and returns
  one byte per call, so the loop iterates and sees the deadline. Real `HTTPResponse.read(65536)`
  blocks, so the test does not exercise the failing code path. A faithful test must model a read
  that blocks until 64 KiB/EOF (or read with `read1`/a per-read socket timeout recomputed from the
  deadline).
- **Suggested fix direction:** recompute the socket timeout before each bounded read from the
  remaining deadline (e.g. `sock.settimeout(max(0.01, deadline - now))`) and read in
  deadline-sized chunks, or run the read under a watchdog that closes the response at the deadline.

### 7.2 F1 — PARTIALLY fixed (P1 downgraded; residual P2)

- **Memory (transport): fixed.** `/s/huge?size=268435456` now raises
  `provider reply exceeds ORCHESTRATOR_MAX_REPLY_BYTES (1048576)` with `MAX_RSS_KB 33,072`; end to
  end a 64 MiB reply → `MAX_RSS_KB 35,376`, `events.db 32,768 B`, `DISPATCH_FAILED` payload 135 B.
- **Adapter body bound: enforced, but too late to bound the store.** `validate_output` rejects a
  body over `MAX_OUTPUT_BODY_BYTES` (64 KiB), and the rejection reason is bounded (77 B). However,
  the untrusted body is already written to `EXECUTOR_OBSERVATION_ADMITTED` and `RESULT_ADMITTED`
  (the events carry `dict(response)`, including `model_outputs`) before `admit_model_outputs`
  runs. Measured: a 1,000,000-byte reply (under the 1 MiB transport cap, over the 64 KiB body
  bound) → `MODEL_OUTPUT_REJECTED` with a 77-byte reason, but `EXECUTOR_OBSERVATION_ADMITTED`
  payload 1,001,115 B and `events.db 2,035,712 B`. The in-process `rejected_reason_probe.py`
  (8 MiB body, no transport cap) → reason 77 B and `body {}`, but `events.db 16,826,368 B`.
- **Consequence:** for the shipped HTTP client the durable growth is bounded by
  `ORCHESTRATOR_MAX_REPLY_BYTES` (≈2× the cap), not by the adapter's 64 KiB bound; for any
  non-HTTP/in-process client it remains unbounded. The commit's claim "the event store cannot grow
  with a reply for any client" is false. Suggested fix: apply the body-size bound before the
  observation/result events are emitted, or exclude `model_outputs` bodies from those payloads.

### 7.3 F3 — fixed (reasons bounded)

- HTTP path: `/s/bad_verdict_huge?size=200000` (200 KB uncatalogued verdict, under the reply cap) →
  `DISPATCH_FAILED` payload **485 B**, `events.db 32,768 B`. The client also truncates the verdict
  to 64 chars in its parse error.
- Adapter path: `rejected_reason_probe.py` → `MODEL_OUTPUT_REJECTED` reason **77 B**, `body {}`
  (the oversized body is caught by the 64 KiB bound first). The residual durable growth in 7.2 is
  the observation/result copy, not the reason.
- `_bounded_reason` (512 B) is applied to `MODEL_OUTPUT_REJECTED`, `DISPATCH_FAILED`,
  `EXECUTOR_FAILED`, and protocol diagnostics.

### 7.4 F4 — resolved (mapping documented and reachable)

The real-path mapping is now documented in the client: a parse-layer refusal (no typed output) is a
provider/protocol failure recorded as `DISPATCH_FAILED` with the attempt failed and settled;
`MODEL_OUTPUT_REJECTED` applies to a typed output that fails admission. The oversized-body case now
makes `MODEL_OUTPUT_REJECTED` reachable from the shipped client (`/s/huge?size=200000` →
`MODEL_OUTPUT_REJECTED`, reason 77 B, attempt `RESULT_PRODUCED`). The claim/audit-trail mismatch is
closed.

### 7.5 F5 — resolved

- `transcript_write` now `os.chmod(path, 0o600)` after writing; a pre-existing `0644` transcript
  becomes `0600` (verified).
- `_record` now reads `request["call_id"]`/`request["call_key"]`, so a real probe line carries
  `attempt_id=PROBE-1-root-attempt-…`, `node_id=PROBE-1-root` (verified).

### 7.6 Re-verification summary

| Finding | Status on `dc4acfd` | Evidence |
|---|---|---|
| F1 memory (transport) | **Fixed** | 256 MiB reply → 33 MB RSS; cap error; e2e 64 MiB → 35 MB RSS, 32 KB db |
| F1 durable store | **Partial (P2)** | 1 MB reply → 2 MB db via observation/result; 8 MiB in-process body → 16 MB db |
| F2 total wall deadline | **Not fixed (P1)** | slow drip 12 s vs wall 2 s; `drip_forever` ≥20 s unbounded; regression test non-faithful |
| F3 bounded reasons | **Fixed** | 200 KB verdict → 485 B payload; adapter reason 77 B |
| F4 mapping | **Fixed** | documented + `MODEL_OUTPUT_REJECTED` reachable via oversized body |
| F5 transcript | **Fixed** | pre-existing → 0600; call binding present |

Still open before GO: F2 (bound the whole call by the deadline, with a faithful regression test) and
the F1 observation/result persistence residual (or correct the claim to "bounded by
`ORCHESTRATOR_MAX_REPLY_BYTES`").

---

## 8. Final re-verification against `83f8ae1`

- Corrective revision: `83f8ae1` ("Fix the reply-boundary re-verification: bound the read and
  persist no oversized reply"), frozen worktree `/tmp/kilo/reply-review-83f8ae1`. Baseline:
  `.venv/bin/python -m pytest -q` → **552 passed in 89.62s**; `./scripts/check-docs` green
  (167 links, 0 errors). Same local stub and scenario matrix. No source edits.

**Re-verification verdict: GO** on the model-reply boundary claims as scoped. Both open items are
closed with faithful regressions. Residuals in §4 (client-reported usage) and the latent P3 below
remain non-blocking and out of the claim set.

### 8.1 F2 — fixed (total call deadline)

- Root cause confirmed as reported: `response.read(65536)` blocks until 64 KiB/EOF, so the
  between-read deadline check was unreachable for a drip. The client now uses
  `read1` (`getattr(response, "read1", None) or response.read`, `scripts/smoke_run.py`), which
  returns per system call, and the socket timeout stays clamped to the remaining budget
  (`remaining = max(0.1, min(self.timeout, deadline - now))`), with `request["timeout_seconds"]`
  carrying the run's absolute remaining deadline from `dispatch_attempt` (`controller.py:1086-1104`).
- **Reproducer (bounded drip):** `/s/slow_drip?drip=1.5`, `ORCHESTRATOR_WALL_SECONDS=2` →
  `[03] probe FAILED: … provider reply exceeded the wall deadline` in **3.21 s** (was 12 s),
  attempt `FAILED`/`FINALLY_SETTLED`.
- **Reproducer (previously unbounded drip):** `/s/drip_forever?drip=1.0`
  (`Content-Length: 100000000`, 100 B/s forever), `ORCHESTRATOR_WALL_SECONDS=2` → fails closed in
  **2.23 s** (was still blocked at ≥20 s), attempt `FAILED`/`FINALLY_SETTLED`, `DISPATCH_FAILED`
  payload 158 B.
- **Regression test is faithful:** `test_total_deadline_bounds_a_real_dripping_reply` replaces the
  non-faithful fake with a real `http.server` that promises 64 bytes and dribbles 1 byte every
  0.2 s (12.8 s total); `_post` must raise `TimeoutError` within a 0.5 s deadline, asserted under a
  3 s wall bound. The reply-size-cap test is retained.

### 8.2 F1 residual — fixed (no oversized body is persisted)

- `_strip_oversized_outputs` (`controller.py:1480`) runs at the top of `admit_observation_and_result`
  (`controller.py:1237`), **before** `EXECUTOR_OBSERVATION_ADMITTED` (`controller.py:1311`) and
  `RESULT_ADMITTED`: an output body over `MAX_OUTPUT_BODY_BYTES` (64 KiB) is dropped and recorded
  as a `MODEL_OUTPUT_REJECTED` with the fixed reason
  `output body exceeds the 65536-byte bound`; only bounded outputs proceed to admission.
- **Reproducer (HTTP, 1 MB reply):** `/s/huge?size=1000000` → `events.db 32,768 B`
  (was 2,035,712 B), `MODEL_OUTPUT_REJECTED` payload 197 B, and the untrusted marker is absent
  from every event payload.
- **Reproducer (in-process, 8 MiB body, no transport cap):** `rejected_reason_probe.py` →
  `events.db 32,768 B` (was 16,826,368 B), rejection reason 40 B, `body {}`, marker absent from
  `EXECUTOR_OBSERVATION_ADMITTED`/`RESULT_ADMITTED`/all events.
- **Boundary behaviour:** a 1,000-byte rationale admits (`MODEL_OUTPUT_ADMITTED`, 1,479 B payload);
  a 65,537-byte rationale is rejected (`MODEL_OUTPUT_REJECTED`, 197 B).
- **Regression test is faithful:** `test_oversized_reply_is_not_persisted_before_validation` builds
  a ~132 KB body, asserts a bounded `MODEL_OUTPUT_REJECTED`, asserts the marker appears in **no**
  event payload, and asserts `events.db < 1 MB`.

### 8.3 Regression spot-check (unchanged behaviour)

| Scenario | Outcome |
|---|---|
| `prose`, `bad_verdict`, `deep_body_raw`, `overrun_unparseable` | `exit 7`, `DISPATCH_FAILED`, `FAILED`/`FINALLY_SETTLED`, bounded reason, `model_outputs {}` |
| `usage_missing`, `forged_fields` | `exit 0`, `MODEL_OUTPUT_ADMITTED`, provenance adapter-bound (forged fields dropped) |
| `negative_usage` | `exit 2`, `CANCELLED`/`FINALLY_SETTLED`, `BUDGET_EXHAUSTION_RECORDED` (conservative settlement) |
| F3 bounded reason | `bad_verdict_huge?size=200000` → `DISPATCH_FAILED` payload 485 B (unchanged) |

### 8.4 Residuals (non-blocking, unchanged or latent)

1. **Client-reported usage (§4, unchanged):** a reply that reports usage but fails to parse is
   settled conservatively at the commitment; exposure `max(0, true_charge − commitment)`, unbounded
   only for a provider ignoring the declared `max_tokens`. Known residual.
2. **Latent P3 (pass-through clients only):** the oversized rejection's `output_type` field is
   `str(output.get("output_type", "UNKNOWN"))` and is not size-bounded. Not reply-reachable through
   the shipped client (the parser hardcodes `SEMANTIC_EVALUATION`); reachable only through an
   adapter/client that passes a model-supplied `output_type` through.
3. `_dispatch_responses` retains the unstripped response in memory for the caller; only the durable
   store is protected. Bounded by `ORCHESTRATOR_MAX_REPLY_BYTES` for the shipped client.

### 8.5 Final summary

| Finding | `d6b48c9` | `dc4acfd` | `83f8ae1` |
|---|---|---|---|
| F1 memory (transport) | Falsified (5×) | Fixed (33 MB RSS) | Fixed |
| F1 durable store | Falsified (3× reply) | Partial (observation/result copies) | **Fixed** (32 KB, marker absent) |
| F2 total wall deadline | Falsified (12 s → unbounded) | Not fixed (test non-faithful) | **Fixed** (2.2–3.2 s, real dribble test) |
| F3 bounded reasons | Falsified (20 MB payload) | Fixed (485 B) | Fixed |
| F4 mapping | Unmet (no `MODEL_OUTPUT_REJECTED`) | Fixed | Fixed |
| F5 transcript | Partial | Fixed (0600 + binding) | Fixed |

**Verdict: GO.** Reproduce with the §6 command list pointed at
`REVIEW_WORKTREE=/tmp/kilo/reply-review-83f8ae1`; the key probes are
`/s/slow_drip?drip=1.5` and `/s/drip_forever` at `ORCHESTRATOR_WALL_SECONDS=2`, `/s/huge?size=…`
for the store bound, and `rejected_reason_probe.py` for the in-process case.

