Commit Graph
3039 Commits
Author SHA1 Message Date
Daniel Salazar 5e5ad4953a perf(metering): read the global usage total as one paced listing (#4772)
Benchmarks / changes (push) Canceled after 0s
Benchmarks / bench shard 1/3 (push) Canceled after 0s
Benchmarks / bench shard 2/3 (push) Canceled after 0s
Benchmarks / bench shard 3/3 (push) Canceled after 0s
Benchmarks / benchmarks (push) Canceled after 0s
Notify HeyPuter / notify (push) Canceled after 0s
Backend Tests / changes (push) Canceled after 0s
Backend Tests / typecheck (push) Canceled after 0s
Backend Tests / test shard 1/4 (push) Canceled after 0s
Backend Tests / test shard 2/4 (push) Canceled after 0s
Backend Tests / test shard 3/4 (push) Canceled after 0s
Backend Tests / test shard 4/4 (push) Canceled after 0s
Backend Tests / test (main) (push) Canceled after 0s
Backend Tests / coverage (push) Canceled after 0s
getGlobalUsage got every shard of a month by key, 10,000 keys in batches
of 100 with several in flight. It now lists the shards by prefix, a page
at a time, and waits between pages so the read stays under a fixed
number of read units per second.

getGlobalUsageByMonth returns every month from the same listing, for a
caller that shows more than one.
2026-11-24 22:25:30 -07:00
Filip Kujundžić a53319baac fix(ai): reconcile Claude cache lifetimes from reported iterations (#4770) 2026-11-24 17:36:19 -07:00
Giridhar SriramanandClaude Opus 5.5 ae51c23978 fix(pagination): reject limits that floor below one (#4767)
normalizeLimit now floors before validating, so a fractional limit such
as 0.5 returns the same 400 as zero or a negative limit instead of
becoming 0 and failing keyset pagination.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-24 16:27:42 -07:00
404oops 8eb5a85223 Merge main into Kling model cleanup 2026-11-24 09:34:17 +01:00
Filip Kujundžić 70687abf06 Merge pull request #4760 from HeyPuter/fix/ai-model-monitor-alert-presentation
fix(ai): make model monitor alerts easier to read
2026-11-23 22:15:00 +01:00
404oops 37aa34c250 fix(ai): simplify model monitor alerts 2026-11-23 22:04:00 +01:00
Daniel Salazar 8969c8b3b4 refactor(backend): layer pass for duplicated logic, dead code and round trips, with the bugs it turned up (#4754)
* refactor(util): shared helpers for hosts, timeouts, chunking, paging, shutdown flush and codes

Adds normalizeHost/getPuterHostedDomains, withTimeout, chunk, nowSeconds,
isMissingTable, clampLimit/parsePageQuery/pageEnvelope, finalFlush,
parseRetryAfterMs/doublingBackoffMs, randomCode, sweepInBatches,
hashPassword/generateEmailConfirmCode, requestIp and isTemporaryAccount, and
removes util exports nothing called.

* refactor(clients,core): drop unread alarm state and dead shutdown paths, share host helpers

DynamoDB batches still throttled after the retries answer 503 db_unavailable.

* refactor(stores): one cache read per miss, tombstones on every write, batch methods for callers above

The multi-check permission cache is read with pipelined GETs. claimOwnership,
replaceDataUrlIcon and setLabel tombstone their keys. updateMetadata merges in
one statement. App stats reject an unknown period and cap grouped answers.

* refactor(services): fewer serial round trips in permission, share, metering and events paths

checkMany no longer caches a check that threw. Account deletion revokes its
sessions first. OIDC email_verified strings are read as booleans. Events
limits, FS service types and the events worker deployer live under services.

* refactor(drivers): one teardown path for workers, shared credit hold and provider helpers

A URL input and a generated-media download have a deadline and a size cap.
Azure chat clients take the shared client options. xAI and Mistral chat send
tools through toolsToWire and honor apiBaseUrl.

* refactor(controllers): shared download, paging and second-factor helpers, store methods for raw SQL

/batch answers a non-HTTP op error generically and logs it. /fs/search returns
the client entry shape. The unused /puterai/video/proxy route is removed.

* refactor: thumbnails accept raster types only, boot failure exits, docs for new limits

* fix: sessions stay listed after a rename, token grants follow the whole revoke cascade, app delete in one transaction

- listSessions asks the primary about rows marked as changed, so a renamed
  session stays on the list under its new label.
- The revoke cascade reports the access tokens it revoked, and their grants
  are dropped at any depth. The read before each revoke is gone.
- App delete records the deletion, clears filetype associations and deletes
  the row in one transaction.
- A local worker deploy waits for the runtime to start, so a script it cannot
  load fails the deploy.
- Speechify plain text: an & that starts no XML entity and a < that starts no
  complete tag are escaped.
- The events forward queue's byte bound counts UTF-8 bytes.
- Without a dedicated store, thumbnails stay in the default bucket.
- AppStore.invalidateWrittenByUid for writers that hold the uid.
- subdomainFromHost takes the configured domain list; the sorting wrapper only
  tests called is removed.
- Changelog and alarm docs match the code.

* fix: cache pipelines fall back to single commands across shards, TURN records metered one by one, allowance baseline kept

- execTogether runs single-key cache commands in one round trip and, on a
  cluster that cannot route them in one pipeline, sends each on its own. The
  row cache, tombstone reads and writes, the FS entry backfill, the permission
  check cache and the revoked-session cache write use it.
- TURN usage ingestion makes one metering call per user with each record as
  its own usage, so one malformed record does not affect the others.
- The allowance settlement keeps the baseline fold for month records without
  allowanceUsed.
- Speechify plain text keeps a self-closing tag without attributes.

* fix(localworker): a deploy waits for the runtime to start and a failed cold start answers 502

A script the runtime cannot load fails the deploy. What was serving before
goes back in place, and a first request for such a worker answers 502.

* fix(subdomains): the sites rooted under a folder are read in name order, a page at a time

subdomainsRootedUnder takes the name to start past, so a caller pages
through every match instead of stopping at one query's limit.
2026-11-23 14:00:35 -07:00
404oops b589060668 fix(ai): restrict Kling to verified video models 2026-11-23 21:45:34 +01:00
Filip Kujundžić c73cd4de51 feat(ai): refresh provider model catalogs and add Gemini Omni 1.2 (#4755) 2026-11-23 13:11:08 -07:00
54589ae1c2 fix(localworker): swap Miniflare instance before disposing previous one and dedupe concurrent cold starts (#4689)
* fix(localworker): swap Miniflare instance before disposing previous one and dedupe concurrent cold starts

* test(localworker): restore the service's tests and cover the swap on the real runtime

Brings back the existing LocalWorkerService tests and adds cases for a
request during a redeploy, concurrent first requests, and a retry after a
failed first deploy. The first-request deploy moves into its own method,
and both dispose paths share one helper.

---------

Co-authored-by: U-ITACHII <356922991+U-ITACHII@users.noreply.github.com>
Co-authored-by: Daniel Salazar <daniel.salazar@puter.com>
2026-11-23 11:57:39 -07:00
Daniel Salazar 5b8f4fb548 fix(apps): accept the Dev Center new-app placeholder as an index_url (#4757)
apps.create and apps.update refuse an index_url on the host of a godmode app. Dev Center points every new app at https://console.puter.com/coming-soon.html until its first deploy, and that page is on Dev Center's own host. That exact URL is now accepted. Any other URL on the host, including the placeholder with a query string or fragment, is still refused.
2026-11-23 11:34:46 -07:00
522c5af1a7 fix(puter-js): clear launch params from app tabs; private app sign-in keeps the tab's launch (#4743)
* fix(puter-js): clear launch params from an app tab's address bar

An app the desktop opens in its own browser tab removes the puter.*
params it was launched with from its URL after load. The app's own
params, utm_* and the hash stay; framed apps are unchanged.

The SDK reads launch items from the query it booted with, so
onLaunchedWithItems() and wasLaunchedWithItems() still see the opened
item after the URL changes.

* fix(puter-js): keep a tab's app id across a reload after the launch params are cleared

A godmode token doesn't name the app, so once the desktop answers a tab's
launch, the app id from the launch URL is stored the way a token's own app
id is.

* fix(hosting): a private app's sign-in page continues with the desktop's token and keeps the opened item

In a tab the desktop opened, the sign-in page waits for the desktop's
handoff, sends the handed token to its own URL in X-Puter-Auth-Token so
the host sets its cookie, then loads the URL the tab was opened at. The
token goes in the URL only after a redirect, a failed request, or on a
click after a header try didn't load the app.

Before leaving, the page keeps the opened item in sessionStorage, bound
to the launch and a fingerprint of the handed token, for 5 minutes. The
app's page takes it when it boots on that token in the same tab.

Reading sessionStorage for it can't stop the SDK from booting where
storage is blocked.

---------

Co-authored-by: Salazareo <25314977+Salazareo@users.noreply.github.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
2026-11-23 11:33:48 -07:00
Giridhar SriramanandClaude Opus 5.5 19ae43b02b fix(email): match blocked domains on a label boundary (#4647)
isBlockedEmail compared each blocked entry as a raw suffix of the whole
address, so `mailinator.com` also blocked `notmailinator.com` and a TLD
entry like `ru` blocked `site.guru`. A bare entry now matches the
address's domain exactly or as a parent domain. Entries containing `@`
or starting with `.` keep matching as written.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-23 11:25:37 -07:00
HanadHassan 19590857a6 test(ai): fail CI if the SDK timeout outgrows plain fetch's timeout (#4714)
The AI vendor SDKs use plain fetch, and nodeFetchDispatcherGuard gives it
a 10-minute header and body timeout. SDK_TIMEOUT_MS relies on that, but
nothing linked the two values, so raising SDK_TIMEOUT_MS above 10 minutes
would still be cut off at 10 with no error.

The guard now exports OUTBOUND_FETCH_TIMEOUT_MS, and sdkClient.test.ts
checks that SDK_TIMEOUT_MS isn't larger than it. No change in behavior.
2026-11-23 11:07:45 -07:00
HanadHassan 35f27bfa97 test(ai): benchmark a streamed chat completion through the credit gate (#4744)
No benchmark covered the AI path, so a change could add round trips
to a chat completion's rate limit, concurrency slot, credit gate, hold
or usage record without the comparison noticing.

Four scenarios now run a completion through the real gates and the
real credit hold against a local stand-in for the vendor: streamed and
unstreamed through /drivers/call, for an account on its allowance and
for one with purchased credit, and streamed through the OpenAI chat
completions route.
2026-11-23 11:07:32 -07:00
HanadHassan f8ead99d32 test(ai): stream two interleaved tool calls through the compatibility routes (#4739)
* test(ai): stream two interleaved tool calls through the compatibility routes

The route tests for the OpenAI chat, Responses and Anthropic messages
routes stub the chat driver, and the HTTP tests that run a fake vendor
through the real driver only stream text. Nothing checked that a
vendor's streamed tool calls reach a client of those routes intact.

A new HTTP test boots the backend, plays Chat Completions, Responses and
Anthropic vendors at the fetch boundary with two tool calls whose
arguments arrive in pieces, interleaved for Chat Completions, and
rebuilds the calls from each route's stream. The fuzz test's healthy
upstream answers a streamed request that offers tools with the same
fixtures, and the misbehaving case offers a tool on half its requests,
so corrupted tool-call streams are exercised too.

* test(ai): review follow-ups for streamed tool-call tests

The fuzz test fed Mistral the piece-by-piece Chat Completions fixture,
which Mistral's SDK rejects because it requires a name on every
tool-call delta, and the fuzz test still passed. Mistral now gets every
call whole in one chunk, the shape it sends, and the HTTP test gains a
Mistral row and a whole-calls row for the OpenAI SDK.

The piece-by-piece fixture now opens each call with empty arguments, as
OpenAI does. The HTTP test also checks that the chat route numbers calls
from 0 and sends a call's id and name only once, that Anthropic blocks
never overlap, and that each route ends its stream the way clients wait
for.
2026-11-23 11:07:15 -07:00
HanadHassan 0692132771 fix(ai): the Anthropic messages route keeps every piece of parallel tool calls (#4740)
The Anthropic stream writer can have one content block open, and a
tool_use_start for a second call closed the first call's block. Pieces of
the first call that arrived after that were dropped, and its closing
tool_use was skipped as already written, so a client got its input as
truncated JSON whenever an upstream interleaved two calls' arguments.

A call that starts while the open call's input is still incomplete JSON
now waits, collecting its pieces. When the open call ends, its block
closes and the next waiting call opens with the pieces it has so far,
then streams the rest live. A call that starts after the open call's
input is complete closes it and streams live as before, so calls sent one
after the other are not delayed. A whole tool_use that arrives while a
call is open waits the same way, calls without a distinct id never wait,
and calls still waiting when the message ends are written before
message_delta.
2026-11-23 11:07:12 -07:00
HanadHassan 4e82cd27df fix(ai): streamed tool calls keep their arguments when an upstream's deltas differ from OpenAI's (#4713)
* fix(ai): streamed tool calls keep their arguments when an upstream's deltas differ from OpenAI's

The OpenAI-compatible stream handler slotted tool-call deltas by index
alone and appended function.arguments as it arrived. Parallel calls that
shared an index, or sent none, merged into one block whose JSON could not
parse, and the second call was lost. A delta without arguments started the
buffer with "undefined", and object arguments, which Mistral's SDK allows,
became "[object Object]". Each reached the caller as a tool call with
input {}. A delta carrying both content and tool_calls emitted only the
text.

A delta with an index still continues the call at that index, unless it
brings a new id and its own name, which opens another call. A delta with
no index resolves by id, then to the call in progress. Arguments are read
as JSON text, and a delta's tool calls are handled after its text.
Arguments that still don't parse pass as {} as before, and the call's
name, id and length are logged.

* fix(ai): review follow-ups for streamed tool calls

Two calls that shared an index were told apart only when the second one
opened. After that the index pointed at the second call, so a later
delta carrying the first call's id was appended to the second, and both
came back with arguments that don't parse when their pieces alternated.

Each index now remembers the calls opened on it by id, and a delta whose
id matches one of them continues that call. The lookup stays within the
index, so calls at different indexes that repeat an id stay apart.
2026-11-23 11:05:57 -07:00
Daniel Salazar 0a5328bb24 fix: launch args decoded once, revoked sessions off the list, per-session socket eviction, writes into respelled folders, read URLs through folder access (#4752)
Backend Tests / changes (push) Canceled after 0s
Backend Tests / typecheck (push) Canceled after 0s
Backend Tests / test shard 1/4 (push) Canceled after 0s
Backend Tests / test shard 2/4 (push) Canceled after 0s
Backend Tests / test shard 3/4 (push) Canceled after 0s
Backend Tests / test shard 4/4 (push) Canceled after 0s
Backend Tests / test (main) (push) Canceled after 0s
Backend Tests / coverage (push) Canceled after 0s
Benchmarks / changes (push) Canceled after 0s
Benchmarks / bench shard 1/3 (push) Canceled after 0s
Benchmarks / bench shard 2/3 (push) Canceled after 0s
Benchmarks / bench shard 3/3 (push) Canceled after 0s
Benchmarks / benchmarks (push) Canceled after 0s
Notify HeyPuter / notify (push) Canceled after 0s
* fix: decode puter.args once and keep just-revoked sessions off the session list

* fix(socket): a session revoke drops only that session's sockets; the GUI reconnects after a server disconnect

* fix(fs): a write into a folder spelled in another case or form lands under the folder's stored path

* fix(auth): access tokens for fs: scopes accept access held through a parent folder

* docs(changelog): read URLs through folder access and writes into respelled folders

* style: format

* fix: address review — stored paths for created parents, batch alias dedupe, uid-only ACL mint, scoped socket eviction fallback, events suites

* test(fs): build the legacy respelled-descendant rows directly

* fix: address second review — refuse duplicate overwrite targets before upload, reuse ensured folders, check stored path length, match created folders by entry, decode a doubly encoded API origin

* docs(changelog): file this PR's entries under its merge day
2026-11-22 13:40:24 -07:00
Filip Kujundžić 30da7a8b0c Merge pull request #4741 from HanadHassan/HH/responses-final-arguments
fix(ai): the Responses route gives a streamed function call its arguments in the finished item
2026-11-22 15:18:47 +01:00
Hanad Hassan 8cd680fb60 fix(ai): the Responses route gives a streamed function call its arguments in the finished item
The Responses route asks the driver to stream tool input, so every
function call starts with tool_use_start, even from an upstream that
sends the call whole. The route added each call to the response output
with empty arguments and sent the pieces only as
function_call_arguments.delta events. The items in
response.output_item.done and in the output of response.completed kept
arguments "", so a client that reads the finished response rather than
the deltas, such as the OpenAI SDK's finalResponse() or the Agents SDK,
got every streamed tool call with no arguments.

When the call ends, its item now takes the arguments the route collected
for it, before the done events are sent.
2026-11-21 18:59:43 -07:00
Hanad Hassan 20d11ebf18 perf(ai): the chat model listing is built when the model map changes, not on each request
The chat driver rebuilt its model listing on every call to models() and
list(): it flattened the model map, visiting each model once per name it
answers to, dropped the repeats, applied the listed rates and sorted.
The map only changes at boot and on the fifteen-minute refresh, and the
routes that serve the listing are public.

The listing is now built when the model map is swapped and both methods
return it. A scheduled price change still takes effect at its instant:
the listing records the span of time its rates hold for and is rebuilt
from the current map on the first call outside that span. The returned
arrays are frozen, since every caller now shares them. What the routes
return is unchanged.
2026-11-21 18:02:54 -07:00
414090bb36 fix(ai): bill Mistral OCR for a page count a document can have (#4734)
* fix(ai): bill Mistral OCR for a page count a document can have

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* fix(ai): retry a chat credit hold apart from lost headroom when the balance changed

A conditional hold refused because the balance changed since it was read
is now reported as 'stale', separately from one that no longer fits. The
chat gate reads the balance again for it, up to five times with a short
randomized wait, without spending the tries a lost headroom gets, and
refuses with a plain 429 rather than credits_reserved if it never holds
still.

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
Co-authored-by: Daniel Salazar <daniel.salazar@puter.com>
2026-11-21 15:52:17 -07:00
Filip KujundžićandClaude Fable 5.2 0dbf84bc3e fix(ai): give Cloudflare image requests a timeout and a reply size cap (#4733)
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:52:17 -07:00
Filip KujundžićandClaude Fable 5.2 9e1ee69ac5 fix(ai): bill no more Replicate runtime than a prediction is given (#4732)
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:52:17 -07:00
Filip KujundžićandClaude Fable 5.2 24bc88b451 fix(ai): keep a failed model map build from leaving an unhandled rejection (#4731)
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:52:16 -07:00
Filip KujundžićandClaude Fable 5.2 16419dc951 fix(ai): reserve chat and video credits only while they still fit the balance (#4730)
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:52:16 -07:00
Filip KujundžićandClaude Fable 5.2 02a2d87d5e test(ai): fuzz vendor replies, gateway catalogs and recorded usage (#4729)
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:52:16 -07:00
Filip KujundžićandClaude Fable 5.2 3b5d6619dd fix(ai): classify malformed text-to-speech provider replies (#4728)
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:52:15 -07:00
Filip KujundžićandClaude Fable 5.2 ec8789e9fa fix(ai): classify malformed video provider replies (#4727)
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:52:15 -07:00
Filip KujundžićandClaude Fable 5.2 d60b909e83 fix(ai): classify a malformed Gemini image reply (#4726)
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:52:14 -07:00
Filip KujundžićandClaude Fable 5.2 b0df774be7 fix(ai): classify malformed image provider replies and options (#4725)
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:52:14 -07:00
Filip KujundžićandClaude Fable 5.2 2f43d618ae fix(ai): reject a Claude 2xx answer that isn't a message object (#4724)
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:52:14 -07:00
Filip KujundžićandClaude Fable 5.2 2798d721e0 fix(ai): record no usage for a provider count that isn't a positive number (#4723)
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:52:13 -07:00
Filip KujundžićandClaude Fable 5.2 d8bb1b3570 fix(ai): hold billed transcription seconds to what the audio can contain (#4722)
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:52:13 -07:00
Filip KujundžićandClaude Fable 5.2 f244f5d27e fix(ai): skip gateway catalog entries the chat model map can't use (#4721)
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:52:13 -07:00
Filip KujundžićandClaude Fable 5.2 3d300fae5c fix(ai): answer an unreadable 2xx JSON body from Mistral with a 502 (#4720)
Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:52:12 -07:00
Filip KujundžićandClaude Fable 5.2 61c5186f4f fix(ai): meter Gemini thoughts and audio input separately (#4717)
* fix(ai): meter Gemini thoughts and audio input separately

* fix(ai): schedule Gemini legacy redirect pricing

* fix(ai): keep video in Gemini conversations that contain audio

The native Gemini adapter maps video data URLs to inline data for the
models whose audio input it serves, so a conversation with both audio
and video is sent to Google instead of failing with 400.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

* fix(ai): meter Gemini audio by content, send video and Puter file audio

Audio and video data URLs count as audio and video input whatever part
carries them, and the input check runs again once Puter files are read.
Gemini 2.5 Flash and Flash-Lite requests with video use the native API
so the audio track is metered at the audio rate. Remote video URLs are
fetched and inlined for Gemini, video reaches the compatible endpoint
in the part it reads, and audio inlined from a Puter file is sent as
bare base64 with a wav or mp3 format. The native adapter answers 400
for a tool call without a function name and no longer fails on a tool
call id or image URL that is not text.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-21 15:52:12 -07:00
Daniel Salazar 4a13169815 fix(s3): close pooled connections before S3 drops them; name the host and site owner on error alarms (#4749)
* fix(s3): close pooled connections before S3 drops them

S3 hangs up on a keep-alive connection that has been idle for about 6 s and
sends no keep-alive hint, while the client's pool kept idle sockets
indefinitely. A request written to a socket as S3 closed it failed with
`socket hang up`, and the SDK's retries could draw more sockets of the same
age from the pool and fail the same way.

The pool now closes a socket after 4 s idle. Requests in flight keep the
handler's own socket timeout. Plain-HTTP endpoints get the same pool settings
as HTTPS ones.

* feat(alarms): name the host and a hosted site's owner on HTTP error alarms

A hosted site's visitor is usually anonymous, so an error alarm for a site
request named nobody, and its path alone did not say which site failed. The
site middleware now records the owner as the actor to report a failure
against, used when the request has no actor of its own, and every HTTP error
alarm carries the request host.
2026-11-21 15:51:19 -07:00
Daniel Salazar 5b8e0576fd feat(auth): the SMS-to-card fallback follows what the account owes (#4748)
A card stands in for the phone step only on an account that neither owes a
card nor has verified one. A number on file is still stood in for by the card
on file. An account that owes both keeps both steps.

`puter.phone-verification.check` gains two optional fields:

- `countsTowardFallback: false` keeps a refused send out of the count that
  opens the fallback. Refused sends count by default, as before.
- `refuseWithoutFallback` keeps a `card_fallback_instead` refusal in place
  when there is no fallback to offer, instead of letting the send through.

GUI: a message for a card the verification doesn't accept, and the
virtual-number message no longer mentions a card (the card link shows on its
own when one is offered).
2026-11-21 15:45:32 -07:00
Daniel Salazar 78a7400c98 feat(auth): an extension can switch the SMS-to-card fallback on or off over config (#4747)
Adds the puter.card-fallback.policy event, asked before
phone_verification_card_fallback.enabled is read. A listener that sets
enabled decides in place of config; with none, config decides as before.
2026-11-21 14:41:15 -07:00
Daniel Salazar af15ba8bfb feat(auth): proof on file signs out other sessions; a sign-in reads the team seat once (#4719)
* perf(auth): a sign-in reads the team seat once; validate event carries request signals

- The seat a sign-in reads for its listeners is handed to the account
  payload it builds afterwards, instead of being read again: one cache read
  and, for an account with no seat, one database read fewer, and two fewer
  serial stages.
- puter.signin.validate carries `request_signals`, every signal the edge
  proxy raised on the request.
- A card step on an account that already has a card asks for that card,
  entered again, the way a number on file asks for its number.

* feat(auth): proof of the phone or card on file belongs to the session that gives it

A sign-in made while the account owes proof of its phone or card on file
doesn't have its device remembered, and its session is noted. When a
session proves the phone or card, its device is remembered then, and every
other session opened while the proof was owed is revoked before the gate
clears, so clearing it from one session can't let another one in.

* fix(auth): proving the phone or card on file signs out the account's other web sessions

The proving session keeps its sign-in and is the only device remembered. A
sign-in that completes after the proof was given is not kept and is asked to
sign in again. If the other sessions can't be signed out, the gate goes back
on and the request fails.

* fix(auth): other sessions are signed out before the on-file gate clears; the phone proof counts for its sign-in

Proving the phone or card on file signs the account's other web sessions out
before the gate clears and again after it, so a session never sees the gate
open. Only the gates the request cleared go back on if the second pass fails.
The proof that allows an email change while the address is pending is kept
with the sign-in that gave it. A sign-in that isn't kept sets no session
cookie, and a provider sign-in in that case returns to its page.

* fix(auth): a gated sign-in checks the gate after its device id is kept

The check is the last step before the session cookie is set. Tests assert the
order of the gate writes and that a provider sign-in that isn't kept leaves no
session.
2026-11-20 11:23:07 -07:00
Daniel Salazar 59524cc580 feat(auth): phone on file step, email replacement while unconfirmed, no lock without email (#4707)
Benchmarks / changes (push) Canceled after 0s
Benchmarks / bench shard 1/3 (push) Canceled after 0s
Benchmarks / bench shard 2/3 (push) Canceled after 0s
Benchmarks / bench shard 3/3 (push) Canceled after 0s
Benchmarks / benchmarks (push) Canceled after 0s
Backend Tests / changes (push) Canceled after 0s
Backend Tests / typecheck (push) Canceled after 0s
Backend Tests / test shard 1/4 (push) Canceled after 0s
Backend Tests / test shard 2/4 (push) Canceled after 0s
Backend Tests / test shard 3/4 (push) Canceled after 0s
Backend Tests / test shard 4/4 (push) Canceled after 0s
Backend Tests / test (main) (push) Canceled after 0s
Backend Tests / coverage (push) Canceled after 0s
Notify HeyPuter / notify (push) Canceled after 0s
* feat(auth): phone on file step, email replacement while unconfirmed, no lock without email

- Phone gate on an account that already has a number: /send-confirm-phone
  sends the code to that number and ignores any other, /confirm-phone checks
  only that number, and `lostNumber: true` opens the card fallback (409 when
  there is none). The send response and whoami carry `phone_on_file`, the
  number's last two digits; the phone window drops the number field for it.
- /user-protected/change-email runs while the email code is pending, with
  every other gate still applied, for an account with a verified phone,
  card, paid plan or second factor; otherwise the code is still required.
  Provider-only accounts keep the code. Confirming the replacement runs the
  same side effects as confirming the code. The email window gets a step
  for it.
- The per-account wrong-password lock skips accounts with no email; the
  failures still count and alarm.
- puter.signin.validate carries `credential_exposed`.
- GUI gate flows read the account again between gate windows and before
  opening one.

* feat(auth): a number on file is stood in for only by the card on file; two codes a day

- The card fallback for a phone on file opens only when the account already
  has a card, and confirming it clears the phone step only when the card's
  fingerprint matches the one on file (`card_not_on_file` otherwise).
- Codes to a number on file: two per account per day; past that the route
  answers 429 `phone_on_file_send_limit` and offers the card on file.
- Phone window drops the signup help line in on-file mode; the email
  window's footer no longer shows a stray separator in the change step.

* feat(auth): replacing an unconfirmed email takes a factor the account had before

A phone or card first verified while the address is unconfirmed is recorded
in the account's metadata (`factorsAddedWhileEmailPending`), before it is
stored, and no longer counts toward /user-protected/change-email. A number
on file proven again and the card already on file still count, as do a
second factor and a paid plan. The route no longer asks for a new factor;
with none from before it answers `email_confirmation_required`, and the
email window says the code is needed.

* feat(auth): email replacement and the card stand-in each take proof in hand

- Replacing an unconfirmed email: a dormant sign-in records, once, the
  number the account had (`phoneAtDormantSignIn` in metadata). The change is
  allowed only when the account still has that number and proved it within
  the hour, by its code or by the card on file; otherwise the route starts
  the phone step for it, or answers `email_confirmation_required`. A phone
  or card merely being on the account, a paid plan, and a number or card
  verified since no longer count. This replaces the list of factors added
  while unconfirmed.
- Card confirmation while a number on file waits: only the card already on
  file verifies, under any gate order. The confirm event carries
  `required_fingerprint`, and the listener reports `card_entered` (details
  typed for this confirmation, not a saved card or an old confirmation);
  both are checked.
- A card fallback opened earlier no longer offers a card to an account whose
  number on file has no card to stand in for it.
2026-11-19 23:28:35 -07:00
Daniel Salazar bfcacc8469 fix(db): bound numbers must be safe integers; path, cursor and lookup input checks (#4708)
* fix(db): bound numbers must be safe integers; path and cursor input checks

Bound numbers outside ±2^53 (including NaN and Infinity) are refused with a
400 by every database client.

- Paths longer than 4096 characters are refused with a 400.
- The path lineage lookup returns null for paths deeper than its walk
  without querying.
- The read batcher's circuit breaker counts a failed fallback flush only
  when an item could not reach the database.
- App, subdomain and worker list cursors must carry a non-negative integer
  id.
- App stats grouping accepts only its own keys.
- App batch lookups skip values of the wrong type, and app writes refuse
  keys that are not column names.
- User, notification, durable subscription and KV share handle lookups
  return no row for values of the wrong type.
- OIDC links are looked up by the sub as a string.
- User-to-user and group permission reads keep exact matches only.
- revoke-dev-app validates its parameters like grant-dev-app.
- A durable subscription's expiresAt must be before the year 10000.
- Installed apps paging reads page and limit as whole numbers.

* fix(db): review follow-ups for input checks

- The path length check measures the canonical absolute path, after the
  leading slash is added and a trailing one dropped.
- The lineage lookup handles up to 500 segments, SQLite's compound select
  limit.
- Group permission reads keep matching by the column's collation.
- A server error code is never read as a lost connection from its message.
- Cursor ids must be integers or digit strings, and a cursor that is
  neither a string nor an object is refused.
- OIDC links store the sub as a string, matching lookups.
- findEmailOwner returns no row for a value that is not a string.
- Invalid stats groupings and non-string or non-number expiresAt values
  return a 400.
- Installed apps limit clamps before rounding down.
2026-11-19 15:19:28 -07:00
Daniel Salazar 03639b9589 fix(db): bound parameters must be scalars; text lookups match only strings (#4706)
Every database client refuses an array, object or function parameter with a
400 before it reaches the driver. Strings, numbers, bigints, booleans, null,
dates and buffers still bind. tryHardReadAll checks the whole batch first.

Store lookups on text columns return null for a value that is not a string:
users (only id takes a number), apps (also existsByName and
uidExistsOnPrimary), fsentries by uuid, subdomains by uuid, sessions by
uuid, shares and notifications by uid, notifications by send key. OIDC links
still look up a numeric provider sub.
2026-11-19 13:48:09 -07:00
Filip Kujundžić fdc1f9f3d8 feat(ai): add Gemini 4 Neon chat model (#4695) 2026-11-19 09:42:25 -07:00
Nariman Jelveh 8955253e2f feat(gui): app launches say what the user did and which page sent them (#4697)
Apps get `utm_content` set to how the user opened them: `app_icon`,
`file_open`, `open_with` or `file_drop`. Apps opened from the app browser
embed get the framing page's host as `utm_source`, which the server reads
from the same referrer check that pins `frame-ancestors`.
2026-11-19 09:40:36 -07:00
Daniel Salazar 442a50baed fix(auth): user lookups match only string and number values (#4698)
UserStore.getByProperty returns null for a value that is not a string or a
number, so an array or object from a request body never reaches the query.
POST /send-pass-recovery-email answers 400 for a username that is not a
string; it answered 500 for an array.
2026-11-19 09:13:16 -07:00
Daniel Salazar 6b8af52077 feat(auth): sign-in pipeline, per-account wrong-password budget and idle session expiry (#4692)
Sign-in
- One sign-in path (SignInService) for password, 2FA, recovery code, signup
  and OIDC. It emits puter.signin.attempt (before the account lookup on
  POST /login), puter.signin.validate (before the session is created) and
  puter.signin. Listeners can refuse or require phone or card verification; a
  listener that throws is ignored.
- POST /login keeps a wrong-password budget per account across all networks,
  20 an hour and 50 a day. A browser that has signed in to the account before
  is not refused, and the budget belongs to the current password.
- An account unused for dormantSignInDays (default 180) confirms an
  unconfirmed email at sign-in, where the deployment can send mail.
- New account emails: sign-in from a new browser, sign-in attempts blocked,
  password reset completed.
- pwnedPasswords (off by default): a k-anonymity range lookup after a
  successful password sign-in, with a notice to the owner.
- requestSignalHeaders and requestSignalValue turn configured request headers
  into req.requestSignals and a puter.request.flagged event.

Sessions
- web and app sessions end after 180 days without activity; accounts with no
  password and no email keep 365 days. A missing expiry on web, app and asset
  rows no longer means no expiry, and ended rows are purged.
- The cookie a private hosted site sets from ?auth_token= is tied to the
  token's session row and carries a 7-day expiry.

Email confirmation codes
- A 6-digit code is valid for 60 minutes and has a wrong-code budget.

Mailbox ingress
- email.ingress.validate runs before a message is stored; a listener can refuse
  it or record a sender check. X-Puter-Sender-Auth is written by the server
  only. Header blocks over 256 KiB are refused.

GUI
- Login sends the device fingerprint, can show the captcha widget
  (gui_params.turnstileLogin), offers a password reset when sign-in is locked,
  and runs pending verification windows after a popup sign-in or signup.
2026-11-18 23:02:16 -07:00
Nariman Jelveh e62418f7a9 fix(thumbnails): files edited or written by apps get a thumbnail in the dashboard (#4691)
* fix(thumbnails): files edited or written by apps get a thumbnail in the dashboard

An overwrite clears a file's thumbnail and nothing made a new one, so a file
an app saved over lost its picture, and files apps created never had one.

The dashboard now makes a thumbnail for a file with none as its row comes
into view, with the upload thumbnail generator, within budgets on size,
downloads at a time, files per minute, and bytes per page load. A version
that gives no thumbnail is remembered so it isn't downloaded again.

/update-fsentry-thumbnail takes an optional expectedModified and refuses a
thumbnail made from an older version with 409, tells the owner's other
clients about the new thumbnail, and has its own rate-limit scope instead of
sharing the one opening a file uses. Overwrites and replacements emit
thumbnail.discarded, and the thumbnails extension deletes the object behind
it, so replaced thumbnails no longer stay in the bucket.

* fix(thumbnails): expectedModified must be a whole number of seconds the column can hold

A fraction or a value past the column's range reached the UPDATE, which
Postgres refuses with an error after the thumbnail was already uploaded.
The route now answers 400 before it uploads anything.

* fix(thumbnails): setting a thumbnail keeps the current one when the new one can't be stored

The route stored whatever the thumbnail.created listeners left behind:
a pointer whose upload failed, or the null left for an image that can't
be decoded. Either replaced a working thumbnail and answered 200. It now
answers 500 or 400 and leaves the entry as it was.

* fix(thumbnails): the update announced after setting a thumbnail carries the entry's current name and path

The event was built from the entry read before the thumbnail was
uploaded, so a rename or move that landed during the upload was
announced with the name and path it had just replaced, and open clients
put the row back on a path that no longer exists. The entry is read
again after the thumbnail is stored.

* fix(thumbnails): a file that stops needing a thumbnail is no longer downloaded for one

A file waiting its turn, or already downloading, was still read and its
thumbnail stored after another tab had made one, or after the file was
saved again as something the generator can't read. A queued file is now
checked again before its download starts, and a change that makes the
thumbnail unwanted drops the queued job and cancels the download.

* fix(thumbnails): refreshing the folder on screen keeps its thumbnail downloads

A refresh of the folder on screen (a sort, a view switch, an upload
finishing, coming back to the tab) cancelled the downloads under way.
The rows drawn right after were skipped, because their files still
counted as being tried, so they stayed without a thumbnail until some
later render. The rest were downloaded again from the start.

A download is now cancelled only if its file's row isn't drawn again in
the same task, and the new row takes it over. A row that comes back
while a cancelled download is still ending is queued again.

* fix(thumbnails): a stored thumbnail is recorded on the row's own entry

The filler handed its callback a copy of the row's entry, so the
thumbnail was written to an object nothing else reads, and the row's
entry kept saying the file had none. It now passes the row's entry, and
skips a row whose file was saved again while the thumbnail was being
stored, which would otherwise show the older version's picture.

* fix(thumbnails): the download budget counts the bytes that were downloaded

A cancelled download gave its whole size back to the page's download
budget, though the bytes it had received were already billed as egress.
A file saved over and over while its row was on screen could be started
again each time, well past the budget. A download the server refused
kept its size charged with nothing downloaded.

The file is now read as a stream and the budget is charged what arrived.
Reading also stops as soon as a file turns out to be over the size cap,
where before a file larger than its listed size was buffered whole.

* fix(thumbnails): a thumbnail download that fails to connect is tried again

A download that failed on the network counted as tried, so the file went
without a thumbnail for the rest of the page load. A laptop waking before
its Wi-Fi is back marked every row on screen that way. A failed
connection now pauses the filler like a 429 does, and the file is tried
again after the pause.

* fix(thumbnails): a thumbnail that couldn't be stored yet is sent again, not made again

When storing a thumbnail got a 429, the file was queued again and
downloaded a second time after the pause. When the request failed to
connect, the thumbnail was dropped and the file went without one. The
thumbnail is now kept with the queued job and sent again after the
pause, as long as the file is still at the version it shows.

* fix(thumbnails): a file whose thumbnail the server refuses isn't downloaded again on every page load

When the server answers 400 for a thumbnail, the file's version is now
remembered like one that gave no thumbnail at all. It counted as tried
for the page load only, so each later page load downloaded the file and
sent the same image again.

* fix(thumbnails): only pictures a browser can draw are downloaded for a thumbnail

Any file typed image/ counted as one the generator reads, so TIFF scans,
CAD drawings, DjVu books and the like were each downloaded in full, up
to 20 MiB, to make a thumbnail no browser can draw. A file is now
downloaded only when its type or name is one browsers decode. Uploads
are unchanged: the generator still tries any image there, where the file
is already local.

* fix(thumbnails): missing thumbnails are downloaded one file at a time

Each download holds one of the account's concurrent file reads until it
ends. Two at a time left a temporary account, which has three, a single
read for everything its apps do, so an app reading two files at once got
a 429 while a folder's thumbnails were being filled in. The per-minute
cap of 20 files already bounds how fast they're made.

* fix(thumbnails): an update refreshes the icon of every item it matches

An update can match the Files row and the same item in a file dialog
open over the dashboard. The row updater set the new thumbnail on the
first match only, where it used to set it on all of them.

* perf(thumbnails): an update works out a row's icon again only when its thumbnail changed

Every update event carries a thumbnail key, so the row updater worked
out the icon on each one. For a .app file or a web link that reads the
file, once per event. The icon is now refreshed only when the event's
thumbnail differs from the one the row has.

* perf(thumbnails): drawing a large folder doesn't rescan the thumbnail queue for every row

Each row handed to the filler went through every row queued before it,
looking for a job to start, so drawing a folder of files without
thumbnails took the square of its length: about a second for 20,000
rows. A row that isn't on screen yet has nothing to start, so the queue
is now only gone through when a row is reported on screen, a job ends,
or a wait is over.

* fix(thumbnails): one tab no longer drops the failed files another tab remembered

Each tab read the list of files that gave no thumbnail once, then wrote
its own copy back whole on every addition, which dropped whatever
another tab had added in between. Those files were downloaded again on
a later page load. The stored list is now read again and merged before
each write.

* perf(thumbnails): files downloaded for a thumbnail stay out of the browser's HTTP cache

The download asked the cache to revalidate, which still writes each
response to it, up to 100 MiB of originals per page load that nothing
reads back. The read route doesn't answer conditional requests, so a
cached copy could never save a download either.

* bench(thumbnails): scenario for setting a file's thumbnail from the dashboard

The dashboard calls the route for each file it fills in a thumbnail
for, up to 20 a minute, so its round trips are measured from here on.

* docs(thumbnails): list the picture formats downloaded for a missing thumbnail

* perf(thumbnails): setting a thumbnail reads the entry again alongside the write, not after it

The read that keeps the announced name and path current ran after the
update, which added a serial round trip to the route. It now runs with
the update. The window it closes is the upload before both.

* feat(thumbnails): a file saved over keeps showing its old thumbnail until the new one is ready

A save cleared the row to its type icon for the few seconds it takes to
make the new thumbnail, so a file an app saves repeatedly flashed
between the two. The row now keeps the old thumbnail while a new one is
on its way.

It goes back to the type icon at once when no thumbnail will be made
(the file is too large, the download budget is spent, the filler is
paused), as soon as the attempt fails, and after 10 seconds at most,
counted from the first save, so an old picture can't stay on a file
that keeps changing.

* fix(thumbnails): a document gets its thumbnail when the view goes to the list and back while it's made

A list row shows a document's type icon, so switching to the list gave up
on the thumbnail being made for it. Switching back before that ended found
the version already tried and queued nothing, and the row kept its type
icon until the folder was drawn again. The row now takes the job back.

* fix(thumbnails): a file being saved waits to settle whatever the computer's clock says

The wait before a saved file is downloaded was measured from its modified
time, which the server sets, against the browser's clock. On a computer
whose clock runs a few seconds ahead the wait came out as zero, so every
save of a file an app keeps saving started a download that the next save
cancelled. A file an update just arrived for now waits at least two
seconds, the least it waits when the clocks agree.

* fix(thumbnails): an item in a file dialog gets a new thumbnail when its folder isn't the one on screen

The row updater only set a thumbnail through the entry a Files row
carries. An update for a file shown only in a file dialog, with another
folder open in Files, matched an item that has no entry, and the item
kept the picture it had.

* refactor(thumbnails): the row observer asks for no margin around the screen

The 200px margin never took effect. The rows scroll inside the listing's
own pane, and a margin on the viewport doesn't widen what that pane clips,
so a row was only ever reported once it was on screen. That's also what
the download budget is written for, so the option goes rather than being
made to work.

* test(thumbnails): a version tried once, a hidden tab, and a browser saving data

Three of the filler's cost guards had no test: a version whose thumbnail
the server turned away isn't downloaded again in the page load, nothing
starts while the tab is hidden, and nothing is downloaded when the
browser asks to use less data.
2026-11-18 18:58:43 -07:00