Skip to content

fix(azure-devops): retry with -preview api-version and keep project-level Git base for on-prem Server (STA-3494) - #12832

Merged
brennanb2025 merged 2 commits into
mainfrom
brennanb2025/sta-3494-ado-preview-apiversion
Aug 6, 2026
Merged

brennanb2025 merged 2 commits into
mainfrom
brennanb2025/sta-3494-ado-preview-apiversion

Conversation

@brennanb2025

Copy link
Copy Markdown
Contributor

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/:

  1. Missing -preview api-version suffix. Every request hardcoded api-version=7.1, which Server rejects with HTTP 400 VssInvalidPreviewVersionException. requestAzureDevOpsJsonAtBase() collapsed that to null, so getAzureDevOpsAuthStatus() reported authenticated: false and the integration card sat on "Auth failed" forever, even with a valid PAT — indistinguishable from a bad token.
  2. Collection vs. project scope. On Server, connectionData lives 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

  • On a 400 whose body carries typeKey: "VssInvalidPreviewVersionException", retry the request once with -preview appended (e.g. 7.1-preview) and remember the requirement per origin, so subsequent requests to that host go straight to the -preview form. Cloud (dev.azure.com) behavior is unchanged — no extra round trips unless a host actually rejects.
  • The same retry-and-remember applies to PR creation (pull-request-creation.ts), which previously had its own hardcoded api-version=7.1. The preview rejection happens before the PR is created, so the single retry cannot double-create.
  • A configured ORCA_AZURE_DEVOPS_API_BASE_URL that 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 → 400 VssInvalidPreviewVersionException; ?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'], resolved null (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" and pull-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, set ORCA_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 on src/main/azure-devops plus the audit:code-quality:native, audit:code-quality:type-aware, and check:max-lines-ratchet gates on the changed scope, all clean
  • pnpm typecheck — all three projects (tsconfig.node, tsconfig.tc.cli, tsconfig.tc.web) pass
  • pnpm test — targeted suites pass: src/main/azure-devops + src/main/source-control (17 files, 159 tests), including the untouched hosted-review-azure-devops.integration.test.ts proxy-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 suite
  • pnpm build — not run; main-process TypeScript only, no packaging/bundling surface touched (covered by typecheck + CI)
  • Added or updated high-quality tests that would catch regressions: 5 new request-layer tests (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:

  • Retry loops / amplification: retry happens at most once per request; the retried URL carries -preview, and shouldRetryWithPreviewApiVersion() refuses to fire when the request already had a -preview version, so a host that rejects both cannot loop. The per-origin memo removes the extra 400 round trip after first contact.
  • Response-body handling: the preview-rejection probe reads the 400 body via response.json(); non-preview failure paths still run cancelUnreadResponseBody() (safe on consumed bodies) so the undici unread-body crash guard (Uncatchable AssertionError: assert(!this.paused) on socket end nodejs/undici#5360) is preserved.
  • Behavior change blast radius: the base-URL scope change only reorders precedence when the configured base and the remote-derived base share an origin (previously guaranteed-broken on Server for one endpoint class or the other, and silently wrong cross-project on cloud). Cross-origin overrides — the only configuration the shipped integration tests exercise — are untouched, verified by the unchanged hosted-review-azure-devops.integration.test.ts passing.
  • Non-preview 400s: unchanged classification; a plain validation 400 does not retry (dedicated test).
  • Cross-platform (macOS/Linux/Windows): change is pure 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

  • Auth/secrets: credential handling untouched — same Basic/Bearer header 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 the api-version query param). No credentials are logged; the rejection probe reads only typeKey from the error body.
  • Input handling: the per-origin memo keys on URL.origin of URLs Orca itself constructs from the configured base or the parsed remote; a hostile response body can at worst set a boolean that appends -preview to a version string on its own origin. No user-controlled string reaches command execution or the filesystem.
  • SSRF surface: unchanged — requests still go only to the configured base URL or the remote-derived base, same as before.
  • Dependencies/IPC: none added, none touched.

Notes

  • The preview-requirement memo is per-origin and process-lifetime; a Server upgrade that stops requiring -preview still works because Server accepts -preview versions regardless.
  • Error surfacing (the card cannot distinguish "bad token" from "server rejected the request", suggested fix 3 in the issue) is deliberately left out to keep this tightly scoped; it touches the status wire shape consumed by the renderer and deserves its own change.
  • Both open Azure CLI auth PRs (feat(azure-devops): authenticate via az CLI Entra login with token fallback #12201, Connect Azure DevOps with the Azure CLI without a PAT #6735) carry their own hardcoded api-version=7.1; whichever lands second should adopt azureDevOpsApiVersionForOrigin() — noted so on-prem Server does not regress.

…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.
@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@brennanb2025, you've reached your PR review limit, so we couldn't start this review.

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: f184cdd8-d1cd-4f27-b04b-d04a9514d124

📥 Commits

Reviewing files that changed from the base of the PR and between 44ec877 and d384c0a.

📒 Files selected for processing (3)
  • src/main/azure-devops/azure-devops-api-request.test.ts
  • src/main/azure-devops/azure-devops-api-request.ts
  • src/main/azure-devops/pull-request-creation.test.ts
📝 Walkthrough

Walkthrough

Azure DevOps requests now detect preview-version rejection responses, retry with a -preview version, and cache that version per origin. Git requests resolve same-origin and cross-origin API bases differently. Pull-request creation uses the shared request wrapper for API-version selection, timeout handling, and retry behavior. Tests cover caching, error handling, base resolution, on-premises authentication, and pull-request creation.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the Azure DevOps preview-version retry and on-premises Git base URL fixes.
Description check ✅ Passed The description covers the required sections, explains the changes and risks, and documents testing limitations and follow-up work.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 630f13b and 44ec877.

📒 Files selected for processing (5)
  • src/main/azure-devops/azure-devops-api-request.test.ts
  • src/main/azure-devops/azure-devops-api-request.ts
  • src/main/azure-devops/client.test.ts
  • src/main/azure-devops/pull-request-creation.test.ts
  • src/main/azure-devops/pull-request-creation.ts

@brennanb2025

Copy link
Copy Markdown
Contributor Author

Electron QA evidence

Validated the exact PR worktree (brennanb2025/sta-3494-ado-preview-apiversion) in an isolated Electron profile via CDP. A local Azure DevOps Server mock returned HTTP 400 + VssInvalidPreviewVersionException for api-version=7.1, then accepted api-version=7.1-preview; the rendered Settings > Integrations card visibly reported STA-3494 QA Server · Connected. Playwright reported 0 console errors.

STA-3494 Azure DevOps Server connected after preview retry

@brennanb2025
brennanb2025 merged commit b81450f into main Aug 6, 2026
43 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…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
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.

1 participant