Repository navigation
Conversation
…s lock onSubscribeToTask read the task from the store and tapped its queue in two unordered steps, while the bus thread persisted and distributed each event. An event persisted after the read and distributed before the tap reached neither the snapshot nor the stream: an artifact was lost, or a terminal status was lost and the stream never closed (A2A spec 3.1.6). MainEventBusProcessor.processEvent now holds a private monitor from persisting an event to distributing it to the child queues, and onSubscribeToTask runs its read, checks, tap and createOrTap fallback under the same monitor (withEventProcessingPaused). Adds SubscribeWindowTest. Fixes a2aproject#1370
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This change was found and re-checked with Daavar, a conformance checker we develop at MPI-SWS (https://github.com/joulook/daavar); the issue it fixes is #1370.
CONTRIBUTINGGuide.Change.
MainEventBusProcessorgets a private monitor, held byprocessEventfrom step 1 (persist the event) to the end of step 3 (distribute it to the children), so step 2 (the replication hook and push-notification scheduling) runs under it too, and a slow push scheduler now delays subscribes. A new public method,withEventProcessingPaused(Supplier), runs an action under the monitor;onSubscribeToTaskruns its store read, not-found and terminal checks,tapandcreateOrTapfallback through it, unchanged (a privatereadAndTap);processEvent's step order is unchanged.This closes both findings: an event is now persisted either before the read (the snapshot has it, and a terminal one makes the subscribe refused, as §3.1.6 requires) or distributed after the tap (it reaches the new child queue).
Both paths take the monitor before any queue or store lock; distribution uses the non-blocking
offer. Code inside the section (aTaskStore, a replication hook or strategy, the lifecycle hook'sonSubscribe/onUnsubscribe) must not wait for the bus. The monitor is per JVM: replicated multi-instance deployments are not covered.Of the in-repo implementations (
InMemoryTaskStore,JpaDatabaseTaskStore,InMemoryQueueManager,ReplicatedQueueManagerwithReactiveMessagingReplicationStrategy,BasePushNotificationSenderwith both push-config stores,DefaultTaskStreamLifecycleHook,CloseStreamsHook), none waits for the bus or, with the default push executor, for I/O other than database round trips (with a synchronous executor, whichsetPushNotificationExecutorallows for tests, the HTTP sends run under the lock); third-party ones are not checked. With this change, a subscribe's task-store read and queue tap run while the event bus is paused, so withJpaDatabaseTaskStoreeach subscribe holds up the events of all tasks for one primary-key query (two if a stream lifecycle hook closes the task's last stream), next to the read and write the bus already does for each persisted task update. We have not measured this cost and can measure it on request. Alternatives: tapping first with a sequence filter, as a2a-rs does, needs a sequence thatTaskand the stores lack (aTaskStorecontract, JPA schema and replication change, or an in-process cache like a2a-rs's). A per-task lock needs a registry whose cleanup never hands out two locks for one live task (cancelLocksremoves its lock safely only because a cancelled task is terminal), and gains little: the bus is one loop, so once it reaches the subscribed task's event every task waits anyway. An optimistic read (sample a counter the bus bumps per event, read the store outside the lock, tap if the counter is unchanged, else retry) keeps the query out of the lock while the bus is quiet, but retries under load and needs a bound falling back to the locked read; we can offer it as a follow-up.Tests. New
SubscribeWindowTest(server-common,requesthandlers):eventPublishedBetweenReadAndTap_reachesSnapshotOrStreamandterminalStateBetweenReadAndTap_closesTheStream(#1370). AQueueManagersubclass stops the subscribe at itstap, after the store read, while the agent publishes. Each run checks that the window was exercised (the bus finished inside it, orThreadMXBeanshows the bus blocked on a lock the subscriber holds), so they cannot pass by timing. With the change, each waits out the hook's 3 s timeout by design (class: 6.8 s). Both fail onmain3f321f1cand at369ee867(#1353's merge, the issue's pin) without the change, and pass with it.Verification (JDK 17.0.21, Maven 3.10.2). On
main3f321f1c, where the diff applies without conflict: 4,135 tests, 0 failures, 0 errors, 121 skipped; at369ee867: 4,082 tests, 0 failures, 0 errors, 121 skipped. On both, all 83 reactor modules succeeded undermvn -B -fae installplusmvn -B clean install -pl boms/extras(the Extras BOM test needed the rebuild after a stale invoker-repository entry). NullAway passes.Re-check with Daavar (model at
d83d3b7,A2ATaskFixed2). In our model of a2a-java with the subscribe's read and tap made one step, as in the fix, the behaviours the specification program does not produce fell from 2,060 to 0 over the 15 scenarios of #1370, with no new kind of difference. Against our a2a-rs model, every behaviour only the fixed Java model shows (11,041) conforms to the specification.Per scenario and reproduction
Uncovered behaviours, before → after. Columns: (a) both streams kept, (b) A disconnects, (d) B subscribes at once. Rows: the executor answers with a
Message(msg) or opens the task with aTask(tasks) or a status update (taskw), split by how it completes (done).msgtasks,done-yestasks,done-notaskw,done-yestaskw,done-noRequirements as in #1370; the join takes about 3.5 minutes and 20 GiB, as there. It prints warnings that some tag names of the A2A vocabulary are written both as a unit and with one field, and a note that
Erroccurs only in the specification; neither is a failure.This PR was prepared with AI assistance and reviewed by us.
Fixes #1370