Skip to content

fix(desktop): make desktop policy optional and non-blocking - #5131

Merged
benjaminshafii merged 3 commits into
devfrom
fix/signed-out-local-providers
Sep 18, 2026
Merged

benjaminshafii merged 3 commits into
devfrom
fix/signed-out-local-providers

Conversation

@reachjalil

@reachjalil reachjalil commented Sep 17, 2026 •

Copy link
Copy Markdown
Member

Problem

Desktop policy currently blocks local desktop use through provider restrictions, verification failures, startup gates, and execution rules. Suspend desktop-policy enforcement pending its redesign, for both signed-in and signed-out users.

Change

  • Centralize the suspension with DESKTOP_POLICY_ENFORCEMENT_ENABLED=false.
  • Make desktop policy evaluation, capability checks, native browser policy checks, and legacy/v2 engine policy projection non-blocking.
  • Stop desktop policy readiness, required sign-in, and allowed-version policy from gating local desktop use.
  • Keep policy schemas and control-plane configuration available for redesign.
  • Preserve Cloud authentication, resource entitlements, ordinary user permissions, and enterprise activation. This is not a Cloud authorization bypass.

No visual redesign; existing controls become available without desktop-policy restrictions.

Validation

  • 56 focused server tests passed.
  • 53 focused app tests passed.
  • 12 desktop tests passed.
  • App and server TypeScript checks passed.
  • Electron main syntax check and git diff --check passed.
  • Focused independent review found no blockers.
  • No full build, packaged Electron launch, or live local-model inference/UI eval was performed.

An earlier broader diagnostics run on the initial signed-out-only commit had 95 passes and one fresh-state runtime.sqlite creation failure (agent-context-diagnostics.test.ts:2094); its baseline status was not verified. That broader diagnostics suite was not rerun for this revision.

@reachjalil
reachjalil requested a review from a team September 17, 2026 22:54
@vercel

vercel Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
openwork-app Ready Ready Preview Sep 18, 2026 1:18am UTC
openwork-den Ready Ready Preview Sep 18, 2026 1:18am UTC
openwork-diagnostics Ready Ready Preview Sep 18, 2026 1:18am UTC
openwork-landing Ready Ready Preview, v0 Sep 18, 2026 1:18am UTC

