Skip to content

feat: Add the Device custody and operations foundation - #178

Merged
scotwells merged 19 commits into
feat/manual-inventory-recordsfrom
feat/device-custody-foundation
Nov 25, 2026
Merged

scotwells merged 19 commits into
feat/manual-inventory-recordsfrom
feat/device-custody-foundation

Conversation

@scotwells

Copy link
Copy Markdown
Contributor

Summary

Every physical action on a server will go through one custody record per Device, as the Device custody and operations proposal describes.

This change adds that record, the shared operation envelope, and the coordinator that admits operations, fences them, holds unproven outcomes, and rebuilds lost custody. It also adds the webhook that records who created each operation, and the seams a new kind such as power plugs into.

Nothing is wired into a deployment, the manager, or staging yet, and the existing lifecycle is unchanged.

Decisions

  • An allocation's private facts will live on its MachineAllocation, which only Fleet writes. Increment C implements this.
  • A recovery skips the current-discovery and shared-key checks only to retire a server or to resolve unverified custody. Settling and retrying still need current discovery.
  • A recovery that no site confirms before its deadline ends Failed, and the hold stays.
  • Queued provider and release operations wait while a hold they cannot settle exists, because their names are deterministic. The operation that settles the hold goes first and is never replaced.
  • When a retried operation also ends unknown, its hold keeps the original name and Retry count, so the next retry is named on from the original.
  • Refusal reasons use the names in the proposal's table, and each kind declares its own.
  • The webhook will be served by the existing registration server on its own path when the cutover wires it.

Decisions for a person

  • Whether a recovery needs a second person to confirm it. It does not for now.
  • The interim source of the Prepared and Healthy capacity conditions, before the cutover. Until it is decided, the capacity projector stays unwired.
  • The sealed store for bootstrap payloads. Bootstrap stays refused until one is chosen.

Test plan

  • Every admission rule, race, crash point, rebuild conflict, recovery decision and extension seam passes against a real API server with the race detector
  • The creator webhook stores the original caller and refuses any other creator
  • Both local end-to-end runs pass, and the Milo provider project API refuses every write the custody rules forbid

Related to #174

🤖 Generated with Claude Code

scotwells and others added 16 commits November 24, 2026 18:09
Add DeviceCustody and the DeviceInstallation, DeviceWipe and
DeviceRecovery operation kinds proposed in #174 at 3907eec. Every
operation shares one envelope and one status. CEL keeps an operation's
spec immutable, moves its phases forward only, keeps the custody fence
from decreasing and keeps Retired terminal.

The device-operations component also carries the ProtectedResources,
the coordinator, requester, viewer and recovery operator roles, and the
creator webhook configuration. No root includes it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the coordinator, the only writer of custody and of operation status.
It admits each operation with one conditional custody update, queues
provider and release work, refuses staff work it cannot run now, and
expires staff work after five minutes. It accepts only results that
carry the active fence, moves unknown outcomes into a recovery hold,
applies DeviceRecovery decisions after the sites confirm the raised
fence, and rebuilds missing custody as Unverified.

Kinds plug in through a registry entry and rows of the admission table.
Test-only kinds prove each seam, against a real API server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add the validating webhook that Milo's root API server calls. It admits
a create only when spec.creator is the authenticated caller, and an
update only when the creator is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Mark Increment A implemented and inert, record its decisions and the
points that need a person, and describe how to add an operation kind.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A DeviceRecovery with Settle or Retry now needs current discovery and a
unique BMC key, like any other operation. Settling a power hold needs
fresh discovery evidence of the power state. Retire and Resolve still
skip both checks, so a server with an unreachable BMC can be retired.
The registry refuses the skip for any kind that can reach the server.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The allocation's non-secret facts live on its MachineAllocation, which
only Fleet writes. Increment C can start after B.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rebuild now holds an operation that ended OutcomeUnknown unless a later
success settled it, ends a held unfinished operation OutcomeUnknown, and
never admits a held operation again. With several, the newest is held
and custody stays Unverified for a Resolve.

Admission decides only on custody that did not change while it listed
operations, raises the fence above every fence a site reports, and
confirms a recovery only once the sites report that older workers
stopped. Resolve must agree with the live MachineAllocations. Queued
operations wait under a hold they cannot settle. Retention keeps a
succeeded retirement until inventory retires the Device. The creator
webhook reads keys case-sensitively.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Separate the fence a fake site has seen from the fence for which it
confirmed older workers stopped, and test that admission rises above
the first while a recovery waits for the second. Test on its own that a
held operation is never a candidate for admission.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Kind checks now see the Device object the snapshot records, the injected
clock and the discovery interval, and the coordinator decides again if
the Device changes before the custody update. Kinds can add bounded
fields to the snapshot, declare their refusal reasons with where each is
raised, and declare whether a Retry applies to their holds. A hold keeps
its deadline and admission snapshot for the settle hook.

A refusal with an undeclared reason is recorded as UndeclaredReason.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Both local end-to-end runs now install the custody CRDs into the
provider project, require its API to refuse eight writes the CEL rules
forbid, and remove the CRDs again. Milo ignores admission policies
stored in a project, so the rules need this proof.

