Repository navigation
fix(azure-devops): retry with -preview api-version and keep project-level Git base for on-prem Server (STA-3494) - #12832
Conversation
…evel Git base for on-prem Server (STA-3494) Azure DevOps Server rejects api-version=7.1 with 400 VssInvalidPreviewVersionException unless the -preview suffix is supplied, so auth and every Git endpoint failed. Retry once with -preview on that rejection and remember the requirement per origin. Also stop letting a same-origin ORCA_AZURE_DEVOPS_API_BASE_URL (collection-level, needed only for the connectionData auth probe) override the project-level base derived from the remote for Git endpoints; cross-origin (proxy) overrides keep working.
|
Warning Review limit reached
Next review available in: 6 minutes You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughAzure DevOps requests now detect preview-version rejection responses, retry with a 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: ffc0faf0-9329-4e68-b791-791fe55c9f9b
📒 Files selected for processing (5)
src/main/azure-devops/azure-devops-api-request.test.tssrc/main/azure-devops/azure-devops-api-request.tssrc/main/azure-devops/client.test.tssrc/main/azure-devops/pull-request-creation.test.tssrc/main/azure-devops/pull-request-creation.ts
Electron QA evidenceValidated the exact PR worktree ( |
…evel Git base for on-prem Server (STA-3494) (stablyai#12832) * fix(azure-devops): retry with -preview api-version and keep project-level Git base for on-prem Server (STA-3494) Azure DevOps Server rejects api-version=7.1 with 400 VssInvalidPreviewVersionException unless the -preview suffix is supplied, so auth and every Git endpoint failed. Retry once with -preview on that rejection and remember the requirement per origin. Also stop letting a same-origin ORCA_AZURE_DEVOPS_API_BASE_URL (collection-level, needed only for the connectionData auth probe) override the project-level base derived from the remote for Git endpoints; cross-origin (proxy) overrides keep working. * fix(azure-devops): constrain preview retry and base override

Summary
Fixes STA-3494 / #12695: the Azure DevOps integration could never authenticate against on-prem Azure DevOps Server (TFS). Two defects, both in
src/main/azure-devops/:-previewapi-version suffix. Every request hardcodedapi-version=7.1, which Server rejects with HTTP 400VssInvalidPreviewVersionException.requestAzureDevOpsJsonAtBase()collapsed that tonull, sogetAzureDevOpsAuthStatus()reportedauthenticated: falseand the integration card sat on "Auth failed" forever, even with a valid PAT — indistinguishable from a bad token.connectionDatalives at the collection level while_apis/git/*lives at the project level.ORCA_AZURE_DEVOPS_API_BASE_URL(collection-level, required for the auth probe) overrode the correctly remote-derived project-level base for every Git endpoint, so whichever value was set broke the other half — and silently substituted the wrong project for repos in other projects.Fix
typeKey: "VssInvalidPreviewVersionException", retry the request once with-previewappended (e.g.7.1-preview) and remember the requirement per origin, so subsequent requests to that host go straight to the-previewform. Cloud (dev.azure.com) behavior is unchanged — no extra round trips unless a host actually rejects.pull-request-creation.ts), which previously had its own hardcodedapi-version=7.1. The preview rejection happens before the PR is created, so the single retry cannot double-create.ORCA_AZURE_DEVOPS_API_BASE_URLthat shares its origin with the remote-derived base is now treated as the collection-level auth-probe URL only; Git endpoints use the project-level base derived from the remote. A cross-origin configured base (e.g. a rewrite proxy, which is also what our own integration tests use) still overrides Git endpoints, so existing proxy setups keep working.Reproduction
The reporter verified against a real Server instance with curl (same PAT):
/_apis/connectionData?api-version=7.1→ 400VssInvalidPreviewVersionException;?api-version=7.1-preview→ 200. I do not have an on-prem Azure DevOps Server instance available, so the reproduction here is encoded as unit tests that mock Server's documented rejection exactly (status 400 +typeKey), per the issue's captured responses. Before the fix, these tests fail on unmodified code:azure-devops-api-request.test.ts› "retries with -preview when Azure DevOps Server rejects the api-version" — received only['7.1'], resolvednull(this is the "Auth failed" card)azure-devops-api-request.test.ts› "remembers the -preview requirement per origin" — received['7.1', '7.1']azure-devops-api-request.test.ts› "uses the remote-derived project base for Git endpoints…" — Git URL was/tfs/MyCollection/_apis/...(project segment stripped → Server answers "A project name is required")client.test.ts› "authenticates against an on-prem Server that requires -preview api-versions" andpull-request-creation.test.ts› "retries PR creation with -preview…" fail the same way pre-fix.Repro steps from the issue (needs a real Server): point a repo at
https://ado.example.com:8443/tfs/MyCollection/MyProject/_git/my-repo, setORCA_AZURE_DEVOPS_TOKEN+ORCA_AZURE_DEVOPS_API_BASE_URL=https://ado.example.com:8443/tfs/MyCollection, restart Orca, open the integration card → "Auth failed" despite a valid PAT.Screenshots
No visual change (main-process HTTP layer only; the existing integration card now reports authenticated on Server).
Testing
pnpm lint— oxlint onsrc/main/azure-devopsplus theaudit:code-quality:native,audit:code-quality:type-aware, andcheck:max-lines-ratchetgates on the changed scope, all cleanpnpm typecheck— all three projects (tsconfig.node,tsconfig.tc.cli,tsconfig.tc.web) passpnpm test— targeted suites pass:src/main/azure-devops+src/main/source-control(17 files, 159 tests), including the untouchedhosted-review-azure-devops.integration.test.tsproxy-style tests. A full local run was aborted mid-flight by machine-wide disk exhaustion (shared multi-agent machine), so its result is not claimable — relying on CI for the full suitepnpm build— not run; main-process TypeScript only, no packaging/bundling surface touched (covered by typecheck + CI)azure-devops-api-request.test.ts), 1 end-to-end auth-status test (client.test.ts), 1 PR-creation retry test (pull-request-creation.test.ts). All fail before the fix where they encode the bug.AI Review Report
Reviewed by Claude (this change was authored and self-reviewed agentically). Risks checked:
-preview, andshouldRetryWithPreviewApiVersion()refuses to fire when the request already had a-previewversion, so a host that rejects both cannot loop. The per-origin memo removes the extra 400 round trip after first contact.response.json(); non-preview failure paths still runcancelUnreadResponseBody()(safe on consumed bodies) so the undici unread-body crash guard (UncatchableAssertionError: assert(!this.paused)on socket end nodejs/undici#5360) is preserved.hosted-review-azure-devops.integration.test.tspassing.fetch/URL/env-var logic in the main process — no paths, shells, shortcuts, or Electron platform APIs touched; behavior is identical on all three platforms and for SSH/folder workspaces (requests always run on the client's main process). No renderer/wire changes, so no remote wire-compatibility impact.Flagged and addressed during review: the first draft removed the env override for Git endpoints entirely, which would have broken cross-origin proxy setups (including the reporter's interim workaround and our integration tests); narrowed to the same-origin rule instead.
Security Audit
Basic/Bearerheader construction from existing env vars; the retry re-sends the same headers to the same origin only (the retried URL is rebuilt from the same base + path, differing only in theapi-versionquery param). No credentials are logged; the rejection probe reads onlytypeKeyfrom the error body.URL.originof URLs Orca itself constructs from the configured base or the parsed remote; a hostile response body can at worst set a boolean that appends-previewto a version string on its own origin. No user-controlled string reaches command execution or the filesystem.Notes
-previewstill works because Server accepts-previewversions regardless.api-version=7.1; whichever lands second should adoptazureDevOpsApiVersionForOrigin()— noted so on-prem Server does not regress.