Skip to content

fix(opencode): honor OPENCODE_TOOL_CHOICE on live SessionPrompt path - #15

Merged
TimothyVang merged 1 commit into
mainfrom
agent/m23-tool-discipline
Jul 9, 2026
Merged

fix(opencode): honor OPENCODE_TOOL_CHOICE on live SessionPrompt path#15
TimothyVang merged 1 commit into
mainfrom
agent/m23-tool-discipline

Conversation

@TimothyVang

Copy link
Copy Markdown
Owner

Summary

m19 (#14) forced tool_choice: required only on the V2 SessionRunner. Live verdict run (what caseforge investigate spawns) still goes through SessionPrompt, which ignored OPENCODE_TOOL_CHOICE / VERDICT_FORCE_TOOL_CHOICE and only set required for json_schema turns.

This residual still showed up as intermittent invalid tool-name loops / timeouts on m20 even when caseforge exported the force flags.

Changes

  • Shared resolveAgentToolChoice() used by both V2 runner and SessionPrompt
    • non-final + flag/required → required
    • max-steps final → none (early stop)
    • structured-output → required
  • Unknown/invalid tool errors now include available tool names so models can self-correct faster
  • Tests lock flag → choice resolution and V2 request toolChoice: required

Not claimed

  • Does not guarantee agent seal every run (model discipline / timeouts can still force fallback)
  • Does not invent nhc-003 SCHARDT content

Test plan

  • packages/core typecheck
  • packages/opencode typecheck
  • bun test test/tool-choice-flag.test.ts test/tool-choice-resolve.test.ts test/session-runner-tool-registry.test.ts
  • bun test test/session-runner.test.ts -t "forces tool_choice required|durably settles local tool failures|forces a text response"
  • bun test test/application-tools.test.ts

m19 only forced tool_choice on the V2 SessionRunner. caseforge investigate
uses `verdict run` → SessionPrompt, which ignored the flag. Shared
resolveAgentToolChoice now drives both paths (required on non-final steps,
none on max-steps exit). Unknown/invalid tool errors list available names
so weak models can self-correct instead of looping until timeout.
@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

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.

@github-actions

github-actions Bot commented Jul 9, 2026

Copy link
Copy Markdown

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e516d7ce2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

readonly isLastStep: boolean
readonly structuredRequired?: boolean
}): "auto" | "required" | "none" | undefined {
if (input.isLastStep) return "none"

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve required tool choice for structured output

When a JSON-schema response runs on an agent's final allowed step (for example steps: 1, or after tool continuations consume the step budget), this returns none before checking structuredRequired. The live SessionPrompt path still adds the StructuredOutput tool and later treats a normal text finish as StructuredOutputError, so these requests can no longer succeed even though they previously forced toolChoice: "required" for all json_schema turns.

Useful? React with 👍 / 👎.

@TimothyVang
TimothyVang merged commit 1c284c8 into main Jul 9, 2026
9 of 10 checks passed
@TimothyVang
TimothyVang deleted the agent/m23-tool-discipline branch July 9, 2026 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant