[PR #7201] Fix reasoning-only replies and TODO continuation loops #12295

Closed
opened 2026-02-16 18:17:13 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/7201

State: closed
Merged: No


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.
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/7201 **State:** closed **Merged:** No --- ## 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.
yindo added the pull-request label 2026-02-16 18:17:13 -05:00
yindo closed this issue 2026-02-16 18:17:13 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12295