Skip to content

Unlock sites stuck behind an operation whose pid now belongs to another process - #6193

Merged
youknowriad merged 1 commit into
trunkfrom
stu-2864-unlock-stuck-site-operations
Nov 25, 2026
Merged

youknowriad merged 1 commit into
trunkfrom
stu-2864-unlock-stuck-site-operations

Conversation

@youknowriad

Copy link
Copy Markdown
Contributor

Related issues

How AI was used in this PR

Claude Code read the report and the site-operation lock, reproduced the stuck site with the released 2.4.0 CLI on a throwaway config, wrote the fix and tests, and checked the before/after behavior with real CLI builds. The scope (including unlocking records from older builds) was decided along the way.

Proposed Changes

A site could stay stuck forever on "Cannot run a site start: an export is already in progress for this site", with no way out short of editing the config by hand. Restarting Studio or the computer didn't help.

Studio marks a site as busy by storing the pid of the process running the operation, and treats it as busy as long as that pid is alive. When the operation's process died without clearing that mark, and its pid was later reused by an unrelated process (after a reboot, or once pids wrap around), Studio kept believing the operation was still running.

  • An operation now also records when the machine booted, so one taken before the last reboot no longer blocks the site.
  • Marks left by older builds, which recorded no boot time, are treated as stale. This unlocks sites already stuck today, including after the 2.4 config import, which copied them over.
  • Clearing the mark when an operation ends is retried when the config lock is briefly unavailable. A single lock timeout used to leave the site busy for as long as the owning process lived, which for studio mcp or the daemon can be indefinitely.

Trade-off: right after upgrading from 2.4.0, an operation still running in a 2.4.0 process (most likely a studio mcp server kept alive across the update) is no longer protected for its remaining duration.

Testing Instructions

Unit tests: npm test -- apps/cli/lib/tests/site-operations.test.ts

To reproduce with the real CLI, on a throwaway config:

  1. npm run cli:build
  2. export DEV_CONFIG_DIR=/tmp/s2864/config STUDIO_PROCESS_MANAGER_HOME=/tmp/s2864/pm STUDIO_BASE_PORT=9470
  3. Create a site and stop it: node apps/cli/dist/cli/main.mjs site create --path /tmp/s2864/sites/test --skip-browser, then site stop --path /tmp/s2864/sites/test
  4. In /tmp/s2864/config/config.json, add "operation": { "pid": <pid of Finder>, "kind": "export" } to the site, which is what 2.4.0 leaves behind after a crash and a pid reuse.
  5. site start --path /tmp/s2864/sites/test
    • With the installed 2.4.0 CLI (/Applications/Studio.app/Contents/Resources/bin/node /Applications/Studio.app/Contents/Resources/cli/main.mjs): refused with "an export is already in progress".
    • With this branch: the site starts.
  6. Set the operation to { "pid": <pid of Finder>, "kind": "export", "bootTime": <now minus os.uptime() in ms> }, which is what a live operation looks like: this branch refuses the start, as it should.
  7. Stop the site and daemon with site stop --all, then remove /tmp/s2864.

Pre-merge Checklist

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

🤖 Generated with Claude Code

…er process

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@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: youknowriad is a trusted author.

@youknowriad
youknowriad merged commit 3a6bdcc into trunk Nov 25, 2026
9 of 11 checks passed
@youknowriad
youknowriad deleted the stu-2864-unlock-stuck-site-operations branch November 25, 2026 17:07
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