fix(runs): encode agent prompts and action input with sorted keys (#2083)

This commit is contained in:
sam committed 2026-11-21 14:53:36 +11:00
1 parent 7b6154e7e8
commit 1989948ab3
4 files changed
+6 -4

No files matched your search

+2 -1
View File
@@ -503,7 +503,8 @@ func followThrough(rc *Context, judge Judge, decls []connectors.Declaration, inp
if len(missed) == 0 {
return res, nil
}
prompt, err := json.Marshal(map[string]any{"event": input, "findings": res.Answer, "described_but_not_called": missed})
// The prompt is part of the journaled request digest, so its key order must be the same on replay.
prompt, err := json.Marshal(map[string]any{"event": input, "findings": res.Answer, "described_but_not_called": missed}, json.Deterministic(true))
if err != nil {
return res, err
}
+2 -1
View File
@@ -86,7 +86,8 @@ func recordCause(rc *Context, mem Memory, input jsontext.Value, res AgentResult,
if !res.Completed {
return nil
}
prompt, err := json.Marshal(map[string]any{"event": input, "findings": res.Answer})
// The prompt is part of the journaled request digest, so its key order must be the same on replay.
prompt, err := json.Marshal(map[string]any{"event": input, "findings": res.Answer}, json.Deterministic(true))
if err != nil {
return err
}
+1 -1
View File
@@ -230,7 +230,7 @@ func stringify(value any) string {
case string:
return v
default:
encoded, err := json.Marshal(v)
encoded, err := json.Marshal(v, json.Deterministic(true))
if err != nil {
return fmt.Sprint(v)
}
+1 -1
View File
@@ -206,7 +206,7 @@ func runAction(d Deps, rc *Context, p *progress, name string, s actionSettings)
if input == nil {
input = map[string]any{}
}
in, err := json.Marshal(input)
in, err := json.Marshal(input, json.Deterministic(true))
if err != nil {
return StepResult{}, fmt.Errorf("step %q: encode input: %w", name, err)
}