Keep raw runtime parameters out of early capture

This commit is contained in:
2026-11-28 16:12:52 +00:00
parent 63cdd7a7c5
commit 95d46c7da3
6 changed files with 127 additions and 3 deletions

View File

@@ -130,7 +130,7 @@ and report delivery. See [preflight operation](../operations.md#preflight-lifecy
[Debug selection](../../internal/cli/run_debug.go) preserves native boolean and [Debug selection](../../internal/cli/run_debug.go) preserves native boolean and
supplied directory semantics independently of verbosity. Run and explicit preflight supplied directory semantics independently of verbosity. Run and explicit preflight
calls [debug.Start](../../internal/framework/debug/recorder.go). call [debug.Start](../../internal/framework/debug/recorder.go).
[Bundle allocation](../../internal/core/debugbundle/bundle.go) validates identity, [Bundle allocation](../../internal/core/debugbundle/bundle.go) validates identity,
creates a new absolute per-run directory, and atomically updates a relative creates a new absolute per-run directory, and atomically updates a relative
latest link at start. Failure can return an available directory for explanation/ latest link at start. Failure can return an available directory for explanation/
@@ -147,6 +147,10 @@ fallback directory. Available files are retained.
## Native And Application Evidence ## Native And Application Evidence
Both invocation owners share early context capture. It records provider-parameter
override presence rather than raw maps; effective parameters remain in native
evidence with selected-target sensitivity marks applied.
[Run capture](../../internal/cli/run_capture.go) snapshots the original secret-aware [Run capture](../../internal/cli/run_capture.go) snapshots the original secret-aware
application/PromptKit configuration. The runner selects the explicit evidence application/PromptKit configuration. The runner selects the explicit evidence
writer when provided, otherwise enabled debug, and writes original and parsed writer when provided, otherwise enabled debug, and writes original and parsed

View File

@@ -118,6 +118,12 @@ snapshot tests or additional upstream-library documentation are needed.
## Finding 3: Apply Existing Sensitive-Parameter Handling To Invocation Context ## Finding 3: Apply Existing Sensitive-Parameter Handling To Invocation Context
**Status: Complete.** Both commands use shared early context capture that omits
raw provider-parameter maps. Raw operation-request evidence uses the same
projection; target-aware native evidence still retains masked effective values.
Regression tests scan both commands' captures on success and early failure,
verify actual provider values are unchanged, and retain ordinary settings.
**Priority:** P2 — integration with the established capture contract. **Priority:** P2 — integration with the established capture contract.
Related plan stages: 1, 4, and 7. Related plan stages: 1, 4, and 7.

View File

@@ -0,0 +1,86 @@
package cli
import (
"bytes"
"context"
"encoding/json"
"os"
"path/filepath"
"strings"
"testing"
"time"
"go.maximumdirect.net/commandkit"
"go.maximumdirect.net/promptkit"
)
func TestInvocationCaptureOmitsMarkedRuntimeParameters(t *testing.T) {
for _, command := range []string{"run", "preflight"} {
for _, earlyFailure := range []bool{false, true} {
name := command + "/success"
if earlyFailure {
name = command + "/early-failure"
}
t.Run(name, func(t *testing.T) {
probe := &runProbe{}
_, configPath, inputPath, _ := runFixture(t, probe, func(configuration string) string {
return strings.Replace(configuration, " prompts:", " extra_params: {token: configured-placeholder}\n prompts:", 1)
})
if earlyFailure {
inputPath += "-missing"
}
calls := 0
client := captureClient(func(ctx context.Context, request promptkit.GenerateRequest) (*promptkit.GenerateResponse, error) {
calls++
if request.Target.ExtraParams["token"] != "runtime-private-placeholder" || request.Target.ExtraParams["caption"] != "ordinary-runtime-caption" {
t.Fatal("capture mutated execution parameters")
}
if productionSchemaHasProperty(request, "status") {
return &promptkit.GenerateResponse{Content: `{"status":"ok"}`}, nil
}
return probe.Generate(ctx, request)
})
app, err := NewApplication("test", Options{Registries: runRegistries(t, probe), LLMClient: client, RunIDGenerator: func(time.Time) (string, error) { return "capture", nil }})
if err != nil {
t.Fatal(err)
}
root := t.TempDir()
var out, stderr bytes.Buffer
outcome := app.Execute(context.Background(), []string{command, "demo", "--config", configPath, "--input-file", inputPath, "--llm-profile", "chosen", "--llm-extra-params", `{"token":"runtime-private-placeholder","caption":"ordinary-runtime-caption"}`, "--cache", "bypass", "--debug", "--debug-dir", root, "--format", "json"}, commandkit.Streams{Out: &out, Err: &stderr})
if (outcome.Status != 0) != earlyFailure || earlyFailure && calls != 0 {
t.Fatalf("outcome=%+v calls=%d stderr=%s", outcome, calls, stderr.String())
}
if !earlyFailure {
var report map[string]any
if err := json.Unmarshal(out.Bytes(), &report); err != nil || calls == 0 {
t.Fatalf("report error=%v calls=%d", err, calls)
}
}
ordinaryRetained := false
err = filepath.WalkDir(root, func(path string, entry os.DirEntry, err error) error {
if err != nil {
return err
}
if !entry.Type().IsRegular() {
return nil
}
content, err := os.ReadFile(path)
if err != nil {
return err
}
if bytes.Contains(content, []byte("runtime-private-placeholder")) {
t.Errorf("marked runtime parameter retained in %s", path)
}
ordinaryRetained = ordinaryRetained || bytes.Contains(content, []byte("ordinary-runtime-caption"))
return nil
})
if err != nil {
t.Fatal(err)
}
if !earlyFailure && !ordinaryRetained {
t.Fatal("ordinary effective parameters were lost")
}
})
}
}
}

View File

@@ -104,7 +104,7 @@ func executePreflight(invocation commandkit.Invocation, input pipelineRunInput,
return finish(commandkit.Failure(err.Error()).WithCause(err)) return finish(commandkit.Failure(err.Error()).WithCause(err))
} }
add("debug", preflightScope{Path: capture.Path()}, "passed", "Debug capture is accessible.") add("debug", preflightScope{Path: capture.Path()}, "passed", "Debug capture is accessible.")
if err := capture.WriteJSON("context.json", map[string]any{"application_version": version, "pipeline": input.PipelineID, "input_path": input.InputFile.Value, "run_id": runID, "started_at": startedAt, "lanes": input.Lanes, "references": input.References, "unbinds": input.Unbinds, "resources": input.Overrides.Resources, "execution_overrides": input.Overrides.Execution}); err != nil { if err := captureInvocationContext(capture, input, version, runID, startedAt); err != nil {
add("debug", preflightScope{Path: capture.Path()}, "failed", err.Error()) add("debug", preflightScope{Path: capture.Path()}, "failed", err.Error())
return finish(commandkit.Failure(err.Error()).WithCause(err)) return finish(commandkit.Failure(err.Error()).WithCause(err))
} }

