# Audit Remediation Review ## Scope And Result Reviewed all 36 stages of [the implementation plan](implementation.md) against `c5d8697d9f645a7b3b9041769da02704bd495b7a`, including the changes since planning commit `cecd68f`, their tests, the accepted [feature roadmap](audit-remediation.md), and current canonical architecture/internal documentation. The review below records that snapshot; the remediation status records the subsequent correction. The targeted architecture is substantially in place. Core retains typed operation execution; a separate capture package serves operations and one-shot validators. The runner shares a whole-source index, separates working state from logical results, retains completed diagnostics independently of lane eligibility, and finalizes diagnostics once. Configuration, CLI, and resolution reuse pipeline-owned layout, target selection, and pure copying. Families own scene rules, duplicate eligibility/identity, and prepared ordering keys. The executable owns cooperative signals; embedded callers retain context ownership. The one required failure-cause retention gap is now resolved. No other required correctness, code-quality, architectural/documentation gap, or inadvertently strengthened requirement was substantiated in the inspected changes. The previously resolved standalone native-executor cancellation finding remains fixed; the issue below is at the enclosing runner's error-selection boundary. ## Finding 1 — Retain Drained Capture Failures Alongside Caller Cancellation **Status:** Resolved. The runner now joins caller cancellation with capture-bearing errors from drained jobs, preserving their scope and typed causes in canonical stage/lane/chunk order. Unrelated sibling errors remain suppressed, and ordinary uncanceled error selection is unchanged. **Priority:** P2, error integrity; requires concurrent cancellation and a capture failure, not an ordinary successful run. **Affected plan scope:** Stage 17's primary/capture/finalization cause retention, with Stage 21's cancellation path. The aggregation finalizer itself works; the loss occurs before that boundary receives the operation error. **Location:** [selectRunError](../../internal/framework/pipeline/runner_concurrent.go), lines 402–405 at the reviewed revision; also inspect the extraction outcome capture defer in the same file and the analogous continuation completion path. ### Behavior And Evidence After started work drains, `selectRunError` immediately returns `parent.Err()` when the caller context is canceled. This discards the recorded job errors, including a `contracts.CaptureError` joined by operation outcome recording. The runner's finalizer can preserve the error it receives, but cannot recover a cause already removed by selection. A temporary offline Go test overlay exercised the real `Runner.Run` boundary: 1. Prepare the existing small concurrent-pipeline fixture, use one worker, and supply a cancelable caller context plus an explicit evidence writer. 2. When the writer receives an extraction operation's `outcome.json`, cancel that caller context and return a distinct sentinel capture error. 3. Assert that the returned error retains `context.Canceled`, the capture sentinel, and the typed `contracts.CaptureError`. The writer reached the boundary once. The diagnostic failed with: ```text capture cause present=false, want=true: execute pipeline step "default": context canceled (capture writes=1) ``` The expanded diagnostic repeated this at extraction, merge, and normalization outcome recording. All three combined-failure cases failed; cancellation-only and capture-only controls passed for each stage (six passing controls). Cancellation remains observable, but `errors.Is(err, captureCause)` and `errors.As(err, &captureError)` fail in the combined cases. No timing-dependent sleep or provider call is needed. The diagnostic exists only in a temporary overlay, not a committed production or test change. The selection branch predates this work set; this is an incomplete end-state requirement, not a newly introduced regression. Existing tests cover capture failure and caller cancellation separately, and cancellation plus aggregation failure, but do not cover capture failure in a drained job alongside caller cancellation. This finding does not establish successful publication after cancellation, loss of available files, or that the standard CLI recorder forgets its own retained write error. The confirmed issue is loss from the runner's returned error chain, particularly relevant to explicit writer/direct framework consumers. ### Required Remediation - Preserve caller cancellation as the primary terminal classification, while retaining required capture-failure causes from drained operations. Joining the relevant typed capture failures with that primary error is sufficient. - Keep canonical operation-error selection and sibling-cancellation suppression for ordinary execution errors. Do not indiscriminately expose every sibling error, add a ledger/schema, change retry/fallback behavior, or introduce shutdown deadlines. Required capture failures are not just harmless sibling cancellation. - Add a focused permanent runner regression at the controlled writer boundary above. Assert cancellation and capture cause/type, no deliverable files or successful completion, and normal drain. Exercise extraction and continuation capture boundaries using a small table. Retain the existing core cancellation, aggregation-prefix, native-local timeout, and capture-error tests. **Acceptance:** `Runner.Run` preserves both cancellation and the supplied capture cause/type after started work drains, without acceptance/fallback or another model call. Ordinary cancellation still returns cancellation; uncanceled failures retain their established canonical selection. Available diagnostics and capture remain under the existing lifecycle. ### Implemented Remediation `selectRunError` retains drained job errors containing `contracts.CaptureError` when caller cancellation takes precedence. It returns the caller context error first in the joined chain, keeping every capture cause from those jobs without changing retry, fallback, finalization, or publication behavior. Permanent runner regressions cancel the caller and fail outcome capture at each of extraction, merge, and normalization. They verify cancellation, capture cause and type, one outcome write, no deliverables, and no fallback. Selection coverage also checks multiple capture failures, canonical ordering, and suppression of an unrelated ordinary sibling failure. Post-remediation checks passed: the focused cancellation/capture/finalization and error-selection tests (ten consecutive runs), `go test ./...`, `go vet ./...`, `go build ./cmd/notarius`, and the five-package race command below. ## Stage-By-Stage Review Coverage | Stages | Evidence inspected / result | | --- | --- | | 1–4 | Safe chunk/window arithmetic, exact rational negativity, structured producer keys, slice-view cycle tracking, and boundary regressions are present. | | 5–9 | Citation union traversal and all ten extraction index paths match the target; run/step sharing, standalone fallback, same-ID changed layouts, grounding, scene reuse, and cache checks have focused coverage. | | 10 | Worker tests use controlled overlap, bounded cancellation-safe handshakes, and joining; repeated focused checks pass. | | 11–13 | Native capture is a reusable framework owner; disabled projections are guarded; shared source and operation records reach the selected sink, including explicit writers and failure/cache paths. | | 14 | Group caps and collection truncation are removed; samples, grouping, checked counts, and selected diagnostic classification remain. Successor ADR scope is narrow. | | 15–19 | Private working state, completed diagnostics, one aggregation pass/prefix retention, last-consumer release, and runner phases are present. Finding 1 qualifies composed cancellation/capture error retention. | | 20–21 | Invocation-local CLI state and executable signal handling are present. Subprocess tests exercise first-signal drain and subsequent-signal termination. Finding 1 concerns the runner error chain, not signal registration. | | 22–26 | Pure copies preserve supported containers/absence distinctions; layout and inventory are reused by config, CLI, and complete resolution. Reference/type/capability/selection boundaries remain explicit. | | 27–31 | Scene facts have family ownership with codec differences preserved; grouping is shared across selected families, including spells, with item equality kept separate; prepared sort keys retain family ordering premises. | | 32–35 | Prose-based assertions and private run-ID regex are removed, useful prompt/session contracts remain, example tests are independent, concurrency/lifetimes are documented, and dead declarations/alias dispositions are recorded. | | 36 | Canonical docs and narrow ADR status updates reflect the changes. Broad checks pass, but the completion claim needs the composed failure-path correction in Finding 1. CAT-033 remains deliberately deferred. | ## Validation Passed on the reviewed state: ```sh go test ./... go vet ./... go build ./cmd/notarius go test -race ./internal/framework/pipeline ./internal/framework/capture ./internal/framework/semanticreconcile ./internal/modules/dnd/shared ./internal/modules/dnd/validate/scenedescriptions/combat_semantics go test ./internal/framework/pipeline -run 'Concurrent|Concurrency|ReverseCompletion|ReadyJobs|Cancellation|RetainsDiagnostic|Finalization' -count=10 go test ./internal/cli -run '^TestExecutableSignalsCancelAndDrainProviderWork$' -count=3 git diff --check ``` Go reused cached results where applicable; the repeated checks ran afresh. The additional cancellation/capture overlay failed as described. No API credentials, production inference, application fixes, or permanent test edits were used. Local link checks found no missing targets among 199 distinct paths referenced by the 15 changed canonical documentation files inspected.