Skip to content

[server] Retry failed post-sync maintenance - #1901

Merged
Asherlc merged 5 commits into
mainfrom
issue-1730
Jul 24, 2026
Merged

Asherlc merged 5 commits into
mainfrom
issue-1730

Conversation

@Asherlc

@Asherlc Asherlc commented Jul 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • reject required post-sync maintenance failures after reporting step-specific progress and Sentry context
  • reuse the established BullMQ retry policy for global-maintenance and per-user refit jobs
  • add regression coverage for refit and cache-invalidation rejection behavior

Validation

  • pnpm vitest run src/jobs/process-post-sync-job.test.ts src/jobs/queues.test.ts --project unit
  • pnpm test:changed
  • pnpm lint
  • root, server, and web TypeScript checks

The full local unit/mobile suite passed 13,224 tests but hit one unrelated load-sensitive timeout in the Garmin multi-chunk ZIP streaming test; that exact test passed immediately in isolation.

Closes #1730

Summary by Sourcery

Make post-sync maintenance steps fail fast and be retried using the shared BullMQ retry policy.

Bug Fixes:

  • Ensure body measurement refresh, personalized parameter refit, and user cache invalidation reject on failure instead of completing with errors so BullMQ can retry them.

Enhancements:

  • Add step-specific progress messages and Sentry context for post-sync maintenance failures.
  • Apply the shared SYNC_JOB_RETRY_OPTIONS to global post-sync maintenance and per-user refit jobs while preserving debounce, deduplication, and completion-removal behavior.

Documentation:

  • Document the design and implementation plan for retrying required post-sync maintenance in new superpowers plan and spec files.

Tests:

  • Update post-sync job processor tests to assert rejection behavior, failure progress, and Sentry tagging for maintenance steps.
  • Extend queue tests to verify post-sync jobs are enqueued with the established retry options and failure retention settings.

Summary by cubic

Make required post-sync maintenance fail fast and reuse the shared retry policy so BullMQ retries both global and per-user post-sync jobs. Prevents stale personalized params and cache after sync; addresses #1730.

  • Bug Fixes
    • Body refresh, refit, and cache invalidation now reject on failure; log step-specific Sentry tags and progress, and stop later steps.
    • Applied SYNC_JOB_RETRY_OPTIONS (attempts: 288, backoff: fixed 300_000 ms, failed-job retention) to enqueueDebouncedPostSyncMaintenance and enqueueDebouncedUserRefit while keeping delay, deduplication, and removeOnComplete.
    • Tests: added rejection and retry coverage, assert original error identity for body refresh/refit/cache failures, removed “completed with errors”; progress update failures remain non-fatal.

Written for commit 42f4306. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features

    • Added retry handling for required post-sync maintenance tasks.
    • Failed steps now stop processing, report progress, and retry automatically.
    • Added standardized retry and failure cleanup settings for maintenance jobs.
  • Bug Fixes

    • Prevented later maintenance steps from running after an earlier step fails.
    • Preserved the original error details in failure reporting.

Copilot AI review requested due to automatic review settings July 24, 2026 17:01

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codereviewbot-ai

Copy link
Copy Markdown

🤖 Review skipped: Repository rate limit exceeded. Free accounts are limited to 2 reviews per 4 hours per repository. Upgrade to a paid plan for unlimited reviews.

@cursor

cursor Bot commented Jul 24, 2026

Copy link
Copy Markdown

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@qodo-code-review

Copy link
Copy Markdown

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@sourcery-ai

sourcery-ai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Post-sync job processing is updated so required maintenance steps fail fast with Sentry context and step-specific progress while BullMQ post-sync queues now reuse the shared retry policy, and tests/docs are adjusted to cover the new rejection and retry behavior.

Flow diagram for post-sync queues using shared retry options

