Skip to content

Paginate fetchComments and keep recent comments on truncation#536

Merged
gjkim42 merged 1 commit intomainfrom
kelos-task-528
Mar 4, 2026
Merged

Paginate fetchComments and keep recent comments on truncation#536
gjkim42 merged 1 commit intomainfrom
kelos-task-528

Conversation

@kelos-bot
Copy link

@kelos-bot kelos-bot bot commented Mar 3, 2026

What type of PR is this?

/kind bug

What this PR does / why we need it:

fetchComments previously made a single HTTP request, returning at most 100 comments per issue. On busy issues (>100 comments), the most recent comments — including TriggerComment and ExcludeComment commands — were silently dropped. This PR:

  1. Paginates fetchComments using the same loop pattern as fetchAllIssues (up to maxPages pages), via a new fetchCommentsPage helper that mirrors fetchIssuesPage.
  2. Reverses concatCommentBodies truncation order so that when the total exceeds maxCommentBytes, older comments are dropped from the front and the most recent comments are preserved. Uses an efficient O(n) append-then-reverse approach.

Which issue(s) this PR is related to:

Fixes #528

Special notes for your reviewer:

The pagination infrastructure (parseNextLink, maxPages) already existed for issues. This PR reuses it for comments with the same pattern. No new constants or types were introduced.

Does this PR introduce a user-facing change?

Fix comment pagination to fetch all pages (up to 1000 comments) instead of only the first 100, preventing missed trigger/exclude commands on busy issues.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 2 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="internal/source/github.go">

<violation number="1" location="internal/source/github.go:429">
P2: Quadratic slice prepend: `append([]string{...}, parts...)` copies the entire `parts` slice on every iteration, resulting in O(n²) allocations. Consider appending in reverse order and reversing at the end, or pre-allocating with index placement.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Copy link
Collaborator

@gjkim42 gjkim42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/reset-worker

@kelos-bot kelos-bot bot force-pushed the kelos-task-528 branch from ce8f03c to 2705688 Compare March 4, 2026 13:56
Copy link
Collaborator

@gjkim42 gjkim42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lgtm
/squash-commits

fetchComments previously made a single HTTP request, returning at most
100 comments. On busy issues the most recent comments — including
trigger and exclude commands — were silently dropped. Apply the same
pagination loop used by fetchAllIssues (up to maxPages).

concatCommentBodies truncated from the front (oldest kept), compounding
the data loss. Reverse the truncation direction so the most recent
comments are preserved within the maxCommentBytes budget. Replaces the
O(n²) prepend pattern with an O(n) append-then-reverse approach.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@kelos-bot kelos-bot bot force-pushed the kelos-task-528 branch from 2705688 to 1564de7 Compare March 4, 2026 14:33
@gjkim42 gjkim42 enabled auto-merge March 4, 2026 14:41
@gjkim42 gjkim42 added priority/important-soon triage-accepted kind/bug Categorizes issue or PR as related to a bug labels Mar 4, 2026
@github-actions github-actions bot removed needs-triage needs-kind Indicates an issue or PR lacks a kind/* label needs-priority labels Mar 4, 2026
@gjkim42 gjkim42 disabled auto-merge March 4, 2026 14:42
@gjkim42 gjkim42 added this pull request to the merge queue Mar 4, 2026
Merged via the queue into main with commit 613fbf7 Mar 4, 2026
22 of 29 checks passed
@gjkim42 gjkim42 deleted the kelos-task-528 branch March 4, 2026 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: fetchComments does not paginate — misses trigger/exclude comments on busy issues

1 participant