Skip to content

feat: Fence and journal each Device at the site - #180

Merged
scotwells merged 8 commits into
feat/manual-inventory-recordsfrom
feat/device-site-execution
Nov 26, 2026
Merged

scotwells merged 8 commits into
feat/manual-inventory-recordsfrom
feat/device-site-execution

Conversation

@scotwells

Copy link
Copy Markdown
Contributor

Summary

The site that reaches a server will fence and journal each Device on its own, so an older worker can never act after a newer operation is admitted.

This change adds that site framework, with the Redfish install and wipe workers behind one worker contract. Before anything is sent, the framework checks the per-Device credential, the approved TLS key and the server's identity, and it stops each worker at its deadline.

It is inert until the cutover, and the existing executors keep running the current lifecycle with nothing connecting the two paths.

Decisions

  • Each site keeps one durable directory per Device on its retained volume: the fence it has seen, the fence for which older workers stopped, the journal, and its copy of each result.
  • A stored result is final, and a worker shut down from outside stores none, so its replacement resumes from the journal.
  • A power-on is observed after a crash and never sent again. The existing executor resends it within a small budget.
  • The framework checks identity only, and each worker checks the capabilities it uses, so a kind such as power needs no network boot.
  • The cutover adds the access layer for the local VM and simulator executors. The worker contract takes it without changing.
  • The cutover also adds synchronized DHCP reservations to the new workers.

Test plan

  • Two workers on one Device and two Devices in parallel keep the fence, journal and results consistent
  • A TLS key mismatch and an identity mismatch send nothing to a TLS test server
  • An install interrupted in either phase resumes with one power-on per phase
  • The offline checks and both local end-to-end runs pass

Related to #174

🤖 Generated with Claude Code

@scotwells
scotwells requested a review from ecv November 25, 2026 04:41
@scotwells
scotwells marked this pull request as ready for review November 25, 2026 04:53
@scotwells
scotwells requested a review from a team as a code owner November 25, 2026 04:53

@kevwilliams kevwilliams 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.

Hold: a same-fence redelivery can act on the BMC after the first worker stored its result.

  • Runner.Run checks Results.Get only before acquire; a copy at the same fence that waits on the lock resumes from the journal once worker 1 ends (e.g. OutcomeUnknown) and sends more steps. A temporary test showed runs=2 sends=2.
  • Fix: re-check Results.Get after taking the lock, or end same-fence waiters when stopped == fence.
  • Test: a same-fence copy that waits through the first worker's failure.

@scotwells
scotwells force-pushed the feat/device-site-execution branch from 5d142ae to 370d02b Compare November 25, 2026 05:37
scotwells and others added 7 commits November 24, 2026 23:44
Identify walks the Systems collection and verifies the enrolled System
with reads only, and records what it offers without requiring it.
Discover is Identify followed by the install and cleanup capability
checks, so the existing executor behaves as before. A kind that needs no
network boot, such as power, can then verify identity alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the site framework for Device operations. Each Device has a durable
fence store and journal on the site's retained volume. A newer fence
stops the older worker before the newer one starts, and the site
records that confirmation for the coordinator. The journal records each
step and its payload before sending it, refuses steps below the stored
fence, and replays a step after a crash by observing it.

Before anything is sent, the framework checks the inputs' digest, the
site's enrollment against the admitted snapshot, the per-Device
credential, the approved TLS pin, and the server's identity. Workers
stop at their deadline, and results carry the fence and typed evidence.
The coordinator records an undeclared worker reason as
UndeclaredReason.

It is inert: nothing delivers an assignment to it until the cutover.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Port the Redfish executor's install and wipe phases to the site
framework. Power-on is journaled and sent once, and observed after a
crash. Boot admissions are served only at the Device's stored fence, so
a superseded operation can never boot the server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mark Increment B implemented and inert, record where a site stores
fences and its journal, and describe the worker contract.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A worker that finds the same assignment already holding the run lock
now stores nothing and leaves the result to that worker. Any other
refusal is Failed only when the journal holds nothing for the
operation. A stored result is final, and a redelivery returns it. A
worker stopped from outside stores no result, so its replacement
resumes from the journal. The fence is checked again just before each
send.

The Redfish workers journal each verified phase and skip it on resume,
so a worker interrupted in the disk phase continues. Power-off is
bounded at five minutes again, and the receipt wait after power-off is
30 seconds, as in the old executor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A worker stopped from outside while it waits for the run lock now
stores no result, like one stopped during its checks or its steps. A
resumed phase keeps the time it was first verified. Add tests for each
shutdown stage, a lost lock with journaled steps, a fence raised between
journal and send, and the power-off bound's reason and timing.

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

Copy link
Copy Markdown
Contributor Author

This branch is rebased onto #178 at 9cf6d32, which closes six admission gaps the power kind found in #179. The head is now e4ec436.

B's own commits are unchanged. The one conflict kept B's declared Redfish worker reasons together with #178's new evidence validator, which now receives the operation it checks. A worker result whose reason its kind never declared is still recorded as UndeclaredReason, alongside #178's new rule that a kind can require evidence for a success.

The rereviewer approved this exact head. The site, custody, Redfish and discovery tests pass with the race detector.

@kevwilliams kevwilliams 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.

