Skip to content

fix(core): reject incomplete and malformed tool-call arguments - #3739

Merged
jujn merged 2 commits into
agentscope-ai:mainfrom
Buktal:codex/harness-tool-integrity
Oct 25, 2026
Merged

jujn merged 2 commits into
agentscope-ai:mainfrom
Buktal:codex/harness-tool-integrity

Conversation

@Buktal

@Buktal Buktal commented Oct 23, 2026

Copy link
Copy Markdown
Collaborator

AgentScope-Java Version

2.1.0-SNAPSHOT

Description

Summary

Incomplete tool arguments can be normalized to {} and executed. Retain the response finish reason, mark malformed arguments during accumulation, and return a paired error before the permission gate or handler. Complete sibling calls remain executable.

- incomplete arguments -> {} -> handler
+ incomplete arguments -> malformed marker -> ERROR(original call ID)

Validate the entire argument string as one JSON object, including its suffix. Preserve the existing builders, no-argument accumulator method, and metadata storage shape. EN/ZH context documentation describes execution behavior.

Parent issue: #3737. This PR can target main independently; the Anthropic replay PR builds on it. Related: #2648 and #2841; this PR does not claim raw-argument retention or the complete large-output recovery policy.

Evidence

The baseline invokes a local counter tool for truncated JSON. Regression tests assert zero handler invocations, original-ID error pairing and events, and execution of two complete siblings in a mixed batch. A valid root followed by a second root or malformed suffix is rejected; complete {} and trailing whitespace remain accepted.

Isolated verification on upstream 07c5f3078d682da30f29e96b6d76f68242cbc2e1: 60 tests, 0 failures/errors/skips; Spotless passed.

mvn -B -T1C -pl agentscope-core -am test spotless:check '-Dtest=TruncatedToolCallIntegrityTest,ToolCallsAccumulatorTest,JsonUtilsTest,ReasoningContextTest' -Dsurefire.failIfNoSpecifiedTests=false

DeepSeek Harness agent.ts:547 stops before tool execution at max-tokens. ZCode tool-input-normalization.ts:32 validates the whole string with JSON.parse, but its {} error fallback loses the failure. Keeping complete siblings and returning ASJ's normal error results is an ASJ-specific choice verified through handler counts.

Merge Danger

Door: reversible code change. Blast radius: accumulated client tool calls across providers. Malformed raw JSON is rejected even if an application's custom codec can repair it; ordinary codec serialization/deserialization remains configurable. The strict validator does not change the global Jackson configuration. Existing ambiguous empty starts are rejected only when the output-limit condition is present.

Checklist

  • Code formatting verified with Spotless.
  • Relevant tests pass on this PR's isolated source snapshot.
  • Javadoc comments follow project conventions.
  • Related EN/ZH documentation updated.
  • Code is ready for review.

@mintlify

mintlify Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit b0b4a62.

Approve preview

@jujn
jujn merged commit 1ac8c83 into agentscope-ai:main Oct 25, 2026
7 checks passed
chickenlj added a commit that referenced this pull request Nov 13, 2026
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.

2 participants