Skip to content

test flake: test_rate_limited_post_carries_retry_after gets 201 when the first POST takes 2s+ (pin the limiter clock) - #4020

Merged
jaylfc merged 1 commit into
devfrom
exec/tsk-k4bvzj
Oct 28, 2026
Merged

jaylfc merged 1 commit into
devfrom
exec/tsk-k4bvzj

Conversation

@jaylfc

@jaylfc jaylfc commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

CARD TITLE (intent, not commit subject): test flake: test_rate_limited_post_carries_retry_after gets 201 when the first POST takes 2s+ (pin the limiter clock)

Autonomous build of board card tsk-k4bvzj.

test: freeze limiter clock in test_rate_limited_post_carries_retry_after

The test was flaky on loaded runners because the first POST could take 2s+,
allowing the token bucket to refill and the second POST to succeed (201)
instead of being rate limited (429).

Fix: patch tinyagentos.rate_limit.time.monotonic to a fixed value before
constructing the RateLimiter, and tighten the retry-after assertion to
exactly 2 seconds.

20-run tally:
2 1 passed, 7 deselected in 3.57s
1 1 passed, 7 deselected in 3.59s
1 1 passed, 7 deselected in 3.60s
1 1 passed, 7 deselected in 3.66s
1 1 passed, 7 deselected in 3.67s
1 1 passed, 7 deselected in 3.73s
1 1 passed, 7 deselected in 3.74s
1 1 passed, 7 deselected in 3.77s
1 1 passed, 7 deselected in 3.83s
1 1 passed, 7 deselected in 3.85s
2 1 passed, 7 deselected in 3.88s
1 1 passed, 7 deselected in 3.93s
1 1 passed, 7 deselected in 3.99s
1 1 passed, 7 deselected in 4.05s
1 1 passed, 7 deselected in 4.07s
1 1 passed, 7 deselected in 4.08s
1 1 passed, 7 deselected in 4.31s
1 1 passed, 7 deselected in 4.51s

Files:
tests/test_routes_client_logs.py | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)

In-house review (pre-PR)

in-house-review: PASS (kilo/nvidia/nemotron-3-ultra-550b-a55b:free)

reviewer output

VERDICT: PASS

  • NIT: None. The diff correctly freezes the limiter clock before constructing RateLimiter, tightens the retry-after assertion to exactly 2, and updates the comment to reflect the frozen clock. All changes are confined to the specified test file as required.

In-house-Review: PASS model=kilo/nvidia/nemotron-3-ultra-550b-a55b:free head=3c3bc228d needs-lead=0

Summary by CodeRabbit

  • Tests
    • Improved rate-limit test reliability by checking that blocked requests return HTTP 429 with a consistent 2-second retry interval.

The test was flaky on loaded runners because the first POST could take 2s+,
allowing the token bucket to refill and the second POST to succeed (201)
instead of being rate limited (429).

Fix: patch tinyagentos.rate_limit.time.monotonic to a fixed value before
constructing the RateLimiter, and tighten the retry-after assertion to
exactly 2 seconds.

20-run tally:
      2 1 passed, 7 deselected in 3.57s
      1 1 passed, 7 deselected in 3.59s
      1 1 passed, 7 deselected in 3.60s
      1 1 passed, 7 deselected in 3.66s
      1 1 passed, 7 deselected in 3.67s
      1 1 passed, 7 deselected in 3.73s
      1 1 passed, 7 deselected in 3.74s
      1 1 passed, 7 deselected in 3.77s
      1 1 passed, 7 deselected in 3.83s
      1 1 passed, 7 deselected in 3.85s
      2 1 passed, 7 deselected in 3.88s
      1 1 passed, 7 deselected in 3.93s
      1 1 passed, 7 deselected in 3.99s
      1 1 passed, 7 deselected in 4.05s
      1 1 passed, 7 deselected in 4.07s
      1 1 passed, 7 deselected in 4.08s
      1 1 passed, 7 deselected in 4.31s
      1 1 passed, 7 deselected in 4.51s
@qodo-code-review

Copy link
Copy Markdown

ⓘ Qodo reviews are paused because your trial has ended. Ask your workspace admin to add credits to resume reviews. Manage billing

@coderabbitai

coderabbitai Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 23dfeda and 3c3bc22.

Files selected for processing: 1
  • tests/test_routes_client_logs.py

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

Walkthrough

The rate-limit test freezes the monotonic clock before sending two requests. It now requires the blocked response to return HTTP 429 with Retry-After set to exactly 2 seconds.

Changes: Rate-limit test

Layer / File(s) Summary
Freeze time and assert retry delay
tests/test_routes_client_logs.py
The test freezes time.monotonic at 1000.0 before sending two posts. It replaces the prior allowance of 1 or 2 seconds with an exact Retry-After assertion of 2 seconds.

Priority: Low

Estimated code review effort: 1 (Trivial) | ~3 minutes

Change: Bug fix

Merge Risk: Minimal · up to 3c3bc

The change removes elapsed-time sensitivity from the rate-limit test and checks the expected two-second retry delay. No actionable merge-blocking issue was identified; merge after normal checks pass.

Pre-merge checks: Passed 5
Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly identifies the flaky rate-limit test and the clock-freezing fix. It is specific to the main change.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files.

Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@gitar-bot

gitar-bot Bot commented Oct 27, 2026

Copy link
Copy Markdown

Important

You are using the Gitar free plan. Upgrade to unlock code review, CI analysis, auto-apply, custom automations, and more.

Gitar

@jaylfc

jaylfc commented Oct 28, 2026

Copy link
Copy Markdown
Owner Author

Lead review (tsk-k4bvzj): PASS. The diff does exactly what the card asked: it freezes the limiter clock before the bucket is built and asserts retry-after == 2. 35/38 checks are green. The 3 that are not are all CodeRabbit, which is rate-limited on this head.

Non-blocking note, carried to a follow-up: tinyagentos.rate_limit.time is the global time module, so this patch also freezes asyncio's loop clock (BaseEventLoop.time reads time.monotonic) for the rest of the test. That is harmless here because no timer runs between the two POSTs, and monkeypatch tears down before client. But an asyncio.sleep or wait_for added to this path later would hang. That instruction came from the card, not the lane.

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@jaylfc
jaylfc merged commit c44256e into dev Oct 28, 2026
49 of 52 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant