Skip to content

feat(allocation): Power a Machine's server from its powerState - #203

Merged
scotwells merged 5 commits into
feat/manual-inventory-recordsfrom
feat/device-power-customer
Nov 29, 2026
Merged

scotwells merged 5 commits into
feat/manual-inventory-recordsfrom
feat/device-power-customer

Conversation

@scotwells

@scotwells scotwells commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Related to #173. Stacked on #190.

The Metal provider can now turn a Machine's requested power into a power operation on its server, and the Machine reports the power that operation proved. powerState no longer defaults to Off: left unset, Fleet does not manage that Machine's power and creates no operation, so a freshly installed server that boots on is never forced off. No running provider asks for power yet, so no customer server changes power until one does.

Three things change on merge, in every root that ships the Metal CRD:

  • New Machines created without powerState keep it unset, and the consumer UI no longer sets it. Machines already stored with Off keep it and stay managed. The synthetic provider and the standalone runner accept unset or Off, and still refuse On.
  • The power projector reports the newer of discovery's reading and the state a power operation proved. It reports Unknown after any operation other than a recovery that finished at or after discovery's last read, such as a commissioning, until discovery reads the server again.
  • Simulator sites register a power worker, and their discovery reports each server's power and offers every action. A server whose power cannot be read keeps its last discovery.

Test plan

  • An unmanaged Machine creates no operation after an install leaves its server on, then gets ForceOff once it asks for Off; a Machine asking for On from Off gets On
  • Unset and Off claims are accepted, and On refused, by the synthetic provider and the standalone runner, and the UI creates Machines without powerState
  • A request waits through a discovery lapse with nothing sent, a hold reports Unknown and settles with fresh discovery, and a Retry repeats only the held action
  • The standalone smoke and both multi-plane runs pass with fixtures that leave power unset

A Machine generation runs at most one power operation, so power that drifts after it succeeded is not corrected until the generation changes.

🤖 Generated with Claude Code

@scotwells
scotwells requested review from ecv and kevwilliams November 25, 2026 18:44
@scotwells
scotwells force-pushed the feat/device-power-worker branch from 77770f1 to a95a293 Compare November 26, 2026 00:56
@scotwells
scotwells force-pushed the feat/device-power-customer branch from 2509ab0 to e8c60a2 Compare November 26, 2026 01:07
@scotwells
scotwells force-pushed the feat/device-power-worker branch from a95a293 to 38d73b3 Compare November 26, 2026 01:11
@scotwells
scotwells force-pushed the feat/device-power-customer branch 3 times, most recently from 27371dc to 037b93d Compare November 26, 2026 01:28
@scotwells
scotwells force-pushed the feat/device-power-worker branch from 38d73b3 to acdab22 Compare November 26, 2026 02:00
@scotwells
scotwells force-pushed the feat/device-power-customer branch from 037b93d to a1d32d7 Compare November 26, 2026 02:00
@scotwells
scotwells force-pushed the feat/device-power-worker branch from acdab22 to 7bd9f3f Compare November 28, 2026 17:41
@scotwells
scotwells force-pushed the feat/device-power-customer branch from a1d32d7 to c760beb Compare November 28, 2026 17:41
@scotwells
scotwells force-pushed the feat/device-power-worker branch from 7bd9f3f to 32d8ced Compare November 28, 2026 18:08
@scotwells
scotwells force-pushed the feat/device-power-customer branch from c760beb to ad41d35 Compare November 28, 2026 18:08
@scotwells scotwells added the multiplane-acceptance Run the multiplane acceptance suites on GitHub-hosted runners label Nov 28, 2026
@scotwells
scotwells marked this pull request as ready for review November 28, 2026 19:19
@scotwells
scotwells requested a review from a team as a code owner November 28, 2026 19:19
@scotwells
scotwells removed the request for review from a team November 28, 2026 19:19

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

