fix: name both Git grants when the platform cannot tell them apart - #1374
Draft
l2ysho wants to merge 1 commit into
Draft
fix: name both Git grants when the platform cannot tell them apart#1374l2ysho wants to merge 1 commit into
l2ysho wants to merge 1 commit into
Conversation
l2ysho
marked this pull request as draft
September 1, 2026 09:08
Base automatically changed from
claude/cli-github-auth-stuck-47be9b
to
master
September 1, 2026 10:21
`GET /v2/integrations/git` reports an authorized user with no app installation exactly like one whose token the provider revoked: the integration is present, `workspaces` is empty, and `addWorkspaceUrl` is absent because it is derived from the first installation. Only one of the two is fixed by installing the app, so picking either one dead ends the other. The old code always picked the installation, which left a revoked token polling a state that could never change. `getPendingGrants` now returns both, likeliest first, and the wait loop opens the first and prints the rest. A run that watched the user authorize knows the integration it then sees is that grant landing, which settles authorization and leaves only the installation. That only counts when no integration existed at the time — offering authorization in the ambiguous state says nothing about whether the user completed it. `createGrantTracker` holds the across-poll state, so the decision is testable without mocking the browser, the API or the clock. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
l2ysho
force-pushed
the
claude/cli-git-grant-ambiguity-9d41c7
branch
from
September 1, 2026 10:23
738efd9 to
0d13335
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Important
TL;DR —
apify create --source githubin some scenarios I got stuck in auth flow, this needs further investigationStacked on #1371 — it depends on the
GitAccountparameter that PR adds togetGitConnectUrl. Retarget tomasteronce #1371 merges.Not the redirect bug in #1371. This one hits personal accounts too.
The state the CLI has to read
apify-core,
src/api/src/routes/integrations/git_providers.ts, reports four situations in three shapes:workspacesaddWorkspaceUrl[][]addWorkspaceUrlcomes fromdata.installations[0]?.app_slug, so it is absent when there are no installations — and absent again in thecatchwhen the installation listing fails, which is what a revoked token produces. The last two rows are byte-identical on the wire. No heuristic separates them.The old code always chose the installation link for both, so a revoked token was handed a link that changes nothing, and the poll loop waited out its full budget on a state that could never move.
What changed
src/lib/git-source/gitSource.tsgetPendingGrants()returns the grants that may still be missing, likeliest first. No integration means authorization, unambiguously. An integration carryingaddWorkspaceUrlmeans the listing succeeded, so the token works and only the installation is left. Anything else is ambiguous and names both.createGrantTracker()holds the state that spans polls: the last URL opened, and whether this run watched an authorization land. A run that offered authorization while no integration existed knows the integration it then sees is that grant landing. Offering authorization in the ambiguous state proves nothing and does not count — treating it as proof reorders the grants on the very next poll and opens a second tab on top of a user still sitting on the consent page.noWorkspacerecovery steps name both grants, for the same reason the wait loop does.Reviewer notes
createGrantTrackeris driven directly over a poll sequence, with no mocking ofopen,fetchor timers. Reverting the tie-break fails five of those tests.--jsongitConnectUrlstill carries a single URL fornoWorkspace. The same payload includesnextSteps, which names both, and a single-URL field cannot represent an ambiguity the API itself cannot resolve.catchingetGithubIntegrationturns a revoked token into a shape meaning "authorized, nothing installed". Returningnullon a 401 collapses that into "not authorized". There is also nogithub_app_authorizationwebhook handler, soisAuthorizedis never cleared when a user revokes on GitHub.Verification
Reproduced live by revoking the Apify authorization on GitHub, which leaves
GET /v2/integrations/gitreportingworkspaces: []and noaddWorkspaceUrl— the state that used to hang. The CLI now opens the authorization URL, the grant lands, and workspace selection proceeds.Checks
lint,format,build,test:local(503 passed, 4 skipped). No docs regen — no flag, arg or description changed.🤖 Generated with Claude Code