Skip to content

Signing worker agents in and out: the authorization server, consent, lifetimes and reverse states #736

Closed

Description

@allisonmahmood

Part of #730.

Question

How does a person connect a worker agent, and how do they, their admin or Patchy take it away again: the authorization server, consent, token lifetimes and refresh, and every reverse state?

Context

Fixed at charting: build and work token purposes, neither opening the other's door; one token per device or client; agent access off until an admin turns it on; a connection is one grant as the person. The prototype (#727) built Patchy's own OAuth 2.1 authorization server: protected resource and server metadata, dynamic client registration, PKCE, a consent page on the browser session, one use machine token per client, and reconnecting replaces the old token. Clerk is the identity provider today; ADR-0008 covers machine tokens. The authorization research supplies the facts.

To decide

  • Whose authorization server: Patchy's own or Clerk's.
  • Registration: Client ID Metadata Documents, dynamic registration or both; what Patchy keeps about a client, how long unused registrations live, how its name is shown, and the limits on fetching a client's metadata document (Patchy fetching a URL a stranger names).
  • What a connection is. The prototype replaces a person's earlier token for the same OAuth client when they reconnect. With metadata documents every install of a client shares one client id, so connecting a second laptop would disconnect the first, against the fixed one-token-per-device decision. Decide what tells two connections apart and which one a reconnect replaces.
  • Lifetimes and refresh: access token lifetime, refresh tokens and rotation, what an expiry looks like to a person mid-task, and how this sits with machine tokens' existing expiry.
  • Consent: what the page tells the person (which company, that the agent acts as them, what it can reach); being signed in as someone else; denying.
  • Reverse states, each with how it's seen and what the agent is told (in the MCP surface ticket's refusal shape): disconnecting on Your machines; deactivation and reactivation; agent access turned off and on again; an admin removing someone's connection; someone leaving the company; revoke-all after a lost device. Each covers the whole grant, not only live tokens: pending authorization codes (the prototype leaves them redeemable after a reactivation), refresh token families, and calls already admitted. ADR-0008's rule that reactivation needs fresh authorization holds.
  • ADR-0008: the amendment for a second token purpose.
  • Dev instances: keep the loopback token endpoint found in testing, or a cleaner equivalent.

Resolves when

Connecting and disconnecting are written as decisions ready for the spec, with the auth glossary's terms updated (agent connection, the work purpose).

