Skip to content

fix(cli): publish refuses a repo with no recorded version instead of going over newer work - #1179

Merged
allisonmahmood merged 1 commit into
mainfrom
fix/publish-unknown-base-version
Nov 4, 2026
Merged

allisonmahmood merged 1 commit into
mainfrom
fix/publish-unknown-base-version

Conversation

@allisonmahmood

Copy link
Copy Markdown
Owner

What changed

A repo publish sends patchy.json's version so the instance can refuse it as behind when someone published since. A repo last published before the CLI recorded version has none, so publish left the check out and went over whatever was live, including a newer version that had been rolled back. Publish now refuses a bound repo with no recorded version locally, before building or sending anything, with unknown_base_version: pull a fresh copy, or publish with --allow-behind once the person agrees. That publish records a version, so a legacy repo needs the flag once.

Closes #1164

Look at

  • The refusal (packages/patchy/src/commands.ts): it applies only when patchy.json names a patch and has no version, and --allow-behind isn't passed. It runs before prepareRepoPublish, so a refused repo isn't built and its patchy.json (description sync included) is untouched. Recovering a pending publish still comes first. A repo's first publish (no patch yet) and file publishing don't reach it, and a repo with a version sends it as before, so a rollback still refuses it as behind.

On the base, the legacy repo silently publishes v3 over a rolled-back v2; on the head it is refused before anything is built or sent, and one --allow-behind publish records its version.

Transcript unknown-base-version

Before is 1f187a9 (where this branch left main) and after is 059055c (fix/publish-unknown-base-version), 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, login-code, API-key and access-token shapes, email addresses outside the scenarios' example domains, secret-named variables, and any accounts the run acts as).

4 of 4 lines changed.

A patch with two versions, rolled back to the first

Changed. Before, exit 0 in 4.2 s; after, exit 0 in 3.9 s.

$ patchy init notes --purpose "Team notes" > /dev/null && cd notes && patchy publish > /dev/null && patchy publish > /dev/null && patchy rollback 1
Rolled back patch
Patch ID: <after-patch-id>
Version: 1
URL: <origin>/acme/notes
Data and description are unchanged.
 Rolled back patch
-Patch ID: <before-patch-id>
+Patch ID: <after-patch-id>
 Version: 1
 URL: <origin>/acme/notes
@@ 1 unchanged line @@
Its repo, as a CLI from before patchy.json kept a version left it

Changed. Before, exit 0 in 0.0 s; after, exit 0 in 0.0 s.

$ cd notes && node -e 'const fs=require("fs");const j=JSON.parse(fs.readFileSync("patchy.json","utf8"));delete j.version;fs.writeFileSync("patchy.json",JSON.stringify(j,null,2)+"\n")' && cat patchy.json
{
  "instance": "<origin>",
  "patch": "<after-patch-id>",
  "description": "Team notes",
  "descriptionSyncedAt": "2026-11-01T16:17:29.773Z"
}
 {
   "instance": "<origin>",
-  "patch": "<before-patch-id>",
+  "patch": "<after-patch-id>",
   "description": "Team notes",
-  "descriptionSyncedAt": "2026-11-01T16:17:23.171Z"
+  "descriptionSyncedAt": "2026-11-01T16:17:29.773Z"
 }
Publishing it

Changed. Before, exit 0 in 1.3 s; after, exit 1 in 0.2 s.

$ cd notes && patchy publish
[stderr]
Unknown base version: patchy.json names patch <after-patch-id> but no version, so publish can't tell whether anyone published since this copy. Pull a fresh copy into a new folder with `patchy pull <after-patch-id>` and make the change there, or, once the person you are working for agrees to replace whatever is live, publish with --allow-behind; that publish records the version.
-Publishing to <origin> (target came from patchy.json).
-Updated patch
-URL: <origin>/acme/notes
-Scope: company (signed-in colleagues in your company)
-Patch ID: <before-patch-id>
-Tier: 1
-Version: 3
-Repo: 16 files, 38.3 KiB, kept with this version
-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]
+Unknown base version: patchy.json names patch <after-patch-id> but no version, so publish can't tell whether anyone published since this copy. Pull a fresh copy into a new folder with `patchy pull <after-patch-id>` and make the change there, or, once the person you are working for agrees to replace whatever is live, publish with --allow-behind; that publish records the version.
Publishing over what is live, once the person agrees