Record each extension-point decision for the power and commissioning
kinds.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Prove that a newer pending operation replaces only its own kind when two
superseding kinds share an allocation, that Retry needs the held kind to
be Retryable, and that a rebuilt hold keeps the deadline and snapshot
its operation's status recorded. A held kind's reasons are accepted only
through its settle hook.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rename the shared admission reasons to the names #174 now gives them:
CustodyUnverified, CreatorNotPermitted, OperationInProgress and
DeviceIdentityMismatch, which also covers discovery that is not
current. A hold now counts the Retry decisions applied to it, so a kind
such as power can name its next operation from a retry count. Pin #174
at abb1f88 throughout.

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


An operation created after a Retry is now named from the held operation:
its name, -retry- and the Retry count custody records with the hold. It
waits until the Retry is applied, and a retry that itself ends unknown
keeps the original name and count. Rebuild reads that lineage back from
the names.

Pending replacement never cancels an operation that settles a hold, and
operations waiting for the hold no longer hold back the one that settles
it. A row can admit from a holder only to settle a hold of its kind, as
the staff power row needs. Pin #174 at 23c583f.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
#174 now says what a recovery hold carries and when a Retry is
accepted. The implementation already matches. Record how the hold's
retry count and its unused-Retry marker map to that text, and pin the
new head.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Cover the refusals of a row that admits from Service only under a hold
of its kind: with no hold, and under a hold the kind does not settle.
Both end Failed with HolderMismatch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scotwells
scotwells requested a review from ecv November 25, 2026 03:29
@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.

Verified only the coordinator role writes custody or operation status, the creator webhook rejects spoofed callers, and envtest refuses every custody CEL violation.

scotwells and others added 3 commits November 24, 2026 23:32
The power kind, built on this foundation, found six gaps. Each now has a
subtest in TestRowsAndReplacement that fails when its fix is removed.

- Only an operation that passes the creator, authority, holder and
  allocation checks on a queue row can replace another, so a request
  refused its permission check no longer cancels a customer's pending
  operation.
- Staff rows never queue, so staff requests never replace one another.
- A row can set its own naming rule, such as generated names for staff
  power and generation-based names for provider power.
- A kind's own checks run before the shared identity and key checks, so
  its more specific reason is the one reported.
- An operation named for a Retry waits for it, a staff one included, and
  does not expire while it waits.
- The evidence validator receives the operation, and EvidenceRequired
  makes a success without evidence prove nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Reading the operation for its evidence returned a plain error for a
result naming an unregistered kind, so the site would retry it forever.
Read the operation only when there is evidence to check for a
registered kind, and let the stale path reject the rest.

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

Copy link
Copy Markdown
Contributor Author

The power kind, built on this branch in #179, found six gaps in the admission seams. Each now has a subtest that fails when its fix is removed, and the head is 9cf6d32.

  • Only an operation that passes the creator, authority, holder and allocation checks can replace another. Before, a staff request naming a customer's allocation was refused, but only after it had cancelled the customer's pending operation.
  • Only rows that queue can replace, and staff rows never queue, so a newer staff request no longer cancels an older undecided one.
  • A row can set its own naming rule, so power can use generated names for staff requests and generation-based names for provider requests.
  • A kind's own checks run before the shared identity and key checks, so a more specific reason such as SystemUUIDNotRecorded is the one reported.
  • An operation named for a Retry waits in Pending until that Retry is applied, staff ones included, and does not expire meanwhile. Before, a staff retry created early failed and used up its name, leaving the server stuck.
  • The evidence validator receives the operation, so it can require reset proof for a restart. A new per-kind flag makes a success without evidence prove nothing.

A follow-up commit fixes a regression the rereview found: a result naming an unregistered kind is rejected as stale again, instead of failing so the site retries it forever.

The rereviewer approved this exact head. #180 is rebased onto it.

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

Custody foundation looks sound on the fencing and admission paths I read; the coordinator raises the fence above every fence a site has seen (spec.Fence = max(spec.Fence, seen) + 1) and confirms stops before a recovery applies. CI is green (validate, standalone-smoke, image and bundle builds), and custody tests pass locally at 9cf6d32.

  • The enforcement of the fence at the BMC action point lives in #180's site Step, not here, so this PR's safety rests on that stack member; #180 currently has an open hold on a same-fence redelivery.
  • Stack: base is feat/manual-inventory-records, and #180 is rebased onto this head (9cf6d32) with only its own delta.

Follow-ups:

  • I read internal/custody/coordinator.go for fence handling and did not read the 9k lines of CRDs, protected-resource policies, generated code or the tenancy/role wiring in config/components/admission/policies.yaml in depth. A tenant-cannot-trigger-operations test on hardware they do not hold should be confirmed before the API is exposed.
  • Tamper-test the fence confirmation (siteFence) and the Seen-above rule in the coordinator tests; I only tampered the site-side guards in #180.

@scotwells
scotwells merged commit 782758b into feat/manual-inventory-records Nov 25, 2026
9 checks passed
@scotwells

Copy link
Copy Markdown
Contributor Author

@ecv the tamper tests you suggested for the coordinator's fence confirmation and the rule that admission raises the fence above every fence a site has seen go into the end-to-end failure-scenarios increment, stacked on #182. A commit here would move this PR's approved head and force a rebase of #180 and #182, so this PR stays at 9cf6d32.

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