fix(turns): keep the run task in every stage's input
Later visits' input.md held only the previous stage's output, so the operator's task reached only the first stage; when a Prepare stage summarised (paths, HEAD), Code never saw the task or its acceptance checklist and either blocked (run #202) or did part of it (#195, #197, #198). Later inputs now carry the run prompt under '# Run task' (headings demoted) before '# Previous turn output'.
This commit is contained in:
+3
-2
@@ -662,8 +662,9 @@ files as that step's artifacts:
|
||||
<artifacts>/<run>/public/
|
||||
```
|
||||
|
||||
`input.md` is the run prompt on the first visit and the previous visit's output
|
||||
body (without its outcome section) afterwards. `memory.md` is the accumulated markdown of completed turns plus the
|
||||
`input.md` is the run prompt on the first visit; later visits carry the run
|
||||
prompt under `# Run task` followed by the previous visit's output body (without
|
||||
its outcome section) under `# Previous turn output`. `memory.md` is the accumulated markdown of completed turns plus the
|
||||
files each turn added to the shared `public/` directory. A text-only stage (an
|
||||
explicit empty `tools` block) receives both files' contents in its prompt
|
||||
instead, because it has no file-reading tool. The model returns the complete
|
||||
|
||||
@@ -16,8 +16,10 @@ Every model visit gets its own directory under the run's artifact root:
|
||||
<artifacts>/<run>/public/
|
||||
```
|
||||
|
||||
- `input.md` is the run prompt on the first visit and the previous visit's body
|
||||
after that, under a `# Previous turn output` heading.
|
||||
- `input.md` is the run prompt on the first visit. Later visits keep the run
|
||||
prompt under a `# Run task` heading (its own headings demoted two levels) and
|
||||
add the previous visit's body under a `# Previous turn output` heading, so
|
||||
every stage sees what the run is for even when an earlier stage summarised.
|
||||
- `memory.md` is one `## <stage> · visit <n>` section per completed turn: the
|
||||
turn body followed by a system-written, sorted list of the files that turn
|
||||
added to `public/`.
|
||||
|
||||
@@ -15,9 +15,11 @@ the run's artifact root:
|
||||
zero-padded to two digits). `Paths.Ensure` creates the turn, private and public
|
||||
directories idempotently; it never deletes or rewrites existing files.
|
||||
|
||||
`input.md` is the run prompt on the first visit and the previous visit's output
|
||||
body (without the outcome section) under a `# Previous turn output` heading
|
||||
afterwards. `memory.md` is plain
|
||||
`input.md` is the run prompt on the first visit. Afterwards it is the run
|
||||
prompt under a `# Run task` heading (headings demoted two levels) followed by
|
||||
the previous visit's output body (without the outcome section) under a
|
||||
`# Previous turn output` heading. Carrying the task forward means a stage that
|
||||
only summarised its own work is never the sole carrier of what the run is for. `memory.md` is plain
|
||||
markdown: one `## <stage> · visit <n>` section per completed turn, with that
|
||||
turn's body — its own ATX headings demoted two levels, so the turn heading stays
|
||||
the structural one — followed by a system-written list of files it added to
|
||||
|
||||
@@ -57,7 +57,7 @@ explicitly asks to manage a schedule; scheduling alone is not workflow authoring
|
||||
|
||||
## Turns and artifacts
|
||||
|
||||
Each visit has `input.md` (the run prompt or previous body), `memory.md`
|
||||
Each visit has `input.md` (the run prompt; later visits add the previous body), `memory.md`
|
||||
(completed turns), `output.md`, and `private/`. Every run also has one shared
|
||||
`public/` directory, addressed by its absolute path; files there are visible to
|
||||
later stages and are the stage's real artifacts. `input.md`, `memory.md`,
|
||||
|
||||
@@ -89,8 +89,8 @@ func TestTurnsAccumulateMemoryAndListFilesAsArtifacts(t *testing.T) {
|
||||
if detail.Status != "succeeded" || len(detail.Steps) != 2 {
|
||||
t.Fatalf("run = %q steps=%d: %+v", detail.Status, len(detail.Steps), detail.RunSummary)
|
||||
}
|
||||
if secondInput != "# Previous turn output\n\nfirst body\n" {
|
||||
t.Fatalf("second input.md = %q, want the previous turn's output", secondInput)
|
||||
if secondInput != "# Run task\n\noriginal task\n\n# Previous turn output\n\nfirst body\n" {
|
||||
t.Fatalf("second input.md = %q, want the run task and the previous turn's output", secondInput)
|
||||
}
|
||||
for _, want := range []string{"## first · visit 1", "first body", "Files added to public/:\n- public/shared.txt"} {
|
||||
if !strings.Contains(secondMemory, want) {
|
||||
|
||||
@@ -89,16 +89,16 @@ func turnInputWithRetry(base string, retryInput stage.Values) string {
|
||||
return base + "\n# Retry input\n\nThis retry was given this complete input:\n\n```json\n" + string(encoded) + "\n```\n"
|
||||
}
|
||||
|
||||
// turnInput is the run prompt on the first visit and the previous visit's
|
||||
// output afterwards.
|
||||
// turnInput is the run prompt on the first visit; later visits carry the run
|
||||
// prompt and the previous visit's output.
|
||||
func (s *runState) turnInput() string {
|
||||
if len(s.turns) == 0 && strings.TrimSpace(s.lastOutput) == "" {
|
||||
return s.prompt
|
||||
}
|
||||
if strings.TrimSpace(s.lastOutput) == "" {
|
||||
return "# Previous turn output\n\n_(no output)_\n"
|
||||
return turn.RenderInput(s.prompt, "_(no output)_\n")
|
||||
}
|
||||
return turn.RenderInput("", s.lastOutput)
|
||||
return turn.RenderInput(s.prompt, s.lastOutput)
|
||||
}
|
||||
|
||||
// turnOutput renders a completed step for later memory. Model stages store their
|
||||
|
||||
+10
-4
@@ -6,14 +6,20 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// RenderInput renders the markdown a turn receives. The first turn receives the
|
||||
// run prompt as-is. Later turns receive the previous turn's output verbatim
|
||||
// under a heading; prompt is not repeated.
|
||||
// RenderInput is a visit's input.md: the run prompt on the first visit, and on
|
||||
// later visits the run prompt under "# Run task" followed by the previous
|
||||
// visit's body under "# Previous turn output". Every stage keeps the operator's
|
||||
// task: a stage that summarised its own work must not be the only carrier of
|
||||
// what the run is for.
|
||||
func RenderInput(prompt string, previousOutput string) string {
|
||||
if strings.TrimSpace(previousOutput) == "" {
|
||||
return prompt
|
||||
}
|
||||
return "# Previous turn output\n\n" + previousOutput
|
||||
if strings.TrimSpace(prompt) == "" {
|
||||
return "# Previous turn output\n\n" + previousOutput
|
||||
}
|
||||
task := strings.TrimRight(prompt, "\n")
|
||||
return "# Run task\n\n" + demoteHeadings(task) + "\n\n# Previous turn output\n\n" + previousOutput
|
||||
}
|
||||
|
||||
// MemoryEntry is one completed turn in a later turn's memory file. Output is
|
||||
|
||||
@@ -15,15 +15,16 @@ func TestRenderInputFirstTurnIsTheRunPrompt(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderInputLaterTurnShowsOnlyPreviousOutput(t *testing.T) {
|
||||
func TestRenderInputLaterTurnKeepsTheTaskAndThePreviousOutput(t *testing.T) {
|
||||
previous := "## Result\n\n- changed `internal/turn`\n\n```diff\n+new line\n```\n"
|
||||
got := RenderInput("the original prompt", previous)
|
||||
want := "# Previous turn output\n\n" + previous
|
||||
got := RenderInput("# Goal\n\nThe original prompt.\n", previous)
|
||||
want := "# Run task\n\n### Goal\n\nThe original prompt.\n\n# Previous turn output\n\n" + previous
|
||||
if got != want {
|
||||
t.Fatalf("later turn input = %q, want %q", got, want)
|
||||
}
|
||||
if strings.Contains(got, "the original prompt") {
|
||||
t.Fatal("later turn input repeated the run prompt")
|
||||
// Without a recorded prompt the previous output stands alone.
|
||||
if got := RenderInput("", previous); got != "# Previous turn output\n\n"+previous {
|
||||
t.Fatalf("promptless later input = %q", got)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user