Skip to content

fix(dev): an environment's agent makes new patches in its workspace - #864

Merged
allisonmahmood merged 2 commits into
mainfrom
fix/829-dev-workspace-isolation
Oct 22, 2026
Merged

allisonmahmood merged 2 commits into
mainfrom
fix/829-dev-workspace-isolation

Conversation

@allisonmahmood

@allisonmahmood allisonmahmood commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

What changed

An agent started from a dev environment's agent launcher, or by pnpm dev trial, saved new patches in the developer's real ~/Patchy, outside the environment, so pnpm dev down missed them. It also cleared PATCHY_API_URL, so in a repo bound to production that repo's own address won, and launcher sessions shared auto memory and /tmp.

Now, as decided on #738:

  • The workspace gets a CLAUDE.md: "Make each new patch or page directly in this folder." up writes it every time, for a finished environment too, and never over one that exists.
  • The launcher sets PATCHY_API_URL to the environment's instance, so a command in a repo bound to another one is refused before anything is sent. An explicit --api-url still wins, and so does another checkout's .local/dev/env, which only ever names a local instance (see the review comment).
  • Each launcher session has auto memory off and a temp folder of its own, ${TMPDIR:-/tmp}/patchy-agent-<pid>.*. The launcher still execs Claude Code, and each launch deletes the folders of sessions whose process is gone.
  • A trial writes this checkout's agent into both sides, so both get the same folder and guard whatever commit built them. That retires the adapters for older launchers (confineTemp, OldLauncher).

docs/DEVELOPMENT.md, the patchy-dev-loop and pr-evidence skills and scenarios/README.md say where agent-made work goes, and that one builder agent per patch is the norm and nothing enforces it.

Closes #829

Look at

Where the agent puts new work. On pnpm dev up (team), …/agent -p on Sonnet:

Task Where it went The agent said
"Make a simple page listing our office hours (Monday to Friday, 9 to 5) and publish it." <env>/workspace/office-hours.html "the source is office-hours.html in the workspace folder, per CLAUDE.md."
"Start a new tier 1 tool for tracking office snacks. Only set the project up; don't build features or publish yet." <env>/workspace/office-snacks "directly in the workspace folder as your CLAUDE.md asks, rather than the default ~/Patchy."

~/Patchy gained nothing, and pnpm dev down removed both.

The guard. A copy of office-snacks with patchy.json bound to https://other-instance.invalid, with commands run in the launcher's environment and the shell exporting a different PATCHY_API_URL and PATCHY_API_TOKEN:

# before: main's launcher clears PATCHY_API_URL, so patchy.json's address wins and only the missing key stops it
$ patchy publish --json
{"ok":false,"error":"No publishing key is stored for https://other-instance.invalid.\nRun: patchy login","kind":"local"}

# after
$ patchy publish --json
{"ok":false,"error":"patchy.json is bound to https://other-instance.invalid, but this command targets http://<env-host>. Use the same instance; publishing does not change the repo's instance.","kind":"local","code":"instance_mismatch"}
$ patchy refresh --json
{"ok":false,"error":"patchy.json is bound to https://other-instance.invalid, but this command targets http://<env-host>. …","kind":"local","code":"instance_mismatch"}

# an explicit --api-url still wins
$ patchy publish --json --api-url https://other-instance.invalid
{"ok":false,"error":"No publishing key is stored for https://other-instance.invalid.\nRun: patchy login","kind":"local"}

Clean sessions. With a canary memory planted in the workspace's Claude project folder ("the office secret word is PINEAPPLE"), the launcher's session answered UNKNOWN. The same launcher without its auto-memory line answered PINEAPPLE. The two real sessions above wrote no memory folder.

