opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Fix reasoning-only replies and TODO continuation loops

Open salacoste opened this issue 1 week ago • 1 comments

Summary

This PR fixes two user-facing regressions observed in OpenCode sessions:

  1. Responses that only contain reasoning/tool output resulted in no visible final answer.
  2. 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 final agent with tools disabled.
  • Ensures a plain-text final response is returned.

2) TODO continuation loop guard

  • Adds todo_state tracking (paused/updatedAt/lastUpdatedMessageID).
  • Pauses automatic TODO continuation unless the user explicitly asks to continue.
  • Clears pause on todowrite updates 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 final agent with tools disabled to avoid recursive tool calls.

salacoste avatar Jan 07 '26 12:01 salacoste