Repository navigation
Conversation
A message that continues a task is admitted in three steps: the task is read and checked in authorizeTaskAccess, the snapshot is saved with the message, and the agent is submitted. Nothing recorded that an input request had already been answered, so two messages answering the same INPUT_REQUIRED could both run the agent, and an answer that read the task before the other answer's turn was saved and run after that turn had completed the task, displacing the first answer from the history. Right after authorizeTaskAccess, a message to a task in INPUT_REQUIRED now reserves that input request, identified by its status timestamp, which updateWithMessage keeps. The reservation is an atomic compute on a per-task map that holds the latest request answered. A message whose request is not newer than that one is refused with InvalidRequestError before its snapshot is saved and before the agent is started. Messages to tasks in other non-final states and new tasks are not affected. The reservation lives in the handler instance and is not shared between handlers or persisted across a restart. Status timestamps are taken as increasing per task. A failure after the reservation leaves the request reserved. TwoAnswersOneInputTest holds one task-store read back after it happened and checks that of two answers to one input request exactly one runs the agent and the other is refused. Fixes: a2aproject#1389
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.
This closes the time-of-check-to-time-of-use race reported in #1389: an authorised client's answer could be run by the
agent against a stale revision of an input request another answer had already consumed (input integrity).
Right after
authorizeTaskAccessininitMessageSend, a message to a task in INPUT_REQUIRED reserves that inputrequest, identified by the status timestamp (which
updateWithMessagekeeps), with an atomicConcurrentMap.computeon a per-task map holding the latest request answered. A message whose request is not newerthan that one is refused with
InvalidRequestError("The input requested by task ... has already been answered")before its snapshot is saved and before the agent is started.
What this guarantees, within one
DefaultRequestHandlerinstance (the reservation map is an instance field, neithershared between handlers over one task store nor persisted across a restart): two messages admitted against the same
INPUT_REQUIRED status never both run the agent, also when one read the task before the other's turn; a message read
against an older request than one already answered is refused. Behaviour changes and limits: messages to tasks in any other non-final state (refinements) and new tasks are
not affected; status timestamps are taken as increasing per task (a new request whose timestamp is equal to or older
than the last answered one would be refused); a failure after the reservation (context construction, the save) leaves
the request reserved, with no rollback; one map entry, never removed, per task that has received an answer in that
handler.
Fixes #1389.
Tests
fix/pending-input-single-answer= upstream mainbc7f9d74+ this commit (d255f376).TwoAnswersOneInputTest: fails 3 of 3 on369ee867; passes 3 of 3 on the branch.mvn -pl server-common teston the branch: 673 tests, 1 failure,DefaultRequestHandlerBuilderAuthorizationTest.emptyTaskIdWithoutEffectiveCardIsInvalid. It fails the same way onunpatched
bc7f9d74in the same build, so it is not caused by this change; an online build should be checked.On
369ee867with the same patch: 661 tests, 0 failures.server-commonwas built from source and the other modules taken from cached1.5.2.Final-SNAPSHOTjars. The Error Prone/NullAway processors were removed from the build only. The four tooling versions upstream
bumped since the pin (spotless, mapstruct-spi-protobuf, groovy, quarkus platform) were set back to the pin's values
with
-D, because the new ones are not in the offline cache.Found with. We are a research team at MPI-SWS building Daavar, a conformance checker for distributed protocol
implementations. The race was found by a JMC model of the continuation path with an adversary client and confirmed
natively. This PR was prepared with AI assistance and reviewed by us.
Reproduce with Daavar (fixed form)