How it was verified

  • vitest run scripts/dev/src/environment.test.ts scripts/dev/src/trial.test.ts: 15 pass. The launcher tests cover:
    • PATCHY_API_URL set to the instance, the shell's token dropped, auto memory off;
    • a temp folder per session in $TMPDIR (or /tmp), named for the launcher's pid (so exec kept it) and with Claude Code's exit code; a later launch deletes it, and keeps a folder whose process is alive;
    • the workspace CLAUDE.md written, and an existing one kept.
  • The CLI side of the guard was already covered: Instance.test.ts (an env target that disagrees with patchy.json) and cliRepoPublish.test.ts (refused with no request to either instance).
  • By hand on this worktree's environment: the two agent tasks, the guard and the memory canary above. A second up on the finished environment restored a deleted CLAUDE.md and kept an edited one. pnpm dev down removed the agent-made patches.
  • pnpm dev trial (below), on caed395: both sides, the before side built by main, put the page in their own workspace, and ~/Patchy gained nothing.
  • Typecheck of @patchy/dev through turbo, and eslint and prettier on the changed files.

Release impact

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

Dev tooling and docs only (scripts/dev, the dev-loop docs and skills). Nothing that ships in the server, CLI, API or schema changes.

  • What does a revert leave behind? Environments already up keep the new launcher until their next up rewrites it, and keep the workspace CLAUDE.md, which is harmless.
  • Does the release before it still work with that? Yes. Nothing deployed changes.

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

Trial office-hours-page

Make a simple page listing our office hours (Monday to Friday, 9 to 5) and publish it.

Before is e838227 (where this branch left main) and after is caed395 (fix/829-dev-workspace-isolation), both on the team scenario, from pnpm dev trial.

Each side gave the task to a fresh agent: after's agent launcher in the side's environment, Claude Code on claude-sonnet-5-5 as the scenario's publisher, with the side's release of the Patchy skill and no personal instructions or settings, run without a person within 30 turns and 10 minutes. The log keeps each tool call, commands with their exit codes, and one line per failure; not the agent's reasoning or what its commands printed. Redacted before writing: email addresses outside the scenarios' example domains; the accounts the run acts as.

One run is a smell test, not a measurement.

Before After
Finished Yes Yes
Commands 11 11
Failures 4 5
Help lookups 0 0
Minutes 0.7 1.0

Before answered: “The office hours page is published. Anyone signed in to the Acme Co account can open it: <origin>/acme/office-hours It's a table of Monday to Friday, 9:00 am – 5:00 pm.”

After answered: “The office hours page is published: <origin>/acme/office-hours Anyone signed in to your company (Acme Co) can open it. It isn't public.”

Before's log: 11 commands, 4 failures
skill   patchy
denied  $ patchy status --json; patchy whoami --json; patchy look --json > /tmp/look.json; echo look:$?; head -c 600 /tmp/look.json
        A variable in this command can't be checked before it runs
exit 0  $ patchy status --json
exit 0  $ patchy whoami --json
denied  $ patchy look --json > /tmp/look.json; echo $?; wc -c /tmp/look.json; head -c 1500 /tmp/look.json
        A variable in this command can't be checked before it runs
denied  $ patchy look --json > /tmp/look.json && wc -c /tmp/look.json && head -c 1500 /tmp/look.json
        This Bash command contains multiple operations. The following parts require approval: patchy look --json, wc -c /tmp/look.json, head -c 1500 /tmp/look.json
exit 0  $ patchy look --json
denied  $ patchy look --json > /tmp/patchy-look.json
        Output redirection to '/tmp/patchy-look.json' needs approval. The path is outside the working directories for this session ('<env>/workspace', '/tmp/patchy-agent-1726098.zZfBnf'). Allowing runs the co…
exit 0  $ patchy look --json > /tmp/patchy-agent-1726098.zZfBnf/look.json
write   /tmp/patchy-agent-1726098.zZfBnf/build.mjs
exit 0  $ node /tmp/patchy-agent-1726098.zZfBnf/build.mjs /tmp/patchy-agent-1726098.zZfBnf/look.json <env>/workspace/office-hours.html
exit 0  $ patchy validate <env>/workspace/office-hours.html
exit 0  $ patchy publish <env>/workspace/office-hours.html --new --description "Office hours: Monday to Friday, 9 am to 5 pm." --json
After's log: 11 commands, 5 failures
skill   patchy
denied  $ patchy status --json; patchy whoami --json; cd <env>/workspace && patchy look --json > /tmp/look.json 2>/tmp/look.err; echo $?; head -c 300 /tmp/look.err; ls
        A variable in this command can't be checked before it runs
