Skip to content

fix(gitlab): report PAT connect and authentication failures accurately - #8536

Merged
iscekic merged 6 commits into
mainfrom
drain/gitlab-auth-failure-reporting
Oct 22, 2026
Merged

iscekic merged 6 commits into
mainfrom
drain/gitlab-auth-failure-reporting

Conversation

@iscekic

@iscekic iscekic commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

Evidence

Evidence: demonstrated — the local dev stack exercised PAT connect, repository-sync failure, and authentication reporting. A follow-up database regression reproduced stale credential invalidation after reconnect; the fixed real tRPC route reports the reconnected installation as installed even when repository sync fails.

Change

  • connectWithPAT commits the integration and credential before repository caching. A cache failure returns success with a warning. Same-instance reconnects preserve the last successful repository list; instance changes discard the previous instance's cache on sync failure.
  • A validated PAT reconnect sets active status and clears auth_invalid_at and auth_invalid_reason in the credential transaction. Repository-sync success is not required to restore credential health.
  • GitLab webhook and project-access-token operations distinguish 401 authentication failures from 403 Maintainer-role failures. Callers report reconnect guidance for authentication failures. Reviews fail with accurate guidance while Code Reviewer stays enabled; provider 401 reporting does not mutate stored connectivity state.
  • The integration page displays repository-sync warnings in the success toast and refreshes installation state without reloading the document.

Verification

Initial-session evidence retained:

  • Integration and code-review Jest suites: 118 suites, 1603 tests passed; web typecheck and lint passed.
  • Real local Next.js, Postgres, fake-account session, and network-boundary provider/broker stubs: 18/18 checks passed for connect, installation status, repository refresh, and webhook-read 401 versus 403 guidance.
  • Chromium exercised PAT validation and connection. The warning remained visible in the success toast and the connected view replaced the PAT form. Screenshot: fix(gitlab): report PAT connect and authentication failures accurately #8536 (comment)

Follow-up verification:

  • New database-backed reconnect regression failed before the fix because auth_invalid_at remained set. After the fix, the credential persistence suite passed all 21 tests.
  • POSTGRES_URL=<local database> NODE_ENV=test pnpm exec jest --runInBand src/lib/integrations src/lib/code-reviews: 118 suites passed; 1604 tests passed, 1 skipped.
  • pnpm --filter web run typecheck passed. Targeted oxlint: 0 warnings, 0 errors. Changed TypeScript files formatted with oxfmt; git diff --check passed.
  • Real local Next.js/tRPC run: 5/5 checks passed. An org-owned PAT integration seeded with the authorizing-user-deletion state first returned installed: false. Reconnect with a validated replacement PAT and a project-list 502 returned success with a warning. A subsequent getInstallation returned installed: true; Postgres confirmed active status, both invalidation fields cleared, and the replacement credential authorized by the signed-in fake org owner.
  • Provider paths observed in the follow-up: authenticated GET /api/v4/personal_access_tokens/self, /api/v4/user, and /api/v4/projects. No provider writes occurred. This run used only owned fake-account fixtures and local Postgres and provider endpoints.

Boundary: provider-shaped responses prove the application's behavior, not acceptance by a real GitLab instance. Project-access-token create/list/rotate/revoke remain covered by adapter/service tests, not HTTP E2E. GitHub and Bitbucket paths are unchanged. This follow-up changes backend reconnect state only; no new visual capture was taken.

Proxy answers

The owner's proxy gave these answers in the owner's place; precedents are paraphrased.

  1. Question: How should GitLab 401 responses be represented? Answer: New GitLabAuthenticationError class. Confidence: 0.65. Precedent: Fix the class of issue while retaining 403 handling.
  2. Question: What should an authentication failure during review token creation do? Answer: Fail the review and keep Code Reviewer enabled. Confidence: 0.55. Precedent: Accurate reconnect guidance without an additional cross-surface reason.
  3. Question: What should users see after a post-commit repository-fetch failure? Answer: Success plus warning plus toast description. Confidence: 0.70. Precedent: Explain retryable failure and retain Refresh Projects recovery.
  4. Question: How broadly should the adapter distinguish 401 from 403? Answer: All seven affected sites. Confidence: 0.85. Precedent: Fix every affected surface.
  5. Question: Should reporting a provider 401 mutate stored connectivity state? Answer: No, report only. Confidence: 0.70. Precedent: Credential-broker state changes are a separate concern.

The PAT connect commits the integration and credential before it loads the
repository list, so a repository-list refusal used to surface as a failed
connection even though the connection was stored. The sync failure is now a
warning on the successful result and the existing refresh path fills the cache
later, and the settings toast shows the warning.

