Repository navigation
test: make Codex rate-limit window checks deterministic - #2726
Conversation
|
Warning Review limit reachedYou'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. View limit details
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. |
|
@coderabbitai review |
Action not completed
|
|
@coderabbitai review |
Action not completed
|
|



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
Dateinside 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
pnpm --filter @simple-agent-manager/api lintpnpm --filter @simple-agent-manager/api typecheckThese 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-a3fc10d62102explicitly 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.mdSpecialist Review Evidence
Reviewed implementation
8c8b6a57bb2d03fe891ae557186f5cc27ea92a88; subsequent commit updates only the task's validation record.CodeRabbit Review Evidence
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
Classification
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.tsand its task record. The productionenforceRateLimitfunction is unchanged. Adjacent 429 tests gain the same deterministic clock.Documentation & Specs
Updated
tasks/active/2026-11-14-deterministic-codex-rate-limit-test.mdwith 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.