Files
narratio/docs/roadmap/audit/discussion.md

457 lines
20 KiB
Markdown
Raw Normal View History

# Audit Remediation Discussion
Status: Discussion in progress
## Purpose
Work through the seven topics raised in the catalog review before preparing a
remediation roadmap. Section numbers match that review and the operator's
responses. They are discussion topics, not implementation stages or catalog IDs.
The [catalog](catalog.md) remains the findings inventory. Its original audit links
own the detailed evidence. This document records decisions, explains consequences,
and distinguishes recommendations from approved scope. No remediation has been
implemented by this document.
The operator has settled the main direction for topics 1, 2, and 3. Checkpoint
upload timing in topic 2 and topics 4, 5, 6, and 7 need discussion. Each open
topic ends with a question and space for a response. Implementation details can
be settled during planning after the operator-facing behavior is clear.
## 1. Coordinate destructive cleanup with other work
Status: Simplified locking direction agreed; contention behavior proposed
Finding: [CAT-01](catalog.md#cat-01--p1-coordinate-whole-session-deletion-with-active-invocations).
### What goes wrong today
A run holds a lock inside its session directory. Manual whole-session cleanup
can delete that directory, including the lock's filename, while the run is still
active. Another run can create a replacement lock file and start working against
the same paths. The first process still owns its original lock, but it no longer
coordinates access to the replacement file.
The final pipeline cleanup stage is different: it already runs under invocation
locking and preserves the session root.
### Agreed direction
Concurrent sessions are not a goal or known use case. Use one workspace-wide lock
if that is the simplest design. Serializing work on different sessions is
acceptable. A shared/exclusive admission hierarchy and per-session concurrency
are unnecessary for this scope.
The coordination file must survive the directory deletions it protects. All
participating operations must use the same identity, including whole-workspace
session cleanup and creation of a new session's working state. This is local
process coordination for a workspace, not a distributed lock across machines.
### Remaining recommendation
Use cancellation-aware waiting, consistent with existing invocation locking,
and identify the lock being waited on. An immediate busy error is a viable
alternative if the operator prefers to retry manually. Waiting is a recommendation,
not an already approved behavior.
The roadmap should identify the mutating command participants explicitly. Pure
inspection and unrelated workspaces need no new serialization requirement.
Operator response:
_Optional: confirm waiting or prefer an immediate busy error._
## 2. Separate published artifacts from resumable execution checkpoints
Status: Separation agreed; checkpoint upload timing open
Finding: [CAT-02](catalog.md#cat-02--p2-make-restored-carried-products-agree-with-manifest-authority).
### The two purposes of remote storage
Remote storage serves two independent purposes:
1. Store completed artifacts for publication and later use. Publication locks
preserve selected published files.
2. Store execution checkpoints so a saved session can later be restored and
resumed, retaining its manifest, fingerprints, and applicable provenance.
The current session manifest is Narratio's local progress ledger. It records
completed work and evidence used to decide whether that work can be reused.
The remote publication commit separately identifies published files. The current
restore flow combines these records in a way that can mix different generations.
### Concrete example
1. Generate transcript A and publish it.
2. Lock the published transcript because A is the distributed, canonical copy.
3. Regenerate locally, producing transcript B. The local manifest describes B.
4. Publish again. The lock correctly keeps A in the remote publication.
5. Restore that publication into an empty workspace.
The audit reproduced this result:
| Item | Restored value |
| --- | --- |
| Transcript file | A |
| Manifest's recorded transcript checksum | Checksum of B |
| Manifest's completion evidence | Generation B |
| Restore command | Reports success |
| Subsequent normal transcript resolution | Rejects the checksum mismatch |
The lock correctly retained A. The failure comes from combining publication's A
with execution's manifest describing B.
### Agreed direction: published artifacts
Published artifacts are finished products available for consumption. They can be
imported as inputs to a subsequent session or a fresh run of the same session.
Publication import uses file identity and location to select the requested
product. Transfer-integrity checks, such as verifying downloaded bytes against
a checksum, are separate from generation history.
Generation fingerprints, historical inputs, prompts, models, settings, and
generation provenance are irrelevant to using these published products. Import
does not require reconstructing historical completion records or evaluating
whether the original producer would be reusable under today's configuration.
An imported artifact is a supplied input; it does not assert that its producer
executed in the receiving workspace.
Published products may come from different generations. This direction adds no
requirement for a publication-wide coherent pipeline generation.
### Agreed direction: resumable execution checkpoints
Checkpoint recovery restores a saved execution state for continuation. It
retains the manifest's progress, fingerprints, and provenance, together with the
corresponding files needed to resume. Restoring the manifest alone is insufficient
when its completed outputs are unavailable or belong to another generation.
Ordinary resume checks apply to the recovered execution state. Publication locks
govern published artifacts; they do not substitute older published files for
the outputs belonging to an execution checkpoint.
In the example above, publication import retrieves A as an input. A checkpoint
saved after generating B recovers the manifest describing B and the files needed
to resume that execution, including B. These are distinct recovery purposes.
### Consequences for remediation
Separate publication import from execution recovery rather than reconstructing
generation evidence for locked published products. The earlier proposal to
reconcile historical producer evidence for publication import is superseded by
this decision.
The two purposes can share a bucket and storage adapter. They need independent
logical records and selection rules. Physical layout, command syntax, and storage
formats remain implementation-planning matters.
Current remote-state loading, restore, status, and previous-session acquisition
depend on the uploaded session-manifest snapshot. The roadmap must examine those
consumers when separating the responsibilities. Previous-session artifact
selection already uses the publication inventory; it should consume published
products according to the import semantics above.
This decision preserves local execution checkpoints and normal resume behavior.
It does not approve automatic remote backup on each local checkpoint or select
a new checkpoint upload schedule.
### Open choice: checkpoint upload timing
The current publication-time manifest snapshot does not necessarily represent
the latest interrupted or failed local execution. "Most recent checkpoint"
must mean the most recent checkpoint saved under the chosen upload policy.
Possible policies for discussion:
- Explicit checkpoint upload: gives the operator control and avoids automatic
transfer overhead, but recovery reaches only the last explicitly saved state.
- Upload at invocation completion, including failed invocations: can preserve
partial progress automatically, but a process or host failure can occur before
that upload, and remote transfer failures need an explicit handling policy.
- Upload during execution at selected checkpoints: reduces potential lost work,
with additional transfer cost and checkpoint-publication lifecycle complexity.
No upload policy has been selected. Frequency, trigger, and transfer-failure
behavior remain open; the eventual roadmap should select them proportionately
to the recovery need.
### Question for discussion
When should Narratio upload resumable execution checkpoints, and what should
happen if that upload fails?
Operator response:
_Separation approved. Checkpoint upload timing and failure behavior pending
discussion._
## 3. Inspect S3 when planning and preflighting
Status: Read-only S3 checks agreed
Finding: [CAT-13](catalog.md#cat-13--p2-give-s3-session-planning-the-evidence-needed-for-truthful-reuse-decisions).
### What goes wrong today
Execution can compare current S3 audio identities with preparation's recorded
identities. The planning projection omits that storage collaborator and can
translate its absence into "inputs changed." It can therefore predict work that
execution would correctly reuse.
### Agreed direction
Planning should make a read-only S3 check. Preflight should make the relevant
read-only S3 check as well. Use existing storage capabilities and share the
identity interpretation with execution where practical.
The S3 identity check is read-only. This decision does not redefine the entire
preflight command as read-only. The current
[preflight workflow](../../operations.md#prompt-requirements-preflight) prepares
or reuses inputs, may download files and update the manifest, and checks downstream
providers. Preserve those responsibilities unless separately changed.
### Follow-through for the roadmap
Verify which S3 checks preflight already performs through preparation and reuse
that work rather than adding redundant calls. Observe unchanged, changed, and
unavailable sources through both commands. An access or connectivity failure
should be identified as such rather than reported as proven content change.
Use existing command failure/reporting conventions where they fit. The lookup
does not guarantee that S3 remains unchanged between planning and execution.
Operator response:
_Read-only S3 checks approved; no further product choice identified here._
## 4. Keep downloaded audio and its source identity together
Status: Open
Findings: [CAT-04](catalog.md#cat-04--p2-bind-prepared-s3-audio-bytes-to-their-observed-generation)
and [CAT-06](catalog.md#cat-06--p2-stop-known-size-downloads-before-oversized-bodies-exhaust-staging-space).
### Concrete example
Narratio lists a speaker recording in S3 and sees version A. Before the download,
an ordinary uploader replaces that key with version B of the same size. Narratio
downloads B but records A's listed source identity alongside B's checksum.
If S3 later contains A again, Narratio can conclude that its local copy is current:
the remote identity matches the recorded A identity, and the local bytes match
the recorded B checksum. Both checks pass individually, but they describe
different versions. Narratio can reuse the wrong recording.
Here "version" means an observed object generation/identity; this does not
require enabling S3 bucket versioning. The existing read operation already
provides metadata associated with the returned body. The audio download path
currently loses that association.
### Recommendation
Use the metadata returned with the actual download as the identity of the bytes
accepted. If B is a valid recording satisfying the acquisition rules, record B
and continue. This accommodates ordinary uploads without claiming that the
earlier directory listing froze all the session's audio.
If the observed response cannot satisfy the applicable checks, fail clearly.
There is no need for an automatic retry-until-stable loop or a session-wide
snapshot protocol.
### Viable alternative
Require the downloaded generation to match the earlier listing and stop on any
change. This is easy to explain and preserves the listing as the selected identity,
but an operator must retry preparation after an otherwise acceptable replacement.
### Related size-bound question
Restore and other downloads already reject content that differs from a known
expected size, but only after writing the complete response. Stop an oversized
response during transfer instead. This applies an existing acceptance condition
earlier; it introduces no universal maximum recording size.
For committed products, the committed size is authoritative. If audio adopts B
instead of A, the response identity and size boundary must both describe B.
The byte count remains checked rather than trusting response metadata alone.
Unknown-size input remains distinct from a known zero-byte declaration.
### Question for discussion
When audio changes between listing and downloading, should Narratio accept and
record the valid generation actually downloaded, or stop and ask for a retry?
I recommend accepting the observed generation. Do you also agree with stopping
known-size invalid transfers early?
Operator response:
_Pending discussion._
## 5. Finish subprocess shutdown before releasing its files
Status: Open
Finding: [CAT-05](catalog.md#cat-05--p2-retain-subprocess-and-stream-ownership-through-delayed-completion).
### What goes wrong today
When a downstream command times out or is cancelled, Narratio requests graceful
termination and then forceful termination. A separate waiter observes process
exit and completion of output copying.
On an exceptional path, the final wait timer expires before that waiter finishes.
Narratio can return an error and start closing log or result files while the
waiter or output copier still uses them. Issuing a kill request is not the same
as observing completion of every resource user.
The audit established this ordering from source. It did not reproduce a dynamic
race. Normal cancellation and subprocess tests passed.
### Recommendation
Keep the bounded graceful-to-forceful escalation, then join process/output
completion before releasing the associated resources or returning their ownership
to callers. Exercise the delayed-completion branch with a controlled test.
Ordinary cancellation should still terminate promptly. In an exceptional blocked
filesystem write or kernel operation, resource completion can take longer than
the escalation windows. There is no straightforward absolute return-time
guarantee for arbitrary blocked I/O.
### Viable alternative
Return before completion using an explicit ownership handoff. A remaining
supervisor would have to own every resource still in use, including output
destinations normally owned by the caller. This is more complex than starting a
background waiter and is justified only if returning promptly despite unfinished
I/O is an actual operational requirement.
### Question for discussion
Is it acceptable to wait for safe resource completion after forceful termination,
even when exceptional blocked I/O outlasts the escalation timers? I recommend yes,
with accurately scoped timeout documentation.
Operator response:
_Pending discussion._
## 6. Open publication sources as they are needed
Status: Open
Finding: [CAT-09](catalog.md#cat-09--p2-bound-publications-simultaneously-open-source-descriptors).
### What goes wrong today
Publication opens every selected local source before uploading and keeps all
those handles open until the stage ends. Each open file consumes an operating
system descriptor. A large inventory can exhaust that resource even though
uploads occur one at a time. Closing the handles at the end prevents an ordinary
leak but does not prevent excessive simultaneous use.
The audit established this scaling from source; it did not reproduce exhaustion
or establish a failure threshold for a production deployment.
### Why the current approach exists
Opening and validating sources up front catches invalid sources before uploading.
Retaining a verified handle also avoids substituting a later pathname lookup for
the file that was checked. Those are separate concerns from retaining every handle
throughout the entire attempt.
Remote publication becomes current only when the final pointer is updated.
An earlier failure may already leave immutable uploads that were never selected
as current. Preserving the old current pointer is the important existing commit
boundary; failure does not promise that no remote bytes were uploaded.
### Recommendation
Keep complete destination planning, then open, verify, upload, and close each
source using a bounded number of handles. Retain confinement and regular-file
checks and use the verified handle for the transfer. Accept that a later invalid
source may be discovered after earlier immutable uploads, while leaving the
previous current publication selected.
This relaxes the documented all-sources-rejected-before-upload behavior. Record
that relaxation expressly if approved. It adds no artifact-count cap and requires
no copies of every source solely to pin its original generation.
### Viable alternatives
- Run a bounded upfront validation pass, then reopen and revalidate sources for
transfer. This preserves early detection of initially invalid sources but adds
work; later changes can still fail during transfer.
- Make verified disk-backed snapshots before uploading. This can preserve stronger
source pinning with fewer descriptors, at the cost of disk space, I/O, and
temporary-file management. No known use case currently establishes that need.
### Question for discussion
May publication discover an invalid later source after earlier immutable uploads,
provided it leaves the previous publication current? I recommend yes and a simple
one-source-at-a-time transfer lifecycle.
Operator response:
_Pending discussion._
## 7. Give preparation and inspection the same audio selection rules
Status: Open
Finding: [CAT-12](catalog.md#cat-12--p2-share-audio-discovery-and-accept-valid-same-basename-recordings-in-inspection).
### Concrete example
The operator selects `first/speaker.flac` and `second/speaker.flac`. Preparation
accepts these distinct recordings and gives the prepared copies distinct names.
Inspection rejects them because their basenames match. A status command can
therefore report unavailable audio for a session preparation can process.
The duplicate implementations also differ on selecting the exact same file twice
and on file eligibility. Preparation's initial file check rejects directories;
inspection requires a regular file. A named pipe or device can pass the former
check but fail the latter. The audit does not establish successful end-to-end
support for those non-regular sources.
### Recommendation
Share read-only selection rules. Accept distinct local recordings with matching
basenames and retain preparation's rejection of duplicate resolved source paths.
Keep destination naming in preparation. Keep the separately selected S3 basename
rule distinct from local selection.
For the remaining eligibility choice, I recommend ordinary regular recording
files as the supported file-input surface. That fits repeated reading, hashing,
and resume. Requiring a regular file consistently would narrow preparation's
current initial check, so it needs approval. It does not by itself establish a
new blanket symlink prohibition; existing path/confinement rules remain separate.
### Viable alternative
Fix the demonstrated basename disagreement and share preparation's existing
selection behavior without tightening file eligibility. This minimizes behavior
changes. Unusual non-regular sources may then fail later during reading or
transcription rather than at discovery. The broader acceptance should not be
presented as evidence that streaming pipes and devices are supported end to end.
### Question for discussion
Should the shared discovery contract require regular recording files, or preserve
preparation's broader initial eligibility check? I recommend regular files, with
no additional filesystem restrictions bundled into that choice.
Operator response:
_Pending discussion._
## After Discussion
Record approved answers here, then prepare a remediation roadmap against the
catalog. The roadmap should distinguish agreed behavior changes from internal
refactoring, retain the audit evidence links, and include focused regression
coverage. This document does not authorize implementing unresolved recommendations
or replacing existing policies before those choices are settled.