Skip to content

fix(core): reject trailing content during JSON decoding - #3697

Merged
juruoO-o merged 2 commits into
agentscope-ai:mainfrom
fengyue-xve:fix/json-codec-trailing-content
Nov 12, 2026
Merged

juruoO-o merged 2 commits into
agentscope-ai:mainfrom
fengyue-xve:fix/json-codec-trailing-content

Conversation

@fengyue-xve

@fengyue-xve fengyue-xve commented Oct 21, 2026 •

Copy link
Copy Markdown

The default JacksonJsonCodec accepts the first root JSON value and ignores remaining input. Consequently JsonUtils.isValidJsonObject accepts raw tool-call arguments such as {"x":1} garbage or {"x":1} {}, and resolveToolCallArgsJson preserves malformed arguments instead of falling back to the structured input. Providers can then reject the tool history.

Use a per-call ObjectReader with FAIL_ON_TRAILING_TOKENS for both Class and TypeReference deserialization. Valid trailing JSON whitespace remains accepted. A custom ObjectMapper keeps its own configuration unchanged.

Validation: native Maven regression on the original code reports5failed/1passed. After the fix, native agentscope-core -am tests for JacksonJsonCodecTrailingContentTest, JacksonJsonCodecTest and JsonUtilsTest pass:44tests,0failures,0skips. Cases cover trailing garbage, a second object, null/number roots after an object, both overloads, actual tool-argument fallback, whitespace and custom mapper configuration. Project Spotless and diff checks pass. Matching English/Chinese tool docs updated. Full repository verification was not run.

CI follow-up: Windows failed in unchanged channel-common/BotLoopGuardTest.activePeersSurviveEvictionOfIdleOnes (expected 1 but was 0), job log. Its900ms sleep can overshoot the1000ms idle/sweep threshold, so allow(active-peer) automatically evicts the idle peer before the later explicit sweep. A standalone run against the unchanged baseline source with a1100ms first sleep reproduces removed=0 while the active peer remains and trackedPeers=1. The JSON module tests pass locally. A rerun attempt currently returns job cannot be rerun; the Ubuntu job is still running. This failure is recorded explicitly pending a rerun rather than modifying unrelated channel logic in this PR.

@mintlify

mintlify Bot commented Oct 21, 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 b24c279.

Approve preview

@CLAassistant

CLAassistant commented Oct 21, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@jujn jujn added the P1 紧急不重要 label Nov 3, 2026
Signed-off-by: fengyue-xve <[email protected]>

@juruoO-o juruoO-o left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed strict single-root JSON decoding for both overloads, preservation of trailing whitespace and isolation of caller ObjectMapper configuration.

No blocking findings in the reviewed diff. This was a static review of source and tests; local Java/Maven tests were not run.

@juruoO-o
juruoO-o merged commit 0a989c8 into agentscope-ai:main Nov 12, 2026
5 of 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

P1 紧急不重要

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants