Separate runner working state from returned results
This commit is contained in:
@@ -12,8 +12,10 @@ ordering in `internal/framework/pipeline`.
|
|||||||
The framework receives prepared composition, source bytes, a supplied session,
|
The framework receives prepared composition, source bytes, a supplied session,
|
||||||
native execution options, and explicit cache/capture collaborators. It returns
|
native execution options, and explicit cache/capture collaborators. It returns
|
||||||
logical deliverable files, process diagnostics, and fallback count. Normalized
|
logical deliverable files, process diagnostics, and fallback count. Normalized
|
||||||
artifacts and reuse eligibility remain private run state for handoffs/evidence;
|
artifacts, reuse eligibility, and pending diagnostic groups remain private
|
||||||
there is no reporting ledger in the output boundary.
|
run/lane working state for handoffs and aggregation. The returned result keeps
|
||||||
|
only finalized diagnostics, logical files, and fallback count; there is no
|
||||||
|
reporting ledger in the output boundary.
|
||||||
|
|
||||||
```text
|
```text
|
||||||
input -> chunk -> ordered steps [extract -> merge -> normalize] -> output
|
input -> chunk -> ordered steps [extract -> merge -> normalize] -> output
|
||||||
|
|||||||
@@ -174,6 +174,10 @@ 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,
|
||||||
|
eligibility, or diagnostic working state. Releasing lane intermediates after
|
||||||
|
their last consumers remains pending.
|
||||||
|
|
||||||
**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).
|
||||||
|
|
||||||
Lane reorder maps and extraction values survive completed continuation while
|
Lane reorder maps and extraction values survive completed continuation while
|
||||||
|
|||||||
@@ -471,6 +471,14 @@ architecture/pipeline/operator claims. No new durable reporting protocol.
|
|||||||
|
|
||||||
## Stage 15 — Separate Working State From Logical RunOutput
|
## Stage 15 — Separate Working State From Logical RunOutput
|
||||||
|
|
||||||
|
**Completed.** Private run/lane state now owns normalized artifacts, reuse
|
||||||
|
eligibility, and pending diagnostic groups. Public results contain only final
|
||||||
|
diagnostics, logical output files, and fallback count. Existing focused tests
|
||||||
|
inspect private state where necessary; integration and CLI use the public result.
|
||||||
|
The prescribed suites and pipeline race checks pass. Completed-work diagnostic
|
||||||
|
retention, finalization failures, and earlier intermediate release remain for
|
||||||
|
their explicitly scheduled follow-up work.
|
||||||
|
|
||||||
**Coverage:** CAT-006 structure; CAT-009/CAT-022 foundation.
|
**Coverage:** CAT-006 structure; CAT-009/CAT-022 foundation.
|
||||||
**Prerequisites:** Stages 12–14.
|
**Prerequisites:** Stages 12–14.
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ func TestRunnerMaterializesAndFullyAssessesEachNativePlanRevision(t *testing.T)
|
|||||||
profile.Chunk.Mode, profile.Chunk.MaxAdditionalTurns = &test.mode, &test.turns
|
profile.Chunk.Mode, profile.Chunk.MaxAdditionalTurns = &test.mode, &test.turns
|
||||||
profile.Chunk.Validators = ValidatorOverride{Set: true, Validators: []ModuleBinding{Binding("first-plan-policy"), Binding("second-plan-policy")}}
|
profile.Chunk.Validators = ValidatorOverride{Set: true, Validators: []ModuleBinding{Binding("first-plan-policy"), Binding("second-plan-policy")}}
|
||||||
profile.Artifacts = map[string]ArtifactLaneProfile{"notes": registerRunnerNotes(t, catalog, runnerNotesProducer{name: "notes", probe: probe})}
|
profile.Artifacts = map[string]ArtifactLaneProfile{"notes": registerRunnerNotes(t, catalog, runnerNotesProducer{name: "notes", probe: probe})}
|
||||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, engine), RawInput: []byte("input")})
|
output, err := New().run(context.Background(), RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, engine), RawInput: []byte("input")})
|
||||||
if (err != nil) != test.wantError || calls != test.turns+1 {
|
if (err != nil) != test.wantError || calls != test.turns+1 {
|
||||||
t.Fatalf("native plan output=%#v error=%v calls=%d", output, err, calls)
|
t.Fatalf("native plan output=%#v error=%v calls=%d", output, err, calls)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ func cloneDiagnosticSamples(samples []contracts.DiagnosticSample, chunk *source.
|
|||||||
return cloned
|
return cloned
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendDiagnosticGroups(output *RunOutput, groups []contracts.DiagnosticGroup) {
|
func appendDiagnosticGroups(output *runState, groups []contracts.DiagnosticGroup) {
|
||||||
if output == nil || len(groups) == 0 {
|
if output == nil || len(groups) == 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -75,7 +75,7 @@ func appendDiagnosticGroups(output *RunOutput, groups []contracts.DiagnosticGrou
|
|||||||
output.diagnosticGroups = append(output.diagnosticGroups, cloned...)
|
output.diagnosticGroups = append(output.diagnosticGroups, cloned...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func finalizeDiagnostics(output *RunOutput) error {
|
func finalizeDiagnostics(output *runState) error {
|
||||||
if output == nil {
|
if output == nil {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func TestRunnerRetainsManyDiagnosticGroups(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAppendDiagnosticGroupsRetainsOnlyStructuredDiagnostics(t *testing.T) {
|
func TestAppendDiagnosticGroupsRetainsOnlyStructuredDiagnostics(t *testing.T) {
|
||||||
output := RunOutput{}
|
output := runState{}
|
||||||
appendDiagnosticGroups(&output, []contracts.DiagnosticGroup{{
|
appendDiagnosticGroups(&output, []contracts.DiagnosticGroup{{
|
||||||
Disposition: contracts.DiagnosticDispositionAdvisory,
|
Disposition: contracts.DiagnosticDispositionAdvisory,
|
||||||
Category: contracts.DiagnosticCategoryDataQuality,
|
Category: contracts.DiagnosticCategoryDataQuality,
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ func TestRunnerWorkersAndNativeBackendAdmissionAreIndependent(t *testing.T) {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
done := make(chan error, 1)
|
done := make(chan error, 1)
|
||||||
go func() {
|
go func() {
|
||||||
output, err := New().Run(ctx, RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: limits.workers})
|
output, err := New().run(ctx, RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: limits.workers})
|
||||||
if err == nil && len(output.normalizeOutputs) != 2 {
|
if err == nil && len(output.normalizeOutputs) != 2 {
|
||||||
err = fmt.Errorf("got %d lane outputs", len(output.normalizeOutputs))
|
err = fmt.Errorf("got %d lane outputs", len(output.normalizeOutputs))
|
||||||
}
|
}
|
||||||
@@ -247,7 +247,7 @@ func TestRunnerNativeCapacityFailureUsesOperationModeWithoutAnotherQueue(t *test
|
|||||||
prepared.Steps[0].lanes[lane].resolved.ExtractControls = contracts.ProducerControls{Mode: mode, MaxAdditionalTurns: 2}
|
prepared.Steps[0].lanes[lane].resolved.ExtractControls = contracts.ProducerControls{Mode: mode, MaxAdditionalTurns: 2}
|
||||||
}
|
}
|
||||||
zero := 0
|
zero := 0
|
||||||
output, err := New().Run(ctx, RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: 1, Execution: contracts.ExecutionOptions{TransientRetries: &zero}})
|
output, err := New().run(ctx, RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: 1, Execution: contracts.ExecutionOptions{TransientRetries: &zero}})
|
||||||
if mode == contracts.ModeStrict {
|
if mode == contracts.ModeStrict {
|
||||||
var capacity *promptkit.CapacityError
|
var capacity *promptkit.CapacityError
|
||||||
if !errors.As(err, &capacity) || output.FallbackCount != 0 || len(output.OutputFiles) != 0 {
|
if !errors.As(err, &capacity) || output.FallbackCount != 0 || len(output.OutputFiles) != 0 {
|
||||||
@@ -289,7 +289,7 @@ func TestRunnerCancellationDrainsNativeWorkAndReleasesAdmission(t *testing.T) {
|
|||||||
defer cancel()
|
defer cancel()
|
||||||
done := make(chan error, 1)
|
done := make(chan error, 1)
|
||||||
go func() {
|
go func() {
|
||||||
output, err := New().Run(ctx, RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: 3})
|
output, err := New().run(ctx, RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: 3})
|
||||||
if output.FallbackCount != 0 || len(output.normalizeOutputs) != 0 {
|
if output.FallbackCount != 0 || len(output.normalizeOutputs) != 0 {
|
||||||
err = fmt.Errorf("cancellation delivered output: %v", err)
|
err = fmt.Errorf("cancellation delivered output: %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -75,7 +75,12 @@ type RunOutput struct {
|
|||||||
|
|
||||||
Diagnostics contracts.DiagnosticCollection `json:"diagnostics,omitempty"`
|
Diagnostics contracts.DiagnosticCollection `json:"diagnostics,omitempty"`
|
||||||
OutputFiles []contracts.OutputFile `json:"-"`
|
OutputFiles []contracts.OutputFile `json:"-"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// runState owns intermediate artifacts and diagnostic bookkeeping until the
|
||||||
|
// runner has produced its final logical result.
|
||||||
|
type runState struct {
|
||||||
|
RunOutput
|
||||||
normalizeOutputs []contracts.SerializedOutput
|
normalizeOutputs []contracts.SerializedOutput
|
||||||
normalizeReuseEligibility map[generatedOutputKey]bool
|
normalizeReuseEligibility map[generatedOutputKey]bool
|
||||||
diagnosticGroups []contracts.DiagnosticGroup
|
diagnosticGroups []contracts.DiagnosticGroup
|
||||||
@@ -87,7 +92,12 @@ func (output RunOutput) ArtifactCount() int {
|
|||||||
return len(output.OutputFiles)
|
return len(output.OutputFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err error) {
|
func (r *Runner) Run(ctx context.Context, input RunInput) (RunOutput, error) {
|
||||||
|
state, err := r.run(ctx, input)
|
||||||
|
return state.RunOutput, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Runner) run(ctx context.Context, input RunInput) (output runState, err error) {
|
||||||
if r == nil {
|
if r == nil {
|
||||||
return output, fmt.Errorf("runner must not be nil")
|
return output, fmt.Errorf("runner must not be nil")
|
||||||
}
|
}
|
||||||
@@ -356,7 +366,7 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
|||||||
return output, nil
|
return output, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) runPreparedSteps(ctx context.Context, input RunInput, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, chunks []source.Chunk, output *RunOutput) error {
|
func (r *Runner) runPreparedSteps(ctx context.Context, input RunInput, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, chunks []source.Chunk, output *runState) error {
|
||||||
for _, step := range input.Prepared.Steps {
|
for _, step := range input.Prepared.Steps {
|
||||||
stepInput := input
|
stepInput := input
|
||||||
stepInput.stepID = step.ID
|
stepInput.stepID = step.ID
|
||||||
@@ -459,10 +469,8 @@ func startedTime(t time.Time) time.Time {
|
|||||||
return t.UTC()
|
return t.UTC()
|
||||||
}
|
}
|
||||||
|
|
||||||
func failOutput(output RunOutput) RunOutput {
|
func failOutput(output runState) runState {
|
||||||
// Preserve any diagnostics already accepted by the pipeline when a later
|
// Attempt to preserve diagnostics accumulated before a later failure.
|
||||||
// operation fails. Producers and validators validate each diagnostic before
|
|
||||||
// it is appended, so finalization here cannot introduce a new failure path.
|
|
||||||
_ = finalizeDiagnostics(&output)
|
_ = finalizeDiagnostics(&output)
|
||||||
return output
|
return output
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ func TestRunnerChecksCurrentSourceOnConcurrentCacheHits(t *testing.T) {
|
|||||||
}
|
}
|
||||||
for run := 0; run < 2; run++ {
|
for run := 0; run < 2; run++ {
|
||||||
// The filesystem store is concurrency-safe; its counting test wrapper is not.
|
// The filesystem store is concurrency-safe; its counting test wrapper is not.
|
||||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepared, Cache: cache.inner, RawInput: []byte("input"), Workers: chunkCount})
|
output, err := New().run(context.Background(), RunInput{Prepared: prepared, Cache: cache.inner, RawInput: []byte("input"), Workers: chunkCount})
|
||||||
if err != nil || len(output.normalizeOutputs) != 2 {
|
if err != nil || len(output.normalizeOutputs) != 2 {
|
||||||
t.Fatalf("run %d: outputs=%d error=%v", run, len(output.normalizeOutputs), err)
|
t.Fatalf("run %d: outputs=%d error=%v", run, len(output.normalizeOutputs), err)
|
||||||
}
|
}
|
||||||
@@ -101,7 +101,7 @@ func TestRunnerReusesAcceptedPredecessorAfterDownstreamFailure(t *testing.T) {
|
|||||||
t.Fatalf("predecessor not stored before downstream failure: calls %d reads/writes %d/%d", calls, store.reads, store.writes)
|
t.Fatalf("predecessor not stored before downstream failure: calls %d reads/writes %d/%d", calls, store.reads, store.writes)
|
||||||
}
|
}
|
||||||
first = false
|
first = false
|
||||||
output, err := New().Run(context.Background(), input)
|
output, err := New().run(context.Background(), input)
|
||||||
if err != nil || len(output.normalizeOutputs) != 2 || calls != 1 || store.reads != 2 || store.writes != 1 || output.FallbackCount != 0 {
|
if err != nil || len(output.normalizeOutputs) != 2 || calls != 1 || store.reads != 2 || store.writes != 1 || output.FallbackCount != 0 {
|
||||||
t.Fatalf("rerun=%v outputs=%d calls=%d cache=%d/%d", err, len(output.normalizeOutputs), calls, store.reads, store.writes)
|
t.Fatalf("rerun=%v outputs=%d calls=%d cache=%d/%d", err, len(output.normalizeOutputs), calls, store.reads, store.writes)
|
||||||
}
|
}
|
||||||
@@ -129,7 +129,7 @@ func TestRunnerCacheWarningsDoNotFailSuccessfulPublication(t *testing.T) {
|
|||||||
catalog := typedResolutionCatalog(t, completeTypedCatalogOptions())
|
catalog := typedResolutionCatalog(t, completeTypedCatalogOptions())
|
||||||
profile := typedResolutionProfile()
|
profile := typedResolutionProfile()
|
||||||
profile.Artifacts = map[string]ArtifactLaneProfile{"notes": registerRunnerNotes(t, catalog, runnerNotesProducer{name: "native", probe: newRunnerProbe(), native: true})}
|
profile.Artifacts = map[string]ArtifactLaneProfile{"notes": registerRunnerNotes(t, catalog, runnerNotesProducer{name: "native", probe: newRunnerProbe(), native: true})}
|
||||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, engine), RawInput: []byte("input"), Cache: store, Workers: 1})
|
output, err := New().run(context.Background(), RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, engine), RawInput: []byte("input"), Cache: store, Workers: 1})
|
||||||
if err != nil || len(output.normalizeOutputs) != 1 || output.FallbackCount != 0 {
|
if err != nil || len(output.normalizeOutputs) != 1 || output.FallbackCount != 0 {
|
||||||
t.Fatalf("cache warnings failed successful work: %v, outputs=%d", err, len(output.normalizeOutputs))
|
t.Fatalf("cache warnings failed successful work: %v, outputs=%d", err, len(output.normalizeOutputs))
|
||||||
}
|
}
|
||||||
@@ -311,7 +311,7 @@ func TestRunnerCachesAppliedMergeAndNormalizationArtifacts(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for range 2 {
|
for range 2 {
|
||||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepared, Cache: store, RawInput: []byte("input"), Workers: 1})
|
output, err := New().run(context.Background(), RunInput{Prepared: prepared, Cache: store, RawInput: []byte("input"), Workers: 1})
|
||||||
if err != nil || len(output.normalizeOutputs) != 2 {
|
if err != nil || len(output.normalizeOutputs) != 2 {
|
||||||
t.Fatalf("cached %s execution: %v, outputs %d", role, err, len(output.normalizeOutputs))
|
t.Fatalf("cached %s execution: %v, outputs %d", role, err, len(output.normalizeOutputs))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ func TestRunnerIsolatesTypedValidatorCandidates(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input")})
|
output, err := New().run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input")})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Run() error = %v, want nil", err)
|
t.Fatalf("Run() error = %v, want nil", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ func TestRunnerExecutesOrderedStepsWithHardBarriers(t *testing.T) {
|
|||||||
return erasedTypedResult{Value: codecScore{Value: 2}}, nil
|
return erasedTypedResult{Value: codecScore{Value: 2}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: 2})
|
output, err := New().run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: 2})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Run() error = %v", err)
|
t.Fatalf("Run() error = %v", err)
|
||||||
}
|
}
|
||||||
@@ -286,7 +286,7 @@ func TestRunnerStopsLaterOrderedStepsAfterFailure(t *testing.T) {
|
|||||||
encoder := &countingOrderedOutput{}
|
encoder := &countingOrderedOutput{}
|
||||||
prepared.output = encoder
|
prepared.output = encoder
|
||||||
|
|
||||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: 2})
|
output, err := New().run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: 2})
|
||||||
if err == nil || !strings.Contains(err.Error(), `execute pipeline step "step-2"`) {
|
if err == nil || !strings.Contains(err.Error(), `execute pipeline step "step-2"`) {
|
||||||
t.Fatalf("Run() error = %v, want step-scoped failure", err)
|
t.Fatalf("Run() error = %v, want step-scoped failure", err)
|
||||||
}
|
}
|
||||||
@@ -486,7 +486,7 @@ func TestRunnerBoundsConcurrentLaneContinuations(t *testing.T) {
|
|||||||
prepared.Steps[0].ArtifactLanes = publicLanes
|
prepared.Steps[0].ArtifactLanes = publicLanes
|
||||||
|
|
||||||
type outcome struct {
|
type outcome struct {
|
||||||
output RunOutput
|
output runState
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
done := make(chan outcome, 1)
|
done := make(chan outcome, 1)
|
||||||
@@ -504,7 +504,7 @@ func TestRunnerBoundsConcurrentLaneContinuations(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
go func() {
|
go func() {
|
||||||
output, err := New().Run(ctx, RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: 2})
|
output, err := New().run(ctx, RunInput{Prepared: prepared, RawInput: []byte("input"), Workers: 2})
|
||||||
done <- outcome{output, err}
|
done <- outcome{output, err}
|
||||||
}()
|
}()
|
||||||
for i := 0; i < 2; i++ {
|
for i := 0; i < 2; i++ {
|
||||||
|
|||||||
@@ -50,10 +50,13 @@ type extractJobResult struct {
|
|||||||
|
|
||||||
type laneCompletion struct {
|
type laneCompletion struct {
|
||||||
index int
|
index int
|
||||||
output RunOutput
|
output laneOutput
|
||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// laneOutput is private intermediate state for one lane or step.
|
||||||
|
type laneOutput struct{ runState }
|
||||||
|
|
||||||
type orderedRunError struct {
|
type orderedRunError struct {
|
||||||
stage int
|
stage int
|
||||||
lane int
|
lane int
|
||||||
@@ -61,8 +64,8 @@ type orderedRunError struct {
|
|||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) runLanes(parent context.Context, input RunInput, step PreparedPipelineStep, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, chunks []source.Chunk) (RunOutput, error) {
|
func (r *Runner) runLanes(parent context.Context, input RunInput, step PreparedPipelineStep, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, chunks []source.Chunk) (laneOutput, error) {
|
||||||
output := RunOutput{}
|
output := laneOutput{}
|
||||||
states, err := initializeLaneStates(input, step, chunks)
|
states, err := initializeLaneStates(input, step, chunks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return output, err
|
return output, err
|
||||||
@@ -121,13 +124,13 @@ type laneEngine struct {
|
|||||||
results chan laneJobResult
|
results chan laneJobResult
|
||||||
workers sync.WaitGroup
|
workers sync.WaitGroup
|
||||||
pending []*laneExtractState
|
pending []*laneExtractState
|
||||||
completedOutputs []RunOutput
|
completedOutputs []laneOutput
|
||||||
runErrors []orderedRunError
|
runErrors []orderedRunError
|
||||||
nextExtract int
|
nextExtract int
|
||||||
active int
|
active int
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) runLaneEngine(parent context.Context, config laneEngineConfig) ([]RunOutput, []orderedRunError) {
|
func (r *Runner) runLaneEngine(parent context.Context, config laneEngineConfig) ([]laneOutput, []orderedRunError) {
|
||||||
engine := newLaneEngine(r, parent, config)
|
engine := newLaneEngine(r, parent, config)
|
||||||
return engine.run()
|
return engine.run()
|
||||||
}
|
}
|
||||||
@@ -141,11 +144,11 @@ func newLaneEngine(r *Runner, parent context.Context, config laneEngineConfig) *
|
|||||||
return &laneEngine{
|
return &laneEngine{
|
||||||
runner: r, laneEngineConfig: config, ctx: ctx, cancel: cancel, workerCount: workerCount,
|
runner: r, laneEngineConfig: config, ctx: ctx, cancel: cancel, workerCount: workerCount,
|
||||||
jobs: make(chan laneJob), results: make(chan laneJobResult, workerCount),
|
jobs: make(chan laneJob), results: make(chan laneJobResult, workerCount),
|
||||||
completedOutputs: make([]RunOutput, len(config.states)),
|
completedOutputs: make([]laneOutput, len(config.states)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *laneEngine) run() ([]RunOutput, []orderedRunError) {
|
func (e *laneEngine) run() ([]laneOutput, []orderedRunError) {
|
||||||
defer e.cancel()
|
defer e.cancel()
|
||||||
e.startWorkers()
|
e.startWorkers()
|
||||||
e.collect()
|
e.collect()
|
||||||
@@ -259,9 +262,9 @@ func (e *laneEngine) handleCompletion(completion laneCompletion) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func mergeCompletedLanes(output *RunOutput, completedOutputs []RunOutput) {
|
func mergeCompletedLanes(output *laneOutput, completedOutputs []laneOutput) {
|
||||||
for i := range completedOutputs {
|
for i := range completedOutputs {
|
||||||
mergeLaneOutput(output, completedOutputs[i])
|
mergeLaneOutput(&output.runState, completedOutputs[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,9 +338,9 @@ func finalizeLaneExtract(state *laneExtractState) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) continueLane(ctx context.Context, input RunInput, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, chunks []source.Chunk, state *laneExtractState) (RunOutput, 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) {
|
||||||
lane := state.prepared.resolved
|
lane := state.prepared.resolved
|
||||||
local := RunOutput{FallbackCount: state.fallbackCount}
|
local := laneOutput{runState: runState{RunOutput: RunOutput{FallbackCount: state.fallbackCount}}}
|
||||||
results := finalizedExtractResults{
|
results := finalizedExtractResults{
|
||||||
accepted: state.values,
|
accepted: state.values,
|
||||||
diagnostics: state.diagnostics,
|
diagnostics: state.diagnostics,
|
||||||
@@ -355,7 +358,7 @@ func (r *Runner) continueLane(ctx context.Context, input RunInput, doc *source.S
|
|||||||
if len(results.accepted) == 0 {
|
if len(results.accepted) == 0 {
|
||||||
return local, nil
|
return local, nil
|
||||||
}
|
}
|
||||||
err := r.continueTypedLane(ctx, input, doc, sourceInput, sessionID, state.prepared, results, &local)
|
err := r.continueTypedLane(ctx, input, doc, sourceInput, sessionID, state.prepared, results, &local.runState)
|
||||||
return local, err
|
return local, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,7 +418,7 @@ func isSiblingCancellation(err error) bool {
|
|||||||
return errors.Is(err, context.Canceled) && !errors.Is(err, promptkit.ErrOperationTimeout)
|
return errors.Is(err, context.Canceled) && !errors.Is(err, promptkit.ErrOperationTimeout)
|
||||||
}
|
}
|
||||||
|
|
||||||
func mergeLaneOutput(dst *RunOutput, src RunOutput) {
|
func mergeLaneOutput(dst *runState, src laneOutput) {
|
||||||
if dst == nil {
|
if dst == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ func TestRunnerPropagatesLaneFallbackWithoutCountingDependents(t *testing.T) {
|
|||||||
}
|
}
|
||||||
profile := typedResolutionProfile()
|
profile := typedResolutionProfile()
|
||||||
profile.Artifacts = map[string]ArtifactLaneProfile{"affected": affected, "unrelated": unrelated}
|
profile.Artifacts = map[string]ArtifactLaneProfile{"affected": affected, "unrelated": unrelated}
|
||||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, nil), RawInput: []byte("input"), Workers: 1})
|
output, err := New().run(context.Background(), RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, nil), RawInput: []byte("input"), Workers: 1})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -264,7 +264,7 @@ func TestRunnerAssessesNativeRevisionsWithoutOuterRevalidation(t *testing.T) {
|
|||||||
profile.LLMProfile = "chosen"
|
profile.LLMProfile = "chosen"
|
||||||
turns := 1
|
turns := 1
|
||||||
profile.MaxAdditionalTurns = &turns
|
profile.MaxAdditionalTurns = &turns
|
||||||
output, err := New().Run(context.Background(), RunInput{
|
output, err := New().run(context.Background(), RunInput{
|
||||||
Prepared: prepareRunnerProfile(t, catalog, profile, engine), RawInput: []byte("input"), SessionID: "runner-session",
|
Prepared: prepareRunnerProfile(t, catalog, profile, engine), RawInput: []byte("input"), SessionID: "runner-session",
|
||||||
Execution: contracts.ExecutionOptions{Execution: &promptkit.ExecutionTargetOverride{Model: "runner-model"}},
|
Execution: contracts.ExecutionOptions{Execution: &promptkit.ExecutionTargetOverride{Model: "runner-model"}},
|
||||||
})
|
})
|
||||||
@@ -298,7 +298,7 @@ func TestRunnerGeneratedFallbackReferencesTaintOnlyActualConsumers(t *testing.T)
|
|||||||
{ID: "build", Artifacts: map[string]ArtifactLaneProfile{"producer": producer, "earlier": earlier}},
|
{ID: "build", Artifacts: map[string]ArtifactLaneProfile{"producer": producer, "earlier": earlier}},
|
||||||
{ID: "consume", Artifacts: map[string]ArtifactLaneProfile{"consumer": consumer, "later": unrelated}},
|
{ID: "consume", Artifacts: map[string]ArtifactLaneProfile{"consumer": consumer, "later": unrelated}},
|
||||||
}
|
}
|
||||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, nil), RawInput: []byte("input"), Workers: 1})
|
output, err := New().run(context.Background(), RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, nil), RawInput: []byte("input"), Workers: 1})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -342,7 +342,7 @@ func TestRunnerChunkFallbackTaintsEveryDerivedOperation(t *testing.T) {
|
|||||||
permissive := contracts.ModePermissive
|
permissive := contracts.ModePermissive
|
||||||
profile.Chunk.Mode = &permissive
|
profile.Chunk.Mode = &permissive
|
||||||
profile.Artifacts = map[string]ArtifactLaneProfile{"notes": lane}
|
profile.Artifacts = map[string]ArtifactLaneProfile{"notes": lane}
|
||||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, nil), RawInput: []byte("input")})
|
output, err := New().run(context.Background(), RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, nil), RawInput: []byte("input")})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -380,7 +380,7 @@ func TestRunnerDoesNotAcceptModuleFallbackUnderStrictControls(t *testing.T) {
|
|||||||
profile := typedResolutionProfile()
|
profile := typedResolutionProfile()
|
||||||
profile.Chunk = Binding("fallback-chunk")
|
profile.Chunk = Binding("fallback-chunk")
|
||||||
profile.Artifacts = map[string]ArtifactLaneProfile{"notes": registerRunnerNotes(t, catalog, runnerNotesProducer{name: "notes", probe: probe})}
|
profile.Artifacts = map[string]ArtifactLaneProfile{"notes": registerRunnerNotes(t, catalog, runnerNotesProducer{name: "notes", probe: probe})}
|
||||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, nil), RawInput: []byte("input")})
|
output, err := New().run(context.Background(), RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, nil), RawInput: []byte("input")})
|
||||||
if err == nil || output.FallbackCount != 0 || len(output.normalizeOutputs) != 0 || probe.calls["notes/extract"] != 0 {
|
if err == nil || output.FallbackCount != 0 || len(output.normalizeOutputs) != 0 || probe.calls["notes/extract"] != 0 {
|
||||||
t.Fatalf("strict controls accepted module fallback: %#v %v", output, err)
|
t.Fatalf("strict controls accepted module fallback: %#v %v", output, err)
|
||||||
}
|
}
|
||||||
@@ -394,7 +394,7 @@ func TestRunnerDiscardsDeterministicOutputReturnedAfterCancellation(t *testing.T
|
|||||||
lane := registerRunnerNotes(t, catalog, runnerNotesProducer{name: "notes", probe: probe, cancel: cancel})
|
lane := registerRunnerNotes(t, catalog, runnerNotesProducer{name: "notes", probe: probe, cancel: cancel})
|
||||||
profile := typedResolutionProfile()
|
profile := typedResolutionProfile()
|
||||||
profile.Artifacts = map[string]ArtifactLaneProfile{"notes": lane}
|
profile.Artifacts = map[string]ArtifactLaneProfile{"notes": lane}
|
||||||
output, err := New().Run(ctx, RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, nil), RawInput: []byte("input")})
|
output, err := New().run(ctx, RunInput{Prepared: prepareRunnerProfile(t, catalog, profile, nil), RawInput: []byte("input")})
|
||||||
if !errors.Is(err, context.Canceled) || output.FallbackCount != 0 || len(output.normalizeOutputs) != 0 || probe.calls["notes/merge"] != 0 || probe.calls["notes/extract/fallback"] != 0 {
|
if !errors.Is(err, context.Canceled) || output.FallbackCount != 0 || len(output.normalizeOutputs) != 0 || probe.calls["notes/merge"] != 0 || probe.calls["notes/extract/fallback"] != 0 {
|
||||||
t.Fatalf("cancellation = %#v %v, calls %#v", output, err, probe.calls)
|
t.Fatalf("cancellation = %#v %v, calls %#v", output, err, probe.calls)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ type normalizeStageResult struct {
|
|||||||
reuseEligible bool
|
reuseEligible bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) continueTypedLane(ctx context.Context, input RunInput, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, prepared preparedLaneExecutor, extracts finalizedExtractResults, output *RunOutput) error {
|
func (r *Runner) continueTypedLane(ctx context.Context, input RunInput, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, prepared preparedLaneExecutor, extracts finalizedExtractResults, output *runState) error {
|
||||||
lane := prepared.resolved
|
lane := prepared.resolved
|
||||||
if prepared.typed == nil {
|
if prepared.typed == nil {
|
||||||
return fmt.Errorf("typed lane %q executor is not prepared", lane.ID)
|
return fmt.Errorf("typed lane %q executor is not prepared", lane.ID)
|
||||||
@@ -74,7 +74,7 @@ func (r *Runner) continueTypedLane(ctx context.Context, input RunInput, doc *sou
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) runMergeStage(ctx context.Context, input RunInput, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, prepared preparedLaneExecutor, extracts finalizedExtractResults, output *RunOutput) (state mergeStageResult, err error) {
|
func (r *Runner) runMergeStage(ctx context.Context, input RunInput, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, prepared preparedLaneExecutor, extracts finalizedExtractResults, output *runState) (state mergeStageResult, err error) {
|
||||||
lane, typed := prepared.resolved, prepared.typed
|
lane, typed := prepared.resolved, prepared.typed
|
||||||
references := operationReferenceSet(input, lane.MergeReferences)
|
references := operationReferenceSet(input, lane.MergeReferences)
|
||||||
state.reuseEligible = extracts.reuseEligible && !input.reuseIneligible && referenceTargetReuseEligible(input, lane.MergeReferences)
|
state.reuseEligible = extracts.reuseEligible && !input.reuseIneligible && referenceTargetReuseEligible(input, lane.MergeReferences)
|
||||||
@@ -134,7 +134,7 @@ func (r *Runner) runMergeStage(ctx context.Context, input RunInput, doc *source.
|
|||||||
return state, nil
|
return state, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Runner) runNormalizeStage(ctx context.Context, input RunInput, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, prepared preparedLaneExecutor, merged erasedMergeArtifact, upstreamReuseEligible bool, output *RunOutput) (state normalizeStageResult, err error) {
|
func (r *Runner) runNormalizeStage(ctx context.Context, input RunInput, doc *source.SourceDocument, sourceInput contracts.LLMInputMaterial, sessionID string, prepared preparedLaneExecutor, merged erasedMergeArtifact, upstreamReuseEligible bool, output *runState) (state normalizeStageResult, err error) {
|
||||||
lane, typed := prepared.resolved, prepared.typed
|
lane, typed := prepared.resolved, prepared.typed
|
||||||
references := operationReferenceSet(input, lane.NormalizeReferences)
|
references := operationReferenceSet(input, lane.NormalizeReferences)
|
||||||
state.reuseEligible = upstreamReuseEligible && !input.reuseIneligible && referenceTargetReuseEligible(input, lane.NormalizeReferences)
|
state.reuseEligible = upstreamReuseEligible && !input.reuseIneligible && referenceTargetReuseEligible(input, lane.NormalizeReferences)
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ func TestRunExecutesHeterogeneousTypedLanes(t *testing.T) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Prepare() error = %v", err)
|
t.Fatalf("Prepare() error = %v", err)
|
||||||
}
|
}
|
||||||
output, err := New().Run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte(`{"source":true}`), RunID: "typed-run"})
|
output, err := New().run(context.Background(), RunInput{Prepared: prepared, RawInput: []byte(`{"source":true}`), RunID: "typed-run"})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Run() error = %v", err)
|
t.Fatalf("Run() error = %v", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user