Skip to content

Conversation

@ostapus
Copy link

@ostapus ostapus commented Jan 13, 2026

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 #6244
Fixes #6838

mtv added 5 commits January 12, 2026 23:42
- Make 'description' optional in BashTool and TaskTool with smart fallbacks to prevent validation errors.
- Provide explicit feedback for empty outputs in BashTool and ListTool (e.g., '(No files found)') to prevent model confusion.
- Refine session loop exit condition: only stop if the model provides text or makes no tool calls, preventing premature exits on 'stop' finish reasons during tool-only turns.
- Add enhanced logging for session lifecycle and tool execution debugging.
@github-actions
Copy link
Contributor

Hey! Your PR title Fix/tool robustness and loop exit 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
Copy link
Contributor

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

Based on my search, I found one potentially related PR:

PR #1333: fix: make description parameter optional in bash tool
#1333

This PR is relevant because it addresses the same issue mentioned in the current PR (PR #8134) - making the description field optional in the bash tool. However, PR #1333 appears to be older and may be a partial fix for one of the three issues addressed in the current PR.

The current PR #8134 is a more comprehensive fix that builds upon this by also handling:

  • Better error formatting for tool validation
  • Explicit feedback for empty results in bash and list tools
  • Refined session loop exit logic in SessionPrompt.ts to prevent premature exits

Conclusion: PR #1333 is related but not a duplicate—it's addressing one component that the current PR (8134) handles more comprehensively as part of a larger robustness improvement initiative.

@ostapus ostapus changed the title Fix/tool robustness and loop exit fix(opencode): improve tool robustness and session loop stability Jan 13, 2026
@github-actions
Copy link
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@ostapus ostapus force-pushed the fix/tool-robustness-and-loop-exit branch from d6bdebe to a3b3de6 Compare January 13, 2026 07:50
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.

Tool.edit should recieve json object Response terminates prematurely when using Gemini 3 via LiteLLM

1 participant