Webhook and project access token calls classified a 401 together with a 403 as
a Maintainer-role refusal. A 401 means GitLab rejected the credential, so it now
throws its own error kind that webhook sync, project token creation and review
preparation route to a reconnect message, while a 403 keeps the role guidance.
The document reload discarded the connect toast before it could be read. Refresh the installation query instead, so the success message with its warning stays visible and the connected view replaces the form.
@iscekic iscekic added drain Work item from the findings drain janitor:features-workflows Janitor finding family: features-workflows labels Oct 22, 2026
@iscekic

iscekic commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator Author

bot: Verified the GitLab PAT connect result on the local dev stack with the project list refusing at the provider boundary.

Observed in Chromium on the GitLab integration settings page: the PAT form validated a token, the connect action completed, and the success toast rendered with the repository-list warning as its description and stayed on screen. The PAT form was then replaced by the connected installation view, so the in-place refresh works without reloading the document.

GitLab connected toast with the repository-list warning

@kilo-code-bot

kilo-code-bot Bot commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

The incremental change clears auth_invalid_at and auth_invalid_reason in the reconnect transaction and adds a regression test; the previous credential-health WARNING is resolved, and no new defects were found in the 51 changed lines.

Assumptions: [INFERENCE] Verification of runtime behavior is based on the added test and current code paths; no live GitLab instance was exercised in this review.

Files Reviewed (2 files)
  • apps/web/src/lib/integrations/gitlab-service.ts
  • apps/web/src/lib/integrations/gitlab-service.credentials.test.ts
Previous Review Summaries (3 snapshots, latest commit 8c441ac)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit 8c441ac)

Status: 1 Issue Found | Recommendation: Address before merge

Executive Summary

The incremental commit only corrects the repository-cache JSDoc, which is now accurate; the one unresolved defect is that a PAT reconnect does not clear auth_invalid_at, so a connected installation can still report installed: false.

Assumptions: [INFERENCE] The authorizing-user-deletion path (apps/web/src/lib/user/index.ts:1347-1358) was read in current code, but the admin-reconnect-after-deletion scenario was not reproduced on a live stack.

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/lib/integrations/gitlab-service.ts 1289 The connect transaction sets integration_status: 'active' (line 1179) but never clears auth_invalid_at/auth_invalid_reason. The reply to the existing thread says no GitLab path writes those columns, but apps/web/src/lib/user/index.ts:1347-1358 sets both, plus integration_status: 'suspended', for GitLab PAT integrations whose authorizing user is deleted (and deletes that credential). Another admin reconnecting such an integration leaves auth_invalid_at set, so isPlatformIntegrationHealthy (health.ts:12-21) stays false and gitlab.getInstallation returns installed: false; if the post-commit repository sync also fails, the result is success: true with the warning while the page still renders the connect form. Clear both columns in the connect transaction since they describe the credential being replaced.
Files Reviewed (1 file)
  • apps/web/src/lib/integrations/gitlab-service.ts - 1 issue (documentation change verified accurate; carried WARNING re-verified on current HEAD)

Fix these issues in Kilo Cloud

Previous review (commit 2432479)

Status: 2 Issues Found | Recommendation: Address before merge

Executive Summary

The reconnect path still leaves auth_invalid_at set after an authorizing user is deleted, so a successful PAT reconnect can report installed: false; the broker reconnect detection and instance-change cache handling are now correct.

Assumptions: [INFERENCE] The user-deletion-to-reconnect path was traced through apps/web/src/lib/user/index.ts and gitlab.getInstallation, not reproduced on a live stack. Provider 401/403 behavior and the UI toast were not re-exercised in this pass.

Overview

Severity Count
CRITICAL 0
WARNING 1
SUGGESTION 1
Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/lib/integrations/gitlab-service.ts 1178 The connect transaction sets integration_status: 'active' but never clears auth_invalid_at/auth_invalid_reason. The earlier reply stated no GitLab path writes those columns, but apps/web/src/lib/user/index.ts:1348-1358 does exactly that for GitLab PAT integrations when the authorizing user is deleted. Another admin reconnecting that integration (typical for org-owned rows) leaves the flags set, so isPlatformIntegrationHealthy stays false and gitlab.getInstallation returns installed: false; if the post-commit repository sync also fails, the result is success: true with the warning while the page still renders the connect form. Clear both columns in the connect transaction, since they describe the credential being replaced.

SUGGESTION

