Skip to content

fix: Use states to manage reboot operation to avoid race condition.#3779

Merged
abvarshney-nv merged 1 commit into
NVIDIA:mainfrom
abvarshney-nv:bug_6482334
Jul 21, 2026
Merged

fix: Use states to manage reboot operation to avoid race condition.#3779
abvarshney-nv merged 1 commit into
NVIDIA:mainfrom
abvarshney-nv:bug_6482334

Conversation

@abvarshney-nv

Copy link
Copy Markdown
Contributor

Three fixes to the DPF-requested power cycle:

  1. No delay between power commands and status check:
    ForceOff and On were issued and their result checked in the same tick, giving the BMC no time to act. A delay (reachability_params.power_down_wait, consistent with ReprovisionState::PowerDown) is now enforced after each command before reading back the power state.

  2. No retry when power state does not change:
    If the host failed to respond to ForceOff or On, the handler would wait indefinitely with no recovery. The handler now retries the command up to 3 times before stopping and waiting for manual intervention.

  3. Only the current DPU's state was advanced on power off/on:
    A host power cycle affects all DPUs simultaneously, but the handler was calling set_one_dpu_dpf_state instead of transition_all_dpus_to_dpf_state. With multiple DPUs, the second DPU would enter the same reboot branch independently and issue another ForceOff/On cycle against the host, causing repeated unintended reboots. All DPUs now advance together when a host power transition completes.

Related issues

Type of Change

  • Add - New feature or capability
  • Change - Changes in existing functionality
  • Fix - Bug fixes
  • Remove - Removed features or deprecated functionality
  • Internal - Internal changes (refactoring, tests, docs, etc.)

Breaking Changes

  • This PR contains breaking changes

Testing

  • Unit tests added/updated
  • Integration tests added/updated
  • Manual testing performed
  • No testing required (docs, internal refactor, etc.)

Additional Notes

@abvarshney-nv
abvarshney-nv requested a review from a team as a code owner July 21, 2026 16:51
@coderabbitai

coderabbitai Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 1a293b67-982d-4569-9001-f766b999e5c0

📥 Commits

Reviewing files that changed from the base of the PR and between 88a7443 and 365f106.

📒 Files selected for processing (4)
  • crates/api-model/src/machine/mod.rs
  • crates/machine-controller/src/handler.rs
  • crates/machine-controller/src/handler/dpf.rs
  • crates/machine-controller/src/handler/helpers.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • crates/machine-controller/src/handler/helpers.rs
  • crates/machine-controller/src/handler.rs
  • crates/machine-controller/src/handler/dpf.rs

Summary by CodeRabbit

  • New Features
    • Added a step-by-step DPF reboot workflow with explicit host power off/on control.
    • Introduced a configurable wait during host power transitions to improve timing reliability.
  • Bug Fixes
    • Improved reboot handling by persisting progress with a bounded retry counter across attempts.
    • If the host doesn’t reach the expected power state within the retry limit, the workflow now stops for manual intervention.
    • Reboot-required behavior now consistently routes DPUs into the correct reboot sequence state.

Walkthrough

The DPF state machine now persists reboot operations and retry counts, performs delayed and bounded host power transitions, reports reboot completion, and integrates the new flow into reprovisioning and DPU initialization.

Changes

DPF reboot handling

Layer / File(s) Summary
Persisted reboot state contract
crates/api-model/src/machine/mod.rs
Extends DpfState with persisted HandleReboot { op, retry_count } data using PerformPowerOperation.
Reboot transition handler
crates/machine-controller/src/handler/dpf.rs, crates/machine-controller/src/handler.rs
Adds delayed power-control handling, bounded retries, reboot completion reporting, state dispatch, and shared wait-helper visibility.
Workflow integration
crates/machine-controller/src/handler.rs, crates/machine-controller/src/handler/helpers.rs
Passes power_down_wait through reprovision and initialization flows and routes HandleReboot through the all-DPU transition path.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Workflow
  participant DpfHandler
  participant Redfish
  participant DpfSdk
  Workflow->>DpfHandler: Dispatch HandleReboot(op, retry_count)
  DpfHandler->>DpfHandler: Wait for power_down_wait
  DpfHandler->>Redfish: Issue ForceOff or On command
  Redfish-->>DpfHandler: Return power state
  DpfHandler->>DpfSdk: Report reboot_complete when powered On
  DpfHandler-->>Workflow: Persist next DPF state
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately reflects the state-machine reboot handling change and the race-condition fix.
Description check ✅ Passed The description matches the implemented DPF power-cycle fixes and aligns with the stated objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
crates/api-model/src/machine/mod.rs (1)

1764-1773: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Doc comments hardcode "30 s" for a configurable delay.

The Off/On variant docs and the HandleReboot doc all state a fixed "30 s delay," but the actual value is reachability_params.power_down_wait (a configured chrono::Duration threaded into handle_dpf_state/handle_dpf_handle_reboot). If the default changes or an environment overrides it, these docs on a persisted enum become misleading.

