Repository navigation
feat(mcp): every way a person's credentials end also ends their agent connections - #879
Conversation
Review rounds (GPT-6.1-Sol, xhigh)Round 1, on 5a30481: nothing blocking or should-fix. The brief asked about three areas. The reviewer's answers:
Review stops here: the round found nothing blocking. |
Acceptance: PASS with notesChecked Done means
Golden journeys
Local evidenceFocused command: Rollback answers: They match the diff. No new schema or external contract is introduced by this layer. Single disconnect leaves the existing Not run
Notes
All temporary instances were taken down. The checkout remains clean at the checked head; no PR code, branch, body, or labels were changed. |
82a05f4 to
39527c5
Compare
2f28800 to
0a1da02
Compare
39527c5 to
18cac61
Compare
… connections Each row of the spec's endings table now ends what it says, and the next call sees it. Disconnect everything and deactivation end every agent connection through #838's credentials-ended stamp alone, which the release before the stack writes too, so a rollback can't bring one back. AgentConnections.disconnect ends one of the person's own connections; nobody else, an admin included, can aim at it. Endings.test.ts has one test per row, and races a connection's exchange against a deactivation and a refresh against Disconnect everything in both orders. The rollback rehearsal now runs live, HEAD, live, HEAD: the live release deactivates, reactivates and disconnects everything, and HEAD then finds both connections dead and the approved device login minting nothing. ADR-0008 reads as decided. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
0a1da02 to
2e06801
Compare
… own authorization metadata (#880) Stacked on #879 (ticket #847); merges with the rest of #833's stack, not alone. ## What changed An MCP client such as Claude or Codex first reads how Patchy wants it to connect, then names itself with a metadata document on its own site. Patchy now publishes its protected resource metadata for `/mcp` and its authorization server metadata, and it can fetch and judge a client's document under the spec's rules. That document's URL is a stranger's, so the fetch is the SSRF-sensitive part of this PR. Nothing calls it yet: #849's authorize and code exchange do. Closes #848 ## Look at **The fetch reaches only global unicast, and connects only to the answer it checked.** `ClientDocuments` resolves the host once through `ClientDocumentNetwork.resolve`. It refuses the fetch if *any* answer isn't global unicast, then hands the checked addresses to `connect`. The production `connect` opens TLS for the host name, with `lookup` answering from those addresses, so the name is never resolved again. The address rule moved from the Postgres integration to `@patchy/core` (`isPublicAddress`), so both refuse the same set: only `2000::/3` passes for IPv6, so mapped, compatible, NAT64, 6to4 and Teredo forms all fail, and so do `169.254.0.0/16` and `fd00:ec2::254`. A client id must be the URL parser's own canonical https form on a host name. That refuses decimal, octal, hex and short-form IPv4, any IP literal, dot segments, userinfo, fragments and the default port before anything is fetched. ```text # The production layers against the real URLs, from a dev machine: {"url":"https://claude.ai/oauth/mcp-oauth-client-metadata","ms":184,"result":{"clientId":"https://claude.ai/oauth/mcp-oauth-client-metadata","name":"Claude","site":"claude.ai","redirectUris":["https://claude.ai/api/mcp/auth_callback"]}} {"url":"https://claude.ai/oauth/claude-code-client-metadata","ms":143,"result":{"clientId":"https://claude.ai/oauth/claude-code-client-metadata","name":"Claude Code","site":"claude.ai","redirectUris":["http://localhost/callback","http://127.0.0.1/callback"]}} {"url":"https://chatgpt.com/oauth/client.json","ms":62,"result":{"clientId":"https://chatgpt.com/oauth/client.json","name":"ChatGPT","site":"chatgpt.com","redirectUris":["https://chatgpt.com/connector_platform_oauth_redirect"]}} {"url":"https://chatgpt.com/oauth/codex/client.json","ms":70,"result":{"clientId":"https://chatgpt.com/oauth/codex/client.json","name":"Codex","site":"chatgpt.com","redirectUris":["http://127.0.0.1/callback","http://localhost/callback"]}} {"url":"https://claude.ai/oauth/does-not-exist","ms":22,"result":{"_tag":"ClientDocumentUnavailable","site":"claude.ai","stage":"status","status":403}} {"url":"https://localhost/client.json","ms":1,"result":{"_tag":"ClientDocumentUnavailable","site":"localhost","stage":"address"}} ``` **The other limits live in two places.** The HTTP rules are in `get`: no redirect, 200 only, a declared `Content-Length` over 5,000 refused before the body, a chunked body cut off once it crosses 5,000 bytes, and the whole fetch, DNS included, timed out at 5 s. The host limits are two maps in `ClientDocuments.make`: `kept` holds accepted documents, least recently used first, and `running` holds the one fetch for each URL. - **Running fetches.** Every load that arrives while a fetch runs waits on it, failures included. The fetch belongs to the service's scope, not the first caller. Claiming a URL and forking its fetch can't be interrupted apart. An observer on the fetch fiber settles every waiter however it ends, so an interrupted load or a shutdown never strands a URL. Keeping documents never evicts a running fetch. - **What's kept.** A document is kept for its `max-age`, or `Expires` − `Date`, or the hour row when neither is sent. `Age` counts against each, the time is counted from the request, and the hour is the cap. `no-store`, `no-cache`, `max-age=0` and a malformed or repeated `max-age` keep nothing, and a failure is never kept. - **Starts.** Each miss spends one of 30 starts a minute host-wide before fetching. A hit spends nothing. **Accepting.** `client_id` must equal the URL exactly. `client_name` and `redirect_uris` are required, as MCP's client registration requires, and every listed redirect must be an absolute URI without a fragment. `token_endpoint_auth_methods_supported` is read when present and `token_endpoint_auth_method` otherwise, and must offer `none`. That is exactly why ChatGPT's recorded document (single field `private_key_jwt`, list `["none", "private_key_jwt"]`) is accepted. Grant types and other fields are ignored. `redirectAllowed` matches an https redirect the document lists exactly. It matches plain http to `localhost`, `127.0.0.1` or `[::1]` on any port, with the host and path exact, and only when written canonically, so only the port varies. It never allows plain http to another computer, even when listed. **Patchy's metadata.** `/.well-known/oauth-protected-resource/mcp` (and the root form) name `scope="patches"`. `/.well-known/oauth-authorization-server` advertises `client_id_metadata_document_supported`, `none`, `S256`, `patches`, `iss` and no `registration_endpoint`. Both send `cache-control: public, max-age=3600`. In production they also send `access-control-allow-origin: *` without credentials, and answer a preflight with the spec's headers. `OAuthMetadata.cors` and `preflight` are exported for #849's token endpoint and #851's door. A dev instance (a loopback public origin, the rule dev personas already used, now `Session.isLoopback`) sends no CORS and advertises `http://127.0.0.1:<port>/oauth/token`, whatever loopback host it is served on. ## How it was verified - `packages/auth/src/ClientDocuments.test.ts`, 25 tests over a real HTTP server on loopback behind a test `ClientDocumentNetwork`, with one test per rule. Highlights: - Claude's, Claude Code's, ChatGPT's and Codex's documents, recorded byte for byte as fixtures in `@patchy/auth/testing`, all accepted. - 17 resolver answers refused before any connection, including `169.254.169.254`, `fd00:ec2::254`, `::ffff:127.0.0.1`, `64:ff9b::a9fe:a9fe`, `0.0.0.0`, `::`, and a public answer mixed with a private one. - A rebinding resolver: the first fetch connects only to the checked addresses, and the next fetch re-resolves and refuses the private answer without connecting. - Every 3xx and non-200 refused, with exactly one request seen. - 5,000 bytes accepted. A declared 5,001 is refused with no body sent, and a chunked 5,001 closes the connection. - A silent server and a trickling body both time out at 5 s and not at 4.999 s (`TestClock`). - 17 cache-header cases, errors and refused documents never kept, and LRU eviction at the entry limit. - Busy past the minute's starts, with a cache hit spending none. 20 concurrent loads make one request for a success and for a 500. 40 URLs at once make exactly 30 fetches. - A running fetch survives the kept documents filling up. Closing the service before a fetch runs ends every waiting load. - `ClientDocumentNetwork.test.ts`: the production `connect` reaches a TLS server on `127.0.0.1` under the unresolvable `client.invalid`, sends that name as SNI and refuses its self-signed certificate. - Mutation check: removing each of these makes the suite fail. The address check, the declared-size check, the canonical client id, list-before-single, `no-store`, `Age`, the loopback host match, the 200-only rule, the start limit and the IP-literal refusal. - `OAuthMetadata.test.ts` covers both documents, the preflight, and dev instances on `<label>.localhost`, `localhost` and `127.0.0.1`. `Server.test.ts` shows the full server answers `/.well-known/*` ahead of `/:company/:name/*`. - GPT-6.1-Sol reviewed in three rounds; [the findings and their fixes](#880 (comment)). Round 3 found nothing. - `pnpm test:rollback-rehearsal --live e4243ff` (release 16, live, with #837 and #838) passed: `e4243ff → fd374a4 → e4243ff → fd374a4, in 161s`. The commit after fd374a4 only changes `ClientDocuments.load` and a test, and adds no migration. - `vitest run packages/limits packages/auth packages/core apps/server/src/Server.test.ts`: 297 passed. The Postgres integration's `Source.test.ts` passed after the move. Typecheck (packages and tests) and lint pass. - Not checked here: a real client connecting, which needs #849's endpoints, and the fetch from production's egress, which #834 already showed for all four documents. ## Release impact - [ ] **Breaking** — requires action from anyone already running this - [x] **Not breaking** — no action required New routes and an in-memory service. No migration, configuration or wire contract changes, and the three new limits are optional `PATCHY_LIMITS_JSON` ids with defaults. Within the stack, the metadata names `/oauth/authorize` and `/oauth/token`, which #849 builds. Nothing here ships before the whole stack does. - **What does a revert leave behind?** Nothing: no rows, schema or stored state. Clients that cached the metadata for its hour would find `/oauth/*` gone, as before the stack. - **Does the release before it still work with that?** Yes. Built by Claude Opus 5.5 (xhigh) in Claude Code on T3 Code; reviewed and accepted by GPT-6.1-Sol (xhigh).
## What changed This PR adds release 17's What's new entry, written from `5dd94f3`. It covers everything merged since release 16's `through` (`dd3f41f`), and it sets the `patchy` release to `0.17.0` in `packages/patchy/package.json` and `CURRENT_RELEASE`. With this release, people's agents can use their company's patches through Patchy MCP (#833). | Change | PRs | | --- | --- | | New: Your AI agent can use your company's tools | #873, #878, #880, #881, #882, #883, #884, #886, #887 | | New: Admins choose whether agents can use the company's tools | #871 | | Improved: Your machines shows your agents too (Revoke all machines is now Disconnect everything) | #885, #879 | | New: See what agents can do with a tool | #876 | | New: The log says when an agent made a change | #888 | | New: Your agent can make a tool ready for agents | #869, #870, #872, #875, #896 | | Behind the scenes: agents' calls have their own limits, and a server only an agent uses rests a minute after its last call | #889, #892 | | Behind the scenes: New and Improved changes are public, for patchyhq.com | #893 | | Behind the scenes: library updates | #899 | Five merged PRs get no line: - #874 is release 16's own entry. - #894 is dev tooling: worker agent launchers and scenario data. Its one CLI fix lets a `patchy` installed outside a tier 2 repo publish it. The skills have agents use the repo's pinned `pnpm patchy` instead, so that path is off the documented one. - #900 is CI. - #901 rewords an internal skill. ## Look at - **The entry**, at the top of `releases` in `packages/core/src/whatsNew.ts`. - It names only Claude Code and Codex. Both have connected through real consent against dev instances. Hosted clients (Claude.ai, ChatGPT) are checked in production only (`docs/product.md` › Patchy MCP › Acceptance). - Its labels are the pages' own: Agent access on Company, Your machines, What agents can do, Disconnect everything, and "Jordan Lee via Claude". - **Rollback safety, from the live commit `e4243ff` to `5dd94f3`.** - No PR in the range is labelled `one-way`, and every PR answers both Release impact questions with "Yes". - Migrations 0020–0025 are all additive: - three defaulted or nullable columns on `companies`; - `agent_name` on the runtime log, with a widened `credential_kind` check; - the agent connection tables, `agent_consents` and `change_keys`; - two columns on execution bindings. The new tables reference `users` without a cascade, but no release deletes users or companies. Release 16 reads the runtime log only for credential kinds it knows, so rows from agents can't break it. - `rollback-rehearsal` on #892 rehearsed the whole stack, since #892 adds the last migration and the rest of the stack sits below it: `Exercised rollback paths passed: e4243ff → c8bede4 → e4243ff → c8bede4, in 238s.` #896's run skipped, because it changes no migration or handler descriptor. - #883 turns on the load balancer's host header preservation, which the Deploy workflow's app stack deploy applies. A rollback leaves it on. That's harmless, because release 16's server never reads `Host`. - A rollback takes `/mcp` and `/whats-new.json` away. Connected agents get a 404 until this release returns, and then their connections work again, unless one ended in between. Agent tools published in between stay refused to pages, because #837 already shipped in release 16. ## How it was verified - `pnpm check` on `2d528b1`: format, lint, typecheck and synth passed. In the test step, 2,300 of 2,301 tests passed. The one failure was `packages/sdk/src/install.test.ts` › "says how to reach patchy when the prefix's bin is not on PATH", which timed out at 180 s while the shared machine was loaded. Rerun alone, that file passes all 7 tests in 62 s. The release's own tests pass too: `whatsNew.test.ts`, `schemas.test.ts` and `WhatsNewPages.test.ts`. - The live commit was pinned from `/healthz/deep`: `e4243ff`, release 16. The Deploy run updated last succeeded, and none is unfinished. - Each PR in the range was read with `gh pr view`, including its Release impact answers. ## Release impact - [ ] **Breaking** — requires action from anyone already running this - [x] **Not breaking** — no action required This PR changes only the changelog text and the `patchy` version. As with every release, a CLI installed before this deploy is told to upgrade. - **What does a revert leave behind?** Nothing. People whose seen marker reached 17 would just see no new release. - **Does the release before it still work with that?** Yes. If this release misbehaves, roll back to `e4243ff54d2acbbc88b60eeb0cf9b82a26dc9d5d` (release 16). Prepared by Claude Opus 5.5 (xhigh) in Claude Code on T3 Code. Co-authored-by: Claude Opus 5.5 <[email protected]>
Stacked on #878 (ticket #846); merges with the rest of #833's stack, not alone.
What changed
A person ends an agent connection in several ways: they disconnect it, press Disconnect everything, leave it 30 days without a call, or have its refresh token reused. Deactivation ends it too, and reactivation brings nothing back. Each of these now ends what the spec's endings table says, in one transaction, and the next call sees it. That includes a rollback to the release before the stack. ADR-0008 now reads as decided, retitled Every bearer is somebody: machine tokens and agent connections.
Closes #847
Look at
Disconnect everything and deactivation end agent connections through #838's stamp alone. Neither writes an
agent_connectionsrow. #846's check already treats a connection made at or beforeusers.credentials_ended_atas dead, and both endings already set the stamp in their own transaction, under the person's row lock. Release 16 sets the same stamp and knows nothing of agent connections, so a rollback that ends credentials still ends connections. This PR keeps that one mechanism rather than adding a second. OnlyMachineTokens.revokeAllandUsers.deactivatechange, and only in their comments.revokeAllneeds no machine token to exist, as #853 will rely on.The one new write is
AgentConnections.disconnect({ id, userId }), for Your machines' Disconnect (#853 wires the route). It is oneUPDATE … RETURNINGscoped to the owner. Another person's id, an admin's included, isAgentConnectionNotFound. Disconnecting a connection that has already ended keeps its first stamp. The statement takes only the connection's row, which refresh also holdsFOR UPDATEwhile it rotates. It holds no lock before or after that one, so it can't invert refresh's user-then-connection order.The races, tested deterministically. Each test holds one side's transaction open, waits until the other blocks on a lock in
pg_stat_activity, then commits:UserUnavailable, so reactivation finds nothing to bring back. When the exchange commits first, the deactivation's stamp comes later on the database's clock and ends the connection. Withcreate'sFOR SHAREremoved, the first case fails: the exchange returns a live connection made against a committed deactivation, and it survives reactivation.ended. When the refresh commits first, what it issued dies with the connection.Every comparison is
clock_timestamp()againstcredentials_ended_at, both written under the person's row lock, so no app server's clock enters it.The rollback rehearsal now runs four steps: live → HEAD → live → HEAD.
workcheck refuses Jordan's and Priya's connections and still accepts the publisher's;unknown. Anexpiredanswer would show nothing, so it fails as well;How it was verified
packages/auth/src/Endings.test.ts, one test per row of the endings table. Each asserts the next call and the next refresh:Red before green: on Agent connections: the
workcredential and its tokens #846's code, only the disconnect row failed (connections.disconnect is not a function). The stamp rows passed already, which is the point of the first item under Look at.The auth suites (
Endings,AgentConnections,DeviceLogins,MachineTokens,DevicePages) and the companiesUserssuite pass. Typecheck and lint pass.pnpm test:rollback-rehearsal --live e4243ff(release 16, live since 2026-10-22, with Tier 2 readers accept handler descriptions, read-only actions and agent tools, and enforce them #837 and Deactivation and Disconnect everything end pending device logins and record when a person's credentials ended #838) passed:Step 4 also fails when it should. A throwaway commit whose
workcheck ignores the stamp fails step 4, naming both members. Its device poll still answered410 unknownand the machine token401:That run also exercised the head's sturdier
press, which waits for the new document after a form's POST. CI'srollback-rehearsalrehearses the head against production, which is release 16.Surfaces. ADR-0008 has the decided text word for word. Its device login and confirmation paragraphs stay as they are, and so do the dead-row, browser sign-out and human-owner sentences. #838's stamp sentence now covers agent connections. The decision line adds the sign-in decision with #846, #847 and #849.
GLOSSARY-MAP.mdcarries the new title. The Auth glossary's Revocation, Device login and Your machines and Companies' Deactivation and Reactivation already read as built, so they're unchanged.docs/OPERATIONS.md› Rolling back anddocs/DEVELOPMENT.mddescribe the fourth step. There's no route, CLI, API or migration change: #853 adds the Disconnect route and #849 the consent rows.Release impact
No schema change. One new service method, comments, a test file, the ADR and the rehearsal.
revoked_at. Nothing else is written.Built by Claude Opus 5.5 (xhigh) in Claude Code on T3 Code; reviewed and accepted by GPT-6.1-Sol (xhigh).