flowchart LR
  SYNC_JOB_RETRY_OPTIONS["SYNC_JOB_RETRY_OPTIONS (attempts: 288, fixed 300000ms backoff, removeOnFail)"]

  enqueueDebouncedPostSyncMaintenance["enqueueDebouncedPostSyncMaintenance"]
  enqueueDebouncedUserRefit["enqueueDebouncedUserRefit"]

  GlobalPostSyncQueue["BullMQ queue: global-maintenance"]
  UserRefitQueue["BullMQ queue: user-refit"]

  SYNC_JOB_RETRY_OPTIONS --> enqueueDebouncedPostSyncMaintenance
  SYNC_JOB_RETRY_OPTIONS --> enqueueDebouncedUserRefit

  enqueueDebouncedPostSyncMaintenance --> GlobalPostSyncQueue
  enqueueDebouncedUserRefit --> UserRefitQueue

  GlobalPostSyncQueue --> processPostSyncJob["processPostSyncJob (global maintenance)"]
  UserRefitQueue --> processPostSyncJobUser["processPostSyncJob (per-user refit)"]
Loading

File-Level Changes

Change Details Files
Required post-sync maintenance steps now report failure progress, log to Sentry, and rethrow so jobs can be retried instead of completing with partial success.
  • Removed partial-success tracking and the "completed with errors" terminal state from post-sync processing.
  • Updated body-measurement refresh, personalized parameter refit, and cache invalidation to log errors, capture Sentry context, emit step-specific failure progress messages, and rethrow the original error.
  • Ensured cache invalidation does not run after refit failures and that 100% completion progress is only reported on fully successful runs.
src/jobs/process-post-sync-job.ts
BullMQ post-sync queues now use the shared sync-job retry policy so global-maintenance and user-refit jobs are retried with fixed backoff and failure retention.
  • Extended global post-sync maintenance enqueue options to spread SYNC_JOB_RETRY_OPTIONS while preserving debounce, deduplication, and remove-on-complete.
  • Applied the same shared retry options to per-user refit enqueue calls.
  • Updated queue tests to assert attempts, fixed backoff delay, and removeOnFail options for both post-sync job types.
src/jobs/queues.ts
src/jobs/queues.test.ts
Post-sync processor tests and internal documentation/specs were updated to describe and validate the new failure, rejection, and retry semantics.
  • Replaced prior partial-completion tests with rejection-focused tests that assert Sentry tagging, failure progress messages, and absence of terminal completion on error.
  • Extended body-refresh failure tests to check failure progress and ensured progress-update failures remain non-fatal.
  • Added design and implementation plan docs describing ordered required maintenance, retry behavior, idempotency assumptions, and testing strategy.
src/jobs/process-post-sync-job.test.ts
docs/superpowers/plans/2026-07-24-post-sync-retry.md
docs/superpowers/specs/2026-07-24-post-sync-retry-design.md

Assessment against linked issues

Issue Objective Addressed Explanation
#1730 Make required post-sync maintenance steps (body-measurement refresh, personalized parameter refit, and user cache invalidation) reject on failure instead of completing the job, while preserving Sentry context and clear progress messages. ✅
#1730 Ensure failed post-sync jobs are retried by configuring BullMQ post-sync queues to use the existing SYNC_JOB_RETRY_OPTIONS retry policy. ✅
#1730 Add regression tests and documentation clarifying the required/ordered nature of post-sync maintenance steps and their retry behavior. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Post-sync user maintenance now rejects on required-step failures, records step-specific progress and Sentry context, and stops subsequent steps. Both post-sync enqueue paths reuse the shared BullMQ retry policy, with updated processor and queue tests.

Changes

Post-sync retry behavior

