Skip to content

refactor(flow): Track current operation run phase#3458

Open
jw-nvidia wants to merge 1 commit into
NVIDIA:mainfrom
jw-nvidia:refactor/reduce-locking-targets
Open

refactor(flow): Track current operation run phase#3458
jw-nvidia wants to merge 1 commit into
NVIDIA:mainfrom
jw-nvidia:refactor/reduce-locking-targets

Conversation

@jw-nvidia

Copy link
Copy Markdown
Contributor
  • Track current operation run phase index in operation run table so that the dipatcher needs to lock the targets in the current phase only.

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

@jw-nvidia jw-nvidia requested a review from a team as a code owner July 13, 2026 23:02
@coderabbitai

coderabbitai Bot commented Jul 13, 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: 80d866ec-e588-4a94-b29d-fb082445c64b

📥 Commits

Reviewing files that changed from the base of the PR and between de804c9 and 230d598.

📒 Files selected for processing (20)
  • rest-api/flow/internal/converter/dao/converter.go
  • rest-api/flow/internal/db/migrations/20260713000000_operation_run_current_phase_index.down.sql
  • rest-api/flow/internal/db/migrations/20260713000000_operation_run_current_phase_index.up.sql
  • rest-api/flow/internal/db/model/operation_run.go
  • rest-api/flow/internal/operationrun/manager/dispatcher/decision.go
  • rest-api/flow/internal/operationrun/manager/dispatcher/dependencies.go
  • rest-api/flow/internal/operationrun/manager/dispatcher/dispatcher_test.go
  • rest-api/flow/internal/operationrun/manager/dispatcher/phase.go
  • rest-api/flow/internal/operationrun/manager/dispatcher/preparation.go
  • rest-api/flow/internal/operationrun/manager/dispatcher/reconciliation.go
  • rest-api/flow/internal/operationrun/manager/manager_test.go
  • rest-api/flow/internal/operationrun/manager/manual_controls.go
  • rest-api/flow/internal/operationrun/manager/store.go
  • rest-api/flow/internal/operationrun/manager/store/dispatch.go
  • rest-api/flow/internal/operationrun/manager/store/store.go
  • rest-api/flow/internal/operationrun/manager/store/store_test.go
  • rest-api/flow/internal/operationrun/operationrun.go
  • rest-api/flow/internal/operationrun/progress.go
  • rest-api/flow/internal/operationrun/progress_test.go
  • rest-api/flow/internal/operationrun/stats.go
🚧 Files skipped from review as they are similar to previous changes (18)
  • rest-api/flow/internal/db/model/operation_run.go
  • rest-api/flow/internal/converter/dao/converter.go
  • rest-api/flow/internal/db/migrations/20260713000000_operation_run_current_phase_index.up.sql
  • rest-api/flow/internal/operationrun/operationrun.go
  • rest-api/flow/internal/operationrun/manager/dispatcher/dependencies.go
  • rest-api/flow/internal/operationrun/manager/dispatcher/preparation.go
  • rest-api/flow/internal/operationrun/manager/dispatcher/decision.go
  • rest-api/flow/internal/operationrun/manager/store.go
  • rest-api/flow/internal/operationrun/stats.go
  • rest-api/flow/internal/operationrun/manager/store/store.go
  • rest-api/flow/internal/operationrun/manager/dispatcher/phase.go
  • rest-api/flow/internal/operationrun/manager/store/store_test.go
  • rest-api/flow/internal/operationrun/manager/store/dispatch.go
  • rest-api/flow/internal/operationrun/manager/manager_test.go
  • rest-api/flow/internal/operationrun/manager/manual_controls.go
  • rest-api/flow/internal/operationrun/progress.go
  • rest-api/flow/internal/operationrun/manager/dispatcher/dispatcher_test.go
  • rest-api/flow/internal/operationrun/progress_test.go

Summary by CodeRabbit

  • New Features

    • Operation runs now persist and expose the current phase index for more reliable progress and manual continuation.
    • Target locking and processing are now phase-scoped, preventing work from spanning multiple phases.
    • Automatic phase advancement can occur when the current phase is terminal (per phase policy).
    • Manual phase advancement now validates that the current phase is terminal and matches the expected next phase precisely.
    • Phase-based progress and safety-gate decisions now use phase-scoped aggregates.
  • Bug Fixes

    • Upgraded/older runs are backfilled with a suitable current phase during migration.
    • Phase-gating behavior was corrected so only current-phase targets are considered.

Walkthrough

Operation runs now persist CurrentPhaseIndex, aggregate phase statistics separately, lock targets by phase, and use explicit claim, advance, or pause decisions for automatic and manual progression.

Changes

Phase-aware operation runs