File Line Issue
apps/web/src/lib/integrations/gitlab-service.ts 1008 The new JSDoc says the repository list refetches after a failed sync, but listGitLabRepositories (gitlab-service.ts:316) only refetches when the cache is empty or repositories_synced_at is null. A same-instance reconnect keeps both, so the retained cache is served until an explicit refresh. Scope the comment to the empty-cache case.
Files Reviewed (5 files)
  • apps/web/src/lib/integrations/gitlab-service.ts - 2 issues (1 carried WARNING, 1 SUGGESTION)
  • apps/web/src/lib/integrations/platforms/gitlab/credential-errors.ts - 0 issues
  • apps/web/src/lib/code-reviews/triggers/prepare-review-payload.ts - 0 issues (prior broker-detection finding fixed)
  • apps/web/src/lib/code-reviews/triggers/prepare-review-payload.test.ts - 0 issues
  • apps/web/src/lib/integrations/gitlab-service.credentials.test.ts - 0 issues

Previous review (commit 26d47b4)

Status: 3 Issues Found | Recommendation: Address before merge

Executive Summary

The 401/403 split and the warning-on-failed-sync flow work as described, but the existing-integration connect path can return success while leaving stale repository and auth-invalid state, and the new auth detection misses the credential broker's reconnect error.

Assumptions: none (adapter, service, review-preparation, classifier, sync, and UI call sites were read; the PR's stated provider-behavior gaps are unchanged by this review).

Overview

Severity Count
CRITICAL 0
WARNING 3
SUGGESTION 0
Issue Details (click to expand)

WARNING

File Line Issue
apps/web/src/lib/integrations/gitlab-service.ts 1252 Existing-integration path never clears repositories/repositories_synced_at, so a failed post-commit sync keeps serving stale cache (old instance's projects after an instance change) and listGitLabRepositories will not refetch.
apps/web/src/lib/integrations/gitlab-service.ts 1266 Connect sets integration_status: 'active' but never clears auth_invalid_at, so when the repo sync also fails the result is success: true while getInstallation still reports installed: false.
apps/web/src/lib/code-reviews/triggers/prepare-review-payload.ts 571 isGitLabAuthenticationFailure misses the credential broker's TRPCError UNAUTHORIZED (GitLab integration must be reconnected), which still falls into the generic token message and is classified as gitlab_project_access_required, disabling Code Reviewer.
Files Reviewed (10 files)
  • apps/web/src/components/integrations/GitLabIntegrationDetails.tsx - 0 issues
  • apps/web/src/lib/code-reviews/action-required.test.ts - 0 issues
  • apps/web/src/lib/code-reviews/triggers/prepare-review-payload.test.ts - 0 issues
  • apps/web/src/lib/code-reviews/triggers/prepare-review-payload.ts - 1 issue
  • apps/web/src/lib/integrations/gitlab-service.credentials.test.ts - 0 issues
  • apps/web/src/lib/integrations/gitlab-service.ts - 2 issues
  • apps/web/src/lib/integrations/platforms/gitlab/adapter.test.ts - 0 issues
  • apps/web/src/lib/integrations/platforms/gitlab/adapter.ts - 0 issues
  • apps/web/src/lib/integrations/platforms/gitlab/webhook-sync.test.ts - 0 issues
  • apps/web/src/lib/integrations/platforms/gitlab/webhook-sync.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by deepseek-flash-latest · Input: 30.2K · Output: 2.2K · Cached: 200.4K

Review guidance: REVIEW.md from base branch main

A credential-broker reconnect refusal is the same credential problem as a
provider 401, so review preparation now treats both through one predicate:
the credential is unusable until the owner reconnects, and role guidance
cannot fix it.

A failed repository sync also drops the cached list when the connect moved to
a different GitLab instance, so projects from the previous instance are not
shown against the new credential.
A same-instance reconnect keeps its last list until the user refreshes it; only an empty cache is refetched on the next read.
@iscekic iscekic added merge:blocked:kilobot-not-ready Review bot has not recommended merge at this head merge:human Substantive functional risk requires human review. labels Oct 22, 2026
@iscekic iscekic added merge:human Substantive functional risk requires human review. and removed merge:blocked:kilobot-not-ready Review bot has not recommended merge at this head merge:human Substantive functional risk requires human review. labels Oct 22, 2026
…lure-reporting

# Conflicts:
#	apps/web/src/lib/integrations/platforms/gitlab/adapter.test.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

drain Work item from the findings drain janitor:features-workflows Janitor finding family: features-workflows merge:human Substantive functional risk requires human review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants