Release extraction intermediates after their last consumers
This commit is contained in:
@@ -178,6 +178,11 @@ The runner finalizes diagnostics once before output encoding, or on an earlier
|
|||||||
failure. If aggregation fails, the result retains the successfully aggregated
|
failure. If aggregation fails, the result retains the successfully aggregated
|
||||||
prefix and the error includes both the aggregation failure and any run failure;
|
prefix and the error includes both the aggregation failure and any run failure;
|
||||||
encoding does not proceed after unsuccessful aggregation.
|
encoding does not proceed after unsuccessful aggregation.
|
||||||
|
Ordered extraction assembly releases its reorder map, and the coordinator drops
|
||||||
|
each lane's extraction values after its continuation returns, even while siblings
|
||||||
|
remain active. On failure, remaining values are dropped after dispatched work
|
||||||
|
drains and diagnostics have been retained. Normalized artifacts remain available
|
||||||
|
through generated handoffs, evidence construction, and output encoding.
|
||||||
|
|
||||||
The encoder receives owned normalized/auxiliary values and returns logical files.
|
The encoder receives owned normalized/auxiliary values and returns logical files.
|
||||||
It does not choose a directory, publish a report, or serialize execution ledgers.
|
It does not choose a directory, publish a report, or serialize execution ledgers.
|
||||||
|
|||||||
@@ -174,9 +174,11 @@ between sources/runs; a chunk-only or process-global index is not equivalent.
|
|||||||
|
|
||||||
**Assessment:** Source-established resource-lifetime weakness; original P2.
|
**Assessment:** Source-established resource-lifetime weakness; original P2.
|
||||||
|
|
||||||
**Progress:** Returned run results no longer retain intermediate artifact,
|
**Status:** Resolved. Returned results retain no private working state. Ordered
|
||||||
eligibility, or diagnostic working state. Releasing lane intermediates after
|
assembly releases extraction reorder maps, completed continuations release lane
|
||||||
their last consumers remains pending.
|
values while siblings run, and drained failures drop undeliverable values after
|
||||||
|
diagnostics are retained. Normalized artifacts remain through their consumers.
|
||||||
|
Controlled lifetime, integration, and pipeline race checks pass.
|
||||||
|
|
||||||
**Source:** [RES-002](05-resources.md#res-002--intermediate-results-outlive-their-consumers).
|
**Source:** [RES-002](05-resources.md#res-002--intermediate-results-outlive-their-consumers).
|
||||||
|
|
||||||
|
|||||||
@@ -546,6 +546,13 @@ Update finalization docs; errors convey incompleteness without new report fields
|
|||||||
|
|
||||||
## Stage 18 — Release Intermediates After Their Last Consumer
|
## Stage 18 — Release Intermediates After Their Last Consumer
|
||||||
|
|
||||||
|
**Completed.** Ordered assembly releases reorder maps; the coordinator releases
|
||||||
|
extraction values when each continuation returns and drops undeliverable values
|
||||||
|
after failure drains. Diagnostics survive independently and normalized artifacts
|
||||||
|
remain through handoff, evidence, and encoding. A controlled blocked-sibling
|
||||||
|
test checks owner references and output retention; pipeline, integration, and
|
||||||
|
pipeline race suites pass.
|
||||||
|
|
||||||
**Coverage:** CAT-006 completion. **Prerequisites:** Stages 15–17.
|
**Coverage:** CAT-006 completion. **Prerequisites:** Stages 15–17.
|
||||||
|
|
||||||
Release reorder maps after successful ordered extraction assembly and extraction
|
Release reorder maps after successful ordered extraction assembly and extraction
|
||||||
|
|||||||
@@ -80,6 +80,10 @@ func (r *Runner) runLanes(parent context.Context, input RunInput, step PreparedP
|
|||||||
groups = append(groups, state.completedGroups[index]...)
|
groups = append(groups, state.completedGroups[index]...)
|
||||||
}
|
}
|
||||||
completedOutputs[lane].diagnosticGroups = append(groups, completedOutputs[lane].diagnosticGroups...)
|
completedOutputs[lane].diagnosticGroups = append(groups, completedOutputs[lane].diagnosticGroups...)
|
||||||
|
// All dispatched jobs have drained; incomplete values cannot be consumed.
|
||||||
|
state.completedGroups = nil
|
||||||
|
state.results = nil
|
||||||
|
state.values = nil
|
||||||
}
|
}
|
||||||
mergeCompletedLanes(&output, completedOutputs)
|
mergeCompletedLanes(&output, completedOutputs)
|
||||||
if err := selectRunError(parent, runErrors); err != nil {
|
if err := selectRunError(parent, runErrors); err != nil {
|
||||||
@@ -263,6 +267,9 @@ func (e *laneEngine) handleExtractResult(result extractJobResult) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *laneEngine) handleCompletion(completion laneCompletion) {
|
func (e *laneEngine) handleCompletion(completion laneCompletion) {
|
||||||
|
// The worker has returned, so merge, normalization, and capture no longer
|
||||||
|
// borrow this lane's extraction values even if a sibling is still running.
|
||||||
|
e.states[completion.index].values = nil
|
||||||
e.completedOutputs[completion.index] = completion.output
|
e.completedOutputs[completion.index] = completion.output
|
||||||
if completion.err != nil {
|
if completion.err != nil {
|
||||||
e.runErrors = append(e.runErrors, classifyLaneError(completion.index, len(e.chunks), completion.err))
|
e.runErrors = append(e.runErrors, classifyLaneError(completion.index, len(e.chunks), completion.err))
|
||||||
@@ -342,6 +349,8 @@ func finalizeLaneExtract(state *laneExtractState) {
|
|||||||
state.fallbackCount++
|
state.fallbackCount++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Ordered values now own the needed references; the reorder map is redundant.
|
||||||
|
state.results = nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) continueLane(ctx context.Context, input RunInput, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, chunks []source.Chunk, state *laneExtractState) (laneOutput, error) {
|
func (r *Runner) continueLane(ctx context.Context, input RunInput, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, chunks []source.Chunk, state *laneExtractState) (laneOutput, error) {
|
||||||
|
|||||||
77
internal/framework/pipeline/runner_lifetime_test.go
Normal file
77
internal/framework/pipeline/runner_lifetime_test.go
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
package pipeline
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"testing"
|
||||||
|
"testing/synctest"
|
||||||
|
|
||||||
|
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestLaneReleasesExtractValuesWhileSiblingRuns(t *testing.T) {
|
||||||
|
synctest.Test(t, func(t *testing.T) {
|
||||||
|
prepared := preparedConcurrentPipeline(t, 1)
|
||||||
|
doc := typedTestDocumentWithUnits(1)
|
||||||
|
_, chunks, err := validateAndMaterializeChunkPlan(doc, typedTestPlan(doc))
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
input := RunInput{Prepared: prepared, Workers: 2, pipeline: prepared.resolved}
|
||||||
|
states, err := initializeLaneStates(input, prepared.Steps[0], chunks)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
release := make(chan struct{})
|
||||||
|
installExtractOperation(prepared, 1, func(ctx context.Context, request contracts.ExtractionInput) (erasedTypedResult, error) {
|
||||||
|
select {
|
||||||
|
case <-release:
|
||||||
|
case <-ctx.Done():
|
||||||
|
return erasedTypedResult{}, ctx.Err()
|
||||||
|
}
|
||||||
|
return erasedTypedResult{Value: typedValueForLane(1, request.Chunk.Index)}, nil
|
||||||
|
})
|
||||||
|
completed := make(chan struct{})
|
||||||
|
original := prepared.Steps[0].lanes[0].typed.normalize
|
||||||
|
prepared.Steps[0].lanes[0].typed.normalize = func(ctx context.Context, implementation any, request contracts.NormalizeInput[any], execution ExecutionContext[any]) (erasedTypedResult, error) {
|
||||||
|
result, err := original(ctx, implementation, request, execution)
|
||||||
|
close(completed)
|
||||||
|
return result, err
|
||||||
|
}
|
||||||
|
type result struct {
|
||||||
|
outputs []laneOutput
|
||||||
|
errors []orderedRunError
|
||||||
|
}
|
||||||
|
done := make(chan result, 1)
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
go func() {
|
||||||
|
outputs, failures := New().runLaneEngine(ctx, laneEngineConfig{input: input, doc: doc, chunks: chunks, states: states})
|
||||||
|
done <- result{outputs, failures}
|
||||||
|
}()
|
||||||
|
<-completed
|
||||||
|
synctest.Wait()
|
||||||
|
if states[0].results != nil || states[0].values != nil {
|
||||||
|
t.Fatal("completed lane retains extraction intermediates")
|
||||||
|
}
|
||||||
|
close(release)
|
||||||
|
got := <-done
|
||||||
|
if len(got.errors) != 0 {
|
||||||
|
t.Fatalf("lane errors = %v", got.errors)
|
||||||
|
}
|
||||||
|
if len(got.outputs[0].normalizeOutputs) != 1 || len(got.outputs[1].normalizeOutputs) != 1 {
|
||||||
|
t.Fatalf("normalized outputs were retired early: %#v", got.outputs)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestFinalizeLaneExtractReleasesReorderMapWithoutMutatingArtifacts(t *testing.T) {
|
||||||
|
value := erasedExtractArtifact{Value: codecNotes{Items: []string{"kept"}}}
|
||||||
|
state := &laneExtractState{results: map[int]extractJobResult{0: {value: value}}}
|
||||||
|
finalizeLaneExtract(state)
|
||||||
|
if state.results != nil || len(state.values) != 1 {
|
||||||
|
t.Fatalf("finalized state = %#v", state)
|
||||||
|
}
|
||||||
|
if got := state.values[0].Value.(codecNotes).Items[0]; got != "kept" {
|
||||||
|
t.Fatalf("artifact value = %q", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user