Skip to content

feat(ncps): add progress ticker to migrate-chunks-to-nar - #1310

Merged
kalbasit merged 3 commits into
mainfrom
user/wnasreddine/migration-progress
Jun 1, 2026
Merged

kalbasit merged 3 commits into
mainfrom
user/wnasreddine/migration-progress

Conversation

@kalbasit

@kalbasit kalbasit commented Jun 1, 2026

Copy link
Copy Markdown
Owner

Summary

  • Adds a 5-second progress ticker goroutine to migrateChunksToNarAction, matching the existing pattern in migrate-nar-to-chunks
  • Every 5 seconds while workers run, logs a structured Info line with total, processed, succeeded, failed, skipped, percent, elapsed, and rate fields
  • Uses sync.WaitGroup to ensure the goroutine exits cleanly before the action returns (no goroutine leak, race-detector safe)
  • Exports migrateChunksToNarProgressInterval via export_test.go so tests can override the 5 s interval to 1 ms for deterministic coverage

Test plan

  • task fmt — no diff
  • task lint — 0 issues
  • task test — all pass (including 2 new tests: TestMigrateChunksToNar_CLI_ProgressLogEmitted, TestMigrateChunksToNar_CLI_NoProgressLogOnEmptyRun)
  • Tests capture os.Stdout via os.Pipe (the CLI's getZeroLogger writes there, not the context logger) and verify presence/absence of "migration progress" log lines with -race

kalbasit and others added 2 commits May 31, 2026 19:21
The migrate-chunks-to-nar command lacked the periodic progress
reporting that migrate-nar-to-chunks already had. Operators had
no visibility into how far along the reverse migration was.

Add a 5-second progress ticker goroutine to migrateChunksToNarAction
that logs total, processed, succeeded, failed, skipped, percent,
elapsed, and rate — identical fields to the forward migration command.
A sync.WaitGroup ensures the goroutine exits cleanly before the
function returns (no goroutine leak, race-detector safe).

Also exports migrateChunksToNarProgressInterval via export_test.go
so tests can override the 5 s interval to 1 ms for deterministic
coverage. Tests capture os.Stdout via os.Pipe because the CLI's
getZeroLogger writes there, not the context logger.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
Move the change artifacts to the archive directory now that the
implementation is complete and committed.

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@kalbasit

kalbasit commented Jun 1, 2026 •

Copy link
Copy Markdown
Owner Author

This change is part of the following stack:

Change managed by git-spice.

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request go Pull requests that update go code labels Jun 1, 2026
@coderabbitai

coderabbitai Bot commented Jun 1, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 500b519f-f280-46ea-9259-0b147b211ad8

📥 Commits

Reviewing files that changed from the base of the PR and between 69f9e27 and dd6220e.

📒 Files selected for processing (2)
  • pkg/ncps/migrate_chunks_to_nar.go
  • pkg/ncps/migrate_chunks_to_nar_test.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • pkg/ncps/migrate_chunks_to_nar_test.go
  • pkg/ncps/migrate_chunks_to_nar.go

📝 Walkthrough

Summary by CodeRabbit

  • New Features

    • The migrate-chunks-to-nar command now emits periodic progress updates every 5 seconds during migration, showing total items, processed/succeeded/failed/skipped counts, completion percentage, elapsed time, and processing rate.
  • Documentation

    • Added specification, design, and proposal docs describing progress-reporting behavior, lifecycle, and edge-case handling.
  • Tests

    • Added tests to verify progress logging is emitted during migrations and suppressed when there are no items.

Walkthrough

Introduces periodic progress reporting to the migrate-chunks-to-nar command. A 5-second ticker logs structured migration progress while the migration runs, including fields for total items, processed counts, completion percentage, elapsed time, and processing rate. The implementation uses atomic counters and goroutine coordination, with tests validating both the presence of progress logs during migration and suppression when no items exist.

Changes

Periodic progress reporting for migrate-chunks-to-nar

Layer / File(s) Summary
Specification and design documentation
openspec/changes/archive/2026-05-31-migrate-chunks-to-nar-progress-ticker/.openspec.yaml, openspec/changes/archive/2026-05-31-migrate-chunks-to-nar-progress-ticker/design.md, openspec/changes/archive/2026-05-31-migrate-chunks-to-nar-progress-ticker/proposal.md, openspec/changes/archive/2026-05-31-migrate-chunks-to-nar-progress-ticker/specs/migrate-chunks-to-nar-progress-reporting/spec.md, openspec/changes/archive/2026-05-31-migrate-chunks-to-nar-progress-ticker/tasks.md, openspec/specs/migrate-chunks-to-nar-progress-reporting/spec.md
Design proposal and formal specification document the 5-second ticker interval, structured log fields (total, processed, succeeded, failed, skipped, percent, elapsed, rate), goroutine lifecycle (start after startTime, stop via progressDone before final summary), and edge cases (zero-item early return, safe division handling).
Test-only progress interval export
pkg/ncps/export_test.go
Adds MigrateChunksToNarProgressIntervalForTest pointer export to allow tests to override the internal progress interval.
Progress reporter implementation
pkg/ncps/migrate_chunks_to_nar.go
Implements concurrent progress logging via a configurable 5s ticker: adds sync import, introduces migrateChunksToNarProgressInterval, starts a background goroutine that reads atomic counters and emits Info-level "migration progress" logs until workers finish, then coordinates shutdown and final summary logging.
Progress reporter tests
pkg/ncps/migrate_chunks_to_nar_test.go
Adds bytes and time imports and two CLI integration tests: one short-interval test asserting "migration progress" lines with required fields appear before final "migration completed", and another asserting no progress lines are emitted on an empty run.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • kalbasit/ncps#1301: Introduces the migrate-chunks-to-nar command itself; this PR adds progress reporting to that same command.

Suggested labels

documentation

Poem

🐰 I hop and tick while migrations run,
Counting chunks until the work is done.
Progress whispers every little while,
Logged in JSON, neat and concise style.
Then goroutines bow and the final line's fun. 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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 'feat(ncps): add progress ticker to migrate-chunks-to-nar' directly and clearly describes the main change: adding a progress ticker to the migrate-chunks-to-nar command.
Description check ✅ Passed The description provides a comprehensive summary of changes including the 5-second progress ticker, structured logging fields, goroutine safety, test exports, and a detailed test plan with specific test names and verification steps.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

@gemini-code-assist gemini-code-assist 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.

Code Review

This pull request introduces periodic progress reporting to the migrate-chunks-to-nar command by running a background goroutine that logs migration metrics every 5 seconds. Feedback on the newly added tests highlights a potential deadlock risk when capturing os.Stdout synchronously using an unbuffered os.Pipe. It is recommended to read from the pipe concurrently in a separate goroutine to prevent the tests from hanging if the output exceeds the operating system's pipe buffer limit.

Comment thread pkg/ncps/migrate_chunks_to_nar_test.go Resolved
Comment thread pkg/ncps/migrate_chunks_to_nar_test.go Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

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)
pkg/ncps/migrate_chunks_to_nar_test.go (2)

