Skip to content

Body limit fix, token revocation, header-matched faults, MCP seed hint - #61

Merged
RhysSullivan merged 3 commits into
mainfrom
gaps-revoke-faults-limits
Nov 27, 2026
Merged

RhysSullivan merged 3 commits into
mainfrom
gaps-revoke-faults-limits

Conversation

@RhysSullivan

Copy link
Copy Markdown

Four gaps in the hosted emulators, one commit each (the token and fault changes share a commit with their docs).

1. The OpenAI emulator failed on bodies within its stated 32 MiB limit.

  • The cause: input of many messages (a few hundred thousand, as in a body of exactly 33,554,432 bytes) answered 500 "Maximum call stack size exceeded" and recorded no usage. The token count passed every message as a separate argument. It also built an array with one element per character, which for a long input could exhaust the instance's memory.
  • The fix: token counts now walk the text with no spread and no array. Rule matching looks in each text rather than joining them. The body is decoded as it arrives.
  • On a staging copy of the hosted worker, every shape at exactly the limit now answers 200 with its usage record. The shapes: one string, many input messages, many chat messages, many content parts, escaped and raw non-ASCII text.

2. Revoking one token.

  • The control call: POST /_emulate/tokens/revoke with { "token": "..." }. Requests with that token then get the provider's own 401, and every other token keeps working.
  • What it covers: the shared token map (GitHub, Google, Apple, Microsoft, Slack, Vercel, Okta, Clerk, PostHog, MCP, and /_emulate/credentials tokens). Through a new ServicePlugin.revokeToken hook, it also covers the tokens X, Zapier, PlanetScale and Miro keep, OpenAI API keys, and WorkOS API keys and refresh tokens.
  • Refused everywhere: a revoked token is refused even where unknown tokens fall back to a default user.
  • Kept: the revocation is stored with the instance, so it survives a hosted unload.
  • Not covered: WorkOS access tokens are signed JWTs checked by signature alone, so they can't be revoked one by one; revoking the refresh token ends the session.
  • GitHub's own route: DELETE /applications/:client_id/token (Basic client auth, { "access_token" }, 204, 404 or 422 as GitHub documents).
  • GitHub's 401: GitHub now answers a token it doesn't accept with 401 {"message":"Bad credentials"} on REST routes, as api.github.com does, instead of treating the request as anonymous.

3. A fault can match a header. match.headers matches request headers by exact value, with header names case-insensitive. So a fault meant for one caller's Authorization leaves every other caller alone, and only that caller spends its count.

4. The MCP sign-in pages' seed hint. It said to POST {"github":{"users":[…]}} to /__seed. On the MCP service that key seeds nothing, and /__seed replaces the whole instance, including the client that is signing in. It now names POST /_emulate/seed with {"users":[…]}, which works on the MCP service and on GitHub's MCP surface.

Docs: README, docs pages (control routes, ledger and faults, GitHub) and skills.

Tests:

  • Core: header faults; revoke, also with a fallback user; the service hook.
  • Hosted, through the Durable Object with eviction: GitHub by the control call and by its own route; an X store token; an OpenAI key.
  • OpenAI: 300,000 messages on both endpoints, which fail on the old code; the code-point count.

A body within the 32 MiB limit could still fail. Input of many messages
(a few hundred thousand) answered 500 "Maximum call stack size exceeded" and
recorded no usage, because the token count passed every message as a separate
argument. And the count built an array with one element per character, which
for a long input could exhaust the instance's memory.

- Token counts walk the text without an argument spread or a character array.
- Rule matching looks in each text instead of joining them into a second copy.
- The body is decoded as it arrives, not held as bytes and text at once.

Every shape at exactly 33,554,432 bytes now answers 200 with its usage
record: one string, many input messages, many chat messages, many content
parts, escaped and raw non-ASCII text.
The "User not found" page and the sign-in footer told the reader to POST
{"github":{"users":[...]}} to /__seed. On the MCP service that key seeds
nothing, and /__seed replaces the whole instance, including the client that
is signing in, so the retry failed either way. The hint now names
POST /_emulate/seed with {"users":[...]}, which adds a user on both the MCP
service and GitHub's MCP surface.
Revoking: POST /_emulate/tokens/revoke { token } revokes one token, after
which requests with it get the provider's own 401 and every other token keeps
working. It covers the shared token map and, through a new
ServicePlugin.revokeToken hook, the tokens X, Zapier, PlanetScale and Miro
keep, OpenAI API keys, and WorkOS API keys and refresh tokens. A revoked token
is refused even where unknown tokens fall back to a default user, and the
revocation is kept with the store, so it survives a hosted unload.

GitHub also gains its own route, DELETE /applications/:client_id/token (Basic
client auth, 204), and answers a token it does not accept with
401 {"message":"Bad credentials"} on REST routes, as api.github.com does,
instead of treating the request as anonymous.

Faults: a fault can also match request headers by exact value
(match.headers, names case-insensitive), so a fault meant for one caller's
Authorization leaves every other caller alone.
@RhysSullivan
RhysSullivan marked this pull request as ready for review November 27, 2026 16:17
@RhysSullivan
RhysSullivan merged commit 682f587 into main Nov 27, 2026
1 check passed
@RhysSullivan RhysSullivan mentioned this pull request Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant