Skip to content

fix: retry rejected capture batches and self-heal newly-gapped repos (CM-1441) - #4729

Merged
themarolt merged 29 commits into
mainfrom
fix/CM-1441-star-snapshot-capture-batch-retry
Sep 23, 2026
Merged

themarolt merged 29 commits into
mainfrom
fix/CM-1441-star-snapshot-capture-batch-retry

Conversation

@themarolt

Copy link
Copy Markdown
Contributor

Summary

  • captureStarSnapshots: retries batches still rejected after activity/rate-limit handling, once, after a 30s cooldown - most transient GitHub/DB blips no longer leave a permanent snapshot gap for that day.
  • selfHealStarBackfill: now also sweeps completed-but-newly-gapped repos (via findReposNeedingGapHeal) once per full run, alongside the existing never-completed page scan, so a dropped batch self-heals without manual intervention.
  • star-snapshot-backfill bin script: new --gapped-only flag targets exactly the repos with a current snapshot gap instead of a full sweep, for fixing a specific gap on demand.
  • starSnapshotHealthReporting job: the reported gap count now matches the day-list it displays (drops repos whose gap closed between the two underlying queries).

Root cause: a capture batch on 2026-09-22 was dropped after exhausting retries, leaving ~1884 repos missing one day - not a date-boundary bug in the health report.

Test plan

  • pnpm tsc-check passes
  • Next 08:00 UTC capture run: verify no repos come up short after a simulated/real batch failure
  • Next 09:00 UTC self-heal run: verify newly-gapped completed repos get backfilled
  • Manual: --gapped-only run against a known-gapped repo set

…(CM-1441)

Signed-off-by: Uroš Marolt <uros@marolt.me>
Copilot AI balanced review requested due to automatic review settings September 23, 2026 11:21
@cursor

cursor Bot commented Sep 23, 2026

Copy link
Copy Markdown

PR Summary

Medium Risk
Changes scheduled Temporal capture and self-heal workflows (including deploy-time patched() behavior) and expands automated backfill dispatch for completed repos; mistakes could affect daily snapshot completeness or GitHub API load.

Overview
Addresses dropped daily star-snapshot capture batches and repos that become gapped after backfill is marked complete (CM-1441).

captureStarSnapshots refactors batch handling so rejected batches are collected instead of immediately counted as failures, then—behind patched('CM-1441-retry-rejected-batches')—runs one extra pass after a 30s sleep before repos are marked failed.

selfHealStarBackfill adds a second paginated scan of completed, non-dead-lettered repos (findReposNeedingGapHeal / findCompletedReposEligibleForGapHeal + gap check) alongside the existing incomplete-backfill scan, with separate cursors and gap-heal-namespaced child workflow IDs (patched for safe mid-deploy replay).

Data layer centralizes batched gap detection in findAllRepoIdsWithStarSnapshotGaps; the backfill CLI gains --gapped-only (separate checkpoint/completed files) to target only repos with a current gap. The health reporting cron uses the shared gap helper and reports gap counts only for repos with missingDays > 0, avoiding over-count when a gap closes between queries.

Reviewed by Cursor Bugbot for commit 7dfa1f9. Bugbot is set up for automated code reviews on this repo. Configure here.

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 review overview

🟡 Changes recommended

Critical scalability and checkpoint issues, plus a retry logic defect, must be addressed before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 3 High severity · 1 Medium severity

Open (4)
What changed in this PR

Improves star-snapshot recovery through capture retries, automated gap healing, targeted backfills, and accurate health reporting.

Changes:

  • Retries rejected capture batches after a cooldown.
  • Adds scheduled and --gapped-only gap healing.
  • Aligns reported gap counts with displayed results.