207-207: ⚡ Quick win

Consider using a zerolog context for consistency.

Other tests in this file initialize the context with zerolog.New(os.Stderr).WithContext(context.Background()). While functionally equivalent here (the CLI creates its own logger), using the same pattern improves consistency and aids debugging.

♻️ Align with existing test pattern
-	ctx := context.Background()
+	ctx := zerolog.New(os.Stderr).WithContext(context.Background())
🤖 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 `@pkg/ncps/migrate_chunks_to_nar_test.go` at line 207, Replace the plain
context initialization "ctx := context.Background()" with a zerolog-backed
context to match other tests: create a logger via
zerolog.New(os.Stderr).WithContext(context.Background()) and assign that to ctx;
ensure zerolog and os are imported and the variable name "ctx" remains the same
so existing code (e.g., calls in the test using ctx) continues to work—locate
the ctx initialization in the test (the line using context.Background()) and
swap it to the zerolog context creation.

255-255: ⚡ Quick win

Consider using a zerolog context for consistency.

Other tests in this file initialize the context with zerolog.New(os.Stderr).WithContext(context.Background()). While functionally equivalent here (the CLI creates its own logger), using the same pattern improves consistency and aids debugging.

♻️ Align with existing test pattern
-	ctx := context.Background()
+	ctx := zerolog.New(os.Stderr).WithContext(context.Background())
🤖 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 `@pkg/ncps/migrate_chunks_to_nar_test.go` at line 255, Replace the plain
context creation for the test's ctx variable with a zerolog-backed context for
consistency: change the existing ctx := context.Background() in
migrate_chunks_to_nar_test.go to use
zerolog.New(os.Stderr).WithContext(context.Background()); ensure the file
imports github.com/rs/zerolog and os if they aren't already and keep the
variable name ctx and existing usage unchanged.
🤖 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 `@pkg/ncps/migrate_chunks_to_nar.go`:
- Around line 328-329: The progress ticker goroutine is being signaled to stop
only via a deferred close(progressDone) at function return, allowing it to log
after the final summary is emitted; change the shutdown to occur immediately
after progressWg.Wait()/g.Wait() and before emitting the final summary log
(e.g., before the "migration completed" log) by removing the deferred
close(progressDone) and calling close(progressDone) right after the wait,
ensuring the ticker goroutine exits before final logs; update or add TDD unit
tests to assert that progressWg/ progressDone lifecycle ends before final
summary is logged.

