feat(agent): add resource limits and local $ref expansion to tool argument validation (T31) #151
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
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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
yuluo-yx
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
$refhandling — so thevalidator 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
ToolArgumentValidatorplus its tests; the opt-in gatewiring 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, soneither 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 isopt-in, so no default behavior shifts):
#/...pointers are resolved locally (RFC 6901 tokens incl.~0/~1escapes andarray indices); validation continues against the resolved schema, with a
visited-reference guard plus the depth limit for cycles (
REF_CYCLE).https://...etc.) are rejected explicitly(
REF_NOT_LOCAL) — the validator never fetches anything.REF_UNRESOLVED) instead of being silentlyskipped, so a broken schema cannot silently disable validation for a property.
Failures still use the existing
ToolCallResponseerror shape witherrorCode/fieldPathmetadata and never echo argument values; the structured errorprotocol remains T38's scope, per the discussion in #134.
Describe how to verify it
ToolArgumentValidatorTest16 → 27 (byte/depth/collection limits incl.at-limit boundary passing, local
$refexpansion with violation paths, root-level$ref, remote-ref rejection, unresolvable pointer, cycle detection,~0/~1escapes) and
ToolArgumentValidationGateTest7 → 9 (oversized payload rejectedbefore the callback with invocation count 0; local-
$reftool schema enforcedend-to-end).
./mvnw -pl argi-agent-framework -am test -DskipTests=false -Dtest='ToolArgumentValidatorTest,ToolArgumentValidationGateTest'argi-graph-core579 +argi-agent-framework859 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).
Special notes for reviews
$refnodes were previously skipped; now local pointersare enforced and non-local / unresolvable ones fail explicitly. The gate is opt-in
(
validateToolArguments, defaultfalse), so no default behavior shifts; if youprefer keeping silent-skip semantics for unresolvable pointers, that is a one-line
change.
ToolArgumentValidator— happy toadjust the values.
existing error shape); a structured protocol stays with T38 per the #134 discussion.