Skip to content

fix(flow): preserve expected component descriptions - #4713

Open
pbreton wants to merge 2 commits into
NVIDIA:mainfrom
pbreton:codex/issue-4353-preserve-expected-descriptions
Open

fix(flow): preserve expected component descriptions#4713
pbreton wants to merge 2 commits into
NVIDIA:mainfrom
pbreton:codex/issue-4353-preserve-expected-descriptions

Conversation

@pbreton

@pbreton pbreton commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Preserve Core descriptions for ExpectedMachine, ExpectedSwitch, and ExpectedPowerShelf when Flow mirrors expected inventory.

The Core-owned value is stored under the reserved expected_description key so expected reconciliation can create, update, or clear it without replacing runtime- or operator-owned description entries.

Fixes #4353.

Root cause

The Core API detail models already exposed descriptions, but the Flow normalization and persistence paths omitted them. Consequently, new mirrored components lost their descriptions and existing components never received description changes.

The description column is also shared with runtime metadata such as the NVSwitch nvos_ip, so replacing the entire JSON map would have caused data loss.

Changes

  • Carry descriptions through normalization for ExpectedMachine, ExpectedSwitch, and ExpectedPowerShelf.
  • Store the expected description under the reserved expected_description key.
  • Merge updates into the existing description map, preserving runtime and operator keys.
  • Remove only expected_description when Core clears the value.
  • Add unit coverage for conversion, change detection, merging, and clearing.
  • Add PostgreSQL-backed insert, change, clear, and merge coverage for every component type.

Validation

  • make test-flow
  • go vet ./flow/internal/scheduler/jobs/inventorysync
  • git diff --check

The full Flow suite was rerun after rebasing onto current upstream main.

Note

This is an attempt at fully automated issue resolution using Codex.

@copy-pr-bot

copy-pr-bot Bot commented Aug 7, 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 Aug 7, 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: 6c9531bc-bfa5-469d-9388-4bf75ca0f756

📥 Commits

Reviewing files that changed from the base of the PR and between 0838a98 and d4ef351.

📒 Files selected for processing (3)
  • rest-api/flow/internal/scheduler/jobs/inventorysync/expected_mirror_component.go
  • rest-api/flow/internal/scheduler/jobs/inventorysync/expected_mirror_component_test.go
  • rest-api/flow/internal/scheduler/jobs/inventorysync/expected_mirror_db_test.go

Summary by CodeRabbit

  • New Features

    • Component synchronization now carries expected descriptions for machines, switches, and power shelves.
    • Description updates preserve operator- and system-managed metadata while adding, updating, or removing expected descriptions.
  • Bug Fixes

    • Improved detection and application of component description changes, including non-text values.
    • Clearing an expected description now removes only the managed entry without affecting unrelated descriptions or concurrent updates.
  • Tests

    • Added coverage for description synchronization across supported component types and database update scenarios.

Walkthrough

The mirror carries Core descriptions into normalized machine, NVSwitch, and power-shelf components. Reconciliation manages the reserved description entry, preserves unrelated metadata, persists updates, and clears removed descriptions. Unit and database-backed tests cover the lifecycle.

Changes

Expected description synchronization

Layer / File(s) Summary
Normalize expected descriptions
rest-api/flow/internal/scheduler/jobs/inventorysync/expected_mirror_component.go, rest-api/flow/internal/scheduler/jobs/inventorysync/expected_mirror_component_test.go
Expected component specifications copy descriptions from machine, switch, and power-shelf details. Component conversion stores descriptions under the reserved expected_description key.
Reconcile description metadata
rest-api/flow/internal/scheduler/jobs/inventorysync/expected_mirror_component.go, rest-api/flow/internal/scheduler/jobs/inventorysync/expected_mirror_component_test.go, rest-api/flow/internal/scheduler/jobs/inventorysync/expected_mirror_db_test.go
Component creation and updates modify only the reserved description entry, preserve unrelated metadata, handle non-object and non-string values, detect changes, and clear removed descriptions. Tests cover creation, replacement, clearing, preservation, and interleaved runtime updates.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to d4ef3

This localized change preserves expected component descriptions while retaining existing metadata, with no actionable merge-blocking risk remaining after normal checks and review.

Sequence Diagram(s)

sequenceDiagram
  participant Core
  participant Reconciliation
  participant updateMirroredComponent
  participant Database
  Core->>Reconciliation: provide expected component description
  Reconciliation->>updateMirroredComponent: apply expected_description
  updateMirroredComponent->>Database: set or remove reserved metadata key
  Database-->>updateMirroredComponent: preserve runtime and operator metadata
  updateMirroredComponent-->>Reconciliation: persist mirrored component
``

<!-- walkthrough_end -->
<!-- pre_merge_checks_walkthrough_start -->

<details>
<summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary>

### ❌ Failed checks (1 warning)

|     Check name     | Status     | Explanation                                                                           | Resolution                                                                         |
| :----------------: | :--------- | :------------------------------------------------------------------------------------ | :--------------------------------------------------------------------------------- |
| Docstring Coverage | ⚠️ Warning | Docstring coverage is 40.91% which is insufficient. The required threshold is 80.00%. | Write docstrings for the functions missing them to satisfy the coverage threshold. |

