fix(opencode): stop repeated cross-turn tool loops - #165
Open
robertelee78 wants to merge 1 commit into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why this belongs in Agentic Kit
OpenCode 1.18.18 checks for repeated tool calls only among parts attached to the current assistant message. A normal tool result starts another assistant continuation, so the same completed call can repeat across assistant messages without reaching the native detector. Interleaved reasoning or text can also mask its same-message tail check.
This is not an hf2q inference responsibility: the server does not reliably know whether OpenCode executed a tool or what result the client delivered. Agentic Kit already owns and receipt-deploys the OpenCode lifecycle adapter through
ak sync, and that adapter observes user turns plustool.execute.beforeandtool.execute.after. It is therefore the narrow, upgrade-resistant place for an immediate compatibility guard while OpenCode core remains unchanged.Native detector source: https://github.com/anomalyco/opencode/blob/v1.18.18/packages/opencode/src/session/processor.ts
The open upstream proposal scans matching calls across the whole compacted history, which would also count legitimate nonconsecutive calls. This guard intentionally does not copy that behavior: anomalyco/opencode#32089
Behavior
The session abort is deliberately fail-closed because the fourth execution may repeat a side effect. This can stop an intentional polling loop if it returns the exact same output three times; changing output or beginning a new user turn resets the guard. The workaround should be removable after OpenCode ships an equivalent turn-scoped, tested core fix.
Changes
ruflo-hooks.jstemplate.Validation
node --test tests/kit/opencode-hooks.test.mjspnpm run typecheckpnpm run lintpnpm run build