Changed. Before, exit 0 in 1.3 s; after, exit 0 in 1.1 s.

$ cd notes && patchy publish --allow-behind | grep Version && grep '"version"' patchy.json
Version: 3
  "version": 3
-Version: 4
-  "version": 4,
+Version: 3
+  "version": 3

How it was verified

  • New test in cliRepoPublish.test.ts: a bound legacy repo is refused with kind: "local", code: "unknown_base_version", naming patchy pull <id> and --allow-behind. Nothing is sent, patchy.json is unchanged and no attempt is saved. --allow-behind then publishes with no baseVersion and records version: 3.
  • Unchanged cases stay covered by existing tests: the starter's first publish and then baseVersion: 1 on the next one (cliRepoPublish), recovery of a pending attempt in a repo whose patchy.json has no version (cliRepoRecovery, cliLifecycle), and file publishing (cliPublish).
  • Four existing fixtures wrote a bound patchy.json with no version only as setup. They now carry version: 1.
  • Locally, with the machine heavily loaded by other worktrees: pnpm vitest run on cliRepoPublish, cliRepoDescriptions and cliRepoRecovery passed, 25 of 25. cliLifecycle and cliPublish fail a different handful of tests on each run, on a stray GET / from the local editor's port probe; this is a known local-only failure that CI doesn't see, and those tests don't reach the changed path. pnpm format:check, pnpm lint and pnpm typecheck (the workspace, tests included) pass. I didn't run a full pnpm verify or the whole offline suite locally; CI runs them on this PR.

Release impact

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

A compatibility change to the CLI: a repo bound to a patch with no version in patchy.json, last published by a CLI from before versions were recorded, is now refused at its next publish with unknown_base_version, exit 1. The upgrade path is in the message, the README, ADR-0004's local codes table and patchy-loop: pull a fresh copy with patchy pull <patch>, or publish once with --allow-behind after the person agrees to replace what's live. From then on the repo has a version and publishes as before. It reaches a repo only through a release and a refresh.

  • What does a revert leave behind? Nothing. No schema, rows or wire change; repos that published with --allow-behind keep the version that any publish records.
  • Does the release before it still work with that? Yes. The API already accepted publishes with and without baseVersion.

Built by Claude Opus 5.5 (claude-opus-5-5) in Claude Code, through T3 Code.

@github-actions github-actions Bot added area:server Touches the server area area:cli Touches the cli area area:docs Touches the docs area size:s Under 100 changed lines labels Nov 1, 2026
@allisonmahmood

Copy link
Copy Markdown
Owner Author

Review (GPT 6.1 Sol, xhigh) on 059055c: PASS, no findings.

  • The refusal: a bound repo with no version gets unknown_base_version, naming a pull or --allow-behind. It follows ADR-0004 (exit 1, kind: "local"). It happens before building or saving an attempt, so no stale pending record is left, and existing recovery runs first.
  • Unchanged: unbound first publishes and file publishing. Known versions still compare against MAX(version_number), so a rollback can't bypass the check.
  • --allow-behind: one publish with it records the returned version.
  • Coverage: other repo-publish callers, including the dev runner's pinned CLI, go through the same handler.
  • Docs: they match the code, and the compatibility change is called out.
  • Tests: 114 tests pass across the publish, description, recovery, lifecycle and file-publish suites.

@allisonmahmood

Copy link
Copy Markdown
Owner Author

Acceptance: PASS with notes

Checked 059055c15b01c73b0bdbfb2b12588d266912a819 (base 1f187a92b2c20da81e8a1d647ea28a60a075d6ef) on team, by Claude Opus 5.5 in Claude Code (T3 Code).

I ran everything on a pnpm dev up team environment at the head, as Ada through the environment's CLI. Version numbers come from that instance's patch_versions table. Patch ids and the origin are replaced with placeholders.

