Separate runner working state from returned results
This commit is contained in:
@@ -50,10 +50,13 @@ type extractJobResult struct {
|
||||
|
||||
type laneCompletion struct {
|
||||
index int
|
||||
output RunOutput
|
||||
output laneOutput
|
||||
err error
|
||||
}
|
||||
|
||||
// laneOutput is private intermediate state for one lane or step.
|
||||
type laneOutput struct{ runState }
|
||||
|
||||
type orderedRunError struct {
|
||||
stage int
|
||||
lane int
|
||||
@@ -61,8 +64,8 @@ type orderedRunError struct {
|
||||
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) {
|
||||
output := RunOutput{}
|
||||
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 := laneOutput{}
|
||||
states, err := initializeLaneStates(input, step, chunks)
|
||||
if err != nil {
|
||||
return output, err
|
||||
@@ -121,13 +124,13 @@ type laneEngine struct {
|
||||
results chan laneJobResult
|
||||
workers sync.WaitGroup
|
||||
pending []*laneExtractState
|
||||
completedOutputs []RunOutput
|
||||
completedOutputs []laneOutput
|
||||
runErrors []orderedRunError
|
||||
nextExtract 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)
|
||||
return engine.run()
|
||||
}
|
||||
@@ -141,11 +144,11 @@ func newLaneEngine(r *Runner, parent context.Context, config laneEngineConfig) *
|
||||
return &laneEngine{
|
||||
runner: r, laneEngineConfig: config, ctx: ctx, cancel: cancel, workerCount: 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()
|
||||
e.startWorkers()
|
||||
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 {
|
||||
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
|
||||
local := RunOutput{FallbackCount: state.fallbackCount}
|
||||
local := laneOutput{runState: runState{RunOutput: RunOutput{FallbackCount: state.fallbackCount}}}
|
||||
results := finalizedExtractResults{
|
||||
accepted: state.values,
|
||||
diagnostics: state.diagnostics,
|
||||
@@ -355,7 +358,7 @@ func (r *Runner) continueLane(ctx context.Context, input RunInput, doc *source.S
|
||||
if len(results.accepted) == 0 {
|
||||
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
|
||||
}
|
||||
|
||||
@@ -415,7 +418,7 @@ func isSiblingCancellation(err error) bool {
|
||||
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 {
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user