Files
narratio/docs/roadmap/remediation.md

5.0 KiB
Raw Blame History

Durable Cleanup Integration Remediation

Review baseline: afd04e49d79afa775649e8f9dcc928b1db8cac05.

The integration review followed all seven stages of the implementation plan. One actionable issue remains. The existing single-invocation cleanup, canonical-product reuse, publication, restore, and managed-view behavior otherwise match the selected design.

1. Serialize Standalone Readiness Probes With Session Cleanup

Status: Pending.

Priority: P2.

Affected plan stages: Stage 3 (session-wide deletion), Stage 4 (writer lifecycle), and Stage 7 (operator/internal guidance).

Finding

inspectSessionValidation creates and uses Audita and Notarius probe destinations under runs/.validation without acquiring the session lock. The runner and restore hold that lock, but standalone session validate does not participate. Cleanup now deletes the complete runs/ tree, including the shared validation namespace. It can therefore delete the input and diagnostics of a validation command that is still executing.

Relevant locations:

  • internal/app/session_inspection_command.go:137: reads the prepared manifest and builds the Audita probe without session locking; the corresponding Notarius path begins at line 175, with probe execution at lines 209–215.
  • internal/stage/extract_preflight.go:40: creates the Notarius probe directories; lines 52–55 write its synthetic transcript beneath the selected probe root.
  • internal/adapters/notarius/preflight.go:85: runs pipeline inspection and then reopens its captured report; lines 108–110 repeat that pattern for the native readiness assessment. These are live run-local dependencies until checking completes.
  • internal/stage/cleanup.go:48: removes views and the session-wide runs tree while protected only from operations using the existing session lock.

The former published-run-only cleanup did not delete runs/.validation, so the new deletion scope exposes this previously independent writer. Automatic preflight is already inside the runner's session lock and is not the missing boundary.

Observed Behavior

Two temporary, channel-controlled tests used real session directories, the ordinary cleanup runner, and fake external readiness adapters:

  1. Pause standalone Notarius validation after its request and synthetic input have been prepared. Run authorized cleanup for the same session, then resume the probe. Cleanup succeeds, but validation fails opening runs/.validation/notarius/synthetic-transcript.json because it was deleted.
  2. Pause an Audita readiness fake before a final diagnostic write. Run successful cleanup, then release the writer. The write recreates runs/.validation after cleanup has completed.

These tests confirm the overlapping lifetimes, not a claim that every native probe always performs the second write. Native Notarius's report rereads also demonstrate why deleting these paths during a check can invalidate its result. Both diagnostic tests passed in reproduction mode and were removed after review; no production or maintained test code was changed by this audit.

Required Remediation

Use the existing context-aware session lock for standalone readiness work that reads prepared session evidence and creates or consumes session-local probe files. Acquire it before the relevant prepared-manifest read and probe construction, and retain it through native execution, report consumption, reference verification, and writer completion. Share the lock across that operation; avoid nested acquisition through already-locked runner paths.

Preserve validation's existing behavior when prepared inputs are unavailable: report the missing prerequisite without creating a new session workspace solely to acquire a lock. Honor cancellation while waiting and report release errors through existing command error handling. Validation still leaves processing and cleanup stage records unchanged.

A validation that starts its session-local work after cleanup releases the lock may create a fresh runs/ tree normally. The fix coordinates overlapping work; it does not prohibit later diagnostics or promise permanent directory absence.

Keep the agreed complete deletion target, including finished validation probes. No active-probe registry, retention exception, background cleanup scheduler, provider change, or standalone-preflight feature is needed. Update the focused validation/workspace guidance to explain serialization where relevant; keep read-only status and planning semantics unchanged.

Verification

Add a deterministic, offline regression using channels and fake readiness adapters at the external boundary. Verify that an active standalone probe and cleanup cannot overlap their session-local file lifetimes, and that cleanup subsequently removes the completed probe directory. Also cover cancellation while waiting for the lock and reuse the existing no-prepared-state and manifest-unchanged validation tests. Exercise both Audita and Notarius through their shared locking boundary without duplicating native subprocess tests.