exit 0  $ patchy status --json
exit 0  $ patchy whoami --json
denied  $ cd /tmp && patchy look --json > /tmp/look.json; echo $?; python3 -I -c " …
        A variable in this command can't be checked before it runs
denied  $ patchy look --json > /tmp/look.json; echo done $?
        A variable in this command can't be checked before it runs
denied  $ patchy look --json > /tmp/look.json
        Output redirection to '/tmp/look.json' needs approval. The path is outside the working directories for this session ('<env>/workspace', '/tmp/patchy-agent-1726099.BOjOny'). Allowing runs the command a…
exit 0  $ patchy look --json > /tmp/patchy-agent-1726099.BOjOny/look.json
denied  $ python3 -I -c " …
        This command requires approval
exit 0  $ head -c 1500 /tmp/patchy-agent-1726099.BOjOny/look.json; wc -c /tmp/patchy-agent-1726099.BOjOny/look.json
write   /tmp/patchy-agent-1726099.BOjOny/build.mjs
exit 0  $ node /tmp/patchy-agent-1726099.BOjOny/build.mjs /tmp/patchy-agent-1726099.BOjOny/look.json <env>/workspace/office-hours.html && patchy validate <env>/workspace/office-hours.html
exit 0  $ patchy publish <env>/workspace/office-hours.html --new --description "Office hours: open Monday to Friday, 9 to 5." --json

@github-actions github-actions Bot added area:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area size:m 100-500 changed lines labels Oct 22, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Review: GPT-6.1-Sol (xhigh), two rounds

Round 1, at 4f3c599

  1. Blocking, scripts/dev/src/environment.ts: the guard can be bypassed. The CLI ranks a checkout's .local/dev/env above PATCHY_API_URL (packages/patchy/src/Instance.ts). A repo inside another checkout that is running pnpm dev therefore resolves to that checkout's instance without --api-url.
    Dismissed, and documented. The builder pipeline for agent areas: declaring, describing, testing and what the skills say #738 decided the guard is PATCHY_API_URL, "a default, not a sandbox". .local/dev/env outranks PATCHY_API_URL on purpose, so that a stray exported URL can't steer a worktree that is running pnpm dev. Reordering it would change the CLI for every user, not dev tooling. The gap needs the agent to go into another Patchy checkout that is running pnpm dev, and that file only ever names a local instance, so production stays unreachable this way. docs/DEVELOPMENT.md now names the exception. It's flagged to the chief of staff for whether it deserves its own ticket.
  2. Should-fix, scripts/dev/src/environment.ts: signals sent to the launcher's pid alone no longer reached Claude Code. That pid was now bash, which deleted the temp folder and left Claude Code running.
    Fixed in caed395. The launcher execs Claude Code again. Each session's temp folder is ${TMPDIR:-/tmp}/patchy-agent-<pid>.XXXXXX, and each launch deletes this user's folders whose pid is gone. The test checks that the name carries the spawned pid, that the folder outlives its session, that the next launch removes it, and that a folder named for a live pid survives.

Round 2, at caed395: nothing blocking, no new findings. Sol checked the sweep's quoting, unmatched globs, odd names, ownership, pid reuse (it only ever keeps a stale folder), eight launches at once and direct SIGTERM delivery. It accepted the round 1 dismissal.

allisonmahmood and others added 2 commits October 22, 2026 09:56
The agent launcher left new patches in the developer's real ~/Patchy,
where `down` never looks, and a repo bound to production kept its own
address because the launcher cleared PATCHY_API_URL.

- The workspace gets a CLAUDE.md, "Make each new patch or page directly
  in this folder", written on every `up` and never over one that exists.
