opencode icon indicating copy to clipboard operation
opencode copied to clipboard

Fix reasoning-only replies and TODO continuation loops

Open salacoste opened this issue 2 months 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

The following comment was made by an LLM, it may be inaccurate:

No duplicate PRs found

github-actions[bot] avatar Jan 07 '26 12:01 github-actions[bot]

Hey! Your PR title Fix reasoning-only replies and TODO continuation loops doesn't follow conventional commit format.

Please update it to start with one of:

  • feat: or feat(scope): new feature
  • fix: or fix(scope): bug fix
  • docs: or docs(scope): documentation changes
  • chore: or chore(scope): maintenance tasks
  • refactor: or refactor(scope): code refactoring
  • test: or test(scope): adding or updating tests

Where scope is the package name (e.g., app, desktop, opencode).

See CONTRIBUTING.md for details.

github-actions[bot] avatar Jan 09 '26 17:01 github-actions[bot]

Closing this PR; we will keep and maintain these changes in our fork instead.

salacoste avatar Jan 09 '26 17:01 salacoste