Skip to content

Commit 52030cf

Browse files
test(cluster): only require accepted follow-ups to survive the replica race (a2aproject#1303)
# Description `tests/integration/test_multiserver.py::test_concurrent_followups_no_lost_update[mysql]` fails intermittently in CI on unrelated pull requests (e.g. the runs for a2aproject#1236, a2aproject#1300, the SSE grace-period and signing branches), always with: ``` AssertionError: ['m1', '<agent message id>', 'ma'] # assert 2 == 3 ``` I reproduced it locally against `mysql:8.0` with the CI settings and tallied 300 runs of the scenario: | Follow-up results (replica A, replica B) | User turns persisted | Runs | |---|---|---| | success, success | 3 | 297 | | success, `InternalError` ("…was modified concurrently by another writer") | 2 | 3 | So nothing is lost silently: in every failing run the follow-up whose message is missing was **rejected** with an `A2AError`. That is the documented behaviour of `ActiveTask` — on `ConcurrentTaskModificationError` it reloads and retries the event once, and if the other replica keeps advancing the task it reports an `InternalError`. The test, however, demanded all three user turns even when one follow-up was rejected. This PR changes only the assertion to the actual guarantee: - the first turn and every follow-up that **returned successfully** are in the persisted history; - at least one of the two racing follow-ups succeeds. A follow-up that is accepted but then dropped would still fail the test. With the change, 300 consecutive runs against MySQL pass; `scripts/lint.sh` is clean and the full suite passes with `MYSQL_TEST_DSN` set (2271 passed). Whether a rejected follow-up should instead be retried until it lands is a design question for the cluster mode; this PR doesn't change runtime behaviour. - [x] Follow the [`CONTRIBUTING` Guide](https://github.com/a2aproject/a2a-python/blob/main/CONTRIBUTING.md). - [x] Make your Pull Request title in the <https://www.conventionalcommits.org/> specification. - [x] Ensure the tests and linter pass - [x] Appropriate docs were updated (if necessary) Co-authored-by: mykytanetipa <mykytanetipa@google.com>
1 parent ee61dc1 commit 52030cf

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

‎tests/integration/test_multiserver.py‎

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,12 @@ async def dsn(request) -> AsyncGenerator[str, None]:
313313
@pytest.mark.asyncio
314314
@pytest.mark.timeout(60)
315315
async def test_concurrent_followups_no_lost_update(dsn: str) -> None:
316-
"""Racing follow-up sends from both replicas never lose a write (OCC)."""
316+
"""Racing follow-up sends from both replicas never lose an accepted write.
317+
318+
A replica that keeps losing the compare-and-swap rejects its follow-up
319+
with an A2AError instead of retrying forever; only a follow-up that
320+
returned successfully must be persisted.
321+
"""
317322
cluster = Cluster(
318323
dsn,
319324
InputRequiredThenCompleteAgent(),
@@ -349,14 +354,22 @@ async def test_concurrent_followups_no_lost_update(dsn: str) -> None:
349354
if isinstance(r, BaseException):
350355
assert isinstance(r, A2AError), r
351356

352-
# Durable task intact: all three user turns (q1, a, b) survived.
357+
# Durable task intact: q1 and every accepted follow-up survived.
353358
final = await cluster.replica_a.task_store.get(task_id, ctx)
354359
assert final is not None
355360
assert not final.version.is_missing
356-
user_turns = sum(
357-
1 for m in final.task.history if m.role == Role.ROLE_USER
358-
)
359-
assert user_turns == 3, [m.message_id for m in final.task.history]
361+
user_turns = {
362+
m.message_id for m in final.task.history if m.role == Role.ROLE_USER
363+
}
364+
accepted = {
365+
message_id
366+
for message_id, r in zip(('ma', 'mb'), results, strict=True)
367+
if not isinstance(r, BaseException)
368+
}
369+
assert accepted, results
370+
assert {'m1', *accepted} <= user_turns, [
371+
m.message_id for m in final.task.history
372+
]
360373
finally:
361374
await cluster.aclose()
362375

0 commit comments

Comments
 (0)