Skip to content

test: make Codex rate-limit window checks deterministic - #2726

Merged
simple-agent-manager[bot] merged 3 commits into
mainfrom
sam/deterministic-codex-rate-limit
Nov 14, 2026
Merged

simple-agent-manager[bot] merged 3 commits into
mainfrom
sam/deterministic-codex-rate-limit

Conversation

@simple-agent-manager

@simple-agent-manager simple-agent-manager Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The Codex refresh-lock rollover test can calculate its expected minute before asynchronous credential setup and execute the request in the next minute. PR #2722's CI retry observed exactly this 60-second assertion difference.

Freeze only Date inside the rate-limit test group and restore it after each test. Exercise exhausted previous-window buckets one millisecond before, exactly at, and one millisecond after a controlled minute boundary. Keep the exact status, counter, and window assertions. Production code is unchanged.

PR #2722 remains unchanged at coordinator-approved 5b86fdd85ad6a2451c0671532abf4afd7ae7c8f1. Coordinator approved PR #2726 at exact head8462cbd33bec9ad5c5e8601bd7e8083de7c6579a in verified SAM evente4bf5532-0425-4cc0-9c73-1876c9ec5527. Approval permits removing the hold, readiness, one CI refresh, and squash merge after green checks. Any new commit voids approval.

Validation

  • API lint: pnpm --filter @simple-agent-manager/api lint
  • API typecheck: pnpm --filter @simple-agent-manager/api typecheck
  • Full affected test file: 71/71 pass
  • Thirty independent full-file runs: 30/30 pass, 2,130 test executions; every run includes controlled clock offsets -1/0/+1 ms from a minute boundary
  • Mutation proof: temporarily remove the production window equality guard; all three rollover cases fail with 429 instead of 200. Restore production source byte-for-byte, confirm no production diff, and rerun the full file: 71/71 pass
  • All 11 API dependency package builds pass

These are controlled-clock boundary cases, not claims about OS process launch precision. All functional checks in CI run 43575982635 passed, including broad tests, all three Durable Object shards, build, lint, and typecheck. E2E smoke passed. Sonar passed with zero issues/hotspots. The initial preflight job rejected a missing checked classification in this description; metadata is corrected and its single job-only rerun132397850951 passed. The Specialist gate remains intentionally held by needs-human-review. The first local run needed generated worker-core artifacts; building the API dependencies resolved that setup prerequisite.

Staging Verification Evidence

N/A: test-only change. Coordinator event 0c278241-6b90-4569-8b77-a3fc10d62102 explicitly exempts this corrective PR from staging. No application, deployment, migration, configuration, or UI change. No staging resources provisioned.

UI Screenshot Evidence

N/A: no UI changes.

End-to-End Verification

Data Flow Trace

Existing tests invoke CodexRefreshLock.fetch, perform real SQLite/AES-GCM credential setup, and assert the stored rate-limit window and counter. Only external fetch and DO storage remain stubbed as before. No new system boundary.

Untested Gaps

This unit correction does not exercise runtime DO scheduling or change production rate-limit semantics.

Post-Mortem

What broke

CI run 43570510620 attempt 2 failed the rollover assertion, expected epoch 1794642300 versus actual 1794642360. The other 15,132 API tests and all 5,228 web tests passed.

Root cause

Expected-window setup and production window selection read the uncontrolled wall clock on opposite sides of awaited credential setup. A minute boundary can occur between them. No production rollover defect was found; the existing guard correctly resets stale buckets.

Class of bug

Uncontrolled wall-clock dependency across asynchronous test setup.

Why it wasn't caught

Ordinary executions within one minute passed; the test did not control the clock.

Process fix included in this PR

Scoped Date control, exact boundary cases, 30 repeated full-file runs, and a guard-removal mutation check. This localized correction requires no new standing guidance.

Post-mortem file

tasks/active/2026-11-14-deterministic-codex-rate-limit-test.md

Specialist Review Evidence

  • All local reviewers completed; no findings remain
