← Back to Pull requests

feat(agent): add resource limits and local $ref expansion to tool argument validation (T31) #151

Closed
unknown closed this pull request without merging on Oct 12, 2026 13:49 UTC
View on GitHub
unknown unknown commented on Oct 12, 2026 02:18 UTC
Author

Describe what this PR does / why we need it

Follow-up to #149 (the first part of T31, already merged): adds the items that PR
explicitly left for a second change — resource limits and $ref handling — so the
validator rejects oversized / over-deep payloads explicitly and never loads remote
references or recurses unboundedly on hostile schemas.

Does this pull request fix one issue?

Fixes #134

Describe how you did it

All changes are confined to ToolArgumentValidator plus its tests; the opt-in gate
wiring from #149 is untouched.

Resource limits (fail-closed, constants at the top of the validator):

  • MAX_ARGUMENTS_BYTES = 64 KiB — checked on the raw UTF-8 payload before parsing

  • (ARGUMENTS_TOO_LARGE).
  • MAX_DEPTH = 64 — one depth counter shared by the arguments/schema traversal, so

  • neither hostile arguments nor hostile schemas can recurse unboundedly
    (DEPTH_EXCEEDED).
  • MAX_COLLECTION_SIZE = 1_000 — array length and object property count

  • (COLLECTION_TOO_LARGE).

    $ref: local expansion instead of silent skip (behavior change vs #149; the gate is
    opt-in, so no default behavior shifts):

  • #/... pointers are resolved locally (RFC 6901 tokens incl. ~0/~1 escapes and

  • array indices); validation continues against the resolved schema, with a
    visited-reference guard plus the depth limit for cycles (REF_CYCLE).
  • Non-local references (https://... etc.) are rejected explicitly

  • (REF_NOT_LOCAL) — the validator never fetches anything.
  • Unresolvable pointers fail explicitly (REF_UNRESOLVED) instead of being silently

  • skipped, so a broken schema cannot silently disable validation for a property.

    Failures still use the existing ToolCallResponse error shape with
    errorCode/fieldPath metadata and never echo argument values; the structured error
    protocol remains T38's scope, per the discussion in #134.

    Describe how to verify it

  • New tests: ToolArgumentValidatorTest 16 → 27 (byte/depth/collection limits incl.

  • at-limit boundary passing, local $ref expansion with violation paths, root-level
    $ref, remote-ref rejection, unresolvable pointer, cycle detection, ~0/~1
    escapes) and ToolArgumentValidationGateTest 7 → 9 (oversized payload rejected
    before the callback with invocation count 0; local-$ref tool schema enforced
    end-to-end).
  • Run them: ./mvnw -pl argi-agent-framework -am test -DskipTests=false -Dtest='ToolArgumentValidatorTest,ToolArgumentValidationGateTest'

  • Full local regression: argi-graph-core 579 + argi-agent-framework 859 tests,

  • 0 failures (the three pre-existing Windows-only env failures in
    FileSystemStoreTest / FilesystemInterceptorTest / FileSystemToolsTest are excluded
    and reproduce on a clean baseline, as documented in #149).
  • checkstyle 0 violations, spotless clean, license headers byte-identical.
  • Special notes for reviews

  • Behavior change vs #149: $ref nodes were previously skipped; now local pointers

  • are enforced and non-local / unresolvable ones fail explicitly. The gate is opt-in
    (validateToolArguments, default false), so no default behavior shifts; if you
    prefer keeping silent-skip semantics for unresolvable pointers, that is a one-line
    change.
  • Limit constants are centralized at the top of ToolArgumentValidator — happy to

  • adjust the values.
  • The error-code protocol intentionally stays minimal (errorCode + fieldPath on the

  • existing error shape); a structured protocol stays with T38 per the #134 discussion.

    Diff: 438 lines (+328 / -110) across 5 files Reviewer: yuluo-yx Review duration: 690m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.45) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.45 · 438 lines diff across 5 files
    0.45
    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.364
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #151"
    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: 45.3% (MEDIUM) · Higher = larger blast radius
    45.3%
    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: 19.6% · Safe to merge
    19.6%