Coordinate workspace cleanup with active operations
This commit is contained in:
@@ -52,7 +52,7 @@ Planner behavior:
|
||||
directories, symlinks, and other non-regular targets remain conflicts.
|
||||
|
||||
For a non-dry-run restore, planning/classification happens only after acquiring
|
||||
the session lock. Runner manifest/reuse checks acquire that same lock first.
|
||||
the workspace lock. Runner manifest/reuse checks acquire that same lock first.
|
||||
|
||||
Previous-cache readiness is resolved through `previouscache.Resolve` for restore,
|
||||
prepare, status, and validation. Each requirement selects the unique
|
||||
|
||||
@@ -27,14 +27,14 @@ canonical stage sequence through adapter interfaces, while manifests record
|
||||
progress and artifact services resolve durable inputs and outputs.
|
||||
|
||||
The pipeline runner follows one explicit invocation lifecycle: inspect bounded
|
||||
prerequisites without mutation, prepare the workspace layout, acquire one
|
||||
session lock, load or create the authoritative session manifest, complete or
|
||||
prerequisites without mutation, acquire the workspace lock, prepare the workspace
|
||||
layout, load or create the authoritative session manifest, complete or
|
||||
reuse selected preparation, check projected downstream work, compose only the
|
||||
collaborators needed by selected work, execute each selected stage in order, finalize terminal state, release resources, and return a possibly partial
|
||||
summary with preserved failure causes. Narrow terminal local persistence detaches
|
||||
cancellation; active work retains the canceled operation context. Cleanup, when
|
||||
selected, is the ordinary final stage rather than runner finalization work.
|
||||
The lock remains held from manifest initialization through finalization, and a
|
||||
The lock remains held from layout preparation through finalization, and a
|
||||
failed stage or required manifest save prevents later stages from starting.
|
||||
Standalone preflight shares that lifecycle, runs only preparation, and checks
|
||||
enabled capabilities while holding the same lock.
|
||||
@@ -44,7 +44,7 @@ enabled capabilities while holding the same lock.
|
||||
| Area | Implemented owners | Responsibility |
|
||||
| --- | --- | --- |
|
||||
| Executable | `cmd/narratio` | Process entry, standard stream wiring, argument handoff, and exit status. |
|
||||
| Application orchestration | `internal/app` | Native CommandKit declarations/reporting, lazy configuration selection, secret-file environment loading, production composition, session locking, planning, execution, restore, and user-facing reporting. |
|
||||
| Application orchestration | `internal/app` | Native CommandKit declarations/reporting, lazy configuration selection, secret-file environment loading, production composition, workspace locking, planning, execution, restore, and user-facing reporting. |
|
||||
| Configuration | [`internal/config`](configuration.md) | Typed ConfigKit results and lifecycle defaults, imports/overlays, canonical party loading, separate catalog/player/publication derivation, session templating, and validation. |
|
||||
| Pipeline stages | `internal/stage` | Canonical stage registry, shared stage contract, execution dependencies, and implemented stage behavior. |
|
||||
| Glossaries | `internal/glossary` | Native vocabulary resolution, schema validation, party projection, and deterministic documents. |
|
||||
|
||||
@@ -37,7 +37,7 @@ discovery, and discovery issues produce warnings. Findings survive independent
|
||||
failures and cancellation stops new work.
|
||||
|
||||
Probe files use invocation-scoped destinations under `runs/`, protected by the
|
||||
session lock through report consumption, reference verification, and terminal
|
||||
workspace lock through report consumption, reference verification, and terminal
|
||||
persistence. A later authorized cleanup can remove those files without removing
|
||||
durable prepared inputs. See [workspace internals](workspace.md),
|
||||
[CLI](../cli.md#preflight), and [operations](../operations.md#prompt-requirements-preflight).
|
||||
|
||||
@@ -46,11 +46,14 @@ session run-history cleanup, and are excluded from publish and restore enumerati
|
||||
|
||||
## Locking
|
||||
|
||||
`artifacts.LocalStore` enforces the single-writer session lock via an
|
||||
operating-system lock held on `.lock` (`ErrLockConflict` on contention). The
|
||||
`artifacts.LocalStore` enforces single-writer workspace access via an
|
||||
operating-system lock held on `<workspace.root>/.lock` (`ErrLockConflict` on contention). The
|
||||
file retains owner metadata after release or process death; its existence is
|
||||
not evidence that a lock is active. Command and restore flows wait for this
|
||||
lock only while their context remains active, and report a release failure.
|
||||
not evidence that a lock is active. Runs, preflight, mutating restore, and
|
||||
manual cleanup acquire it before creating or changing managed session state.
|
||||
Initialization targeting managed work also acquires it. They wait only while
|
||||
their context remains active and report a release failure. Read-only inspection
|
||||
and dry runs do not acquire it; separate workspaces remain independent.
|
||||
Standalone preflight holds the same lock through preparation, readiness probes,
|
||||
and finalization, keeping active probe files outside concurrent cleanup.
|
||||
Preparation uses ordinary manifest transitions and invalidation.
|
||||
|
||||
@@ -137,7 +137,7 @@ not rerun; otherwise it uses a synthetic input. These checks do not establish
|
||||
real-transcript feasibility, editorial quality, or future provider availability.
|
||||
See [Audita](integrations/audita.md) and [Scriptorium](integrations/scriptorium.md).
|
||||
|
||||
The session lock covers preparation, probes, and finalization. Probe diagnostics
|
||||
The workspace lock covers preparation, probes, and finalization. Probe diagnostics
|
||||
under `runs/` are disposable and can be removed by a later authorized cleanup;
|
||||
prepared inputs remain durable. Preflight itself does not run cleanup or rotate
|
||||
processing-stage diagnostic views. See [cleanup](#cleanup).
|
||||
@@ -737,6 +737,9 @@ the session workload.
|
||||
Use `narratio session clean SESSION` to remove an entire local session, or
|
||||
`narratio session clean --all` for all local sessions. Add `--dry-run` to inspect
|
||||
planned targets. These commands do not delete subprocess caches or remote data.
|
||||
Mutating cleanup waits for the same workspace lock used by runs, preflight, and
|
||||
restore. Waiting can be cancelled; dry-run inspection does not take the lock.
|
||||
The lock file remains at `<workspace.root>/.lock` after cleanup.
|
||||
|
||||
Automatic cleanup requires `workspace.cleanup_after_publish=true` and successful
|
||||
publication evidence. When selected, it removes the entire session `runs/` tree,
|
||||
|
||||
@@ -74,7 +74,7 @@ itself an architectural goal.
|
||||
## Ownership And Dependency Direction
|
||||
|
||||
The application boundary owns command composition, configuration selection,
|
||||
production composition, session locking, and top-level lifecycle. It may depend
|
||||
production composition, workspace locking, and top-level lifecycle. It may depend
|
||||
on concrete implementations to assemble a run.
|
||||
|
||||
Stage orchestration expresses intent in Narratio-level data and interfaces.
|
||||
@@ -131,7 +131,7 @@ not configurable.
|
||||
Downstream readiness is an invocation check after selected preparation and
|
||||
before the selected processing work. It does not create a stage success.
|
||||
Standalone preflight prepares or reuses session inputs and checks enabled
|
||||
capabilities under the same session lock; its checks may probe destinations and
|
||||
capabilities under the same workspace lock; its checks may probe destinations and
|
||||
contact configured providers.
|
||||
|
||||
A stage may explicitly self-skip with a stable reason and no outputs. That
|
||||
|
||||
@@ -131,6 +131,10 @@ Release/process exit permits later acquisition, and deleting a session or the
|
||||
|
||||
## Stage 3: Coordinate runners, restore, preflight, and manual cleanup
|
||||
|
||||
**Complete:** Mutating commands acquire the workspace lock before managed work;
|
||||
controlled command-level tests cover cleanup, cancellation, new admission, and
|
||||
managed initialization. Application, artifact, and documentation checks pass.
|
||||
|
||||
Read:
|
||||
|
||||
- `audit/08-testing.md`, lines 170–201 (TE-04).
|
||||
|
||||
@@ -795,21 +795,21 @@ narratio run 2026-04-04 --stage prepare --force
|
||||
|
||||
Relevant reference: [Operations: Restore Workflow](./operations.md#restore-workflow).
|
||||
|
||||
## Session lock conflict (`.lock`)
|
||||
## Workspace lock wait (`.lock`)
|
||||
|
||||
Symptom:
|
||||
|
||||
- command fails acquiring session lock.
|
||||
- a mutating command waits for the workspace lock or is cancelled while waiting.
|
||||
|
||||
Likely causes:
|
||||
|
||||
- another process is running for the same session;
|
||||
- another process is mutating the same workspace;
|
||||
- a process still holds the operating-system lock while it is shutting down.
|
||||
|
||||
Diagnostics:
|
||||
|
||||
```bash
|
||||
ls -l {workspace.root}/work/{campaign}/{session_id}/.lock
|
||||
ls -l {workspace.root}/.lock
|
||||
ps aux | grep narratio
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user