Safe as written because nothing in the tree calls Allocator.Power outside tests, and its guards hold when something does: ownership is checked in the allocator, then holder and allocation again by custody. Wiring it to the Machine controller is a separate step, and its ownership inputs need a review of their own.

  • Cross-tenant: Allocator.Power refuses (ErrConflict) unless the Machine's UID, namespace and name, the allocation name, ConsumerRef, MachineRef and both UID labels all match the owner. only the Machine that owns the allocation can request its power runs eight cases, each differing in one field, and asserts that no DevicePowerOperation was created. This is the negative cross-tenant test.
  • Released allocation: any phase other than Active returns ErrReleased. Custody backs that up: the provider row admits only holder Allocation, and a pending operation is cancelled with HolderMismatch once the holder becomes Release (coordinator.go, preconditions 2 and 3).
  • Staff hold, commissioning, cleaning: the holder is then Service or Release, so the provider row never matches. A recovery hold queues provider power until staff apply a Retry, and the retry repeats only the held action (a power hold reports Unknown..., after a Retry the provider repeats the held action, and only that action).
  • Power is not forced from an unknown state: nothing is created while observed power is missing or Unknown, and Off maps to ForceOff only once On or Off is observed.

Follow-ups:

  • No test calls Power with a Releasing or Released allocation. Add one, so the first line's phase check has a guard of its own and does not rest only on custody.
  • The caller must build owner from the authenticated consumer project, not from the Machine's own fields. Power checks that owner matches the allocation and Machine, but a caller that fills owner from the same Machine would pass. Pin that when the controller wiring lands.
  • A customer's Off is a ForceOff, a hard cut with no guest shutdown. That follows #173, but customer docs should say so.

@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: customer power can force-off a freshly installed server, and never re-converges within one Machine generation.

  • powerState defaults to Off and an install ends with the server On, so once discovery reads On, Power issues ForceOff, possibly mid first boot. Nothing sets the desired state On after an install. Default to unset, or treat a completed install as satisfying On.
  • The operation name is (allocation, generation), so after it succeeds an OS shutdown or staff power-off leaves spec On and status Off forever unless the field is toggled twice. Re-issue when observed differs and no operation for this generation is pending, or document it.
  • Add tests for both.

@scotwells
scotwells force-pushed the feat/device-power-worker branch from 32d8ced to c4fc2ce Compare November 28, 2026 20:22
@scotwells
scotwells force-pushed the feat/device-power-customer branch from ad41d35 to a9e58e5 Compare November 28, 2026 20:22

@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: the rebase leaves both power issues in place, and standalone-smoke now fails in the synthetic lifecycle.

  • internal/allocation/power.go is unchanged: the default Off still force-offs a freshly installed server, and an operation named by (allocation, generation) still never re-converges after an OS or staff power-off.
  • Fix those two, and check whether the smoke failure comes from the Off default powering off a just-installed synthetic server.

@scotwells
scotwells force-pushed the feat/device-power-worker branch from c4fc2ce to 9f489d5 Compare November 28, 2026 21:00
@scotwells
scotwells force-pushed the feat/device-power-customer branch from a9e58e5 to 8fbb0b5 Compare November 28, 2026 21:00
@scotwells scotwells added multiplane-acceptance Run the multiplane acceptance suites on GitHub-hosted runners and removed multiplane-acceptance Run the multiplane acceptance suites on GitHub-hosted runners labels Nov 28, 2026
@scotwells
scotwells requested review from ecv and kevwilliams November 28, 2026 21:09

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