Activity

  1. added
    wayfinder:grilling
    on Oct 17, 2026
  2. allisonmahmood commented on Oct 17, 2026

    @allisonmahmood
    OwnerAuthor

    Handed over from The MCP surface on the latest revision:

    • Refusals: this ticket's cases (agent access off, deactivated, a revoked connection) take the surface's one refusal shape. That is a tool result over HTTP 200 with isError: true, text saying what happened and then what to do, and structuredContent: { error: { code, from, message, details?, retryAfterSeconds? } }. Never a 403.
    • CORS: the OAuth machine endpoints (metadata, registration, token) get Access-Control-Allow-Origin: * without credentials. The consent page stays outside CORS.
    • A dev gap Sol found: GET /dev/sign-in?as=<email> (packages/auth/src/DevPersonas.ts) switches the dev persona on a plain GET, so any page the developer visits can change who they are signed in as locally. The proposed fix is to make persona switching a protected POST and to require Sec-Fetch-Site: same-origin on the dev instance's browser routes, consent included.
  3. allisonmahmood commented on Oct 21, 2026

    @allisonmahmood
    OwnerAuthor

    Resolution

    Decided with Allison on 2026-10-21 over two rounds. GPT 6.1 Sol checked the recommendations before she answered, and four changed as a result: the refresh grace, the idle clock, cancelling consents when agent access goes off, and device logins awaiting their poll. Sol then checked this resolution, and its eight precision fixes are folded in. The facts come from the authorization research and the MCP surface. Everything below is written to go straight into the spec.

    Patchy is its own authorization server. Clerk only signs the person in on the consent page. MCP clients speak OAuth's authorization code flow with PKCE, not device login. Consent still keeps device login's rules:

    • the person confirms in their own signed-in browser;
    • the answer counts only for the account the page showed;
    • an approval nobody collects creates nothing;
    • Patchy stores only hashes, except an encrypted copy of a rotation's new tokens kept for the one minute a retry may ask for them.

    Clerk was ruled out because it can't list or end one person's grant, its refresh tokens never expire, it has no hook for agent access, and its OAuth price is unpublished.

    Clients name themselves only through metadata documents. Patchy advertises Client ID Metadata Documents with the none auth method and offers no dynamic registration.

    • The clients that matter are Claude (Claude.ai, Claude Desktop's connectors, Claude Code) and Codex. ChatGPT is supported where it works. Gemini CLI and Cursor still need dynamic registration and are not a concern.
    • Codex connects through its metadata document from v0.148.0, using its own /callback. A custom callback URL, or --oauth-client-registration dcr, can't connect.
    • Also unable to connect until Anthropic moves them onto metadata documents:
      • Claude Code sign-ins that Claude Desktop starts itself (its Code tab);
      • Claude Desktop deployed on a third-party cloud.
    • Auth methods: Patchy reads a document's list of auth methods when it has one, and its single field otherwise, and accepts a client that offers none. ChatGPT's single field says private_key_jwt while its list includes none; Claude's documents have only the single field.
    • A document is accepted only when its client_id is exactly the https URL fetched and its required fields are valid. The requested redirect must be one the document lists. Grant types Patchy doesn't offer are ignored (Claude's document lists a JWT bearer grant).
    • Fetching a document means fetching a URL a stranger names, so the fetch:
      • never reaches special-use, private, link-local or cloud metadata addresses;
      • pins DNS between the check and the fetch;
      • follows no redirects and accepts only a 200;
      • reads at most 5 KB and gives up after 5 s;
      • caches by the response headers, within bounds, and never caches an error.
    • No list of known or trusted clients. Every consent shows the client's name and its document's site.
    • Patchy keeps no registrations. An agent connection keeps its client's id (the document URL) and the name shown at consent, which is also the "via" name in the log.
    • An early build task: fetch Claude's and ChatGPT's documents from production's real egress. Two reports say claude.ai's Cloudflare edge challenges fetches from some datacenter addresses, and nothing else would let Claude connect.

    An agent connection is one consent.

    • Each consent makes a new agent connection, and reconnecting replaces none. Nothing in OAuth tells two installs of a client apart.
    • A connection left behind by a reconnect is unusable, because the client has discarded its credentials. It stays on Your machines until it is disconnected or goes 30 days without a call.
    • Consent is asked every time, even for a client the person has already connected, because any program on their computer can claim a client's id.

    Lifetimes.

    • Access token: opaque, one hour, checked against the database on every call. Every ending below takes effect on the next call.
    • Refresh token: rotates on every use, and its chain is the connection. There is only ever one chain.
      • A retry within a minute of a rotation gets back the same new tokens. They are kept encrypted for that minute, and revocation is checked before they are served.
      • Any later reuse ends the connection. That revocation commits before the invalid_grant answer.
    • The connection ends after 30 days without a call to /mcp; refreshing alone doesn't count. It has no absolute lifetime, which no MCP or OAuth MUST requires, so consent lasts until something ends it.
    • Last used on Your machines is the last call.
    • Machine tokens are unchanged: 90 days, or 30 idle.
    • What a person notices: nothing, until a connection ends. Then the client's own reconnect appears (Claude.ai's Reconnect, Claude Code's /mcp). Not every client offers one; an unverified report says ChatGPT desktop doesn't. Acceptance checks each client's recovery, and the docs say how to reconnect by hand.

    The consent page must say these things; the mocks ticket draws it.

    • "Connect Claude to Acme?", with the company first.
    • Who is signed in, such as [email protected], with Use another account. An answer from a page left open across an account switch is refused and asked again.
    • It acts as the person. It finds Acme's patches they can open and uses the agent tools their builders added. It can't do anything they can't, and it can't publish.
    • Everything it does is logged as "Jordan via Claude".
    • The client's name and its document's site, and the host the answer returns to. When the answer returns to the person's own computer: "Allow only if you just started connecting it."
    • They can disconnect it any time on Your machines.
    • Deny returns access_denied to the client and records nothing.
    • Other states:
      • Agent access off: the page says so and names the admins. An admin also gets a link to turn it on.
      • Deactivated: the existing deactivated page.
      • No company yet: create-or-join, then back to the consent page.

    Reverse states. An ended connection answers HTTP 401 invalid_token, so the client runs its own reconnect, and the consent page explains anything that still blocks it. A live connection refused by policy gets the surface's refusal shape over HTTP 200. Neither case is ever a 403.

    State What ends How it's seen What the agent gets
    The person disconnects one agent on Your machines That connection: its access tokens and refresh chain It leaves Your machines 401 and the client's reconnect
    Disconnect everything on Your machines (the old Revoke all, for a lost device) Every machine token and agent connection, unredeemed consents, and approved device logins whose terminal hasn't collected its token Your machines is empty 401
    30 days without a call That connection It leaves Your machines 401
    A refresh token reused after its minute That connection It leaves Your machines 401
    Deactivation, which is also how someone leaves a company Every machine token, agent connection, unredeemed consent and uncollected device login, in the deactivation's own transaction The deactivated state, as today 401; reconnecting reaches the deactivated page
    Reactivation Nothing comes back As today Connect again, with fresh consent
    Agent access off No connection ends. Unredeemed consents are cancelled, and consent and the code exchange refuse new connections Off on Company; the consent page says so and names the admins Each tool call gets agent_access_off from patchy: "Agent access is off at Acme. Ask an admin to turn it on: Priya Shah, Sam Ortiz." Initialize, the tool list and refresh keep working, and refused calls count as use
    Agent access on again Nothing On on Company The same connections work on the next call
    • Calls already admitted finish. Each company callback inside them rechecks the connection, the person and agent access, as a page's callbacks recheck the browser session. A mutation is atomic, so it either landed before or not at all.
    • No stale switch: code issuance, the code exchange and agent access changes are serialized, so an exchange never acts on an "on" read before an "off" committed. The same holds for minting against the endings above.
    • A role change doesn't touch the connection; the agent's rights follow the person's on every call.
    • Browser sign-out ends no connection, just as it ends no machine token.

    Admins have two levers and nothing aimed at one person's agent: the agent access switch and deactivation. There is no admin view of connections, and the switch shows no count. Machine tokens and agent connections both stay the person's alone. Allison: "admin can switch. they dont oversee connections of individuals. they deactivate the users account."

    Dev instances.

    • Token endpoint: advertised on 127.0.0.1, because Claude Code sends credentials over plain http only to localhost or 127.0.0.1.
    • Hosted clients are checked in production only. A dev instance is never exposed, because dev personas let anyone sign in as anyone.
    • pnpm dev mcp-token mints agent connections straight into the dev database for launchers that take a pasted token, with a long-lived access token. Only the dev runner can mint one; no route exists for it.
    • Persona switching (GET /dev/sign-in?as=) is refused when the browser says the request came from another site (Sec-Fetch-Site: cross-site or same-site), so a page you visit can't change who you're signed in as. This replaces the same-origin POST agreed in round one, which would have broken every dev tool that switches persona with that GET (pnpm dev open, shot, film, compare, the rollback rehearsal and the documented curl recipe). Those tools send none or no header and keep working unchanged.
    • The consent answer already requires the same origin. The consent page's GET doesn't, because a CLI opens it through the operating system.

    ADR-0008, amended in place and retitled Every bearer is somebody: machine tokens and agent connections. Its opening and its control paragraph become:

    Patchy issues two credentials, both owned by a person and each for one door. A machine token (build) is held by a machine and shared by the agents on it, and lets the CLI act as its person on the API. It expires 90 days after minting or after 30 idle days, whichever comes first. An agent connection (work) lets an MCP client act as its person at Patchy MCP. Neither opens the other's door, and neither opens a company patch's login door, which admits only Clerk's browser session.

    An agent connection is made through OAuth, the protocol MCP clients speak. Patchy is the authorization server; Clerk only signs the person in. A client names itself with a metadata document on its own site, and Patchy keeps no registrations. The person answers on a consent page in their signed-in browser every time, even for a client they've connected before, because any program on their computer can claim a client's id. The answer counts only for the account the page showed. Each consent makes a new connection, since nothing tells two installs of a client apart. The client's code exchange creates the connection, so an abandoned consent creates nothing. A replayed code ends the connection it made.

    Access tokens last an hour and are checked against the database on every call, so every ending takes effect on the next call. A rotating refresh token renews them. A retry within a minute gets the same new tokens, the one secret Patchy keeps recoverable, encrypted, for that minute; any later reuse ends the connection. A connection ends after 30 days without a call, however often it refreshes, and has no absolute lifetime: rotation exposes a copied refresh token once both copies are used, and a forced reconnect every quarter would break hosted connectors for nothing.

    People control their own credentials on Your machines: revoke a machine, disconnect an agent, or disconnect everything, which also cancels device logins and consents that were approved but not yet collected. A machine token is also replaced at its person's next login on that machine and revoked by API logout. Admins have two levers, neither aimed at one credential. Agent access off refuses agents and new connections and cancels consents in progress, but ends no connection. Deactivation ends every one of the person's credentials and pending approvals in one transaction. Reactivation restores none of them.

    The device login, browser sign-out, dead-row and human-owner paragraphs stay as they are.

    Vocabulary for the glossaries, written in with the spec. "Connection" and "disconnect" already belong to Integrations (a company's Postgres or PostHog source), so this one is always an agent connection.

    • Purpose (Auth): What a person's credential is for. build is a machine token's and opens the CLI's API; work is an agent connection's and opens only Patchy MCP. A credential used at the wrong door is refused as unknown. Avoid: scope (OAuth's word), token type.
    • Agent connection (Auth): One person's consent for one install of an MCP client, such as Claude or Codex, to use their company's patches as them through Patchy MCP. Each consent makes a new one and replaces none. It lasts until its person disconnects it, 30 days pass without a call, a refresh token is reused, or the person is deactivated, and it works only while agent access is on. Avoid: connection on its own (Integrations' company source), integration, app (the client, not the connection), grant.
    • Consent (Auth): The person's answer, in their signed-in browser, to a client asking to connect as them. It is asked every time and counts only for the account the page showed. Only the client's code exchange creates the agent connection. Avoid: authorization (the protocol), approval.
    • Updated entries:
      • Machine token (now the build credential).
      • Identity ("the machine or agent connection acting for them").
      • Revocation (covers both credentials, plus a reused refresh token).
      • Your machines (agent connections, with disconnect one and disconnect everything).
      • Agent access (Companies; it also cancels consents in progress).
      • Deactivation and Reactivation (Companies; agent connections beside machine tokens).

    For the tickets

    • Bounds for worker agents (Bounds for worker agents: rate limits, polling and what an agent keeps running #737):
      • There is no registration endpoint.
      • Set limits for discovery, the token endpoint, unauthenticated /mcp and metadata document fetches.
    • The worker pipeline's pages (Prototype: the worker pipeline's pages as static mocks #739):
      • Your machines lists agent connections (name and site, created, last used) with Disconnect and Disconnect everything.
      • Company's agent access switch has no list and no count.
      • The consent page says what's listed above.
      • There is no admin view of connections; it has been removed from that ticket's question.
    • The spec and build tickets (Write the Patchy MCP spec and file the build tickets #740):
      • The ADR-0008 text and the vocabulary above.
      • Allison on clients: "as long as we work with like claude and stuff and then codex those are the key. chatgpt and that we can support if we can". The acceptance journey's ChatGPT leg is best effort.
      • Acceptance records:
        • each checked client's recovery after its connection ends;
        • whether Claude Desktop's Code tab connects;
        • Claude Code and Codex connecting for real through consent against a dev instance on a laptop, since pnpm dev mcp-token skips consent and the document fetch;
        • whether any client calls a revocation endpoint (Patchy offers none).
      • Build items:
        1. The prototype's open redirect before sign-in, first.
        2. Loopback redirects match on any port, with host and path exact, localhost included.
        3. resource is bound through the code exchange and refresh.
        4. The 401 and the protected resource metadata name scope="patches", and the 401 adds error="invalid_token" when a token was sent.
        5. iss on every redirect, and HEAD /mcp answered like GET.
        6. A replayed code ends the connection it made, committed before invalid_grant. redirect_uri is optional at the token endpoint, and checked when sent.
        7. The production egress fetch of Claude's and ChatGPT's documents, early.
        8. Offline tests swap the document fetcher by layer.
        9. Disconnect everything and deactivation cancel approved device logins whose terminal hasn't collected its token. This fixes an existing gap in today's device login.
        10. Persona switching refuses cross-site and same-site requests, as above.
    • Outside this map: A lost laptop stays signed in to Patchy in its browser after Revoke all. Disconnect everything doesn't sign out a lost laptop's browser, which could approve a new connection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

wayfinder:grilling

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions