Skip to content

feat(mcp): Runtime runs agent tools for people's agents, as their person - #873

Merged
allisonmahmood merged 1 commit into
mainfrom
mcp/843-runtime-agent-invocations
Oct 23, 2026
Merged

allisonmahmood merged 1 commit into
mainfrom
mcp/843-runtime-agent-invocations

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

Stacked on #872 (ticket #842); merges with the rest of #833's stack, not alone.

What changed

People's agents need a way to run a patch's agent tools as the person who connected them. The door (#854) and patchy dev agent (#844) will both call through one entry point, Invocation.callAgent. It runs a tool on the version the caller read it from, as the person, with the agent's name in Patchy's own binding, which nothing in a request can set.

An agent's call can start only a marked agent tool. Handler code sees the agent as ctx.agent, nested calls included. Every log row of the call names the agent, and the caller's recheck runs before each company callback.

Closes #843

Look at

1. Admission (packages/runtime/src/Invocation.ts). #837 already refused a page's call to an agent tool, at any depth. This PR adds the other half: at the top level an agent starts only a marked tool, and inside it ctx.run reaches ordinary siblings as usual. callAgent refuses a person outside the version's company. Invocation.test.ts › "only an agent's call reaches a marked agent tool, nested calls included" covers both directions:

  • an unmarked agent.* handler is refused;
  • a page handler named by an agent binding is refused;
  • agent rides on the top-level and every nested Invoke, and is absent from a page's.

With the new rule removed, the test goes red: expected 'invalid_request' to equal 'access_denied'.

2. ctx.agent across releases (packages/api/src/guest.ts, packages/execution/src/loader.ts, packages/patchy/src/guest.ts). The Invoke and the guest request carry agent only on an agent's calls. Older loaders and published guests decode strictly, so a page's call never sends the field and keeps working on them. A guest reads a missing agent as null.

In a mixed fleet, a new host's agent call to an execution task from an older release is refused by that task's strict decode and fails as handler_failed. It never runs with ctx.agent null. Page calls are unaffected.

3. The log (migration 0021_runtime_log_agents):

  • runtime_invocations.agent_name is set on every invocation of an agent's call tree.
  • Callback rows (runtime_calls) get credential kind agent with agent_name, under a check that ties the two together. That follows the Runtime glossary's Runtime log: the call names the agent connection, not a session.
  • RuntimeLog.Call and InvocationLog.Invocation read it back as agent: { name } | null, so The log says which agent made each change: "Jordan Lee via Claude" #856 only has to render it.
  • Integrations' recent calls label the credential "A person's agent, Claude, using a patch's agent tool" instead of "A viewer's session".
  • dev.log says usr_… via patchy dev agent.listDeals success 12ms (devLog.test.ts).

4. One live test on supervised workerd and Postgres (InvocationLocal.test.ts › "an agent's call runs its tool as the person…"). It builds a real bundle whose agent/ file re-exports a page query, then checks four things:

  • The re-exported query: ctx.agent is { name: "Claude" } from the agent and null from the page.
  • Nesting: an action's ctx.run sibling sees the same agent.
  • The log: a mutation tool's write is logged with credential agent and the agent's name, and every top-level and nested invocation row names Claude beside usr_dev.
  • The recheck: one that passes once and then fails stops the second members.get (2 rechecks, 1 read).

With the loader's forwarding removed, this test goes red.

How it was verified

Release impact

  • Breaking — requires action from anyone already running this
  • Not breaking — no action required

Additive: two nullable columns and a widened credential check. The guest wire's new field is optional and only sent for agent calls, which nothing makes until the door ships in this stack.

  • What does a revert leave behind? Migration 0021's agent_name columns and widened credential_kind check, plus any rows agents wrote in the meantime.
  • Does the release before it still work with that? Yes. It never writes agent, and its log reads filter credential kinds to the ones it knows, so agents' callback rows stay hidden instead of failing to decode. Agents' invocation rows read as the person's own, without the agent's name.

Built by Claude Opus 5.5 (xhigh) in Claude Code on T3 Code; reviewed and accepted by GPT-6.1-Sol (xhigh).

@github-actions github-actions Bot added area:server Touches the server area area:cli Touches the cli area area:docs Touches the docs area area:integrations Company connections and integration implementations area:ui Portal and first-party browser pages, shared rendering and styles size:m 100-500 changed lines labels Oct 22, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Review: GPT-6.1-Sol (xhigh), round 1 on 04f3206. No blocking, should-fix or nit findings.

Sol checked these areas and found them correct:

  • top-level admission both ways, including subscriptions and nested ctx.run;
  • nested ctx.agent, with the guest wire leaving agent out for pages, so older loaders and guests keep serving them;
  • an agent call against an older execution task fails closed;
  • migration 0021's constraints, and the rollback to dd3f41f, which filters unknown credential kinds on read;
  • the caller's recheck before every company callback at any depth;
  • the log reads and the touched surfaces (API.md, the patchy-server skill, the dev log).

It ran 123 tests across 13 files.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Acceptance: PASS with notes

Checked 3a4945659406b0e01328c0c7f647cd96921d620a (base c6020af9c299eb020526b6ce9dd63407e28d3979) on fresh brightline data and isolated Runtime/browser fixtures, by GPT-6.1-Sol (xhigh) in Codex on T3 Code.

Done means

  • Agent context runs a marked tool and refuses an unmarked handler: passed. Invocation.test.ts checks marked, unmarked, missing and wrong-company calls; refused admission never reaches the executor.
  • Page context refuses a marked tool: passed, including subscription and nested-call admission.
  • ctx.agent reaches nested calls: passed on real supervised workerd. The re-exported handler sees the agent from an agent call and null from a page; ordinary nested siblings retain the person and agent.
  • Log rows name the agent: passed for root and nested invocation records, callback credential attribution and dev log output. An independent rendering check confirms connection details name the agent and escape a script-shaped agent label.
  • A failing recheck stops the next callback: passed. The real guest makes two rechecks and only one directory read. An independent nested-call probe gets the same result; a recheck returning a different person or company is refused before any directory read.

Golden journeys

  • Publish a page / find and open existing tools: passed for CLI identity, listing, publishing, Home and every seeded tier 0/1/2 patch in the rollback rehearsal, before upgrade, after upgrade and after rollback.
  • Use a tier 1 tool live, runtime portion: passed. A colleague's write reaches the subscribed screen, and reconnect recovers a missed write.
  • Use a tier 2 tool, runtime portion: passed. Two viewers stay synchronized; an existing document retains its version across publishing, and removing a handler ends only the new version's obsolete subscription.
  • Agent writes reaching live pages: passed at the notification boundary. An independent real-workerd/Postgres probe confirms a committed mutation announces its table resource. Replaying its mutation key returns the same reply without another row or notification; a failing mutation rolls back without a notification; a distinct key writes and announces again.

Additional risks and mirrored surfaces

  • The base commit's actual RuntimeLog reader hides a newly written agent callback row, and its session writer still works on the upgraded schema. The new reader returns that session with agent: null.
  • Invalid session/agent attribution is refused by runtime_calls_agent_check.
  • Actual base guest/loader schemas still accept page requests and strictly reject requests carrying the new agent field. The new guest schema accepts both shapes. Combined with the passing invocation and workerd tests, this verifies omission for pages and forwarding for agents.
  • Checked the private wire and generated API docs, loader/guest forwarding, runtime/dev log readers, SDK context and skill, existing Runtime vocabulary, connection-page attribution, migration 0021, and affected portal/API log consumers. No command flags, exit codes, new company-database caller, lifecycle door or package layout changed.
Local evidence: 488 tests, 2 browser journeys, and rollback rehearsal

Focused Runtime, execution Local/Engine, devExecution, guest, devLog, ConnectionsView and server migration suites:

Test Files  31 passed (31)
     Tests  307 passed (307)

Independent real-workerd/Postgres acceptance probe:

Test Files  1 passed (1)
     Tests  1 passed (1)

API, patch log API, portal, and independent mixed-release/connection-rendering checks:

Test Files  9 passed (9)
     Tests  180 passed (180)

Browser journeys:

two viewers stay in sync and a removed handler ends only its new-version subscription — passed
a colleague's write updates the subscribed screen and reconnect catches a missed write — passed
2 passed (51.3s)

pnpm test:rollback-rehearsal --live dd3f41f26da57474bd53df564a8f8b8d3d029847:

Step 1: dd3f41f seeds the data — passed
Step 2: 3a49456 upgrades it — passed
Step 3: dd3f41f comes back — passed
Exercised rollback paths passed: dd3f41f → 3a49456 → dd3f41f, in 204s.

Rollback answers: match the diff. Nullable agent-name columns and the widened credential constraint remain; older readers tolerate the added rows. No one-way label is needed. The head's CI rollback rehearsal also passed all three steps against release e4243ff, through GitHub's test merge, in 200 seconds. The red rollback gate recorded in the previous verdict no longer applies to this head's CI result.

Not run

  • Full pnpm verify and live Clerk were not rerun locally. In CI for this head, Node 22/26 tests, lint/typecheck/synth, concurrency, browser, tier 2 smoke, Node 26 CLI smoke and Clerk have passed. Node 24 tests and the other CLI smoke job were still running at the final check; their completion is not claimed here.
  • The exact Brightline CRM-stage/self-approval controls and Home search were not replayed locally. The changed runtime path and live-update behavior were exercised as described above.
  • A real mixed-release ECS fleet and the future MCP door / patchy dev agent callers were not exercised. Those callers belong to Worker agents read patches through their agent tools #854/Builder agents call their agent tools locally with patchy dev agent #844.

Notes

  • No behavioral failures found. Remaining CI jobs must finish before treating the PR as ready to merge. The PR body still describes the older red rollback rehearsal; the current head's rehearsal is green.

@allisonmahmood
allisonmahmood force-pushed the mcp/842-schemas-publish branch from c6020af to b27f0c9 Compare October 23, 2026 02:08
@allisonmahmood
allisonmahmood force-pushed the mcp/843-runtime-agent-invocations branch from 3a49456 to a89e676 Compare October 23, 2026 02:09
@allisonmahmood allisonmahmood mentioned this pull request Oct 23, 2026
@allisonmahmood
allisonmahmood force-pushed the mcp/842-schemas-publish branch from b27f0c9 to f0f2048 Compare October 23, 2026 12:14
Base automatically changed from mcp/842-schemas-publish to main October 23, 2026 12:24
Invocation.callAgent is how Patchy's own agent callers, the door and
`patchy dev agent`, start a tool: on the version they read it from, as
the person, with the agent's name in the binding, which no request can
set. An agent's call starts only a marked agent tool; inside it, ctx.run
reaches sibling handlers as usual. The tool's kind runs it through the
same invocation as a page's call.

The guest wire carries `agent` only on an agent's calls, nested ones
included, so loaders and guests built before it keep serving pages, and
handler code reads its absence as ctx.agent null.

Every invocation row of an agent's call names the agent beside its
person, and its callbacks' rows name the agent connection as their
credential (migration 0021). dev's log says "<person> via <agent>". The
caller's recheck runs before each company callback, as a page's session
check does, so a failing one stops the call at its next callback.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood force-pushed the mcp/843-runtime-agent-invocations branch from a89e676 to fa5e9ea Compare October 23, 2026 12:24
@allisonmahmood
allisonmahmood merged commit ffea887 into main Oct 23, 2026
25 of 26 checks passed
@allisonmahmood
allisonmahmood deleted the mcp/843-runtime-agent-invocations branch October 23, 2026 12:39
allisonmahmood added a commit that referenced this pull request Oct 23, 2026
… dev agent` (#875)

Stacked on #873 (ticket #844); merges with the rest of #833's stack, not
alone.

## What changed

In the skill test, no builder agent could call its own agent tools
before publishing, so each told its person the tools were untested. Now
`patchy dev agent` lists a patch's tools as a worker agent sees them,
and `patchy dev agent <tool> [<json>|-]` calls one the way Patchy MCP's
door will, against the running `patchy dev` session, as the dev viewer
or the colleague (`--colleague`). Open dev pages update live.

Closes #844

## Look at

**1. One call path, the door's shapes**
(`packages/patchy/src/devAgent.ts`, `packages/api/src/agentTools.ts`).
Each dev mount answers a nonce-guarded `POST /~dev/agent` as its own
person. The daemon reads the binding once, checks that the tool exists
and that its arguments fit the schema on that version, and calls
`Invocation.callAgent` (#843) with `ctx.agent` `{ name: "patchy dev" }`.
A change gets a fresh key: a mutation's becomes its mutation key, which
the daemon reuses on a retry of `unknown_outcome`. An action is never
retried. Answers come from the shared module, which gains
`unknownToolRefusal`, `invalidArgsRefusal`, `runtimeRefusal` and
`callAnswer`, so the door (#854) shows agents the same words. The agent
access switch is never read.

**2. The CLI contract** (`devLifecycle.ts`, `CliError.ts`, ADR-0004).
These follow the ticket's exit codes:
- 0: a result.
- 2: any refusal the door would give. ADR-0004's failure document gains
`from`, `details` and `retryAfterSeconds`.
- 1: a local problem: `not_running`, `no_agent_tools`, or arguments that
aren't one JSON object.
- 3: a started call got no usable answer.

**3. Naming the binding** (`devServer.ts`, `devResources.ts`). Server
builds are counted per session, and a call's `version` is its build.
`dev.log` now says `Server build N ready`. When the latest rebuild
failed, the answer says the last good build answered, in `warnings`
under `--json`.

A live run on this worktree's dev instance, with a starter tier 2 repo
and two tools in `agent/notes.ts`:

```
$ pnpm patchy dev agent addNote '{"title":"Call Acme back"}'
{
  "result": { "id": "01a16390-…", "by": "Patchy Dev", "via": "patchy dev" },
  "version": 1
}
Server build 1 answered as Patchy Dev via patchy dev.
[exit 0]
$ echo '{"title":"Send the deck"}' | pnpm patchy dev agent addNote - --colleague
{ "result": { "id": "01a16390-…", "by": "Dev Colleague", "via": "patchy dev" }, "version": 1 }
Server build 1 answered as Dev Colleague via patchy dev.
[exit 0]
$ pnpm patchy dev agent listNotes --json
{"result":["Send the deck","Call Acme back"],"version":1}
[exit 0]
$ pnpm patchy dev agent addNote '{"title":" "}' --json
{"ok":false,"error":"agent-notes refused addNote (blank): give the note a title.","kind":"rejected","code":"blank","from":"patch","details":{"message":"give the note a title"}}
[exit 2]
$ pnpm patchy dev agent addNote '{}' --json
{"ok":false,"error":"addNote's arguments don't fit its schema: Missing key at [\"title\"]. Fix them from its args in open_patch.","kind":"rejected","code":"invalid_args","from":"patchy"}
[exit 2]
# (since review round 1 this refusal also names the tools the patch has now and says to call open_patch)
$ pnpm patchy dev agent create '{"title":"x"}' --json
{"ok":false,"error":"agent-notes has no tool create. Its tools now: addNote, listNotes. Call open_patch to see what each does and takes.","kind":"rejected","code":"unknown_tool","from":"patchy"}
[exit 2]
$ pnpm patchy dev agent addNote '[1]' --json
{"ok":false,"error":"A tool's arguments are one JSON object, such as '{\"name\":\"Acme\"}'.","kind":"local"}
[exit 1]
# listNotes' description deleted, so the rebuild fails:
$ pnpm patchy dev agent listNotes
{ "result": [ … ], "version": 1 }
Server build 1, the last good one, answered as Patchy Dev via patchy dev: the latest rebuild failed. Read `pnpm patchy dev logs`.
# description restored:
$ pnpm patchy dev agent listNotes
{ "result": [ … ], "version": 2 }
Server build 2 answered as Patchy Dev via patchy dev.
```

The colleague's dev page was open throughout. Before and after `patchy
dev agent addNote '{"title":"Book the venue for Friday"}'` ran as the
primary viewer, with no reload in between:

![Colleague page
before](https://github.com/user-attachments/assets/ba50a3bb-36b7-4a15-9d84-8ec7cdc33b13)
![Colleague page
after](https://github.com/user-attachments/assets/a0d295b2-fa31-49b2-9132-897ff61d76d8)

## How it was verified

- `devAgent.test.ts` runs on supervised workerd and PGlite, through
`DevResources` as `patchy dev` builds it. It checks:
  - `open_patch`'s answer;
- a change as the viewer and as the colleague, each publishing the wake
open pages re-run on;
  - a read that sees both, with `ctx.agent` and the person;
  - the dev settlement naming the agent;
- the patch's refusal, `invalid_args` and `unknown_tool` (the page's own
handler isn't a tool), and `handler_failed`;
  - `no_agent_tools` for tier 2 without tools and for tier 1.
- `cliDevAgent.test.ts` runs the bundled CLI against a stub daemon. It
checks the request, both outputs, `-` and `--colleague`, the stale
build, and exits 0, 2 (with `from`, `details`, `retryAfterSeconds`), 1
(arguments, `no_agent_tools`, `not_running`) and 3 (a 500, an unreadable
reply).
- The live run above on `pnpm dev`, including the open page.
- `agentTools.test.ts` covers the shared refusals and `callAnswer`.
`devServer`, `devServerWatch`, `devExecution`, `devLifecycle`, `devLog`
and all of `packages/api` pass. `pnpm typecheck:tests` and eslint pass,
and `docs/API.md` is re-rendered.
- `pnpm verify` on cdd420b passes all nine steps: format, lint,
typecheck, synth, test (2,090 tests), postgres-concurrency, cli-smoke,
tier2-smoke and browser. CI is green on cdd420b. `clerk-live` hit its
10-minute job cap twice on slow runners and passed on the third run.
- `pnpm test:rollback-rehearsal --live dd3f41f` passes. dd3f41f is the
`main` commit with #837 and #838; the run was dd3f41f → cdd420b →
dd3f41f. This PR adds no migration.
- Review: GPT-6.1-Sol (xhigh), two rounds. Round 1 had one blocking
finding, round 2 none. Every finding is fixed or dismissed with a reason
in the review comment.
- Acceptance: [PASS with
notes](#875 (comment))
on cdd420b. It also forced a lost reply after a committed mutation (the
retry wrote once) and after an action (it ran once and warned it may
have partly happened).

## Release impact

- [ ] **Breaking** — requires action from anyone already running this
- [x] **Not breaking** — no action required

A new CLI subcommand and a new route on the local dev daemon. It adds no
migration and no instance route. The one changed log line is `Server
binding ready` → `Server build N ready` in `dev.log`, and nothing parses
it.

- **What does a revert leave behind?** Nothing. The command and daemon
route go with the release, and no data changes shape.
- **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).
allisonmahmood added a commit that referenced this pull request Oct 23, 2026
## 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:cli Touches the cli area area:docs Touches the docs area area:integrations Company connections and integration implementations area:server Touches the server area area:ui Portal and first-party browser pages, shared rendering and styles size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Runtime runs agent tools for agents, as their person

1 participant