<details>
<summary>✅ Passed checks (4 passed)</summary>

|         Check name         | Status   | Explanation                                                                                                                       |
| :------------------------: | :------- | :-------------------------------------------------------------------------------------------------------------------------------- |
|         Title check        | ✅ Passed | The title clearly identifies the primary change: preserving expected component descriptions in Flow.                              |
|      Description check     | ✅ Passed | The description directly explains description propagation, ownership, merging, clearing, tests, and validation for the changeset. |
|     Linked Issues check    | ✅ Passed | The changes satisfy issue `#4353` by preserving descriptions for all component types and retaining runtime and operator metadata.   |
| Out of Scope Changes check | ✅ Passed | The code and tests remain within the linked issue scope of expected description propagation, ownership, merging, and clearing.    |

</details>

</details>

<!-- pre_merge_checks_walkthrough_end -->
<!-- finishing_touch_checkbox_start -->

<details>
<summary>✨ Finishing Touches</summary>

<details>
<summary>🧪 Generate unit tests (beta)</summary>

- [ ] <!-- {"checkboxId": "f47ac10b-58cc-4372-a567-0e02b2c3d479", "radioGroupId": "utg-output-choice-group-5296370324"} -->   Create PR with unit tests

</details>

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---




<sub>Comment `@coderabbitai help` to get the list of available commands.</sub>

<!-- tips_end -->
Loading

@thossain-nv thossain-nv added the rest-api Add this label when an issue or PR concerns NICo REST API label Aug 7, 2026 — with ChatGPT Codex Connector
@pbreton

pbreton commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@pbreton: I will perform a complete review of PR #4713.

✅ Action performed

Full review finished.

@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
`@rest-api/flow/internal/scheduler/jobs/inventorysync/expected_mirror_component.go`:
- Line 446: Update the inventory reconciliation update logic around the
description column so it never replaces the complete stored JSONB map with the
stale snapshot value. Use an atomic JSONB expression against the database column
to update only expected_description, deleting that key when Core clears it,
while preserving unrelated runtime metadata such as nvos_ip. Add an interleaving
integration test covering a runtime metadata update during reconciliation.
🪄 Autofix

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: d60ad4bc-7b8c-4fd8-8cab-313b65fbe667

📥 Commits

Reviewing files that changed from the base of the PR and between 54ac133 and 659c611.

📒 Files selected for processing (3)
  • rest-api/flow/internal/scheduler/jobs/inventorysync/expected_mirror_component.go
  • rest-api/flow/internal/scheduler/jobs/inventorysync/expected_mirror_component_test.go
  • rest-api/flow/internal/scheduler/jobs/inventorysync/expected_mirror_db_test.go

Comment thread rest-api/flow/internal/scheduler/jobs/inventorysync/expected_mirror_component.go Outdated
@pbreton

pbreton commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review.

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@pbreton: I will perform a complete review of PR #4713.

✅ Action performed

Full review finished.

@pbreton
pbreton marked this pull request as ready for review August 10, 2026 20:12
@pbreton
pbreton requested a review from a team as a code owner August 10, 2026 20:12
@github-actions

github-actions Bot commented Aug 10, 2026

Copy link
Copy Markdown

🔐 TruffleHog Secret Scan

No secrets or credentials found!

Your code has been scanned for 700+ types of secrets and credentials. All clear! 🎉

🔗 View scan details

🕐 Last updated: 2026-08-12 17:24:45 UTC | Commit: a4d9d45

@pbreton
pbreton force-pushed the codex/issue-4353-preserve-expected-descriptions branch from 1643cc9 to a4d9d45 Compare August 12, 2026 17:19
@coderabbitai

coderabbitai Bot commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@github-actions

Copy link
Copy Markdown

@pbreton
pbreton force-pushed the codex/issue-4353-preserve-expected-descriptions branch from a4d9d45 to 14209d1 Compare August 12, 2026 23:34
Signed-off-by: Patrice Breton <pbreton@nvidia.com>
Signed-off-by: Patrice Breton <pbreton@nvidia.com>
@pbreton
pbreton force-pushed the codex/issue-4353-preserve-expected-descriptions branch from 14209d1 to d4ef351 Compare August 14, 2026 17:03
@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@pbreton

pbreton commented Aug 14, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai full review.

@coderabbitai

coderabbitai Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

@pbreton: I will perform a complete review of PR #4713.

✅ Action performed

Full review finished.

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

Makes sense to me, Description as a JSON makes this a bit confusing. @kunzhao-nv Can you take a look as well?

labelComponentSlotID = "slot_id"
labelComponentTrayIdx = "tray_idx"
labelComponentHostID = "host_id"
expectedDescriptionKey = "expected_description"

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.

Should this be metadata_description?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source is Metadata.description but this is really the description for all the Expected* components...
Depends what we want the name to reflect.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rest-api Add this label when an issue or PR concerns NICo REST API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(flow): preserve expected component descriptions through the Core mirror

2 participants