Skip to content

fix(modal): sandbox lifetimes up to 24 h, never sign above the expected price (v3.49.28) - #248

Merged
VickyXAI merged 2 commits into
mainfrom
fix/modal-long-lifetime
Nov 13, 2026
Merged

VickyXAI merged 2 commits into
mainfrom
fix/modal-long-lifetime

Conversation

@VickyXAI

Copy link
Copy Markdown
Contributor

Problem

ModalCreate refused any timeout above 300 s and told the model "Gateway rejects values > 300 with HTTP 400". That is false: the gateways accept 10 to 86400 s and bill longer lifetimes hourly. Also:

  • The cost function decided flat vs hourly from size only, ignoring the lifetime, and had no CPU hourly rate. A 24 h CPU create would have reserved $0.01 against a $6.00 quote.
  • The client signed whatever the 402 asked. Nothing checked the quote against the price it had reserved.

Verified max lifetime (unpaid probes, 2026-11-13)

body sol.blockrun.ai blockrun.ai
{"timeout":86400} 402, amount 6000000 402, amount 2401000
{"timeout":86401} 400 too_big, maximum 86400 400 too_big, maximum 86400
{"timeout":5} 400 minimum 10 400 minimum 10
{"cpu":0.1} 400 minimum 0.125 402

Arc and nano carry the same schema (MODAL_MAX_CREATE_TIMEOUT_SECONDS = 86_400) and the same rates as sol.

Changes

  • Cap lifted to 86400 s (integer, min 10; cpu >= 0.125). Default is still 300.
  • Tool text now says timeout is the billed lifetime: flat only at <= 300 s, <= 1 CPU and <= 1024 MB. Anything else pays hourly x the full requested lifetime, upfront, never below flat, with no refund on early terminate. Examples: 600 s A100 = $1.17, 1200 s H100 = $3.00, 86400 s H100 = $216. The ModalExec text no longer says the sandbox dies at 300 s.
  • modalCreatePricing mirrors the gateway's getModalCreatePricing: the lifetime is part of flat eligibility, and CPU bills $0.25/h. Rates are sol/arc/nano's. Base's rates are lower, so these never under-reserve there.
  • Quote guard: postWithPayment(…, maxPriceUsd) reads the 402 amount before signing. If it is above list + $0.001 Base fee (rounded up, +1 atomic unit for the gateway's hourly round-up), or unreadable, nothing is signed or sent, and the call returns 402 quote_exceeds_expected. Create, exec, status, terminate and the session cleanup all pass their price.
  • Reservation: ModalCreate holds that same ceiling, not the list price.
  • The confirm dialog and the result show the billing mode (hourly: $9.00/h x 24.00 h, upfront, no refund…).
  • maxTimeoutSeconds in the signer is the x402 authorization window, not the sandbox lifetime, so it is unchanged. A comment now says so.
  • Release 3.49.28 (package.json, lockfile, CHANGELOG). Not published.

Tests

  • test/reservation.local.mjs (+10 tests): ceiling arithmetic; a quote over the ceiling is refused with no signer call and no paid request; refused at ceiling+1 and signed at the ceiling; the live sol and base quotes above all pass; an unreadable 402 is refused; ModalCreate sends timeout: 86400 unclamped and signs a $216 H100 quote; ModalCreate refuses a $6 quote for a default flat create; the reservation holds the hourly ceiling (a balance of $7.0005 refuses a $7 A100 hour); out-of-range timeout and cpu are rejected before any request.
  • test/local.mjs: hourly-at-any-size pricing, CPU included, and the flat floor.
  • Revert checks: with the guard disabled, 4 of the new tests fail. Holding the list price instead of the ceiling fails 1.
  • npx tsc --noEmit: clean. npm test: 970 pass, 0 fail. The root package has no lint script.

1bcMax added 2 commits November 13, 2026 23:28
…ve the expected price

The gateways accept create timeouts from 10 to 86400 s (probed 2026-11-13:
86400 -> 402 quote, 86401 -> 400 on sol.blockrun.ai and blockrun.ai), but
ModalCreate refused anything above 300 s and told the model the gateway would
400 it.

- Lift the client cap to 86400 s (min 10, integer, cpu >= 0.125); default 300.
- Tool text explains timeout is the BILLED lifetime: flat only at <= 300 s,
  <= 1 CPU and <= 1024 MB; otherwise hourly x the full requested lifetime,
  upfront, never below flat, no refund on early terminate.
- modalCreatePricing mirrors getModalCreatePricing: the lifetime now decides
  flat vs hourly, and CPU sandboxes bill $0.25/h (a 24 h CPU create was
  priced $0.01 against a $6.00 quote).
- postWithPayment takes the expected list price and refuses to sign a 402
  quote above list + Base fee (or an unreadable one); all Modal calls pass it.
  ModalCreate reserves that same ceiling.
@VickyXAI
VickyXAI merged commit 5bae1e5 into main Nov 13, 2026
6 checks passed
VickyXAI added a commit that referenced this pull request Nov 14, 2026
…erminate refunds nothing (v3.49.29) (#249)

* fix(modal): fail closed without a price, report the settled amount, terminate 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.

* chore: release v3.49.29 — Modal: fail closed without a price, report the settled charge, terminate refunds nothing

---------

Co-authored-by: 1bcMax <viewitter@gmail.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.

1 participant