Skip to content

fix(protocol): serialize concurrent task submissions - #3643

Merged
juruoO-o merged 2 commits into
agentscope-ai:mainfrom
pengmoubuaixuexi:fix/protocol-submit-idempotency
Nov 11, 2026
Merged

juruoO-o merged 2 commits into
agentscope-ai:mainfrom
pengmoubuaixuexi:fix/protocol-submit-idempotency

Conversation

@pengmoubuaixuexi

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT, based on main c3959cea69c40e2c44fd2365dfbdeed4bc53e951.

Description

Fixes #3642.

Two concurrent submit calls with the same task ID can both observe no running future and schedule an agent run, despite the documented idempotency contract. A persisted PENDING record does not prevent the second submission from passing the check before the first future is registered. This can duplicate model/tool execution and leave only one of the runs addressable by task ID.

Use the existing per-task monitor (already used by resume) around the submission checks, pending persistence and future registration. Actual agent execution remains asynchronous; different task IDs retain independent registration. Keep the existing identity-based future cleanup and terminal-task rejection behavior. Update the English and Chinese protocol guides to state the single-instance scope.

The regression pauses the first PENDING save after it reaches a real temporary workspace repository. A second submission then either completes registration on the old code or blocks on the first thread's task monitor after the fix. The agent stream is held open until assertions finish. A separate different-ID case requires the second submission to finish before the first save is released, guarding against accidental global serialization. Completion and rejection of a completed ID are also checked.

Validation

Java 17.0.20.1, Maven 3.9.12, Windows, from the repository root:

mvn -B -T1 -pl agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agent-protocol -am -Dtest=AgentProtocolTaskStoreConcurrentSubmitTest -Dsurefire.failIfNoSpecifiedTests=false spotless:apply test
mvn -B -T1 -pl agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agent-protocol -am "-Dtest=AgentProtocol*Test,WorkspaceProtocolTaskRepositoryTest" -Dsurefire.failIfNoSpecifiedTests=false spotless:apply test
mvn -B -T1 -pl agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agent-protocol -am spotless:check
  • Final regression tests with the original production implementation: 2 tests, 1 failure (one registration per logical task ==> expected: <1> but was: <2>); the different-ID control passes.
  • Fixed implementation: all 35 protocol module tests pass, including existing HITL resume tests; no failures, errors or skips.
  • Spotless and git diff --check pass.
  • In docs/, npm test: 13 pass; npm run validate: passes (430 pages, 584 redirects plus Mintlify build validation).
  • npm run broken-links: exits 1 with 2,208 reported links in 326 files. Re-running with the original EN/ZH pages gives the same file/link entries; no new reports from this change.

Scope: coordination within one AgentProtocolTaskStore, not cross-replica exactly-once execution. This reuses the existing task-lock registry and its lifecycle; cancellation and persisted-task recovery semantics are unchanged. Full-repository clean verify and real-model/HTTP integration tests were not run.

AI assistance: investigation, implementation and test execution were performed with Codex. The final diff was checked against the reproduction and the validation above; this is not a claim of independent human review.

Checklist

  • Code has been formatted with mvn spotless:apply
  • All tests are passing (mvn test) — all 35 protocol module tests pass; full-repository suite not run
  • Javadoc comments are complete and follow project conventions
  • Related documentation has been updated
  • Code is ready for review

Copilot AI balanced review requested due to automatic review settings October 18, 2026 00:17

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing. Review the Copilot code review billing settings.

if (prior != null && !prior.isDone()) {
return;
}
Object lock = taskLocks.computeIfAbsent(taskId, k -> new Object());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这里把锁表的使用范围从 resume 扩大到了所有 submit,但没有对应的回收逻辑。每个普通任务结束后,taskId 和锁对象都会一直留在 taskLocks 中。
我在本地对照验证了不同 ID 的普通任务:全部完成且 Future、提交上下文都已清空后,基线锁表为 0,当前 PR 会没有被删除掉。长期运行的服务会因此按历史任务数量持续积累锁对象。
建议补上安全的回收机制或采用有界锁方案和对应的测试用例,谢谢

@pengmoubuaixuexi pengmoubuaixuexi Oct 21, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this. You're right: retaining one lock object per taskId would grow with completed task volume. I replaced the per-task map with 64 fixed lock stripes selected by taskId hash. Both submit and resume use the same stripe, so same-task transitions remain serialized; hash collisions can add contention between unrelated tasks but do not affect correctness.

I added a regression that completes 80 unique tasks and asserts lock storage stays within the stripe bound. On the original PR head it failed after the tasks completed; with this change the focused protocol-module suite passes (3 tests), including same-task serialization and independent-task submission. spotless:check and git diff --check pass. Updated head: 4fb3010. Please re-review.

@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 4fb3010.

Approve preview

@xiaoyuuuuuupeng xiaoyuuuuuupeng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM 本地复测过了

@jujn jujn added the P0 重要紧急 label Nov 3, 2026

@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.

submit 的检查、PENDING 持久化与 future 注册在同一 task 条带锁下完成,并与 resume 共用同步边界,能够关闭同实例的重复提交窗口。固定条带限制锁存储量,实际执行保持异步;未引入分布式保证或持久化格式变化。已核对并发回归用例与文档中的单实例边界,未发现阻塞问题。本轮未重跑测试。

@juruoO-o
juruoO-o merged commit 9d4f864 into agentscope-ai:main Nov 11, 2026
6 of 7 checks passed
chickenlj pushed a commit that referenced this pull request Nov 13, 2026
Backport the verified fix to the 2.0.x implementation and retain its existing public contracts where the upstream kernel differs.

(cherry picked from commit 9d4f864)
Backport-review-patch: 1ae54d35eb93893ae8f00e28d3cff6af54f3b4b6
Constraint: No AgentScope Service or SDK migration
Confidence: high
Not-tested: Whole-repository verification pending after lane integration
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P0 重要紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Concurrent protocol submissions with the same task ID can start duplicate runs

5 participants