# Preventive-fix completeness review

This maps every row in PRODUCT §5 to the integrated PR. The follow-up adds no commands, tools, settings, dependencies or model-facing text. Existing safeguards are retained where already sufficient; additional regressions cover the gaps identified during this review.

| Planned preventive work | Implementation and executable evidence |
| --- | --- |
| Advancing request/cache sequences (#30/#32/#67/#68/#71/#79) | `goal-live-retention.ts` verifies complete history, bounds sessions/tails/bytes and resets obsolete policy. `goal-live-retention.test.ts` covers 1,000 requests, byte/count eviction, history edits, counter removal and tool boundaries. `prompt-cache-sdk-worker.ts` now exercises real Responses/Completions serialization beyond eviction, unchanged retries, policy edits and compaction, checking stable system/tools. `retention-check.mjs` now measures text, large tool outputs and image-bearing histories at 64 KiB, 1 MiB and 4 MiB. |
| Host capability/lifecycle matrix (#45/#47/#52/#66/#24/#78) | Capability-based rich/primitive routing in `goal-questionnaire.ts`; `goal-rpc-dialogs.test.ts` covers success, cancellation, missing/unavailable UI and synchronous/asynchronous failures. Deferred widgets use plain cwd/storage snapshots; `goal-widget-lifetime.test.ts` now invalidates old contexts, flushes queued work and replaces focused/unfocused widgets across different directories. Existing headless SDK tests and the packed-loader smoke cover registration/reload. |
| Separate spending/context/allowance concepts (#59/#74/#76) | Shared model formatters in `goal-accounting.ts`, policy limits in stable state and historical observations in counters. `goal-context-usage.test.ts` checks unknown telemetry and removed limits. Budget/confirmation tests cover omitted/null/positive values and stale/cancelled changes; `provider-crosscheck.mjs` verifies registered optional/nullable schemas and three strictness variants using real serialization. No accounting math or human total changes. |
| Preserve deliberate autonomy policy (#53/#55/#58/#63/#64) | Implicit continuation stays default, strict contracts remain opt-in. `goal-scheduler.test.ts` and the real SDK scheduler worker cover default continuation, strict-mode transitions, waits, takeover, deadlines, ownership and unchanged spent allowance. Existing status/limit guidance remains in use. No new stop heuristic or mandatory contract. |
| Tool-call/result protocol invariant (#48/#79) | Full reset at any unsafe replay anchor prevents duplicate policy and keeps batches contiguous. Unit tests cover delayed result vocabularies and parallel results; real serializers now receive delayed/error results with intervening display-only audit messages filtered out. Existing marker tests preserve foreign content-bearing suffixes/marker ownership and TTL; session-safety e2e tests cover delegated/audit paths. |
| Multiple sessions/worktrees against one pool (#49/#73) | One resolved root routes locks, state, ledger, archives and snapshots; focus is pool-scoped and scheduler admission remains authoritative. `goal-storage-root.test.ts` now exercises two independent cores in different worktrees: the second stale writer is rejected, refresh sees the winner, a fresh write succeeds, and a missing pinned pool fails without recreation. Existing same-process/child-process contention and cross-pool focus tests remain. `goal-scheduler.test.ts` adds model/provider changes, unidentified-session clearing and shutdown reset to existing interleaved-session/ownership scenarios. |
| Historical auditor incidents (#70) | Auditor instructions prohibit runtime metadata cleanup and distinguish environment failures; completion supplies at most 600 characters of the relevant previous rejection. The completion tool regression verifies prior findings reach the auditor with the bound. The auditor remains evidence-based and does not gain a single-task or fixed-rejection-count gate. These prompt constraints are guidance, not a claim of a filesystem sandbox. |
| Declared host/Node support (#77) | CI checks each supported Pi minor (0.83–0.87), including real Node 22.15 with the compatible host. The primary job runs full tests, context/provider checks, retention costs and same-runner base/candidate benchmarks. |
| Respect platform maintenance boundary (#60/#61) | No Windows test-suite port or OS matrix expansion. Runtime path normalization and existing confinement remain covered in the scoped storage tests. |

## Defects found by this review

1. A delayed result could invalidate a later counter anchor while leaving an earlier policy tail valid. Truncating only the unsafe suffix and then appending the fresh pair duplicated the policy. Reset the complete live replay instead. The new regression fails before the fix and passes after it.
2. Removing optional counters with unchanged policy could replay their old observations indefinitely. Reset on counter removal. The new regression fails before the fix and passes after it.

Both changes reduce obsolete/duplicate request text. They add no extra I/O, no retained state and no steady-state prompt content. Prefix reuse is intentionally reset when protocol or policy correctness requires it.

## Boundaries

All accepted preventive implementation is in the PR. Publishing, live provider cost/hit-rate experiments, the upstream Responses normalization change, and visible-TUI release smoke remain separate activities as the original plan specified. The optional broad diagnostic snapshot was not turned into a framework: existing status/provenance, health reports, scheduler diagnostics and deterministic cache regressions supply the relevant evidence without a new command or hot-path instrumentation.