File Description
services/​libs/​data-access-layer/​src/​repositoryStarSnapshots/​index.ts Adds completed-repository lookup and gap detection.
services/​apps/​star_snapshot_worker/​src/​workflows/​selfHealStarBackfill.ts Dispatches gap-healing child workflows.
services/​apps/​star_snapshot_worker/​src/​workflows/​captureStarSnapshots.ts Adds rejected-batch retry handling.
services/​apps/​star_snapshot_worker/​src/​bin/​star-snapshot-backfill.ts Adds targeted gapped-only backfills.
services/​apps/​star_snapshot_worker/​src/​activities/​index.ts Implements gap-healing discovery.
services/​apps/​star_snapshot_worker/​src/​activities.ts Exports the new activity.
services/​apps/​cron_service/​src/​jobs/​starSnapshotHealthReporting.job.ts Reconciles gap counts with displayed results.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread services/apps/star_snapshot_worker/src/activities/index.ts Outdated
Comment thread services/apps/star_snapshot_worker/src/workflows/selfHealStarBackfill.ts Outdated
Comment thread services/libs/data-access-layer/src/repositoryStarSnapshots/index.ts Outdated
Comment thread services/apps/star_snapshot_worker/src/workflows/captureStarSnapshots.ts Outdated
Copilot AI review requested due to automatic review settings September 23, 2026 11:26
Signed-off-by: Uroš Marolt <uros@marolt.me>

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 review overview

🔵 Needs a closer look

Moderate retry correctness, pagination, validation, indexing, timeout, and payload-limit concerns remain unresolved.

Review effort: Balanced
Findings: 3 High severity · 1 Medium severity

Open (4)

Copilot AI review requested due to automatic review settings September 23, 2026 11:31

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 review overview

🔵 Needs a closer look

Unbounded gap scans, quadratic backfill persistence, and a retry guard bug must be addressed before approval.

Review effort: Balanced
Findings: 3 High severity · 1 Medium severity

Open (4)

Copilot AI review requested due to automatic review settings September 23, 2026 11:39

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 review overview

🟡 Changes recommended

Temporal compatibility, overlapping scans, and gapped-only scalability and checkpoint consistency must be addressed.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 2 High severity

Open (2)
Resolved since last review (4)

Comment thread services/apps/star_snapshot_worker/src/workflows/captureStarSnapshots.ts Outdated
…ploy (CM-1441)

Signed-off-by: Uroš Marolt <uros@marolt.me>
Copilot AI review requested due to automatic review settings September 23, 2026 11:52
Signed-off-by: Uroš Marolt <uros@marolt.me>
Signed-off-by: Uroš Marolt <uros@marolt.me>

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 review overview

🟡 Changes recommended

The resume correctness, unbounded scanning, and pre-patch failure-accounting issues must be addressed.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 Medium severity · 2 Low severity

Open (3)
Resolved since last review (2)
Previously missed (3)

In code that hasn't changed since last review

Low severity Reduce comment to the repository's two-line limit

services/​apps/​cron_service/​src/​jobs/​starSnapshotHealthReporting.job.ts:68

The race explanation is useful, but this comment exceeds the repository's two-line maximum (CLAUDE.md:74-86). It can be reduced without losing the invariant.

Low severity Shorten function comment to the non-obvious constraint

services/​apps/​star_snapshot_worker/​src/​activities/​index.ts:408

This three-line function narration exceeds the repository's two-line limit (CLAUDE.md:74-86). Keep only the non-obvious performance constraint.

Low severity Shorten comment to the pagination invariant

services/​apps/​star_snapshot_worker/​src/​workflows/​selfHealStarBackfill.ts:84

This three-line narration exceeds the repository's two-line maximum for allowed comments (CLAUDE.md:74-86). Keep only the non-obvious pagination invariant.

Comment thread services/apps/star_snapshot_worker/src/workflows/captureStarSnapshots.ts Outdated
Comment thread services/apps/star_snapshot_worker/src/workflows/selfHealStarBackfill.ts Outdated
Copilot AI review requested due to automatic review settings September 23, 2026 11:57
… comments (CM-1441)

Signed-off-by: Uroš Marolt <uros@marolt.me>

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 review overview

🔵 Needs a closer look

Retry compatibility, child-workflow reuse, and gapped-only scalability issues remain unresolved.

Review effort: Balanced
Findings: 1 Medium severity

Open (1)
Resolved since last review (2)
Previously missed (3)

In code that hasn't changed since last review

Low severity Condense race explanation comment to protected invariant

services/​apps/​cron_service/​src/​jobs/​starSnapshotHealthReporting.job.ts:68

The race explanation is useful, but this comment exceeds the two-line limit. Condense it to the invariant the filter protects.

