Skip to content

fix(hub): cancel superseded collaborator searches - #349

Open
zachshallbetter wants to merge 2 commits into
github:build/hub/newfrom
zachshallbetter:fix/hub-cancel-mention-searches
Open

zachshallbetter wants to merge 2 commits into
github:build/hub/newfrom
zachshallbetter:fix/hub-cancel-mention-searches

Conversation

@zachshallbetter

Copy link
Copy Markdown

Why

When reviewers keep typing a mention, the browser drops the old search. Hub can still page through GitHub collaborators for every abandoned search, using the same rate limit as the current one.

Addresses #328.

What changes

Hub cancels the in-flight collaborator lookup when the browser disconnects and skips any remaining pages. Connected searches keep their existing limits and repository access checks. Hub still verifies mentions when a comment is saved.

@zachshallbetter
zachshallbetter requested review from a team and nshki as code owners November 24, 2026 10:37
Copilot AI adaptive review requested due to automatic review settings November 24, 2026 10:37

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

Cancellation does not cover the full mention request or installation-token minting, allowing abandoned requests to continue or initiate unnecessary GitHub calls.

2 open issues
What changed in this PR

This PR adds disconnect-driven cancellation to Hub’s review mention searches, reducing unnecessary GitHub collaborator paging when reviewers keep typing. It addresses #328 while retaining existing search limits, repository access checks, and save-time mention verification.

Changes:

  • Passes browser-disconnect cancellation through the mention directory to GitHub requests.
  • Stops collaborator pagination after cancellation.
  • Adds a disconnect regression test and documents the behavior.
File Description
hub/​server/​routes/​api/​review-comments/​collaboration.db.test.ts Tests cancellation and prevention of further paging after disconnect.
hub/​server/​routes/​api/​review-comments/​collaboration-handlers/​index.ts Tracks disconnects and avoids responding to destroyed connections.
hub/​server/​integrations/​github/​create-review-directory/​types.ts Adds an optional cancellation signal to collaborator searches.
hub/​server/​integrations/​github/​create-review-directory/​index.ts Combines cancellation with timeouts and checks before further paging.
hub/​server/​domains/​review-comments/​create-review-mention-directory/​index.ts Forwards cancellation to the GitHub directory.
hub/​docs/​review-collaboration.md Documents disconnect cancellation for collaborator lookups.

Review effort: Max (adaptive)

async search(repositoryId, query, cancellation) {
cancellation?.throwIfAborted()
const timeout = AbortSignal.timeout(6000)
const signal = cancellation ? AbortSignal.any([timeout, cancellation]) : timeout
cancellation.abort()
}
// The incoming GET can finish before its client disconnects.
response.once("close", cancel)
@zachshallbetter

Copy link
Copy Markdown
Author

I pushed ad28a18 for the two cancellation findings. A disconnect now cancels the lookup through both access checks. Token requests that are already shared keep running for callers still waiting on them. The directory and collaboration suites passed locally, including disconnects during the initial and final checks.

@zachshallbetter

Copy link
Copy Markdown
Author

Could someone approve the CI runs for ad28a18 when you get a chance? The Hub CI run is waiting for approval. Thanks!

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

Thanks so much for opening this PR, @zachshallbetter! After taking a look, I dug a bit more to see whether we could avoid the inefficient query in the first place. Based on the default GitHub App permissions we request for new Hub installations, it looks like we should be able to use GitHub’s GraphQL Repository.collaborators(query: ...) field instead of fetching broad REST pages and filtering them in Hub.

Could you investigate using the filtered GraphQL query here? It may address the unnecessary pagination more directly than cancellation.

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