Skip to content

fix: [Bug]: ReAct 流式事件为同一次缺少原始 ID 的工具调用分配不同 ID - #4163

Closed
xixi-box wants to merge 1 commit into
agentscope-ai:mainfrom
xixi-box:fix/issue-4162-a4306d6-2a91377d
Closed

xixi-box wants to merge 1 commit into
agentscope-ai:mainfrom
xixi-box:fix/issue-4162-a4306d6-2a91377d

Conversation

@xixi-box

Copy link
Copy Markdown

Fixes #4162

Root cause: ToolCallBuilder generated a new fallback ID on each build instead of caching it per tool call, causing streaming snapshots and final history to use different IDs when the provider supplied none.

Tests: mvn -B -T1C -pl agentscope-core -am test -Dtest=ToolCallIdentityAuditTest -Dsurefire.failIfNoSpecifiedTests=false -Dspotless.skip=true (fails on base; passes with this patch).
Regression coverage: agentscope-core/src/test/java/io/agentscope/core/agent/ToolCallIdentityAuditTest.java.

AI assistance: Codex helped implement and test this change. oss-scout independently replayed the regression before opening this PR.

@CLAassistant

CLAassistant commented Nov 13, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@xihongshichaojidan8

Copy link
Copy Markdown
Contributor

感谢你关注 #4162,也谢谢你提交修复。我在报告这个问题时提到过愿意提供修复和回归测试,现在已经把自己的实现提交到了 #4167。

这次我想继续跟进 #4167,就不另在 #4163 上推进了。为避免两边重复投入,如果你有建议,欢迎直接在 #4167 里讨论。最终采用哪份实现,以维护者的评审意见为准。谢谢理解!

@xixi-box

Copy link
Copy Markdown
Author

感谢说明,也抱歉造成了重复投入。

我看了 #4167,确实是在修复同一个问题,而且补充了不同工具调用及重置后备用 ID 不重复的测试。

我会关闭 #4163,避免维护者重复评审。如果后续有实质性的补充建议,我会直接在 #4167 讨论。

感谢理解,也祝后续评审顺利!

@xixi-box xixi-box closed this Nov 14, 2026
juruoO-o pushed a commit that referenced this pull request Nov 19, 2026
## AgentScope-Java Version

`2.1.0-SNAPSHOT`,基线为官方 `main` 的
`a4306d63d8ac737b535657f56a0ad5496503d4d8`。

## Description

Fixes #4162.

当自定义模型分片返回一次没有原始 ID 的工具调用时,累加器在构建流式快照和最终消息时会分别按时间戳补
ID。工具只执行一次,但消费端无法用同一个 `toolCallId` 拼接参数并关联执行结果。

本 PR 在单次工具调用的累加状态中生成并复用一个备用 ID。备用 ID 保留 `tool_call_` 前缀并使用
UUID,避免不同累加状态恰好在同一毫秒生成相同的 ID。模型提供的原始 ID 保持不变。不改分片路由、工具调度、权限或事件字段;不扩展到原始
ID 迟到的语义。

### 验证

- 端到端回归覆盖缺少原始 ID 和已有原始 ID:开始、参数分片、结束、执行结果及历史使用同一 ID,拼接后的参数能得到预期工具结果。
- 单元测试验证同一调用多次构建时 ID 保持稳定、不同调用不共享备用 ID,以及累加器重置后不复用旧 ID。
- 在未修复基线上,缺 ID 的新回归用例因分片 ID 不一致而失败;带原始 ID 的对照通过。应用补丁后两个场景均通过。
- `mvn -B -T1C -pl agentscope-core -am test`:3452 项,0 failures、0
errors、11 skipped。实际在本机使用 Maven Central 临时 settings 与离线缓存;Spotless
通过。未运行全仓测试或 Windows。
- 已同步中英文 dev 事件文档。文档单测 20 项通过,导航、语法、本地链接及资源检查通过,`npm run broken-links`
未发现坏链。Mintlify 完整构建校验被本地预览缓存的文件权限阻止,待 CI 验证。

### 相关 PR

#4163 也处理 #4162 的同一根因。本 PR 额外验证不同调用与重置之间不复用备用
ID,并补充双语事件文档。两份修复不需要同时合并,请维护者选择合适的实现。

## Checklist

- [x] Code has been formatted with `mvn spotless:apply`.
- [ ] All repository tests are passing (`mvn test`) — 已验证 Core,未运行全仓。
- [x] Javadoc comments follow project conventions — 无新增公共 API。
- [x] Related documentation has been updated.
- [x] Code is ready for review.
xzxiaoshan added a commit that referenced this pull request Nov 20, 2026
…#4274)

## Background