The simulator and fixture deltas are correct, but kevwilliams's first hold is still open at this head: nothing in the request path changed, so the default-Off hazard he named remains.

  • Agree with kevwilliams: Machine.spec.powerState defaults to Off in the Metal CRD (config/base/crd/metal.datumapis.com.yaml:262), an install ends with the server On, and internal/allocation/power.go is unchanged since his review, so once the projector observes On, Power creates a ForceOff. The doc says no running provider calls this yet, so nothing is broken today, but wiring it is the stated next step and opens a force-off of every freshly installed customer server. Default to unset (no request) or treat a completed install as satisfying On, and add a test.
  • kevwilliams's second point (no re-convergence within one generation) is addressed by documenting it, in the Power comment and the Customer power table, which his review allowed. Fine as is.
  • His smoke-failure remark: standalone-smoke passes at this head, so it is resolved. The acceptance runs are still pending.
  • Resume is correct. The reset step journals the pre-command read and send time under the operation key and fence. A resumed run, finished or not, reports the journaled values, sends nothing, and proves a restart against the journaled send time, so a server already on cannot be mistaken for "needed no command". TestAResumedRunReportsTheJournaledCommand covers unfinished power-on, unfinished restart and finished restart.
  • A failed observe can no longer report a stale On that admits something: DiscoverPower skips the write for that Device, so its inventory observedAt stops advancing and admission hits DiscoveryNotCurrent after twice the interval. Power settle also needs a read after the operation ended, which a skipped write cannot provide. The test checks both the unreadable and readable cases.

Follow-ups:

  • A failed observe also skips the IdentityMatched condition update for that Device, so a changed enrollment is not reflected until the next good read. Acceptable for a simulator.

@scotwells
scotwells force-pushed the feat/device-power-customer branch from ab6f505 to 7138838 Compare November 29, 2026 00:23
@scotwells scotwells added multiplane-acceptance Run the multiplane acceptance suites on GitHub-hosted runners and removed multiplane-acceptance Run the multiplane acceptance suites on GitHub-hosted runners labels Nov 29, 2026
@scotwells
scotwells requested a review from ecv November 29, 2026 00:30
@scotwells

Copy link
Copy Markdown
Contributor Author

The hold is resolved at 7138838 by removing the default, so a freshly installed server is never forced off.

  • powerState has no default in the Metal CRD. Unset means Fleet does not manage that Machine's power, and the provider creates no power operation whatever the server's state. Off or On still gets ForceOff or On when observed power differs.
  • The consumer UI no longer sets powerState when it creates a Machine, and shows no requested power for an unmanaged one.
  • The synthetic provider and the standalone runner accept unset or Off, and still refuse On. Fixtures that are not about power leave it unset.
  • Machines already stored with Off keep it and stay managed. A request created before powerState is cleared still runs. Both are documented in the custody guide.
  • New tests: an unmanaged Machine after an install, with its server on, creates nothing until it asks for Off, then gets ForceOff. Unset, Off and On claims go through the synthetic provider, and the standalone runner's fixture check covers the same three. The UI's create payload and power intent are covered too.

All checks are green on this head, and the multi-plane acceptance run is in progress.

@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 delta since my hold (7138838) closes it: Machine.spec.powerState no longer defaults to Off, and an unset value leaves the Machine's power unmanaged, so a freshly installed server that discovery reads as on gets no operation. A Machine that asks for Off or On still converges once observed power differs. The new envtest walks the exact case from the hold (install, server on, discovery reads it, nothing created) and then shows asking for Off yields one ForceOff. The synthetic provider and standalone runner accept unset or Off and still refuse On, and the consumer UI no longer writes Off on create.

Follow-ups:

  • Machines already stored with the old Off default keep it, so once a provider is wired, any of those whose server is on gets forced off. Clear powerState on existing Machines, or confirm none outside synthetic staging carry it, before the provider is enabled.

@scotwells
scotwells force-pushed the feat/device-power-worker branch from 9f489d5 to 4f64ad7 Compare November 29, 2026 01:57
@scotwells
scotwells force-pushed the feat/device-power-customer branch from 7138838 to ab46cfe Compare November 29, 2026 02:06
@scotwells
scotwells requested a review from ecv November 29, 2026 02:07

@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. Rebase with no change since 7138838: the power fix commit is identical.

scotwells and others added 5 commits November 28, 2026 20:16
Customer power needs a site that can run it without a BMC. The
simulator site now registers a power worker for its simulated servers.
Like the Redfish worker, it reads the server's power before it sends
anything, sends at most one reset through the journal, and reports
Succeeded only for the state it then reads. A restart is proven only
by the server's reset time moving to the command. A test-only fault
makes a server ignore resets, so the operation ends unknown. The reset
step journals the read before the command and the send time, so a run
resumed after a crash, finished or not, reports both, sends nothing
again, and proves a restart against the journaled send time.