Layer / File(s) Summary
Phase state and progress model
rest-api/flow/internal/db/migrations/*, rest-api/flow/internal/db/model/operation_run.go, rest-api/flow/internal/operationrun/*, rest-api/flow/internal/converter/dao/converter.go
Adds persisted current-phase state, migrates existing rows, updates DAO conversion, and refactors phase summaries and statistics around aggregate and current-phase data.
Phase-scoped storage and persistence
rest-api/flow/internal/operationrun/manager/store.go, rest-api/flow/internal/operationrun/manager/store/*, rest-api/flow/internal/operationrun/manager/dispatcher/dependencies.go, rest-api/flow/internal/operationrun/manager/store/store_test.go
Locks targets for a specific phase, aggregates completed phases, persists current_phase_index, and uses the stored run index for phase-scoped SQL.
Dispatcher phase decisions
rest-api/flow/internal/operationrun/manager/dispatcher/*.go, rest-api/flow/internal/operationrun/manager/dispatcher/dispatcher_test.go
Reconciles current-phase targets and handles explicit claim, advance, and pause decisions, including phase-specific test stores and transition coverage.
Manual phase advancement
rest-api/flow/internal/operationrun/manager/manual_controls.go, rest-api/flow/internal/operationrun/manager/manager_test.go
Validates terminal and expected next phases, increments the run phase index, and constructs continuation summaries from phase-scoped targets and aggregates.

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

Sequence Diagram(s)

sequenceDiagram
  participant Dispatcher
  participant PostgresStore
  participant TargetPhaseSummary
  Dispatcher->>PostgresStore: LockOperationRunTargets(runID, currentPhaseIndex)
  Dispatcher->>PostgresStore: GetTargetPhaseAggregate(runID, currentPhaseIndex)
  PostgresStore-->>Dispatcher: Current-phase targets and completed-phase aggregate
  Dispatcher->>TargetPhaseSummary: NewTargetPhaseSummary(currentPhaseIndex, aggregate, targets)
  TargetPhaseSummary-->>Dispatcher: Phase terminality and status counts
  Dispatcher->>PostgresStore: UpdateRunState(CurrentPhaseIndex)
Loading
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.76% 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 is concise and accurately summarizes the main change: tracking the current operation run phase.
Description check ✅ Passed The description is clearly related to the change set and correctly describes the new phase-index tracking and phase-scoped locking.
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.

@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown

🔍 Container Scan Summary

Service Total Critical High Medium Low Other
nico-flow 15 1 3 3 0 8
nico-nsm 7 0 1 5 0 1
nico-psm 15 1 3 3 0 8
nico-rest-api 17 1 4 4 0 8
nico-rest-cert-manager 14 1 3 3 0 7
nico-rest-db 15 1 3 3 0 8
nico-rest-site-agent 15 1 3 3 0 8
nico-rest-site-manager 14 1 3 3 0 7
nico-rest-workflow 15 1 3 3 0 8
TOTAL 127 8 26 30 0 63

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

@github-actions

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-07-13 23:07:34 UTC | Commit: de804c9

@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)
rest-api/flow/internal/operationrun/manager/dispatcher/reconciliation.go (1)

36-59: 🎯 Functional Correctness | 🔵 Trivial | 💤 Low value

Drop the unused reconciliation summary
reconcileTargets never populates reconciliationSummary; preparedDispatch.summary is assembled later from GetTargetPhaseAggregate, so this return value is dead weight. Returning only the error would make the ownership clearer.

🤖 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 `@rest-api/flow/internal/operationrun/manager/dispatcher/reconciliation.go`
around lines 36 - 59, Update reconcileTargets to stop creating and returning the
unused reconciliationSummary; change its return contract to only report errors,
and adjust its callers such as preparedDispatch to remove summary handling while
preserving the existing GetTargetPhaseAggregate-based summary assembly.
🤖 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 `@rest-api/flow/internal/operationrun/manager/dispatcher/reconciliation.go`:
- Around line 36-59: Update reconcileTargets to stop creating and returning the
unused reconciliationSummary; change its return contract to only report errors,
and adjust its callers such as preparedDispatch to remove summary handling while
preserving the existing GetTargetPhaseAggregate-based summary assembly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 4b0b1eb5-54ea-4b7f-a072-3cfd422368a6

📥 Commits

Reviewing files that changed from the base of the PR and between 27e2a40 and de804c9.

📒 Files selected for processing (20)
  • rest-api/flow/internal/converter/dao/converter.go
  • rest-api/flow/internal/db/migrations/20260713000000_operation_run_current_phase_index.down.sql
  • rest-api/flow/internal/db/migrations/20260713000000_operation_run_current_phase_index.up.sql
  • rest-api/flow/internal/db/model/operation_run.go
  • rest-api/flow/internal/operationrun/manager/dispatcher/decision.go
  • rest-api/flow/internal/operationrun/manager/dispatcher/dependencies.go
  • rest-api/flow/internal/operationrun/manager/dispatcher/dispatcher_test.go
  • rest-api/flow/internal/operationrun/manager/dispatcher/phase.go
  • rest-api/flow/internal/operationrun/manager/dispatcher/preparation.go
  • rest-api/flow/internal/operationrun/manager/dispatcher/reconciliation.go
  • rest-api/flow/internal/operationrun/manager/manager_test.go
  • rest-api/flow/internal/operationrun/manager/manual_controls.go
  • rest-api/flow/internal/operationrun/manager/store.go
  • rest-api/flow/internal/operationrun/manager/store/dispatch.go
  • rest-api/flow/internal/operationrun/manager/store/store.go
  • rest-api/flow/internal/operationrun/manager/store/store_test.go
  • rest-api/flow/internal/operationrun/operationrun.go
  • rest-api/flow/internal/operationrun/progress.go
  • rest-api/flow/internal/operationrun/progress_test.go
  • rest-api/flow/internal/operationrun/stats.go

- Track current operation run phase index in operation run table so that the
  dipatcher needs to lock the targets in the current phase only.
@jw-nvidia jw-nvidia force-pushed the refactor/reduce-locking-targets branch from de804c9 to 230d598 Compare July 14, 2026 00:19
@jw-nvidia jw-nvidia requested a review from spydaNVIDIA July 14, 2026 00:20
@github-actions

Copy link
Copy Markdown

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.

1 participant