Repository navigation
feat(mcp): agents' calls are held to 300 a minute per patch and 16 in flight per person - #889
Conversation
b2ab836 to
fd27c49
Compare
60fdaeb to
50274ce
Compare
Review: GPT-6.1-Sol (xhigh), two roundsRound 1 (at 3d625ad): one blocking finding, nothing else.
Checked and clean in round 1:
Round 2 (at f293ed9): nothing blocking. Sol confirmed the round 1 fix: children retain independently, mutation retries and rebinds stay under the same hold, and callback fencing prevents a late child dispatch. No further race, double hold or leak. One should-fix:
|
Acceptance: PASS with notesChecked Done means
{"route":"/mcp","status":200,"mcpTool":"read_patch","agentTool":"countDeals","outcome":"refused","code":"rate_limited","limitId":"mcp.calls.perMinute","clientName":"Codex"}
{"route":"/mcp","status":200,"mcpTool":"read_patch","agentTool":"waitAction","outcome":"refused","code":"busy","limitId":"mcp.inFlight","clientName":"Codex"}Other risks checked
Golden journeys
Mirrored surfaces: registry and rendered limits, Limits/MCP vocabulary, the release-bound Rollback answers: match this PR's diff. No migration, descriptor, wire or infrastructure change. Counters are in memory; optional new limit-override rows remain readable but unused by older code. No Not run
Notes
|
fd27c49 to
1013df8
Compare
5d20897 to
725b481
Compare
1013df8 to
52de1e0
Compare
… flight per person read_patch and change_patch pass the door's admission once they reach their target, before a change key is claimed or anything runs: the person's calls a minute on the patch (mcp.calls.perMinute, 300), their calls in flight across every agent (mcp.inFlight, 16), then the company's admission, which agents now spend from the same bucket as pages (CompanyAdmission, moved out of RuntimeProduction). Every counter is per host replica and keyed by the person. A refusal is the refusal shape over HTTP 200 with retryAfterSeconds, writes no log row, keeps the change key free, and names its limit in the request's event. An admitted call holds its slot until its work settles: the request holds it while it runs, and Runtime retains it as it dispatches the work (AgentCall's retain) and lets go when that work ends, so a client that hangs up after dispatch leaves its slot held and one that gives up before gives it back. An agent's actions take their own tier2.actions.viewer key beside the person's page, and an action Runtime refuses before it starts gives its change key back. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…version history Every read_patch and change_patch, and every catalogue call, read the company's patches through Patches.read, whose shared-read edges scan the declarations of every version of every patch. On a company of 200 patches with 20 versions each that was about 190 ms of database time per call, which at 300 calls a minute would keep a platform database core busy for one person's agent. Patches.list answers the same patches by the same rule without those edges, which the door never shows; a call there now takes about 27 ms, flat in versions. The portal keeps Patches.read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ettles An action's ctx.run child is its own run, which can outlast the action when the action is fenced, so the slot came back while the child still ran. Every run in an agent call's tree now takes its own hold at its fork and lets it go when it settles, as Runtime's execution lease already follows the tree. Co-Authored-By: Claude Opus 5.5 <[email protected]>
…s its change key The supervisor refuses a bind or invoke for residency capacity before dispatch, so the handler never ran, yet the action's key was settled as used and a retry after the busy got key_used. ExecutorBusy now gives the key back, as an action slot or bind refusal does. Co-Authored-By: Claude Opus 5.5 <[email protected]>
725b481 to
d6eb363
Compare
…nd waits for it to start (#892) Stacked on #889 (ticket #857); merges with the rest of #833's stack, not alone. ## What changed An agent's call used to keep its company's server for thirty minutes, as a tab does, so an agent polling every few minutes kept a company running around the clock. Now an agent's call keeps the server for a minute after it settles, on a clock of its own that never touches a tab's thirty minutes, and a call on a released company waits for the server to start (up to 40 s) before it's refused `busy` with `retryAfterSeconds: 15`. Closes #858 ## Look at - **Two clocks on the binding row** (`packages/execution/src/fleetStore.ts`). `last_activity_at` stays the documents' clock, with `idle_since` as before: the window starts no earlier than the first pass to find no document holding the task. A binding no document or page ever touched (`last_activity_at = 0`) skips that step. The new `agent_activity_at` is the agents' clock. Agent admissions run only their own clock and never set or clear `idle_since`. `idleFence` releases once no document holds the task, nothing is in flight on it or on a binding of the company still draining, and both clocks are out. - **A settling call runs its clock before it lets go of the binding**, so no pass can find the binding free with the clock not yet run. It lets go even if that update fails, and then keeps its crash protection to the deadline. Clocks only move forward (`GREATEST`), so a settlement that lands late never shortens a later one's window. An update that finds no live binding runs once more, because a replacement that committed while it waited is outside its snapshot. That costs a warm call one more statement, six instead of five: the clock, then the protection clear. - **A tab's window starts when a pass first sees it gone**, even while agent work holds the binding. So overlapping agent calls can't postpone a tab's thirty minutes. - **Who called** is now a required argument of `ExecutionLifecycle.acquire` (`"page" | "agent"`), set by Invocation from the binding's agent. Nested calls ride on their parent's one admission, so the agent's clock starts when the whole tree, cleanup included, settles. - **The deadline.** The bind wait was already outside the handler's deadline, and the process start inside it. A new Invocation test pins both: 30 s waiting for the server, then a 2.9 s start succeeds and a 3.1 s start is `handler_timeout`. ## How it was verified - Fleet tests on Postgres with `TestClock`, all red before the change: - an agent-only binding survives 5 min of in-flight work and is released exactly 60 s after settling; - a call that settles on a binding a deployment replaced while it ran still gets its minute on the replacement; - a pass landing right after a long call lets go of the binding finds the minute already running; - a document holder that vanished without letting go still leaves its thirty minutes from the first pass to find it gone; - a tab that leaves while an agent's call runs starts its thirty minutes then, not when the call ends; - a settled call whose clock update fails still lets go of the binding and idles out after its protection; - a call settling while a deployment replacement commits runs its minute on the replacement; - an abandoned cold wait still says how long it waited; - a tab's 30 min and an agent's minute run side by side: a call 29m30s after the tab let go keeps the task until 30m30s, not 59m30s; - a call's event says `bound` / `spare` / `launch` and the wait, including a wait refused at the end of `execution.pool.wait`; - binding events carry `agentOnly`. - The door test: a bind-wait refusal reaches `read_patch` and `change_patch` as `busy`, "Acme's server is starting; try again in 15 seconds.", `retryAfterSeconds: 15`. - `pnpm typecheck`, eslint on the changed files, and the execution, runtime, mcp, analytics, limits and server suites. - **Dev-instance run.** `pnpm dev up brightline`, with `countDeals`, a read tool, added to New Business. Agent access was turned on at `/company`, and Jordan's token came from `pnpm dev mcp-token jordan --client "Claude Code"`. The dev runner's server is no-pool and its environment is closed, so a second host from this worktree ran beside it on the instance's database and storage. It had `EXECUTION_PROVIDER=local-fleet`, its own `EXECUTION_LOCAL_DIRECTORY`, `EXECUTION_CALLBACK_URLS`/`EXECUTION_CALLBACK_PORT` and `PATCHY_PUBLIC_BASE_URL`, and short clocks through `PATCHY_LIMITS_JSON`: `{"execution.company.agentIdle":10000,"execution.company.idle":60000,"execution.housekeeping.interval":1000}`, plus `execution.fleet.budget` and `execution.pool.wait` for the last run. A script sent `read_patch` to that host's `/mcp`, and a watcher printed Brightline's bindings from the database. Run at the PR's head (fbc2de3): <details><summary>An agent calling every 30 s (for every five minutes; agent idle 10 s): each call binds and the company is released ~11 s later</summary> ``` 22:36:08 call 1: 200 {"result":{"deals":17},"version":2} 565 ms 22:36:09 bindings 24:active 22:36:20 bindings 24:stopped, bound 11.4 s, idle, agentOnly true 22:36:38 call 2: 200 252 ms 22:36:39 bindings 25:active 22:36:50 bindings 25:stopped, bound 10.9 s, idle, agentOnly true 22:37:09 call 3: 200 346 ms 22:37:09 bindings 26:active 22:37:20 bindings 26:stopped, bound 10.7 s, idle, agentOnly true binding event: {"type":"binding","releaseCause":"idle","agentOnly":true, ...} ``` </details> <details><summary>A tab beside the agent keeps its own clock (tab 60 s, agent 10 s): released after both, never extended by agent calls</summary> ``` 22:37:25 bindings 27:active Jordan opens New Business 22:37:29 call A: 200, 59 ms runs on the tab's binding, no new one 22:38:04.976 the tab leaves last_activity_at 22:38:04.976, idle_since 22:38:05.221 (next pass) -> the tab's window runs to 22:39:05 22:38:25 call B: 200, 121 ms had it touched the tab's clock: no release before 22:39:25 22:39:00 call C: 200, 123 ms agent_activity_at 22:39:00.322 -> agent clock runs to 22:39:10 22:39:10.541 bindings 27:stopped, bound 105.6 s, idle, agentOnly false ``` </details> <details><summary>A call on a cold company waits for the bind; one past the pool wait is refused busy (budget 1 task, pool wait 5 s)</summary> Calls made the instant the company was released, before the replacement spare was ready (`execution.fleet.budget: 1`): ``` call 1: {"companyBind":"launch","bindWaitMs":1646,"durationMs":1980} call 2: {"companyBind":"launch","bindWaitMs":942,"durationMs":1254} call 3: {"companyBind":"launch","bindWaitMs":761,"durationMs":1003} call 4: {"companyBind":"launch","bindWaitMs":1096,"durationMs":1434} ``` A Patchy Dev tab holding the only task the budget allows, so Brightline's server can't start (`"execution.pool.wait":5000`): ``` 22:40:35.364 Patchy Dev's tab holds the only task 22:40:35.366 call: 200 after 5228 ms {"error":{"code":"busy","from":"patchy","message":"Brightline Studio's server is starting; try again in 15 seconds.","retryAfterSeconds":15}} event: {"companyBind":"launch","bindWaitMs":5003,"outcome":"refused","code":"busy","limitId":"execution.pool.wait"} 22:41:34.855 Patchy Dev released; a spare is ready 22:41:34.859 call: 200 {"companyBind":"spare","bindWaitMs":42} ``` Patchy Dev's patch is a copy of New Business published by the instance's dev key. </details> ## Release impact - [ ] **Breaking** — requires action from anyone already running this - [x] **Not breaking** — no action required Additive migration `0025_agent_idle`: `execution_bindings.agent_activity_at` (default 0) and `execution_binding_history.agent_only` (nullable). - **What does a revert leave behind?** The two new columns, and bindings an agent claimed with `last_activity_at = 0`. - **Does the release before it still work with that?** Yes. It never reads the new columns. `0` is a valid `last_activity_at` to it, and its own `idle_since` step gives such a binding a fresh thirty minutes. `idle_since` keeps the meaning both releases give it, so a rollout or rollback keeps every document's window. 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 #888 (ticket #856); merges with the rest of #833's stack, not alone.
What changed
A person's agent could call a patch through Patchy MCP as often, and as many calls at once, as its client liked. Only the door's 600 requests a minute held it back. Its calls spent none of the company's admission, and its actions took the same two action slots as the person's own tab. Now
read_patchandchange_patchare admitted per person, as the spec's Bounds set out:mcp.calls.perMinute), across their agents, beside the page's ownruntime.calls.perMinute. An agent's loop never touches its person's tab.mcp.inFlight), across their agents. The seventeenth isbusywithretryAfterSeconds: 1. An admitted call holds its slot until its work settles, including after its client hangs up.tier2.actions.viewerkey of their own beside the person's page. The company's action slots stay shared.Every counter is per host replica and keyed by the person, never an address or connection. A refusal is the refusal shape over HTTP 200 with
retryAfterSeconds, writes no log row, keeps the change key free, and names its limit id in its wide event.Each call is also cheaper: it used to read the company's patches with a scan of every version's manifest, about 190 ms per call at 200 patches × 20 versions. It now skips that scan and takes about 27 ms (second commit, measured below).
Closes #857
Look at
Done means, on a dev instance (
brightline, New Business given agent tools, tokens frompnpm dev mcp-token, driven by a script against/mcp). The loop usescountDeals, a read-only action, which always writes a log row, so rows count admitted calls exactly.Jordan's tab while his agent was refused:
The two refusals' wide events, from
dev.log:The two
busycases stay apart in events: a change key still running has nolimitId, and the in-flight cap's saysmcp.inFlight.On the dev instance, 17 slow queries at once got 8 through and 9
busyfrom the company's database connections. A query holds a connection for its snapshot while it runs. This is the spec's note that 16 in flight can still fill the company's connections, and it is not the cap. The in-flight run above uses read-only actions, with Brightline's action slots raised by an override so the cap is what's measured.How the slot follows the work (
packages/mcp/src/Admission.ts,Invocation.AgentCall.retain). The order is: the minute on the patch, then a slot, then company admission, all before a change key is claimed. The request holds the slot while it runs. Runtime takes one more hold for each run it forks, inside its uninterruptible region, nestedctx.runchildren included, and lets each go in that run'sensuring. The slot comes back when every hold is gone.An action Runtime refuses before it starts gives its key back. That covers its own action slots (
InvocationBusy), a refused bind (LifecycleError) and the execution service at capacity (ExecutorBusy). Before this PR, abusyrefusal said to retry in a second, and the retry with the same key gotkey_used. A mutation's key is never discarded, because its retry already runs under its mutation key.The per-call company patch read (handed over from #854). Every agent call, and every catalogue call, read the company's patches through
Patches.read. Its shared-read edges scan theusesof every version of every patch. Measured on the test Postgres, with manifests the size of New Business's (3 KB stored), p50 over 35 calls on a loaded machine:Patches.read(portal, unchanged)read_patch, beforePatches.list)At 189 ms a call, one person's agent at 300 a minute on one patch would keep about one platform database core busy, and two across patches under the door's 600. That isn't comfortable.
Patches.listanswers the same patches by the same rule withoutreadsanddependants, which the door never shows. With it, 300 a minute costs about 0.14 database seconds per second per person per patch, flat in versions and linear only in patches. The portal still usesreadand pays the version scan on each page. That is out of scope here; caching or bounding those edges is the lever if it shows in data.CompanyAdmissionis the company token bucket, moved out ofRuntimeProductioninto its own service now that it has two consumers.RuntimeProduction.layerprovides it, so the door spends the same instance as pages.How it was verified
packages/mcp/src/Admission.test.ts(4 cases):packages/runtime/src/Invocation.test.ts:retaintaken at dispatch and let go when the work settles, after the caller is interrupted, and held by actx.runchild after its action returns; never taken by a call refused, or given up, before dispatch. Fails without the change.packages/patches:listanswers whatreaddoes, minus the edges.packages/mcp,packages/runtime,packages/patches,packages/portal,packages/integrations,packages/limits(thedocs/limits.mdrender test) andpackages/api/agentToolsare green. A few runtime and catalogue cases timed out at load average 50–67 and passed when rerun alone. Typecheck,tsconfig.test.json, lint and format are clean.mainat e4243ff, which has 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:pnpm test:rollback-rehearsal --live e4243ffpassed e4243ff → 3d625ad → e4243ff → 3d625ad in 360 s. The later commits touch no migration or descriptor schema.pnpm verifyon 5d20897: all passed (format, lint, typecheck, synth, test, postgres-concurrency, cli-smoke, tier2-smoke, browser). CI is green on the same head.brightlinedata), in the verdict comment below. Its one load flake, a supervised-workerd diagnostics case, passed alone and is filed as flaky: supervised workerd diagnostics misses invocation settlement deadline under load #895.Release impact
New operating limits with defaults. No migration, and no wire or CLI change.
mcp.calls.perMinuteormcp.inFlight, if anyone set them, stay as rows the older release doesn't read.Built by Claude Opus 5.5 (xhigh) in Claude Code on T3 Code; reviewed and accepted by GPT-6.1-Sol (xhigh).