Skip to content

fix: page through branches and tags in resource completions - #4019

Open
chanyang721 wants to merge 2 commits into
github:mainfrom
chanyang721:fix/completions-page-branches-tags
Open

chanyang721 wants to merge 2 commits into
github:mainfrom
chanyang721:fix/completions-page-branches-tags

Conversation

@chanyang721

@chanyang721 chanyang721 commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Branch and tag completion for repository resource templates now reads past the first page of refs, and when the completion handler receives more than 100 values it now reports hasMore: true.

Each branch or tag completion reads at most 10 pages (1,000 refs). If refs are left unread at that point, it returns an error asking for a longer prefix rather than a list that may be missing matches, so a prefix that matches nothing cannot walk every page of a large repository.

Why

completeBranch and completeTag call ListBranches and ListTags once with no options, so they only ever see the API's default first page of 30 refs. In a repository with more refs, a branch or tag past the 30th is never suggested, even when the typed text matches it exactly (for example a release tag such as v2.0.0 listed after older tags).

RepositoryResourceCompletionHandler cuts values to 100, but never sets hasMore (so it is omitted from the response) and sets total to the cut length, so a client cannot tell that more matches exist.

No upstream issue is associated with this fix.

What changed

  • pkg/github/repository_resource_completions.go:

    • completeBranch and completeTag request 100 refs per page and follow the next page until more than 100 values match or the list ends. Stopping after the page that holds the 101st match lets the handler know there are more without reading every remaining page. The existing filters are unchanged (prefix for branches, substring for tags).
    • A failed list request now returns its error. Before, the error was ignored, and with paging a failure on a later page would have returned a partial list that looked complete. This overlaps with fix: propagate repository completion API errors #3583, which makes the same change for single-page calls; whichever lands second can be rebased onto the other.
    • When the handler receives more than 100 values it returns the first 100 with hasMore: true and leaves total unset, because a resolver may have stopped reading before it saw every ref and the real count is unknown. For results that are not cut, nonempty responses include the exact total and empty responses still omit it, as before. Other resolvers (owner, sha, prNumber, path) still cut to 100 themselves, so the handler cannot detect more for them; that is unchanged.
  • pkg/github/repository_resource_completions_test.go: a paginated mock that behaves like the list endpoints (30 per page by default, per_page/page parameters, a Link next header), and tests that

    • the 31st branch is suggested,
    • a tag that only appears on the second page is suggested,
    • branch completion stops after the page that takes it past 100 values (2 requests for 450 branches),
    • the handler returns 31 values with total: 31 for 31 branches, and 100 values with hasMore: true for 150 branches,
    • exactly 100 matches return total: 100 without hasMore,
    • an error on the second page is returned for branches and tags,
    • the existing MaxResults test also asserts hasMore: true.

    With these tests applied on main, all of the new tests and MaxResults fail; with this change they pass.

Commit SHA completion (completeSHA) still reads one page. It lists recent commits, so this may be intended, and it is left out of this PR.

MCP impact

  • No tool or API changes

Tool definitions and schemas are unchanged. Branch and tag completions can return matches from later pages and now return list errors. When the handler cuts results, it sets hasMore and omits total.

Prompts tested (tool changes only)

  • N/A: no tool changes. Completion behavior is covered by unit tests.

Security / limits

  • No security or limits impact
  • Auth / permissions considered
  • Data exposure, filtering, or token/size limits considered

Branch and tag completion can now make more than one list request, so the request count is bounded: each completion reads at most 10 pages of 100 refs (1,000 refs), and stops earlier after the page that holds the 101st match or the last page. If refs are still unread after 10 pages, it returns an error asking for a longer prefix instead of a possibly incomplete list, so a prefix that matches nothing cannot walk every page of a large repository or exhaust the API quota. Results are still cut to 100 values. No new permissions, scopes or data sources are used; the same list endpoints are called with the caller's existing token.

Tool renaming

  • I am renaming tools as part of this PR (e.g. a part of a consolidation effort)
    • I have added the new tool aliases in deprecated_tool_aliases.go
  • I am not renaming tools as part of this PR

Lint & tests

  • Linted locally: golangci-lint run ./pkg/github/... (v2.14.0, the version script/lint installs): ran, passed, 0 issues
  • Tested locally: go test ./pkg/github -run 'Complet|RepositoryResource' -count=1: ran, passed (Go 1.27.4, darwin/arm64)
  • Before the fix: the same command with repository_resource_completions.go from main fails the new tests and MaxResults.
  • ./script/test (go test -race ./...) and the full ./script/lint: not run on the final commit; relying on PR CI for the full suite.

Docs

  • Not needed

Skills

  • Updated relevant skills or confirmed no bundled skill applies

No tool or toolset instruction changes, so no bundled skill applies.

Branch and tag completion called ListBranches and ListTags once without
options, so only the first 30 refs were ever offered. Request 100 per
page and follow the next page until more than 100 values match or the
list ends. A failed list request now returns its error instead of a
partial list that looks complete.

The completion handler cut results to 100 but never reported hasMore
and set Total to the cut length. Report hasMore=true when values are
cut, and leave Total unset then because a resolver may stop reading
before it has seen every ref.
@chanyang721
chanyang721 requested a review from a team as a code owner December 3, 2026 07:05
Copilot AI adaptive review requested due to automatic review settings December 3, 2026 07:05

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.

🟡 Changes recommended

Branch and tag completion can fetch every ref page for nonexistent prefixes, risking API quota exhaustion because neither resolver enforces a per-completion request budget.

1 open issue
What changed in this PR

Fixes repository resource completions so branches and tags beyond the first API page can be suggested.

Changes:

  • Fetches additional pages until more than 100 matches are found or refs are exhausted.
  • Reports hasMore for truncated results and propagates list errors.
  • Adds regression tests for pagination, result limits, and later-page failures.
File Description
pkg/​github/​repository_resource_completions.go Adds branch/tag pagination and updates completion metadata and error handling.
pkg/​github/​repository_resource_completions_test.go Adds paginated mocks and regression coverage.

Review effort: Balanced (adaptive)

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

AI Assessment: Missing Details

Thanks for the contribution. Please edit the description to fill in these
sections of the pull request template:

  • Security / limits

Generated by Pull Request Triage · copilot · auto (Claude Sonnet 5.5) · ~11 AIC · ⌖ ~1 AIC · ⊞ 6.4K · history

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.

3 participants