Repository navigation
feat(ncps): add progress ticker to migrate-chunks-to-nar - #1310
Conversation
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]>
|
This change is part of the following stack: Change managed by git-spice. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
📝 WalkthroughSummary by CodeRabbit
WalkthroughIntroduces periodic progress reporting to the ChangesPeriodic progress reporting for migrate-chunks-to-nar
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
Comment |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
pkg/ncps/migrate_chunks_to_nar_test.go (2)
207-207: ⚡ Quick winConsider 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 winConsider 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
📒 Files selected for processing (9)
openspec/changes/archive/2026-05-31-migrate-chunks-to-nar-progress-ticker/.openspec.yamlopenspec/changes/archive/2026-05-31-migrate-chunks-to-nar-progress-ticker/design.mdopenspec/changes/archive/2026-05-31-migrate-chunks-to-nar-progress-ticker/proposal.mdopenspec/changes/archive/2026-05-31-migrate-chunks-to-nar-progress-ticker/specs/migrate-chunks-to-nar-progress-reporting/spec.mdopenspec/changes/archive/2026-05-31-migrate-chunks-to-nar-progress-ticker/tasks.mdopenspec/specs/migrate-chunks-to-nar-progress-reporting/spec.mdpkg/ncps/export_test.gopkg/ncps/migrate_chunks_to_nar.gopkg/ncps/migrate_chunks_to_nar_test.go
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]>
Summary
migrateChunksToNarAction, matching the existing pattern inmigrate-nar-to-chunkstotal,processed,succeeded,failed,skipped,percent,elapsed, andratefieldssync.WaitGroupto ensure the goroutine exits cleanly before the action returns (no goroutine leak, race-detector safe)migrateChunksToNarProgressIntervalviaexport_test.goso tests can override the 5 s interval to 1 ms for deterministic coverageTest plan
task fmt— no difftask lint— 0 issuestask test— all pass (including 2 new tests:TestMigrateChunksToNar_CLI_ProgressLogEmitted,TestMigrateChunksToNar_CLI_NoProgressLogOnEmptyRun)os.Stdoutviaos.Pipe(the CLI'sgetZeroLoggerwrites there, not the context logger) and verify presence/absence of"migration progress"log lines with-race