Skip to content

nvlink: use switch state machine to rotate certs#3249

Open
tmcroberts97 wants to merge 5 commits into
NVIDIA:mainfrom
tmcroberts97:nvlink/use-switch-state-machine
Open

nvlink: use switch state machine to rotate certs#3249
tmcroberts97 wants to merge 5 commits into
NVIDIA:mainfrom
tmcroberts97:nvlink/use-switch-state-machine

Conversation

@tmcroberts97

Copy link
Copy Markdown
Contributor

Instead of rotating the certs via RMS directly in the switch cert monitor, exercise the switch state machine.

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

Instead of rotating the certs via RMS directly in the switch cert
monitor, exercise the switch state machine.

Signed-off-by: Thomas McRoberts <tmcroberts@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 8, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Summary by CodeRabbit

  • New Features

    • Routed switch certificate reconfiguration through the switch-maintenance state-controller workflow.
    • Routed on-demand rack maintenance scheduling through the rack-maintenance state-controller workflow.
  • Bug Fixes

    • Certificate monitoring now reports only pending/error/skipped outcomes (removed applied-update accounting from metrics and iteration reporting).
    • Improved rack maintenance scheduling to be atomic and idempotent under contention, including correct “busy/deferred” handling.
  • Tests

    • Updated certificate-monitoring tests to validate behavior via database state and rack maintenance requests instead of direct RMS configure calls.

Walkthrough

NvLinkManager and SwitchCertificateMonitor now use ComponentManager state-controller maintenance requests instead of RMS certificate jobs. Rack maintenance scheduling is transactional and idempotent, API handlers delegate to shared scheduling paths, and tests verify persisted maintenance state.

Changes

Switch certificate apply migration

