Skip to content

Fix: activePrompt lock should be per-session, not global#9

Open
WXY-V1hZ wants to merge 1 commit into
agentclientprotocol:mainfrom
WXY-V1hZ:fix/per-session-active-prompt
Open

Fix: activePrompt lock should be per-session, not global#9
WXY-V1hZ wants to merge 1 commit into
agentclientprotocol:mainfrom
WXY-V1hZ:fix/per-session-active-prompt

Conversation

@WXY-V1hZ
Copy link
Copy Markdown

Description

Problem

AcpAgentSession uses a single AtomicReference<ActivePrompt> to enforce single-turn semantics, but the lock is global across all logical sessions. When session A has an in-progress prompt, session B's prompt request is immediately rejected with error -32000, even though the ActivePrompt record already stores sessionId — it just wasn't being used for the lock check.

Root Cause

The compareAndSet(null, newPrompt) on a single AtomicReference acts as a global mutex. The ActivePrompt record was correctly designed with a sessionId field, but the lock implementation ignored it:

// Before: global lock — any active prompt blocks all sessions
activePrompt.compareAndSet(null, newPrompt)

Fix

Change AtomicReference<ActivePrompt> to ConcurrentHashMap<String, ActivePrompt> keyed by sessionId:

// After: per-session lock — only same-session prompts are rejected
activePrompts.putIfAbsent(sessionId, newPrompt)

Different sessions can run prompts concurrently. Same session still enforces single-turn.

Changes

  • AcpAgentSession.java: Replace AtomicReference with ConcurrentHashMap, update lock/acquire/release/cancel paths
  • AcpAgentSessionTest.java: Update reflection-based tests to work with the new field type

Verification

./mvnw test -pl acp-core323 tests passed, 0 failures

The AtomicReference<ActivePrompt> used a single slot for all sessions,
rejecting concurrent prompts from different logical sessions. Changed to
ConcurrentHashMap<String, ActivePrompt> keyed by sessionId so that only
same-session prompts are rejected, while different sessions can run
concurrently.
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.

1 participant