Swept the last 125 PRs (#4272→#4075) for single-OS CI failures under
`mvn -B -T1C clean verify` (one build OS red, the other green on the
same commit = flake suspect). Cross-PR repeats and main's own red run on
2026-11-19 (ubuntu, run 44516464414) pinpoints four still-broken test
classes; all fixes are test-side only (no `src/main` changes).

## Fixes and evidence

| Test class | Victims | Signature | Fix |
|---|---|---|---|
| `RocketMqExecutionTest` | #4182, #4192, #4103 + main run 44516464414
(2026-11-19, ubuntu) | `turn reaches SUCCEEDED did not become true
within 10s` while the turn kept progressing (modelCalls complete, acks
climbing, lastFailure=none) — deadline breakthrough under starvation,
not a lost turn | shared `waitUntil` deadline 10s→30s (repo tier
#3726/#3774) |
| `AgentScopeAdapterTest` | #4204 (same-commit re-run green = confirmed
flake), #4191, #4246 | `Timed out observing Turn` at 6.7–8.5s elapsed;
resume/recovery one step from terminal | `turn.await(5s)`→30s at all 3
sibling sites via `TURN_DEADLINE`, outer `get` budgets +5s margin |
| `WorkerRuntimeTest` | #4219, #4224, #4255 (windows) | (a) `Worker
lease lost` after 2.4s — 1s claim leases expired between claim and
release; (b) `renewed.await(5s)` missed at 6.5s while the recovery lane
was healthy; (c) `Interrupted sleep interrupted` —
`WorkerRuntime.process()` interrupts the calling thread on lease-renewal
failure and manual `tick()` runs it on the test thread | (a) claim
leases 1s→30s (staleness under test still comes from `release(ZERO)` +
re-claim); (b) latches 5s→30s; (c) raw `Thread.sleep`→interrupt-proof
`pause()` at 5 sites, mirroring the #4176 fix for the same signature in
`ProcessRecoveryTest` |
| `ChatSessionsTest.await` (shared with `ChatControllerTest`) | #4233,
#4182 (stuck-RUNNING at 40.8s/46.4s), #4268, #4163 (poll threw `Durable
database transaction failed`) | two surfaces of one cause: every
snapshot poll opens a writing sqlite transaction contending with the
runtime's own writes, and windows runners starve turns past 30s (same
file already measured 56.6s starvation and uses 120s elsewhere, #3726) |
deadline 30s→120s (aligned tier) + tolerate transient `UNAVAILABLE`
store exceptions while polling; persistent failure rethrows at the
deadline, FAILED-turn fast-fail unchanged |
| `CommandExecutorTest.missingExitCodeIsUnknown` | local -T2C full-repo
stress (2026-11-19; pristine-main baseline of the same class green) |
the 2s network budget fired on scheduler starvation before the instant
fake response was processed, misclassifying the failure as a deadline
miss instead of a missing exit code (2.97s elapsed) | budget 2s→30s for
this non-deadline-semantics test; the two deadline-semantics tests keep
their tight budgets |

## Constraint compliance

- Happy path zero cost: every change only extends failure-path deadlines
or hardens helpers; no new sleeps, no weakened assertions.
- Minimal widening anchored to measured data (each comment cites victims
+ measured values); 30s follows the repo's established deflake tier,
120s follows this file's own previously measured starvation tier.
- Structural hardening preferred: `pause()` helper, transient-lock
retry, lease decoupling from the tested invariant.
- No `src/main` changes.

## Observed but deliberately not fixed here

-
`ProcessRecoveryTest.replacementCollectsOriginalResultWithoutRepeatingEffect`
(#4214: `expected: 2 but was: 3`): recovery-semantics race (model re-run
without effect re-run after abrupt halt) — a product question for the
durable recovery work, not a deadline flake.
-
`JevEvidenceProcessorTest.filterFailureIsWithheldButRankFailureFollowsScoredEvidence`
(#4265: delivered `[]` on a 25×-slowed runner): root cause not
established; single occurrence.
- Already fixed upstream, victims predate the fix:
`AgentScopeAgentExecutorInputRequiredTest` (#4157/#4187/#4152 all
predate #4176's `BaseReActAgentRunner` change), `InboxMiddlewareTest`
(#4093 predates #3738), `HarnessAgentSubagentStreamEventsTest` (#4183
predates #2917).
- `SkillBoxTest$UploadContainment` quartet (#4201/#4202/#4212/#4229):
test does not exist on main (fork stack only); deterministic cross-drive
path bug, not load flakiness.
- #4184/#4185: both-OS compile breaks from dependency major bumps
(dependabot), out of scope.

Also applied during review: sibling sites with the identical measured
mechanism were widened in the same pass — the remaining 1s fixture claim
leases in `WorkerRuntimeTest` (fenced begin/update/release sequences,
same #4219 signature), the start/PAUSED 5s budgets in the same
`AgentScopeAdapterTest` method as the victims, and the 5s/4s observe
budgets in
`completeLocalBackendRunsNativeAgentWhileManagedObserverIsBlocked`.

## Test plan

- [x] Full local `mvn -B -T2C clean verify` green (stricter than CI's
-T1C). Locally excluded, each verified to fail identically on pristine
main on this machine (Windows/git-bash) while passing on CI:
`JsonFileAgentStateStoreTest` (symlink permissions), the
`agentscope-extensions-durable-sandbox` trio plus
`ToolInSandboxExampleTest`/`SandboxRoundTripTest` (sandbox shell heredoc
incompatible with local git-bash python3), and the
`AgentScopeAdapterTest`/`ProcessRecoveryTest`/`HarnessExternalToolProcessRecoveryTest`
trio (durable-adapter classes whose Windows runs are skipped on CI; the
same named tests fail on pristine main locally).
- [ ] CI green on both OS.
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.

[Bug]: ReAct 流式事件为同一次缺少原始 ID 的工具调用分配不同 ID

3 participants