Done means

  • A bound repo with no recorded version is refused with a clear "unknown base version" message: passed. A repo had v1 and v2, was rolled back to v1, and had version deleted from patchy.json. Publishing it exits 1 with {"ok":false,"kind":"local","code":"unknown_base_version"}. The message names patchy pull <patch> and --allow-behind. Afterwards patchy.json's hash is unchanged, no file in the repo is newer than the attempt, there is no .patchy/publish/*/attempt, and the instance still has versions: 1,2; served: v1.
  • --allow-behind publishes and records a version: passed. publish --allow-behind gives Version: 3, and patchy.json gets "version": 3.
  • A bound repo with a known version is still compared with the newest version, including after a rollback: passed.
    • The next plain publish from that repo gives v4.
    • A pulled copy publishes v5, and then the v4 copy is refused: rejected / behind, baseVersion 4, latestVersion 5, exit 2.
    • After rollback 3, the v4 copy is still refused as behind (latest 5). So is a fresh pull of the served v3 (baseVersion 3, latestVersion 5).
    • The v5 copy, which holds the newest version, publishes v6.
  • A repo's first publish, before it's bound: passed. patchy init notes followed by patchy publish gives v1 and records patch and "version": 1.
  • Recovering a pending publish: passed. I made a repo folder read-only so the instance would accept v7 but the CLI couldn't write patchy.json ("Could not write patch into patchy.json. Run publish again to recover the saved result.", exit 1). The attempt stayed in .patchy/publish/<hash>/attempt/. I then deleted version from patchy.json and published again. Recovery ran before the new refusal: Updated patch / Version: 7, exit 0, no new version on the instance, "version": 7 recorded and the attempt cleared.
  • Publishing an HTML file: passed. publish standup.html --name standup --description … gives v1, and a second publish standup.html gives v2. --allow-behind on a file is still refused locally as before ("…a file publish has no version to be behind.", exit 1).
  • Called out as a compatibility change: passed. The PR is marked Breaking. The README, ADR-0004's local codes table, docs/product.md and patchy-loop all say a legacy repo needs --allow-behind once.
  • Test: the new cliRepoPublish case fails on the base's commands.ts (expected { status: 0 … } to match { status: 1, stdout: '' }) and passes on the head. Locally cliRepoPublish, cliRepoRecovery and cliRepoDescriptions pass, 25 of 25.
CLI lines from the refusal and recovery
$ patchy publish                      # patchy.json names a patch, no version
Unknown base version: patchy.json names patch <patch> but no version, so publish can't tell whether anyone published since this copy. Pull a fresh copy into a new folder with `patchy pull <patch>` and make the change there, or, once the person you are working for agrees to replace whatever is live, publish with --allow-behind; that publish records the version.
exit 1
versions: 1,2; served: v1

$ patchy publish --allow-behind
Updated patch
Version: 3
  "version": 3

$ (cd notes && patchy publish --json)  # after rollback 3; this copy is from v4
{"kind":"rejected","code":"behind","baseVersion":4,"latestVersion":5}
exit 2

$ patchy publish                      # pending attempt, then version deleted
Updated patch
Version: 7
exit 0
  "version": 7
versions: 1,2,3,4,5,6,7; served: v7

Golden journeys

  • Publish a page: passed. Ada's CLI publishes standup.html, and Ben's Home lists /acme/standup, which answers 200 for him. retire serves "standup is retired" with no frame, and restore brings back the page titled "Standup".
  • The other journeys don't reach this change. The one changed path is the CLI's repo publish, after recovery and before the build.

Rollback answers: they match the diff. There is no migration, wire change or stored shape (packages/api is untouched, and rollback-rehearsal passes). A revert only lets legacy repos publish unchecked again, and repos keep the version any publish records. No one-way label is needed. All checks pass on the head; attio-live and pidgeon-suite skipped as unaffected.

Not run

  • Recovering an attempt that an older CLI release staged. My pending attempt came from the head's CLI. The order (recovery, then the refusal) doesn't depend on who staged it.
  • cliLifecycle and cliPublish locally, because CLI suites are flaky on this shared machine. CI's test (22/24/26/bun) pass on the head.

Notes

  • A legacy repo bound to a retired patch now gets unknown_base_version first. Its real state shows up only on the next try: publish --allow-behind gives rejected / patch_retired ("This patch is retired. Restore it…"). Nothing is published, so it costs an agent one extra step. Still, the message's "agrees to replace whatever is live" doesn't fit a patch with nothing live. A deleted patch would presumably behave the same way. Not a blocker.

