Public: anyone can read this; the crew can change it.

A bet that would overrun the wallet is refused before it starts, naming the estimate and the balance #13623

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

A bet over the wallet was already refused before it started (from #13490). It answered 409 with a longer sentence, so this pull changes the status and the wording to match what #13604 asks for.

Notes

shipped production is serving it deploy 8e1361f

opened this

A bet over the wallet was already refused before it started (from #13490). It answered 409 with a longer sentence, so this pull changes the status and the wording to match what #13604 asks for. I ran bun test on test/bets.test.ts, test/bet-wallet-refusal.test.ts, test/tui-bets-wallet.test.ts and test/mcp-size.test.ts, plus tsc --noEmit and the gate; all pass. The check run you get on push covers the rest.

  • Status: a JSON client refused over the wallet now gets 422 instead of 409 (src/web/pages/bets.ts).
  • Sentence: it now reads "Estimate $X, balance $Y (after the bets already running): lower the share, or ask a site admin to raise your grant." (walletRefusal in src/crew/bets.ts). The MCP bet tool and the terminal show the same text.
  • Tests: the assertions in test/bet-wallet-refusal.test.ts, test/bets.test.ts and test/tui-bets-wallet.test.ts that pinned the old status and wording now pin the new ones. Those were the old behaviour, not new tests; I added no new test file.
  • Docs: docs/features/bets.md says 422 and quotes the sentence.
  • Race: nothing to change. backBet checks the wallet and marks the bet backed in one synchronous step with no await between them, and the wallet already counts bets already running. The existing test "two bets that each fit alone are refused together" covers this.

What I left alone:

  • A form submission on the page still redirects with the sentence as a flash on the bet rather than returning a 422 page. Only a client asking for JSON sees the 422.
  • I did not add test/bet-over-wallet.test.ts, because the existing wallet tests already cover each door.
  • I did not touch the terminal; the commit carries a No door: line saying why.

To try it, back a bet with an estimate above the balance with Accept: application/json and read the 422.

Closes #13604

2 earlier comments
commented

A bet over the wallet was already refused before it started (from #13490). It answered 409 with a longer sentence, so this pull changes the status and the wording to match what #13604 asks for. I ran bun test on test/bets.test.ts, test/bet-wallet-refusal.test.ts, test/tui-bets-wallet.test.ts and test/mcp-size.test.ts, plus tsc --noEmit and the gate; all pass. The check run you get on push covers the rest.

  • Status: a JSON client refused over the wallet now gets 422 instead of 409 (src/web/pages/bets.ts).
  • Sentence: it now reads "Estimate $X, balance $Y (after the bets already running): lower the share, or ask a site admin to raise your grant." (walletRefusal in src/crew/bets.ts). The MCP bet tool and the terminal show the same text.
  • Tests: the assertions in test/bet-wallet-refusal.test.ts, test/bets.test.ts and test/tui-bets-wallet.test.ts that pinned the old status and wording now pin the new ones. Those were the old behaviour, not new tests; I added no new test file.
  • Docs: docs/features/bets.md says 422 and quotes the sentence.
  • Race: nothing to change. backBet checks the wallet and marks the bet backed in one synchronous step with no await between them, and the wallet already counts bets already running. The existing test "two bets that each fit alone are refused together" covers this.

What I left alone:

  • A form submission on the page still redirects with the sentence as a flash on the bet rather than returning a 422 page. Only a client asking for JSON sees the 422.
  • I did not add test/bet-over-wallet.test.ts, because the existing wallet tests already cover each door.
  • I did not touch the terminal; the commit carries a No door: line saying why.

To try it, back a bet with an estimate above the balance with Accept: application/json and read the 422.

commented

Starting a bet whose estimate is above the wallet balance was already refused on main. This pull changes the status and the wording to what #13604 asks for.

The check failure was test/refusals-lead-somewhere.test.ts, which keys each refusal sentence by its text. It still held the old wording, so it saw the new sentence as unkeyed. I re-keyed that entry in test/refusals-lead-somewhere.test.ts and pushed. The test passes now, and I ran only that file. I haven't re-run the full check.

  • Status: a client asking for JSON gets 422 instead of 409 when the bet is over the wallet (src/web/pages/bets.ts).
  • Sentence: it now reads "Estimate $X, balance $Y (after the bets already running): lower the share, or ask a site admin to raise your grant." It comes from walletRefusal in src/crew/bets.ts, so the page, the MCP bet tool and the terminal all show the same text.
  • Tests: I edited the existing wallet tests that pinned the old status and wording: test/bet-wallet-refusal.test.ts, test/bets.test.ts and test/tui-bets-wallet.test.ts. I added no new test file.
  • Docs: docs/features/bets.md now says 422 and quotes the sentence.
  • Race: nothing to change. The wallet check and marking the bet backed happen in one synchronous step, and the wallet already subtracts bets that are running.

What I left alone:

  • A form submission on the page still redirects back with the sentence as a flash, not a 422 page.
  • The terminal has no code change. Its commit carries a No door: line, because it already shows the shared sentence.
  • I added no test/bet-over-wallet.test.ts.

To try it, back a bet over the balance with Accept: application/json and read the 422.

commented

I merged main into the branch and pushed it. The type check, the gate and the touched bet tests pass; I didn't run the full suite.

main had reworked the wallet code, adding walletEstimate, estimateLine and WALLET_WAY_OUT, plus the "Before you press" card. I took main's versions of src/crew/bets.ts, test/refusals-lead-somewhere.test.ts and docs/features/bets.md, then put my changes back on top:

  • Wording: the refusal sentence now reads "Estimate $X, balance $Y (after the bets already running): lower the share, or ask a site admin to raise your grant."
  • Status: a JSON client still gets 422 instead of 409.
  • Docs: the wallet line in docs/features/bets.md says 422 and quotes the sentence. The new "Before you press" paragraph is unchanged.
  • Test key: main's key in test/refusals-lead-somewhere.test.ts matches the way-out text, which I didn't change, so no edit was needed there.

I ran tsc --noEmit, bun scripts/gate.ts, test/bets.test.ts, test/bet-wallet-refusal.test.ts, test/tui-bets-wallet.test.ts, test/refusals-lead-somewhere.test.ts, test/mcp-size.test.ts and test/bet-estimate-line.test.ts.

Approved

Small, single-purpose change that does what #13604 asks. JSON clients refused over the wallet get 422, and the sentence now leads with "Estimate $X, balance $Y". The sentence comes from one function, so the page flash, MCP and terminal show the same words. The existing tests and docs/features/bets.md are updated to match, and the how-to stays out of README. The page is still a form POST that redirects with a flash on the bet. That works without JavaScript, with no layout change. The race is covered by the existing test "two bets that each fit alone are refused together".

Two things I would do next:

  1. Add a test that asserts the 422 JSON body and that no run or queue row exists after a refusal. The issue names that as its done condition, and today the status is only pinned inside the door test.
  2. Put the figures first in the flash so a phone reader sees them before the way-out text. Check that the flash on the bet wraps at 360px without pushing the Back it button off screen.
Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs