Skip to content

fix: require explicit wallet selection after account errors - #158

Merged
VickyXAI merged 2 commits into
BlockRunAI:mainfrom
KillerQueen-Z:fix/user-switching-audit
Sep 5, 2026
Merged

VickyXAI merged 2 commits into
BlockRunAI:mainfrom
KillerQueen-Z:fix/user-switching-audit

Conversation

@KillerQueen-Z

@KillerQueen-Z KillerQueen-Z commented Sep 5, 2026 •

Copy link
Copy Markdown
Collaborator

An API 401 or unsupported-endpoint 404 silently replayed the request against a wallet gateway; a 401 also switched the rest of the process to wallet billing. This follow-up to #157 returns account errors without changing payment methods. Users can explicitly retry with --wallet.

Invalid, empty or unreadable configured keys now stop with an actionable error instead of selecting a wallet or another saved account. Key saving, rotation and logout refresh the active credential. README and agent instructions describe API registration/top-ups and explicit switching. The wallet reservation boundary test now uses a fixed clock instead of relying on a 1 ms scheduling window.

Validation: build and all 724 local tests pass. New tests cover 401/402/404/429/500 without wallet replay, invalid env/file configuration, explicit --wallet and key rotation/logout across Solana and Base. The fallback tests failed before this patch. Production paid Anthropic Messages SSE and Surf calls now pass against api.blockrun.ai, with account credit snapshots and matching portal receipts. Follow-up coverage found the separate Messages 402 path still invoked wallet signing; preserve the gateway credit error and never sign a key-authenticated request. Its regression test failed before the fix. No real wallet transfers were executed.

Based on current main, rather than the older open #156. Automatic account-to-wallet fallback is deliberately removed because it changes who pays.

@VickyXAI
VickyXAI merged commit 11c53e7 into BlockRunAI:main Sep 5, 2026
6 checks passed
VickyXAI added a commit that referenced this pull request Sep 5, 2026
main went red on `the mode is read at call time, not captured at import`.
The code is right; the test was wrong.

#163 landed before #158, when invalidateKey() demoted a session to wallet
mode after a 401, so the test used it to prove the billing copy re-reads the
mode. #158 changed that on purpose: a rejected key now only refreshes the
credential, because an account failure is never permission to spend from a
wallet.

The property still holds — useWalletMode() (`--wallet`) is the lever that
actually flips the mode. The test now uses it, and additionally asserts that
invalidateKey() does NOT move billing to the wallet, so it cannot drift back.

Both directions are mutation-tested: freezing the mode at import fails it, and
restoring invalidateKey()'s old demotion fails it too.


Claude-Session: https://claude.ai/code/session_01Rm7cRGtC7wCofhYuHRo21h

Co-authored-by: 1bcMax <195689928+1bcMax@users.noreply.github.com>
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.

2 participants