Skip to content

fix(backfill): summarize issues before PRs so a PR backlog can't starve the To-do surface - #23

Merged
AndresL230 merged 1 commit into
mainfrom
fix/backfill-summarize-issues-first
Jul 7, 2026
Merged

fix(backfill): summarize issues before PRs so a PR backlog can't starve the To-do surface#23
AndresL230 merged 1 commit into
mainfrom
fix/backfill-summarize-issues-first

Conversation

@AndresL230

@AndresL230 AndresL230 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Problem

On prod, the My Work To-do cards render without their structured fields (humanized displayTitle, next_step) — the boxes show but look half-filled. Root cause is in the backfill, not the frontend:

runBackfill shares one per-invocation AI-call budget (summaryBatchLimit) across PR and issue summaries, and spent it PR-first. With a large closed-PR backlog and the frontend's 10-batch auto-loop driving a sustained run, assigned-issue summaries were reached last — right where the Workers AI rate-limit wall hits "partway through" a long run. So issue summaries were starved and their structured columns never populated.

Observed on remote D1: 17 issue summaries, 0 structured (all title/next_step NULL); 56 of 146 PR summaries also stale — the issue queue simply never got budget.

Fix

Reorder runBackfill so the issue loop runs before the PR loop under the shared budget. Issues are far fewer than PRs, so they clear in the first batch — well before the wall. PRs (Previous activity) take whatever budget remains and finish across follow-up Sync batches. No new budget knob; ordering alone removes the starvation.

Test

Rewrites the backfill test that previously encoded PR-first (shares one AI-call budget … PRs consume it first) to assert issues-first: with 3 PRs + 1 assigned issue and a budget of 2, the issue is summarized this run rather than starved. Full suite green (408 tests), typecheck clean.

Follow-up (operational, not in this PR)

Deploying this does not itself rewrite the already-stale rows — a Sync GitHub run under the deployed fix regenerates the 17 issue (+ 56 PR) summaries, issues-first, so they land structured instead of hitting the wall.

Summary by CodeRabbit

  • Behavior Changes

    • Backfill processing now prioritizes open issues before closed pull requests when sharing a limited AI summary budget.
    • Assigned issues are counted and summarized more consistently, with progress pacing preserved during longer runs.
  • Bug Fixes

    • Improved handling of backfill runs so work is distributed more predictably under rate limits or backlog pressure.
    • Updated coverage ensures the summary budget is spent in the new issue-first order.

…ve the To-do surface

runBackfill shares one per-invocation AI-call budget across PR and issue
summaries, and it spent that budget PR-first. With a large PR backlog (and the
frontend's 10-batch auto-loop feeding a sustained run), the assigned-issue
summaries were reached last — right around where the Workers AI rate-limit wall
hits "partway through" a long run — so the To-do surface's structured fields
(displayTitle / next_step) were starved and never populated.

Reorder so the issue loop runs before the PR loop. Issues are far fewer than PRs,
so they clear in the first batch, well before the wall; PRs (Previous activity)
take whatever budget remains and finish across follow-up Sync batches. No new
budget knob — ordering alone fixes the starvation.

Updates the backfill test that previously encoded the PR-first behavior to assert
issues-first: an assigned issue is summarized even when the PR count exceeds the
per-invocation budget.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jul 7, 2026

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
canopy ef7d4b5 Commit Preview URL

Branch Preview URL
Jul 07 2026, 04:58 AM

@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The runBackfill function is reordered so open issues are processed and summarized before closed PRs, sharing a single AI summarization budget across both loops. Running count variables are hoisted earlier, and the test suite is updated to assert issues-first budget allocation with a matching fixture change.

Changes

Backfill summarization ordering

Layer / File(s) Summary
Shared budget state hoisted
src/tools/backfill.ts
prSummarizedCount, issueSummarizedCount, and issuesToSummarize are moved earlier in runBackfill, with comments clarifying the shared AI-call budget and ordering effects.
Issues-first, PRs-second processing loops
src/tools/backfill.ts
The issues loop now runs first, ingesting issue events, applying progress, and summarizing assigned issues against the shared summaryBatchLimit; the PR loop runs afterward, ingesting PR events and summarizing remaining PRs under the same shared budget, incrementing prSummarizedCount only for non-excerpt results.
Test coverage for issues-before-PRs budget spend
test/backfill.test.ts
The test fixture changes to three PRs and one assigned issue with a budget of 2; assertions verify the issue plus one PR are summarized first, and the remaining PRs are summarized in a follow-up run without re-invoking issue summarization.

Estimated code review effort: 2 (Simple) | ~12 minutes

Sequence Diagram(s)

sequenceDiagram
  participant runBackfill
  participant IssuesLoop
  participant PRLoop
  participant Summarizer

  runBackfill->>IssuesLoop: process assigned issues
  IssuesLoop->>Summarizer: summarize issue (within summaryBatchLimit)
  Summarizer-->>IssuesLoop: summary result
  IssuesLoop-->>runBackfill: summaryBudgetExhausted?
  runBackfill->>PRLoop: process PRs
  PRLoop->>Summarizer: summarize PR (if budget remains)
  Summarizer-->>PRLoop: summary result
  PRLoop-->>runBackfill: prSummarizedCount updated
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: reordering backfill to summarize issues before PRs to avoid starving To-do items.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/backfill-summarize-issues-first

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.

@AndresL230
AndresL230 merged commit 4b93a90 into main Jul 7, 2026
1 of 2 checks passed

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

🧹 Nitpick comments (1)
src/tools/backfill.ts (1)

246-345: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚖️ Poor tradeoff

Reordering logic verified correct against the new test fixture.

Traced the budget math against the updated test/backfill.test.ts scenario (3 PRs + 1 assigned issue, summaryBatchLimit: 2): issue consumes 1 unit, 1 PR takes the remainder, exhaustion correctly triggers, and the follow-up run correctly skips the already-summarized issue while draining the rest of the PR backlog. Capture/progress application is correctly decoupled from the summarization budget gate.

One observation: the issue-summarization block (Lines 264-294) and PR-summarization block (Lines 312-348) share an almost identical shape (existing-summary check → budget gate → store → pace delay), differing only in the query/table and store call. Since both loops are touched directly in this change, this could be a good moment to extract a small shared helper (e.g., taking the existing-summary query, a store callback, and a counter ref) to prevent the two paths from silently diverging in future edits.

🤖 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 `@src/tools/backfill.ts` around lines 246 - 345, The issue is duplicated
issue/PR summarization flow in backfill.ts, where the issue and PR loops now
repeat the same existing-summary check, budget gate, store call, and pacing
logic. Extract a small shared helper around the backfill summarization path in
backfill.ts that accepts the lookup/query, store callback, and per-type counters
so the issue and PR branches stay consistent and do not diverge on future edits.
🤖 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 `@src/tools/backfill.ts`:
- Around line 246-345: The issue is duplicated issue/PR summarization flow in
backfill.ts, where the issue and PR loops now repeat the same existing-summary
check, budget gate, store call, and pacing logic. Extract a small shared helper
around the backfill summarization path in backfill.ts that accepts the
lookup/query, store callback, and per-type counters so the issue and PR branches
stay consistent and do not diverge on future edits.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 16e06743-9c09-42cf-8387-618685e3f0f8

📥 Commits

Reviewing files that changed from the base of the PR and between 6a49723 and ef7d4b5.

📒 Files selected for processing (2)
  • src/tools/backfill.ts
  • test/backfill.test.ts

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