Repository navigation
feat(companies): admins turn agent access on and off at Company - #871
Conversation
7eeba59 to
d6421bf
Compare
cec9b2d to
736e18f
Compare
d6421bf to
b8ec35d
Compare
8584fe3 to
7f93c31
Compare
1ac249c to
c00413f
Compare
Review: GPT-6.1-Sol (xhigh), two roundsRound 1 (head d6421bf): nothing blocking.
Sol also checked the rest and found it sound: the page copy against the mock, escaping and the shell components, the admin-only same-origin route, events after commit, the seed and template defaults, and no Round 2 (head 1ac249c): no blocking, should-fix or nit findings. All three fixes hold. |
7f93c31 to
814cd9c
Compare
c00413f to
e3ecce3
Compare
Acceptance: PASS with notesChecked Done means
Golden journeys
Other risks
Focused command: pnpm exec vitest run packages/companies packages/auth/src/CompanyPage.test.ts packages/auth/src/AuthPages.test.ts packages/auth/src/DevicePages.test.ts packages/serving/src/Pages.test.ts apps/server/src/migrations.test.tsRollback answers: match the diff. A revert leaves three additive company columns and any latest-change stamp; the preceding release ignores them and its inserts use defaults. No Not run
Notes
|
bde24e7 to
884ef8a
Compare
e3ecce3 to
1257031
Compare
884ef8a to
2e2a24a
Compare
Agent access is stored on the company, starts off, and records who made the latest change and when (migration 0020). Admins flip it with one button at the foot of Company; every member sees the state and the stamp. A change is a business event, and code issuance and exchange can hold the switch against a change with holdAgentAccess. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A FOR SHARE read that waits for a change re-reads the company row but not the joined user, so the held read could return a fresh switch with no stamp. Issuance and the exchange need only the switch, so holdAgentAccess returns whether it is on. The test now waits for a session blocked by the holder itself. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1257031 to
7dead9d
Compare
…blish lists them (#872) Stacked on #871 (ticket #841); merges with the rest of #833's stack, not alone. ## What changed People's agents will know a patch's agent tools only from what Patchy shows them, and the door, `patchy dev agent`, the card and publish must all show the same thing. The shapes they share now live once in `packages/api` (`agentTools.ts`): handler descriptors as JSON Schema 2020-12, `open_patch`'s tools, the agent area check, and how a tool call answers or refuses. Publishing a patch with agent tools now checks them, names the fix when one is wrong, and lists them: ``` Agent tools: addLead (change), listDeals (read). People's agents use these through Patchy's MCP at <instance>/mcp. Warning: Agent access is off at Acme, so no agent can use these agent tools yet. An admin turns it on at <instance>/company. ``` Closes #842 ## Look at **1. The schema mapping** (`handlerJsonSchema`, `argsJsonSchema`), as the spec has it: closed objects that require what isn't optional, nullable as `anyOf` with an outer description winning, 32-bit integers, `date-time` timestamps, `t.json()` as `{}`, string enums, and `t.row(table)` as the full stored row described "A row of <table>: <table description>". `agentTools.test.ts` › "maps every value kind to JSON Schema 2020-12" checks every kind. One call the spec didn't spell out: a row value with its own `.describe()` keeps that description, the outer-wins rule nullable already has (the prototype did the same); `docs/product.md` now says so. **2. One check, three callers** (`checkAgentArea`). It refuses a tool with no description, `t.upload()`/`t.fileHandle()` anywhere in its arguments or result, a row naming an undefined table, and tools whose `open_patch` rendering, rows expanded, passes 60 KiB of UTF-8. It walks tools in name order, so CLI and instance report the same first problem however jsonb stored the keys. - `patchy publish` and watched dev builds run it after the description check, naming the file; a failed dev build keeps the last good binding. From `devServerWatch.test.ts`: `agent/intake.ts: count needs a description: it is all an agent knows about the tool. Say what it does, what it changes and when it refuses. The last successful binding stays served.` - The instance runs it in `Content.publish` on the inspected descriptors, naming the tool (`InvalidAgentArea` → `invalid_manifest`). `PatchesApi.test.ts` › "refuses an agent area that fails the shared check" hand-rolls each case, including 40 tools of 2,000 characters: `An agent reads all of this patch's tools in one answer of at most 64 KiB, and the tools get 60 KiB of it; yours come to 85 KiB. Shorten descriptions or drop tools.` - A row naming an unknown table is refused earlier, by the manifest's own check. That check now names the handler (an agent tool by its tool name) and the fix, and the instance passes a manifest-wide check's words through instead of "Invalid manifest." (field-level problems stay generic). **2b. `server/agent.ts` on the instance** (`c6020af`). Only `server/agent.ts` builds an `agent.*` handler without the agent tool mark. The CLI already refused it before building (#840), and now the shared check refuses one first on the instance too, so a hand-rolled publish can't skip it: `agent.listDeals comes from server/agent.ts. Agent tools live in agent/; move these exports there.` Reading an older version is unchanged: its unmarked `agent.*` handlers stay page handlers. `PatchesApi.test.ts` › "refuses an unmarked agent.* handler, as server/agent.ts builds". **3. What publish says.** The CLI builds the agent tools line from the manifest the attempt sent (`cliRepoRecovery.test.ts` recovers an attempt with a broken config and still lists its tools). The instance adds the argument warnings and, through `Companies.agentAccess`, the access-off warning; JSON gains no field. `PatchesApi.test.ts` › "warns about undescribed arguments, and that no agent can use the tools while access is off" publishes with access off, turns it on and publishes again. **4. Answers and refusals** for the door and `patchy dev agent`: `toolAnswer` (compact JSON text plus `structuredContent`), `CallSuccess` `{ result, version, replayed? }`, `ToolRefusal` and `patchRefusal`, which reads "New Business refused addLead (missing_fields): give every field." from a handler's `details.message` and keeps code and details unchanged. ## How it was verified - `vitest` on `packages/api`, `packages/sdk`, `packages/patches` `PatchesApi`/`Content`, and `packages/patchy` `devServerWatch`, `serverModules`, `server`, `cliRepoRecovery`: 199 tests on `5a00179`, all passing (one SDK repack test timed out under machine load and passed alone); the round 1 fixes add tests to the api, patches and patchy suites, all passing. - `pnpm typecheck` and `eslint` on the changed files. - `pnpm dev transcript` on throwaway `team` instances, base `c00413f` against `5a00179`: a fresh tier 2 repo with two agent tools publishes with the line and both warnings, and dropping one description is refused locally, naming `agent/notes.ts`, where the base published. The transcript is below. - GPT-6.1-Sol (xhigh) reviewed in two rounds: round 1's blocking size-check crash and three smaller findings are fixed in `f69e936`, and round 2 found nothing. The rounds are in [the review comment](#872 (comment)). - `pnpm test:rollback-rehearsal --live dd3f41f`, a `main` commit with #837 and #838: dd3f41f → f69e936 → dd3f41f passed in 290 s. On `f69e936`, CI's `rollback-rehearsal` failed against production's then-commit d77baaf, which couldn't read the stack's agent tools (#833). - `pnpm verify` on `f69e936`: format, lint, typecheck, synth, postgres-concurrency, cli-smoke and browser passed. `test` and `tier2-smoke` failed only on timeouts while the shared machine was at load 40; `tier2-smoke` then passed alone, and the 12 test files that timed out in either run passed alone (115 tests). CI passed both on this head. - Sol's round 3 on `c6020af`'s delta found nothing ([comment](#872 (comment))). Every CI check passes on `c6020af`, `rollback-rehearsal` included: production's commit has since moved to e4243ff, and the rehearsal ran e4243ff → c6020af → e4243ff. - Acceptance on `c6020af` by GPT-6.1-Sol (xhigh): [**PASS with notes**](#872 (comment)). It upgraded a version with an unmarked `agent.legacy` from `f69e936`: its page call kept working, a new publish of it was refused, and rollback to it still served it. It also ran the rehearsal against dd3f41f. Its note: merge with the stack, not alone. - Earlier, acceptance on `f69e936` by GPT-6.1-Sol (xhigh): [**PASS with notes**](#872 (comment)). It checked the publish line and warnings, seven CLI and eight hand-rolled refusals, byte counts against `JSON.stringify` up to exactly 61,440 bytes, watched dev keeping the last good binding, the publish and lifecycle journeys, and its own rehearsal against dd3f41f. Its note is the documented `rollback-rehearsal` gate above. <!-- patchy-dev:transcript:agent-tools --> #### Transcript `agent-tools` Before is `5f474a6` (where this branch left main) and after is `5a00179` (mcp/842-schemas-publish), both on the `team` scenario, from `pnpm dev transcript`. Each line ran in its own `bash -c` from the side's agent workspace, as the scenario's signed-in CLI, with stdin closed. Each side's origin reads `<origin>`, its environment folder `<env>`, its checkout `<checkout>` and the home folder `~`; nothing else is normalized. Nothing in it matched a collected secret (each side's CLI state, machine-token and login-code shapes, email addresses outside the scenarios' example domains, secret-named variables, and any accounts the run acts as). 2 of 4 lines changed. ##### A tier 2 patch whose agent/ folder holds two tools <details><summary><code>$ patchy init notes --purpose "Notes for the team" --tier 2 --json > /dev/null && echo "initialized no…</code>: no change, exit 0 in 4.6 s</summary> ```console $ patchy init notes --purpose "Notes for the team" --tier 2 --json > /dev/null && echo "initialized notes at tier 2" initialized notes at tier 2 ``` </details> <details><summary><code>$ mkdir -p notes/agent && printf '%s\n' 'import { query, mutation, t } from "../patchy/_generated/serv…</code>: no change, exit 0 in 0.0 s</summary> ```console $ mkdir -p notes/agent && printf '%s\n' 'import { query, mutation, t } from "../patchy/_generated/server.js";' 'export const listNotes = query({ description: "Lists the newest 100 notes.", args: {}, result: t.array(t.row("notes")), handler: async (ctx) => (await ctx.tables.notes.list({ limit: 100 })).rows });' 'export const addNote = mutation({ description: "Adds a note with the given title.", arg… import { query, mutation, t } from "../patchy/_generated/server.js"; export const listNotes = query({ description: "Lists the newest 100 notes.", args: {}, result: t.array(t.row("notes")), handler: async (ctx) => (await ctx.tables.notes.list({ limit: 100 })).rows }); export const addNote = mutation({ description: "Adds a note with the given title.", args: { title: t.text() }, result: t.row("notes"), handler: async (ctx, args) => ctx.tables.notes.insert({ title: args.title }) }); ``` _Lines are cut at 400 characters. `--json` has it all._ </details> ##### Publishing names the tools, warns about the undescribed argument and that agent access is off **Changed.** Before, exit 0 in 4.1 s; after, exit 0 in 4.7 s. ```console $ cd notes && pnpm --silent patchy publish Publishing to <origin> (target came from patchy.json). Published patch URL: <origin>/acme/notes Scope: company (signed-in colleagues in your company) Patch ID: xuxps3o2scg0 Tier: 2 Version: 1 Provisioned tables: notes. Provisioned columns: notes.title. Provisioned indexes: none. Provisioned stores: none. Unused tables: none. Unused columns: none. Unused indexes: none. Unused stores: none. Agent tools: addNote (change), listNotes (read). People's agents use these through Patchy's MCP at <origin>/mcp. [stderr] Warning: Agent access is off at Acme Co, so no agent can use these agent tools yet. An admin turns it on at <origin>/company. Warning: addNote's argument title has no description, so an agent knows only the name and type. Add .describe() where the name doesn't say enough. ``` ```diff @@ 2 unchanged lines @@ URL: <origin>/acme/notes Scope: company (signed-in colleagues in your company) -Patch ID: u3hupcnf5x84 +Patch ID: xuxps3o2scg0 Tier: 2 Version: 1 @@ 6 unchanged lines @@ Unused indexes: none. Unused stores: none. +Agent tools: addNote (change), listNotes (read). People's agents use these through Patchy's MCP at <origin>/mcp. +[stderr] +Warning: Agent access is off at Acme Co, so no agent can use these agent tools yet. An admin turns it on at <origin>/company. +Warning: addNote's argument title has no description, so an agent knows only the name and type. Add .describe() where the name doesn't say enough. ``` ##### A tool with no description is refused before anything is sent, naming its file **Changed.** Before, exit 0 in 4.3 s; after, exit 1 in 4.1 s. ```console $ cd notes && sed -i 's/description: "Lists the newest 100 notes.", //' agent/notes.ts && pnpm --silent patchy publish Publishing to <origin> (target came from patchy.json). [stderr] agent/notes.ts: listNotes needs a description: it is all an agent knows about the tool. Say what it does, what it changes and when it refuses. ``` ```diff Publishing to <origin> (target came from patchy.json). -Updated patch -URL: <origin>/acme/notes -Scope: company (signed-in colleagues in your company) -Patch ID: u3hupcnf5x84 -Tier: 2 -Version: 2 -Provisioned tables: none. -Provisioned columns: none. -Provisioned indexes: none. -Provisioned stores: none. -Unused tables: none. -Unused columns: none. -Unused indexes: none. -Unused stores: none. +[stderr] +agent/notes.ts: listNotes needs a description: it is all an agent knows about the tool. Say what it does, what it changes and when it refuses. ``` <!-- /patchy-dev:transcript:agent-tools --> ## Release impact - [ ] **Breaking** — requires action from anyone already running this - [x] **Not breaking** — no action required New refusals apply only to agent tools, which nothing released has yet, plus clearer wording for refusals the instance already made. No schema, no stored shape. - **What does a revert leave behind?** Versions published while it was live, whose manifests are the shape #837 already reads, and publish warnings stored in replayable responses as plain strings. - **Does the release before it still work with that?** Yes. It reads the same manifests and simply stops checking new agent areas. 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]>
## What changed Patchy MCP has been live in production since release 17, but the product doc, the glossary map and the MCP glossary still called it specified or being built. They now describe what runs, and where the build settled a detail differently from the spec, the spec now says what the code does. Production acceptance (#861) hasn't run: the section says so, and claims about particular clients are framed as what the build was designed for. Part of #862. This is everything in #862's "What to do" except "What remains takes acceptance's findings", which waits for #861. ## Look at **Status and pointers.** Each of these now reads as built: - `docs/product.md`: the "Built and live" intro line names Patchy MCP; the Patchy MCP section opens "Built, and live since release 17", links #833 and says #861 hasn't run. - The same file's tier 2 sentence, `agent/` pointer, Companies (admins, deactivation), Who's who and Bounds' admission rule. - `GLOSSARY-MAP.md`: Auth and Patchy MCP. - `packages/mcp/GLOSSARY.md`. - `README.md`: the layout, plus one sentence on tier 2. - `AGENTS.md`'s tier 2 line. - `docs/OPERATIONS.md`: request events. **Spec details the build settled differently.** Each claim was checked against main: | Claim in the doc | What main does | Where | | --- | --- | --- | | A forwarded host is trusted from Patchy's proxy | The door never believes a forwarded host and refuses two `Host` fields | `packages/mcp/src/RequestTrust.ts:7-10` | | `Host` gates the OAuth endpoints too | Only `/mcp` is Host-gated; a dev instance serves every route on `127.0.0.1` | `packages/mcp/src/Door.ts:372`, `packages/auth/src/OAuthEndpoints.ts:19-20` | | An unknown method is `404` | `404` on 2026-07-28, `200` on legacy, where 404 means session ended | `packages/mcp/src/Door.ts:356-363` | | An `unknown_outcome` always resolves on retry | Only until a few minutes before 24 h; then `key_expired` | `packages/mcp/src/ChangeKeys.ts:116-123`, `Calls.ts:339-347` | | An action's key never runs again | Unless Runtime refused the first try before it started | `packages/mcp/src/ChangeKeys.ts:60-64`, `Calls.ts:409-419` | | `resource` is bound through exchange and refresh | Optional; must name the door wherever sent | `packages/auth/src/Consents.ts:203-205, 345-348` | | Consent re-asks after an account switch | Also re-asks an Allow after the client's name changes | `packages/auth/src/OAuthEndpoints.ts:423-436` | | With agent access off, consent names the admins | To members; an admin is told to turn it on | `packages/auth/src/OAuthEndpoints.ts:182-185` | | "logged as Jordan via Claude" | The person's full name: "Jordan Lee via Claude" | `packages/auth/src/OAuthEndpoints.ts:151-162` | | The docs say how to reconnect by hand | Not written; Connect an app gives first-time steps only | no such doc in `docs/`, `skills/`, `packages/sdk/skills` | | Publish's warning points at `<instance>/company` | `<instance>/company/agent-access` | `packages/patches/src/PatchesApi.ts:454` | | The instance names a duplicated tool | It can't: inspection drops the bundle's message; only the CLI names it | `packages/execution/src/inspection.ts:12-16` | | A read-only action's writes are type errors | Table and file writes are; Pidgeon writes typecheck and the callback gate refuses them | `packages/patchy/src/server.ts:247-262`, `packages/runtime/src/CallbackGateway.ts:107-111` | | `dev.log` names the person | It writes their id: `usr_dev via patchy dev …` | `packages/patchy/src/devLog.ts:23-27` | | New repos include `agent` | Tier 1 and 2 repos do | `packages/patchy/src/initProject.ts:207` | | The MCP request event says whether its binding is agent-only | Only the binding event carries `agentOnly` | `packages/analytics/src/WideEvents.ts:228` | | An in-flight slot is held after the client disconnects | A client gone before dispatch gives it back | `packages/mcp/src/Admission.ts:13-17` | | The week-unused note opens "Not used since 2 Oct." | It opens "If you reconnected …" | `packages/auth/src/MachinesPage.ts:178` | | "today a person types everything into them" | Agents now find, read and change patches too | the section itself | | Pages "get phone checks when built" | They were checked at 390 px in their PRs' screenshots (#871 #876 #882 #885 #931 #932) | — | ## How it was verified - Four read-only passes went claim by claim through the Patchy MCP section against main at 2f9f7c1. I re-read the code for every finding before changing a line. The table lists each change. - **Findings left as they are:** - "the one secret Patchy keeps recoverable": the context is the connection's tokens. - "each change gets a fresh change key" in `patchy dev agent`: the code's own comment says the same. - The lists of which outside clients can connect: these are facts about those clients, and the code offers no dynamic registration. - `pnpm check`: format, lint, typecheck and synth passed. Two test files failed under load average 19, a 5 s timeout in `PgliteCompanyDatabases.test.ts` and a worker SIGKILL in `devExecution.test.ts`. Both passed when rerun alone. Neither touches docs. - **Not done here:** `packages/sdk/skills/patchy-server/SKILL.md:415` and `packages/sdk/src/sdkCapabilities.ts:107` say a patch's tools fit in 64 KiB, but the check allows 60 KiB of that answer. Those files belong to another lane, so they're left for a follow-up. ## Release impact - [ ] **Breaking** — requires action from anyone already running this - [x] **Not breaking** — no action required Docs only. - **What does a revert leave behind?** Nothing; the docs go back to calling Patchy MCP specified. - **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). --------- Co-authored-by: Claude Opus 5.5 <[email protected]>



Stacked on #870 (ticket #840); merges with the rest of #833's stack, not alone.
What changed
Every Patchy MCP call will need the company's agent access on, and until now there was no switch. Company now ends with an Agent access section: an On or Off tag, who made the latest change and when ("Turned off by Priya Shah on 12 Oct 2026"), a paragraph, and for admins one button, Turn on or Turn off, with no confirmation. Members see the same state and stamp without a button: "Connect yours on Your machines" when it's on, the admins' names when it's off. It starts off for every company, new or existing.
Closes #841
Look at
1. The switch lives on the company row (
0020_agent_access):agent_access_ondefaults to false, andagent_access_changed_by/_athold the latest change, null together for the starting Off.CompaniesgainsagentAccess,setAgentAccessandholdAgentAccess. A change is oneUPDATE … WHERE agent_access_on <> $on, so asking for the state it already has changes nothing and reports nothing. Each real change reportsagent_access.changedwithon, after it commits.2. The lock #849 shares.
holdAgentAccessreads whether the switch is on,FOR SHAREof the company row. Inside a transaction, a change waits for the holder, and the holder waits for a change in flight and then reads what it committed. It returns the switch alone: a read that waited re-reads only the locked row, so a joined stamp could come back stale (Sol's round 1). Code issuance and the code exchange call it, so an exchange never acts on an "on" an "off" already replaced. The same row lock serializes it with deactivation, which locks the company rowFOR UPDATE.Companies.test.ts› "makes a change wait for a holder of agent access, and a holder wait for a change" shows both directions on Postgres, waiting for a session the holder blocks; without theFOR SHAREit times out.3. The page and route.
POST /company/agent-accesswithstate=on|off, same-origin, admins only. A member's POST is the page's existing 403, and a malformed state is a 422 alert. It redirects to/company#agent-access, so the admin lands back on the section at the foot of the page. Screenshots and a short film:The admin's Company page, before and after (Ada,
team):Before and after, as Ada Park (admin)
Before is
f76fecf(where this branch left mcp/840-agent-folder) and after is7eeba59(mcp/841-agent-access-switch), both on theteamscenario, frompnpm dev compare.Every page answered 200 with no browser errors.
/company1280px, after
1280px, before
A member's (Ben):
Before and after, as Ben Ortiz (member)
Before is
f76fecf(where this branch left mcp/840-agent-folder) and after is7eeba59(mcp/841-agent-access-switch), both on theteamscenario, frompnpm dev compare.Every page answered 200 with no browser errors.
/company1280px, after
1280px, before
Turning it on and off as the admin, head only:
Flow
agent-access, as Ada Park (admin)After is
7eeba59(mcp/841-agent-access-switch), on theteamscenario, frompnpm dev film.after.mp4
How it was verified
vitest:Companies.test.tscovers a new company starting Off with no stamp, on and off stamped with who and when (underTestClock), a repeated state leaving the stamp alone, unknown companies, and the hold in both directions.CompanyPage.test.tscovers the four page states, the redirect, the events, a stale Turn on from a second admin, the 422, and/company/agent-accessin the member-refusal and Origin cases. Alsoapps/server/src/migrations.test.ts, the companies suite,AuthPages,DevicePagesand serving'sPages.tsconfig.test.json) and lint.pnpm verifyon e3ecce3: 8 of 9 steps passed. Theteststep had 14 timeouts in 9 files this PR doesn't touch (CLI repo builds, SDK, fleet, PGlite) while the machine's load was above 30. Rerun alone, all 9 passed (137 tests), and CI's threetestjobs passed.maindd3f41f, 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 dd3f41fgivesExercised rollback paths passed: dd3f41f → e3ecce3 → dd3f41f, in 470s.CI's run against production's d77baaf fails only in step 3, on the agent-area patch production can't serve, the gate Build Patchy MCP #833 documents. Its upgrade step, which applies0020_agent_access, passes.Release impact
An additive migration: three columns on
companies, defaulted or null. Nothing reads the switch yet; the door and consent (#849 onward) will.Built by Claude Opus 5.5 (xhigh) in Claude Code on T3 Code; reviewed and accepted by GPT-6.1-Sol (xhigh).