ArcpClient records pending submissions in a ConcurrentHashMap, but handleAccepted matches a job.accepted response by calling pendingSubmits.keySet().stream().findFirst() in arcp-client/src/main/java/dev/arcp/client/ArcpClient.java around line 348. The comment says this traverses pending submits in insertion order, but ConcurrentHashMap does not provide insertion order. If two threads submit jobs concurrently, the client can complete the wrong handle with the accepted job id and then route the eventual result to the wrong caller.
Fix prompt: Replace the unordered pendingSubmits matching with a deterministic correlation mechanism. If the wire protocol can echo the original request id, carry that id through job.accepted and job.error and complete the exact pending future. If the protocol intentionally relies on per-session ordering, store pending request ids in a ConcurrentLinkedQueue or another FIFO structure and remove the same id from the map when the next acceptance arrives. Add a concurrent test that submits multiple jobs before any acceptance is processed and verifies every returned JobHandle and result correspond to the correct submitted payload.
ArcpClient records pending submissions in a ConcurrentHashMap, but handleAccepted matches a job.accepted response by calling pendingSubmits.keySet().stream().findFirst() in arcp-client/src/main/java/dev/arcp/client/ArcpClient.java around line 348. The comment says this traverses pending submits in insertion order, but ConcurrentHashMap does not provide insertion order. If two threads submit jobs concurrently, the client can complete the wrong handle with the accepted job id and then route the eventual result to the wrong caller.
Fix prompt: Replace the unordered pendingSubmits matching with a deterministic correlation mechanism. If the wire protocol can echo the original request id, carry that id through job.accepted and job.error and complete the exact pending future. If the protocol intentionally relies on per-session ordering, store pending request ids in a ConcurrentLinkedQueue or another FIFO structure and remove the same id from the map when the next acceptance arrives. Add a concurrent test that submits multiple jobs before any acceptance is processed and verifies every returned JobHandle and result correspond to the correct submitted payload.