Layer / File(s) Summary
Retry behavior design and implementation plan
docs/superpowers/...
Documents ordered maintenance, fail-fast semantics, idempotency, progress/Sentry reporting, and shared BullMQ retry configuration.
Required maintenance fail-fast handling
src/jobs/process-post-sync-job.ts, src/jobs/process-post-sync-job.test.ts
Required failures are rethrown after step-specific progress and Sentry reporting; later steps and completion progress are skipped.
BullMQ retry option wiring
src/jobs/queues.ts, src/jobs/queues.test.ts
Both debounced enqueue paths use SYNC_JOB_RETRY_OPTIONS, including attempts, fixed backoff, and failed-job retention. Tests preserve debounce and completion-removal assertions.

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

Sequence Diagram(s)

sequenceDiagram
  participant BullMQ
  participant processPostSyncJob
  participant Sentry
  participant PostSyncStep
  BullMQ->>processPostSyncJob: Run post-sync maintenance
  processPostSyncJob->>PostSyncStep: Execute ordered required step
  PostSyncStep-->>processPostSyncJob: Return success or error
  processPostSyncJob->>Sentry: Capture error with postSyncStep
  processPostSyncJob-->>BullMQ: Rethrow error for retry
Loading

Assessment against linked issues

Objective Addressed Explanation
Required refit and cache-invalidation failures reject the job [#1730] ✅
Existing BullMQ retry policy is applied [#1730] ✅
Maintenance steps remain safely retryable [#1730] ✅
Sentry context and actionable progress messages are preserved [#1730] ✅

Possibly related PRs

Suggested labels: type/bug

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is imperative, area-prefixed, under 70 characters, and accurately summarizes the post-sync retry change.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

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

Hey - I've left some high level feedback:

  • In the catch blocks for body refresh/refit/cache invalidation, consider wrapping updatePostSyncProgress in its own try/catch so that a progress-update failure cannot mask the original maintenance error you're intentionally rethrowing for BullMQ retries.
  • The step progress percentages and messages (20/45/75/100 and their strings) are now duplicated across tests and implementation; factoring these into shared constants would reduce the risk of the tests drifting from the actual processor behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In the catch blocks for body refresh/refit/cache invalidation, consider wrapping `updatePostSyncProgress` in its own try/catch so that a progress-update failure cannot mask the original maintenance error you're intentionally rethrowing for BullMQ retries.
- The step progress percentages and messages (20/45/75/100 and their strings) are now duplicated across tests and implementation; factoring these into shared constants would reduce the risk of the tests drifting from the actual processor behavior.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@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

🤖 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 `@src/jobs/process-post-sync-job.test.ts`:
- Around line 194-196: Update the rejection assertion for processPostSyncJob to
use identity comparison with refreshError via toBe rather than deep error
matching via toThrow, ensuring the original body-refresh error instance is
rethrown.
🪄 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: ASSERTIVE

Plan: Pro Plus

Run ID: 786fef8e-c344-40d2-a890-04aec7f878ee

📥 Commits

Reviewing files that changed from the base of the PR and between 16e630f and 4fe2ad0.

📒 Files selected for processing (6)
  • docs/superpowers/plans/2026-07-24-post-sync-retry.md
  • docs/superpowers/specs/2026-07-24-post-sync-retry-design.md
  • src/jobs/process-post-sync-job.test.ts
  • src/jobs/process-post-sync-job.ts
  • src/jobs/queues.test.ts
  • src/jobs/queues.ts

Comment thread src/jobs/process-post-sync-job.test.ts Outdated
@Asherlc Asherlc changed the title Retry failed post-sync maintenance [server] Retry failed post-sync maintenance Jul 24, 2026
@codereviewbot-ai

Copy link
Copy Markdown

🤖 Review skipped: Repository rate limit exceeded. Free accounts are limited to 2 reviews per 4 hours per repository. Upgrade to a paid plan for unlimited reviews.

@Asherlc
Asherlc merged commit 67e0c6f into main Jul 24, 2026
102 checks passed
@Asherlc
Asherlc deleted the issue-1730 branch July 24, 2026 17:28
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.

Fail and retry post-sync jobs when required maintenance fails

2 participants