Skip to content

Refresh each host's agent package from main on an hourly job - #6

Merged
mimen merged 2 commits into
mainfrom
agent-refresh
Sep 15, 2026
Merged

mimen merged 2 commits into
mainfrom
agent-refresh

Conversation

@mimen

@mimen mimen commented Sep 15, 2026

Copy link
Copy Markdown
Owner

Why

This is the root cause of the stale-template bug. Every machine pins its own agent package, so a skill fix merged to main only reaches a host when someone re-runs bootstrap-agent there by hand. A theme that main had already deleted stayed in use for a week that way, across three machines, and every plan generated in that window used it.

What it does

bin/refresh-agent compares the installed .release-revision against the tip of main and, when they differ, re-runs bootstrap-agent from the package being replaced, so the installer picks up its own fixes on the same tick. It reads url and tokenRef from the existing host config and never writes that file. A matching pin prints one line and exits zero.

It runs unattended, so there is no recovery path and no default that papers over a broken host. A missing config, a missing package, a non-sha revision, and an unreachable GitHub each exit nonzero naming the failing step.

--install --job-id schedules it hourly as a user LaunchAgent whose ProgramArguments go through the hub reporter, so an unattended failure surfaces as a failed run rather than silence. The job id differs per host, hence an explicit argument. It refuses to overwrite a plist at that label it did not write.

The scheduled command deliberately points at the stable agent-current link rather than a resolved path, which would bake packages/<sha> into the plist and strand the job at the first upgrade.

Review notes

The second commit is mine on top of the implementation. It adds the non-blocking flock, because two hourly runs, or one racing a manual bootstrap-agent, would both clear install-agent's guards and then race the agent-current relink. mini-host.py guards activate the same way. It also corrects the job id examples to the registry's <host>.launchd.<label> convention.

Known gaps, deliberately not addressed here

Nothing checks that main is green. The Mini's own deploy path runs typecheck and both suites inside activate before flipping current, but bootstrap-agent verifies nothing, so a bad merge would propagate to every agent host within the hour. Gating on the commit's check-runs status would close it. It is a real hole, and it turns this from tracking main into tracking a release channel, which is a separate decision.

Nothing prunes packages/<sha>, so an hourly refresh against an active repo accumulates one package directory per merged commit.

Verification

Self-check passes under the Mini's Python 3.9.6 and under 3.14. 14 Python deploy regressions, up from 8. 68 bun tests, 193 assertions. Clean typecheck. The live resolve path was also exercised read-only against the real GitHub API and returned exactly git rev-parse origin/main, so it is proven rather than inferred. The mutating path was never run and no LaunchAgent was installed.

🤖 Generated with Claude Code

mimen and others added 2 commits September 15, 2026 13:34
Every machine pins its package independently, so a skill fix merged to main
only reaches a host when someone re-runs bootstrap-agent there. A theme
deleted on main stayed in use for a week that way.

bin/refresh-agent compares the installed .release-revision against the tip
of main and, when they differ, re-runs bootstrap-agent from the package
being replaced, so the installer updates on the same tick. It reads url and
tokenRef from the existing host config and never writes it. A matching pin
prints one line and exits zero. A missing config, a missing package, a
non-sha revision, and an unreachable GitHub each exit nonzero naming the
failing step, because this runs unattended.

--install --job-id writes the hourly LaunchAgent through the hub reporter
and refuses to overwrite a plist it did not write.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Two hourly runs, or one racing a manual bootstrap-agent, would both clear install-agent's guards and then race the agent-current relink. mini-host.py takes the same non-blocking flock around activate; a second runner now exits naming the lock step instead of interleaving. The documented and suggested job ids also have to follow the registry's <host>.launchd.<label> convention, and a wrong example in the one document telling operators how to run this is how the next drift starts.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@mimen
mimen merged commit 9467fe2 into main Sep 15, 2026
1 check passed
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