View File

@@ -64,7 +64,7 @@ func (run *runInvocation) execute() commandkit.Outcome {
run.group = &promptkit.ExecutionGroup{} run.group = &promptkit.ExecutionGroup{}
ctx = promptkit.WithExecutionObserver(ctx, run.group.Observe) ctx = promptkit.WithExecutionObserver(ctx, run.group.Observe)
} }
if err := run.capture.WriteJSON("context.json", map[string]any{"application_version": version, "pipeline": input.PipelineID, "input_path": input.InputFile.Value, "run_id": runID, "started_at": startedAt, "lanes": input.Lanes, "resources": input.Overrides.Resources, "execution_overrides": input.Overrides.Execution}); err != nil { if err := captureInvocationContext(run.capture, input, version, runID, startedAt); err != nil {
return run.finish(commandkit.Failure(err.Error()).WithCause(err)) return run.finish(commandkit.Failure(err.Error()).WithCause(err))
} }
if err := captureRunConfiguration(run.capture, result); err != nil { if err := captureRunConfiguration(run.capture, result); err != nil {

View File

@@ -7,6 +7,7 @@ import (
"slices" "slices"
"strconv" "strconv"
"strings" "strings"
"time"
"gitea.maximumdirect.net/eric/notarius/internal/core/config" "gitea.maximumdirect.net/eric/notarius/internal/core/config"
frameworkdebug "gitea.maximumdirect.net/eric/notarius/internal/framework/debug" frameworkdebug "gitea.maximumdirect.net/eric/notarius/internal/framework/debug"
@@ -15,6 +16,30 @@ import (
"go.maximumdirect.net/promptkit" "go.maximumdirect.net/promptkit"
) )
// Target-aware native evidence retains effective parameters with their secret
// marks. Early context records presence only, before a target is available.
func captureInvocationContext(recorder *frameworkdebug.Recorder, input pipelineRunInput, version, runID string, startedAt time.Time) error {
if !recorder.Enabled() {
return nil
}
execution := input.Overrides.Execution
extraParamsSupplied := false
if execution.Execution != nil {
extraParamsSupplied = execution.Execution.ExtraParams != nil
execution.Execution = captureExecutionOverride(execution.Execution)
}
return recorder.WriteJSON("context.json", map[string]any{"application_version": version, "pipeline": input.PipelineID, "input_path": input.InputFile.Value, "run_id": runID, "started_at": startedAt, "lanes": input.Lanes, "references": input.References, "unbinds": input.Unbinds, "resources": input.Overrides.Resources, "execution_overrides": execution, "extra_params_supplied": extraParamsSupplied})
}
func captureExecutionOverride(execution *promptkit.ExecutionTargetOverride) *promptkit.ExecutionTargetOverride {
if execution == nil {
return nil
}
copy := *execution
copy.ExtraParams = nil
return &copy
}
// captureRunConfiguration inspects the original, frozen application load. It // captureRunConfiguration inspects the original, frozen application load. It
// neither reloads resources nor serializes typed settings containing credentials. // neither reloads resources nor serializes typed settings containing credentials.
// Shared loaders remain independent of run storage. // Shared loaders remain independent of run storage.
@@ -107,6 +132,9 @@ func newRunEvidenceRecorder(recorder *frameworkdebug.Recorder, result *configkit
func (writer *runEvidenceRecorder) WriteJSON(name string, payload any) error { func (writer *runEvidenceRecorder) WriteJSON(name string, payload any) error {
switch value := payload.(type) { switch value := payload.(type) {
case promptkit.RunRequest:
value.Execution = captureExecutionOverride(value.Execution)
payload = value
case *promptkit.PreparedRun: case *promptkit.PreparedRun:
copy := *value copy := *value
copy.EffectiveModelParams = writer.target(copy.EffectiveModelParams, copy.SelectedProfileID, copy.SelectedBackendID) copy.EffectiveModelParams = writer.target(copy.EffectiveModelParams, copy.SelectedProfileID, copy.SelectedBackendID)