[PR #8134] fix(opencode): improve tool robustness and session loop stability #12629

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

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

State: open
Merged: No


This PR significantly improves the reliability and robustness of the AI agent execution loop by addressing three common failure modes where the agent appears to get "stuck" or "idle" without completing its task:

  1. Robust Tool Parameter Handling: Makes the description field optional in the bash and task tools. Many models (especially in fast or direct modes - gemini) omit this field, previously triggering Zod validation errors
    that halted execution. Added smart fallbacks (using the command string or "Task") and improved error formatting for tool validation.
  2. Explicit Feedback for Empty Results: Modifies the bash and list tools to return clear strings like (Command executed successfully with no output) or (No files found in directory) instead of empty results. This
    prevents models from interpreting silence as an environment failure or a signal to stop.
  3. Refined Session Loop Exit Logic: Updates SessionPrompt.ts to prevent premature loop exits. The loop now only terminates if the assistant has provided a real text response to the user or if no tool calls were
    made in the turn. Previously, the loop would exit purely based on the provider's finishReason: "stop", which often occurs after tool-only turns before the model has a chance to summarize or reply.

How did you verify your code works?

  1. Replication & Log Analysis: Reproduced the "stuck" behavior in a live environment and analyzed the dev.log to confirm that the session was exiting with finish=stop while the message content was still empty
    (tool-only turns).
  2. Live Testing: Applied the fixes and verified that opencode successfully continued the loop to provide final summaries after multiple turns of tool calls (e.g., after running ls or git remote -v).
  3. Schema Validation: Confirmed that omitting the description parameter in bash tool calls no longer triggers a validation error and uses the command string as a fallback.
  4. Build Verification: Built a single native binary using bun run build --single and verified the versioned binary functions correctly on Linux x64.
  5. Type Safety: Ran bun turbo typecheck across the monorepo and resolved strict TypeScript errors related to ZodError property access in the new validation logic. █

Fixes https://github.com/anomalyco/opencode/issues/6244
Fixes https://github.com/anomalyco/opencode/issues/6838

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/8134 **State:** open **Merged:** No --- This PR significantly improves the reliability and robustness of the AI agent execution loop by addressing three common failure modes where the agent appears to get "stuck" or "idle" without completing its task: 1. Robust Tool Parameter Handling: Makes the description field optional in the bash and task tools. Many models (especially in fast or direct modes - **gemini**) omit this field, previously triggering Zod validation errors that halted execution. Added smart fallbacks (using the command string or "Task") and improved error formatting for tool validation. 2. Explicit Feedback for Empty Results: Modifies the bash and list tools to return clear strings like (Command executed successfully with no output) or (No files found in directory) instead of empty results. This prevents models from interpreting silence as an environment failure or a signal to stop. 3. Refined Session Loop Exit Logic: Updates SessionPrompt.ts to prevent premature loop exits. The loop now only terminates if the assistant has provided a real text response to the user or if no tool calls were made in the turn. Previously, the loop would exit purely based on the provider's finishReason: "stop", which often occurs after tool-only turns before the model has a chance to summarize or reply. How did you verify your code works? 1. Replication & Log Analysis: Reproduced the "stuck" behavior in a live environment and analyzed the dev.log to confirm that the session was exiting with finish=stop while the message content was still empty (tool-only turns). 2. Live Testing: Applied the fixes and verified that opencode successfully continued the loop to provide final summaries after multiple turns of tool calls (e.g., after running ls or git remote -v). 3. Schema Validation: Confirmed that omitting the description parameter in bash tool calls no longer triggers a validation error and uses the command string as a fallback. 4. Build Verification: Built a single native binary using bun run build --single and verified the versioned binary functions correctly on Linux x64. 5. Type Safety: Ran bun turbo typecheck across the monorepo and resolved strict TypeScript errors related to ZodError property access in the new validation logic. █ Fixes https://github.com/anomalyco/opencode/issues/6244 Fixes https://github.com/anomalyco/opencode/issues/6838
yindo added the pull-request label 2026-02-16 18:17:31 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12629