Repository navigation
Description
OpenCodeReview Version
v1.9.8 (latest release). Affected range: v1.9.3 through v1.9.8. The grace round was introduced in da972b2; v1.9.2 and earlier predate it.
Operating System
macOS (Apple Silicon)
Installation Method
Built from source
LLM Provider
Other OpenAI-compatible endpoint
The deterministic reproduction uses a scripted client, so the defect is not provider-specific.
Bug Description
When a file exhausts its tool-call budget, RunPerFile makes a final grace-round LLM request limited to code_comment and task_done.
If the model calls task_done(DONE) in that round, the tool call is parsed and executed, but its completion state is discarded. RunPerFile returns completed=false, so scan/review callers record the file as incomplete rather than persisting a reusable review_item_done checkpoint. A later ocr resume then re-runs a file that the model explicitly marked complete.
Steps to Reproduce
- Configure a test template with
MaxToolRequestTimes=1. - Return a valid context-tool call in the first LLM response so the budget is exhausted.
- Return
task_donewith{"state":"DONE"}in the grace-round response. - Observe that
RunPerFilereturns(completed=false, StopMaxRounds, nil). - Run the same flow through scan mode, finalize the session, then load it with
LoadResumeState. - Observe that no completed checkpoint is available and a resumed scan invokes the LLM again for the unchanged file.
This can be reproduced deterministically with a scripted LLM client; no API key is required.
Expected Behavior
A task_done(DONE) executed in the grace round should propagate completion through RunPerFile. Scan/review should persist review_item_done, and a later resume should reuse the unchanged file without another LLM request.
Logs / Error Output
main_task did not complete before stoppingAdditional Context
Root cause in v1.9.8:
internal/llmloop/loop.go:377-381invokesrunGraceRoundafterStopMaxRoundsand then unconditionally returnscompleted=false.internal/llmloop/loop.go:432-434executes grace-round tool calls but discards each returnedTaskCheckpoint.task_done(DONE)returnsTaskCheckpoint{Completed: true}, but that state never reaches scan/review checkpoint persistence.
The grace round still records its LLM response and executes side effects such as code_comment; only the terminal completion state is lost.
Activity
JasonBuildAI commentedon Oct 9, 2026
I'd like to take this one.
I re-checked current
mainand the defect is still present:runGraceRound(internal/llmloop/loop.go) discards theTaskCheckpointreturned byexecuteToolCall, andRunMainTaskreturns(false, stop, nil)after the grace round, so atask_done(DONE)issued there never reaches the caller. A file the model explicitly marked complete is therefore recorded as incomplete -- scan persistsreview_item_failedinstead of a reusablereview_item_done, andocr resumere-runs it.Plan: have
runGraceRoundreport whether it completed and propagate that fromRunMainTask, leaving theStopEmptyRounds/StopCompressionpaths untouched, plus unit tests for a completing and a non-completing grace round.Disclosure: this work is being prepared with AI assistance (Codex, GPT-5-based coding agent). I understand and have reviewed every change myself before submitting it.
fix(llmloop): count a grace-round task_done as completion
fix(llmloop): count a grace-round task_done as completion (alibaba#1678)