Hold: a same-fence copy that wins the lock after worker 1 ends still acts; Results.Get runs only before acquire.

  • At e4ec436, Runner.Run still checks Results.Get once, before r.acquire; when worker 1 finishes while the copy waits, acquire succeeds and the copy resumes and sends.
  • TestARedeliveryWhileTheSameOperationRunsStoresNothing covers a copy that times out while worker 1 still runs, not one that gets the lock after worker 1 stores its result.
  • Fix: re-check Results.Get after acquire, with a test where worker 1 fails mid-wait.

@ecv ecv 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.

Request changes.

Agree with kevwilliams's hold, and I reproduced it at e4ec436: a same-fence redelivery that waits for the run lock can act on the BMC after worker 1 has already stored its result.

  • internal/site/runner.go Runner.Run reads Results.Get once, before r.acquire. With a copy waiting on the lock, worker 1 ending OutcomeUnknown (its first send failed) releases the lock, the copy acquires it, resumes from the journal and runs the kind again. My temporary test with an Idempotent first step gave runs=2 sends=3, and the second run sent a BMC action after the result was recorded. TestARedeliveryWhileTheSameOperationRunsStoresNothing only covers a copy that times out while worker 1 still runs.
  • Fix: re-check Results.Get after acquire and return the stored result, releasing the lock first. Add a test where worker 1 fails while a same-fence copy waits.
  • Tamper results (go test ./internal/site/...): dropping the fence re-check before send fails TestAFenceRaisedBetweenJournalAndSendStopsTheStep; dropping the approved-pin == admitted-key check fails TestPinMismatchSendsNothing; resending a replayed non-idempotent step fails TestAReplayedStepIsObservedNotSentAgain. Those three guards are covered. The post-acquire result check is the one that is not.
  • Fencing otherwise holds: Store.IntendWithPayload and Done refuse a fence below the stored one under the per-Device lock, Step re-reads the fence after journaling and before Send, and watch cancels the worker on a newer fence. A step journaled but not done is observed, not resent, unless the kind marks it Idempotent.
  • Credentials: looked up per Device from labelled Secrets in the site namespace, pin required and equal to the admitted key, and sanitize keeps BMC bodies and endpoints out of results. No Secret RBAC is added here.
  • Stack: base is feat/device-custody-foundation, head contains #178's head 9cf6d32, and the delta is 23 files (+3336/-43). Validate, standalone-smoke and image builds pass; custody, site, redfishwork, bmcdiscovery and redfish tests pass locally with -timeout 10m.

Follow-ups:

  • Fence is per-site store state; cross-site exclusion depends on the coordinator seeing every serving site's Seen before raising it. I did not trace that path in #178's coordinator under a partitioned site.
  • The discovery Role grants get, list, watch on all Secrets in the namespace (comment in config/base/bmc-discovery/rbac.yaml says so); the site worker reuses that, so keep it in a dedicated namespace.

A same-fence redelivery checked for a stored result only before it
waited for the run lock. If the first worker stored its outcome while
the copy waited, the copy took the lock, resumed from the journal and
could send to the server again, as a step marked safe to repeat did.
The copy now checks again once it holds the lock and returns the
stored result without running the kind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scotwells
scotwells changed the base branch from feat/device-custody-foundation to feat/manual-inventory-records November 25, 2026 14:58
An error occurred while trying to automatically change base from feat/device-custody-foundation to feat/manual-inventory-records November 25, 2026 14:58
@scotwells

Copy link
Copy Markdown
Contributor Author

@kevwilliams @ecv thanks for the hold and the reproduction. Fixed at 9885927.

After acquire, Runner.Run checks Results.Get again. If the first worker stored a result while the copy waited, the copy returns that result and releases the lock without running the kind.

TestACopyWaitingForTheLockReturnsTheStoredResult covers the case you described. Worker 1's first send is safe to repeat and fails while a same-fence copy waits on the run lock, so worker 1 stores OutcomeUnknown. The test asserts the copy returns that stored result with one run and one send. With the re-check removed it fails with runs=2 sends=2, and an independent re-review repeated that mutation and approved this exact head.

The test knows the copy is waiting through an unexported hook that fires on each lock retry, so it needs no sleep. The rule and the test are recorded in the device custody development notes.

The two follow-ups, tamper tests for the coordinator's fence confirmation and the Seen-above rule, go into the end-to-end increment stacked on #182 rather than #178, so #178's approved head stays as it is.

@scotwells
scotwells requested review from ecv and kevwilliams November 25, 2026 15:02

@ecv ecv 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.

Approve. The hold is fixed.

Runner.Run now reads Results.Get again after acquire, and returns the stored result to a copy that waited for the lock, instead of resuming from the journal. TestACopyWaitingForTheLockReturnsTheStoredResult covers the reproduced case: the first worker's idempotent send fails and stores OutcomeUnknown, then the waiting copy must return that result, with no second run and no second send. The waiting hook is test-only and unexported.

Follow-ups from the earlier review stand: cross-site fence behaviour under a partitioned site, and the namespace-wide Secret read the site worker reuses.

@kevwilliams kevwilliams 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.

Verified Run now re-checks Results.Get after acquire, and TestACopyWaitingForTheLockReturnsTheStoredResult pins one run and one send for a copy that waited through worker 1.

@scotwells
scotwells merged commit 415a952 into feat/manual-inventory-records Nov 26, 2026
9 checks passed
@scotwells
scotwells deleted the feat/device-site-execution branch November 26, 2026 04:05
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.

3 participants