Skip to content

fix: dual-send API key for CG Manager delegate 401s - #828

Draft
thisrohangupta wants to merge 4 commits into
mainfrom
cursor/delegate-auth-401-plan-183e
Draft

fix: dual-send API key for CG Manager delegate 401s#828
thisrohangupta wants to merge 4 commits into
mainfrom
cursor/delegate-auth-401-plan-183e

Conversation

@thisrohangupta

@thisrohangupta thisrohangupta commented Aug 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

Delegate list/token calls were returning 401 while other NG APIs worked on the same session. Those paths are ingress-routed to CG Manager, which rejects inter-service JWTs and needs x-api-key or Authorization: Bearer.

Root cause

HarnessClient.applyDefaultAuth skipped injecting x-api-key whenever any Authorization header was already present. NG Manager could still authorize; CG Manager (/ng/api/delegate-setup, /ng/api/delegate-token-ng) returned 401. Error copy incorrectly blamed an expired API key.

Fix

  • Always inject x-api-key for non-FME requests (dual-send with existing Authorization).
  • On CG Manager delegate paths, replace non-Bearer Authorization (e.g. genaiservice …) with Bearer <configured PAT/SAT> when the key is not a placeholder.
  • Enrich 401 messages for those paths with CG Manager auth guidance.
  • FME auth behavior unchanged.

Tests

  • pnpm typecheck
  • pnpm exec vitest run tests/client/harness-client.test.ts — 81 passed

Follow-up

AskAI/mcpServerInternal still needs a CG-valid PAT/SAT if the session only has a genaiservice JWT — dual-auth cannot invent one. Live PAT smoke for delegate / delegate_token still pending.

Open in Web Open in Cursor 

cursoragent and others added 2 commits August 17, 2026 06:02
Document why delegate list returns 401 while other NG APIs work:
paths route to CG Manager, which rejects inter-service JWTs and
needs x-api-key/Bearer; applyDefaultAuth can skip x-api-key when
Authorization is already set.

Co-authored-by: Rohan Gupta <thisrohangupta@users.noreply.github.com>
Capture that delegate endpoints are CG-routed and need x-api-key/Bearer,
so Authorization-only sessions fail with a misleading 401.

Co-authored-by: Rohan Gupta <thisrohangupta@users.noreply.github.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

cursoragent and others added 2 commits August 17, 2026 06:08
Delegate-setup and delegate-token APIs are served by CG Manager, which
rejects inter-service JWTs that NG Manager accepts. Stop skipping
x-api-key when Authorization is already set, replace non-Bearer auth on
CG paths with Bearer from the configured PAT/SAT, and clarify 401s.

Co-authored-by: Rohan Gupta <thisrohangupta@users.noreply.github.com>
Co-authored-by: Rohan Gupta <thisrohangupta@users.noreply.github.com>
@cursor cursor Bot changed the title Plan: fix delegate 401 — CG Manager auth / missing x-api-key fix: dual-send API key for CG Manager delegate 401s Aug 17, 2026
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.

3 participants