📝 Suggested doc wording
 pub enum DpfRebootOp {
-    /// ForceOff issued; waiting for `power_state == Off` then 30 s delay.
+    /// ForceOff issued; waiting for `power_state == Off` then the configured
+    /// `power_down_wait` delay.
     Off,
-    /// On issued; waiting for `power_state == On` then 30 s delay.
+    /// On issued; waiting for `power_state == On` then the configured
+    /// `power_down_wait` delay.
     On,
 }

Also applies to: 1791-1797

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/api-model/src/machine/mod.rs` around lines 1764 - 1773, Update the
documentation for DpfRebootOp::Off, DpfRebootOp::On, and HandleReboot to
describe a configured power-down wait from reachability_params.power_down_wait
rather than hardcoding “30 s”; keep the docs accurate for overridden or changed
durations without altering runtime behavior.
crates/machine-controller/src/handler/dpf.rs (1)

309-316: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Stale doc: HandleReboot { On, now } doesn't match the implementation.

The transition description mentions a now field, but HandleReboot only has op and retry_count — the successful Off → On transition actually sets retry_count: 0 (line 350-353). This looks like it wasn't updated when the design moved from timestamp-based tracking to retry-count tracking (per the library summary).

📝 Suggested fix
 /// Transitions:
 /// - `Off`: wait for `power_state == Off` + 30 s → issue On →
-///   `HandleReboot { On, now }`
+///   `HandleReboot { op: On, retry_count: 0 }`
 /// - `On`:  wait for `power_state == On`  + 30 s → `reboot_complete` →
 ///   `WaitingForReady`
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/machine-controller/src/handler/dpf.rs` around lines 309 - 316, Update
the `HandleReboot` transition documentation to match the current `DpfState`
fields and implementation: describe the successful `Off → On` transition as
`HandleReboot { op: On, retry_count: 0 }` instead of referencing `now`, while
preserving the documented timing and subsequent `On` transition.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/machine-controller/src/handler/dpf.rs`:
- Around line 372-380: Update both retry-exhaustion branches in the power-down
handler to return StateHandlerError::ManualInterventionRequired instead of
StateHandlerOutcome::wait, preserving the existing manual-intervention context.
Change both tracing::error! calls to emit MAX_RETRIES as a structured tracing
attribute rather than interpolating it into the message, while retaining the
host identifier and logfmt-style fields.

---

Nitpick comments:
In `@crates/api-model/src/machine/mod.rs`:
- Around line 1764-1773: Update the documentation for DpfRebootOp::Off,
DpfRebootOp::On, and HandleReboot to describe a configured power-down wait from
reachability_params.power_down_wait rather than hardcoding “30 s”; keep the docs
accurate for overridden or changed durations without altering runtime behavior.

In `@crates/machine-controller/src/handler/dpf.rs`:
- Around line 309-316: Update the `HandleReboot` transition documentation to
match the current `DpfState` fields and implementation: describe the successful
`Off → On` transition as `HandleReboot { op: On, retry_count: 0 }` instead of
referencing `now`, while preserving the documented timing and subsequent `On`
transition.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 2a1b5ebd-40e2-404c-b971-48f107276bda

📥 Commits

Reviewing files that changed from the base of the PR and between a239602 and f0f0ca2.

📒 Files selected for processing (4)
  • crates/api-model/src/machine/mod.rs
  • crates/machine-controller/src/handler.rs
  • crates/machine-controller/src/handler/dpf.rs
  • crates/machine-controller/src/handler/helpers.rs

Comment thread crates/machine-controller/src/handler/dpf.rs

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/api-model/src/machine/mod.rs`:
- Around line 1781-1782: Update the documentation comment immediately above
handle_dpf_handle_reboot to describe the delay as the configured
power-transition delay derived from reachability_params.power_down_wait, rather
than referring to a fixed 30 seconds. Preserve the explanation that
state.version.timestamp() records when the step started.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: a628a9be-5caa-4a09-8500-5c7a7011d686

📥 Commits

Reviewing files that changed from the base of the PR and between f0f0ca2 and 88a7443.

📒 Files selected for processing (4)
  • crates/api-model/src/machine/mod.rs
  • crates/machine-controller/src/handler.rs
  • crates/machine-controller/src/handler/dpf.rs
  • crates/machine-controller/src/handler/helpers.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • crates/machine-controller/src/handler/helpers.rs
  • crates/machine-controller/src/handler.rs
  • crates/machine-controller/src/handler/dpf.rs

Comment thread crates/api-model/src/machine/mod.rs Outdated
@abvarshney-nv
abvarshney-nv merged commit 231c006 into NVIDIA:main Jul 21, 2026
61 checks passed
@abvarshney-nv
abvarshney-nv deleted the bug_6482334 branch July 21, 2026 18:44
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