- The launcher sets PATCHY_API_URL to the environment's instance, so a
  repo bound to another one refuses before anything is sent.
- Each session has auto memory off and a temp folder of its own,
  deleted when Claude Code exits.
- A trial writes this checkout's agent into both sides, so both get the
  same folder and guard; the adapters for older launchers go.

Closes #829

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Signalling the launcher's pid alone left Claude Code running once bash
had deleted its temp folder. The launcher execs Claude Code again, names
each session's temp folder for that pid, and a later launch deletes the
folders whose process is gone. The trial section names after's launcher,
and DEVELOPMENT says another checkout's .local/dev/env outranks the guard.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@allisonmahmood
allisonmahmood force-pushed the fix/829-dev-workspace-isolation branch from caed395 to e6723b4 Compare October 22, 2026 07:56
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Acceptance: PASS with notes

Checked e6723b4f540bd62161a5ed8a15041928ab236ee6 (base b78094419477e4df5769208c4f023b90051b57bd) on fresh team instances in this acceptance checkout, by GPT-6.1-Sol (xhigh) in Codex through T3 Code.

Done means

  • New work stays in the workspace and down removes it: passed. A real launcher session saved <env>/workspace/office-hours.html. Two separate pnpm dev trial runs exercised page creation and tier 1 setup on both pinned commits. All four agents finished in their respective workspaces. The tier 1 agents invoked the Patchy skill and initialized <env>/workspace/office-snacks; the head agent answered: “I put it directly in the workspace folder, as your CLAUDE.md says, instead of the skill's default ~/Patchy.” The trials took both environments down. A separate installed-CLI initialization also succeeded; direct pnpm dev down removed that repo and the agent-made page. Final recursive comparison of ~/Patchy: zero additions.
  • Foreign-instance guard: passed within the documented default's scope. Running the actual launcher with conflicting parent URL/token values captured its own local URL, its own CLI state, and no inherited token. The installed CLI's publish and refresh both returned exit 1 / instance_mismatch for a foreign-bound repo when given that captured target explicitly, preserving the required sanitized CLI invocation. A loopback foreign-instance listener received zero requests. Explicitly selecting the foreign URL cleared the mismatch and stopped at “No publishing key is stored,” as expected. The passing Instance.test.ts covers the environment-variable mismatch itself; cliRepoPublish.test.ts also verifies refusal without requests to either instance.
  • Fresh sessions have no earlier auto memory: passed. A canary in this throwaway workspace's Claude project memory was invisible to two real launcher sessions (UNKNOWN). An otherwise identical control launcher with the memory-disable line removed answered the canary (LANTERN). The canary was removed afterward. Launcher checks also passed for unique per-session temp folders, dead-session cleanup, preserving a live session's folder, retained PID through exec, exit-code propagation, and direct SIGTERM delivery.

Golden journeys

  • Publish a page: passed. The environment CLI identified Ada in Acme Co and published Office Hours. Ben received 200 with the actual office-hours content and found its address on Home. A signed-out reader received 401. Retirement hid the page; restoration returned 200 with its original content at the same address.
  • Other golden journeys have no changed implementation path here. The head's browser, packed CLI, tier 2 and live Clerk CI jobs passed.

Additional evidence

pnpm exec vitest run scripts/dev packages/patchy/src/Instance.test.ts packages/patchy/src/cliRepoPublish.test.ts
Test Files  15 passed (15)
Tests       91 passed (91)

Repeated up on the completed environment restored a deleted workspace CLAUDE.md and preserved an edited one. All 14 head CI checks were green, including rollback-rehearsal: CI run.

All direct installed-CLI calls used env -u PATCHY_API_URL -u PATCHY_API_TOKEN PATCHY_STATE_DIR=<env>/cli-state <env>/bin/patchy …. The tier 1 trial agents used that same argument list through Node after Bash declined its dynamic variables. No production endpoint was used. Final pnpm dev down completed; the direct instance, both trial environments, evidence clones and test temp folders were removed. The tracked checkout remains clean.

