Refresh pipeline execution and run state internal guides

This commit is contained in:
2026-11-22 06:45:28 +00:00
parent 5db09d0203
commit 41f6079040
3 changed files with 355 additions and 383 deletions

View File

@@ -1,279 +1,202 @@
# Pipeline Internals # Pipeline Internals
This document describes the framework-owned pipeline mechanics in This guide explains resolution, typed execution, candidate assessment, and
**internal/framework/pipeline**. [Configuration](../config.md) owns selectable ordering in `internal/framework/pipeline`.
profiles, bindings, and retry settings; [Operations](../operations.md) owns [Configuration](../config.md#pipelines) owns bindings and producer controls;
state lifecycle and recovery; and the [integration contracts](../integrations/) [Operations](../operations.md) owns state/recovery workflows;
own durable output shapes. Concrete production extensions are covered by [integration contracts](../integrations/json-output.md) own deliverable shapes.
[Module Internals](modules.md). [Module Internals](modules.md) owns extension recipes.
## Boundary ## Boundary And Fixed Shape
The pipeline framework accepts a resolved composition, registries, shared The framework receives prepared composition, source bytes, a supplied session,
dependencies, input bytes, a supplied prompt session, and state/debug native execution options, and explicit cache/capture collaborators. It returns
collaborators. It returns logical output files, normalized artifacts, recorded logical deliverable files, process diagnostics, and fallback count. Normalized
rejections, grouped diagnostics, manifest provenance, and checkpoint decisions. The artifacts and reuse eligibility remain private run state for handoffs/evidence;
CLI owns process arguments, configuration discovery, session resolution, there is no reporting ledger in the output boundary.
physical roots, and placement of returned output files.
The framework has one fixed shape: ```text
input -> chunk -> ordered steps [extract -> merge -> normalize] -> output
```
~~~ Input and chunking are pipeline-wide. Each ordered step contains typed artifact
input -> chunk -> extract -> merge -> normalize -> output lanes; the next step waits for the current step and its generated handoffs.
~~~ This fixed pipeline is not a general workflow graph. The CLI owns arguments,
configuration loading, session derivation, physical roots, publication, and
Input and chunking are pipeline-wide. A selected artifact lane owns extract, native reporting; see [CLI Internals](cli.md).
merge, and normalize; output aggregates the terminal lane outcomes. A pipeline
is an ordered list of steps, not an arbitrary workflow graph.
## Resolve, Materialize, Prepare ## Resolve, Materialize, Prepare
Resolution turns a configured pipeline profile into a **ResolvedPipeline**. [ResolvePipeline](../../internal/framework/pipeline/profile.go) selects modules,
It normalizes the pipeline and lane identities, applies stage defaults, selects capabilities, exact artifact kinds, validators, references, options, and concrete
requested lanes where that is supported, resolves validator chains, checks producer controls. It copies static native prompt dependencies from selected
module capabilities and typed artifact compatibility, validates options, and specifications. Effective profiles apply only to model-backed roles; an empty
assigns a deterministic resolved-composition digest. A correction protocol is profile selection leaves native prompt defaults applicable.
selected from each eligible LLM-backed producer specification and becomes part [Control resolution](../../internal/framework/pipeline/validation_policy.go)
of that resolved identity; only `single_response_v1` is currently supported. settles presence-aware controls before execution; modules do not repeat inheritance.
Preparation rejects an LLM-backed producer that combines a non-empty validator The composition digest describes resolved composition, not cache identity.
chain with positive producer retries unless it declares that protocol. Producers
without validators or without retries remain valid without correction support.
The resolved pipeline contains bindings and declared reference targets, not
external reference bytes.
After selection, the resolver applies command, binding, and pipeline profile
precedence to LLM-backed bindings and validators only; prompt defaults remain
an empty resolved binding profile. It resolves structural output repair
separately: a binding's `structured_output_repair_attempts` value wins, then a
pipeline value applies to LLM-backed bindings and validators, and omission
leaves the prompt-owned policy intact. An explicit repair value on a
deterministic binding is rejected. Resolved bindings own copied repair values,
and these effective values are part of the digest, so execution and checkpoint
consumers do not repeat profile inheritance or configuration resolution.
Each LLM request receives its own copy of that resolved value. PromptKit spends
it only for structural correction inside one completion; the runner's binding
retry policy remains the separate outer budget for complete stage attempts.
Configuration resolution supplies the selected overlay and catalog; see
[Configuration Internals](configuration.md).
External reference materialization happens before preparation. The materializer Resolution receives exact reference bindings/unbinds, not CLI selector grammar.
checks that each slot is declared by the selected module, resolves a file path It preserves required slots, external/generated conflicts, prior-step
relative to the correct configuration or working-directory origin, reads dependencies, and artifact compatibility. [Reference materialization](../../internal/framework/pipeline/references.go)
UTF-8 text, verifies media type and size limits, and retains bounded reads selected external bytes with declaration/invocation origins, media/UTF-8
provenance. For a positive slot limit, it reads at most the limit plus one byte and declared size checks. Generated selections remain declarations until their
and rejects overflow before retaining content. A generated-artifact selector producer step completes. Public selection semantics belong in
remains declared but has no bytes until its producing step completes. [References And Ordered Handoffs](../config.md#references-and-ordered-handoffs).
Preparation is the construction boundary. It validates the resolved shape and [Prepare](../../internal/framework/pipeline/prepare.go) clones resolved data and
registry set, clones the resolved data, then constructs the input adapter, constructs input, chunker, validators, typed lanes, and output through supplied
chunker, stage-local validators, every typed lane, and output encoder. The registries and the shared native engine. Builders receive independently owned
prepared producer metadata preserves each selected correction protocol, and build requests. Exact Go type, codec, evidence-projector, registration, and
the resolved digest carrying that metadata participates in checkpoint identity. constructor checks happen before source parsing. There is no correction transport,
Each registered builder receives its own cloned build request immediately asset registry, or persistent execution identity to collect.
before its module-owned code runs. Preparation also collects stable checkpoint Offline known-resource [preflight](../../internal/preflight/preflight.go) is
fingerprints. Missing registrations, incompatible typed entries, nil a separate composition check, not request execution or module construction.
implementations, and constructor failures are reported before source parsing
or any stage operation begins.
An output encoder can opt into source-evidence publication through its output ## Typed Operations And Assessment
policy. Preparation keeps the configured lane allowlist and active lanes
separate, then verifies an exact typed evidence projector and registered codec
for each active lane. The resulting private plan is immutable; lanes excluded
by invocation filtering remain configured but do not acquire a projector for
that run.
## Typed Lanes And References [Typed contracts](../../internal/framework/contracts/typed_pipeline.go) carry
a `ProducerOperation[T]` with resolved controls, one assessor, native execution
options, incoming reuse eligibility, and an optional typed cache binding.
[Runner operation completion](../../internal/framework/pipeline/runner_operation.go)
assesses deterministic production directly. Model modules use
[RunProducer](../../internal/framework/pipeline/producer.go); the runner consumes
its acceptance/fallback outcome without assessing it again.
Each resolved lane has one artifact kind, codec, and exact Go type. The [Candidate assessment](../../internal/framework/pipeline/candidate_assessment.go)
framework uses private type erasure only around those typed operations; every invokes each applicable validator once in configured order. It continues after
handoff checks exact type and codec identity and reports incompatibility as an rejections and unavailable/failed assessments; caller cancellation and framework/
error rather than panicking. Encoding through the registered codec is the capture failures interrupt it. Typed candidates are encoded once for assessment,
boundary for output, checkpoints, debug records, and generated references. then decoded separately for each typed validator. Serialized validators receive
owned bytes/schema metadata; chunk validators receive detached materialized
chunks. Source, references, annotations, and metadata views are isolated too.
Reference targets are stage- and lane-specific. External reference bytes are [Assessment values](../../internal/framework/contracts/assessment.go) distinguish
cloned into the operation request. Generated references are built at the next approval, semantic rejection, failure, and unavailable judgment. An empty configured
step boundary from exactly one accepted normalized producer output. The chain adds no ordinary acceptance criteria, but cannot remove intrinsic codec or
framework decodes and re-encodes that output with the registered producer source-addressing checks. Rejection guidance is module-authored, ordered, and
codec, checks its complete schema and media identity, and records a content deduplicated separately from reason codes/operator messages. Invalid guidance is
digest plus bounded producer provenance. A missing, ambiguous, invalid, or a contract failure, not invented correction text. LLM validators execute directly
incompatible producer prevents the consumer step from starting. on the shared engine and do not own another semantic loop.
Resolution receives only exact stage-and-lane operational reference overrides. ## Native Continuation And Terminal Handling
The CLI may offer broader pipeline- or lane-scoped selectors, but expands and
arbitrates those before entering the framework. External overrides are applied
after configured external defaults and local bindings. They cannot coexist
with a generated binding for the same target and slot, and external unbinds do
not remove generated handoffs.
## Execution And Ordering For executed model work, `RunProducer` checks native errors and structural
validation status before interpretation, including a failed result with no Go
error. Module interpretation produces a usable typed candidate and any actionable
domain guidance. The assessor runs the complete chain on every delivered usable
candidate, including unchanged revisions and the final allowed response.
The runner validates its input, installs no-op state collaborators when none When correction is possible, the helper starts native `Coordinate` from the
were supplied, and serially performs source parsing and chunk-plan selection. captured exchange. Its first callback reuses already-collected initial findings.
It transports the supplied session unchanged to prompt-facing operations and Native coordination owns turn iteration and growing history; the module builds
run-manifest metadata; it neither derives a session nor substitutes a parsed only new correction material from fixed operation inputs. Successful native
source document identifier. The public session contract is owned by the execution, stopped/exhausted coordination, and domain acceptance are distinct.
[CLI reference](../cli.md#run). Native repair/transient retries are not extended by outer application retries.
An accepted plan is materialized into source-addressed chunks and passes the [LLM Integration](llm.md) owns the native request/capture integration.
configured chunk validators before any lane runs. A chunk rejection is a
recorded pipeline outcome: lanes do not start, but the output stage can encode
the terminal result.
For each ordered step, the runner first builds generated reference sets from [Terminal disposition](../../internal/framework/pipeline/producer_outcome.go)
the accepted normalized outputs of earlier steps. It then executes the step's either fails or invokes one supported module fallback. Fallback construction
lanes. Later steps do not begin until the current step is terminal and its preserves intrinsic/source/downstream invariants without ordinary reassessment
generated handoffs have succeeded. or semantic-approval claims. It may fail normally. A failed continuation cannot
recover an earlier candidate; caller cancellation and undelivered responses
produce no acceptance/fallback. Native operational timeouts retain typed causes
rather than becoming caller cancellation solely by error spelling.
Within a step, the lane engine dispatches extraction jobs in deterministic Deterministic work produces once, then uses direct assessment and any supported
chunk-first, lane-second order to a bounded worker group. When all extraction module fallback. An operation/parse/materialization/encoding error remains an
jobs for one lane are terminal, a bounded continuation group can run that error, not a generic rerun or permissive recovery mechanism.
lane's merge and normalize work while extraction for other lanes continues.
The framework does not create an unbounded goroutine per chunk or lane.
Completion timing does not determine public results. The coordinator restores ## One Ready-Job Worker Pool
lane and chunk order before merging results, and selects a framework error by
stable stage, lane, and chunk position. A validator rejection records a lane
outcome without cancelling unrelated work. A framework error or parent
cancellation cancels derived work, prevents queued work from starting, waits
for started workers, and prevents output encoding.
## Validation, Retries, And Output [The lane coordinator](../../internal/framework/pipeline/runner_concurrent.go)
dispatches extraction jobs and ready lane continuations to the same bounded
worker pool. A continuation becomes ready after all extracts for its lane finish;
one worker runs its merge then normalization. Ready continuations can interleave
with unrelated extraction, and prerequisite waits occupy no worker.
Input parsing, chunking, step barriers, and final output remain sequential.
Every chunk, extract, merge, and normalize candidate passes its resolved Results are restored to chunk/lane order before merging. Stable operation/lane/
validator chain. Validators receive immutable canonical input appropriate to chunk positions select the scoped terminal error among reported failures rather
their target: chunks, codec-decoded typed candidates, or serialized codec than response timing. Parent cancellation takes precedence. On failure/cancellation
bytes. Each typed validator receives a newly decoded value from the one the coordinator stops dispatch, drains started results, closes jobs, and joins
candidate serialization for that attempt, while serialized validators receive workers before returning. Output encoding does not run after terminal failure.
separately owned representation bytes and schema metadata. They may approve,
approve with warnings, reject, fail, or be skipped when a runtime prerequisite
is unavailable. The shared executor settles every configured validator in
order. A failed LLM-backed validator retries only itself against the same
immutable candidate; it does not regenerate the producer or alter the
validator request. Rejections stop that validator, while other configured
validators still run. The executor retains ordered results, bounded
deduplicated correction guidance from rejections, and only the final exhausted
failure outcome for each validator. The correction builder keeps first
occurrence order, omits internal reason codes, validator names, and operator
messages, and requests one complete replacement. Missing guidance or an
oversized aggregate is a framework contract error; guidance is never inferred
or truncated.
The runner applies the binding's retry policy around a stage operation and its Nested validation and correction use the operation's worker, not another worker
complete validation chain. It preserves terminal diagnostics only from the final accepted permit. Native backend admission is independent and released before candidate
or rejected attempt, plus one fixed validation-incomplete warning per validator whose execution assessment, allowing a nested validator on the same limited backend. Worker
budget was exhausted under `warn_continue`. Cancellation stops retries. configuration does not create another model scheduler, queue, or retry policy.
Normalizer-specific retry directives consume this same budget and validate any
final safe fallback through the normalizer chain. A directive may carry bounded
correction guidance only when it also exposes the exact latest
`single_response_v1` candidate. The state machine then uses the same replacement
request shape as validator correction. A directive without guidance clears any
prior correction and starts a fresh attempt, which preserves structural retry
behavior when no valid response exists.
The artifact-neutral producer-attempt state machine owns that shared budget, ## Handoffs And Reuse Eligibility
attempt provenance, semantic-correction material, and terminal-policy
selection. It accepts producer and complete-validation closures, so artifact
materialization, cache handling, checkpoints, and debug output stay at the
operation boundary. It distinguishes operational, structural, module-requested,
and validator-semantic retries. Model feedback from either semantic source is
available only for a valid latest `single_response_v1` candidate. A
deterministic or no-model validator rejection instead settles the semantic
policy immediately, while a feedback-free module directive remains an ordinary
fresh retry. Structural-output errors alone use the structural policy, and
validation failure without rejection settles the validator-failure policy
without regenerating the producer.
Chunk planning uses this state machine for generated plans. A rejected or [Generated handoffs](../../internal/framework/pipeline/handoff.go) locate one
validation-incomplete automatic cache hit is not model material and therefore earlier normalized producer, decode/re-encode through its registered codec, check
falls through to a fresh initial generation at producer attempt one; it neither full artifact/schema/media compatibility, and clone bytes into the consumer's
receives a correction, consumes retry budget, promotes cached-candidate declared reference set. Valid qualified fallback is usable current-run context;
diagnostics, nor overwrites the stored record. An incomplete cache validation it does not become ordinary acceptance through a handoff.
under `fail_run` terminates instead. Only a newly generated, completely
validated plan is published to the chunk-plan store. Rejected plans never
advance, and validation-incomplete plans remain unpublishable.
After terminal lane work, the runner assembles manifest provenance, normalized Eligibility travels separately from artifact bytes:
artifacts, rejections, final grouped diagnostics, and an optional accepted chunk map. When an
output policy selected evidence lanes, it decodes accepted serialized normalize
outputs through their registered codecs and invokes the prepared typed
projectors. Rejected or absent lanes contribute nothing. This reconstruction is
also used after normalized-checkpoint reuse, so no second typed output channel
is retained. The runner passes the resulting owned artifact to the output
encoder, which returns logical files and does not choose a physical directory.
The CLI publishes those files only after the runner returns without a framework
error. Logical file names and schemas are defined by the [output integration
contracts](../integrations/).
For every completed producer disposition, the runner projects one bounded - A chunk fallback disables reuse for all derived lane work.
validation summary to the manifest, the affected rejection when present, and - An extract fallback disables reuse for its dependent merge/normalization.
the CLI result receipt. The summary records status, configured-order rejecting - A fallback-derived generated reference disables reuse from the consuming
validators and reason codes, incomplete validators, producer-attempt count, operation onward; unrelated siblings and earlier accepted work remain eligible.
and terminal action. It contains no operator message, correction guidance, or
model response. `complete`, `rejected`, and `incomplete` describe the final
candidate disposition; a run-level `incomplete` status indicates at least one
current-run output advanced under `warn_continue`.
## Checkpoint And Debug Hooks An emitting fallback increments the run count once. Merely consuming its data or
inheriting ineligibility adds no fallback. These are transient dependency facts,
not persisted fingerprints or a second recovery protocol.
The runner receives checkpoint and debug interfaces rather than roots. It [Typed cache bindings](../../internal/framework/pipeline/runner_cache.go) use the
records workflow transitions and reuse decisions through the supplied registered durable codec and available exact-type evidence projection for
collaborators, and clones reusable artifacts before they re-enter normal typed current-source usability. [Chunk planning](../../internal/framework/pipeline/runner_chunk_plan.go)
handoff. Generated-reference dependencies participate in checkpoint decisions. uses the same producer cache with plan decoding/rematerialization. Hits do not
Selective recomputation can require a canonical accepted normalized predecessor run semantic assessment. Deterministic work has no synthetic request/cache key.
before a dependent lane starts. [Run State Internals](state.md) owns prepared-handle/store mechanics and recovery.
The runner writes successful checkpoint artifacts only after complete accepted ## Output And Capture Boundaries
validation. Chunk plans follow the same rule for publication. A rejection,
invalid structured response, or incomplete validation is never reusable state;
the current run may still hand off an otherwise valid `warn_continue` result
according to its terminal policy. The runner carries private reuse eligibility
through extract, merge, normalize, and generated-reference handoff. Any stage
derived from incomplete validation skips both checkpoint lookup and all
checkpoint publication even when that stage's own validation completes.
External references and fully validated generated references remain eligible.
Attempt debug records retain safe kind,
validator, repair-usage, policy, and terminal-decision provenance. Full
assistant and correction content remains confined to the requested detailed
LLM trace.
Debug recording is attempt-scoped and application-owned. A failure to persist [Runner](../../internal/framework/pipeline/runner.go) parses/validates source,
required debug data is a framework error. State roots, persistence, reason-code materializes the final plan, runs ordered steps, aggregates diagnostics, and
meanings, resume, and cleanup are intentionally owned by builds optional chunk-map/evidence values. Normalized values are codec-checked
[Run State Internals](state.md) and [Operations](../operations.md). before handoff/output. Evidence reconstruction also works from reused artifacts;
Extract-validator trace scopes include the current chunk ordinal so concurrent it projects selected citations in source order, not a second typed output channel.
chunks cannot overwrite one another's validator attempts or LLM artifacts. [Evidence internals](../../internal/framework/pipeline/evidence_output.go) and
the [evidence contract](../integrations/evidence-context.md) define those owners.
## Invariants To Preserve The encoder receives owned normalized/auxiliary values and returns logical files.
It does not choose a directory, publish a report, or serialize execution ledgers.
[JSON output](../integrations/json-output.md) owns logical paths and payloads;
[State Internals](state.md) owns physical publication and failure retention.
- The six fixed stages remain explicit; a pipeline is not a general DAG. Optional scoped evidence records inputs, candidates, findings, outcomes, and
- Resolution and preparation reject statically discoverable incompatibility cache decisions. Native observers enroll actual executions once in one invocation
before parsing or execution. group, preserving unknown usage and terminal coverage. Capture failures are
- Every typed lane uses one compatible artifact kind, codec, and exact Go type. ordinary boundary failures, never semantic feedback or reasons to rerun a model.
- Generated references come only from one earlier accepted normalized producer Debug layout is private; it is not a recovery source or consumer protocol.
and carry canonical identity rather than an unverified value.
- Rejections are recorded outcomes; framework errors cancel derived work and
prevent output encoding.
- Public ordering and selected errors are independent of goroutine completion
order.
- Pipeline modules receive collaborators and data, never CLI streams or
physical output, cache, or debug roots.
## Focused Tests ## Focused Verification
- **internal/framework/pipeline/profile_test.go** and - [Resolution](../../internal/framework/pipeline/typed_resolution_test.go),
**typed_resolution_test.go** cover resolution, defaults, ordered steps, [preparation](../../internal/framework/pipeline/preparation_test.go), and
compatibility, validators, references, and resolved identity. [references](../../internal/framework/pipeline/references_test.go) cover static
- **internal/framework/pipeline/preparation_test.go** covers complete compatibility and construction/materialization ownership.
construction before execution and contextual construction failures. - [Assessment](../../internal/framework/pipeline/candidate_assessment_test.go)
- **internal/framework/pipeline/references_test.go** and **handoff_test.go** and [producer tests](../../internal/framework/pipeline/producer_test.go) cover
cover external materialization, generated references, provenance, and typed isolation, whole-chain/final-turn assessment, guidance, native status, and cancellation.
producer checks. - [Runner operations](../../internal/framework/pipeline/runner_operation_test.go)
- **internal/framework/pipeline/runner_concurrency_test.go** covers bounded cover no outer reassessment, deterministic errors, fallback counts/eligibility,
execution, ordered steps, stable error selection, rejections, and and actual generated consumers.
cancellation. - [Worker tests](../../internal/framework/pipeline/runner_concurrency_test.go)
- **internal/framework/pipeline/runner_chunk_plan_test.go**, and [ready-job tests](../../internal/framework/pipeline/ready_jobs_test.go)
**runner_typed_checkpoint_test.go**, and cover mixed jobs, stable order, serial liveness, nested admission, and draining.
**runner_accepted_checkpoint_test.go** cover state hooks and reuse behavior. - [Producer reuse](../../internal/framework/pipeline/producer_cache_test.go),
- **internal/framework/pipeline/runner_attempt_debug_test.go** and [runner reuse](../../internal/framework/pipeline/runner_cache_test.go), and
**runner_terminal_debug_test.go** cover attempt and terminal debug behavior. [plan reuse](../../internal/framework/pipeline/chunk_plan_cache_test.go) cover
initial keys, applied artifacts, no reassessment on hits, and current-source checks.
- [Capture](../../internal/framework/pipeline/native_capture_test.go),
[evidence](../../internal/framework/pipeline/evidence_output_test.go), and
[assembled recovery](../../internal/cli/recovery_contract_test.go) cover
native facts, output reconstruction, and cross-boundary reuse/failure.
Run **go test ./internal/framework/pipeline ./internal/cli** after changing a Use focused pipeline and CLI suites for boundary changes.
pipeline boundary. Use the more focused tests above while iterating. [Development](../development.md#validation) owns repository-wide checks.

View File

@@ -1,165 +1,193 @@
# Run State Internals # Run State Internals
LLM debug response artifacts and their safe per-call references retain an This guide explains physical cache, capture, and publication collaborators.
optional terminal execution summary when one is available. This metadata is [Operations](../operations.md) owns layout, permissions, retention, and recovery
diagnostic only and does not change receipts, checkpoints, or aggregate usage. procedures; [Configuration](../config.md#concurrency-output-cache-and-debug) owns
settings/defaults; [CLI Reference](../cli.md#completion-report) owns reporting.
[Pipeline Internals](pipeline.md) owns assessment, workers, and dependency eligibility.
This document describes the implementation collaborators behind output, cache, ## Composition And Independent State
and debug state. User-visible fields belong in [Configuration](../config.md),
and physical layout, retention, recovery, reason codes, and cleanup belong in
[Operations](../operations.md).
## Composition [The run handler](../../internal/cli/pipeline_run.go) is the physical-path
composition root. It obtains loaded configuration and a safe run identity,
allocates requested capture before engine/preflight, resolves/materializes/
prepares, and then constructs the cache/recorder collaborators for the runner.
Shared inspection loaders create no run storage.
`internal/cli` is the only physical-path composition root. It resolves the Modules receive explicit operation/cache/evidence interfaces and data, not roots
effective configuration, selects exact roots, allocates requested debug bundles, or CommandKit reporters. Output, accepted-result cache, and optional capture
constructs cache collaborators, writes logical output files, and reports paths. remain independent. None is a required metadata bundle for another.
Pipeline modules receive interfaces and request data, never output, cache, or In-memory normalized artifacts support handoffs/evidence; they are not a
debug roots. persisted resume ledger.
The CLI creates no chunk-plan store in bypass mode. It creates a checkpoint ## Prepared Result Reuse
recorder only when recording is enabled and a checkpoint loader only for a
resume invocation. It allocates debug state only after a safe run identity has
been generated and only when debug capture was requested. These choices keep
the three state families independently composable.
## Output And Cache [RunProducer](../../internal/framework/pipeline/producer.go) owns native request
selection and cache interaction for an eligible model operation:
The pipeline runner returns logical output files. After validating every 1. Prepare the initial request once with `PrepareExecution`, retain its detached
logical name, the CLI exclusively creates the run directory beneath the details and opaque `MessageContentHash`.
selected output root and performs confined, atomic file writes within it. 2. For a read-enabled selection, decode a found entry through the expected
The runner supplies an accepted chunk map as an optional, defensively owned durable codec and current-source usability checks. On a usable hit, discard
output-request artifact. The JSON encoder alone decides whether its explicit the prepared handle and return the artifact without model work.
option writes the map and optional index descriptor; neither the map payload 3. On a miss, execute that exact handle with `RunPrepared`, then use ordinary
nor its annotations are copied into the run manifest. The durable fields are interpretation, complete assessment, and native continuation.
owned by the [Accepted Chunk Map contract](../integrations/chunk-map.md). 4. Store only final ordinary acceptance, encoded as the applied typed artifact
or checked logical plan, under the initial key. Dispose of unused
prepared handles on every exit.
`internal/framework/chunkplan` owns source-addressed plan storage, validation, [Typed bindings](../../internal/framework/pipeline/runner_cache.go) attach codec
and atomic publication. Its store is constructed only when the selected mode is and source-evidence checks; [chunk-plan bindings](../../internal/framework/pipeline/runner_chunk_plan.go)
not `bypass`. It preserves rooted entry checks while creating new cache roots decode and rematerialize against the current document. A hit has no ordinary
and source-digest directories with requested mode `0777`, then creates an semantic revalidation, native execution event, restored exchange, or historical
atomic temporary file through rooted `O_CREATE|O_EXCL` with requested mode usage. Normalizers store applied domain results, not reconciliation proposals.
`0666` before sync and rename. Deterministic operations stay uncached without manufactured requests.
`internal/framework/checkpoint` owns checkpoint identity, manifests, payload The key is the native initial message-content value, not a configuration,
codecs, loader, and recorder. The CLI constructs a recorder whenever checkpoint policy, model/session, implementation, or source-only fingerprint. Rendered
recording is enabled and constructs a loader only for a `--resume` invocation. message changes can change selection; settings-only changes need not.
The recorder writes manifest and payload JSON through Correction retains the initial key. Public reuse choices and their consequences
`fileio.WriteJSONWithProcessPermissions`, whose confined atomic writer creates belong in [Operations](../operations.md#accepted-result-cache-and-recovery).
new directories with requested mode `0777` and temporary files with requested
mode `0666` before publication.
Identity incorporates explicit stable semantic fingerprints collected from
prepared modules and validators in addition to configuration, input,
references, runtime overrides, observed LLM profiles, and the LLM runtime's
non-secret effective profile-source identity. A profile source change therefore
causes a cold miss even when the configured profile ID remains unchanged.
The serialized
`workspace_schema_version` identifiers are frozen wire-compatibility fields;
they do not describe a current public state surface.
Ordered-step lane checkpoints include the step identity in their storage scope. Reuse eligibility is separate from the selected cache mode. Fallback and actual
Accepted step and lane identities are encoded injectively before becoming dependent work perform neither lookup nor storage, even if they later produce
filesystem path components, while ordinary safe identifiers retain their otherwise accepted output. Bypass/ineligible work uses ordinary native execution
readable paths. without cache-specific split preparation. Capture reuses available prepared
When a later lane consumes a generated artifact, its dependency fingerprints details; it never adds preparation to explain a hit.
include the producer's artifact kind, complete schema identity, media type,
canonical content digest, and size. Ordinary resume compares those fingerprints
when progressively loading consumer stage checkpoints, so changed producer
content produces `dependency_invalidated` rather than stale downstream reuse.
Selective recomputation instead requires each unselected producer's accepted
normalized artifact; invalid accepted state records its specific bounded reason
and stops before the dependent. The selected step and its transitive dependents
record `forced_recompute`.
Ordinary resume loads extract, merge, and normalize checkpoints progressively ## Filesystem Store And Failure Handling
and may execute later lane stages after an earlier cache miss. Selective
recomputation instead asks the loader for the required producer's accepted
normalize artifact. That lookup reuses the existing normalize files, requires
workspace schema v4 plus an exact non-empty invocation identity, and deliberately
does not require extract or merge checkpoint files or dependency fingerprints.
The runner performs canonical codec and producer-provenance validation before
cloning the artifact into normal step output. Success restores only stored
normalize diagnostics and emits one normalize decision; failure retains the
files, records the decision, and stops without executing the producer or
consumer.
The loader assigns a typed category and reason code at each validation site; [artifactcache.FilesystemStore](../../internal/framework/artifactcache/filesystem.go)
diagnostic prose is not classified after the fact. The runner then applies implements the narrow `contracts.ArtifactCache` interface. Construction retains
forced-execution policy, validates reusable artifact bytes through the prepared the exact selected root without creating it. Lookup checks one confined regular
codec once, returns the canonical hydrated value to the stage, and records the JSON entry; missing data is an ordinary miss. Stored bytes are the unchanged
final decision before enforcing a required-predecessor failure. That failure accepted artifact, without provenance/execution envelopes or alternate key
names only the step, lane, and stable reason code. Decision detail is selected dimensions. Physical placement belongs in
from code-owned descriptions by reason code and then UTF-8 normalized and [Operations](../operations.md#state-surfaces).
bounded; callers cannot supply arbitrary diagnostic prose. Typed categories and
codes remain intact through pipeline events and become strings only in manifest
and debug-summary JSON.
[Operations](../operations.md#checkpoint-recording-resume-and-recompute) is the
canonical operator-facing reason-code reference.
`internal/core/fileio` provides confined atomic file writes used by state The store honors the resolved read/write mode. Refresh does not read or remove
collaborators. Its exact-mode writer remains available to output and debug previous acceptance in anticipation of execution. Only a newly supplied accepted
callers; its process-permission writer is used by checkpoints. The chunk-plan value can replace it. Failed refresh execution or a failed cache write preserves
store retains its stronger rooted entry validation. [Operations](../operations.md#cache-provisioning) the old entry.
owns cache mode and provisioning guidance. Legacy data is not scanned, converted, rewritten, or deleted.
The CLI constructs selective-recomputation policy from resolved generated Publication uses [fileio](../../internal/core/fileio/fileio.go)'s confined atomic
artifact dependencies. It forces the selected step and transitive consumers, process-permission writer. New cache objects use process/deployment creation
while marking unforced producers as required reusable inputs. The runner owns permissions; there is no permission convergence on an existing root.
the actual hydration and rejection decisions; the [Operations guide](../operations.md#checkpoint-recording-resume-and-recompute) [ADR-0017](../adr/0017-defer-cache-access-policy-to-deployment.md) owns that decision.
owns the operator workflow and stable reason-code meanings.
## Debug Bundles [Cache integration](../../internal/framework/pipeline/producer_cache.go) treats
unreadable/malformed/codec-unusable entries as diagnostic misses. Store failures
become scoped process warnings without failing successful production or calling
the provider again. Artifact encoding, caller cancellation, requested evidence,
and observer failures retain their own error boundaries; they are not swallowed
as best-effort storage failures.
`internal/core/debugbundle` allocates an explicitly requested per-run bundle Accepted predecessors can survive downstream failure and be reused by an ordinary
with `summary/` and `trace/` roots. `SummaryWriter` persists redacted command, rerun. There is no checkpoint loader, resume barrier, forced-recompute policy, or
resolution, run, final grouped diagnostic, and failure artifacts. `internal/framework/debug` canonical partition selected solely by source digest. New message selections
implements the pipeline-facing trace recorder under the trace root. populate independently; an accepted plan is rematerialized, not restored with a
historic execution claim.
The CLI allocates a bundle before pipeline resolution and treats requested ## Artifact Publication And Native Reporting
summary or trace persistence failures as command failures. The pipeline's debug
boundaries redact sensitive metadata and credential-shaped bytes while allowing
application-owned trace material. Debug data is never a checkpoint source or
cache input.
Generated reference bytes exist only in cloned operation requests and are not The runner returns logical deliverable files only after successful execution/
written as paths into checkpoints, manifests, or debug summaries. Those state encoding. The [JSON encoder](../../internal/modules/generic/output/json/encoder.go)
surfaces retain canonical identities and bounded producer provenance so that a owns domain-file selection and optional auxiliary inclusion.
resume decision can be explained without copying generated campaign content. [JSON output](../integrations/json-output.md),
[chunk maps](../integrations/chunk-map.md), and
[evidence context](../integrations/evidence-context.md) own logical paths/schemas,
not the store or recorder.
After allocation, one CLI-owned state value accumulates the known report paths, [writeOutputFiles](../../internal/cli/run_output.go) validates every logical
pipeline outcome counts, and validation status. A single guarded terminalization path before allocating the run directory, refuses an existing destination, and
operation writes the success report, or makes one attempt each to write the writes files with confined atomic helpers. This is per-file publication, not
failure report and error log. Terminal persistence failures are reported an all-files transaction. A later write can leave a partial new directory;
separately and never replace the command's primary error. existing siblings are preserved. No rollback deletes available artifacts.
## Invariants To Preserve After complete publication, the run handler finalizes requested capture before
[reportRunResult](../../internal/cli/run_result.go) submits the small native
completion value. The report is not automatically persisted or required to decode
domain files. No index, manifest, receipt, or process-diagnostic sidecar is emitted.
Artifact count counts returned deliverables, including selected available auxiliaries,
not cache/debug/intermediate files.
- Modules receive state collaborators and request data, never physical roots. Post-publication capture/render/delivery failure remains nonzero with available
- Output logical paths are validated before a run directory is allocated, and locations. Valid artifacts remain; model work and capture terminalization are not
files are atomically written within that directory. repeated. Native delivery evidence is separate from the operation cause, and
- Chunk-plan publication occurs only for accepted plans; bypass does not failed stdout may be partial. Public outcomes and caller responsibilities belong
construct or touch a plan store. in [CLI Reference](../cli.md#output-streams-and-exit-statuses) and the
- Checkpoint recording and checkpoint loading remain separate collaborators. [subprocess guide](../consumers/subprocess.md).
- Debug state is opt-in, is not cache input, and terminal reporting does not
obscure the command's primary failure.
## Tests To Inspect ## Capture Lifecycle
- `internal/cli/run_contract_test.go`: command-owned state allocation, [Debug selection](../../internal/cli/run_debug.go) preserves native boolean and
terminalization, and output/report boundaries. supplied directory semantics independently of verbosity. The run path alone
- `internal/cli/cache_contract_test.go`: cache-mode precedence, root selection, calls [debug.Start](../../internal/framework/debug/recorder.go).
and resume collaborator construction. [Bundle allocation](../../internal/core/debugbundle/bundle.go) validates identity,
- `internal/cli/state_hardening_test.go`: independent roots, reuse, failures, creates a new absolute per-run directory, and atomically updates a relative
permissions, cleanup, and redaction. latest link at start. Failure can return an available directory for explanation/
- `internal/cli/recompute_policy_test.go`: forced dependents and required retention. Disabled capture creates nothing; completion never retargets the link.
reusable predecessors for selective recomputation.
- `internal/cli/recompute_execution_contract_test.go`: selective recomputation, One synchronized recorder writes evidence incrementally, retaining lifecycle
filesystem recovery, deterministic decisions, and failed predecessor state. state and the first recording error rather than accumulating whole-run content.
- `internal/cli/production_contract_test.go`: production composition and Callback failures are exposed at the next boundary that can return an error.
configuration validation at the CLI boundary. `Finalize` attempts terminal evidence once, joins primary and capture causes,
- `internal/cli/example_contract_test.go`: maintained example ownership. and retains its result. Repeated calls do not rewrite evidence or retarget latest.
- `internal/core/debugbundle/*_test.go`: bundle allocation and summary writes. A later presentation failure does not change capture into another terminal run.
- `internal/framework/checkpoint/*_test.go`: checkpoint serialization and Allocation/link/record/finalization failures never trigger model retries or a
reuse. fallback directory. Available files are retained.
- `internal/framework/chunkplan/store_test.go`: plan envelope, confinement,
publication, and permissions. ## Native And Application Evidence
[Run capture](../../internal/cli/run_capture.go) snapshots the original secret-aware
application/PromptKit configuration and source evidence. Scoped pipeline capture
records source/reference/incoming artifacts, normalization originals/mappings/
proposals, candidates, complete findings/guidance, fallback/deterministic outcomes,
and cache selection/current artifact bytes.
[NativeCapture](../../internal/framework/pipeline/native_capture.go) composes
existing observers and preparation callbacks. Preparation callbacks retain
detached details cheaply; ordinary boundaries write prepared contracts, native
results, raw response text, and full readable exchanges. Events are written
incrementally. Scope includes operation/step/lane/chunk/validator identity to
avoid concurrent evidence collisions.
One invocation `ExecutionGroup` enrolls actual initial, continuation, and nested
validator executions once. Native identity, terminal coverage, and unknown usage
remain native facts, not a copied profile/attempt accounting model.
Hits can retain prepared evidence without execution or usage. Result-less failures
retain availability/cause evidence; undelivered responses are explicitly unassessed.
Native credential omissions and ConfigKit marked-secret paths are preserved.
Arbitrary source/prompt/response text is not heuristically rewritten or made safe
for general logging. Exact evidence names/nesting/serialized forms are private,
not a public protocol or reconstruction requirement. Debug is neither cache
input nor an artifact-discovery interface; [Operations](../operations.md#debug-bundles)
owns handling.
## Focused Verification
- [Filesystem cache](../../internal/framework/artifactcache/filesystem_test.go)
and [permissions](../../internal/framework/artifactcache/filesystem_permissions_unix_test.go)
cover raw bytes, modes, atomic replacement, diagnostics, confinement, deployment
permissions, and unchanged legacy files.
- [Producer cache](../../internal/framework/pipeline/producer_cache_test.go),
[typed runner cache](../../internal/framework/pipeline/runner_cache_test.go), and
[plan cache](../../internal/framework/pipeline/chunk_plan_cache_test.go) cover
initial handles/keys, final acceptance, current-source checks, and failed refresh.
- [Recorder](../../internal/framework/debug/recorder_test.go) and
[allocation](../../internal/core/debugbundle/bundle_test.go) cover incremental
failure retention, concurrent starts, and one terminalization.
- [Native evidence](../../internal/framework/pipeline/native_capture_test.go) and
[configuration capture](../../internal/cli/run_capture_test.go) cover available
content, exact sensitivity, observer composition, and no duplicate preparation.
- [Output writes](../../internal/cli/run_id_test.go) and
[native result boundaries](../../internal/cli/run_result_command_test.go) cover
collisions, partial directories, capture/presentation failure, and retained causes.
- [Assembled recovery](../../internal/cli/recovery_contract_test.go) covers
downstream fix/rerun, initial-key correction reuse, qualified fallback, actual
generated consumers, and debug on hits/failure.
Use focused pipeline/cache/recorder/CLI checks for state-boundary changes.
[Development](../development.md#validation) owns wider validation.

View File

@@ -2054,6 +2054,27 @@ check cross-links and stale package references.
## Stage 42: Refresh Pipeline And State Internal Guides ## Stage 42: Refresh Pipeline And State Internal Guides
**Status:** Complete. Rewrote both guides around current typed resolution,
materialization/preparation, operation-scoped complete assessment, native
continuation, strict/permissive disposition, and supported fallback. Documented
one ready-job pool, ordered barriers/results, cancellation draining, and separate
native backend admission. Handoffs distinguish usable qualified artifacts from
ordinary acceptance and propagate reuse exclusion only to actual dependents.
State guidance now traces the retained initial prepared handle/hash, durable
typed/plan usability on hits without semantic reassessment, final acceptance
writes, best-effort cache I/O, independent publication, and one incremental
capture lifecycle with native observations. Removed retired checkpoint/resume,
separate pool, generic retry, reporting-sidecar, copied accounting, and heuristic
redaction flows. Public controls, paths, payloads, and handling link to canonical
owners; debug representation remains private. Inspected current runner/helper,
assessment, coordinator, handoff, cache, allocation/recorder, evidence, and CLI
publication code and focused regressions. All 84 local links/anchors resolve;
no current incoming anchors require repair. Pipeline, cache, recorder, bundle,
file I/O, and CLI package tests and vet pass; removal searches and
`git diff --check` pass. No runtime code/data or operator contract changed.
Module and D&D contributor recipes remain assigned to the next stage.
**Goal:** explain acceptance, concurrency, recovery, and capture as implemented. **Goal:** explain acceptance, concurrency, recovery, and capture as implemented.
**Inspect/change:** `docs/internal/{pipeline,state}.md`; typed helper/assessment, **Inspect/change:** `docs/internal/{pipeline,state}.md`; typed helper/assessment,