Document extension concurrency and ownership
This commit is contained in:
@@ -37,7 +37,8 @@ type SerializedOutput struct {
|
||||
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 {
|
||||
Kind() ArtifactKind
|
||||
Schema() ArtifactSchema
|
||||
|
||||
@@ -58,6 +58,7 @@ type InputAdapter interface {
|
||||
Parse(ctx context.Context, req ParseRequest) (*source.SourceDocument, error)
|
||||
}
|
||||
|
||||
// Chunker prepares the plan before extraction jobs are dispatched.
|
||||
type Chunker interface {
|
||||
Key() string
|
||||
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
|
||||
// and reference isolation boundaries still apply. Core does not promise a
|
||||
// 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 {
|
||||
preparedOperation()
|
||||
operationType(T)
|
||||
|
||||
@@ -69,6 +69,8 @@ type ExecutionOptions struct {
|
||||
|
||||
// EvidenceWriter receives optional operation-scoped debug evidence. Modules get
|
||||
// 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 {
|
||||
WriteJSON(string, any) error
|
||||
WriteBytes(string, []byte) error
|
||||
|
||||
@@ -33,17 +33,23 @@ type NormalizeArtifact[T any] struct {
|
||||
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 {
|
||||
Key() string
|
||||
ReferenceSlots() []ReferenceSlot
|
||||
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 {
|
||||
Key() string
|
||||
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 {
|
||||
Key() string
|
||||
ReferenceSlots() []ReferenceSlot
|
||||
@@ -68,6 +74,8 @@ type TypedValidationRequest[T any] struct {
|
||||
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 {
|
||||
Name() string
|
||||
ExecutionClass() ExecutionClass
|
||||
@@ -87,6 +95,7 @@ type ChunkValidationRequest struct {
|
||||
Chunks []source.Chunk
|
||||
}
|
||||
|
||||
// ChunkValidator validates the chunk plan before extraction is dispatched.
|
||||
type ChunkValidator interface {
|
||||
Name() string
|
||||
ExecutionClass() ExecutionClass
|
||||
@@ -112,6 +121,8 @@ type SerializedValidationRequest struct {
|
||||
Content []byte
|
||||
}
|
||||
|
||||
// SerializedValidator instances used during extraction can receive overlapping
|
||||
// calls for different chunks and must protect shared mutable state.
|
||||
type SerializedValidator interface {
|
||||
Name() string
|
||||
ExecutionClass() ExecutionClass
|
||||
|
||||
Reference in New Issue
Block a user