Reviewer Status Outcome
test-engineer + cloudflare-specialist (local clock_test_review) PASS Date cleanup scoped correctly; real async timers retained; saturated stale buckets detect missing guard; real SQLite/crypto preserved
task-completion-validator (local clock_completion_review) PASS Research, diff, criteria, repeated runs, mutation failure, restoration, and final passing file verified; delivery hold remains

Reviewed implementation 8c8b6a57bb2d03fe891ae557186f5cc27ea92a88; subsequent commit updates only the task's validation record.

CodeRabbit Review Evidence

  • Trusted CodeRabbit request after CI/local gates
  • Waited about 15 minutes
  • Review findings resolved, or observed non-response recorded

CodeRabbit Notes

Trusted workflow43578598538 succeeded and posted request6874916787 at09:02:18Z. Draft label run43578596379 skipped. Bot6874918055 replied09:02:25Z: review rate limited. Reconciled at 09:19:22Z after more than 17 minutes: no submitted reviews or inline review comments; response remains rate limited. Request/wait complete. No re-trigger. Any later actual review remains binding before merge.

Exceptions

Staging exemption: test-only scope, coordinator event above. Full repository checks run in PR CI; local validation covers the affected API file, API lint/typecheck, and dependency builds. Coordinator exact-head approval is mandatory before ready/merge. After this correction merges, refresh #2722's merge ref once and require green checks before its approved merge.

Agent Preflight

  • Preflight completed before code changes

Classification

  • docs-sync-change

Test-only clock correction plus synchronized task validation/incident documentation. No external API, cross-component, runtime business logic, public surface, security model, UI, or infrastructure changes.

External References

N/A: existing local Vitest patterns and production source inspected; no external API integration.

Codebase Impact Analysis

Only apps/api/tests/unit/durable-objects/codex-refresh-lock.test.ts and its task record. The production enforceRateLimit function is unchanged. Adjacent 429 tests gain the same deterministic clock.

Documentation & Specs

Updated tasks/active/2026-11-14-deterministic-codex-rate-limit-test.md with the incident, clock rationale, 30 repeated runs, mutation proof, and review evidence. Public documentation and specs retain their existing runtime contracts.

Constitution & Risk Check

Simplicity and correctness: retain the existing runtime implementation, isolate clock control to the affected tests, preserve strict assertions and native async timers. Fixed times are test fixtures, not production configuration.

Coordinator review checkpoint: final gate summary sent for PR #2726 at full head 8462cbd33bec9ad5c5e8601bd7e8083de7c6579a. Exact-head coordinator approval received in evente4bf5532-0425-4cc0-9c73-1876c9ec5527; refreshing CI once before guarded squash merge. Any new commit voids approval.

Approved refresh completed: CI43580144038 and E2E43580144012 both SUCCESS, including Specialist and Preflight gates. Source remains exact approved8462cbd33bec9ad5c5e8601bd7e8083de7c6579a. Historical red Specialist result belongs to the earlier held run. No submitted reviews or inline findings at final reconciliation.

@simple-agent-manager simple-agent-manager Bot added the needs-human-review Agent could not complete all review gates — human must approve before merge label Nov 14, 2026
@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 21 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between c60e30e and 8462cbd.

Files selected for processing: 2

  • apps/api/tests/unit/durable-objects/codex-refresh-lock.test.ts
  • tasks/active/2026-11-14-deterministic-codex-rate-limit-test.md
  • 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

@simple-agent-manager simple-agent-manager Bot added the coderabbit-review Trigger CodeRabbit review for opt-in PRs label Nov 14, 2026
@raphaeltm

Copy link
Copy Markdown
Owner

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

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.

@simple-agent-manager simple-agent-manager Bot removed the needs-human-review Agent could not complete all review gates — human must approve before merge label Nov 14, 2026
@simple-agent-manager
simple-agent-manager Bot marked this pull request as ready for review November 14, 2026 09:21
@raphaeltm

Copy link
Copy Markdown
Owner

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Nov 14, 2026 •

Copy link
Copy Markdown
Action not completed

Review rate limited.

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.

@sonarqubecloud

Copy link
Copy Markdown

@simple-agent-manager
simple-agent-manager Bot merged commit fb2cb3a into main Nov 14, 2026
87 of 91 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coderabbit-review Trigger CodeRabbit review for opt-in PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant