Repository navigation
feat(mcp): worker agents change patches, and a retried change is applied once - #887
Conversation
9b14bea to
8d83b9f
Compare
25306e0 to
a7c9781
Compare
|
Rollback rehearsal against a |
|
Rollback rehearsal again after round 1, now with a stored change key ( |
Review rounds (GPT-6.1-Sol, xhigh)Round 1, on 25306e0: changes requested
Held by the review: racing retries, conflicts and canonicalization, retries after a publish, actions never replayed, scoping per connection and patch, too-large results, key privacy, and crash takeover. Round 2, on a594349: one blocking, two should-fix
Round 3, on 4ce47b6: nothing blocking, two should-fix
Round 4, on 6aa70a8: nothing blocking, three should-fix
Review stopped after round 4, which found nothing blocking. CI is green on 6aa70a8, and on 875e632 as recorded below. |
|
|
Acceptance: PASSChecked Done means
Codex's clean run, with per-invocation MCP configuration in a temporary directory outside HOME and an isolated Golden journeys
Other risks checked
Surface checklist: wire/result shaping and API docs, CLI/dev-agent and project skill, vocabulary, migrations/server composition, sweep and analytics applied. No dev-runner, new company-database caller, served-page layout, lifecycle API or repository-layout changes. Key expiry supplies the reverse path; the migration's foreign keys cascade when its connection or patch is removed. Rollback answers: match the diff. Reverting leaves the additive Not run
Notes
|
8d83b9f to
ceaa057
Compare
875e632 to
d1b1654
Compare
ceaa057 to
2ed13a7
Compare
…ied once change_patch runs a patch's change tools under a change key the agent picks. Patchy keeps each key for its agent connection and patch for 24 hours, with the first try's version, tool and arguments, in a new change_keys table. A mutation's first try gets a fresh Runtime mutation key that every retry reuses, so a committed change is answered again with replayed: true from any replica, and an unknown outcome resolves on retry without writing twice. An action's key runs once. A try while the first still runs is busy; another change under the key, or a retry after a publish, is refused. A change whose result is too large for an agent succeeds with the result left out. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…own replays say so A retry Patchy hasn't seen commit runs under the first try's mutation key only while Runtime is sure to keep that key's outcome; after that it is refused key_expired. Runtime tells an agent call when another invocation's stored outcome answered it, so that retry also carries replayed: true. Any string is a change key. Settling a key is bounded, the sweep reads its index, and the rollback rehearsal stores a change key and replays it after a rollback. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…holds a request, and every string is its own key The retry window reads the time in the first try's mutation key, which Runtime ages it from, instead of when its row was written. The try and its settling run in a fiber the request only joins, with settling bounded, so a stalled pool can't hold a request or shutdown. Keys hash as JSON, so two lone surrogates stay two keys. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ON rule asks Co-Authored-By: Claude Opus 5.5 <[email protected]>
… keeps its key held and its event The request runs the try directly, so a disconnect reaches Runtime as it does for reads and the request's event keeps Runtime's measurements and replayed. A try that ends settles its key, bounded; one whose agent went away keeps its key held until the lease runs out, the spec's busy, and a retry then resolves through Runtime's record. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…hen its result is left out Co-Authored-By: Claude Opus 5.5 <[email protected]>
d1b1654 to
ad271a6
Compare
… Claude" (#888) Stacked on #887 (ticket #855); merges with the rest of #833's stack, not alone. ## What changed When someone's agent changes a patch through Patchy MCP, the log already recorded the agent's client name (#843) but showed only the person, so an owner couldn't tell a colleague's own edits from their agent's. Now everywhere the log names a person, agent work reads **"Jordan Lee via Codex"**, with the client name shown at consent: the Log tab's Person column and the steps that acted as the person, the card's Recent activity, a connection's recent calls, and `patchy logs` (text and `--json`). There is no new column, tag or filter. Closes #856 ## Look at **Codex on a dev instance (Done means).** On `brightline`, New Business got two agent tools (`listDeals`, a query; `addNote`, a mutation). Jordan's Codex connection (`pnpm dev mcp-token jordan --client Codex`, per-invocation config outside `$HOME`) first listed the deals, then was asked to add a note: ``` find_patches → open_patch → read_patch listDeals (run 1: list the deals) find_patches → open_patch → read_patch listDeals → change_patch addNote (run 2: add a note) ``` The database afterwards: the two quiet `listDeals` reads rolled up with no row; the change has one. ``` runtime_invocations: agent.addNote | mutation | usr_env_brightline_jordan | agent_name Codex | success sample.load | mutation | usr_env_brightline_allison | (none) | success runtime_query_rollups: agent.listDeals | 2 runs ``` **`patchy logs`** on that patch, base CLI and server vs. this branch, same data: ```diff -2026-10-22T20:12:29.005Z · v2 · agent.addNote (mutation) · success · 33 ms · Jordan Lee +2026-10-22T20:12:29.005Z · v2 · agent.addNote (mutation) · success · 33 ms · Jordan Lee via Codex entry inv_… · correlation call_… - tables.update deals · as the patch · success · 4 ms · 1 rows - tables.insert activity · as the patch · success · 2 ms · 1 rows ``` `--json`, each entry's `{ handler, viewer, agent }`: before, entries had no `agent`; after: ``` {"handler":"agent.addNote","viewer":{"id":"usr_env_brightline_jordan","name":"Jordan Lee"},"agent":{"name":"Codex"}} {"handler":"sample.load","viewer":{"id":"usr_env_brightline_allison","name":"Allison Mahmood"},"agent":null} ``` `agent` decodes with a default, so a newer CLI reading an instance from before agents (or after a rollback) prints `null` instead of failing to decode; `docs/API.md` shows it as `agent?`. **The pages**, as Allison (the owner and admin), after (before one click away): Log tab:  <details><summary>Log tab before</summary>  </details> Card, Recent activity:  <details><summary>Card before</summary>  </details> A connection's recent calls:  <details><summary>Recent calls before</summary>  </details> <details><summary>Phones, 390 px: before | after</summary> | Before | After | |---|---| |  |  | |  |  | |  |  | At 390 px the Log and recent-calls tables scroll sideways, as they did before; the longer name wraps in its cell. </details> The recent calls are **staged**: a dev instance can't reach a real Postgres (connections need a public TLS host), so the `postgres/warehouse` connection and its two calls (Jordan's page, then Jordan via Codex) were written straight into the dev database. Everything else above came from real calls. `pnpm dev compare` would have shown no change, since no scenario seeds agent activity, so both sides are this worktree's instance on the same data, with the base's five changed source files restored for "before". **The rule** is pinned at the door on real workerd (`packages/mcp/src/Log.workerd.test.ts`): a quiet agent query leaves no row; a query that logs, a query that fails, a read-only action and a change each get a row naming the person and the agent. Runtime never looked at the agent when deciding to log, so this test passed before the change and keeps it that way. **Escaping.** The client name is a stranger's string (≤ 64 characters, controls and bidi marks removed by #846). Every HTML surface escapes it; the portal and connection tests use `Claude <Code> & co`. The person always comes first and from Patchy's own records, so a client's name can't change whose work a row shows. ## How it was verified - On the head `fd27c49` (on #887's `875e632`): CI is all green. `pnpm verify` passed format, lint, typecheck, synth, postgres-concurrency, cli-smoke, tier2-smoke and browser. Its `test` job hit 8 timeouts in suites this PR doesn't touch, at a load average near 30; those 8 files then passed alone (82 tests). - Targeted suites: portal pages, connection pages, patches API, the whole `packages/mcp` suite (workerd included), `patchy logs` text and CLI, and the api package: 20 files, 279 tests. - Review: GPT-6.1-Sol found nothing in one round (comment below); the diff it read is unchanged by the restacks since. - Acceptance: PASS with notes on `fd27c49` (comment below), on fresh `brightline` data. Its notes are outside this diff: the environment CLI's workerd lookup when publishing (#859) and a cold release build. - `dev.log` keeps writing `usr_dev via patchy dev` (#844): it names everyone by id, so it matches the platform's "<person> via <client>" in its own terms. - `patchy-server`'s agent area states the rule in the tested skill text's words: "Patchy's log records each change and action as "Person via Client", failures included. A query that succeeds without `ctx.log` leaves no row; a patch that wants agent reads seen logs them itself, using `ctx.agent` for the name." - No migration and no descriptor or publish changes, so `rollback-rehearsal` has nothing of this PR's to rehearse; the stack's rehearsal waits on #837 and #838 as #833 says. - An earlier head's CI failed once on Node 24 in `PatchesApi.test.ts › refuses a blank or over-long description in the bundle` ("Invalid server manifest: inspection."), a case this PR doesn't touch. It passed on Node 22 and 26 then, alone on Node 24 in acceptance, and on every Node at `fd27c49`. It isn't filed as a known flake. ## Release impact - [ ] **Breaking** — requires action from anyone already running this - [x] **Not breaking** — no action required An additive field on the log's wire shape and wording on existing pages; no migration. - **What does a revert leave behind?** Nothing: no schema or rows. Agent rows written meanwhile keep `agent_name` from #843's migration. - **Does the release before it still work with that?** Yes. A CLI from this release reading an older instance prints `agent: null`. 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 #886 (ticket #855); merges with the rest of #833's stack, not alone.
What changed
A worker agent can now change a patch through
change_patch, and retrying a change never applies it twice. Until now the door refusedchange_patchas not built.Each change carries a change key, any string the agent picks, such as
import-monday. Patchy keeps it for 24 hours, per agent connection and patch, in a newchange_keystable. Every host replica therefore answers a retry the same way:replayed: trueand runs nothing. A try that ended any other way,unknown_outcomeincluded, runs again under the same mutation key, so Runtime commits it at most once. When Runtime's own record answers that retry, it carriesreplayed: truetoo.busywithretryAfterSeconds: 1. The same key for another tool or other arguments is refused, and so is a retry after a publish.Closes #855
Look at
packages/mcp/src/ChangeKeys.ts, the record. It is three statements on the database's clock.It stores only hashes of the key (as JSON, so lone surrogates stay distinct) and of the arguments' canonical JSON. Key order and how a number is written don't make two changes of one.
Calls.changeinpackages/mcp/src/Calls.ts. It claims the key only after every check passes, and only on a host that runs patch code, so a refusal before running leaves the key free. The request calls Runtime itself, asread_patchdoes, so a hang-up reaches Runtime and the request's event keeps its measurements. A try that ends settles its key, time-bounded. A try whose agent hung up keeps the key held until its lease runs out (the spec'sbusywhile it may still be running), and a retry then resolves through Runtime's record.Codex on a dev instance, with two server processes over one database.
pnpm dev up(team scenario), then a tier 2call-logpatch with anagent/area (logCallstakes a list,listCalls,sendDigest, and laterslowLogandexportCalls), published from the environment's workspace. Ada turned agent access on at Company."Another replica" is a second server process (
apps/server/src/start.ts) started against the same dev database and storage on its own port. ItsPATCHY_PUBLIC_BASE_URLwas its own address, because the door answers only its ownHost. Codex had both as MCP servers:patchy(the instance's server) andpatchy_b(the second process). Both servers' own events confirm it: the first wrotereplayed: falseand the secondreplayed: true.Codex ran as Ada with a token from
pnpm dev mcp-token ada --client Codex, from a temp dir outside$HOME:codex exec --json --ephemeral --ignore-user-config -s read-only -c 'mcp_servers.patchy.url=…' -c 'mcp_servers.patchy.bearer_token_env_var="PATCHY_MCP_TOKEN"', and the same two settings forpatchy_b. Codex honouredchange_patch's destructive mark: underexecwith no approver it refused every change ("MCP tool call requires approval, but approval policy is never"). So the runs add-c 'mcp_servers.<server>.tools.change_patch.approval_mode="approve"'. Tool results are cut here.Three calls in one change, then the retry on the other replica
A reused key for another change, and an action's key used twice
After a second publish: the retry is refused, and a large result is left out
busy: two tries of one key racing on the two processes (curl, same token)
One Codex session can't send two calls at once, so this race used curl with Codex's token.
slowLogwaits three seconds before it writes.Afterwards,
change_keysheld four rows, each with a 64-hex key hash and none with a key in clear. Neither server's log containsimport-monday.How it was verified
ChangeKeys.test.tsdrives the door against an alternate Runtime layer, with two doors over one database as two replicas:1.0for1;busy, or replayed if its claim lands after the commit;key_conflictfor other arguments and for another tool, andversion_changedafter a publish;unknown_outcome, then a patch refusal, then a success, all under one mutation key, then a replay;wrong_kindand a host without patch code all leave no row.ChangeKeys.workerd.test.tsruns on real workerd with two invocations and doors over one database:changeAnswerinagentTools.test.ts, the hourly sweep inSweepSchedules.test.ts, and the migration record's ids.packages/mcp(65 tests),packages/apiagentTools(26),patchy dev agent(6), the server's sweep and migrations (5).pnpm turbo run build --filter=@patchy/server --filter=patchy,tsc -p tsconfig.test.json, and eslint and prettier on the changed files.apps/server/src/migrations.ts, which the vitest template and the rehearsal both apply.change_patchthrough/mcp. At step 4, after the live release ran on that data, the same key must answerreplayed: truewith the first result.rollback-rehearsalcheck against production's commit fails, as Build Patchy MCP #833 says. Runs againstmain's e4243ff, which has both, are recorded in comments below.Choices where the spec is silent
key_conflict(same key, another tool or arguments),version_changed(a retry after a publish),key_used(a later try with an action's key) andkey_expired(below).busyis the spec's.{ version, resultLeftOut }. It has noresult, andresultLeftOutsays the change succeeded and to read through the patch's read tools.changeAnswerin@patchy/apigivespatchy dev agentthe same shape.key_expired, saying to read first and use a new key, because a later retry could find Runtime's outcome swept and write twice. A change Patchy saw commit is answered from its own record for the full 24 hours.busybefore starting. An action's refusal can't say whether it started (a callback'sbusycan surface after a write), so the literal rule is the safe one: the agent retries with a new key.One Runtime change.
Invocation.callAgenttakes an optionalonReplay, carried on theBinding. Invocation calls it when a top-level mutation answers with its key's outcome stored by another invocation. That lets the door, andpatchy dev agent, putreplayed: trueon a retry that Runtime's own record answered, such as one after anunknown_outcome. Mutation keys and page calls are unchanged.Release impact
It adds a table (
0024_change_keys) and a door tool that was refused until now.change_keystable and any rows in it: hashes of keys, version ids, and committed mutation results of at most 64 KiB. Its foreign keys toagent_connectionsandpatchescascade on delete.Built by Claude Opus 5.5 (xhigh) in Claude Code on T3 Code; reviewed and accepted by GPT-6.1-Sol (xhigh).