← Back to Pull requests

fix(agent-core-v2): coerce string-typed tool arguments at the parse boundary #2175

Closed
unknown closed this pull request without merging on Aug 25, 2026 09:43 UTC
View on GitHub
unknown unknown commented on Jul 25, 2026 04:08 UTC
Author

Related Issue

Resolve #2118

Problem

Some third-party models emit tool-call arguments as JSON strings ("3") instead of the declared JSON types (3) — reported in the linked issue on 0.29.0 with Qwen. The arguments are decoded faithfully and validated strictly, so the call is rejected with Invalid args for tool ... and the turn stalls, even though the model's intent is unambiguous.

What changed

The fix sits at the tool-call parse boundary — the earliest point the harness controls — and keeps validation itself strict. Two moves, as discussed in the issue:

1. A normalization layer before validation. It is generic and bounded by design, so it stays a single schema-driven rule rather than growing into a catalog of model-specific hacks: only lossless string → integer / number / boolean coercions, only when the schema does not already accept strings at that position; $ref nodes and ambiguous schemas are left untouched.

2. A warning that keeps the provider's violation visible. Coerced calls succeed, but the tool result carries a model-visible note (rendered to the model at projection time, never shown in UIs) describing exactly what was coerced — the non-conforming output is absorbed without being silently hidden.

When coercion cannot fix the arguments, the rejection now says what actually arrived (e.g. /line_offset must be integer (received string "3")) so the model can self-correct, and duplicate type errors from union branches are deduplicated.

Scope: the v2 engine only, which is what the current CLI runs on. The v1 engine has an isomorphic parse/validate path; happy to mirror the change there if the team wants both covered.

Tests: unit coverage for the normalization rules and the new error wording, plus executor integration tests covering coercion with the warning note, note merging with the tool's own note, honest rejection, and clean passthrough. Roughly half of the +571/−11 diff is tests.

Checklist

  • I have read the CONTRIBUTING document.

  • I have linked a related issue, or explained the problem above.

  • I have added tests that prove my feature works.

  • Ran gen-changesets skill, or this PR needs no changeset.

  • Ran gen-docs skill, or this PR needs no doc update.
  • Diff: 295 lines (+221 / -74) across 3 files Reviewer: HelloWorldU Review duration: 44975m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.40) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.40 · 295 lines diff across 3 files
    0.40
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.340
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #2175"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 40.0% (MEDIUM) · Higher = larger blast radius
    40.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 17.3% · Safe to merge
    17.3%