Skip to content

Add --warmup: keep the main worktree fresh, make setup wait on it#6

Open
EasterPeanut wants to merge 1 commit into
DefactoSoftware:mainfrom
EasterPeanut:warmup
Open

Add --warmup: keep the main worktree fresh, make setup wait on it#6
EasterPeanut wants to merge 1 commit into
DefactoSoftware:mainfrom
EasterPeanut:warmup

Conversation

@EasterPeanut

Copy link
Copy Markdown

New worktrees are seeded from the main worktree's build caches and databases, so they're only as fresh as main. A stale main means every new worktree starts with an outdated branch, cold caches, and an unmigrated database — and creating a worktree while main is mid-compile can copy a half-built cache.

What this adds

werksfeer --warmup [--force]

Updates the main worktree (can be triggered from cron, launchd, or shell startup):

  1. Checks out the default branch (from origin/HEAD; override with [warmup] branch) and pulls with --ff-only. Refuses to touch a main worktree with uncommitted tracked changes; untracked files are fine.
  2. Runs a per-project-type refresh chain (override with [warmup] command):
Type Command
Rails bundle install && bin/rails db:prepare
Elixir mix deps.get && mix compile && mix ecto.migrate (+ node package install if package.json exists)
Python uv sync / pipenv install / pip install -r requirements.txt
Node npm ci / yarn / pnpm / bun

Optional [warmup] min_interval (minutes) throttles repeated triggers; --force overrides.

Setup waits on a running warmup

While a warmup runs it holds a per-project lock under ~/.local/share/werksfeer/warmup/. The normal setup flow now waits on that lock before copying from main (configurable [warmup] wait_timeout, default 1800s), so a new worktree never copies a half-built _build/.bundle. Stale locks from crashed runs are detected by PID and removed automatically. Projects that never run --warmup are unaffected — no lock ever exists, the wait is a no-op.

Testing

  • bash -n clean
  • Smoke-tested with a scratch repo: --warmup pulls and runs the configured command; second run within min_interval skips; --force overrides
  • Integration: created a worktree while a warmup was sleeping — setup printed Warmup in progress on main worktree, waiting..., blocked until the lock cleared, then completed; lock dir removed afterwards
  • Stale-lock path: lock with a dead PID is removed and setup continues

🤖 Generated with Claude Code

New worktrees are seeded from the main worktree's build caches and
databases, so they are only as fresh as main. This adds:

- werksfeer --warmup [--force]: updates the main worktree (checkout of
  the default branch, git pull --ff-only, then a per-project-type
  deps/build/migrate chain, overridable via [warmup] command). Refuses
  to touch a main worktree with uncommitted tracked changes. Optional
  min_interval throttle for cron/startup triggers.
- A per-project lock while a warmup runs; the normal setup flow now
  waits on it (configurable wait_timeout, default 30m), so a new
  worktree never copies a half-built cache. Stale locks from crashed
  runs are detected by PID and removed.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@EasterPeanut

Copy link
Copy Markdown
Author

Not merging this one yet, want to look at it with colleague when he returns from his vacation.

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