41 KiB
ADR-0005 Staged Implementation Plan
This document is the executable implementation plan for the target state in ADR-0005 Feature Roadmap, governed by ADR-0005. The feature is not implemented.
The audience is an LLM coding agent. Implement the stages in order. Each stage is deliberately scoped to finish with a compiling, tested repository and may be assigned as one implementation prompt.
Execution Rules
Before every stage:
- read Development, both documents under
docs/policy/, ADR-0005, this plan, and every stage-specific document named below; - inspect
git statusand preserve user changes; - inspect the focused package contracts and tests before editing; and
- confirm that all earlier stages are complete.
During every stage:
- implement only that stage and prerequisites discovered to be inseparable;
- use existing package boundaries and helpers before introducing abstractions;
- keep framework and core packages independent of concrete D&D modules;
- preserve cancellation, deterministic ordering, redaction, path confinement, and atomic-write invariants;
- add or update focused tests with every behavior change;
- do not update current-behavior documentation before the final documentation stage, except for ADR acceptance in Stage 1; and
- do not begin the next stage after meeting the current exit criteria.
At the end of every stage:
- run the focused tests listed for that stage;
- run
go test ./...; - run
go vet ./...; - run
go build ./cmd/notarius; - run
git diff --check; and - mark the stage complete in this document only after all checks pass.
If repository reality conflicts with this plan, stop and update the plan in the same change before implementing a materially different design. Do not silently invent a new contract.
Fixed Decisions
These choices are settled for this implementation:
source.SourceDocument.Digestis the cache lookup identity.- The chunk-plan root is independent of
workspace.directoryand every other state root. - Its default joins the directory returned by
os.UserCacheDirwithnotarius/chunk-plans. workspace.chunk_cache.directoryoverrides that default and names the chunk-plan root itself. The recommended value for a system-wide Linux service is/var/cache/notarius/chunk-plans.- The plan file is
<chunk-plan-root>/<64-character-lowercase-source-sha256-hex>/plan.json. The validatedsha256:prefix remains part of the logical digest but is removed from the path segment. - The plan envelope schema is
notarius.chunk-plan.v1. - There is one mutable plan file per source, atomically replaced. There are no immutable plan objects, pointers, history, locks, or rollback.
- Concurrent writers use last-successful-atomic-write semantics; they must never expose a partial file.
- Chunk modules retain the
contracts.Chunkername but replaceChunkwith aPlanoperation. No legacy interface remains after Stage 2. - Plans and ranges use
map[string]json.RawMessageannotations. Annotation values are canonical valid JSON and namespaces are non-empty trimmed strings. - Materialized chunks expose range annotations through
source.Chunk.Annotationsand plan annotations throughsource.Chunk.PlanAnnotations, never throughMetadata. - Framework materialization owns chunk IDs, indexes, references, content, media type, units, and generic metadata.
- Only the generic
chunkscapability is hard;chunks.scenesis removed. - Cached-plan hits still construct the configured chunker during preparation but never call its operation or the chunk-stage LLM.
- The current pipeline's configured chunk validators run against materialized chunks on every path.
- Canonical plan storage is the only chunk-reuse mechanism; chunk checkpoint APIs and payloads are removed.
- The mode values are
auto,bypass, andrefresh. They are valid in config, environment, and CLI, including persistentrefreshconfiguration. - The YAML field is
workspace.chunk_cache.mode. - The YAML directory field is
workspace.chunk_cache.directory. - The environment variable is
NOTARIUS_WORKSPACE_CHUNK_CACHE_MODE. - The root environment variable is
NOTARIUS_WORKSPACE_CHUNK_CACHE_DIR. - The CLI flag is
--chunk_cache <auto|bypass|refresh>. - Precedence is CLI, environment, file, then default
auto. - Chunk-plan-root precedence is environment, file, then the per-user default; there is no CLI root override.
- Every supplied file, environment, and CLI value is parsed strictly even when a higher-precedence source would override it; precedence selects among valid values and does not mask malformed configuration.
- Existing chunk checkpoint files are ignored and never migrated.
- A structurally invalid stored plan is an
automiss. A configured-validator rejection of a structurally valid hit does not trigger regeneration.
Planned Contracts
Use these names unless an existing collision requires the smallest obvious adjustment.
Source-zone types
Add to internal/core/source:
type ChunkAnnotations map[string]json.RawMessage
type ChunkPlan struct {
SourceDigest string `json:"source_digest"`
Ranges []ChunkRange `json:"ranges"`
Annotations ChunkAnnotations `json:"annotations,omitempty"`
}
type ChunkRange struct {
StartUnitID int `json:"start_unit_id"`
EndUnitID int `json:"end_unit_id"`
Annotations ChunkAnnotations `json:"annotations,omitempty"`
}
Add Annotations ChunkAnnotations and
PlanAnnotations ChunkAnnotations to source.Chunk, with JSON names
annotations and plan_annotations and omitempty on both.
The plan digest covers SourceDigest, ordered ranges, and canonical annotation
bytes. It excludes producer provenance, warnings, timestamps, and storage
schema. Materialization produces:
- IDs
chunk-%06d, numbered from one; - zero-based indexes in plan order;
- references spanning the first and last units in each range;
- cloned contiguous source units;
- media type
application/json; - canonical JSON content shaped as
{"units":[...]}; - generic metadata containing
start_unit_id,end_unit_id, andunit_count; - cloned range annotations in
Chunk.Annotations; and - cloned plan annotations in
Chunk.PlanAnnotations.
The plan and range scopes remain distinct even when both use the same namespace. Copying plan annotations into each runtime chunk is intentional: it makes them available to downstream chunk-scoped operations without duplicating source content in durable storage.
Framework validation permits gaps and overlap between ranges, but requires strictly increasing start positions and rejects duplicate or backward ranges. Producing modules may impose stricter policy before returning a plan.
Module contract
Replace the current chunk result and operation with:
type ChunkPlanResult struct {
Plan source.ChunkPlan
Warnings []Warning
}
type Chunker interface {
Key() string
ReferenceSlots() []ReferenceSlot
Plan(context.Context, ChunkRequest) (ChunkPlanResult, error)
}
Keep ChunkRequest, chunk module keys, stage name chunk, configuration
bindings, registries, and preparation ownership unchanged.
Durable plan record
Define framework-facing record and store contracts beside other pipeline collaborator contracts:
type ChunkPlanProducer struct {
InputModule string
ChunkModule string
LLMProfile string
References []artifacts.ReferenceProvenance
Metadata map[string]any
}
type ChunkPlanRecord struct {
SchemaVersion string
SourceDigest string
PlanDigest string
Plan source.ChunkPlan
Producer ChunkPlanProducer
Warnings []contracts.Warning
CreatedAt time.Time
}
type ChunkPlanStore interface {
Load(sourceDigest string) (ChunkPlanRecord, ChunkPlanDecision, error)
Save(ChunkPlanRecord) error
}
type ChunkPlanStoreFactory func(root string) (ChunkPlanStore, error)
type ChunkPlanDecision struct {
Status ChunkPlanStatus
Reason string
}
type ChunkPlanStatus string
const (
ChunkPlanHit ChunkPlanStatus = "hit"
ChunkPlanMissing ChunkPlanStatus = "missing"
ChunkPlanInvalid ChunkPlanStatus = "invalid"
)
ChunkPlanDecision reports hit, missing, or invalid plus a redacted
reason. A miss or invalid result returns a zero record and nil error. Missing
and structurally invalid records are recoverable in auto. Filesystem access
failures other than absence return an error and are framework failures.
The concrete constructor is:
// Package chunkplan
func NewFilesystemStore(root string) (pipeline.ChunkPlanStore, error)
It treats root as the exact chunk-plan root. CLI composition injects this
constructor through cli.Options.ChunkPlanStoreFactory; tests may inject a
recording factory. cli.Options.UserCacheDir has signature
func() (string, error) and defaults to os.UserCacheDir.
The JSON envelope uses snake-case equivalents of the record fields. It stores references as provenance only, never reference content. Before returning a hit, the loader validates schema version, source digest, plan digest, plan structure, annotation JSON, and materializability against the current source in the runner.
Cache policy and provenance
Add a ChunkCacheMode enum with auto, bypass, and refresh, plus strict
parsing and validation.
Add to RunInput:
ChunkCacheMode ChunkCacheMode
ChunkPlans ChunkPlanStore
An empty mode used by direct framework callers means bypass; the production
CLI always supplies the effective non-empty mode.
Add a run-manifest summary:
type ChunkPlanManifest struct {
Mode string `json:"mode"`
Action string `json:"action,omitempty"`
SourceDigest string `json:"source_digest,omitempty"`
PlanDigest string `json:"plan_digest,omitempty"`
PlanSchemaVersion string `json:"plan_schema_version,omitempty"`
RequestedModule string `json:"requested_module"`
ProducerInputModule string `json:"producer_input_module,omitempty"`
ProducerModule string `json:"producer_module,omitempty"`
ProducerLLMProfile string `json:"producer_llm_profile,omitempty"`
ProducerReferences []ReferenceProvenance `json:"producer_references,omitempty"`
ProducerMetadata map[string]any `json:"producer_metadata,omitempty"`
CreatedAt *time.Time `json:"created_at,omitempty"`
}
Action is one of reused, generated, refreshed, or bypassed. Retain
the existing top-level input_module and chunker fields as the requested
pipeline modules. Add this field to artifacts.RunManifest:
ChunkPlan *ChunkPlanManifest `json:"chunk_plan,omitempty"`
The runner initializes it with the effective mode and requested chunk module, then fills candidate and producer fields when a plan reaches materialization.
Stage 1: Finalize ADR and add the source-zone plan model
Status: Complete
Objective
Accept the architectural decision and introduce domain-neutral plan, annotation, validation, digest, clone, and materialization primitives without changing chunk-module execution yet.
Read first
internal/core/source/source.gointernal/core/source/digest.gointernal/core/source/validation.gointernal/core/source/source_test.go- every current
source.Chunkclone or serialization helper found withrg
Implement
- Revise ADR-0005 before acceptance:
- confirm it retains one source-addressed mutable plan and atomic refresh;
- preserve the independent cache-surface decision;
- keep filesystem and CLI details out of the ADR; and
- change status from
ProposedtoAccepted.
- Add
ChunkAnnotations,ChunkPlan, andChunkRangeininternal/core/source. - Add canonical annotation validation and cloning. Canonicalize each raw JSON
value by decoding with
json.Decoder.UseNumberand re-encoding; reject blank namespaces, invalid JSON, trailing JSON values, and non-finite or unsupported values. - Add plan validation against a
SourceDocumentusing the rules in Planned Contracts. - Add
DigestChunkPlanand deterministicMaterializeChunkPlan. - Add
AnnotationsandPlanAnnotationstosource.Chunk,DigestChunk, every clone helper, debug envelope, and serialized chunk-validation representation. Ensure all ownership boundaries clone raw bytes and retain the two scopes separately. - Do not change the chunker interface or runner flow in this stage.
Tests
Add focused tests for:
- annotation canonicalization, invalid JSON, blank namespaces, and mutation safety;
- plan source mismatch, missing ranges, missing units, backward ranges, duplicate starts, gaps, and overlap;
- stable plan digests and digest changes for boundary or annotation changes;
- exact materialized IDs, references, content bytes, metadata, annotations, gaps, and overlap;
- repeated byte-identical materialization; and
- plan- and range-annotation preservation through existing chunk clones, debug conversion, serialized validation, and downstream extract requests.
Run at minimum:
go test ./internal/core/source
go test ./internal/framework/contracts ./internal/framework/pipeline
Exit criteria
The repository is green; ADR-0005 is accepted; plan primitives are complete and tested; current modules and the runner still behave as before.
Stage 2: Replace the chunk operation with plan generation
Status: Complete
Objective
Make all chunk modules produce plans and make the runner materialize those plans without adding durable reuse yet.
Read first
docs/internal/modules.mddocs/internal/pipeline.mdinternal/framework/contracts/contracts.gointernal/framework/pipeline/chunker_registry.gointernal/framework/pipeline/runner.gointernal/framework/pipeline/chunk_validation.go- both production chunk-module packages and all chunk fakes in tests
Implement
- Replace
ChunkResultwithChunkPlanResultandChunker.ChunkwithChunker.Plan; keep the request, registry, module keys, and stage name. - Update all fakes, registry tests, preparation tests, integration helpers, and compile-time interface assertions in the same stage. Do not retain adapters or a legacy chunk-returning interface.
- Convert
generic/chunk/unitsto emit ranges only. Preservemax_unitsandoverlap_unitssemantics. - Convert
dnd/chunk/scenesto emit namespacednd/scenesat both scopes:- each range value is an object with exact keys
short_title,primary_mode,main_participants,summary,boundary_note, andboundary_confidence, preserving the current normalized scene values; and - the plan value is an object with exact key
boundary_caveats, containing the normalized caveat array.
- each range value is an object with exact keys
- Preserve accepted scene boundary caveats as
contracts.Warningvalues as well as in the plan annotation so warning behavior remains visible. - Remove
chunks.scenesfrom the D&D scene module's provided capabilities. Keep onlychunks. - Change the runner’s non-cached chunk path to:
- call
Planunder the existing retry and debug attempt boundary; - validate the plan structurally;
- materialize chunks;
- run the configured chunk-validator chain on materialized chunks;
- preserve retry and rejection semantics; and
- pass materialized chunks to lanes exactly as before.
- call
- Update chunk debug payloads to distinguish the generated plan from materialized chunks. Plan annotations may appear only in opt-in debug data.
- Leave current chunk checkpoint loading and recording temporarily in place, storing materialized chunks, so existing resume tests remain green until Stage 4 removes that path.
Tests
Update focused module and framework tests to cover:
- exact generic ranges and overlap;
- exact D&D scene annotations and warning conversion;
- annotations absent from generic plans;
- framework materialization rather than module materialization;
- chunk validators receiving materialized annotated chunks;
- retries around generation plus validation;
- stable chunk IDs independent of producing module; and
- no
chunks.scenesresolution dependency.
Run at minimum:
go test ./internal/modules/generic/chunk/units
go test ./internal/modules/dnd/chunk/scenes
go test ./internal/framework/contracts ./internal/framework/pipeline
go test ./internal/modules/integration ./internal/cli
Exit criteria
Every chunk module uses the single plan contract, the runner always materializes, production behavior remains functionally equivalent apart from framework-owned stable chunk IDs and namespaced annotations, and the repository is green.
Stage 3: Add dedicated cache configuration and the plan store
Status: Complete
Objective
Implement the durable source-addressed store and its independent cache-root configuration without changing the runner to consume the store.
Read first
docs/config.mddocs/operations.mdinternal/core/config/*internal/core/workspace/*internal/framework/checkpoint/as the local pattern for a workspace-backed implementationinternal/cli/run.goconfiguration loading, without wiring the store yet
Implement
-
Add
ChunkCacheModeand strict parsing in the pipeline package. -
Add
WorkspaceChunkCacheConfigwithModeandDirectoryto config and file config. The YAML fields areworkspace.chunk_cache.modeandworkspace.chunk_cache.directory. -
Set default mode to
auto; supportNOTARIUS_WORKSPACE_CHUNK_CACHE_MODE; preserve precedence file then environment. CLI precedence arrives in Stage 5. -
Support
NOTARIUS_WORKSPACE_CHUNK_CACHE_DIRwith environment-over-file precedence. Trim the value; an unset or empty effective value selects the per-user default. Do not add a CLI directory override. -
Add
workspace.DefaultChunkPlanRoot, accepting an injectable user-cache-directory resolver and returningfilepath.Join(userCacheDir, "notarius", "chunk-plans"). Production later suppliesos.UserCacheDir; tests supply a stub. Reject resolver errors and empty returned directories. Use this exact signature:func DefaultChunkPlanRoot(userCacheDir func() (string, error)) (string, error) -
Treat a non-empty
workspace.chunk_cache.directoryas the plan root itself, cleaned with the same path rules as other workspace roots. It does not gain an implicitchunk-planssuffix.workspace.directorymust not affect this root, and the chunk-cache directory must not affect checkpoint, diagnostics, debug, or output roots. Do not changeworkspace.FromConfigorworkspace.Settingsfor this feature. -
Add the plan record, producer, decision, and store interfaces described above in the pipeline package.
-
Add
internal/framework/chunkplanwith:- a filesystem implementation;
- a constructor that accepts the already resolved chunk-plan root;
- path
<chunk-plan-root>/<64-character-source-sha256-hex>/plan.json, after strictly validating and stripping the logicalsha256:prefix; - schema
notarius.chunk-plan.v1; - directories mode
0700and file mode0600; - atomic same-directory temp-file rename;
- strict envelope decoding and unknown-field rejection;
- complete digest and annotation validation; and
- no raw reference content.
-
Loaddistinguishes missing, invalid, and operational error.Savealways atomically replaces and implements last-successful-write semantics. -
Keep store fakes local to their tests; do not add a production in-memory or no-op store because
bypassand a nil collaborator already express disabled persistence. -
Do not wire the store into
Runneror CLI execution in this stage.
Tests
Cover:
- config defaults, YAML decoding, environment override, invalid values, cloning, redaction, and validation;
- directory environment-over-file precedence, empty-value fallback, cloning, redaction, cleaning, and validation;
- exact injected per-user default and resolver failure or empty-result errors;
- independence in both directions between
workspace.directoryandworkspace.chunk_cache.directory; - exact acceptance of
/var/cache/notarius/chunk-plansas a configured root without writing to that real path; - safe full-digest paths and rejection of malformed digests;
0700/0600permissions where supported;- envelope round trip, strict decoding, source and plan digest mismatch, invalid annotations, schema mismatch, missing files, operational read errors, atomic replacement, and concurrent writers; and
- absence of raw reference content in persisted JSON.
Run at minimum:
go test ./internal/core/config ./internal/core/workspace
go test ./internal/framework/chunkplan ./internal/framework/pipeline
go test ./internal/cli
Exit criteria
Configuration and storage are complete and independently tested, but normal runs still use Stage 2’s generate-and-materialize behavior.
Stage 4: Integrate cache policy and remove chunk checkpoints
Status: Complete
Objective
Make the runner’s chunk path use the canonical plan store under all three modes and establish it as the only chunk-reuse mechanism.
Read first
internal/framework/pipeline/runner.gointernal/framework/pipeline/checkpoint.gointernal/framework/pipeline/runner_concurrent.gointernal/framework/checkpoint/loader.gointernal/framework/checkpoint/recorder.go- focused runner retry, rejection, debug, and checkpoint tests
Implement
- Add
ChunkCacheModeandChunkPlanstoRunInput. Empty mode meansbypassfor direct framework callers. - Add synchronized store wrapping only if runner access can be concurrent; otherwise document and test the intentionally serial chunk-plan access.
- Implement mode behavior:
autohit: load, structurally validate against the current source, materialize, then run configured chunk validators once;automiss or invalid: generate through existing retries, validate, materialize, validate chunks, then save;bypass: generate and validate normally without callingLoadorSave;refresh: generate and validate normally, then replace throughSave.
- A valid-hit validator rejection is recorded without retry, store mutation, or implicit regeneration. A store I/O error is a framework error.
- A failed or rejected generated plan is never saved. An invalid old file is overwritten only after a replacement passes module execution, structural validation, materialization, and configured validators.
- Build producer provenance from the prepared input module key, prepared chunk module key, resolved chunk-stage LLM profile, chunk-target auxiliary reference provenance, and chunk-module manifest metadata. Clone and redact according to existing boundaries.
- Replay stored producer warnings on a hit, then append current validation warnings. Do not duplicate warnings from discarded generation attempts.
- Remove all chunk methods and types from
CheckpointRecorder,CheckpointLoader, synchronized wrappers, workspace recorder/loader, and checkpoint manifests and envelopes. - Remove runner chunk-checkpoint decisions and events. Retain source, extract, merge, and normalize checkpoints. Keep downstream fingerprints based on the digest of materialized chunks.
- Ignore existing on-disk
chunk/checkpoint files; do not read, delete, or migrate them. - Update debug behavior:
- hit records lookup and materialization but no chunk module attempt or LLM call;
- generated, bypassed, and refreshed paths retain attempt debug; and
- default debug envelopes remain redacted.
Tests
Add table-driven runner tests for every mode and outcome:
- hit, missing, invalid, and I/O error;
- generation success, error, rejection, retry, and cancellation;
- validator warning, rejection, and error on hits and generated plans;
- bypass performs zero store calls;
- refresh performs no load and exactly one successful save;
- invalid record remains untouched when replacement fails;
- stored warnings replay once;
- no module or LLM call on hit;
- downstream chunk digest changes on refresh;
- legacy chunk checkpoint files are ignored; and
- source and lane checkpoint behavior remains intact.
Run at minimum:
go test ./internal/framework/pipeline
go test ./internal/framework/checkpoint
go test ./internal/modules/integration
Exit criteria
The runner implements complete cache semantics, chunk checkpoints no longer exist as a code path, all direct framework tests are green, and production CLI runs are not yet wired to persistent plan storage.
Stage 5: Wire persistent policy into the CLI
Status: Complete
Objective
Make normal CLI runs resolve the effective mode and dedicated chunk-plan root, construct the durable plan store when appropriate, and pass it into the runner.
Read first
docs/cli.mddocs/config.mdcmd/notarius/main.goandinternal/cli/run.go- CLI flag, environment, invocation-metadata, and exit-code tests
- the workspace and configuration code changed in Stage 3
Implement
- Add the exact flag
--chunk_cache <auto|bypass|refresh>. Represent an omitted CLI value separately from an explicit value so precedence is not inferred from the default printed by the flag package. - Resolve the effective mode in this order: explicit CLI flag, environment,
configuration file, default
auto. An invalid CLI flag is a usage error with exit code 2; invalid file or environment configuration follows the existing configuration-load failure path and exit code 1. - Include an explicitly requested CLI value in invocation metadata and the
resolved mode in effective-configuration metadata without adding field-level
origin tracking or plan and annotation payloads. Name the optional
invocation JSON field
chunk_cache_override; the resolved mode already appears atworkspace.chunk_cache.modein the redacted effective config. - Add
UserCacheDir func() (string, error)andChunkPlanStoreFactory pipeline.ChunkPlanStoreFactorytocli.Options, defaulting them toos.UserCacheDirandchunkplan.NewFilesystemStore. Forautoandrefresh, choose the non-empty effectiveworkspace.chunk_cache.directory; otherwise resolve the per-user default withworkspace.DefaultChunkPlanRoot. Invoke the store factory with that exact root and pass the result and effective mode throughRunInput. Never appendchunk-plansto an explicit directory. The injectable factory lets CLI tests assert root selection without writing to production paths. - For
bypass, do not resolve, inspect, or create the chunk-plan root and pass no store. Existing general-workspace setup remains unchanged and independent:workspace.directory, resume, diagnostics, and debug continue to use their current paths and semantics. - Keep resume policy independent of plan reuse. Enabling, disabling, or selecting a resume run must not change the chunk-cache mode or path.
- Configuration validation and pipeline-listing commands validate the mode but do not create workspace directories or plan files.
- Update CLI usage text only as needed to expose the new flag. Defer all narrative documentation to Stage 8.
Tests
Add CLI and integration tests for:
- a default
autorun writing a plan and a second independent invocation reusing it without a chunk operation or chunk LLM call; - file, environment, and CLI precedence, including persistent
refreshin file and environment configuration; bypassperforming no plan-store access and resolving or creating no default chunk-plan root;- invalid flag, environment, and file values with their established error classifications;
- an explicit chunk-plan root from file and environment, including exact use of
/var/cache/notarius/chunk-planswithout an appended suffix, using a recording store factory and never writing to that real path; - an explicit root succeeding without calling a failing per-user cache resolver;
- an injected per-user default resolving exactly to
<user-cache-dir>/notarius/chunk-plans; workspace.directorychanges having no effect on chunk-plan placement and a chunk-cache directory having no effect on other workspace state;- per-user cache-root discovery failure under
auto,refresh, andbypass, including the allowed no-statebypasscase, plus unwritable-store failures; - resume plus each cache mode, showing independent behavior;
- validation and listing commands having no filesystem side effects; and
- reuse across changed pipeline, chunk module/options, references, validators, and LLM settings when the source digest is unchanged.
Run at minimum:
go test ./internal/cli
go test ./internal/framework/pipeline ./internal/framework/chunkplan
go test ./internal/modules/integration
Exit criteria
The production CLI implements the complete mode and precedence contract, independent invocations reuse source-addressed plans by default, bypass and refresh have exact state semantics, and the repository is green.
Stage 6: Expose producer provenance and safe diagnostics
Status: Complete
Objective
Make every output and diagnostic record distinguish the requested chunk module from the producer of the effective plan without exposing sensitive payloads by default.
Read first
docs/integrations/json-output.mddocs/internal/diagnostics.md- manifest assembly in
internal/framework/pipeline/runner.go internal/core/artifacts/artifacts.go- current diagnostics and debug-envelope implementations and tests
Implement
- Add
ChunkPlanManifestto the run manifest and all required clone, conversion, and serialization paths. - Populate
modeand exactly one action after a candidate plan has passed structural validation and materialization:reusedfor anautohit;generatedfor anautomiss or invalid record;refreshedfor generation underrefresh; andbypassedfor generation underbypass. Retain that action if the current chunk-validator chain rejects the candidate; publication still follows Stage 4's accept-only rule. If no candidate reaches materialization, leave action and candidate plan fields empty in the partial failure manifest and report the failure in diagnostics.
- Preserve the existing top-level
chunkerand its module metadata as the requested module. Never overwrite those fields with cached producer data. - Populate producer module, LLM profile, references, metadata, creation time, source digest, plan digest, and schema from the effective stored or newly generated record. A reused record reports its original producer, even when it differs from the requested module.
- Define producer LLM profile as the resolved chunk-stage profile used during generation. Leave it empty for producers that did not use an LLM; do not substitute the current run's requested profile on reuse.
- Keep producer references as existing redacted provenance records. Deep-clone metadata, references, warnings, annotations, and raw JSON at every ownership boundary.
- Add a redacted
chunk-plan.jsondiagnostic artifact, backed by a summary onRunOutputso the CLI can write it on success, rejection, or framework failure. It contains mode, source and candidate plan digests, requested module, lookup status and redacted reason, action, validation status, and publication status. Use these closed values:- lookup:
hit,missing,invalid, orskipped; - validation:
not_run,approved,approved_with_warnings,rejected, orerror; and - publication:
not_requested,published, ornot_published. It contains no source units, materialized chunk content, annotation bytes, reference content, prompts, model responses, or raw invalid-file content.
- lookup:
- Keep complete plan, annotations, attempts, and materialized chunks confined to existing opt-in debug artifacts and apply their normal restrictive file handling.
- Preserve JSON-output compatibility by adding fields rather than renaming unrelated existing fields. Omit producer-only optional values when absent in the same style as the surrounding manifest schema.
Tests
Cover:
- all four actions and their exact manifest fields;
- requested and producer modules differing on a hit;
- producer metadata remaining stable when current configuration changes;
- LLM-backed and non-LLM producers;
- deep-clone and mutation safety for raw annotations and metadata;
- default diagnostic redaction, including invalid stored files;
- complete data appearing only under explicit debug configuration; and
- JSON serialization and compatibility fixtures.
Run at minimum:
go test ./internal/core/artifacts
go test ./internal/framework/pipeline
go test ./internal/cli
Exit criteria
Manifests and diagnostics explain which plan was requested, selected, and produced; default output remains redacted; debug behavior is explicit; and all compatibility tests pass.
Stage 7: Add cross-run, corruption, and concurrency hardening
Status: Complete
Objective
Exercise the completed design across package boundaries and adversarial state, then close any correctness gaps without changing the settled contract.
Read first
- all tests added in Stages 1–6
- end-to-end CLI and module integration test harnesses
- atomic-write, cancellation, retry, and race-sensitive framework code
- repository import-boundary tests
Implement
- Add black-box tests using separate CLI application instances and a shared temporary chunk-plan root. Prove reuse across different pipelines, configured chunk modules, options, references, lanes, validators, and LLM profiles.
- Prove that a changed canonical source digest selects a different path, while byte-identical canonical sources reuse the same plan.
- Exercise generic plans through D&D pipelines and D&D-annotated plans through
generic pipelines. Optional annotations must survive, while no downstream
component may require
dnd/scenesmerely because the requested chunker is the D&D scene module. - Add corruption cases for truncated JSON, unknown fields, schema mismatch,
source mismatch, plan-digest mismatch, bad boundaries, invalid annotations,
and materialization failure. Verify
autoregeneration and non-destructive failure behavior exactly. - Add concurrent reader/writer and writer/writer tests. Readers observe either the old complete envelope or the new complete envelope; after successful writers, the final file is one complete valid record. Do not assert which writer wins.
- Exercise interruption before save, during temp-file creation, and around rename where the implementation permits deterministic fault injection. Prior valid state must remain readable unless a complete replacement was published.
- Verify cancellation, retry limits, warning order, error classification, and debug ordering on misses and hits. No cache hit may consume chunk-stage retry budget or invoke the module.
- Verify legacy chunk checkpoint files cannot influence reuse and that lane resume still keys from effective materialized chunk digests after refresh.
- Extend import-boundary tests so
internal/core/sourceowns no framework or module dependencies and the generic store owns no concrete module imports. - Ensure examples and all tests isolate workspace state in temporary
directories and isolate chunk-plan state with a temporary configured root
or explicitly select
bypass; tests must never write to the real per-user default or/var/cache/notarius/chunk-plans. - Run the race detector over the packages that access the plan store and runner concurrently, and fix any race within feature scope.
Tests
In addition to the new focused tests, run:
go test ./...
go test -race ./internal/framework/chunkplan ./internal/framework/pipeline
go vet ./...
go build ./cmd/notarius
Exit criteria
The feature is demonstrated across independent runs, corruption and concurrent publication cannot expose partial state, cross-domain annotations remain optional, cancellation and retry behavior is deterministic, and all repository and race checks pass.
Stage 8: Publish current-behavior documentation
Status: Not started
Objective
After implementation is complete, make the supported behavior discoverable without duplicating canonical ownership across documents.
Read first
docs/policy/architecture.mddocs/policy/documentation.md- every current-behavior document linked below
- the final code, flags, schemas, examples, and tests from Stages 1–7
Implement
-
Update
docs/policy/architecture.mdwith the plan-generation/materialization boundary, source-addressed reuse, and the independent cache-state surface at the level appropriate for the canonical system overview. -
Update
docs/internal/pipeline.mdwith mode behavior, hit/miss control flow, validator placement, retry behavior, and removal of chunk checkpoints. -
Update
docs/internal/modules.mdwith theChunker.Plancontract, generic boundaries, optional annotation namespaces, and framework materialization. -
Update
docs/internal/overview.mdwith the new plan-store package and current state ownership, and remove chunk checkpoint ownership from its checkpoint description. Keep detailed checkpoint and plan execution flow indocs/internal/pipeline.mdrather than creating a parallel internal state reference. -
Update
docs/config.mdwithworkspace.chunk_cache.mode,workspace.chunk_cache.directory, both environment variables, strict values, precedence, and the per-user cache-root default. State explicitly thatworkspace.directorydoes not affect plan placement and that the configured directory is the root itself. Keep field-level details owned here. Document that Unixos.UserCacheDirrejects a relativeXDG_CACHE_HOMEand that this is a configuration error rather than a fallback. -
Update
docs/cli.mdwith--chunk_cachesemantics and examples. Link to configuration rather than restating its entire precedence model. -
Update
docs/operations.mdwith plan location, permissions, invalid-state recovery, refresh and bypass operations, concurrency semantics, sensitive debug data, deletion as a recoverable but potentially expensive regeneration event, and the no-history/no-rollback limitation. Document both:- the ordinary Linux per-user default,
$XDG_CACHE_HOME/notarius/chunk-planswhenXDG_CACHE_HOMEis a valid absolute path, or$HOME/.cache/notarius/chunk-planswhen it is unset; and /var/cache/notarius/chunk-plansas the recommended configured root for a system-wide Linux deployment running under a dedicated service account. Explain that the system path is not the unprivileged default, show the following minimal configuration, require the operator or package installer to provision it with restrictive service-account ownership and permissions, and warn against sharing the cache across mutually untrusted users:
workspace: chunk_cache: directory: /var/cache/notarius/chunk-plans - the ordinary Linux per-user default,
-
Update
docs/integrations/json-output.mdanddocs/internal/diagnostics.mdwith requested versus producer provenance, actions, warnings, and redaction boundaries. -
Keep package-level plan/range/annotation and materialization invariants in
docs/internal/pipeline.md; no separate source document is needed unless the implemented subsystem becomes too large for that canonical owner. -
Update examples only when they materially clarify operation; examples must use temporary or explicitly configured workspace and chunk-cache paths.
-
Remove future-tense disclaimers from the feature roadmap, mark its completion outcomes as achieved, and mark all completed stages in this document. Keep the roadmap as historical target-state context rather than copying implementation details into it.
-
Validate every changed link, heading, code symbol, flag, environment name, path, and JSON field against the implementation. Search for stale
Chunker.Chunk,ChunkResult,chunks.scenes, and chunk-checkpoint claims.
Tests and validation
Run:
go test ./...
go vet ./...
go build ./cmd/notarius
git diff --check
Also run repository link or documentation checks if present, and manually
inspect the reading map in docs/development.md and component links in
docs/internal/overview.md for canonical ownership and navigation consistency.
Exit criteria
All canonical documents describe implemented behavior, operational guidance is complete and non-duplicative, no stale chunk API or checkpoint documentation remains, roadmap status is accurate, and the repository is green.