Files
narratio/docs/roadmap/audit/06-error-handling.md

201 lines
11 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Error-Handling Audit
Reviewed: 2026-11-30
Baseline: `7a9bbbde9f850debc87e17e6d305c755b6b53fd8`
## Scope And Evidence
This review examined failure detection, propagation, reporting, cancellation,
timeouts, and recovery across configuration acquisition, CLI outcomes,
preflight, pipeline execution, speaker/artifact checkpoints, subprocess and
HTTP adapters, local persistence, remote publication, restore, and cleanup.
The knowledge graph located implementations and call relationships. Direct
source inspection supplemented its incomplete indexing of same-named Go
receiver methods. Findings were checked against the architecture, CLI,
configuration, manifest, artifact, stage, storage, and operator documentation
and relevant existing failure tests.
Verification used Go 1.27.4:
- `go test ./...` passed; this run used cached package results.
- Fresh `go test -count=1` runs passed for `internal/app`, `internal/stage`,
`internal/preflight`, `internal/adapters/whisperx`,
`internal/adapters/subprocess`, `internal/adapters/storage`,
`internal/manifest`, `internal/fileops`, and `internal/artifacts`.
- `go vet ./...` passed.
- `go test -count=1 ./internal/doccheck` passed after writing this report.
- A temporary CLI binary reproduced EH-01 using maintained examples and two
small configuration fixtures outside the repository. These commands performed
planning and configuration validation; they invoked no providers or pipeline
stages.
No production code or tests were changed. This was an offline implementation
review, not live infrastructure, disk-failure, or kernel-stall fault injection.
Existing tests and successful checks establish the paths they exercise; they
do not prove that every exceptional condition is covered.
## Current Failure-Handling Architecture
- CommandKit owns CLI execution and reporting; ckconfig adapts native ConfigKit
diagnostics. Narratio adds domain-input classification and preserves mixed
operational failures through wrapped and joined errors.
- The application runner holds a session lock, persists stage transitions,
stops on failure, and attempts terminal manifest persistence with cancellation
detached from that final local save. Persistence and lock-release errors are
returned alongside the originating failure.
- Transcription joins bounded concurrent speaker workers. Transcription and
analysis checkpoint typed progress collections through the shared manifest
persistence helper. Failed checkpoint saves retain prior durable authority.
- Adapters own external transport and process failures. WhisperX uses
replayable streaming request bodies, per-attempt timeouts, selected retries,
and cancellable retry delays. The subprocess runner owns process-tree
termination, bounded output capture, credential redaction, and diagnostics.
- Stages validate run-local products before canonical promotion. Resume uses
manifest evidence and content identities; missing or changed evidence can
request regeneration without certifying incidental files as completed work.
- Publication selects a remote snapshot only after immutable transfers and
commit creation. Restore verifies selected objects, installs the manifest
last, and retains an incomplete-restore marker after installation failure.
Cleanup is a separate, explicitly enabled stage.
## EH-01 — P3: Domain configuration failures lose the CLI input classification
Status: Open
**Relevant code.**
- [Resolved validation](../../../internal/config/validate.go), `Validate`
(lines 41–45), returns product-destination and cross-document validation
failures without a typed input-error marker.
- [Cross-document validation](../../../internal/config/validate_core.go),
`validateCrossConfig` (lines 109–123), rejects incompatible storage/audio
selections using ordinary errors.
- [Product destination validation](../../../internal/config/product_destinations.go),
`validateProductDestinations` (lines 29–33), returns ordinary errors for
invalid placement or colliding configured destinations.
- [CLI classification](../../../internal/app/command_outcome.go),
`classifyOperationError` (lines 31–56), recognizes Narratio request errors,
artifact-catalog input errors, and native ConfigKit diagnostics. These
unmarked domain errors fall through to ckconfig's operational classification.
- [Execution entry point](../../../internal/app/execution_command.go),
`executeSelectedPipeline`, returns `config.Validate` failures unchanged.
Planning, preflight, status, restore, and lock commands also consume resolved
domain validation.
**Failure condition.** Individually loadable documents form an invalid resolved
configuration, or a completed configuration selects colliding product paths.
The failure is an identified configuration mistake, rather than a missing file,
network failure, cancellation, or ambiguous loading callback failure.
**Expected behavior.** The existing [CLI exit-status contract](../../cli.md#cancellation-and-exit-status)
assigns status `2` to identifiable invalid configuration input. These domain
rejections should retain that classification and their explanatory cause.
Unrelated operational, cleanup, and cancellation causes must retain precedence
when joined with them.
**Actual behavior and reproduction.** A CLI built from the baseline produced:
1. With the maintained minimal pipeline, sample campaign, and S3-audio session:
```sh
narratio session plan 2026-05-03 \
--config examples/pipeline.minimal.yml \
--campaign-file examples/campaigns/sample-campaign/campaign.yml \
--session-file examples/session.s3-audio.yml
```
It reported that `pipeline.storage.backend must be s3 when
session.inputs.audio_s3 is configured`, but exited with status `1`.
The same command using `examples/session.local-audio.yml` succeeded with
status `0`.
2. A temporary pipeline containing the required valid WhisperX URL and
`normalize.output_path: transcripts/base.json`, combined with the sample
campaign and local-audio session, was rejected because the base and final
transcripts share a destination. It also exited with status `1`.
3. As a control, a temporary pipeline with an invalid WhisperX URL was rejected
by native ConfigKit validation and exited with status `2`.
The error messages are useful and the commands stop before execution. The
defect is inconsistent failure classification, not acceptance of invalid
configuration or observed data corruption. Automation cannot consistently
distinguish configuration corrections from operational failures using the
documented statuses.
**Potential remediation.** Give positively identified domain-validation failures
a small typed configuration-input error that preserves its cause, and recognize
it at the existing CLI classification boundary. Apply it where these semantic
checks reject supplied values, following the existing artifact-catalog input
error pattern. Preserve the current wrapped/joined-error operational precedence.
Path-resolution or other environmental failures remain operational.
An alternative is to adapt these domain checks into native ConfigKit validation
diagnostics at a suitable completed-configuration boundary. That requires more
coordination because the checks span separately loaded documents; it should
preserve ConfigKit's configuration-resolution ownership. A narrow domain error
is the simpler local approach. Neither approach requires new validation rules or
reclassifying every error returned by configuration code as an input mistake.
**Verification when addressed.** Retain behavioral CLI checks for a cross-document
storage conflict and a destination collision returning status `2`, a valid
combination succeeding, and input errors joined with cancellation or operational
failures returning status `1` with both causes preserved. Existing native
configuration and artifact-catalog classification tests cover the neighboring
cases, not these two rejections.
## Related Findings Already Recorded
These failure-path issues remain relevant and retain their existing owners:
- [FC-02](01-correctness.md#fc-02--p2-carried-publication-bytes-conflict-with-restored-manifest-evidence):
restore can report success while installed carried products disagree with
restored completion evidence.
- [FC-03](01-correctness.md#fc-03--p2-session-planning-reports-reusable-s3-preparation-as-changed):
planning converts its missing S3 inspection collaborator into a definite
changed-input result rather than representing the inspection limitation.
- [CN-03](04-concurrency.md#cn-03--p2-the-exceptional-subprocess-reap-timeout-releases-ownership-too-early):
an exceptional reap timeout returns while process waiting and stream copying
may still own resources that callers subsequently close.
- [RS-02](05-resources.md#rs-02--p2-known-size-downloads-consume-the-full-response-before-rejecting-oversize):
some downloads detect an oversized object only after consuming the body.
- [RS-03](05-resources.md#rs-03--p3-publications-temporary-manifest-has-cleanup-gaps-before-ownership-transfer):
publication can orphan a temporary manifest on write, close, or
ownership-handoff failure.
These are cross-references, not additional findings from this pass.
## Deliberate Behavior And Review Outcome
The following choices were not treated as defects:
- Console-reporting methods intentionally leave delivery-error retention to
CommandKit so broken output does not interrupt checkpoint persistence.
Delivery failure can still fail the invocation after durable work completes.
- Secondary Audita report discovery is best-effort after a primary process or
output-validation failure. The primary error and diagnostic locations remain
available.
- Read-handle close errors and best-effort temporary cleanup are not uniformly
required to override an already useful failure. RS-03 concerns a specific
missing ownership cleanup, rather than every ignored cleanup error.
- Preparation explicitly treats changed or unavailable resume evidence as a
normal rerun. This audit does not introduce a general requirement that every
failed evidence check preserve prior success. FC-03 covers the distinct
planning/execution discrepancy.
- Optional source absence and explicitly non-current artifact evidence can be
represented as unavailable under their existing contracts. This does not
establish a general license to suppress unrelated transport or persistence
errors.
- Partial canonical promotion and restore do not promise rollback of every
completed write. Durable manifest authority, output verification, and the
restore recovery marker govern subsequent recovery.
- Abrupt process death, power-loss durability, automatic retry of every failure,
and atomic rollback across multiple products are outside the selected
guarantees.
One new P3 finding was confirmed. The reviewed ordinary failure, retry,
checkpoint, cancellation, and terminal-reporting paths otherwise preserve the
selected behavior, subject to the separately recorded findings above.