Capture native execution facts and complete scoped debug evidence
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"fmt"
|
||||
"mime"
|
||||
"path"
|
||||
@@ -14,6 +15,7 @@ import (
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/core/source"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/chunkmap"
|
||||
"gitea.maximumdirect.net/eric/notarius/internal/framework/contracts"
|
||||
"go.maximumdirect.net/promptkit"
|
||||
)
|
||||
|
||||
type Registries struct {
|
||||
@@ -44,15 +46,18 @@ type RunInput struct {
|
||||
// on a hit. Shared observers must synchronize concurrent calls.
|
||||
ObserveCache func(context.Context, contracts.DiagnosticOrigin, contracts.CacheObservation) error
|
||||
Execution contracts.ExecutionOptions
|
||||
Prepared *PreparedPipeline
|
||||
SourceID string
|
||||
Path string
|
||||
RawInput []byte
|
||||
SessionID string
|
||||
RunID string
|
||||
StartedAt time.Time
|
||||
Metadata map[string]any
|
||||
Diagnostics []contracts.ProducerDiagnostic
|
||||
// Executions is the invocation's native group. The runner enrolls its
|
||||
// requests; callers may use Snapshot without maintaining copied totals.
|
||||
Executions *promptkit.ExecutionGroup
|
||||
Prepared *PreparedPipeline
|
||||
SourceID string
|
||||
Path string
|
||||
RawInput []byte
|
||||
SessionID string
|
||||
RunID string
|
||||
StartedAt time.Time
|
||||
Metadata map[string]any
|
||||
Diagnostics []contracts.ProducerDiagnostic
|
||||
|
||||
Debug DebugRecorder
|
||||
// Workers bounds ready extraction and lane-completion jobs together.
|
||||
@@ -107,12 +112,24 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
||||
}
|
||||
debugRecorder = synchronizedDebugRecorder(debugRecorder)
|
||||
input.Debug = debugRecorder
|
||||
if input.Executions == nil {
|
||||
input.Executions = &promptkit.ExecutionGroup{}
|
||||
}
|
||||
input.Execution.Observer = promptkit.ComposeObservers(input.Execution.Observer, input.Executions.Observe)
|
||||
defer func() {
|
||||
if debugRecorder.Enabled() {
|
||||
if captureErr := debugRecorder.WriteJSON("executions.json", input.Executions.Snapshot()); captureErr != nil {
|
||||
err = errors.Join(err, &contracts.CaptureError{Cause: captureErr})
|
||||
output = failOutput(output)
|
||||
}
|
||||
}
|
||||
}()
|
||||
inputDiagnostics, diagnosticErr := promoteProducerDiagnostics(input.Diagnostics, contracts.DiagnosticOrigin{Stage: contracts.DiagnosticOriginStageReferences}, nil)
|
||||
if diagnosticErr != nil {
|
||||
return failOutput(output), fmt.Errorf("promote input diagnostics: %w", diagnosticErr)
|
||||
}
|
||||
appendDiagnosticGroups(&output, inputDiagnostics)
|
||||
if err := writeDebugTimed(debugRecorder, "run.json", debugTimedEnvelope{
|
||||
if err := writeDebugTimed(debugRecorder, "pipeline.json", debugTimedEnvelope{
|
||||
Stage: "run",
|
||||
StartedAt: startedTime(input.StartedAt),
|
||||
Payload: map[string]any{
|
||||
@@ -123,6 +140,11 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
||||
}); err != nil {
|
||||
return failOutput(output), fmt.Errorf("write debug run artifact: %w", err)
|
||||
}
|
||||
if debugRecorder.Enabled() {
|
||||
if err := debugRecorder.WriteJSON("composition.json", captureComposition(input.pipeline)); err != nil {
|
||||
return failOutput(output), &contracts.CaptureError{Cause: err}
|
||||
}
|
||||
}
|
||||
|
||||
adapter := input.Prepared.input
|
||||
var doc *source.SourceDocument
|
||||
@@ -135,8 +157,7 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
||||
SourceID: input.SourceID,
|
||||
Path: input.Path,
|
||||
Raw: debugContentEnvelope(input.RawInput, sourceInputMediaType(input.Path), nil, nil),
|
||||
Options: redactSensitiveMap(input.pipeline.Input.Options),
|
||||
Metadata: redactSensitiveMap(input.Metadata),
|
||||
Metadata: input.Metadata,
|
||||
},
|
||||
}); err != nil {
|
||||
return failOutput(output), fmt.Errorf("write source debug artifact: %w", err)
|
||||
@@ -184,8 +205,7 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
||||
"cache_mode": input.pipeline.ChunkControls.Cache,
|
||||
"source": debugSourceDocumentEnvelope(doc),
|
||||
"source_input": debugContentEnvelope(sourceInput.Content, sourceInput.MediaType, nil, nil),
|
||||
"options": redactSensitiveMap(input.pipeline.Chunk.Options),
|
||||
"metadata": redactSensitiveMap(input.Metadata),
|
||||
"metadata": input.Metadata,
|
||||
},
|
||||
}); err != nil {
|
||||
return failOutput(output), fmt.Errorf("write chunk debug artifact: %w", err)
|
||||
@@ -282,8 +302,7 @@ func (r *Runner) Run(ctx context.Context, input RunInput) (output RunOutput, err
|
||||
}
|
||||
outputDebugPayload := map[string]any{
|
||||
"normalize_outputs": debugSerializedOutputEnvelopes(output.normalizeOutputs),
|
||||
"options": redactSensitiveMap(input.pipeline.Output.Options),
|
||||
"metadata": redactSensitiveMap(input.Metadata),
|
||||
"metadata": input.Metadata,
|
||||
}
|
||||
if acceptedChunkMap != nil {
|
||||
outputDebugPayload["chunk_map"] = debugSerializedOutputEnvelope(contracts.SerializedOutput{Artifact: *acceptedChunkMap})
|
||||
|
||||
Reference in New Issue
Block a user