Skip to content

Stop empty assistant turns from spinning Loop forever - #146

Merged
ByBrawe merged 15 commits into
mainfrom
fix/empty-assistant-turn-loop
Aug 27, 2026
Merged

Stop empty assistant turns from spinning Loop forever#146
ByBrawe merged 15 commits into
mainfrom
fix/empty-assistant-turn-loop

Conversation

@ByBrawe

@ByBrawe ByBrawe commented Aug 27, 2026

Copy link
Copy Markdown
Owner

Problem

A real OpenCode session repeatedly completed assistant turns with no visible text or tool activity. The Loop treated each completed timestamp as a successful iteration, immediately injected the next autonomous continuation, and could churn indefinitely.

Fix

  • Distinguish a merely completed assistant message from a meaningful completed Loop turn.
  • Treat non-empty assistant text and tool/file/patch/artifact activity anywhere in the logical run as meaningful work.
  • Classify a completed assistant run with no meaningful activity as empty.
  • Let host-busy recovery settle an empty completed turn so finalization can handle it instead of waiting forever.
  • Refund an empty logical run: restore runCount, lastRunAt, and a provisionally consumed --max-runs slot.
  • Persist consecutive emptyTurnCount so restart/reload does not erase the safety streak.
  • Retry one empty turn with the normal bounded busy delay, then pause after the second consecutive empty completion with a visible warning instead of spinning forever.
  • Do not run normal success verification/checkpoint finalization for empty turns.
  • Reset the empty-turn streak after a meaningful completed turn.
  • Preserve tool-only work: a run that used a tool and ended with a blank assistant tail is still meaningful.

Regression coverage

New scripts/empty-turn-recovery-test.mjs covers blank/whitespace replies, text/tool activity, tool-then-blank tails, stale busy recovery, max-run refund/re-enable, one retry, second-empty pause, no success checkpoint on empty turns, and streak reset after real work.

The full source check + test suite passed on Node 24, the committed single-file src/index.js bundle was regenerated, node --check src/index.js passed, and the focused empty-turn recovery suite passed again against the generated bundle source head.

Temporary implementation workflows/scripts used to create and validate the patch were removed; the final diff contains only product/runtime/tests/bundle changes.

Copilot AI lite review requested due to automatic review settings August 27, 2026 00:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@ByBrawe
ByBrawe merged commit ab50296 into main Aug 27, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants