Repository navigation
feat(mcp): an agent's call keeps its company's server for a minute, and waits for it to start - #892
Conversation
a33769f to
fbc2de3
Compare
Review: GPT-6.1-Sol (xhigh), four roundsRound 1 (at eafd67a): 2 blocking, 2 should-fix. All fixed.
Round 2 (at 4f1e15d): 1 blocking, 2 should-fix. All fixed.
Round 3 (at a33769f): 1 blocking, 1 should-fix. Both fixed.
Round 4 (at fbc2de3): no findings, nothing blocking. Each new test was checked red against its regression and green with the fix. |
Acceptance: PASS with notesChecked Done means
Golden journeys
Additional checks Run serially at the head, with one Vitest worker: These cover the exact default 60 s / 30 min boundaries, long in-flight work, settlement-before-unlock, failed clock updates, deployment replacement and snapshot races, abandoned waits, and nested admissions. The deadline test passed: a 30 s bind wait plus a 2.9 s process start succeeds; a 3.1 s process start times out. All current PR checks are green. Rollback answers: match the diff. The migration adds two columns with compatible defaults; the predecessor ignores them and accepts agent-only rows with Not run
Notes
|
5d20897 to
725b481
Compare
fbc2de3 to
80f172a
Compare
725b481 to
d6eb363
Compare
…nd waits for it to start A company task now has two clocks. The documents' thirty minutes run from the last document letting go or page work settling, as before, starting no earlier than the first housekeeping pass to find no document holding the task; agents never move them. An agent's call runs its own minute (execution.company.agentIdle) from when it settles, nested work and cleanup included, recorded before it lets go of the binding. The task is released once no document holds it, no admitted work is in flight on it or on a binding of the company still draining, and both clocks have run out. A call on a released company waits for the bind inside its request, outside the handler's deadline, for one execution.pool.wait across its tries; the process start after it counts against the deadline. The door refuses a wait past it as busy: "Acme's server is starting; try again in 15 seconds." A call's event says how it found the server (bound, spare, launch) and how long it waited; binding events say whether the binding was agent-only. Co-Authored-By: Claude Opus 5.5 <[email protected]>
80f172a to
113db7f
Compare
…r 2 patches have agent areas (#894) Stacked on #892 (ticket #858); merges with the rest of #833's stack, not alone. ## What changed A dev environment had only a builder agent, so trying a patch's agent area meant hand-building a client config each time, and the environment's own CLI couldn't publish a tier 2 repo at all. Now `pnpm dev up` puts two worker agent launchers beside `agent`: `worker-claude` (Claude Code, connecting through consent) and `worker-codex <person>` (Codex, with a connection minted by `pnpm dev mcp-token`). Neither loads your instructions, skills, plugins or config, and both reach Patchy only through `/mcp`. `brightline` starts with agent access on, and New Business and Spend Requests have agent areas that keep their rules. Closes #859 ## Look at **1. The launchers' isolation**, in `scripts/dev/src/environment.ts` (`writeWorkers`). Both start in the environment's own `workers/` folder behind the builder's guard (`PATCHY_API_URL` is the instance, the shell's `PATCHY_API_TOKEN` is cleared) with a CLI state that never logs in and a temp folder per session. - **Claude Code**: `--setting-sources project`, the builder's `claudeMdExcludes` for every folder above the environment, `--strict-mcp-config` with one server, auto memory off, `--permission-mode default`. Its sign-in can only live in your `~/.claude/.credentials.json`, keyed by the server's name and address, so the server name is `patchy-dev-<hash of the worktree path>`: one entry per worktree address, replaced by the next sign-in there. `down` leaves it, because your running Claude Code sessions rewrite that file when they refresh and a second writer could drop a refresh and sign you out. DEVELOPMENT says so and how to clear it (`/mcp` › Clear authentication). - **Codex**: `CODEX_HOME` is the environment's, with a `config.toml` naming only the door and turning off the account's `apps`, `plugins` and `remote_plugin` (without that, the TUI listed my ChatGPT connectors, 217 tools, and a plugin from my account). `HOME` is the session's temp folder, because Codex reads skills from `~/.agents/skills` whatever `CODEX_HOME` says. Your login is linked in; Codex writes `auth.json` in place through the link (checked with `codex login --with-api-key` on a throwaway home), so a refresh lands in your one file as another session's would. The token reaches Codex's environment only: the config excludes `PATCHY_MCP_TOKEN` from the commands Codex runs and turns shell snapshots off (Sol's round 1 found both leaking it; a command inside Codex printed `env | grep -c '^PATCHY_MCP_TOKEN='` → 1 before, 0 after, with no snapshot under `CODEX_HOME`). What Codex sees, from `worker-codex jordan debug prompt-input`, which renders the model's prompt without a model call: ```text skill roots: ['<env>/worker-state/codex/skills/.system'] "agents/skills": 0 "~/.codex": 0 personal instructions: 0 token: 0 ``` What the Claude worker reports, `worker-claude -p --model haiku`: ```text skills: dataviz, update-config, keybindings-help, code-review, simplify, … (Claude Code's bundled ones; its code-review is the bundled one, not mine) instructions: NONE MCP servers: patchy-dev-04bc0n ``` **2. The env CLI publishes tier 2**, a separate commit (`fix(cli)`). The CLI resolved workerd beside its own install, so the environment's `bin/patchy` (and any global `patchy`) failed every tier 2 publish and `patchy dev`. A tier 2 repo pins the exact workerd the CLI checks for, so publish and the dev runtime now run the repo's own, as they already run its vite and tsc. `startWorkerd`/`Inspection` take an optional `workerdFrom`; the server never passes it. ```console # before (base), in <env>/workspace/new-business $ patchy publish --json {"ok":false,"error":"Could not inspect the server bundle. Its modules must load and export only valid handlers.","kind":"local","code":"invalid_manifest"} # after $ patchy publish --json {"ok":true, …, "versionNumber":2, "warnings":[]} $ patchy dev --json → {"ok":true,"url":"http://127.0.0.1:<port>/dev/…"} $ patchy dev agent listRequests '{"status":"submitted"}' --json {"result":{"total":0,"requests":[]},"version":1} ``` **3. brightline's agent areas** reuse the patches' rules rather than restating them: `move`, `addNote`, `team.people`, `approve` and `reject` are re-exported from `server/` with descriptions added there; `addLead` and `submitRequest` are tools of their own, with the shared insert moved to `helpers/leads.ts` and `helpers/requests.ts`. `addLead` requires a next step, which the page leaves optional; `submitRequest` takes no receipt, so the patch's own `receipt_required` stops anything from $500. `listDeals` and `listRequests` answer 50 at a time with `total` and `next`, which `from` continues (checked with 55 requests: 50 + `next` 50, then 5 + `next` null). The seed turns agent access on as the publisher only while nobody has touched the switch, so turning it off at Company survives restarts. <details><summary>Done means: Codex adds a lead to New Business through <code>/mcp</code></summary> `pnpm dev up brightline`, then `<env>/worker-codex jordan exec --skip-git-repo-check --json -c '…change_patch.approval_mode="approve"' "Add a lead to New Business: Lumen Labs wants a website refresh, a referral from their CEO. Next step: intro call on Tuesday. Leave the value and owner empty." < /dev/null`. Results cut. ```text agent: I'll find New Business and add Lumen Labs with the referral and next step, leaving value and owner empty. find_patches {"search":"New Business"} → {"actingFor":{"person":"Jordan Lee","company":"Brightline Studio"},"total":1,"patches":[{"name":"new-business",…,"tools":["addLead","addNote",…]}]} open_patch {"patch":"new-business"} → {"name":"new-business",…,"tools":[{"name":"addLead","kind":"change",…}]} change_patch {"patch":"new-business","tool":"addLead","key":"lumen-labs-website-refresh-20261023", "args":{"title":"Website refresh","client":"Lumen Labs","source":"Referral","service":"Website","nextStep":"Intro call on Tuesday"}} → {"result":{"id":"01a165b6-…","stage":"lead","owner":null,"value":null,…},"version":2} change_patch {"tool":"addNote","args":{"deal":"01a165b6-…","note":"Referral from Lumen Labs' CEO."}} → {"result":{…,"kind":"note"},"version":2} agent: Added Lumen Labs — Website refresh to New Business as a lead, with a CEO referral note and "Intro call on Tuesday" as the next step. Value and owner are empty. ``` The patch's log, as its owner (`patchy logs --limit 2` in the repo): ```text … · v2 · agent.addNote (mutation) · success · 84 ms · Jordan Lee via Codex … · v2 · agent.addLead (mutation) · success · 471 ms · Jordan Lee via Codex ``` A patch rule, met through the door (Codex as Jordan, "move the Lumen Labs website refresh to Proposal"): ```text change_patch {"tool":"moveDeal","args":{"deal":"01a165b6-…","stage":"proposal"}} → {"code":"needs_value_and_owner","from":"patch","details":{"stage":"proposal","missing":["value","owner"]}} ``` Interactive too: `worker-codex marcus`, then "Which deals are in Negotiation in New Business?" called `find_patches`, `open_patch` and `read_patch`, and `/mcp` listed only `patchy-dev-04bc0n` and Codex's built-in `codex_worktrees`. </details> <details><summary>Done means: the Claude Code launcher connects through consent</summary> `<env>/worker-claude --model haiku` in a terminal, `/mcp` › `patchy-dev-04bc0n` › Authenticate. Its browser URL was answered as Jordan in a throwaway Playwright browser (personas sign-in, then Allow):  ```text ❯ /mcp ⎿ Authentication successful. Connected to patchy-dev-04bc0n. ❯ In Spend Requests, which requests are waiting for a decision? Approve the smallest one that someone else submitted, with the note: fine by me. (Claude Code asked before each call; each answered Yes) find_patches {search: "Spend Requests", detail: "tools"} · open_patch {patch: "spend"} · read_patch {tool: "listRequests"} change_patch {tool: "approveRequest", args: {id: "01a165b0-…", note: "fine by me"}, key: "approve-saltwater-hotel-priya-2026-10-23"} ● I approved the smallest pending request that someone else submitted: Priya Shah's hotel for the Saltwater site visit (2 nights), $438.20, with the note "fine by me." … I skipped the two you submitted yourself (the $2,850 photographer and the $1,800 copywriter), since approving your own request isn't allowed. ``` </details> ## How it was verified - **Neither launcher reads your instructions or touches `~/Patchy`.** Over all the runs above: `~/Patchy`'s listing is unchanged; `~/.codex/config.toml` and `~/.codex/AGENTS.md` hash the same and `~/.claude/settings.json` and `~/.claude/CLAUDE.md` keep their mtimes; no token-shaped string (`pw[ar]_…`) appears anywhere in the environment folder or `.local/dev`, `dev.log` included; no Codex or Claude process with the environment's paths outlived its session. What the runs did add outside the environment: Claude Code's `patchy-dev-04bc0n` sign-in in `~/.claude/.credentials.json`, and its trust of `<env>/workers` in `~/.claude.json`, both Claude Code's own writes. - `scripts/dev/src/environment.test.ts`: the Claude launcher's guard, worker CLI state, its one server and the excludes; the Codex launcher mints for the named person in this worktree, hands the token only to Codex (the launcher prints nothing of it), runs on its own `CODEX_HOME` and `HOME`, links your login, drops a stale link when you have none and leaves the login alone when started from a shell already on that home, writes the door, the apps/plugins switches, the snapshot switch and the token's shell exclusion into `config.toml`, and starts no Codex when minting fails. - `scripts/dev/src/scenario.test.ts`: seeding brightline turns agent access on as the publisher, and a later off survives a reseed. Red without each half of the seed change. - `packages/execution/src/Inspection.test.ts`: inspection runs the workerd where it's told, and refuses one of another version found there. Red with the resolver reverted. - Both agent areas typecheck and publish with no warnings; their 9 tools are listed in publish's `handlers`. - `pnpm verify` on 33b5445: everything passed except `test/browser-tier1/csv.spec.ts` (instance-side inspection timed out at load ~15); it passed alone, and CI's `browser` job passed on the same head. - Targeted: `vitest run scripts/dev packages/execution/src/Inspection.test.ts packages/patchy/src/devServerWatch.test.ts`, 104 passed; turbo typecheck of execution, the CLI and the dev runner; `tsc -p tsconfig.test.json`; eslint and prettier on the changed files. - Not exercised: Claude Code's own consent in a real browser of yours (Playwright answered it), and macOS. - The vitest template is unchanged: it applies `applyDevSeed`, which this doesn't touch; the scenario seed isn't part of it. ## Release impact - [ ] **Breaking** — requires action from anyone already running this - [x] **Not breaking** — no action required Dev tooling, scenario data and docs, plus one CLI fix: a `patchy` installed outside a tier 2 repo now builds it with the repo's pinned workerd instead of failing. No schema, API or wire change. - **What does a revert leave behind?** Environments already up keep the worker launchers until their next `up`; Claude Code sign-ins already made stay in that developer's credentials file, harmless. A global CLI goes back to refusing tier 2 repos. - **Does the release before it still work with that?** Yes. Nothing it reads changes. 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 #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
busywithretryAfterSeconds: 15.Closes #858
Look at
packages/execution/src/fleetStore.ts).last_activity_atstays the documents' clock, withidle_sinceas 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 newagent_activity_atis the agents' clock. Agent admissions run only their own clock and never set or clearidle_since.idleFencereleases 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.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.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.handler_timeout.How it was verified
TestClock, all red before the change:bound/spare/launchand the wait, including a wait refused at the end ofexecution.pool.wait;agentOnly.read_patchandchange_patchasbusy, "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.pnpm dev up brightline, withcountDeals, a read tool, added to New Business. Agent access was turned on at/company, and Jordan's token came frompnpm 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 hadEXECUTION_PROVIDER=local-fleet, its ownEXECUTION_LOCAL_DIRECTORY,EXECUTION_CALLBACK_URLS/EXECUTION_CALLBACK_PORTandPATCHY_PUBLIC_BASE_URL, and short clocks throughPATCHY_LIMITS_JSON:{"execution.company.agentIdle":10000,"execution.company.idle":60000,"execution.housekeeping.interval":1000}, plusexecution.fleet.budgetandexecution.pool.waitfor the last run. A script sentread_patchto that host's/mcp, and a watcher printed Brightline's bindings from the database.Run at the PR's head (fbc2de3):
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
A tab beside the agent keeps its own clock (tab 60 s, agent 10 s): released after both, never extended by agent calls
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)
Calls made the instant the company was released, before the replacement spare was ready (
execution.fleet.budget: 1):A Patchy Dev tab holding the only task the budget allows, so Brightline's server can't start (
"execution.pool.wait":5000):Patchy Dev's patch is a copy of New Business published by the instance's dev key.
Release impact
Additive migration
0025_agent_idle:execution_bindings.agent_activity_at(default 0) andexecution_binding_history.agent_only(nullable).last_activity_at = 0.0is a validlast_activity_atto it, and its ownidle_sincestep gives such a binding a fresh thirty minutes.idle_sincekeeps 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).