Rollback answers: they match the diff. A revert can leave the workspace instruction file and the newer launcher until another up, but the previous code works with them. No deployed code, schema, stored production data or public CLI contract changes; no one-way label is needed.

Not run

  • A complete local pnpm verify rerun; the focused suites above passed locally and all head CI suites passed.

Notes

  • As the PR and its review explain, another local Patchy checkout's .local/dev/env still outranks PATCHY_API_URL. Acceptance retains that documented scope: this is a default guard, and explicitly selecting another API URL also remains possible.
  • The initial cold up timed out while building the release artifact. Its supervisor finished starting, both local health probes returned 200, and an idempotent up completed. Subsequent direct checks and both trial runs passed; this was not counted as a passing first startup attempt.

@allisonmahmood
allisonmahmood merged commit 26920f9 into main Oct 22, 2026
14 checks passed
@allisonmahmood
allisonmahmood deleted the fix/829-dev-workspace-isolation branch October 22, 2026 08:16
allisonmahmood added a commit that referenced this pull request Oct 22, 2026
…874)

## What changed

Release 16's What's new entry, written from `dd3f41f`. It covers
everything merged since release 15's `through` (`9e4b0df`), and sets the
`patchy` release to `0.16.0` (`packages/patchy/package.json` and
`CURRENT_RELEASE`).

| Change | PRs |
| --- | --- |
| Fixed: Revoke all machines stops logins still on their way | #867 |
| Behind the scenes: `mcp` and `oauth` kept off company addresses | #863
|
| Behind the scenes: read-only actions and agent tools understood and
enforced before anything writes them | #868 |
| Behind the scenes: logs record how long a tool's server takes to start
| #865 |

#814 is release 15's own entry, so it's left out. #818 and #831 are docs
(Patchy is live; the Patchy MCP spec) and #864 is dev tooling, so none
of them gets a line.

## Look at

- **The entry**, at the top of `releases` in
`packages/core/src/whatsNew.ts`. #867 is the only change a person could
notice. The page's button is still labelled "Revoke all machines"
(Disconnect everything is the spec's future name), so the entry uses
that label.
- **Rollback safety, from the live commit `d77baaf` to `dd3f41f`.** No
PR in the range is labelled `one-way`, and every PR answers both Release
impact questions with "Yes".
- #867 is the only migration: `0019_credentials_ended` adds two nullable
columns, `users.credentials_ended_at` and `device_logins.confirmed_at`.
At `d77baaf`, every insert into `users` and `device_logins` lists its
columns, and nothing reads either table with `SELECT *`.
- `rollback-rehearsal` passed on #863, #865, #867 and #868. #868's run
covered #867's migration already on main: `Exercised rollback paths
passed: d77baaf → ffe9988 → d77baaf`.
- A rollback would reopen what #867 closes: an approved login that
hasn't finished could again get past Revoke all machines. It would also
let new companies take the `mcp` and `oauth` addresses (#863). No
release that writes read-only actions or agent tools has shipped, so
going back past #868 leaves nothing behind.

## How it was verified

- `vitest run packages/core/src/whatsNew.test.ts
packages/api/src/schemas.test.ts`: 14 passed.
- `pnpm typecheck`: 23 of 23 tasks pass. Prettier and eslint are clean
on the changed files.
- The live commit was pinned from `/healthz/deep` (`d77baaf`, release
15). The Deploy run updated last succeeded, and none is unfinished.

## Release impact

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

The changelog text plus the `patchy` version bump. A CLI installed
before this deploy is told to upgrade, as with every release.

- **What does a revert leave behind?** Nothing. People whose seen marker
reached 16 would just see no new release.
- **Does the release before it still work with that?** Yes.

If this release misbehaves, roll back to
`d77baafcf10c7cdf28c71bd65ea1a0009aa99ced` (release 15).

Built 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:ci CI, shared testing infrastructure, development scripts and tooling area:docs Touches the docs area size:m 100-500 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A dev environment's agent makes new patches in your real ~/Patchy

1 participant