The simulator's fixture discovery reports each server's power and
offers every power action. Fixture discovery without an observer, as
synthetic staging runs it, still reports power off and no reset types.
A server the observer cannot read keeps its last discovery, so a running
server is never reported off.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Metal provider asks the allocator to apply a Machine's power
intent. On is the action On and Off is ForceOff, named from the
allocation and the Machine generation, so a refused request is not
created again until the generation changes.

A request is due when powerState differs from the Machine's observed
power, or when this allocation's request for another action has not
run yet, so the newer request replaces it. Observed power must be On
or Off: every Machine defaults to Off, so power not yet observed, or
Unknown, asks for nothing.

During a power hold, nothing is created until staff apply a Retry;
then the provider repeats the held operation under the foundation's
retry name, and only while powerState still maps to the held action.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Discovery reads each server about hourly, so after a power change it
reports the old state for a while. The power projector, still the only
writer of Machine power, now reports the newer of discovery's state
and the state custody's last succeeded power operation proved, a tie
going to the operation.

When any other operation except a recovery finished at or after
discovery's read, power is Unknown until discovery reads it again,
because that operation may have changed it. Power stays Unknown during
any hold.

The standalone smoke commissions the server just before it allocates,
so it now waits for discovery to read the server after commissioning
before it checks the Machine's power.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The customer power flow runs against a real API server with the
coordinator, delivery and the simulator site behind its site API:
- power under an allocation, and unknown after a later installation;
- a change waiting behind an installation;
- a newer request replacing a pending one, including an intent that
  returns to the observed state;
- a hold reporting Unknown through release and settling with fresh
  discovery;
- a retry that repeats only the held action;
- a request waiting through a discovery lapse, sending nothing, and
  running once discovery returns.

The allocator gets a capacity evaluator that offers every fixture
server, since these tests cover power, not commissioning.

The custody guide records customer power and two remaining gaps.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Machine.spec.powerState defaulted to Off, and an install leaves the
server on. Once a provider asked for power, the first discovery read
after an install would have forced every freshly installed server off.

powerState now has no default. Unset means Fleet does not manage the
Machine's power: no power operation is created, whatever the server's
state. A Machine that asks for Off or On still gets ForceOff or On when
its observed power differs. A request created before powerState was
cleared still runs, and Machines already stored with Off keep it.

The synthetic provider and the standalone runner accept a claim whose
power is unset or Off, and still refuse On. Fixtures that are not about
power leave it unset, so they take that path. The consumer UI no longer
creates Machines with power Off, and shows no requested power for an
unmanaged Machine.

Tests cover an unmanaged Machine after an install with its server on,
which creates nothing until it asks for Off and then gets ForceOff;
unset, Off and On claims through the synthetic provider; the standalone
runner's fixture check; and the UI's create payload and power intent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scotwells
scotwells force-pushed the feat/device-power-worker branch from 4f64ad7 to 66a9d31 Compare November 29, 2026 02:26
@scotwells
scotwells force-pushed the feat/device-power-customer branch from ab46cfe to 0205906 Compare November 29, 2026 02:26
@scotwells scotwells added multiplane-acceptance Run the multiplane acceptance suites on GitHub-hosted runners and removed multiplane-acceptance Run the multiplane acceptance suites on GitHub-hosted runners labels Nov 29, 2026
@scotwells
scotwells requested a review from ecv November 29, 2026 02:40

@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. Rebase onto the base branch after #252 merged; this PR's own commits are unchanged.

Base automatically changed from feat/device-power-worker to feat/manual-inventory-records November 29, 2026 03:32
@scotwells
scotwells merged commit c399a45 into feat/manual-inventory-records Nov 29, 2026
22 checks passed
@scotwells
scotwells deleted the feat/device-power-customer branch November 29, 2026 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

multiplane-acceptance Run the multiplane acceptance suites on GitHub-hosted runners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants