Repository navigation
loop: progress ledger — goal anchor, todo checklist, resume summary (+ /v1/chat cap fix) - #412
Conversation
The observed failure on real coding tasks was goal drift: 50+ tool calls
of competent-looking exploration that never wrote the deliverable until a
human typed "you still haven't created the index.html". Nothing in the
loop pushed back -- the task statement scrolls out of focus, and only
`pasclaw build --goal` had any goal anchoring.
RunToolLoop now keeps a per-turn progress ledger:
* Goal anchor + fold (A1). From iteration 2 onward an ephemeral block
is appended to the system prompt: the goal (last substantive user
message -- trailing "continue" micro-turns are skipped), the files
written so far, and the model's own checklist. CACHE-STABLE by
design: no counters or volatiles, so consecutive iterations produce
a byte-identical system prompt and the provider prefix cache keeps
hitting; iteration 1 stays pristine to preserve the cross-turn hit.
* todo_write tool. The model maintains a markdown checklist; the loop
harvests it from the call's own arguments (no shared state -- each
gateway session / subagent child loop tracks its own) and folds it
back every turn. tcReadOnly so checklist upkeep never counts as
progress.
* Nothing-written nudge. After 8 tool calls with zero mutating calls,
the fold adds a sticky progress check: start writing, or give the
final answer. Plan mode is exempt.
* Resume summary (A2). On a max-iterations stop the full tally (files
written, commands + exit codes, files read by name) lands in
Loop.LedgerSummary and FormatMaxIterNotice appends it with "do NOT
redo any of it" -- so a "continue" resumes at the next step instead
of re-reading the same files. Rides in the notice (which lands in
carried-over history), so it needs no storage and works for CLI,
TUI and gateway alike.
* /v1/chat cap 8 -> FMaxIter (A3): the legacy endpoint now shares
/v1/chat/completions' 25-iteration default; --max-iter raises both.
Also hardens every RunToolLoop caller: gateway/TUI/agent/subagent built
TToolLoopConfig field-by-field on UNINITIALIZED stack records, so any
field a caller didn't set read stack garbage -- live-verified: the new
DisableProgressLedger Boolean came up True at random on the gateway and
silently switched the ledger off. All callers now Default()-init the
record first (heartbeat and the tests already did).
Opt-out: TToolLoopConfig.DisableProgressLedger for embedders/tests.
Tests: progress_ledger_tests -- fold from iteration 2 with goal/files/
checklist (and pristine iteration 1 + ephemeral restore), nudge fires
only past the threshold, max-iter summary + notice, micro-turn goal
skip, disable switch. Verified live through the relay harness: request
2's system prompt carries the folded goal + demo.html + checklist.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9d39167d2a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| can tell a resumed turn what NOT to redo. Default False = ledger | ||
| on everywhere (managed-record zero); embedders and tests that | ||
| want the pre-ledger prompt shape set True. *) | ||
| DisableProgressLedger: Boolean; |
There was a problem hiding this comment.
Initialize the ledger opt-out in every config builder
This new Boolean is read as an opt-out, but several existing TToolLoopConfig builders still assign fields one-by-one without defaulting or setting it, notably the main CLI BuildLoopConfig and the channel handlers. On those paths, if the stack/function-result slot contains a true value, RunToolLoop skips the progress ledger entirely, so the new goal/checklist/resume behavior silently disappears for CLI and channel turns. Please default-initialize or explicitly set this field in every config construction path, not only the gateway/TUI/component ones touched here.
Useful? React with 👍 / 👎.
…(review fix)
The Default-init pass missed two construction-path families:
* Cmd.Agent's BuildLoopConfig builds its RESULT field-by-field --
function results of record type are as uninitialized as locals, so
the main CLI path (one-shot, interactive, resume, runbook: all four
call sites copy from this builder) could read garbage in any unset
field, e.g. DisableProgressLedger flipping the ledger off at random.
* The seven channel handlers (Matrix, Email, LINE, Telegram, IRC,
WhatsApp, Discord) each hand-build a local LoopCfg starting at
.Identity -- same exposure per inbound message.
Both now Default(TToolLoopConfig) before population, matching the
gateway/TUI/component/subagent sites from the previous commit. Class-
field configs (TUI thread FCfg, SubagentBg box) are zero-initialized by
object allocation and the gateway's LocalCfg is a whole-record copy, so
those paths were already safe.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
Why
The observed failure on real coding tasks (the pasclaw.dev build transcript) was goal drift: 50+ tool calls of competent-looking exploration that never wrote the deliverable until a human typed "you still haven't created the index.html" — and after every max-iter "continue", the model restarted exploration (re-
list_dir, re-read the same files) instead of resuming. Nothing in the loop pushed back; onlypasclaw build --goalhad any goal anchoring.What
RunToolLoopnow keeps a per-turn progress ledger:continue/yesmicro-turns are skipped), the files written so far, and the model's own checklist. Cache-stable by design: no counters or volatiles, so consecutive iterations produce a byte-identical system prompt and the provider prefix cache keeps hitting; iteration 1 stays pristine to preserve the cross-turn hit.todo_writetool. The model maintains a markdown checklist (- [ ]/- [x]); the loop harvests it from the call's own arguments — no shared state, so concurrent gateway sessions and subagent child loops each track their own — and folds it back every turn.tcReadOnly, so checklist upkeep never counts as progress.Loop.LedgerSummary, andFormatMaxIterNoticeappends it with "do NOT redo any of it when continuing". It rides in the notice — which lands in the assistant turn and therefore in carried-over history — so it needs no storage and works identically for CLI, TUI and gateway./v1/chatcap 8 →FMaxIter(A3). The legacy endpoint now shares/v1/chat/completions' 25-iteration default;--max-iter/max_iterationsraise both.Bonus hardening (found live)
Gateway/TUI/agent/subagent built
TToolLoopConfigfield-by-field on uninitialized stack records, so any field a caller didn't explicitly set read stack garbage. Live-verified: the newDisableProgressLedgerBoolean came up True at random on the gateway and silently switched the feature off — the same latent trap applied toToolOutputCapand every other plain field added since the record's creation. All callers nowDefault()-init the record first (heartbeat and the tests already did).Opt-out for embedders/tests:
TToolLoopConfig.DisableProgressLedger.Tests
progress_ledger_tests(new, inmake test): fold appears from iteration 2 with goal/files/checklist while iteration 1 stays pristine andFinalSystemPromptis restored (ephemeral); nudge fires at 9 read-only calls and not at 6; max-iter stop fillsLedgerSummaryand the notice carries the do-not-redo block; goal extraction skips a trailing "continue"; the disable switch works. Regression sweep green (max-iter-notice, subagent-default/bg, plan-build-mode, autoroute-apply, toolview, fs-tool-naming, workspace-paths, gateway-token, session-endpoints, loop-shaping).Verified live through the relay harness: on a real gateway run, request 2's system prompt carries:
🤖 Generated with Claude Code
https://claude.ai/code/session_01LGQKz579j1ZnDRwmr6h1V6
Generated by Claude Code