---

Nitpick comments:
In `@pkg/ncps/migrate_chunks_to_nar_test.go`:
- Line 207: Replace the plain context initialization "ctx :=
context.Background()" with a zerolog-backed context to match other tests: create
a logger via zerolog.New(os.Stderr).WithContext(context.Background()) and assign
that to ctx; ensure zerolog and os are imported and the variable name "ctx"
remains the same so existing code (e.g., calls in the test using ctx) continues
to work—locate the ctx initialization in the test (the line using
context.Background()) and swap it to the zerolog context creation.
- Line 255: Replace the plain context creation for the test's ctx variable with
a zerolog-backed context for consistency: change the existing ctx :=
context.Background() in migrate_chunks_to_nar_test.go to use
zerolog.New(os.Stderr).WithContext(context.Background()); ensure the file
imports github.com/rs/zerolog and os if they aren't already and keep the
variable name ctx and existing usage unchanged.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 9ee4ef3a-22a2-4dee-82fb-65e48d9c02f1

📥 Commits

Reviewing files that changed from the base of the PR and between ff9e8bd and 69f9e27.

📒 Files selected for processing (9)
  • openspec/changes/archive/2026-05-31-migrate-chunks-to-nar-progress-ticker/.openspec.yaml
  • openspec/changes/archive/2026-05-31-migrate-chunks-to-nar-progress-ticker/design.md
  • openspec/changes/archive/2026-05-31-migrate-chunks-to-nar-progress-ticker/proposal.md
  • openspec/changes/archive/2026-05-31-migrate-chunks-to-nar-progress-ticker/specs/migrate-chunks-to-nar-progress-reporting/spec.md
  • openspec/changes/archive/2026-05-31-migrate-chunks-to-nar-progress-ticker/tasks.md
  • openspec/specs/migrate-chunks-to-nar-progress-reporting/spec.md
  • pkg/ncps/export_test.go
  • pkg/ncps/migrate_chunks_to_nar.go
  • pkg/ncps/migrate_chunks_to_nar_test.go

Comment thread pkg/ncps/migrate_chunks_to_nar.go Resolved
The progress ticker goroutine was stopped via a deferred
close(progressDone) that fired only on function return, after
the "migration completed" log line was already written. This
allowed stray progress lines to appear after the summary in
the log stream.

Replace the defers with an explicit close+Wait immediately
after g.Wait() so the goroutine is guaranteed to exit before
the summary is logged (on both error and success paths).

Also drain the os.Stdout pipe concurrently in the progress
tests to prevent a potential deadlock if output exceeds the
64KB OS pipe buffer, and tighten the ordering assertion to
assert progress lines precede "migration completed".

Co-Authored-By: Claude Sonnet 4.6 <[email protected]>
@kalbasit
kalbasit enabled auto-merge (squash) June 1, 2026 03:01
@kalbasit
kalbasit merged commit f21e67c into main Jun 1, 2026
41 of 54 checks passed
@kalbasit
kalbasit deleted the user/wnasreddine/migration-progress branch June 1, 2026 03:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant