Skip to content

fix(db): ignore non-finite rate_limited_until writes, preserve null clear - #12788

Open
maxmad64bis wants to merge 1 commit into
diegosouzapw:release/v3.8.51from
maxmad64bis:fix/ratelimit-write-guard
Open

fix(db): ignore non-finite rate_limited_until writes, preserve null clear#12788
maxmad64bis wants to merge 1 commit into
diegosouzapw:release/v3.8.51from
maxmad64bis:fix/ratelimit-write-guard

Conversation

@maxmad64bis

@maxmad64bis maxmad64bis commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

⚠️ base-red inherited: #12732

Summary

Rate-limit cooldowns are timestamps in the database, and until now any value got written — including ones that make no sense, like NaN, or ones already in the past. A stale write could leave a connection looking locked (or unlocked) at the wrong time. Now only future timestamps are stored; anything expired or invalid is quietly skipped, and clearing a cooldown works exactly as before.

Related Issues

Validation

  • Change type: DB
  • Focused tests and category gates from the golden path
  • npm run lint
  • Reconciled with the current active release base; focused checks rerun afterward
  • Production-code changes include a new or updated automated test in this PR

Tests Added Or Updated

  • tests/unit/db-rate-limit-guard.test.ts (new) — 6 cases: NaN ignored, ±Infinity ignored, past/0 ignored, future writes through, null clear preserved, expired write doesn't overwrite a live row (6/6 pass; 3 fail before the guard as designed)
  • Neighbors green: every suite under tests/unit that calls setConnectionRateLimitUntildb-providers-crud, db-providers-split, antigravity-429-quota-cooldown, persist-429-cooldown-account-fallback, cooldown-epoch-string-3954, mark-account-unavailable-numeric-epoch-guard (82/82 pass)

Coverage Notes

  • Changes src/lib/db/providers/rateLimit.ts (one fused guard + comment at the head of setConnectionRateLimitUntil; readers, markConnectionRateLimitedUntil, and clearConnectionRateLimit untouched). Covered by the new test file; no new branches beyond the guard itself.

Reviewer Notes

  • One deliberate call: past timestamps are noops rather than implicit clears, so an expired write can never overwrite a live future row — the only clear path stays null via clearConnectionRateLimit. If any caller relied on writing the past to "unlock" a row, that pattern now needs an explicit clear (no such caller found in the test suites above).
  • No migrations, no flags, no routing changes. Single commit.

@maxmad64bis
maxmad64bis force-pushed the fix/ratelimit-write-guard branch from d86ca05 to 324d36f Compare September 5, 2026 10:19
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