Files
narratio/docs/roadmap/audit/01-correctness.md

179 lines
9.3 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.
# Functional Correctness Audit
Reviewed on 2026-11-30 against commit
`723b788161f59fd3b0a45eabd370385cc5640b4d`.
## Scope And Evidence
The review examined configuration acquisition and domain projections, canonical
stage execution, semantic resume and invalidation, speaker/artifact checkpoints,
artifact resolution, subprocess and HTTP boundaries, prepared previous-session
inputs, publication, restore, and cleanup. Findings use the current application
contracts in the architecture policy, operations guide, and focused internal
documents. They do not require compatibility shims or stronger transactional
guarantees.
The unmodified repository passed these checks with `GOTOOLCHAIN=go1.27.4`:
- `go test ./...`
- `go test -race -count=1 ./...`
- `go vet ./...`
- `go build ./...`
Four temporary offline diagnostics, supplied through Go's `-overlay` facility,
reproduced the three findings below. They exercised real internal collaborators
and existing filesystem fixtures, with the in-memory storage adapter at the
remote boundary. Their expected-behavior assertions failed as described below;
no production code or repository tests were changed. Live downstream tools,
paid providers, and a real S3 service were not exercised. This review does not
establish the absence of other defects.
## FC-01 — P2: Previous-session hydration omits analysis prerequisites
Status: Open
Relevant code:
- [Preparation](../../../internal/stage/prepare.go):
`collectPreparePreviousRequirements` (line 533) and its caller in `Run`.
- [Requirement collection](../../../internal/artifacts/previous_requirements.go):
`CollectPreviousArtifactRequirements`, particularly lines 32–36.
- [Analysis planning](../../../internal/stage/analyze_plan.go):
`planAnalyzeWork` and `AnalyzeTargetClosure`.
- [Restore planning](../../../internal/app/restore_plan.go):
`buildPreviousCacheRestoreActions` uses the same target-only collector.
**Trigger.** An enabled target `summary` depends on a disabled artifact
`history`, and `history` consumes
`narratio.previous_session.artifact.history`. The same issue occurs with an
explicit `--artifacts summary` selection that excludes its prerequisite from
the target set, even if that prerequisite is otherwise enabled. A previous
session and its published history can be available remotely.
**Expected.** The prerequisite participates in the documented analysis work
closure, so preparation makes its previous-session inputs available before
analysis executes. Required and optional inputs retain their configured
meaning. See [analysis behavior](../../internal/stage-analyze.md) and
[artifact selection](../../operations.md#artifact-development-workflows).
**Actual.** Preparation scans only `EffectiveArtifactSet` targets. Analysis
separately expands those targets to prerequisites. In the diagnostic,
analysis's closure was `[history summary]`, but preparation collected no
previous-session requirements. A required input consequently fails later with
prepare-rerun guidance; repeating the same preparation cannot supply it. An
optional input can instead be omitted despite an available remote artifact.
Restore's previous-cache planning has the same omission for disabled
prerequisites of enabled targets.
**Remediation approaches.** Collect previous-session requirements over the
existing shared analysis dependency closure. Use that requirement set
consistently for preparation, its semantic evidence, object-store composition,
and restore. Preserve explicit targets separately so this change does not
broaden force or publication selection. An alternative is to pass a separately
derived prerequisite-inclusive input-requirement set to these consumers;
avoid maintaining a second dependency algorithm.
**Verification to retain when fixed.** Exercise enabled-target/disabled-
prerequisite and explicit-target/prerequisite cases, including required and
optional previous inputs, followed by analysis and previous-cache restore.
## FC-02 — P2: Carried publication bytes conflict with restored manifest evidence
Status: Open
Relevant code:
- [Publication planning](../../../internal/stage/publish_output_plan.go):
`buildPublishOutputPlan` preserves an exact prior declaration for a locked
source.
- [Committed session manifest](../../../internal/stage/publish_commit.go):
`writeCommittedSessionManifest` (lines 103–134) copies current local output
evidence unchanged.
- [Restore planning](../../../internal/app/restore_plan.go):
`buildCommittedRestoreActions` (lines 172–193) maps the carried object to the
canonical product path.
- [Manifest installation](../../../internal/app/restore_manifest_paths.go):
`rebaseRestoredManifestPaths` changes paths and diagnostic references while
retaining output checksums and completion evidence.
**Trigger.** Publish transcript or artifact version A, lock its source, then
generate local version B and publish again. The new remote commit correctly
carries A's exact declaration while its session-manifest object records B's
local completion. Restore that committed snapshot into an empty workspace.
**Expected.** Restore preserves the locked publication and installs a ledger
whose output authority agrees with the available bytes. It must not claim
that A is the completed B result. The relevant contracts are
[committed publication](../../internal/stage-publish.md) and
[manifest-authoritative resolution](../../internal/manifest.md).
**Actual.** Restore installs A into the canonical product path and preserves
B's checksum and successful stage record. It can return success, but the
restored product then fails normal artifact resolution. The real publication
diagnostic confirmed the conflicting declaration and session-manifest
checksums. A second diagnostic passed that shape through the real restore
planner, installer, manifest loader, and resolver: restore succeeded, then
`narratio.transcript.final_trimmed` failed with `checksum mismatch`. A bounded
analysis run consuming that transcript cannot use the restored publication;
configured-artifact evidence similarly becomes non-current.
**Remediation approaches.** Reconcile restored authority with the selected
commit's actual product identities. Where carried bytes replace a different
local generation, preserve truthful provenance and reconcile affected stage,
per-artifact, and dependent completion state. Another approach is to
separate the generation-ledger snapshot from the restore/publication projection
and explicitly construct a coherent restored manifest. Simply replacing a
checksum while preserving B's fingerprint or dependent success would falsely
certify A as B. Preserve exact carried declarations and checksum validation.
**Verification to retain when fixed.** Publish A, lock, generate B, republish,
restore into a new workspace, and inspect both restored content and reuse
decisions. Include a built-in transcript and a configured analysis artifact.
## FC-03 — P2: Session planning reports reusable S3 preparation as changed
Status: Open
Relevant code:
- [Work projection](../../../internal/app/plan.go):
`projectSelectedWork` (lines 81–104) constructs a stage environment without
an object store.
- [Preparation resume](../../../internal/stage/prepare_resume.go):
`currentPrepareAudioSourceInputs` (lines 196–200) requires an S3 listing;
`ValidateResume` (lines 50–55) converts that failure to a changed-input result.
- [Runtime composition](../../../internal/app/runner_stage_execution.go):
`executeSelectedStage` composes preparation collaborators before checking
its resume evidence, unlike the planning path.
**Trigger.** A session uses `inputs.audio_s3`, preparation has succeeded, and
the prepared copies and remote key/size/ETag identities remain unchanged. Run
`session plan` over a range containing preparation.
**Expected.** The plan reflects verified resume evidence, or identifies evidence
it could not inspect. The documented shared planning semantics should not
describe unchanged inputs as changed solely because a planning collaborator
was omitted. See [planning](../../cli.md#session-plan).
**Actual.** The projection cannot list S3 audio without an object store. It
reports `prepare` as `run` with reason "prepared inputs or their current sources
changed; rerun prepare" and models dependent invalidation. Ordinary execution
supplies the store and can reuse the same preparation. The diagnostic prepared
S3 audio with the existing fake backend, verified `Resumable=true` with that
backend, then projected the identical configuration and manifest and observed
the erroneous `run` decision. This is misleading planning output, not a
durable invalidation or an observed execution rerun.
**Remediation approaches.** Obtain read-only audio identity evidence at the
planning boundary and provide it to the shared decision, keeping stage
execution and the projection's mutation-free behavior separate. A storage
reader or an acquired identity snapshot can supply that evidence. If planning
is deliberately kept free of this remote lookup, expose an unverified or
conditional decision and document that limit instead of reporting a definite
input change. Avoid treating unverifiable inputs as proven reusable.
**Verification to retain when fixed.** Compare plan and execution for unchanged
and changed S3 object identities, and distinguish an unavailable remote source
from an actual content change. Confirm that planning leaves the workspace and
manifest untouched.