@allisonmahmood
allisonmahmood force-pushed the fix/publish-unknown-base-version branch from 059055c to 8932680 Compare November 4, 2026 00:24
@allisonmahmood
allisonmahmood merged commit bc4360d into main Nov 4, 2026
24 checks passed
@allisonmahmood
allisonmahmood deleted the fix/publish-unknown-base-version branch November 4, 2026 00:40
allisonmahmood added a commit that referenced this pull request Nov 4, 2026
…ges publish (#1241)

## What changed

This adds release 36's What's new entry, written from `1acc968`. It
covers everything merged since release 35's `through` (`dd0e2ec`), and
sets the `patchy` release to `0.36.0` in `packages/patchy/package.json`
and `CURRENT_RELEASE`.

| Change | PRs |
| --- | --- |
| Improved: shortcuts work where you use them (keys for one part of a
patch, the closest wins, text boxes keep their typing keys) | #1231 |
| Improved: the shortcuts sheet shows what works where you are (Ctrl+/
and ⌘/ open it, its commands run, it opens from a patch's menu and in
view on a narrow screen, keeps the look, spells keys out away from a
Mac) | #1231, #1181, #1178, #1180, #1177 |
| Fixed: keys pressed while a patch opens reach it | #1183 |
| Fixed: pages styled with Tailwind 4 publish, and a look with the same
rule saves | #1191 |
| Fixed: an old copy of a patch no longer replaces newer work
(**Breaking** for such a copy: it needs `patchy pull` or one
`--allow-behind` publish) | #1179 |
| Improved: your agent can check a publish before sending it | #1188 |
| Improved: your agent hears what changed when it updates a patch |
#1186, #1185 |
| Fixed: your agent stops chasing false alarms (`pnpm install` exit
codes, `manifest.json` bytes, the description notice, a copied dev
record) | #1176, #1174, #1175 |
| Behind the scenes: fuller hotkeys instructions for agents; fewer
redraw costs for patches with many shortcuts | #1182, #1187 |

`patchChanges` has three sentences for the agent refreshing a patch
across this release:
- #1231's, from its PR: text fields keep their keys, `preventDefault()`,
and the sheet's Mod+/ and `.hotkey-row` buttons.
- The sheet's dialog renders in `document.body`, and element-only page
rules don't reach it (#1178, #1180). Its own row lists last (#1181). The
hotkey label helpers take only valid literals (#1177).
- Publish's `unknown_base_version` (#1179).

It also rewords release 33's "Press ? to see every shortcut a patch
has". That was true only for a patch that mounts the shortcuts sheet, so
it now says a patch *can* list its shortcuts.

The rest get no line:
- #1206, #1207, #1209 and #1220 are `pnpm dev eval` tooling.
- #1222 is release 35's own entry.

## Look at

- **The entry**, at the top of `releases` in
`packages/core/src/whatsNew.ts`, and release 33's reworded line.
- **Rollback safety, from the live commit `d28fdd0` (release 35) to
`1acc968`:**
- #1191 is labelled `one-way`. Its Release impact: a company look
published after this release with a nested `@supports` condition stays
stored after a revert. Release 35 refuses any bundle carrying it, so
repo publishes in that company would fail until an admin runs `patchy
look restore` to an earlier revision. Pages and Tailwind 4 repos already
published stay published.
- #1183 is the only change to what the server serves browsers: the
shell's script, under a digest-named URL. Its revert leaves nothing
behind.
- The hotkeys PRs change `patchy/hotkeys`, which patches bundle when
they are built. Published patches keep their copy.
- The CLI PRs change what a CLI writes and refuses. Release 35 reads
everything they leave behind: #1176's `allowBuilds` entry, #1174's
indented `manifest.json`, and the `version` recorded by an
`--allow-behind` publish.

**Rollback line:** If this release misbehaves, roll back to `d28fdd0`
(release 35). First check that no company's look has a nested
`@supports` condition, and `patchy look restore` an earlier revision
where one does (#1191).

## How it was verified

- **Tests.** `whatsNew.test.ts`, `WhatsNewPages.test.ts` and
`schemas.test.ts` pass (22 tests), and `bun fmt` passes on the changed
files.
- **Facts.** The sheet's new `document.body` home and its element-rule
reset were checked against `hotkeys.ts` and `hotkeySheet.ts` on main.
- **Deploy state.** I pinned the live commit from `/healthz/deep`:
`d28fdd0` (release 35). 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

Text and version numbers only. Like every release, the `0.36.0` bump
tells CLIs and patch repos installed before this deploy to upgrade.

- **What does a revert leave behind?** Nothing.
- **Does the release before it still work with that?** Yes.

Built by Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, through 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:server Touches the server area size:s Under 100 changed lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Publish from a repo with no recorded version goes over newer versions unchecked

1 participant