Skip to content

Credit-tracking follow-ups: phone Settings, expired session key, stale strip, live credit shapes - #9

Open
ninedter wants to merge 3 commits into
claude/llm-tracker-credit-tracking-6c9819from
claude/credit-tracking-followups
Open

ninedter wants to merge 3 commits into
claude/llm-tracker-credit-tracking-6c9819from
claude/credit-tracking-followups

Conversation

@ninedter

Copy link
Copy Markdown
Owner

Stacked on #6. Review and merge that first; this PR then retargets to main.

Four items that were parked during the add-on credit work.

1. Settings overflowed at 375px

The page was 408px wide on a 375px viewport. The page container (mx-auto max-w-3xl) is an auto-margin item in the layout's flex column. Without w-full it took its content's min-width: first the Font Size row, then the Hub URL row. It now has w-full, the same as the other pages. The font-size row also wraps now, and the preview path breaks anywhere. Checked in the browser: scrollWidth 375/375.

2. Expired claude.ai session key while OAuth still works

  • ClaudeUsageData.sessionKeyExpired is set when a credit endpoint returns 401/403 and none of them succeeds. A lone 403 next to a 200 is more likely an endpoint this org can't use.
  • After that, the two credit endpoints are skipped for 15 minutes instead of being called on every poll. The backoff is keyed by the session key, so saving a new key in Settings retries right away.
  • The Claude card's Add-on credits section and Settings → Connection Status (ProviderHealthEntry.warning, amber dot) show: "claude.ai session key expired: prepaid balance unavailable. Update it in Settings."

3. Monitor strip showed stale numbers after credentials were deleted

dataUnlessUnconfigured() (src/lib/usage/stale-data.ts) drops a provider's row on MISSING_CREDENTIALS, the same way the dashboard cards switch to their setup placeholder. Other errors still keep the last data.

4. Live claude.ai credit shapes

I probed /usage, /prepaid/credits and /overage_spend_limit with a saved session key. Only shapes, enums and equality checks were printed, never values or the key.

  • Units are cents. Prepaid amount equals balance.credits.amount_minor, and spend-limit monthly_credit_limit equals cap.credits.amount_minor; both have exponent: 2. Currency is an ISO code (USD). The parser now uses extra_usage.decimal_places or the balance/cap exponent when present, and falls back to /100.
  • False "Out of credits". overage_spend_limit.out_of_credits was true while extra usage was switched off (disabled_reason: self_selected_spend_limit_reached, nothing used this period). The card would have shown a red pill next to "Extra usage is off". It's now only flagged while extra usage is enabled, and extra_usage.spend_limit_reached (a new field) takes precedence.
  • A $0 prepaid balance no longer hides extra-usage headroom in the Monitor strip summary. The card still shows the $0.00.

Verification

  • npm test: 317 passed (new client, health route, parser, credit-summary and stale-data tests)
  • npm run test:edge: 84 passed
  • npx tsc --noEmit, npm run lint, next build: clean

The session-key hint (item 2) is covered by unit tests but wasn't seen in a browser. The saved key is still valid, so the expired state couldn't be reproduced live.

🤖 Generated with Claude Code

ninedter and others added 3 commits October 20, 2026 14:39
…ey, stale strip)

- Settings: the page container was an auto-margin flex item without w-full,
  so it sized to its content's min-width (408px at a 375px viewport). Add
  w-full like the other pages; let the font-size row wrap and the preview
  path break.
- Claude: when the credit endpoints reject the saved claude.ai session key
  (401/403 with nothing getting through), flag sessionKeyExpired on the usage
  data and skip those endpoints for 15 minutes, keyed by the session key so a
  newly saved key retries at once. The Claude card and Settings connection
  status show a "session key expired, prepaid balance unavailable" hint.
- Monitor strip: drop a provider's row once it reports MISSING_CREDENTIALS
  instead of showing the stale SWR data.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Checked against live responses with a saved session key (shapes only):
- Units: prepaid `amount` and spend-limit `monthly_credit_limit` equal the
  `amount_minor` of their balance/cap objects with exponent 2, so cents is
  right. Honor `extra_usage.decimal_places` and the balance/cap exponent when
  present instead of hard-coding /100.
- overage_spend_limit reports out_of_credits=true while extra usage is
  switched off (disabled_reason self_selected_spend_limit_reached, nothing
  used), which showed a false "Out of credits" pill. Only flag it while extra
  usage is enabled, preferring extra_usage.spend_limit_reached.
- An empty ($0) prepaid balance no longer shadows extra-usage headroom in the
  Monitor strip summary.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T06:48:45.598371Z 2487806 PR opened
🔒 Security Review ✅ Completed 2026-10-20T06:49:24.085878Z 2487806 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 24878060df

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +286 to +287
const sessionKeyExpired =
results.some((r) => r.authRejected) && results.every((r) => r.data == null);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Avoid treating mixed endpoint failures as expired credentials

When a valid session key gets a permission-related 403 from one credit endpoint while the other endpoint is unavailable with a 404, timeout, or malformed response, both data values are null and this marks the key expired. That is precisely the kind of endpoint-specific 403 the preceding comment recognizes, but the lack of a successful sibling response turns it into a false warning and suppresses both credit requests for 15 minutes. Require stronger authentication evidence, such as both endpoints rejecting authentication or validation through a session-wide endpoint, before setting sessionKeyExpired.

Useful? React with 👍 / 👎.

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