Skip to content

Let a given pull selection replace an interrupted one - #6167

Merged
chubes4 merged 1 commit into
trunkfrom
chubes/pull-selection-replaces-interrupted
Nov 30, 2026
Merged

chubes4 merged 1 commit into
trunkfrom
chubes/pull-selection-replaces-interrupted

Conversation

@chubes4

@chubes4 chubes4 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Related issues

How AI was used in this PR

Claude Opus 5.5 (Claude Code), running as Franklin, Chris's agent, found this while stress-testing Reprint pull on real WordPress.com Atomic and preview sites, then wrote the fix and tests. It was split out of #6157. Chris reviews before merge.

Proposed Changes

  • One failed --only selection blocked every later pull of that site. Studio saved the selection before the pull and reused it whenever an interrupted pull existed, so --only nonexistent/path kept failing even after rerunning with --options all.
  • The saved selection now applies only when no selection is given (a bare studio pull resume). A different selection aborts the interrupted pull and starts over.

Testing Instructions

With STUDIO_ENABLE_PULL_REPRINT=1:

  1. Run studio pull --remote-site <id> --only nonexistent/path. It fails.
  2. Run it again with --options all. On trunk it fails again with the old selection. With this change, the earlier selection is discarded and the full site pulls.
  3. Interrupt a pull and run a bare studio pull: it resumes with the saved selection.

Checked on macOS, Linux (Ubuntu) and a Windows 11 VM. On Linux, an interrupted and resumed pull ended with the same 23,365 files as a full pull.

Unit tests: npx vitest run apps/cli/lib/pull apps/cli/commands/tests/pull.test.ts.

Pre-merge Checklist

  • Have you checked for TypeScript, React or other console errors?

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-approved: chubes4 is a trusted author.

@chubes4
chubes4 marked this pull request as ready for review November 24, 2026 02:10
@chubes4
chubes4 merged commit 2c786e2 into trunk Nov 30, 2026
14 checks passed
@chubes4
chubes4 deleted the chubes/pull-selection-replaces-interrupted branch November 30, 2026 13:46
chubes4 added a commit that referenced this pull request Nov 30, 2026
## Related issues

- Part of the Reprint pull rollout (removing
`STUDIO_ENABLE_PULL_REPRINT`). Follows #6163–#6167.

## How AI was used in this PR

Claude Opus 5.5 (Claude Code), running as Franklin, Chris's agent, found
this while stress-testing Reprint pull on real WordPress.com sites, then
wrote the fix and tests and ran the reproduction below. Chris reviews
before merge.

## Proposed Changes

- Two local sites pulling the same WordPress.com site at the same time
failed with `AUTH_UNKNOWN_KEY` (HTTP 403). Studio generated a Reprint
key per local site, and Jetpack keeps one key per site
(Automattic/jetpack#53537: "Installing a key replaces the previous
one"). The second pull installed its key over the first one's, and the
first pull's next request was refused.
- Studio now signs every Reprint pull with one key per machine,
`~/.studio/reprint-key.pem`, passed to `preflight`, `pull-files` and
`pull-db` as `--private-key-path`. Every local site on the machine
installs the same key, so they no longer replace each other's.
- The key is generated in Node (RSA 3072, the same as `reprint keygen`)
on first use. It is written to a temporary file and hard-linked into
place, so pulls that start at the same time end up with the same key.
This also removes the `pull-metadata` and `keygen` Reprint calls from
the start of each pull.
- Keys in existing per-site state directories are no longer used.
`--private-key-path` takes precedence over them, and the next pull
installs the machine key.
- Pulling one site from two different machines still conflicts, because
Jetpack keeps one key per site. That limit was a deliberate Jetpack
decision and is out of scope here.

## Testing Instructions

With `STUDIO_ENABLE_PULL_REPRINT=1`, start two pulls of the same remote
into two different local sites, about two seconds apart:

```
studio pull --path <site-a> --remote-site <id> --options all &
studio pull --path <site-b> --remote-site <id> --options all &
```

- On trunk (macOS, a preview site): the first pull succeeds and the
second fails at `files-pull` with `AUTH_UNKNOWN_KEY`.
- With this change: both pulls succeed, in two runs out of two. The
first run started with no `~/.studio/reprint-key.pem`. Afterwards there
is a single key file with mode `0600`.

Unit tests: `npx vitest run apps/cli/lib/pull
apps/cli/commands/tests/pull.test.ts`. The new test checks that three
pulls starting together get one key, and that it signs for the public
key it reports. The same key-creation code was also run on a Windows 11
VM, with the same result.

## Pre-merge Checklist

- [x] Have you checked for TypeScript, React or other console errors?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant