Skip to content

test(agents): rate-limit sleep test counts only the agent's own sleeps - #5355

Merged
kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:claude/fix-own-sleeps-flake
Oct 19, 2026
Merged

kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:claude/fix-own-sleeps-flake

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

test_rate_limit_wait_is_capped failed at random, most often on macOS CI (e.g. on #5337). The own_sleeps fixture patched time.sleep for every module. When logging on the test's thread waited on the log-rotation file lock, that lock's 5 ms retry landed in the list. The fixture now records only sleeps called from gaia.agents.base.agent, the code under test.

Reproduced by the new test_own_sleeps_ignores_sleeps_from_other_code_on_this_thread: it fails with the old fixture and passes here.

Test plan

  • pytest tests/unit/agents/test_loop_guard_correction.py: 42 passed
  • python util/lint.py --black --isort --pylint --flake8

own_sleeps patched time.sleep for every module, so when logging on the
test thread waited on the log-rotation file lock (a 5 ms retry), that
sleep landed in the list and test_rate_limit_wait_is_capped failed at
random, most often on macOS CI. It now records only sleeps called from
gaia.agents.base.agent.
@github-actions github-actions Bot added the tests Test changes label Oct 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Verdict: Approve

This should fix the flaky rate-limit test. The test's sleep recorder used to catch every pause on the test's thread, including the short retry the log-file lock makes while the agent logs "waiting…". It now counts only pauses made by the agent code under test. The new self-check fails with the old recorder and passes with this one, so the cause is pinned down, not just made less likely. No blocking issues.

Real-world evidence

N/A: this PR only changes tests, and no user-facing surface is affected. The verdict rests on static review. I could not run the suite here because pytest isn't installed on this runner. The author reports 42 passing.

🔍 Technical details

Issues found: none blocking.

  • 🟢 sys._getframe(1) resolves to the direct caller of time.sleep. That works today because _wait_out_rate_limit calls time.sleep(seconds) itself (src/gaia/agents/base/agent.py:11681). If that sleep moves into a helper in another module, the fixture will silently stop recording it, and test_rate_limit_wait_honours_the_cancel_event (which asserts == []) would still pass. test_rate_limit_wait_is_capped would catch the move, though, so this needs no change. Just keep it in mind.

Strengths

  • The fix targets the real cause: it filters by the calling module instead of loosening the assertion or adding a retry.
  • The self-check test reproduces the original failure, so a future change can't quietly bring the bug back.
  • The thread-identity guard stays in place, so stray sleeps from an earlier test's thread are still sent to the real time.sleep.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Oct 19, 2026
Merged via the queue into amd:main with commit b2bd122 Oct 19, 2026
27 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the claude/fix-own-sleeps-flake branch October 19, 2026 08:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants