opencode
opencode copied to clipboard
Fix reasoning-only replies and TODO continuation loops
Summary
This PR fixes two user-facing regressions observed in OpenCode sessions:
- Responses that only contain reasoning/tool output resulted in no visible final answer.
- Sessions with pending TODOs could loop indefinitely even when the user did not request continuation.
What changed
1) Final-response fallback for reasoning/tool-only replies
- Detects assistant messages that finish without visible text but contain reasoning/tool parts.
- Enqueues a synthetic user message and routes it through a hidden
finalagent with tools disabled. - Ensures a plain-text final response is returned.
2) TODO continuation loop guard
- Adds
todo_statetracking (paused/updatedAt/lastUpdatedMessageID). - Pauses automatic TODO continuation unless the user explicitly asks to continue.
- Clears pause on
todowriteupdates and injects a short system guard when paused.
3) Supporting updates
- Added documentation for both fixes.
- Adjusted a Bun test to avoid
test.concurrent(not supported by Bun).
Files touched (high level)
-
packages/opencode/src/session/prompt.ts -
packages/opencode/src/session/llm.ts -
packages/opencode/src/session/todo.ts -
packages/opencode/src/tool/todo.ts -
packages/opencode/src/agent/agent.ts -
packages/opencode/src/agent/prompt/final.txt -
packages/opencode/test/session/retry.test.ts -
docs/changes-2026-01-07.md -
docs/reasoning-only-fallback-plan.md -
docs/todo-loop-guard.md
Tests
-
bun test(packages/opencode) -
bun turbo typecheck(pre-push hook)
Notes
- The TODO guard is server-side; UI changes are not required.
- The fallback uses a hidden
finalagent with tools disabled to avoid recursive tool calls.