Skip to content

fix(modal): fail closed without a price, report the settled charge, terminate refunds nothing (v3.49.29) - #249

Merged
VickyXAI merged 2 commits into
mainfrom
fix/modal-glm-review-followups
Nov 14, 2026
Merged

VickyXAI merged 2 commits into
mainfrom
fix/modal-glm-review-followups

Conversation

@VickyXAI

Copy link
Copy Markdown
Contributor

Follow-ups from the GLM 5.3 review of #248. Each finding was checked against the code before it was fixed; all six held up.

Fixes

  1. (P2) ModalTerminate text taught usage billing. It said "Modal bills wall-clock GPU time until the sandbox terminates". ModalCreate charges the full requested lifetime upfront and terminate refunds nothing. The new text says terminate stops the sandbox, frees its resources and refunds nothing, and that the timeout should be chosen at create. I searched the repo for the same claim: the tool-guard exemption comment ("orphan sandboxes keep billing GPU time"), the tracker comment and the terminateAllSessionSandboxes docstring had it too, and all are fixed. The old text also said "Session-end auto-cleanup also calls this". That is false: terminateAllSessionSandboxes has no caller, because the vscode-session.ts hook it was written for no longer exists. The claim is removed. Wiring that cleanup up is not part of this PR.
  2. (P3, guard bypass) gpu: "". Tier "" had no price, so the confirm dialog threw a TypeError. With no dialog, hold(maxSignableUsd(undefined)) threw inside a swallowed catch, and the call went out with no reservation and no quote ceiling. Fixed by failing closed at every layer:
    • A blank, whitespace-only or null gpu means CPU. A non-string or unknown gpu (0, false, "cpu", "B200") is rejected before any request.
    • modalCreatePricing throws on an unknown tier. maxSignableAtomic throws on a non-finite or negative price.
    • ModalCreate computes the price and the ceiling before the dialog, and refuses if either fails. A throw from hold() is now a refusal instead of a fall-through.
    • postWithPayment takes maxPriceUsd as required, and refuses to sign (quote_exceeds_expected) when no ceiling can be computed. The old maxPriceUsd !== undefined skip is gone.
    • Found during the audit: walletReservation.hold(NaN) was granted, because every comparison with NaN is false. The NaN then poisoned the reserved total, so every later hold passed whatever the balance. hold() now throws on a non-finite amount.
  3. (P3) "charged:" and recordUsage used the Solana list price. Both now use x-blockrun-cost-usd first, then the 402 quote that was signed, then the list price labeled as an estimate (~$1.17 estimated (list price; ...), recorded with estimated=true). Base A100 600 s now reports $0.667667. Exec, status and terminate record the same way.
  4. (P3) exec/status/terminate held the bare list price. They now hold maxSignableUsd(price), which is the ceiling the guard may sign (list + $0.001 fee + 1 unit). This matches create.
  5. (P3) billingLine. modalCreatePricing returns flatFloor: true when a request is not flat-eligible but its hourly price is below the flat rate. The line then reads "flat floor: the hourly price for this size and lifetime is below the flat rate, ..." instead of quoting the flat-eligibility rule the request breaks.
  6. (P3) Terminate refusal reported as benign. A 402 (quote refusal or failed signing, so nothing was paid and the terminate never ran) or a 5xx is now isError: true, and the sandbox stays tracked. Other 4xx (already gone) are still benign and drop the sandbox from the tracker.

Not changed: the review also noted that create over-holds by the $0.001 Base fee on Solana. That is the intended err-tight behavior from #248, and an existing test pins it.

Tests

test/reservation.local.mjs adds 10 tests, one or more per finding. I revert-checked each fix: I reverted it in the source, rebuilt, confirmed the named test went red, then restored the file and confirmed it was byte-identical. All 10 reverts went red: terminate text; blank gpu reaching tier ""; skipping the guard without a price; a granted NaN hold; reporting the list price; the bare hold on exec, status and terminate, each reverted separately; the flat-floor wording; and a benign terminate refusal.

  • npm test: 980/980 pass
  • npx tsc --noEmit: clean

1bcMax added 2 commits November 14, 2026 02:37
…erminate refunds nothing

Follow-ups from the GLM 5.3 review of #248.

- ModalTerminate's text said Modal bills wall-clock GPU time until terminate.
  The whole lifetime is charged upfront at create and terminate refunds
  nothing; the text now says so, and drops the claim that session-end cleanup
  terminates forgotten sandboxes (terminateAllSessionSandboxes has no caller).
  Same fix in the tool-guard and tracker comments.
- gpu "" (or blank / null) priced tier "" as undefined: the confirm dialog
  threw, and headless the hold threw inside a swallowed catch, so the call ran
  with no reservation and no quote ceiling. Blank gpu is now CPU; a non-string
  or unknown gpu is rejected. modalCreatePricing throws on an unknown tier,
  maxSignableAtomic on a non-finite or negative price, hold() on a non-finite
  amount (a NaN hold was granted and poisoned the reserved total), ModalCreate
  computes price and ceiling before the dialog and refuses if either fails,
  and postWithPayment requires maxPriceUsd and refuses to sign without a
  computable ceiling.
- The "charged:" line and recordUsage reported the sol list price. They now
  use x-blockrun-cost-usd, else the 402 quote that was signed, else the list
  price labeled as an estimate (Base A100 600 s: $0.667667, not $1.17).
- exec / status / terminate hold the ceiling the guard may sign
  (list + fee + 1 unit), as create does.
- A create that is not flat-eligible but priced at the flat floor says
  "flat floor" instead of quoting the flat-eligibility rule it breaks.
- A 402 (quote refusal, failed signing) or 5xx on ModalTerminate is an error
  and the sandbox stays tracked; other 4xx stay benign.
…the settled charge, terminate refunds nothing
@VickyXAI
VickyXAI merged commit 7fa29c3 into main Nov 14, 2026
6 checks 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