Skip to content

Clear the out-of-credits error once the account can pay again - #190

Merged
jelveh merged 4 commits into
mainfrom
clear-credit-error-after-upgrade
Nov 20, 2026
Merged

jelveh merged 4 commits into
mainfrom
clear-credit-error-after-upgrade

Conversation

@jelveh

@jelveh jelveh commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

The red "not enough credits" card stayed in the chat after the user upgraded or bought credits, above the build that went on. It is saved in the chat history, so it also came back on every reload.

Changes

  • clearCreditErrors() (app.js) removes the out-of-credits cards and the usage-limit "Upgrade / Add credits" cards from the chat, marks the saved entries creditErrorCleared and saves the chat. During a running build, the build's next save writes the mark.
  • It runs when a subscription upgrade is detected (completeUpgrade), a top-up completes (openTopUp), or the focus check finds a plan change or bought credit (consumePaidAfterLimit).
  • loadChat skips cleared entries. They stay in the history the AI reads, so it still knows why the build stopped, and deleting them could leave two user messages in a row.
  • New out-of-credits errors are saved with creditError: true. Errors saved before this change are matched by their text. The live card gets a credit-error class from the same test a reload uses (isCreditErrorEntry), so an out-of-credits text without Puter's code also leaves the chat right away.
  • If the removed card's button had focus (the user paid from it), focus moves to the composer after keyboard use, so it doesn't fall to <body> and the success dialog has something to return focus to. After a tap it isn't moved, so a phone's keyboard doesn't pop up.
  • The focus check clears the cards only after confirming no newer limit hit was saved while it waited on Puter. A build that ran out again keeps its card.
  • prepareHistoryForAI removes both markers before the history goes to the AI.

Limits

  • Only the open project is cleared. An out-of-credits card in another project stays.

Testing

  • npm test passes, including the new test-clear-credit-errors and the added paid-check cases in test-usage-limit-unblock.
  • Not yet tried against a real upgrade in the browser.

The red "not enough credits" card stayed in the chat after the user
upgraded or bought credits, above the build that went on, and came back
on every reload since it is saved in the chat history.

An upgrade, a top-up, or a plan change noticed when the tab regains
focus now removes the out-of-credits and usage-limit cards from the
chat, and marks the saved entries so a reload doesn't draw them again.
The entries stay in the history the AI reads, so it still knows why the
build stopped. New errors are tagged creditError; older ones are matched
by their text.
A card whose text said out of credits, but whose error had no
insufficient_funds code or 402, wasn't tagged credit-error. After an
upgrade it stayed in the chat while its saved entry, told by its text,
was marked cleared, so it only went on the next reload. The live card is
now tagged by isCreditErrorEntry on the entry that is saved, the same
test a reload uses. Adds test-clear-credit-errors.
Paying from a card's own Add credits or Upgrade button leaves focus on
that button. clearCreditErrors removed the card, so focus fell to <body>:
the next Tab started over from the top of the page, and the success
dialog opened right after (completeUpgrade) remembered <body> as the
element to hand focus back to. After keyboard use focus now moves to the
composer. After a tap it isn't moved, so a phone's keyboard doesn't pop up.
consumePaidAfterLimit cleared the cards before it checked that no new
limit hit was saved while it waited on Puter. A build that ran out again
in that time had its new, current card removed and its entry marked
cleared, though the account couldn't pay. The cards are now cleared only
once the record the payment was measured against is the one consumed.
@jelveh
jelveh merged commit a5ca9e7 into main Nov 20, 2026
1 check passed
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