fix: cross-origin credentials not sent on agentex-ui API requests#165
Open
sayakmaity wants to merge 1 commit intomainfrom
Open
fix: cross-origin credentials not sent on agentex-ui API requests#165sayakmaity wants to merge 1 commit intomainfrom
sayakmaity wants to merge 1 commit intomainfrom
Conversation
…fetch wrapper The SDK's custom `fetch` option is not properly applied — the SDK calls window.fetch directly via Shims.getDefaultFetch(), bypassing the wrapper. This means `credentials: 'include'` was never sent on cross-origin requests from chat.dev-sgp.scale.com to agentex.dev-sgp.scale.com, causing 401s. The SDK does support `fetchOptions` which is properly merged into every request via the buildRequest() method. Switch to using that instead. Fixes SGPINF-1217
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
chat.dev-sgp.scale.comwhen making API calls toagentex.dev-sgp.scale.comfetchoption is not applied — the SDK internally callswindow.fetchviaShims.getDefaultFetch(), bypassing the wrapper. This meanscredentials: 'include'was never sent on cross-origin requests.fetchOptions: { credentials: 'include' }which the SDK properly merges into every request viabuildRequest()Root Cause
The
system-manager-configsecret hasurls.agentexBackend = agentex.dev-sgp.scale.com, causing the pack template to setapiBaseUrlto a cross-origin URL. Withoutcredentials: 'include', the browser doesn't send auth cookies on these cross-origin fetch requests, resulting in 401s.Additionally, the agentex backend's middleware ordering means 401 responses don't include CORS headers (
AgentexAuthMiddlewareruns beforeCORSMiddleware), which causes the browser to report CORS errors instead of 401s — masking the real issue.Test plan
chat.dev-sgp.scale.comloads agents successfullyagentex.dev-sgp.scale.comincludeCookieheaderFixes SGPINF-1217
Greptile Summary
This PR fixes cross-origin authentication failures on
chat.dev-sgp.scale.comby correcting howcredentials: 'include'is passed to the Agentex SDK client. The previous approach wrappingfetchwas silently bypassed — the SDK internally usesShims.getDefaultFetch()(i.e.window.fetch) rather than the providedfetchoption, so cookies were never included in cross-origin requests, resulting in 401 errors.Key changes:
fetchwrapper inAgentexProviderthat was never actually invoked by the SDK.fetchOptions: { credentials: 'include' }, which the SDK correctly merges into every outbound request (including streaming/SSE requests viabuildRequest()).agentex-provider.tsx.Confidence Score: 5/5
fetchwrapper was provably ineffective (the SDK bypasses it). The newfetchOptionsapproach is the standard pattern for Stainless-generated SDKs and will correctly attach credentials to all requests including streaming ones. No edge cases or regressions are introduced.Important Files Changed
fetchwrapper withfetchOptions: { credentials: 'include' }, which is properly merged by the SDK into every request. Clean, minimal fix with no new issues introduced.Sequence Diagram
sequenceDiagram participant Browser as Browser (chat.dev-sgp) participant SDK as AgentexSDK participant Backend as agentex.dev-sgp (API) Note over Browser,Backend: Before fix — credentials never sent Browser->>SDK: new AgentexSDK({ fetch: customWrapper }) SDK->>Backend: window.fetch(url) — bypasses customWrapper, no Cookie header Backend-->>SDK: 401 Unauthorized (no CORS header → masked as CORS error) SDK-->>Browser: CORS error in console Note over Browser,Backend: After fix — credentials always sent Browser->>SDK: new AgentexSDK({ fetchOptions: { credentials: 'include' } }) SDK->>Backend: window.fetch(url, { credentials: 'include' }) — Cookie header included Backend-->>SDK: 200 OK SDK-->>Browser: Agents/tasks load successfullyLast reviewed commit: 2c4ac96