Document extension concurrency and ownership
This commit is contained in:
@@ -146,6 +146,9 @@ Other callers may attach their own native observer. See the
|
|||||||
[native observation contract][observations] and
|
[native observation contract][observations] and
|
||||||
[ownership decision](../adr/0025-use-consumer-owned-execution-observation.md);
|
[ownership decision](../adr/0025-use-consumer-owned-execution-observation.md);
|
||||||
do not add overlapping totals or a durable profile inventory.
|
do not add overlapping totals or a durable profile inventory.
|
||||||
|
Shared callbacks must tolerate overlapping operations and own their mutable
|
||||||
|
state. Injected clients and observers follow the pinned [PromptKit consumer
|
||||||
|
contract][consumer] and its linked GoDoc, not stronger local guarantees.
|
||||||
|
|
||||||
[Native capture](../../internal/framework/capture/native.go) composes
|
[Native capture](../../internal/framework/capture/native.go) composes
|
||||||
observers/preparation callbacks rather than replacing them. Retain prepared
|
observers/preparation callbacks rather than replacing them. Retain prepared
|
||||||
|
|||||||
@@ -96,7 +96,25 @@ Preparation transfers returned values and callbacks to that operation; a shared
|
|||||||
module must not store mutable operation state. Own mutable slices/maps that a
|
module must not store mutable operation state. Own mutable slices/maps that a
|
||||||
callback might modify and respect the existing detached input boundaries.
|
callback might modify and respect the existing detached input boundaries.
|
||||||
Optional evidence projections are lazy and only invoked when capture is enabled.
|
Optional evidence projections are lazy and only invoked when capture is enabled.
|
||||||
This does not promise thread safety for caller-supplied writers or observers.
|
|
||||||
|
The selected extractor instance and its extraction validators are reused across
|
||||||
|
chunk jobs, so preparation and validation calls can overlap. Registered codecs
|
||||||
|
are shared and their methods can overlap too. Keep mutable operation state in
|
||||||
|
the invocation or synchronize retained mutable fields; detached validator views
|
||||||
|
do not protect receiver state. Parsed source and its shared index are read-only.
|
||||||
|
Chunk preparation precedes extraction. A lane's merge and normalization run in
|
||||||
|
order after its extracts, but can overlap other lanes' work; this is not a claim
|
||||||
|
that every stage method is universally concurrent.
|
||||||
|
|
||||||
|
Callbacks and evidence projections belong to their operation. Borrowed source,
|
||||||
|
references, writers, and other collaborators must not be used after their valid
|
||||||
|
lifetime. If an extension starts background work, it owns stopping and joining
|
||||||
|
it before releasing those collaborators: the runner joins dispatched operations,
|
||||||
|
not arbitrary extension goroutines. Shared callbacks and explicitly supplied
|
||||||
|
evidence writers must support concurrent calls when used by concurrent jobs.
|
||||||
|
The [recorder](../../internal/framework/debug/recorder.go) is synchronized;
|
||||||
|
per-operation wrappers do not serialize a shared external writer. Native client
|
||||||
|
and observer obligations are owned by the pinned [PromptKit contract](llm.md#native-evidence-and-sensitive-data).
|
||||||
|
|
||||||
## Validators And Deterministic Work
|
## Validators And Deterministic Work
|
||||||
|
|
||||||
|
|||||||
@@ -137,6 +137,8 @@ chunk positions select the scoped terminal error among reported failures rather
|
|||||||
than response timing. Parent cancellation takes precedence. On failure/cancellation
|
than response timing. Parent cancellation takes precedence. On failure/cancellation
|
||||||
the coordinator stops dispatch, drains started results, closes jobs, and joins
|
the coordinator stops dispatch, drains started results, closes jobs, and joins
|
||||||
workers before returning. Output encoding does not run after terminal failure.
|
workers before returning. Output encoding does not run after terminal failure.
|
||||||
|
This join covers dispatched operations, not background goroutines started by an
|
||||||
|
extension; those remain the extension's responsibility.
|
||||||
|
|
||||||
Nested validation and correction use the operation's worker, not another worker
|
Nested validation and correction use the operation's worker, not another worker
|
||||||
permit. Native backend admission is independent and released before candidate
|
permit. Native backend admission is independent and released before candidate
|
||||||
|
|||||||
@@ -156,6 +156,11 @@ detached details cheaply; ordinary boundaries write prepared contracts, native
|
|||||||
results, raw response text, and full readable exchanges. Events are written
|
results, raw response text, and full readable exchanges. Events are written
|
||||||
incrementally. Scope includes operation/step/lane/chunk/validator identity to
|
incrementally. Scope includes operation/step/lane/chunk/validator identity to
|
||||||
avoid concurrent evidence collisions.
|
avoid concurrent evidence collisions.
|
||||||
|
The built-in [recorder](../../internal/framework/debug/recorder.go) serializes
|
||||||
|
its writes. An explicit writer selected by the runner is shared directly and
|
||||||
|
must support overlapping calls from concurrent operations; separate native
|
||||||
|
capture instances do not add a common lock around that writer. The caller owns
|
||||||
|
its lifetime through completion of dispatched work.
|
||||||
|
|
||||||
When capture is enabled, the CLI attaches its own native execution group to
|
When capture is enabled, the CLI attaches its own native execution group to
|
||||||
the inherited invocation context after allocation. Its finish path writes one
|
the inherited invocation context after allocation. Its finish path writes one
|
||||||
|
|||||||
@@ -580,6 +580,10 @@ is out of scope.
|
|||||||
**Assessment:** Documentation/extension-contract clarity gap; original P3;
|
**Assessment:** Documentation/extension-contract clarity gap; original P3;
|
||||||
no current default implementation was found to race.
|
no current default implementation was found to race.
|
||||||
|
|
||||||
|
**Status:** Resolved. Interface comments and internals describe actual sharing,
|
||||||
|
borrowed lifetimes, callback and writer obligations, and the worker join boundary.
|
||||||
|
Contract, pipeline, integration, and relevant race tests pass.
|
||||||
|
|
||||||
**Source:** [CONC-002](04-concurrency.md#conc-002--extension-and-explicit-capture-concurrency-obligations-are-implicit).
|
**Source:** [CONC-002](04-concurrency.md#conc-002--extension-and-explicit-capture-concurrency-obligations-are-implicit).
|
||||||
|
|
||||||
Prepared extractors/validators and codecs are reused across concurrent chunk
|
Prepared extractors/validators and codecs are reused across concurrent chunk
|
||||||
|
|||||||
@@ -904,6 +904,8 @@ No assertion DSL or new defaults.
|
|||||||
|
|
||||||
## Stage 34 — Document Actual Extension Sharing And Lifetimes
|
## Stage 34 — Document Actual Extension Sharing And Lifetimes
|
||||||
|
|
||||||
|
**Completed.**
|
||||||
|
|
||||||
**Coverage:** CAT-025. **Prerequisites:** final preceding interfaces.
|
**Coverage:** CAT-025. **Prerequisites:** final preceding interfaces.
|
||||||
|
|
||||||
Update stage/preparation/codec/validator/EvidenceWriter comments and module/LLM/
|
Update stage/preparation/codec/validator/EvidenceWriter comments and module/LLM/
|
||||||
|
|||||||
@@ -37,7 +37,8 @@ type SerializedOutput struct {
|
|||||||
Artifact SerializedArtifact `json:"artifact"`
|
Artifact SerializedArtifact `json:"artifact"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ArtifactCodec owns the stable encoding for one concrete artifact type.
|
// ArtifactCodec owns the stable encoding for one concrete artifact type. The
|
||||||
|
// registered instance is shared and its methods may be called concurrently.
|
||||||
type ArtifactCodec[T any] interface {
|
type ArtifactCodec[T any] interface {
|
||||||
Kind() ArtifactKind
|
Kind() ArtifactKind
|
||||||
Schema() ArtifactSchema
|
Schema() ArtifactSchema
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ type InputAdapter interface {
|
|||||||
Parse(ctx context.Context, req ParseRequest) (*source.SourceDocument, error)
|
Parse(ctx context.Context, req ParseRequest) (*source.SourceDocument, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Chunker prepares the plan before extraction jobs are dispatched.
|
||||||
type Chunker interface {
|
type Chunker interface {
|
||||||
Key() string
|
Key() string
|
||||||
ReferenceSlots() []ReferenceSlot
|
ReferenceSlots() []ReferenceSlot
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ type Preparation[T any] func(context.Context) (PreparedOperation[T], error)
|
|||||||
// operation; callers must not mutate shared input through them. Existing source
|
// operation; callers must not mutate shared input through them. Existing source
|
||||||
// and reference isolation boundaries still apply. Core does not promise a
|
// and reference isolation boundaries still apply. Core does not promise a
|
||||||
// general deep copy of domain values or callback captures.
|
// general deep copy of domain values or callback captures.
|
||||||
|
// Callbacks are operation-scoped; extensions must finish any background work
|
||||||
|
// before releasing borrowed inputs or collaborators. The runner joins its own
|
||||||
|
// dispatched calls, not arbitrary goroutines started by an extension.
|
||||||
type PreparedOperation[T any] interface {
|
type PreparedOperation[T any] interface {
|
||||||
preparedOperation()
|
preparedOperation()
|
||||||
operationType(T)
|
operationType(T)
|
||||||
|
|||||||
@@ -69,6 +69,8 @@ type ExecutionOptions struct {
|
|||||||
|
|
||||||
// EvidenceWriter receives optional operation-scoped debug evidence. Modules get
|
// EvidenceWriter receives optional operation-scoped debug evidence. Modules get
|
||||||
// no filesystem root and cannot use capture as an execution or reporting service.
|
// no filesystem root and cannot use capture as an execution or reporting service.
|
||||||
|
// An explicitly supplied writer shared by concurrent operations must support
|
||||||
|
// concurrent calls; per-operation capture wrappers do not serialize that writer.
|
||||||
type EvidenceWriter interface {
|
type EvidenceWriter interface {
|
||||||
WriteJSON(string, any) error
|
WriteJSON(string, any) error
|
||||||
WriteBytes(string, []byte) error
|
WriteBytes(string, []byte) error
|
||||||
|
|||||||
@@ -33,17 +33,23 @@ type NormalizeArtifact[T any] struct {
|
|||||||
Value T
|
Value T
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extractor instances are reused for a lane; extraction preparations for
|
||||||
|
// different chunks may overlap. Keep mutable operation state local or synchronize it.
|
||||||
type Extractor[T any] interface {
|
type Extractor[T any] interface {
|
||||||
Key() string
|
Key() string
|
||||||
ReferenceSlots() []ReferenceSlot
|
ReferenceSlots() []ReferenceSlot
|
||||||
PrepareExtraction(context.Context, ExtractionInput) (PreparedOperation[T], error)
|
PrepareExtraction(context.Context, ExtractionInput) (PreparedOperation[T], error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Merger runs after a lane's extracts complete, in its ready continuation.
|
||||||
|
// Other lanes can execute concurrently.
|
||||||
type Merger[T any] interface {
|
type Merger[T any] interface {
|
||||||
Key() string
|
Key() string
|
||||||
PrepareMerge(context.Context, MergeInput[T]) (PreparedOperation[T], error)
|
PrepareMerge(context.Context, MergeInput[T]) (PreparedOperation[T], error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Normalizer follows merge in a lane's continuation, which may overlap work in
|
||||||
|
// other lanes. Do not assume exclusive access to shared collaborators.
|
||||||
type Normalizer[T any] interface {
|
type Normalizer[T any] interface {
|
||||||
Key() string
|
Key() string
|
||||||
ReferenceSlots() []ReferenceSlot
|
ReferenceSlots() []ReferenceSlot
|
||||||
@@ -68,6 +74,8 @@ type TypedValidationRequest[T any] struct {
|
|||||||
Value T
|
Value T
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TypedValidator instances attached to extraction can validate different chunks
|
||||||
|
// concurrently. Detached requests do not isolate mutable receiver fields.
|
||||||
type TypedValidator[T any] interface {
|
type TypedValidator[T any] interface {
|
||||||
Name() string
|
Name() string
|
||||||
ExecutionClass() ExecutionClass
|
ExecutionClass() ExecutionClass
|
||||||
@@ -87,6 +95,7 @@ type ChunkValidationRequest struct {
|
|||||||
Chunks []source.Chunk
|
Chunks []source.Chunk
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ChunkValidator validates the chunk plan before extraction is dispatched.
|
||||||
type ChunkValidator interface {
|
type ChunkValidator interface {
|
||||||
Name() string
|
Name() string
|
||||||
ExecutionClass() ExecutionClass
|
ExecutionClass() ExecutionClass
|
||||||
@@ -112,6 +121,8 @@ type SerializedValidationRequest struct {
|
|||||||
Content []byte
|
Content []byte
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SerializedValidator instances used during extraction can receive overlapping
|
||||||
|
// calls for different chunks and must protect shared mutable state.
|
||||||
type SerializedValidator interface {
|
type SerializedValidator interface {
|
||||||
Name() string
|
Name() string
|
||||||
ExecutionClass() ExecutionClass
|
ExecutionClass() ExecutionClass
|
||||||
|
|||||||
Reference in New Issue
Block a user