Skip to content

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

Closed

Description

@pengmoubuaixuexi

Describe the bug
AgentProtocolTaskStore.submit() documents idempotency while a task is running, but two concurrent submissions with the same task ID can both schedule an agent run within a single store instance.

To Reproduce
On current main c3959cea69c40e2c44fd2365dfbdeed4bc53e951, use a real WorkspaceProtocolTaskRepository wrapped by a repository that pauses the first PENDING save after delegating it. Keep mocked agent streams open until assertions finish:

  1. Thread A calls submit("same-task", "worker", "request"). Its PENDING record is saved; pause it before supplyAsync/futures.put.
  2. Thread B submits the same ID. It sees a non-terminal record and no registered future, saves another PENDING record and schedules its agent.
  3. Release A. A schedules a second agent run for the same task.
  4. Both submissions return normally, with two pending registrations and two agent stream invocations.

The local JUnit regression uses latches (no model/network calls). Command:

mvn -B -T1 -pl agentscope-extensions/agentscope-extensions-protocol/agentscope-extensions-agent-protocol -am -Dtest=AgentProtocolTaskStoreConcurrentSubmitTest -Dsurefire.failIfNoSpecifiedTests=false test

Expected behavior
Concurrent submissions of the same running task are idempotent within one store instance: one pending registration and one agent execution. Different task IDs can still proceed independently; completed IDs retain the existing rejection behavior.

Error messages

AgentProtocolTaskStoreConcurrentSubmitTest.concurrentSubmissionsOfSameTaskStartOnlyOneRun
one pending registration per logical task ==> expected: <1> but was: <2>
Tests run: 1, Failures: 1, Errors: 0, Skipped: 0

Environment

  • AgentScope Java: 2.1.0-SNAPSHOT, main c3959ce
  • Java: 17.0.20.1
  • OS: Windows; Maven 3.9.12

Additional context
The record check, futures check, pending persistence and future registration in submit are separate operations. ConcurrentHashMap only makes individual map operations thread-safe. Duplicate runs can repeat model/tool work; only one of their futures remains addressable by task ID. No claim of distributed exactly-once execution is intended.

PR #3602 serializes resume with an existing per-task monitor and fixes identity-based future cleanup, but submit does not yet acquire that monitor. I checked that change and searched open/closed issues and PRs for this class, concurrent submission and duplicate/idempotent tasks; I did not find a matching fix.

I am implementing a small fix using the existing per-task monitor, with regression tests and matching documentation, and will submit the linked PR. Please assign this issue to @pengmoubuaixuexi if assignment is available.

AI assistance: investigated and implemented with Codex; validation results will be recorded in the PR.

Activity

  1. added a commit that references this issue on Nov 11, 2026
    9d4f864
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions