Skip to content

fix(usage): parse numeric-string quota reset timestamps as Unix sec/ms - #4493

Merged
diegosouzapw merged 1 commit into
release/v3.8.33from
fix/port-pr-768-quota-unix-seconds
Jun 21, 2026
Merged

diegosouzapw merged 1 commit into
release/v3.8.33from
fix/port-pr-768-quota-unix-seconds

Conversation

@diegosouzapw

@diegosouzapw diegosouzapw commented Jun 21, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Ports an upstream fix — quota reset timestamp parsing for numeric-string Unix timestamps.

OmniRoute's parseResetTime already handled number Unix-seconds via the < 1e12 ? * 1000 : value heuristic, but the string branch passed everything to new Date(str). When a provider returned the reset timestamp as a numeric string (e.g. "1700000000"), new Date(str) returned Invalid Date, the try/catch swallowed it, and the reset window was silently dropped from quota snapshots (showing as "no reset" in the UI).

Numeric strings (/^\d+$/) are now detected and treated as Unix timestamps with the same seconds-vs-ms heuristic. ISO/parseable strings are untouched. Applied symmetrically in both open-sse/services/usage.ts::parseResetTime and open-sse/services/codexUsageQuotas.ts::parseResetTime.

Changes

  • open-sse/services/usage.ts — string branch detects /^\d+$/ and routes through the < 1e12 ms/sec heuristic.
  • open-sse/services/codexUsageQuotas.ts — same logic, refactored ternary into if/else for clarity.
  • tests/unit/usage-utils.test.ts — 2 new cases (seconds-string, ms-string) covering the gap.

Validation (Hard Rule #18 — TDD)

  • RED proof: before the fix, __testing.parseResetTime("1700000000") returned null (logged in PR work).
  • GREEN: after the fix, both new tests pass. node --import tsx/esm --test tests/unit/usage-utils.test.ts → 47/47.
  • Related quota/usage suites green: usage-extractor + quota-pool-usage-shape + copilot-usage + api-key-usage-limits → 27/27.
  • npm run typecheck:core → clean.
  • npm run check:docs-sync → PASS (41 i18n mirrors validated).
  • npx eslint on touched files → 0 warnings.

Attribution

Inspired by upstream contribution.

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the parseResetTime function in both codexUsageQuotas.ts and usage.ts to support parsing numeric strings as Unix timestamps, and adds corresponding unit tests. The review feedback suggests refining the generic digit regex to specifically match 10-digit or 13-digit timestamps to prevent false positives from other numeric date formats like YYYYMMDD.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

date = new Date(resetValue < 1e12 ? resetValue * 1000 : resetValue);
} else if (typeof resetValue === "string") {
// Numeric strings are Unix timestamps too (seconds or milliseconds).
if (/^\d+$/.test(resetValue)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using a generic /^\d+$/ regex matches any numeric string of any length. This can lead to false positives if a provider returns other numeric date formats (such as an 8-digit YYYYMMDD or a 14-digit YYYYMMDDHHMMSS string), which would then be incorrectly parsed as a Unix timestamp (e.g., 20260425 would be parsed as a timestamp in seconds, resulting in an incorrect date in 1970).

Restricting the regex to exactly 10 digits (seconds) or 13 digits (milliseconds) via /^\d{10}$|^\d{13}$/ is much more robust and specifically targets standard Unix timestamps while avoiding these false positives.

Suggested change
if (/^\d+$/.test(resetValue)) {
if (/^\d{10}$|^\d{13}$/.test(resetValue)) {

date = new Date(resetValue);
// Numeric strings are Unix timestamps too (seconds or milliseconds).
// `new Date("1700000000")` otherwise returns Invalid Date.
if (/^\d+$/.test(resetValue)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using a generic /^\d+$/ regex matches any numeric string of any length. This can lead to false positives if a provider returns other numeric date formats (such as an 8-digit YYYYMMDD or a 14-digit YYYYMMDDHHMMSS string), which would then be incorrectly parsed as a Unix timestamp (e.g., 20260425 would be parsed as a timestamp in seconds, resulting in an incorrect date in 1970).

Restricting the regex to exactly 10 digits (seconds) or 13 digits (milliseconds) via /^\d{10}$|^\d{13}$/ is much more robust and specifically targets standard Unix timestamps while avoiding these false positives.

Suggested change
if (/^\d+$/.test(resetValue)) {
if (/^\d{10}$|^\d{13}$/.test(resetValue)) {

@diegosouzapw
diegosouzapw changed the base branch from release/v3.8.32 to release/v3.8.33 June 21, 2026 14:02
`parseResetTime` in `open-sse/services/usage.ts` and `codexUsageQuotas.ts`
already handled `number` reset values with the `< 1e12 ? * 1000 : value`
seconds-vs-ms heuristic, but for `string` inputs it always called
`new Date(str)`. When a provider returned the reset timestamp as a
numeric string (e.g. `"1700000000"`), `new Date(str)` returned Invalid
Date, the try/catch swallowed it, and the function returned `null` —
the reset window was silently dropped from quota snapshots.

Numeric strings (`/^\d+$/`) are now detected and treated as Unix
timestamps with the same seconds-vs-ms heuristic. ISO/parseable strings
are untouched. Applied symmetrically in both parsers.

TDD: 2 failing tests added in `tests/unit/usage-utils.test.ts` for the
seconds-string and ms-string cases; both green after the fix (47/47 in
file, 27/27 in adjacent usage/quota tests).

Inspired-by: decolua/9router#768

Co-authored-by: Zhen <zhen@dkzhen.org>
@diegosouzapw
diegosouzapw force-pushed the fix/port-pr-768-quota-unix-seconds branch from add72d5 to 9db3c03 Compare June 21, 2026 17:05
@diegosouzapw
diegosouzapw merged commit cd45943 into release/v3.8.33 Jun 21, 2026
3 checks passed
diegosouzapw added a commit that referenced this pull request Jun 21, 2026
…4512)

Rebuilt onto release/v3.8.33; usage.ts baseline reconciled for the #4493/#4494/#4512 quota trio. Integrated into release/v3.8.33.
@diegosouzapw diegosouzapw mentioned this pull request Jun 22, 2026
@diegosouzapw
diegosouzapw deleted the fix/port-pr-768-quota-unix-seconds branch June 22, 2026 02:48
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
cheaper-inference#4493)

Rebuilt onto release/v3.8.33 (squash-base-stale). Integrated into release/v3.8.33.
tkgo11 pushed a commit to tkgo11/OmniRoute that referenced this pull request Sep 23, 2026
…heaper-inference#4512)

Rebuilt onto release/v3.8.33; usage.ts baseline reconciled for the cheaper-inference#4493/cheaper-inference#4494/cheaper-inference#4512 quota trio. Integrated into release/v3.8.33.
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