fix server retry memory input override ordering
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
# Retry memory input override ordering
|
||||
|
||||
On 2026-10-18, selected-stage retry input overrides are persisted separately
|
||||
from the immutable source-stage input. Retry reconstruction now resolves the
|
||||
selected stage's memory bindings from the original prefix first, then applies
|
||||
the validated override once to that invocation. This keeps the persisted
|
||||
`run_steps.input` and downstream handoff aligned with the requested correction
|
||||
without changing the source history or unrelated later stages.
|
||||
|
||||
The shared retry documentation and packaged OpenCode skill reference should be
|
||||
folded by the manual `docs-fold` pipeline; this note records the behavior change
|
||||
without editing those shared documents.
|
||||
@@ -289,6 +289,7 @@ func TestRetryResumeReusesPrefixHandoffAndReplaysRequestAfterReopen(t *testing.T
|
||||
t.Fatal(err)
|
||||
}
|
||||
source := "# stage a\n\n```output\nA\n```\n\n```prompt\nA\n```\n\n```edges\nsuccess -> b\nerror -> #failure\n```\n\n```configs\ntype=model\nprovider=test\nmodel=test\n```\n\n# stage b\n\n```output\nB\n```\n\n```prompt\nB\n```\n\n```edges\nsuccess -> c\nerror -> #failure\n```\n\n```configs\ntype=model\nprovider=test\nmodel=test\n```\n\n# stage c\n\n```output\nC\n```\n\n```prompt\nC\n```\n\n```edges\nsuccess -> #success\nerror -> #failure\n```\n\n```configs\ntype=model\nprovider=test\nmodel=test\n```\n"
|
||||
source = strings.Replace(source, "# stage b\n\n```output", "# stage b\n\n```memory\n{\"task\":\"input.prompt\",\"handoff\":\"a.handoff\"}\n```\n\n```output", 1)
|
||||
if _, err := store.Submit(ctx, "resume", source); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -312,6 +313,13 @@ func TestRetryResumeReusesPrefixHandoffAndReplaysRequestAfterReopen(t *testing.T
|
||||
if input["handoff"] != "from-a" {
|
||||
t.Errorf("resume lost exact prefix handoff: %#v", input)
|
||||
}
|
||||
wantTask := "task"
|
||||
if bCalls == 2 {
|
||||
wantTask = "corrected"
|
||||
}
|
||||
if input["task"] != wantTask {
|
||||
t.Errorf("selected retry memory input = %#v, want task %q", input["task"], wantTask)
|
||||
}
|
||||
if bCalls == 2 && input["correction"] != "use-new-plan" {
|
||||
t.Errorf("selected retry lost input override: %#v", input)
|
||||
}
|
||||
@@ -339,7 +347,7 @@ func TestRetryResumeReusesPrefixHandoffAndReplaysRequestAfterReopen(t *testing.T
|
||||
if err != nil || original.Status != "failed" || len(original.Steps) != 2 {
|
||||
t.Fatalf("initial run did not stop at B: %+v %v", original, err)
|
||||
}
|
||||
retried, err := r.retry(protocol.Message{RunID: original.ID, RequestKey: "resume-key", RetryStage: "b", RetryInput: map[string]any{"correction": "use-new-plan"}})
|
||||
retried, err := r.retry(protocol.Message{RunID: original.ID, RequestKey: "resume-key", RetryStage: "b", RetryInput: map[string]any{"task": "corrected", "correction": "use-new-plan"}})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -354,6 +362,9 @@ func TestRetryResumeReusesPrefixHandoffAndReplaysRequestAfterReopen(t *testing.T
|
||||
if len(retried.Steps) != 2 || retried.Steps[0].Stage != "b" || retried.Steps[1].Stage != "c" {
|
||||
t.Fatalf("retry persisted the wrong steps: %+v", retried.Steps)
|
||||
}
|
||||
if retried.Steps[0].Input["task"] != "corrected" || retried.Steps[0].Input["correction"] != "use-new-plan" {
|
||||
t.Fatalf("retry persisted the wrong selected input: %#v", retried.Steps[0].Input)
|
||||
}
|
||||
if err := store.Close(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -519,11 +519,13 @@ func (r *runner) retrySourceCheckpointSelected(sourceID int64, pinned *protocol.
|
||||
if failed.Input == nil {
|
||||
return retryCheckpoint{}, fmt.Errorf("retry source %d is missing failed-stage handoff context", sourceID)
|
||||
}
|
||||
selectedInput, err := retryInputOverride(failed.Input, override)
|
||||
if err != nil {
|
||||
if _, err := retryInputOverride(failed.Input, override); err != nil {
|
||||
return retryCheckpoint{}, err
|
||||
}
|
||||
handoff = map[string]any{"input": selectedInput, "sequence": failed.Sequence, "stage": failed.Stage, "visit": failed.Sequence}
|
||||
// Keep the source-stage input immutable in the checkpoint. The selected
|
||||
// stage's memory bindings must be resolved from the original prefix before
|
||||
// this override is applied at invocation time.
|
||||
handoff = map[string]any{"input": failed.Input, "override": override, "sequence": failed.Sequence, "stage": failed.Stage, "visit": failed.Sequence}
|
||||
prefix := map[string]any{}
|
||||
for _, step := range source.Steps {
|
||||
if step.Sequence >= failed.Sequence || step.Status != "completed" {
|
||||
@@ -774,6 +776,9 @@ func (r *runner) run(ctx context.Context, id int64, d *protocol.PipelineDetail,
|
||||
return
|
||||
}
|
||||
state := rebuildRetryState(source, checkpoint.failed)
|
||||
if override, ok := storedHandoff["override"].(map[string]any); ok {
|
||||
state.retryOverride = stage.Values(override)
|
||||
}
|
||||
r.runLoop(ctx, id, d.Graph, d.Name, workspace, request, state)
|
||||
return
|
||||
}
|
||||
@@ -852,6 +857,9 @@ type runState struct {
|
||||
// running total without re-reading the store.
|
||||
completed int
|
||||
artifactDirs []string
|
||||
// retryOverride is applied once, after the selected stage's memory bindings
|
||||
// have been resolved. It is intentionally not part of run input or memory.
|
||||
retryOverride stage.Values
|
||||
}
|
||||
|
||||
func newRunState(key string, input stage.Values) *runState {
|
||||
@@ -1269,6 +1277,16 @@ func (r *runner) runLoop(ctx context.Context, id int64, graph protocol.Graph, na
|
||||
finish("failed", "error", copyErr.Error())
|
||||
return
|
||||
}
|
||||
if state.retryOverride != nil {
|
||||
input, copyErr = retryInputOverride(input, state.retryOverride)
|
||||
if copyErr != nil {
|
||||
finish("failed", "error", copyErr.Error())
|
||||
return
|
||||
}
|
||||
// A selected-stage override belongs only to this invocation, not to
|
||||
// a later visit reached through the stage graph.
|
||||
state.retryOverride = nil
|
||||
}
|
||||
if err := r.store.BeginStep(ctx, id, sequence, key, input); err != nil {
|
||||
if ctx.Err() != nil {
|
||||
finish("canceled", "", ctx.Err().Error())
|
||||
|
||||
Reference in New Issue
Block a user