Skip to content

fix(opencode): show reset time on free usage limit - #53254

Closed
werlang wants to merge 2 commits into
anomalyco:devfrom
werlang:free-reset-message
Closed

werlang wants to merge 2 commits into
anomalyco:devfrom
werlang:free-reset-message

Conversation

@werlang

@werlang werlang commented Oct 5, 2026 •

Copy link
Copy Markdown

Issue for this PR

Fixes #52894

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Free 429s showed a static message with no reset time while Go limits render "It will reset in X" from retry-after. This reuses the same formatting for FreeUsageLimitError, falling back to the static message when the header is absent or malformed. Go output is unchanged for valid headers (same helper, same tests).

Follow-up fixes review findings: strict non-negative-integer validation and total-minutes rounding (3599s renders as 1 hour, not 60 minutes).

How did you verify your code works?

  • bun test test/session/retry.test.ts (64 pass, 0 fail, incl. 4 new tests)
  • bun run typecheck in packages/opencode (clean)
  • bun run lint on both touched files (0 errors, 2 pre-existing warnings)
  • git diff --check (clean)

Screenshots / recordings

N/A - non-UI change.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Copilot AI balanced review requested due to automatic review settings October 5, 2026 01:31
@github-actions

github-actions Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

The following comment was made by an LLM, it may be inaccurate:

Copilot AI 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.

Copilot review overview

🟡 Changes recommended

Reset formatting accepts malformed values and can produce impossible durations such as “60 minutes.”

Review effort: Balanced
Findings: 2 Medium severity

Open (2)
What changed in this PR

Adds reset-time details to free-tier usage-limit messages while preserving the static fallback.

Changes:

  • Reuses reset-time formatting for free and Go limits.
  • Adds free-limit reset and fallback tests.
File Description
packages/​opencode/​src/​session/​retry.ts Formats reset times in free-limit messages.
packages/​opencode/​test/​session/​retry.test.ts Tests reset and fallback behavior.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread packages/opencode/src/session/retry.ts Outdated
Comment on lines +153 to +154
const retryAfter = num(value)
if (retryAfter === undefined) return ""

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done - resetText now requires the header to match /^\d+$/ so malformed or negative values fall back to the static message.

Comment thread packages/opencode/src/session/retry.ts Outdated
Comment on lines +155 to +162
const seconds = Math.max(0, Math.ceil(retryAfter))
const days = Math.floor(seconds / 86_400)
const hours = Math.floor((seconds % 86_400) / 3_600)
const minutes = Math.ceil((seconds % 3_600) / 60)
const unit = (count: number, name: string) => `${count} ${name}${count === 1 ? "" : "s"}`
if (days > 0) return hours > 0 ? `${unit(days, "day")} ${unit(hours, "hour")}` : unit(days, "day")
if (hours > 0) return minutes > 0 ? `${unit(hours, "hour")} ${unit(minutes, "minute")}` : unit(hours, "hour")
return minutes > 0 ? unit(minutes, "minute") : "less than a minute"

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Done - rounds to total minutes first, so 3599s renders as 1 hour instead of 60 minutes. Covered by a new regression test.

@thdxr

thdxr commented Oct 10, 2026

Copy link
Copy Markdown
Member

This branch has been upgraded to V2. We're no longer taking PRs for V1. If you think this is still relevant, please port it over and open it for V2.

— from 𝕺𝖕𝖊𝖓𝕮𝖔𝖉𝖊

@thdxr thdxr closed this Oct 10, 2026
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.

[FEATURE]:Show exact free usage limit reset time

3 participants