mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 03:15:01 +00:00
fix(cloud): CODEX-EGRESS-BLOCKED say so when chatgpt.com refuses the egress proxy
chatgpt.com answers every request from Cloudflare Workers' egress IPs with a 403 "Unable to load site" HTML page, whatever the token (verified from a throwaway Worker; the same request from elsewhere gets a normal 401). Codex via the Orca account goes through the Worker egress proxy, so it got that page on /responses and /wham/usage: "Working…" without an answer, and /status had no limits. The proxy now recognises a provider edge's own refusal (403, text/html, server: cloudflare) on routes that define an answer for it, logs egress_upstream_blocked, and answers Codex in ChatGPT's error shape so Codex prints a plain message. The block says nothing about the credential: no status hook, so no refresh and no revoke. This doesn't make Codex work; routing chatgpt.com around the Worker is a separate decision.
This commit is contained in:
@@ -41,6 +41,8 @@ export type AccountProvider = {
|
||||
* normal sign-in message instead of a proxy error.
|
||||
*/
|
||||
signedOut?: { status: number; contentType: string; body: string }
|
||||
/** The provider's edge refused the egress proxy itself (CODEX-EGRESS-BLOCKED): what the agent shows. */
|
||||
upstreamBlocked?: { status: number; contentType: string; body: string }
|
||||
}
|
||||
|
||||
/** Anthropic's token counter: authenticated like Messages, free, and nothing is generated. */
|
||||
|
||||
@@ -186,6 +186,16 @@ export const codexAccount: AccountProvider = {
|
||||
detail: 'Orca Cloud can’t use your ChatGPT sign-in here. Check it in Orca: Settings → Agent accounts.'
|
||||
})
|
||||
},
|
||||
// CODEX-EGRESS-BLOCKED: chatgpt.com answers Cloudflare Workers' egress with a 403 "Unable to load
|
||||
// site" page, whatever the token. Same shape as signedOut, so Codex prints it and stops.
|
||||
upstreamBlocked: {
|
||||
status: 403,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
detail:
|
||||
'Orca Cloud can’t reach ChatGPT with your Orca account right now: ChatGPT refused Orca’s network, not your sign-in. Use another agent for now.'
|
||||
})
|
||||
},
|
||||
credential: async (db, keyring, userId, now) => {
|
||||
const value = await readUsableAgentCredential(db, keyring, userId, 'codex', now)
|
||||
const tokens = value ? parseStoredCodex(value) : null
|
||||
|
||||
@@ -51,6 +51,21 @@ export type ProxiedRoute = {
|
||||
keepResponseFields?: readonly string[]
|
||||
/** Names the swapped credential in the proxy's log line (never its value). */
|
||||
label?: string
|
||||
/**
|
||||
* CODEX-EGRESS-BLOCKED: what the client gets when the provider's own edge refused this proxy (a
|
||||
* Cloudflare 403 HTML page for Workers' egress IPs) instead of answering the request. The raw page
|
||||
* is never passed on: the client shows this message rather than an HTML dump or a retry loop.
|
||||
*/
|
||||
upstreamBlocked?: { status: number; contentType: string; body: string }
|
||||
}
|
||||
|
||||
/** A provider's edge refused the proxy itself: Cloudflare's 403 HTML page, not an API answer. */
|
||||
export function edgeBlocked(upstream: Response): boolean {
|
||||
return (
|
||||
upstream.status === 403 &&
|
||||
(upstream.headers.get('content-type') ?? '').toLowerCase().startsWith('text/html') &&
|
||||
(upstream.headers.get('server') ?? '').toLowerCase() === 'cloudflare'
|
||||
)
|
||||
}
|
||||
|
||||
export type EgressProxyDeps = {
|
||||
@@ -176,6 +191,15 @@ export async function handleEgressProxy(request: Request, deps: EgressProxyDeps)
|
||||
})
|
||||
// Names only: which sandbox, host and credential were swapped, and what the provider answered.
|
||||
secretLog('egress_swap', { sandboxId: row.id, host, credential: route.label ?? route.header, status: upstream.status }, [credential])
|
||||
if (route.upstreamBlocked && edgeBlocked(upstream)) {
|
||||
// The request never reached the provider: no status hook (it says nothing about the credential).
|
||||
secretLog('egress_upstream_blocked', { sandboxId: row.id, host, credential: route.label ?? route.header })
|
||||
await upstream.body?.cancel().catch(() => undefined)
|
||||
return new Response(route.upstreamBlocked.body, {
|
||||
status: route.upstreamBlocked.status,
|
||||
headers: { 'content-type': route.upstreamBlocked.contentType }
|
||||
})
|
||||
}
|
||||
route.onUpstreamStatus?.(upstream.status, { method: request.method, path })
|
||||
if (route.keepResponseFields) {
|
||||
return onlyFields(upstream, route.keepResponseFields)
|
||||
|
||||
@@ -415,6 +415,7 @@ function egressRoutes(env: Env, deps: Deps): (row: SandboxRow, host: string) =>
|
||||
placeholders: [provider.format(provider.placeholder(row))],
|
||||
label: `account:${agent}`,
|
||||
...(provider.pathAllowed ? { pathAllowed: provider.pathAllowed } : {}),
|
||||
...(provider.upstreamBlocked ? { upstreamBlocked: provider.upstreamBlocked } : {}),
|
||||
credential: async () => {
|
||||
// The agent sees the provider's own "sign in again" answer, not a proxy error.
|
||||
const signedOut = (reason: string) => ({ deny: reason, ...(provider.signedOut ? { answer: provider.signedOut } : {}) })
|
||||
|
||||
@@ -73,6 +73,8 @@ async function setup(overrides: Record<string, string> = {}) {
|
||||
const upstream: { url: string; headers: Headers }[] = []
|
||||
const tokenCalls: Record<string, unknown>[] = []
|
||||
const upstreamStatus = { value: 200 }
|
||||
// CODEX-EGRESS-BLOCKED: chatgpt.com's edge answering Workers' egress (what dev saw, 2026-11-15).
|
||||
const edgeBlock = { on: false }
|
||||
let tokenReply: () => Response = () =>
|
||||
Response.json({ access_token: ACCESS_2, refresh_token: REFRESH_2, id_token: ID })
|
||||
const h = await createHarness(
|
||||
@@ -82,6 +84,12 @@ async function setup(overrides: Record<string, string> = {}) {
|
||||
credentials: { authorizationFor: async () => null },
|
||||
egressFetch: async (input, init) => {
|
||||
upstream.push({ url: String(input), headers: new Headers(init?.headers) })
|
||||
if (edgeBlock.on) {
|
||||
return new Response('<html><body>Unable to load site</body></html>', {
|
||||
status: 403,
|
||||
headers: { 'content-type': 'text/html; charset=UTF-8', server: 'cloudflare' }
|
||||
})
|
||||
}
|
||||
return new Response('{}', { status: upstreamStatus.value })
|
||||
},
|
||||
codexTokenFetch: async (input, init) => {
|
||||
@@ -144,6 +152,7 @@ async function setup(overrides: Record<string, string> = {}) {
|
||||
proxied,
|
||||
upstream,
|
||||
upstreamStatus,
|
||||
edgeBlock,
|
||||
tokenCalls,
|
||||
signIn,
|
||||
refreshDeps: async () => ({ ...deps(), keyring: await deps().keyring }),
|
||||
@@ -460,3 +469,25 @@ describe('Codex lease refresher', () => {
|
||||
expect(await view()).toBe('none')
|
||||
})
|
||||
})
|
||||
|
||||
describe('CODEX-EGRESS-BLOCKED: chatgpt.com refuses the proxy itself', () => {
|
||||
it('answers with a message Codex prints, never the HTML page, and leaves the login alone', async () => {
|
||||
const { h, as, signIn, proxied, upstream, edgeBlock, tokenCalls } = await setup()
|
||||
const mia = await as('mia', 'acme', 'member')
|
||||
await signIn(mia)
|
||||
const created = await h.call('POST', '/v1/sandboxes', { body: { workspaceId: 'ws-1', machineSize: 'standard' }, bearer: mia })
|
||||
const id: string = created.body.sandbox.id
|
||||
const auth = { authorization: `Bearer ${codexPlaceholder({ id })}` }
|
||||
edgeBlock.on = true
|
||||
const refreshesBefore = tokenCalls.length
|
||||
const answer = await proxied(id, 'chatgpt.com', auth)
|
||||
expect(upstream.at(-1)!.url).toBe('https://chatgpt.com/backend-api/codex/responses')
|
||||
expect(answer.status).toBe(403)
|
||||
expect(answer.body).not.toContain('<html')
|
||||
expect(JSON.parse(answer.body).detail).toContain('ChatGPT refused Orca’s network')
|
||||
// Not a credential problem: no refresh, no revoke, the next request still swaps.
|
||||
expect(tokenCalls.length).toBe(refreshesBefore)
|
||||
edgeBlock.on = false
|
||||
expect((await proxied(id, 'chatgpt.com', auth)).status).toBe(200)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user