Repository navigation
test(tutorials): poll task state instead of a fixed 1s sleep - #548
Conversation
51c83d3 to
fb2fe3d
Compare
| messages = await wait_for_state_messages(client, "agent", "task", expected_count=3, timeout=0.3, sleep_interval=0.05) | ||
|
|
||
| assert len(messages) == 1 | ||
| assert 0.3 <= time.monotonic() - start < 2 |
There was a problem hiding this comment.
If a busy worker wakes more than two seconds after this test starts, the wall-clock check fails even though wait_for_state_messages honored its deadline. The root suite runs tests in parallel, so this can add an unrelated red test to the suite this PR aims to make more reliable. Check the deadline without requiring a fast wake-up.
Prompt To Fix With AI
This is a comment left during a code review.
Path: tests/lib/test_tutorial_async_utils.py
Line: 67
Comment:
**Busy workers fail this test**
If a busy worker wakes more than two seconds after this test starts, the wall-clock check fails even though `wait_for_state_messages` honored its deadline. The root suite runs tests in parallel, so this can add an unrelated red test to the suite this PR aims to make more reliable. Check the deadline without requiring a fast wake-up.
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
There was a problem hiding this comment.
Fixed. The upper wall-clock bound is gone. The test now asserts only that the helper kept polling until the deadline (elapsed >= timeout) and returned the 1-message state. A late wake on a busy worker can no longer fail it.
fb2fe3d to
cffaa34
Compare
The async base tutorials sent the agent's reply, slept 1s, then asserted the task state held 3 messages. The agent persists the turn to state only after it sends the reply, so a slow model call left the read seeing the previous turn and failed with "assert 1 == 3". Add wait_for_state_messages to test_utils, which polls the state until it reaches the expected count or a 30s timeout, and use it in 010_multiturn and 020_streaming. A state that never updates still fails with its real length. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The lock change only rewrote the SDK's own recorded version (0.21.0 to 0.28.2), a side effect of a local uv run. The polling change doesn't need it, and leaving it in risks a conflict with the next release or reconcile commit that touches uv.lock. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
932cdb0 to
49ddd06
Compare
What
The async base tutorials
010_multiturnand020_streamingnow poll the task state instead of sleeping a fixed second before asserting it.Why
Each test sends an event, waits for the agent's reply, sleeps 1s, then asserts the task state holds 3 messages. The agent sends its reply first and persists the turn to state afterwards. When the model call is slow, the 1s read sees only the system message and the test fails with
assert 1 == 3. This shows up as random red Agent Integration Tests on unrelated server PRs.How
test_utils/async_utils.py: newwait_for_state_messages, which polls the state until it reaches the expected count or a 30s timeout, then returns the last read.A state that never updates still fails, with its real length. The initial-state checks after task creation are unchanged.
Verification
tests/lib/test_tutorial_async_utils.py, new, 3 passed) against a fake client:ruff checkandpyrighton the changed files pass. All 52 CI checks passed on the first push.🤖 Generated with Claude Code

Confidence Score: 5/5
The PR appears safe to merge; both earlier findings are addressed and no new issue was found in this PR’s changes.Fix with agent prompt
Summary
The
010_multiturnand020_streamingtutorial tests now poll task state before checking for three messages, since an agent reply can arrive before the turn is saved.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR A[Agent replies] --> B[Poll task state] B --> C{Three messages yet?} C -- Yes --> D[Check messages] C -- No, time remains --> B C -- No, deadline passed --> DReviews (5) · Last reviewed commit: "chore(tutorials): drop the unrelated uv...." · Reviewed by Greptile