@vercel
vercel Bot temporarily deployed to Preview – openwork-landing September 17, 2026 23:08 Inactive
@reachjalil reachjalil changed the title fix(desktop): allow signed-out local providers fix(desktop): make desktop policy optional and non-blocking Sep 17, 2026
@benjaminshafii
benjaminshafii merged commit 45dc586 into dev Sep 18, 2026
12 checks passed
benjaminshafii pushed a commit that referenced this pull request Sep 25, 2026
The cloud build requires sign-in again, so its packaged first launch shows
the sign-in surface (the contract before #5131) instead of the signed-out
task composer.

Signed-off-by: Benjamin Shafii <[email protected]>
benjaminshafii pushed a commit that referenced this pull request Sep 25, 2026
* fix(desktop): restore forced sign-in and version allowlist

#5131 suspended desktop feature-policy enforcement but also routed two
non-policy controls through the same switch:

- Required sign-in is a property of the enterprise and cloud builds
  (desktop-distribution.mjs); desktop-bootstrap.json can only raise it.
  The app shell ignored it on desktop, so activated enterprise installs
  opened local work without Den sign-in.
- allowedDesktopVersions is an organization setting (PATCH /v1/org), not a
  desktop policy. The runtime projection dropped it, so the updater and
  recovery picker stopped honouring the organization's version pin.

Restore both. Feature-policy toggles and execution rules stay suspended.
The updater again waits for the organization's desktop config before its
first check, and refreshFresh fetches instead of returning the cached
projection so the install-time re-check (#4761) sees a revoked version.

Specs: packaged-activated-launch expects the forced sign-in surface again;
background-desktop-update proves a revoked version is not installed and a
re-approved one is. Docs: the enterprise deployment page no longer claims
feature policies are enforced.

Signed-off-by: Benjamin Shafii <[email protected]>

* fix(desktop): keep update checks working when Den is unreachable

refreshFresh now always fetches the organization's desktop config, so a
failed fetch (offline, or an older or unavailable Den) would have failed
Check now and the alpha channel resolution. Fall back to the last known
config, matching the install re-check's existing offline rule.

Rename updatePolicyKnown to allowedVersionsKnown and split the MDM docs:
allowed desktop versions are an organization setting, not a desktop policy.

Signed-off-by: Benjamin Shafii <[email protected]>

* test(evals): expect the cloud build's sign-in gate on first launch

The cloud build requires sign-in again, so its packaged first launch shows
the sign-in surface (the contract before #5131) instead of the signed-out
task composer.

Signed-off-by: Benjamin Shafii <[email protected]>

---------

Signed-off-by: Benjamin Shafii <[email protected]>
reachjalil added a commit that referenced this pull request Sep 28, 2026
…viders

A member whose effective desktop policy has allowCustomProviders off gets
no free Auto credential, and Auto access reports admin_disabled. The
credential route answers 403 free_not_offered so the desktop can hide Auto.
Den reads the policy itself, so this holds while desktop policy enforcement
is suspended (#5131).
reachjalil added a commit that referenced this pull request Sep 30, 2026
…viders

A member whose effective desktop policy has allowCustomProviders off gets
no free Auto credential, and Auto access reports admin_disabled. The
credential route answers 403 free_not_offered so the desktop can hide Auto.
Den reads the policy itself, so this holds while desktop policy enforcement
is suspended (#5131).
reachjalil added a commit that referenced this pull request Sep 30, 2026
…r pins (#5194)

* feat(gateway): add protected free Auto access and ordered provider pins

* fix(gateway): complete Auto migrations and enforce reservation ownership

* feat(api): document free Auto access and pinned model contracts

* fix(gateway): derive free Auto lookup tags with HMAC instead of bare SHA-256

Free credentials and identities were stored as plain SHA-256 digests, which
code scanning flags as weak hashing of sensitive data. Den and the Gateway now
share one domain-separated helper: identities use a keyed SHA-256 tag and
free credentials use a WebCrypto HMAC, matching the Gateway bearer-key store.
Free access is off by default and unreleased, so no stored tags need migrating.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BMeBni56bB19LwDFqNsQEw

* refactor(gateway): split free Auto by user type and serve it from one OpenAI key

Treat signed-out, signed-in and subscribed users as three separate systems:

- Signed-out desktops keep dedicated anonymous_inference_* tables with no
  organization, member, user or key columns. Their allowance is keyed on a
  machine id carried in the signed proof, so reinstalling does not reset it.
- Signed-in members of unsubscribed organizations use their regular
  OpenWork Models (ow_inf_) key on /api/v1. The proxy serves them only Auto,
  within a weekly per-person allowance held in inference_free_* tables.
  The separate ow_auto_ credential and inference_free_keys are removed.
- Subscribed organizations keep the existing paid path unchanged.

Free requests no longer touch OpenRouter. Both free paths call OpenAI Chat
Completions with a single INFERENCE_FREE_OPENAI_API_KEY; revoking that key is
the kill switch, and its OpenAI usage shows the running cost. Allowance cost
is computed from OpenAI token counts, and requests OpenAI refuses (401, 403,
429) release their hold instead of being charged.

* feat(gateway): bind guest Auto to a supported desktop release window

Guests may use free Auto only from the newest three stable desktop releases,
with every release supported for at least 14 days after it ships. Each stable
release derives its own secret from DESKTOP_FREE_RELEASE_KEY at build time and
tags its signed proof with it (proof v3); the gateway derives the same secret
from the version the proof claims, so a secret lifted from one release cannot
be presented as another and expires with its release.

Knobs: DESKTOP_FREE_SUPPORTED_RELEASE_COUNT, DESKTOP_FREE_SUPPORTED_RELEASE_MIN_DAYS,
DESKTOP_FREE_BLOCKED_RELEASES, DESKTOP_FREE_RELEASE_KEY_PREVIOUS (rotation
overlap), DESKTOP_FREE_FIRST_RELEASE_TAG_VERSION (v2 cutover) and a dev-mode
DESKTOP_FREE_DEV_RELEASE_SECRET for unversioned developer builds. The release
list comes from GitHub and is served stale for up to a day if GitHub fails.
Signed-in members are unaffected.

* feat(gateway): make new guest identities cheap to refuse

Guests can assert any machine id, so make a fresh one worth little instead of
trying to prove it: the weekly device allowance ramps with the machine's age
(ANONYMOUS_INSTALL_RAMP, default $0.10 on day 0, $0.25 from day 1, $0.50 from
day 3, full from day 7; a bucket's limit only ever rises within its week),
each IP may introduce only a few never-seen machines a day
(ANONYMOUS_IP_NEW_IDENTITIES_PER_DAY, default 5), and minting a guest session
costs a small proof of work bound to the proof's single-use nonce
(ANONYMOUS_SESSION_POW_BITS, default 20). First sightings live in the guest-only
anonymous_inference_identities table.

* feat(gateway): ramp the guest allowance over the first 30 minutes and raise the session proof of work to 23 bits

* feat(gateway): unlock the guest allowance in steps over the first hour

* feat(gateway): unlock the guest allowance by time with the app open, and tighten the proof of work

The device allowance now ramps on active minutes rather than wall-clock age:
every signed guest request is a heartbeat, and the time since the previous one
is credited only when the gap is short enough to mean the app stayed open
(ANONYMOUS_ACTIVITY_MAX_GAP_MS, default 3 minutes). Default tiers: $0.10, then
$0.20 after 10 active minutes, $0.50 after 20, the full $1 after 30.

The session proof of work becomes eight 20-bit puzzles instead of one 23-bit
puzzle, so the time to solve clusters around one to three seconds instead of
occasionally taking many times longer; verification stays eight hashes.

* feat(gateway): default the session proof of work to eight 19-bit rounds

* refactor(free-auto): share the free Auto contract as @openwork/free-auto and split the gateway by audience

Free Auto's rules had to be identical in the gateway, the desktop relay and the
desktop app, but lived as copies in each. They now live once in
packages/free-auto:

- `.`            protocol (routes, headers, proof and release-tag messages,
                 signable routes), proof-of-work parameters and verification,
                 desktop version and release-window rules
- `./accounting` usage cost, reservation size, the activity ramp
- `./node`       SHA-256, release secret and tag HMACs, the proof-of-work solver
                 and a worker built from the verifier's own functions

@openwork/types/desktop-free-access is removed; its contents moved unchanged.

The gateway's thirteen flat free-Auto files become src/free/{guest,member,shared}
behind one entry, with shared/ never importing guest/ or member/. That removes
three inverted imports (request parsing reaching into the guest proof module,
the gate reaching into dispatch for its error helper, config reaching into the
release source for a URL). Behaviour and test counts are unchanged.

The gateway, den and den-gateway images copy and build the new package.

* chore: drop the stack branches' Vercel preview opt-out

The deploymentEnabled overrides named this stack's branches and would have
landed in dev's Vercel config; previews build normally again.

* feat(gateway): log members' free Auto requests as organization usage

Moved down from the picker PR: it is Gateway accounting. A member's free
Auto request writes the same write-ahead Gateway request log as every other
route (route openwork_free, against the member's key); if that record cannot
be written the request fails closed and the reservation is released without
an upstream call. Guest requests are never attributed to an organization.
Migration 0112 adds the openwork_free route to the request-log enums.

* fix(gateway): accept GitHub's full release list for the supported-release window

The release source capped the list at 1 MB, but GitHub's last 20 OpenWork
releases, with notes and assets, are about 1.7 MB. Every refresh was
rejected, so guests would have been refused as desktop_version_unavailable.
The cap is now 8 MB, and a regression test uses a list of realistic size.

* fix(gateway): close the member usage log row when dispatch is refused

A member request whose reservation was refused at dispatch returned 403
but left its write-ahead usage log row pending.

* fix(gateway): never downgrade a paying organization to free Auto, refuse untagged proofs

- An organization whose inference subscription Stripe still collects for
  (active, trialing, past_due, incomplete) is refused free Auto even when
  its Models flag is missing. A lost entitlement, as in #5324, keeps
  returning inference_disabled and logs a mismatch for support instead of
  quietly moving members to a $5 weekly allowance.
- Guest proofs without a release tag are always refused with the update
  wall. No released build ever sent one, so the cutover setting only left
  a bypass open; DESKTOP_FREE_FIRST_RELEASE_TAG_VERSION is removed.
- An admin turning Models on before subscribing lifts an earlier free Auto
  opt-out, and the admin toggle keeps the rest of the free settings.
- Settling checks every bucket before writing, and an expired reservation
  that fails the accounting invariant is set aside as retained instead of
  failing every status read and reservation behind it.

* test(gateway): prove the paid-subscription guard and reservation quarantine on MySQL

* fix(gateway): keep public free Auto traffic from slowing paid Gateway requests

Free Auto shares the Gateway process and database with paid Den Gateway
traffic. A surge of signed-out desktops could queue transactions behind
the free control lock and hold the shared connections paid requests need.

- Free Auto uses its own database client (like usage writes do).
- One process-wide limit bounds free database work (FREE_AUTO_MAX_CONCURRENT,
  default 8) and how much may wait (FREE_AUTO_MAX_QUEUED, default 32);
  beyond that, requests get 503 free_auto_busy at once. Settlement,
  release and cancel are never limited, so accounting stays exact.
- Status checks, most of the free traffic, no longer take the global lock
  or reap; expired holds are ignored there and cleared by the next
  reservation.

* fix(gateway): print a release key fingerprint and send the GitHub token only to GitHub

- The gateway logs a short non-secret fingerprint of DESKTOP_FREE_RELEASE_KEY
  (and the previous key) at startup, to compare with the desktop build's, so
  a key mismatch is caught before every guest on a release is refused.
- GITHUB_TOKEN is only sent when the release list URL is api.github.com.

* feat(gateway): trust proxy ranges so guest limits count real client addresses

ANONYMOUS_TRUSTED_PROXY_IPS now accepts CIDR ranges (e.g. 10.0.0.0/8) as
well as exact addresses. Hosts like Render reach the Gateway from changing
private addresses; without a range, trusting the proxy was impossible and
every guest shared the load balancer's IP limit. Ranges wider than /8 and
malformed entries disable trust (fail closed). Adds the first tests for
client address resolution.

* fix(gateway): tell desktops guest Auto is switched off, not unavailable

With ANONYMOUS_INFERENCE_ENABLED off, guest routes answered 503
anonymous_unavailable, the same code as a real outage, so the desktop
could only show Auto as unavailable. They now answer free_disabled, which
the app treats as no Auto at all until an operator turns it on.

* feat(den): no free Auto for organizations that allow only managed providers

A member whose effective desktop policy has allowCustomProviders off gets
no free Auto credential, and Auto access reports admin_disabled. The
credential route answers 403 free_not_offered so the desktop can hide Auto.
Den reads the policy itself, so this holds while desktop policy enforcement
is suspended (#5131).

* fix(den): free Auto follows the free starter model switch

Den's "Free starter model (Auto)" switch is stored as allowZenModel.
Free Auto is refused when it is off, instead of for every organization
that allows only its managed providers.

* free-auto: charge like paid Models, with no holds

Free Auto now follows the paid Models pattern. Before a request it checks
that each window's used total is below its limit. Afterwards it charges the
real cost once, keyed on OpenAI's completion id. When no usage report
arrives, it charges a fixed estimate. Nothing is held up front, so parallel
requests from one person (subagents, parallel chats, title generation) run
as they do on paid Models.

Removed: reservations and reservation charges, the single-row control
tables, the one-request-per-person lock, the global in-flight count, the
per-IP daily spend window, the member global caps, the per-request and
per-proof rate counters, the 4,096-token output cap, the input-size
pre-check, and the whole-stream timeout.

Migration 0115 is regenerated with seven tables: usage windows and one
usage record per request (for guests and for members), plus machine
identities, proof signatures and the new-machine counter.

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
reachjalil added a commit that referenced this pull request Sep 30, 2026
…asks (#5195)

* feat(gateway): add protected free Auto access and ordered provider pins

* fix(gateway): complete Auto migrations and enforce reservation ownership

* feat(api): document free Auto access and pinned model contracts

* feat(desktop): bridge free Auto with identity-bound native credentials

* fix(gateway): derive free Auto lookup tags with HMAC instead of bare SHA-256

Free credentials and identities were stored as plain SHA-256 digests, which
code scanning flags as weak hashing of sensitive data. Den and the Gateway now
share one domain-separated helper: identities use a keyed SHA-256 tag and
free credentials use a WebCrypto HMAC, matching the Gateway bearer-key store.
Free access is off by default and unreleased, so no stored tags need migrating.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BMeBni56bB19LwDFqNsQEw

* refactor(gateway): split free Auto by user type and serve it from one OpenAI key

Treat signed-out, signed-in and subscribed users as three separate systems:

- Signed-out desktops keep dedicated anonymous_inference_* tables with no
  organization, member, user or key columns. Their allowance is keyed on a
  machine id carried in the signed proof, so reinstalling does not reset it.
- Signed-in members of unsubscribed organizations use their regular
  OpenWork Models (ow_inf_) key on /api/v1. The proxy serves them only Auto,
  within a weekly per-person allowance held in inference_free_* tables.
  The separate ow_auto_ credential and inference_free_keys are removed.
- Subscribed organizations keep the existing paid path unchanged.

Free requests no longer touch OpenRouter. Both free paths call OpenAI Chat
Completions with a single INFERENCE_FREE_OPENAI_API_KEY; revoking that key is
the kill switch, and its OpenAI usage shows the running cost. Allowance cost
is computed from OpenAI token counts, and requests OpenAI refuses (401, 403,
429) release their hold instead of being charged.

* fix(desktop): identify free Auto by machine and relay plain OpenAI chat

- Derive a deterministic machine id from the OS identifier (IOPlatformUUID,
  MachineGuid or /etc/machine-id), salted and hashed on the device, and carry
  it in every signed proof. The guest allowance now follows the machine, so a
  reinstall or cleared app data does not reset it. The session body is empty.
- Signed-in members receive their OpenWork Models (ow_inf_) key and reach
  Auto on the regular /api/v1 routes.
- The engine talks to the local relay through @ai-sdk/openai-compatible
  instead of the OpenRouter adapter.

* fix(desktop): keep the proof version literal for the Electron typecheck

* feat(gateway): bind guest Auto to a supported desktop release window

Guests may use free Auto only from the newest three stable desktop releases,
with every release supported for at least 14 days after it ships. Each stable
release derives its own secret from DESKTOP_FREE_RELEASE_KEY at build time and
tags its signed proof with it (proof v3); the gateway derives the same secret
from the version the proof claims, so a secret lifted from one release cannot
be presented as another and expires with its release.

Knobs: DESKTOP_FREE_SUPPORTED_RELEASE_COUNT, DESKTOP_FREE_SUPPORTED_RELEASE_MIN_DAYS,
DESKTOP_FREE_BLOCKED_RELEASES, DESKTOP_FREE_RELEASE_KEY_PREVIOUS (rotation
overlap), DESKTOP_FREE_FIRST_RELEASE_TAG_VERSION (v2 cutover) and a dev-mode
DESKTOP_FREE_DEV_RELEASE_SECRET for unversioned developer builds. The release
list comes from GitHub and is served stale for up to a day if GitHub fails.
Signed-in members are unaffected.

* feat(desktop): tag free Auto proofs per release and activate the relay from user sends

Each stable release derives its free Auto secret from DESKTOP_FREE_RELEASE_KEY
in CI (HMAC over the version) and ships it inside the Electron main bundle in
a split, masked form; every signed proof now carries a release tag (proof v3)
so the gateway can hold guests to its release support window. Developer builds
use OPENWORK_DEV_FREE_RELEASE_SECRET in dev mode; untagged builds keep
signing v2. The desktop now reports its real app version instead of
Electron's in development.

The local relay forwards the engine's model calls only while a task the user
started from the app with Auto selected is live: a send opens a window that
idles out after 15 minutes without completed calls and closes after two
hours, on session end, and whenever the engine credential rotates. Engine
calls that name a session must name one the user started.

* feat(gateway): make new guest identities cheap to refuse

Guests can assert any machine id, so make a fresh one worth little instead of
trying to prove it: the weekly device allowance ramps with the machine's age
(ANONYMOUS_INSTALL_RAMP, default $0.10 on day 0, $0.25 from day 1, $0.50 from
day 3, full from day 7; a bucket's limit only ever rises within its week),
each IP may introduce only a few never-seen machines a day
(ANONYMOUS_IP_NEW_IDENTITIES_PER_DAY, default 5), and minting a guest session
costs a small proof of work bound to the proof's single-use nonce
(ANONYMOUS_SESSION_POW_BITS, default 20). First sightings live in the guest-only
anonymous_inference_identities table.

* feat(desktop): pay the guest session proof of work before minting

The relay picks the proof nonce itself, solves the gateway's proof of work for
that nonce (default 20 bits, OPENWORK_FREE_SESSION_POW_BITS for developer
builds) and asks the signer to sign with it, so the work is bound to a
single-use proof. If the gateway demands more bits than the build assumed, the
relay redoes the work once up to the supported maximum. The signer accepts a
caller-supplied nonce and refuses malformed ones.

* feat(gateway): ramp the guest allowance over the first 30 minutes and raise the session proof of work to 23 bits

* feat(gateway): unlock the guest allowance in steps over the first hour

* feat(desktop): solve the guest session proof of work in the background

The relay starts the proof of work on a worker thread as soon as it
initialises, so the first message finds it done, and begins the next one right
after each mint. Bun (the test runner) falls back to an in-process solve; a
cancelled job never falls back. Default work rises to 23 bits.

* feat(gateway): unlock the guest allowance by time with the app open, and tighten the proof of work

The device allowance now ramps on active minutes rather than wall-clock age:
every signed guest request is a heartbeat, and the time since the previous one
is credited only when the gap is short enough to mean the app stayed open
(ANONYMOUS_ACTIVITY_MAX_GAP_MS, default 3 minutes). Default tiers: $0.10, then
$0.20 after 10 active minutes, $0.50 after 20, the full $1 after 30.

The session proof of work becomes eight 20-bit puzzles instead of one 23-bit
puzzle, so the time to solve clusters around one to three seconds instead of
occasionally taking many times longer; verification stays eight hashes.

* feat(desktop): heartbeat while open and solve the multi-round session proof of work

While the app is open and signed out, the relay sends a signed status check
every minute (OPENWORK_FREE_HEARTBEAT_MS) so the gateway can credit time with
the app open toward the guest allowance. The background solver now works the
gateway's multi-round puzzle (rounds and bits both honoured on a
session_pow_required reply).

* feat(gateway): default the session proof of work to eight 19-bit rounds

* refactor(free-auto): share the free Auto contract as @openwork/free-auto and split the gateway by audience

Free Auto's rules had to be identical in the gateway, the desktop relay and the
desktop app, but lived as copies in each. They now live once in
packages/free-auto:

- `.`            protocol (routes, headers, proof and release-tag messages,
                 signable routes), proof-of-work parameters and verification,
                 desktop version and release-window rules
- `./accounting` usage cost, reservation size, the activity ramp
- `./node`       SHA-256, release secret and tag HMACs, the proof-of-work solver
                 and a worker built from the verifier's own functions

@openwork/types/desktop-free-access is removed; its contents moved unchanged.

The gateway's thirteen flat free-Auto files become src/free/{guest,member,shared}
behind one entry, with shared/ never importing guest/ or member/. That removes
three inverted imports (request parsing reaching into the guest proof module,
the gate reaching into dispatch for its error helper, config reaching into the
release source for a URL). Behaviour and test counts are unchanged.

The gateway, den and den-gateway images copy and build the new package.

* refactor(server): split the free Auto relay into units on @openwork/free-auto

The relay moves to apps/server/src/free-auto/: settings, provider config,
HTTP helpers, task activation, the proof-of-work pool, and response parsing
are pure units with their own tests; the service keeps only orchestration.
anonymous-inference.ts stays as a re-export, so server.ts is unchanged.

The duplicated proof-of-work solver and worker are gone in favour of the
package's startSessionPow. The desktop signer takes the signable routes,
nonce pattern, platforms, hashing and release tag from the package, and the
release-tag build step uses the same secret derivation as the gateway.
Server and desktop depend on @openwork/free-auto; server builds and the
Electron release build compile it first.

* fix(server): compare the relay's member credential directly and list the free Auto host

The relay no longer derives SHA-256 digests from the member's Auto key for
its identity check and caches; it compares the in-memory credential it
already holds, and only the request body is hashed for the failure cache.
The outbound-access manifest now lists inference.openworklabs.com with the
relay that calls it.

* chore: drop the stack branches' Vercel preview opt-out

The deploymentEnabled overrides named this stack's branches and would have
landed in dev's Vercel config; previews build normally again.

* feat(desktop): let developer mode point free Auto at a loopback control plane

Moved down from the picker PR: it only changes the desktop signer. With
OPENWORK_DEV_MODE, the signer accepts a loopback Den and API origin so the
full free Auto flow can run against a local stack.

* feat(gateway): log members' free Auto requests as organization usage

Moved down from the picker PR: it is Gateway accounting. A member's free
Auto request writes the same write-ahead Gateway request log as every other
route (route openwork_free, against the member's key); if that record cannot
be written the request fails closed and the reservation is released without
an upstream call. Guest requests are never attributed to an organization.
Migration 0112 adds the openwork_free route to the request-log enums.

* fix(gateway): accept GitHub's full release list for the supported-release window

The release source capped the list at 1 MB, but GitHub's last 20 OpenWork
releases, with notes and assets, are about 1.7 MB. Every refresh was
rejected, so guests would have been refused as desktop_version_unavailable.
The cap is now 8 MB, and a regression test uses a list of realistic size.

* fix(desktop): hold guest session refusals and scope the release key to the build step

A signed-out desktop solved a fresh proof of work and asked for a guest
session on every heartbeat while guest Auto was switched off. A 503 from
the session route is now replayed until Retry-After (default 15 minutes)
lapses; a send with Auto selected or an identity change asks again. The
next session's work is warmed only after a session is granted.

The release workflow exposed DESKTOP_FREE_RELEASE_KEY to every step of the
Electron jobs; only the build step that derives the release tag sees it now.

* fix(gateway): close the member usage log row when dispatch is refused

A member request whose reservation was refused at dispatch returned 403
but left its write-ahead usage log row pending.

* fix(gateway): never downgrade a paying organization to free Auto, refuse untagged proofs

- An organization whose inference subscription Stripe still collects for
  (active, trialing, past_due, incomplete) is refused free Auto even when
  its Models flag is missing. A lost entitlement, as in #5324, keeps
  returning inference_disabled and logs a mismatch for support instead of
  quietly moving members to a $5 weekly allowance.
- Guest proofs without a release tag are always refused with the update
  wall. No released build ever sent one, so the cutover setting only left
  a bypass open; DESKTOP_FREE_FIRST_RELEASE_TAG_VERSION is removed.
- An admin turning Models on before subscribing lifts an earlier free Auto
  opt-out, and the admin toggle keeps the rest of the free settings.
- Settling checks every bucket before writing, and an expired reservation
  that fails the accounting invariant is set aside as retained instead of
  failing every status read and reservation behind it.

* test(gateway): prove the paid-subscription guard and reservation quarantine on MySQL

* fix(server): let a person's send retry held guest refusals and reload the engine after sign-in

Two gaps found running the desktop app end to end:

- The app asks /anonymous-inference/preflight before a send, and that
  replayed the held guest 503, so a send stayed refused for up to 15
  minutes after guest Auto came back. Preflight and refresh now ask the
  gateway again; the background heartbeat still honours the refusal.
- Signing in rotates the relay token and rewrites the runtime config, but
  the running engine kept the old token and every Auto call returned 401.
  A rotation that changes the engine config now schedules a provider
  reload.

* fix(gateway): keep public free Auto traffic from slowing paid Gateway requests

Free Auto shares the Gateway process and database with paid Den Gateway
traffic. A surge of signed-out desktops could queue transactions behind
the free control lock and hold the shared connections paid requests need.

- Free Auto uses its own database client (like usage writes do).
- One process-wide limit bounds free database work (FREE_AUTO_MAX_CONCURRENT,
  default 8) and how much may wait (FREE_AUTO_MAX_QUEUED, default 32);
  beyond that, requests get 503 free_auto_busy at once. Settlement,
  release and cancel are never limited, so accounting stays exact.
- Status checks, most of the free traffic, no longer take the global lock
  or reap; expired holds are ignored there and cleared by the next
  reservation.

* fix(gateway): print a release key fingerprint and send the GitHub token only to GitHub

- The gateway logs a short non-secret fingerprint of DESKTOP_FREE_RELEASE_KEY
  (and the previous key) at startup, to compare with the desktop build's, so
  a key mismatch is caught before every guest on a release is refused.
- GITHUB_TOKEN is only sent when the release list URL is api.github.com.

* feat(desktop): print the release key fingerprint at build time and list the Auto host

- A tagged desktop build prints the non-secret release key fingerprint, the
  same one the gateway logs at startup, so a release can be checked against
  the gateway before guests reach it.
- The outbound network access guide lists inference.openworklabs.com.

* feat(gateway): trust proxy ranges so guest limits count real client addresses

ANONYMOUS_TRUSTED_PROXY_IPS now accepts CIDR ranges (e.g. 10.0.0.0/8) as
well as exact addresses. Hosts like Render reach the Gateway from changing
private addresses; without a range, trusting the proxy was impossible and
every guest shared the load balancer's IP limit. Ranges wider than /8 and
malformed entries disable trust (fail closed). Adds the first tests for
client address resolution.

* fix(desktop): hand the release key only to the release tag step of the build

electron-build.mjs passed its whole environment to every child: the sidecar
download, the server and app builds. It now removes DESKTOP_FREE_RELEASE_KEY
from its own environment and passes it only to the step that derives the tag.

* fix(gateway): tell desktops guest Auto is switched off, not unavailable

With ANONYMOUS_INFERENCE_ENABLED off, guest routes answered 503
anonymous_unavailable, the same code as a real outage, so the desktop
could only show Auto as unavailable. They now answer free_disabled, which
the app treats as no Auto at all until an operator turns it on.

* test(server): the relay passes a switched-off guest Auto through as free_disabled

* feat(den): no free Auto for organizations that allow only managed providers

A member whose effective desktop policy has allowCustomProviders off gets
no free Auto credential, and Auto access reports admin_disabled. The
credential route answers 403 free_not_offered so the desktop can hide Auto.
Den reads the policy itself, so this holds while desktop policy enforcement
is suspended (#5131).

* fix(server): pass Den's free_not_offered through as the member's Auto status

* fix(den): free Auto follows the free starter model switch

Den's "Free starter model (Auto)" switch is stored as allowZenModel.
Free Auto is refused when it is off, instead of for every organization
that allows only its managed providers.

* free-auto: charge like paid Models, with no holds

Free Auto now follows the paid Models pattern. Before a request it checks
that each window's used total is below its limit. Afterwards it charges the
real cost once, keyed on OpenAI's completion id. When no usage report
arrives, it charges a fixed estimate. Nothing is held up front, so parallel
requests from one person (subagents, parallel chats, title generation) run
as they do on paid Models.

Removed: reservations and reservation charges, the single-row control
tables, the one-request-per-person lock, the global in-flight count, the
per-IP daily spend window, the member global caps, the per-request and
per-proof rate counters, the 4,096-token output cap, the input-size
pre-check, and the whole-stream timeout.

Migration 0115 is regenerated with seven tables: usage windows and one
usage record per request (for guests and for members), plus machine
identities, proof signatures and the new-machine counter.

* free-auto: drop the reserved amount from the relay's allowance

The Gateway no longer holds allowance before a request, so a status carries only the limit, used and remaining amounts.

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>
reachjalil added a commit that referenced this pull request Sep 30, 2026
* feat(gateway): add protected free Auto access and ordered provider pins

* fix(gateway): complete Auto migrations and enforce reservation ownership

* feat(models): unify Auto, pinned models, and provider selection

* fix(models): align provider columns and free allowance recovery

* test(models): prove Auto and provider pins through the real picker

* feat(api): document free Auto access and pinned model contracts

* feat(desktop): bridge free Auto with identity-bound native credentials

* test(chat): match the current first-send pending label

* feat(gateway): key free credential lookups and attribute reservations to organizations

Free Auto credentials and identities now use a domain-separated HMAC digest
shared by Den and the Gateway instead of a bare SHA-256, matching the Gateway
bearer-key store. Free reservations record the verified organization so admin
allowance summaries read from the key link, never from the client. Migration
0109 adds the reservation organization column and the device-key share
receipt table.

* feat(den): manage Auto pins, organization allowance, and device-key sharing

Den exposes the organization free-provider summary to admins, lets admins pin
or unpin Auto for members without touching access or personal pins, and
accepts a device API key from a freshly verified owner or admin: eligibility is
secret-free, the transfer is one transaction with a durable receipt scoped to
organization, member and request id, retries return the same receipt, and
changed contents conflict. Covered against a real MySQL.

* feat(server): pass the organization Auto pin through and share device keys under policy

The desktop server forwards Den's defaultPinned decision with the free status,
so an admin unpin reaches native pickers. Device-key sharing reads the secret
only after eligibility is verified, journals the request id before the
transfer, removes the local key only after a verified receipt, and is governed
by the same desktop model policy as saving a key.

* feat(app): align the model picker, palette, and recovery states with the design

Auto leads the pinned list with the OpenWork mark, rows show provider mark,
subtitle, source glyph and check, and the footer offers Connect more providers
and All models. Loading, no-results, no-connected-models, saved-unavailable,
policy-blocked, failed and stale catalogs, exhausted allowance, update required,
temporary unavailability and sync pending each have their own state; the All
models dialog now receives catalog state and retry from every owner. The
Settings palette shares the Models mode with real options, workspace defaults
keep their effort variant, and the in-chat limit notice keeps the unprocessed
message dimmed with Sign in to OpenWork and Switch model.

* feat(app): group device and organization providers and share a device key with Den

AI providers separates keys on this device from providers the organization
manages in Den, shows OpenWork Models as included with an on/off control, and
reports when Den last synced. Sharing a device key opens a consent dialog that
names what moves to Den, what leaves the device, who is billed and who can
access it; supported API keys share through the verified server path while
custom and sign-in credentials stay private.

* test(evals): own the engine per fixture and prove the picker's recovery states

Worlds choose their engine explicitly so CI's default no longer runs a v2
journey on v1, sessionless specs no longer skip on ambient env, and evidence
records the fixture's engine. The picker journey now covers empty search and
Clear search, collapsed Advanced options, the pinned-row context menu, the
immutable organization pin, and switching from a pinned row, using the current
labels and chords. The outbound manifest lists the inference host.

* fix(build): typecheck free-provider types for Electron and look up free credentials through WebCrypto

The free provider summary schema no longer carries a cross-version zod
annotation that the Electron typecheck rejects, the managed-models policy
narrows on an explicit discriminant, free credential lookups derive their tag
through WebCrypto HMAC like the Gateway bearer-key store, and the provider sync
store omits empty last-run facts instead of recording null.

* fix(types): ship desktop-free-access as a built subpath

The packaged desktop server imports @openwork/types/desktop-free-access at
runtime; the export now resolves to the built file instead of TypeScript
source, which Node refuses to strip under node_modules.

* test(evals): packaged cloud first launch greets with the current heading

* test(evals): first-run journeys greet with the current hero heading

* fix(app): keep opaque model ids out of the palette's Models row

The Models command shows the current model's public name as its value, or
nothing when the selected model only has a gateway id; the palette proof now
matches the root placeholder and allows that public value.

* test(evals): packaged and first-run journeys follow the current first-use surface

The activated enterprise launch expects the current hero heading, the local
first run proves the starter model through the composer instead of removed
status copy, and packaged launches skip loudly when no packaged binary is
available instead of failing the change-proof lane.

* feat(desktop): let developer mode name a loopback control plane for free Auto

With OPENWORK_DEV_MODE=1, an explicit loopback OPENWORK_DEV_FREE_CONTROL_PLANE
counts as the hosted control plane so a local Den and Gateway can exercise
Auto end to end. Packaged builds never set it; every other origin, flavor and
policy check is unchanged.

* feat(desktop): accept a loopback API origin under the developer control plane

A local Den serves its web control plane and API on different loopback
ports, so the developer-only allowance accepts any loopback API origin once
the named control plane matches.

* fix(server): say why Auto is not registered at startup

A refused identity, a blocking policy, or an environment switch used to
disable Auto silently; the server now logs the reason once at startup.

* fix(server): name every reason Auto stays unregistered

The startup diagnostic now also covers a workspace that turned Auto off and a
user-defined provider that already owns the Auto provider id.

* feat(app): keep the built-in OpenCode Zen models as a silent fallback

The engine's free OpenCode Zen models no longer appear as a provider group
once Auto or any connected provider is available; they stay listed only when
nothing else is, and Zen models unlocked with a pasted API key remain
connected models. Matches the picker designs, which offer OpenCode Zen only
under Connect a provider.

* feat(gateway): report OpenWork Models usage in Gateway analytics

Member Auto requests now write the same Gateway request log as every other
provider (route openwork_openrouter, tokens and cost from the settled
receipt), so Den's usage page counts them by model, team and person.
OpenWork Models is its own usage family with Auto labelled by name and offered
as a filter; hosted OpenWork Models usage on the same route is included too.
Guests stay per device and are never attributed to an organization. The usage
caption now reads as the design does: all Gateway providers, including
OpenWork Models.

* fix(app): hide the OpenCode Zen fallback only from picker listings

Entitlement checks used for sends and default resolution still see the
built-in Zen models, so sessions already on them keep working; only the
composer picker, the All models dialog, and the palette omit the group while
another model is available.

* feat(gateway): free Auto follows Gateway write-ahead accounting

Member Auto requests refuse to dispatch when the Gateway request record cannot
be written first and release their reservation, like every other Gateway route,
and settled usage carries the provider generation id as its durable identity.

(cherry picked from commit ab8c200)

* docs(pr-proof): real screenshots of the Auto model picker, palette, chat recovery and providers

* fix(gateway): derive free Auto lookup tags with HMAC instead of bare SHA-256

Free credentials and identities were stored as plain SHA-256 digests, which
code scanning flags as weak hashing of sensitive data. Den and the Gateway now
share one domain-separated helper: identities use a keyed SHA-256 tag and
free credentials use a WebCrypto HMAC, matching the Gateway bearer-key store.
Free access is off by default and unreleased, so no stored tags need migrating.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BMeBni56bB19LwDFqNsQEw

* refactor(gateway): split free Auto by user type and serve it from one OpenAI key

Treat signed-out, signed-in and subscribed users as three separate systems:

- Signed-out desktops keep dedicated anonymous_inference_* tables with no
  organization, member, user or key columns. Their allowance is keyed on a
  machine id carried in the signed proof, so reinstalling does not reset it.
- Signed-in members of unsubscribed organizations use their regular
  OpenWork Models (ow_inf_) key on /api/v1. The proxy serves them only Auto,
  within a weekly per-person allowance held in inference_free_* tables.
  The separate ow_auto_ credential and inference_free_keys are removed.
- Subscribed organizations keep the existing paid path unchanged.

Free requests no longer touch OpenRouter. Both free paths call OpenAI Chat
Completions with a single INFERENCE_FREE_OPENAI_API_KEY; revoking that key is
the kill switch, and its OpenAI usage shows the running cost. Allowance cost
is computed from OpenAI token counts, and requests OpenAI refuses (401, 403,
429) release their hold instead of being charged.

* fix(desktop): identify free Auto by machine and relay plain OpenAI chat

- Derive a deterministic machine id from the OS identifier (IOPlatformUUID,
  MachineGuid or /etc/machine-id), salted and hashed on the device, and carry
  it in every signed proof. The guest allowance now follows the machine, so a
  reinstall or cleared app data does not reset it. The session body is empty.
- Signed-in members receive their OpenWork Models (ow_inf_) key and reach
  Auto on the regular /api/v1 routes.
- The engine talks to the local relay through @ai-sdk/openai-compatible
  instead of the OpenRouter adapter.

* fix(desktop): keep the proof version literal for the Electron typecheck

* feat(gateway): bind guest Auto to a supported desktop release window

Guests may use free Auto only from the newest three stable desktop releases,
with every release supported for at least 14 days after it ships. Each stable
release derives its own secret from DESKTOP_FREE_RELEASE_KEY at build time and
tags its signed proof with it (proof v3); the gateway derives the same secret
from the version the proof claims, so a secret lifted from one release cannot
be presented as another and expires with its release.

Knobs: DESKTOP_FREE_SUPPORTED_RELEASE_COUNT, DESKTOP_FREE_SUPPORTED_RELEASE_MIN_DAYS,
DESKTOP_FREE_BLOCKED_RELEASES, DESKTOP_FREE_RELEASE_KEY_PREVIOUS (rotation
overlap), DESKTOP_FREE_FIRST_RELEASE_TAG_VERSION (v2 cutover) and a dev-mode
DESKTOP_FREE_DEV_RELEASE_SECRET for unversioned developer builds. The release
list comes from GitHub and is served stale for up to a day if GitHub fails.
Signed-in members are unaffected.

* feat(desktop): tag free Auto proofs per release and activate the relay from user sends

Each stable release derives its free Auto secret from DESKTOP_FREE_RELEASE_KEY
in CI (HMAC over the version) and ships it inside the Electron main bundle in
a split, masked form; every signed proof now carries a release tag (proof v3)
so the gateway can hold guests to its release support window. Developer builds
use OPENWORK_DEV_FREE_RELEASE_SECRET in dev mode; untagged builds keep
signing v2. The desktop now reports its real app version instead of
Electron's in development.

The local relay forwards the engine's model calls only while a task the user
started from the app with Auto selected is live: a send opens a window that
idles out after 15 minutes without completed calls and closes after two
hours, on session end, and whenever the engine credential rotates. Engine
calls that name a session must name one the user started.

* feat(gateway): make new guest identities cheap to refuse

Guests can assert any machine id, so make a fresh one worth little instead of
trying to prove it: the weekly device allowance ramps with the machine's age
(ANONYMOUS_INSTALL_RAMP, default $0.10 on day 0, $0.25 from day 1, $0.50 from
day 3, full from day 7; a bucket's limit only ever rises within its week),
each IP may introduce only a few never-seen machines a day
(ANONYMOUS_IP_NEW_IDENTITIES_PER_DAY, default 5), and minting a guest session
costs a small proof of work bound to the proof's single-use nonce
(ANONYMOUS_SESSION_POW_BITS, default 20). First sightings live in the guest-only
anonymous_inference_identities table.

* feat(desktop): pay the guest session proof of work before minting

The relay picks the proof nonce itself, solves the gateway's proof of work for
that nonce (default 20 bits, OPENWORK_FREE_SESSION_POW_BITS for developer
builds) and asks the signer to sign with it, so the work is bound to a
single-use proof. If the gateway demands more bits than the build assumed, the
relay redoes the work once up to the supported maximum. The signer accepts a
caller-supplied nonce and refuses malformed ones.

* feat(gateway): ramp the guest allowance over the first 30 minutes and raise the session proof of work to 23 bits

* feat(gateway): unlock the guest allowance in steps over the first hour

* feat(desktop): solve the guest session proof of work in the background

The relay starts the proof of work on a worker thread as soon as it
initialises, so the first message finds it done, and begins the next one right
after each mint. Bun (the test runner) falls back to an in-process solve; a
cancelled job never falls back. Default work rises to 23 bits.

* feat(gateway): unlock the guest allowance by time with the app open, and tighten the proof of work

The device allowance now ramps on active minutes rather than wall-clock age:
every signed guest request is a heartbeat, and the time since the previous one
is credited only when the gap is short enough to mean the app stayed open
(ANONYMOUS_ACTIVITY_MAX_GAP_MS, default 3 minutes). Default tiers: $0.10, then
$0.20 after 10 active minutes, $0.50 after 20, the full $1 after 30.

The session proof of work becomes eight 20-bit puzzles instead of one 23-bit
puzzle, so the time to solve clusters around one to three seconds instead of
occasionally taking many times longer; verification stays eight hashes.

* feat(desktop): heartbeat while open and solve the multi-round session proof of work

While the app is open and signed out, the relay sends a signed status check
every minute (OPENWORK_FREE_HEARTBEAT_MS) so the gateway can credit time with
the app open toward the guest allowance. The background solver now works the
gateway's multi-round puzzle (rounds and bits both honoured on a
session_pow_required reply).

* feat(gateway): default the session proof of work to eight 19-bit rounds

* refactor(free-auto): share the free Auto contract as @openwork/free-auto and split the gateway by audience

Free Auto's rules had to be identical in the gateway, the desktop relay and the
desktop app, but lived as copies in each. They now live once in
packages/free-auto:

- `.`            protocol (routes, headers, proof and release-tag messages,
                 signable routes), proof-of-work parameters and verification,
                 desktop version and release-window rules
- `./accounting` usage cost, reservation size, the activity ramp
- `./node`       SHA-256, release secret and tag HMACs, the proof-of-work solver
                 and a worker built from the verifier's own functions

@openwork/types/desktop-free-access is removed; its contents moved unchanged.

The gateway's thirteen flat free-Auto files become src/free/{guest,member,shared}
behind one entry, with shared/ never importing guest/ or member/. That removes
three inverted imports (request parsing reaching into the guest proof module,
the gate reaching into dispatch for its error helper, config reaching into the
release source for a URL). Behaviour and test counts are unchanged.

The gateway, den and den-gateway images copy and build the new package.

* refactor(server): split the free Auto relay into units on @openwork/free-auto

The relay moves to apps/server/src/free-auto/: settings, provider config,
HTTP helpers, task activation, the proof-of-work pool, and response parsing
are pure units with their own tests; the service keeps only orchestration.
anonymous-inference.ts stays as a re-export, so server.ts is unchanged.

The duplicated proof-of-work solver and worker are gone in favour of the
package's startSessionPow. The desktop signer takes the signable routes,
nonce pattern, platforms, hashing and release tag from the package, and the
release-tag build step uses the same secret derivation as the gateway.
Server and desktop depend on @openwork/free-auto; server builds and the
Electron release build compile it first.

* chore(scope): keep this PR to Auto and the unified model picker

Device API key storage and sharing with Den, the Den admin screens built on
the retired provider detail views, per-model audience scopes, and the
Gateway usage label move out of this PR. The device key work follows as its
own PR on top of this one; the usage label lands separately against dev;
the admin screens will be redone on the current AI Gateway screen.

What stays: Auto in the picker, palette and settings (including the Auto
on/off preference), the organization Auto pin and summary API, workspace
default models, reply model labels, and Auto's blocked-send recovery.

* fix(server): compare the relay's member credential directly and list the free Auto host

The relay no longer derives SHA-256 digests from the member's Auto key for
its identity check and caches; it compares the in-memory credential it
already holds, and only the request body is hashed for the failure cache.
The outbound-access manifest now lists inference.openworklabs.com with the
relay that calls it.

* fix(types): keep den/inference free of runtime relative imports

Den's web app loads @openwork/types/den/inference from source, where
Turbopack cannot resolve the './managed-models-policy.js' import the Auto
pin helpers added, so the Den preview build failed. The module keeps its own
copy of the six-line metadata reader instead.

* chore: drop the stack branches' Vercel preview opt-out

The deploymentEnabled overrides named this stack's branches and would have
landed in dev's Vercel config; previews build normally again.

* feat(desktop): let developer mode point free Auto at a loopback control plane

Moved down from the picker PR: it only changes the desktop signer. With
OPENWORK_DEV_MODE, the signer accepts a loopback Den and API origin so the
full free Auto flow can run against a local stack.

* feat(gateway): log members' free Auto requests as organization usage

Moved down from the picker PR: it is Gateway accounting. A member's free
Auto request writes the same write-ahead Gateway request log as every other
route (route openwork_free, against the member's key); if that record cannot
be written the request fails closed and the reservation is released without
an upstream call. Guest requests are never attributed to an organization.
Migration 0112 adds the openwork_free route to the request-log enums.

* fix(gateway): accept GitHub's full release list for the supported-release window

The release source capped the list at 1 MB, but GitHub's last 20 OpenWork
releases, with notes and assets, are about 1.7 MB. Every refresh was
rejected, so guests would have been refused as desktop_version_unavailable.
The cap is now 8 MB, and a regression test uses a list of realistic size.

* fix(desktop): hold guest session refusals and scope the release key to the build step

A signed-out desktop solved a fresh proof of work and asked for a guest
session on every heartbeat while guest Auto was switched off. A 503 from
the session route is now replayed until Retry-After (default 15 minutes)
lapses; a send with Auto selected or an identity change asks again. The
next session's work is warmed only after a session is granted.

The release workflow exposed DESKTOP_FREE_RELEASE_KEY to every step of the
Electron jobs; only the build step that derives the release tag sees it now.

* fix(models): keep model shortcuts off a blocked Auto and restore the Fast pricing hint

A saved shortcut for Auto switched to it even while the picker showed Auto
disabled, so the next send failed. Disabled options now resolve as
unavailable and leave the current model alone. The Fast mode row again
carries the higher-pricing tooltip that dev shows.

* fix(gateway): close the member usage log row when dispatch is refused

A member request whose reservation was refused at dispatch returned 403
but left its write-ahead usage log row pending.

* fix(models): keep the Fast label on one line and the Zen starter selectable

- The quiet Fast label sits inside the trigger's text, so the model reads
  as one line ("Fast witness · High · Fast") as on dev.
- The free Zen starter hidden behind better models still works; the picker
  no longer calls it unavailable while sends succeed.
- Cycling onto Auto from the palette never carries the previous effort.
- The full picker's Fast row shows the higher-pricing hint again, as on dev.
- The picker spec expects dev's current "High · Fast" trigger.

* fix(gateway): never downgrade a paying organization to free Auto, refuse untagged proofs

- An organization whose inference subscription Stripe still collects for
  (active, trialing, past_due, incomplete) is refused free Auto even when
  its Models flag is missing. A lost entitlement, as in #5324, keeps
  returning inference_disabled and logs a mismatch for support instead of
  quietly moving members to a $5 weekly allowance.
- Guest proofs without a release tag are always refused with the update
  wall. No released build ever sent one, so the cutover setting only left
  a bypass open; DESKTOP_FREE_FIRST_RELEASE_TAG_VERSION is removed.
- An admin turning Models on before subscribing lifts an earlier free Auto
  opt-out, and the admin toggle keeps the rest of the free settings.
- Settling checks every bucket before writing, and an expired reservation
  that fails the accounting invariant is set aside as retained instead of
  failing every status read and reservation behind it.

* Merge branch 'feature/desktop-auto-access' into feature/auto-model-experience

* test(gateway): prove the paid-subscription guard and reservation quarantine on MySQL

* fix(server): let a person's send retry held guest refusals and reload the engine after sign-in

Two gaps found running the desktop app end to end:

- The app asks /anonymous-inference/preflight before a send, and that
  replayed the held guest 503, so a send stayed refused for up to 15
  minutes after guest Auto came back. Preflight and refresh now ask the
  gateway again; the background heartbeat still honours the refusal.
- Signing in rotates the relay token and rewrites the runtime config, but
  the running engine kept the old token and every Auto call returned 401.
  A rotation that changes the engine config now schedules a provider
  reload.

* fix(gateway): keep public free Auto traffic from slowing paid Gateway requests

Free Auto shares the Gateway process and database with paid Den Gateway
traffic. A surge of signed-out desktops could queue transactions behind
the free control lock and hold the shared connections paid requests need.

- Free Auto uses its own database client (like usage writes do).
- One process-wide limit bounds free database work (FREE_AUTO_MAX_CONCURRENT,
  default 8) and how much may wait (FREE_AUTO_MAX_QUEUED, default 32);
  beyond that, requests get 503 free_auto_busy at once. Settlement,
  release and cancel are never limited, so accounting stays exact.
- Status checks, most of the free traffic, no longer take the global lock
  or reap; expired holds are ignored there and cleared by the next
  reservation.

* fix(gateway): print a release key fingerprint and send the GitHub token only to GitHub

- The gateway logs a short non-secret fingerprint of DESKTOP_FREE_RELEASE_KEY
  (and the previous key) at startup, to compare with the desktop build's, so
  a key mismatch is caught before every guest on a release is refused.
- GITHUB_TOKEN is only sent when the release list URL is api.github.com.

* feat(desktop): print the release key fingerprint at build time and list the Auto host

- A tagged desktop build prints the non-secret release key fingerprint, the
  same one the gateway logs at startup, so a release can be checked against
  the gateway before guests reach it.
- The outbound network access guide lists inference.openworklabs.com.

* feat(gateway): trust proxy ranges so guest limits count real client addresses

ANONYMOUS_TRUSTED_PROXY_IPS now accepts CIDR ranges (e.g. 10.0.0.0/8) as
well as exact addresses. Hosts like Render reach the Gateway from changing
private addresses; without a range, trusting the proxy was impossible and
every guest shared the load balancer's IP limit. Ranges wider than /8 and
malformed entries disable trust (fail closed). Adds the first tests for
client address resolution.

* fix(desktop): hand the release key only to the release tag step of the build

electron-build.mjs passed its whole environment to every child: the sidecar
download, the server and app builds. It now removes DESKTOP_FREE_RELEASE_KEY
from its own environment and passes it only to the step that derives the tag.

* fix(gateway): tell desktops guest Auto is switched off, not unavailable

With ANONYMOUS_INFERENCE_ENABLED off, guest routes answered 503
anonymous_unavailable, the same code as a real outage, so the desktop
could only show Auto as unavailable. They now answer free_disabled, which
the app treats as no Auto at all until an operator turns it on.

* fix(models): show no Auto until it is switched on, keep Zen for subscribers and enterprise as today

- Free Auto that the Gateway (or Den, for members) reports switched off,
  or whose first status check has not answered, appears nowhere: not in
  the picker, the palette, shortcuts, Settings or the first-use caption.
  Auto that is on but failing still shows as unavailable.
- Only the credential-less built-in Zen starter steps aside for other
  models. Zen set up with a key or subscription, in OpenWork or with
  opencode auth login, keeps every model, free ones included.
- Under the only-managed-providers desktop policy the picker lists exactly
  what the existing policy filter allows, Zen included when allowZenModel
  is on, as on dev.
- Tests cover switched-off and failing Auto, Zen and Codex set up outside
  OpenWork, and parity with dev's policy filter for enterprise.

* test(server): the relay passes a switched-off guest Auto through as free_disabled

* fix(models): only a running Auto status check hides Auto

Outside the desktop the status check never runs, so treating it as
pending hid Auto for good. Auto is now hidden while a check is actually
in flight, and otherwise follows what the check (or the engine) reports.

* feat(den): no free Auto for organizations that allow only managed providers

A member whose effective desktop policy has allowCustomProviders off gets
no free Auto credential, and Auto access reports admin_disabled. The
credential route answers 403 free_not_offered so the desktop can hide Auto.
Den reads the policy itself, so this holds while desktop policy enforcement
is suspended (#5131).

* fix(server): pass Den's free_not_offered through as the member's Auto status

* fix(den): free Auto follows the free starter model switch

Den's "Free starter model (Auto)" switch is stored as allowZenModel.
Free Auto is refused when it is off, instead of for every organization
that allows only its managed providers.

* docs(app): describe free_not_offered as the free starter model being off

* test(evals): the model access picker spec finds the picker's search by its prefix

The shared picker's search reads "Search models…"; match either spelling so
"Only models you provide" is proven on this picker too.

* free-auto: charge like paid Models, with no holds

Free Auto now follows the paid Models pattern. Before a request it checks
that each window's used total is below its limit. Afterwards it charges the
real cost once, keyed on OpenAI's completion id. When no usage report
arrives, it charges a fixed estimate. Nothing is held up front, so parallel
requests from one person (subagents, parallel chats, title generation) run
as they do on paid Models.

Removed: reservations and reservation charges, the single-row control
tables, the one-request-per-person lock, the global in-flight count, the
per-IP daily spend window, the member global caps, the per-request and
per-proof rate counters, the 4,096-token output cap, the input-size
pre-check, and the whole-stream timeout.

Migration 0115 is regenerated with seven tables: usage windows and one
usage record per request (for guests and for members), plus machine
identities, proof signatures and the new-machine counter.

* free-auto: drop the reserved amount from the relay's allowance

The Gateway no longer holds allowance before a request, so a status carries only the limit, used and remaining amounts.

* fix(auto): enforce policy and retain accounting through outages

* test(auto): check the Den access response envelope

* Prove disabled Auto stays quiet and regenerate the usage API contract

* feat(models): stage free Auto rollout per organization

---------

Co-authored-by: Claude Opus 5.5 <[email protected]>

This branch was successfully deployed

4 active deployments
Preview – openwork-app — 8562ef44 Deployed Sep 18, 2026 by vercel[bot]
Preview – openwork-landing — 8562ef44 Deployed Sep 18, 2026 by vercel[bot]
Preview – openwork-den — 8562ef44 Deployed Sep 18, 2026 by vercel[bot]
Preview – openwork-diagnostics — 8562ef44 Deployed Sep 18, 2026 by vercel[bot]
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