Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

feat(code): detect stale GitHub integration and offer Reconnect - #2000

Merged
k11kirky merged 1 commit into
mainfrom
05-04-feat_code_detect_stale_github_integration_and_offer_reconnect
May 4, 2026
Merged

k11kirky merged 1 commit into
mainfrom
05-04-feat_code_detect_stale_github_integration_and_offer_reconnect

Conversation

@k11kirky

@k11kirky k11kirky commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

Problem

When a GitHub app installation is uninstalled or its token is revoked, the integration appears as "Connected" even though it can no longer reach GitHub. Users have no way to know their integration is broken or how to fix it.

Changes

  • Tracks failed GitHub installation IDs by detecting errors from the per-integration repository fetch queries
  • Exposes failedInstallationIds from useUserRepositoryIntegration so components can identify stale integrations
  • Adds an integrationIsStale state in GitIntegrationStep when the current integration's installation ID appears in the failed list
  • Replaces the "Connected" status indicator with a "Reconnect needed" warning when the integration is stale
  • Shows an explanatory amber-colored message describing why the integration may have failed
  • Adds a "Reconnect" button that silently disconnects the stale integration and immediately re-initiates the GitHub OAuth/app install flow
  • Supports a silent option on the disconnect mutation to suppress the "GitHub disconnected" toast when reconnecting automatically

@greptile-apps

greptile-apps Bot commented May 4, 2026

Copy link
Copy Markdown
Contributor
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 2
apps/code/src/renderer/features/onboarding/components/GitIntegrationStep.tsx:390-396
**Silent disconnect failure may leave dangling integration**

If `disconnectMutation.mutateAsync` fails (e.g. a 5xx from the backend), the error is swallowed and `handleConnectGitHub()` is still called. The old stale integration record remains in the database while a new OAuth flow starts. Depending on whether the backend enforces uniqueness per user, this can result in two integration rows, and `invalidateGithubQueries` is never called (since `onSuccess` doesn't fire), so the cache retains the stale entry until the reconnect completes.

Consider invalidating the relevant queries in the catch path so the UI doesn't remain in an inconsistent state even when disconnect fails.

### Issue 2 of 2
apps/code/src/renderer/hooks/useIntegrations.ts:155-158
**Stale detection triggers on any error, not just auth failures**

Any error that survives React Query's retry budget (network timeouts, 5xx server errors, etc.) will add the installation to `failedInstallationIds` and show "Reconnect needed" to the user, even when the GitHub token itself is still valid. This could prompt unnecessary reconnects during a temporary backend outage.

If the API client surfaces HTTP status codes, consider restricting the stale signal to 401/403 responses only.

Reviews (1): Last reviewed commit: "feat(code): detect stale GitHub integrat..." | Re-trigger Greptile

Comment on lines +390 to +396
onClick={async () => {
if (!githubIntegration?.installation_id) return;
await disconnectMutation
.mutateAsync({ silent: true })
.catch(() => undefined);
void handleConnectGitHub();
}}

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.

P2 Silent disconnect failure may leave dangling integration

If disconnectMutation.mutateAsync fails (e.g. a 5xx from the backend), the error is swallowed and handleConnectGitHub() is still called. The old stale integration record remains in the database while a new OAuth flow starts. Depending on whether the backend enforces uniqueness per user, this can result in two integration rows, and invalidateGithubQueries is never called (since onSuccess doesn't fire), so the cache retains the stale entry until the reconnect completes.

Consider invalidating the relevant queries in the catch path so the UI doesn't remain in an inconsistent state even when disconnect fails.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/features/onboarding/components/GitIntegrationStep.tsx
Line: 390-396

Comment:
**Silent disconnect failure may leave dangling integration**

If `disconnectMutation.mutateAsync` fails (e.g. a 5xx from the backend), the error is swallowed and `handleConnectGitHub()` is still called. The old stale integration record remains in the database while a new OAuth flow starts. Depending on whether the backend enforces uniqueness per user, this can result in two integration rows, and `invalidateGithubQueries` is never called (since `onSuccess` doesn't fire), so the cache retains the stale entry until the reconnect completes.

Consider invalidating the relevant queries in the catch path so the UI doesn't remain in an inconsistent state even when disconnect fails.

How can I resolve this? If you propose a fix, please make it concise.

Comment on lines +155 to +158
if (result.isError) {
const installationId =
githubIntegrations[index]?.installation_id ?? null;
if (installationId) failedInstallationIds.push(installationId);

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.

P2 Stale detection triggers on any error, not just auth failures

Any error that survives React Query's retry budget (network timeouts, 5xx server errors, etc.) will add the installation to failedInstallationIds and show "Reconnect needed" to the user, even when the GitHub token itself is still valid. This could prompt unnecessary reconnects during a temporary backend outage.

If the API client surfaces HTTP status codes, consider restricting the stale signal to 401/403 responses only.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/code/src/renderer/hooks/useIntegrations.ts
Line: 155-158

Comment:
**Stale detection triggers on any error, not just auth failures**

Any error that survives React Query's retry budget (network timeouts, 5xx server errors, etc.) will add the installation to `failedInstallationIds` and show "Reconnect needed" to the user, even when the GitHub token itself is still valid. This could prompt unnecessary reconnects during a temporary backend outage.

If the API client surfaces HTTP status codes, consider restricting the stale signal to 401/403 responses only.

How can I resolve this? If you propose a fix, please make it concise.

@k11kirky
k11kirky force-pushed the 05-04-feat_code_detect_stale_github_integration_and_offer_reconnect branch from 172b3fe to c0863fa Compare May 4, 2026 14:14
@k11kirky
k11kirky force-pushed the 05-04-feat_code_add_inline_github_disconnect_to_onboarding_step branch from 666b43f to 2f25fac Compare May 4, 2026 14:14

k11kirky commented May 4, 2026 •

Copy link
Copy Markdown
Contributor Author

Merge activity

  • May 4, 2:36 PM UTC: A user started a stack merge that includes this pull request via Graphite.
  • May 4, 3:16 PM UTC: Graphite rebased this pull request as part of a merge.
  • May 4, 3:28 PM UTC: @k11kirky merged this pull request with Graphite.

@k11kirky
k11kirky changed the base branch from 05-04-feat_code_add_inline_github_disconnect_to_onboarding_step to graphite-base/2000 May 4, 2026 15:05
@k11kirky
k11kirky changed the base branch from graphite-base/2000 to main May 4, 2026 15:14
@k11kirky
k11kirky force-pushed the 05-04-feat_code_detect_stale_github_integration_and_offer_reconnect branch from c0863fa to b10465c Compare May 4, 2026 15:15
@k11kirky
k11kirky merged commit 15c30a9 into main May 4, 2026
16 checks passed
@k11kirky
k11kirky deleted the 05-04-feat_code_detect_stale_github_integration_and_offer_reconnect branch May 4, 2026 15:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants