Skip to content

fix(weft): lock each host for its deploy or rollback, refuse a downgrade and an unexpected rollback (#891) [AC-680] - #1275

Open
JacobHaig wants to merge 1 commit into
devfrom
fix/weft-891-deploy-safety
Open

JacobHaig wants to merge 1 commit into
devfrom
fix/weft-891-deploy-safety

Conversation

@JacobHaig

Copy link
Copy Markdown
Member

Closes three of the open items in #891. Each is listed with the failure it prevents.

One run at a time per host (N1, OpenSpec task 5.8). Semaphore runs two templates against one host if a person launches both. A deploy and a rollback of the same host would then interleave their stop, backup, start and deploy.state writes, and one could mark the host healthy at state the other wrote. The issue body records N1 as "no lock", but the later design (design.md known gaps, task 5.8, 2026-11-28) makes the lock a gate before the rack, so this follows the design. Every deploy (tasks/weft-deploy.yml, reached by five launchers) and Roll Back weft Host now take a non-blocking kernel flock on a root-owned deploy.lock in the role's state directory before anything is fetched for the stop. They release it in an always, however the run ends. A second launch is refused before it changes anything, and the refusal names the play holding the lock, when it took it and when it lapses. An Ansible run is many short processes, so the holder is one detached process on the host. The accepted cost: if the controller dies mid-run, nothing releases the lock, and it lapses after weft_host_lock_minutes (default 120, refused if not longer than the health window and the watch together). The template descriptions that told people to check Semaphore's running tasks now describe the lock.

A deploy only moves a rack host forward (N3, task 3.4). A pin reverted to an older version used to deploy that older binary over a catalog the newer release had already migrated. The deploy and the rollback now write the release a host was last started on to a root-owned deploy.release. The deploy writes it after the backup verifies and before the start that migrates. A rack deploy whose pin is an older version than that refuses before anything stops, and says to use Roll Back weft Host, which restores the backup and does not run this check. Staging is not checked because its pins are commits, which have no order.

A rollback goes only where the person meant (F35). Roll Back weft Host deployed whatever the synced inventory pinned. A revert not yet synced, or the wrong host reverted, would restore the backup onto a release nobody chose. A new required survey input, weft_rollback_to, names the intended release, and the rollback refuses before reading or moving anything when the pin names another.

Left out:

  • Snapshot before each host's deploy (task 6.0). This needs decisions. "Snapshot VM" runs in its own isolated Semaphore environment with an AppRole of its own, and "Roll Out weft Release" would need that credential or a new environment. Each weft host would also need its vm_vmid and vm_node declared in site-config, which no weft host carries today. The snapshot stays a manual step.
  • F34 (door.key outside the clone, task 3.3). This needs a decision on where the key goes. The door reads the key as the deploy user (keep-id), so it cannot live in the root-owned state directory, and the door's records directory is one the door can write.
  • N5 (IPv6 brackets). Already done on dev (weft docs: 2026-10-13 proofs, the Alloy outage, and two ledger entries #585), with tests in test_weft_deploy_runs.py.
  • The Discord webhook file. This waits for weft's front door to gain the announcement.

Tests (platform/tests/test_weft_deploy_runs.py, run against the real tasks and a fake engine): a deploy is refused while another run holds the lock, and nothing is stopped; the lock is free after a passing deploy and after a failed one; an older rack pin is refused before the stop; a newer pin deploys (v1.10.0 after v1.9.0); staging deploys any commit; the real rollback-weft-host.yml refuses a weft_rollback_to that the pin does not name and goes on when it does. I mutated the lock release and the version comparison and saw the tests go red. The bats rescue-extraction test is updated for the new block nesting.

Nothing was run against a real host.

…ade and an unexpected rollback (#891)

Two launches against one weft host (a deploy and a rollback, or two
templates) interleaved their stop, backup, start and deploy.state writes,
so one run could mark a host healthy at state the other wrote. Every
deploy (tasks/weft-deploy.yml, five launchers) and Roll Back weft Host now
take a non-blocking kernel flock on a root-owned deploy.lock in the
state directory before anything is fetched for the stop, release it
however they end, and refuse a second launch naming the run that holds
it. The holder is one detached process on the host; if the controller
dies mid-run the lock lapses after weft_host_lock_minutes (120). Task 5.8.

A rack pin moved back to an older version used to deploy over a catalog
the newer release had migrated. The deploy and the rollback now record
the release a host was last started on in root-owned deploy.release, and
a rack deploy whose pin is older refuses before anything stops; going
back is Roll Back weft Host, which restores the backup. Task 3.4 (N3).

Roll Back weft Host went back to whatever the synced inventory pinned,
so an unsynced revert or the wrong host reverted restored a backup onto a
release nobody chose. It now takes weft_rollback_to and refuses when the
pin names another release (F35).
@coderabbitai

coderabbitai Bot commented Dec 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

  • Run on-demand review

This review includes 13 billable files and costs up to $3.25.

  • Add your request for automatic reviews

Open in CodeRabbit

Reviews can continue after your included limit without a manual trigger. An admin must approve usage-based billing.

Or wait 3 minutes for your next included review.

Check out review usage here.

View limit details

Limit details: You’ve used all 2 included reviews currently available. Your 50 included PR review attempts over the past 7 days set your current allowance at 2 reviews per hour.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 7808ad5 and 832ee4b.

Files selected for processing: 13

  • plan/development/25-weft-service.md
  • plan/development/openspec/changes/add-weft-service/design.md
  • plan/development/openspec/changes/add-weft-service/tasks.md
  • platform/playbooks/rollback-weft-host.yml
  • platform/playbooks/tasks/weft-deploy.yml
  • platform/playbooks/tasks/weft-host-lock.yml
  • platform/playbooks/vars/weft.yml
  • platform/semaphore/templates.yml
  • platform/services/weft-door/deployment/README.md
  • platform/services/weft-workspace/deployment/CLAUDE.md
  • platform/services/weft-workspace/deployment/README.md
  • platform/tests/test_service_weft.bats
  • platform/tests/test_weft_deploy_runs.py
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@uhstray-io-plane-github

Copy link
Copy Markdown

Linked to Plane Work Item(s)

This comment was auto-generated by Plane

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant