Separate runner working state from returned results
This commit is contained in:
@@ -75,7 +75,12 @@ type RunOutput struct {
|
||||
|
||||
Diagnostics contracts.DiagnosticCollection `json:"diagnostics,omitempty"`
|
||||
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
|
||||
normalizeReuseEligibility map[generatedOutputKey]bool
|
||||
diagnosticGroups []contracts.DiagnosticGroup
|
||||
@@ -87,7 +92,12 @@ func (output RunOutput) ArtifactCount() int {
|
||||
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 {
|
||||
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
|
||||
}
|
||||
|
||||
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 {
|
||||
stepInput := input
|
||||
stepInput.stepID = step.ID
|
||||
@@ -459,10 +469,8 @@ func startedTime(t time.Time) time.Time {
|
||||
return t.UTC()
|
||||
}
|
||||
|
||||
func failOutput(output RunOutput) RunOutput {
|
||||
// Preserve any diagnostics already accepted by the pipeline when a later
|
||||
// operation fails. Producers and validators validate each diagnostic before
|
||||
// it is appended, so finalization here cannot introduce a new failure path.
|
||||
func failOutput(output runState) runState {
|
||||
// Attempt to preserve diagnostics accumulated before a later failure.
|
||||
_ = finalizeDiagnostics(&output)
|
||||
return output
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user