Layer / File(s) Summary
Rack maintenance scheduling
crates/component-manager/src/component_manager.rs, crates/api-db/src/rack.rs, crates/api-model/src/rack.rs
Adds locked, transactional rack-maintenance scheduling with eligibility, idempotency, credential handling, and contention tests.
Switch maintenance API
crates/component-manager/src/component_manager.rs, crates/api-core/src/handlers/component_manager.rs
Adds per-switch state-controller maintenance requests and routes switch power-control and certificate-maintenance handlers through them.
Rack handler integration
crates/api-core/src/handlers/rack.rs
Delegates on-demand rack maintenance to the shared scheduler and maps scheduling outcomes to API statuses.
NvLinkManager and monitor wiring
crates/nvlink-manager/src/*, crates/api-core/src/setup.rs, crates/nvlink-manager/Cargo.toml
Removes RMS, credential, and rack-profile dependencies and routes certificate reconciliation through rack state-controller requests.
Fixtures and behavioral assertions
crates/api-core/src/tests/common/api_fixtures/mod.rs, crates/api-core/src/tests/nvl_instance.rs
Updates monitor construction and verifies database maintenance state without RMS certificate submissions.

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

Sequence Diagram(s)

sequenceDiagram
  participant NvLinkManager
  participant SwitchCertificateMonitor
  participant ComponentManager
  participant Database

  NvLinkManager->>SwitchCertificateMonitor: start(..., component_manager)
  SwitchCertificateMonitor->>ComponentManager: request_rack_maintenance_via_state_controller(ConfigureNmxCluster)
  ComponentManager->>Database: lock rack and persist maintenance request
  Database-->>ComponentManager: scheduling outcome
  ComponentManager-->>SwitchCertificateMonitor: Scheduled or AlreadyPending
  SwitchCertificateMonitor-->>NvLinkManager: Pending status
Loading

Possibly related PRs

Suggested labels: rack lifecycle

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 40.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: rotating NVLink switch certificates through the switch state machine instead of RMS.
Description check ✅ Passed The description is clearly aligned with the changeset and correctly describes the switch-state-machine-based certificate rotation.
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.

@tmcroberts97

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@tmcroberts97 tmcroberts97 marked this pull request as ready for review July 8, 2026 09:00
@tmcroberts97 tmcroberts97 requested a review from a team as a code owner July 8, 2026 09:00

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

🧹 Nitpick comments (1)
crates/nvlink-manager/src/switch_cert_monitor.rs (1)

820-856: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Optional: a transaction around a single statement adds no atomicity benefit here.

set_switch_maintenance_requested is a single UPDATE; wrapping it in an explicit begin/commit (with only begin made cancellable) is heavier than necessary. Since the helper accepts a &mut PgConnection, you could acquire a pooled connection directly and drop the transaction ceremony. Non-blocking.

🤖 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/nvlink-manager/src/switch_cert_monitor.rs` around lines 820 - 856, The
transaction wrapper in
request_certificate_reconfiguration_with_switch_state_controller is unnecessary
for a single set_switch_maintenance_requested update and only adds
overhead/cancellation asymmetry. Replace the explicit
self.db_pool.begin()/txn.commit() flow with a pooled connection path that passes
a mutable connection directly into db::switch::set_switch_maintenance_requested,
while keeping the same error handling and tracing::info context.
🤖 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.

Nitpick comments:
In `@crates/nvlink-manager/src/switch_cert_monitor.rs`:
- Around line 820-856: The transaction wrapper in
request_certificate_reconfiguration_with_switch_state_controller is unnecessary
for a single set_switch_maintenance_requested update and only adds
overhead/cancellation asymmetry. Replace the explicit
self.db_pool.begin()/txn.commit() flow with a pooled connection path that passes
a mutable connection directly into db::switch::set_switch_maintenance_requested,
while keeping the same error handling and tracing::info context.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 899df5a8-0215-40ee-9f44-4a6b455d24a9

📥 Commits

Reviewing files that changed from the base of the PR and between 2c015f1 and 6872e2d.

📒 Files selected for processing (5)
  • crates/api-core/src/setup.rs
  • crates/api-core/src/tests/common/api_fixtures/mod.rs
  • crates/api-core/src/tests/nvl_instance.rs
  • crates/nvlink-manager/src/lib.rs
  • crates/nvlink-manager/src/switch_cert_monitor.rs
💤 Files with no reviewable changes (3)
  • crates/api-core/src/setup.rs
  • crates/api-core/src/tests/common/api_fixtures/mod.rs
  • crates/nvlink-manager/src/lib.rs

@vinodchitraliNVIDIA vinodchitraliNVIDIA self-requested a review July 8, 2026 09:14
Comment thread crates/nvlink-manager/src/switch_cert_monitor.rs Outdated
Comment thread crates/nvlink-manager/src/switch_cert_monitor.rs Outdated
@github-actions

github-actions Bot commented Jul 8, 2026

Copy link
Copy Markdown

🔍 Container Scan Summary

Service Total Critical High Medium Low Other
boot-artifacts-aarch64 3 0 0 3 0 0
boot-artifacts-x86_64 3 0 0 3 0 0
forge-admin-cli-x86_64 259 13 30 78 7 131
machine-validation-runner 807 40 234 288 36 209
machine_validation 807 40 234 288 36 209
machine_validation-aarch64 807 40 234 288 36 209
nvmetal-carbide 807 40 234 288 36 209
TOTAL 3493 173 966 1236 151 967

Per-CVE detail lives in the per-service grype-* artifacts (JSON + SARIF). Severity counts only — no CVE IDs published here.

..to configure NVSwitch certs.

Signed-off-by: Thomas McRoberts <tmcroberts@nvidia.com>

@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/component-manager/src/component_manager.rs`:
- Around line 102-106: The maintenance request path in component_manager::update
should reject a new request when switch_maintenance_requested is already set,
since set_switch_maintenance_requested currently overwrites the single pending
DB slot. Add an explicit “already pending” guard before calling
db::switch::set_switch_maintenance_requested, returning an appropriate
ComponentManagerError if a PowerOn, PowerOff, Reset, or ReconfigureCertificate
request is already queued; alternatively, change the switch maintenance model to
a queue only if multiple outstanding requests are intended.
🪄 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: b10a4146-2dcb-4804-9f2e-e802cd8ede13

📥 Commits

Reviewing files that changed from the base of the PR and between 6872e2d and ef6ad2e.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (7)
  • crates/api-core/src/handlers/component_manager.rs
  • crates/api-core/src/setup.rs
  • crates/api-core/src/tests/common/api_fixtures/mod.rs
  • crates/component-manager/src/component_manager.rs
  • crates/nvlink-manager/Cargo.toml
  • crates/nvlink-manager/src/lib.rs
  • crates/nvlink-manager/src/switch_cert_monitor.rs
🚧 Files skipped from review as they are similar to previous changes (4)
  • crates/api-core/src/tests/common/api_fixtures/mod.rs
  • crates/api-core/src/setup.rs
  • crates/nvlink-manager/src/lib.rs
  • crates/nvlink-manager/src/switch_cert_monitor.rs

Comment thread crates/component-manager/src/component_manager.rs
...instead of using the configure_switch-certificate flow. Also
introduce a rack maintenance scheduler to ensure atomic and idempotnt
rack maintenance.

Signed-off-by: Thomas McRoberts <tmcroberts@nvidia.com>

@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: 2

🤖 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-db/src/rack.rs`:
- Around line 68-78: Update find_by_id_for_update to filter out soft-deleted
racks by adding a deleted IS NULL condition to its SQL query, while preserving
the existing ID lookup and row-locking behavior.

In `@crates/component-manager/src/component_manager.rs`:
- Around line 150-168: Move the credential_manager.set_credentials call out of
the transaction and execute it only after the locked transaction commits with
Scheduled, preserving the existing single-writer check performed by
find_by_id_for_update. Ensure failures use an explicit post-commit recovery
strategy, such as clearing maintenance_requested in a follow-up transaction or
the established retry mechanism, without holding the database lock across the
external await.
🪄 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: 4062d56d-0248-4ed7-bacf-57dcc9b1fb16

📥 Commits

Reviewing files that changed from the base of the PR and between ef6ad2e and d92c305.

📒 Files selected for processing (8)
  • crates/api-core/src/handlers/component_manager.rs
  • crates/api-core/src/handlers/rack.rs
  • crates/api-core/src/tests/nvl_instance.rs
  • crates/api-db/src/rack.rs
  • crates/api-model/src/rack.rs
  • crates/component-manager/Cargo.toml
  • crates/component-manager/src/component_manager.rs
  • crates/nvlink-manager/src/switch_cert_monitor.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • crates/api-core/src/handlers/component_manager.rs

Comment thread crates/api-db/src/rack.rs Outdated
Comment thread crates/component-manager/src/component_manager.rs Outdated
Comment thread crates/api-db/src/rack.rs Outdated
Comment thread crates/api-core/src/handlers/rack.rs
Comment thread crates/component-manager/src/component_manager.rs
..after vault write failure. If the writing of the RMS token to vault
fails, attempt to cancel the just submitted maintenance request to leave
the rack in a cleaner state.

Signed-off-by: Thomas McRoberts <tmcroberts@nvidia.com>
Signed-off-by: Thomas McRoberts <tmcroberts@nvidia.com>

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

🧹 Nitpick comments (1)
crates/api-db/src/rack.rs (1)

61-69: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Use query_scalar for the single-column existence check.

This query selects only id and discards its value; query_scalar::<_, RackId>(query) with fetch_optional expresses that contract more directly and avoids the single-element tuple mapping.

Proposed refactor
-    sqlx::query_as::<_, (RackId,)>(query)
+    sqlx::query_scalar::<_, RackId>(query)
         .bind(rack_id)
         .fetch_optional(txn)
🤖 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-db/src/rack.rs` around lines 61 - 69, Update lock_for_update to
use sqlx::query_scalar::<_, RackId>(query) for the single-column id lookup,
retaining the existing bind, fetch_optional, error mapping, and row-is-present
boolean result without tuple mapping.

Source: Learnings

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

Nitpick comments:
In `@crates/api-db/src/rack.rs`:
- Around line 61-69: Update lock_for_update to use sqlx::query_scalar::<_,
RackId>(query) for the single-column id lookup, retaining the existing bind,
fetch_optional, error mapping, and row-is-present boolean result without tuple
mapping.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: ef32ae0e-c49e-486e-9b90-f9008f44f63b

📥 Commits

Reviewing files that changed from the base of the PR and between 1b9076e and b597ba4.

📒 Files selected for processing (4)
  • crates/api-core/src/handlers/rack.rs
  • crates/api-db/src/rack.rs
  • crates/component-manager/src/component_manager.rs
  • crates/nvlink-manager/src/switch_cert_monitor.rs
🚧 Files skipped from review as they are similar to previous changes (3)
  • crates/api-core/src/handlers/rack.rs
  • crates/component-manager/src/component_manager.rs
  • crates/nvlink-manager/src/switch_cert_monitor.rs

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.

2 participants