Low severity Shorten header to the timeout pagination constraint

services/​apps/​star_snapshot_worker/​src/​activities/​index.ts:408

This three-line function header mostly restates the function name and implementation. Keep only the timeout-related pagination constraint in a concise form.

Low severity Shorten comment to cursor and page-bound rationale

services/​apps/​star_snapshot_worker/​src/​workflows/​selfHealStarBackfill.ts:84

This three-line comment narrates the newly added control flow. Keep only the non-obvious reason for separate cursors and the page bound, within two lines.

Copilot AI review requested due to automatic review settings September 23, 2026 12:04

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 review overview

🟡 Changes recommended

The workflow can fail during replay when the new patch is disabled, and the identified comment violations remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (3)
Previously missed (2)

In code that hasn't changed since last review

Low severity Condense race explanation comment to two lines

services/​apps/​cron_service/​src/​jobs/​starSnapshotHealthReporting.job.ts:68

The race explanation is useful, but this comment exceeds the repository's two-line maximum (CLAUDE.md:76-86). Condense it while retaining the concurrency invariant.

Low severity Condense comment to separation and pagination invariants

services/​apps/​star_snapshot_worker/​src/​activities/​index.ts:408

This new comment exceeds the repository's two-line limit (CLAUDE.md:76-86) and mostly narrates the function. Keep only the non-obvious separation and bounded-pagination invariant.

Comment thread services/apps/star_snapshot_worker/src/workflows/selfHealStarBackfill.ts Outdated
Signed-off-by: Uroš Marolt <uros@marolt.me>
Copilot AI review requested due to automatic review settings September 23, 2026 16:26

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 review overview

🔵 Needs a closer look

The critical resume correctness issue and moderate unbounded-scan issue must be addressed.

Review effort: Balanced
Findings: None

Resolved since last review (1)

Copilot AI review requested due to automatic review settings September 23, 2026 16:31

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 review overview

🔵 Needs a closer look

The --gapped-only path must use a bounded, paginated candidate scan to avoid estate-wide memory and database load.

Review effort: Balanced
Findings: None

Copilot AI review requested due to automatic review settings September 23, 2026 16:40

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 review overview

🟡 Changes recommended

The critical child-workflow ID collision can prevent detected snapshot gaps from being healed.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity

Open (1)

Comment thread services/apps/star_snapshot_worker/src/workflows/selfHealStarBackfill.ts Outdated
…ollision (CM-1441)

Signed-off-by: Uroš Marolt <uros@marolt.me>
Copilot AI review requested due to automatic review settings September 23, 2026 17:07

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 review overview

🟡 Changes recommended

Critical gap-detection coverage and moderate resume-safety issues remain unresolved.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: 1 High severity · 2 Low severity

Open (3)
Resolved since last review (1)

Comment thread services/apps/star_snapshot_worker/src/workflows/selfHealStarBackfill.ts Outdated
Comment thread services/apps/star_snapshot_worker/src/workflows/selfHealStarBackfill.ts Outdated
Signed-off-by: Uroš Marolt <uros@marolt.me>
Copilot AI review requested due to automatic review settings September 23, 2026 18:04

@gaspergrom gaspergrom 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.

Traced the retry-once/cooldown logic in captureStarSnapshots and the dual-cursor continueAsNew handling in selfHealStarBackfill against the patch-ID replay scenarios Copilot and Cursor flagged earlier in this thread; both hold up. The health report fix reconciles the two underlying queries and closes the race that caused the mismatch. Good to merge.

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 review overview

🔵 Needs a closer look

The batch-ID collision risk and full-population --gapped-only scan must be addressed before approval.

Review effort: Balanced
Findings: None

Resolved since last review (3)

Copilot AI review requested due to automatic review settings September 23, 2026 18:10

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 review overview

🟡 Changes recommended

The --gapped-only implementation must avoid its unbounded double scan before approval.

Get a fresh assessment by requesting another Copilot review.

Review effort: Balanced
Findings: None

@themarolt
themarolt merged commit 2b61bfc into main Sep 23, 2026
14 checks passed
@themarolt
themarolt deleted the fix/CM-1441-star-snapshot-capture-batch-retry branch September 23, 2026 18:33
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.

4 participants