Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/server/search.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { codexAccountFetch } from "../codex/account-egress-runtime";
import { CodexInstallationIdUnavailableError } from "../codex/installation-id";
import { isolateCodexPoolClientMetadata, mergeCodexSelectedHeaders } from "../codex/forward-transport-headers";
/**
Expand Down Expand Up @@ -207,7 +208,7 @@ export async function handleSearch(
let upstreamResponse: Response | undefined;
try {
upstream.beforeDispatch?.();
upstreamResponse = await fetch(url, {
upstreamResponse = await codexAccountFetch(codexLogAccountId(upstream.authContext), { config })(url, {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Local search proxy refusals can switch the active Codex account

When process NO_PROXY conflicts with a Pool account’s HTTP proxy, search records the local refusal as an upstream connection failure. Repeated unqualified searches can switch the active account even though no search reached ChatGPT.

Learn more

The ChatGPT search relay now uses codexAccountFetch for pool traffic. If process NO_PROXY exempts ChatGPT, configuredOutboundFetch rejects an explicitly selected HTTP proxy before opening a connection. The search error handler passes that refusal to the unqualified sidecar’s outcome recorder as connect_error. recordCodexUpstreamOutcome adds to the selected account’s transient failure streak and calls applyFailureFailover for an active account. With an eligible sibling, this updates the shared active selection rather than just returning a search error.

Example: With account A active, account B eligible, and the default threshold of three, three ordinary unqualified searches select A and hit the same local proxy refusal. The third failure can promote B, so fixing A’s proxy settings does not undo the account switch.

Recommended fix: Handle typed pre-send route refusals separately in handleSearch. Release the probe lease and return a local route error without recording an upstream outcome. Add a regression test for a valid HTTP proxy conflicting with process NO_PROXY that checks both zero sends and unchanged Pool health.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 SOCKS5 searches fail before longer configured deadlines

Account-routed SOCKS5 searches inherit a 200-second idle timeout from socks5Fetch. A search that sends no headers during that interval returns 502 even when its configured deadline allows it to finish.

Learn more

The search handler creates an abort signal for the configured total deadline. Applying an account-specific SOCKS5 route makes configuredOutboundFetch use socks5Fetch, which also installs a fixed 200-second upstream socket idle timer. The search contract explains why a healthy request can send no response headers until the search finishes. If the socket timer fires first, it throws Socks5FetchError, not TimeoutError, and the search error handler returns 502 because the request deadline has not yet expired.

Example: With search.timeoutMs set to 240,000, a search that sends its first response headers 210 seconds after dispatch is cut off at 200 seconds when the selected account uses SOCKS5.

Recommended fix: Let this relay pass its upstream deadline policy through the account-aware transport, so the SOCKS5 response idle timer does not preempt the search budget. Keep the SOCKS5 connection and handshake guards and retain the fixed default for callers that do not supply a response budget.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

method: "POST",
headers,
body: JSON.stringify(isolateCodexPoolClientMetadata(
Expand Down
2 changes: 2 additions & 0 deletions structure/providers/codex-installation-identity.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ retain the selected context and project cloned client metadata immediately befor
JSON send, including live's converted multipart session. Live inspects JSON content independently
of Content-Type; non-JSON SDP retains its original bytes. Their selected headers authoritatively
replace or remove mixed-case provider identity defaults; main and main-pool preserve caller values.
Search also resolves the selected Pool account's outbound route at its physical send boundary;
an account route overrides the OpenAI provider route, and an invalid route refuses the send.
Comment on lines +79 to +80

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Public proxy docs still exclude unqualified Pool search

Unqualified search now uses account-aware egress when it selects a Pool account. The provider configuration guide still says unqualified search has no provider route. Update it to distinguish Pool search from caller-owned search.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Vision, audio and sidecar credential selection share materialization.
Dictation in `src/server/audio-dictation.ts` has a 600,000 ms recording budget and
opts into a separate 60,000 ms finalization window after a validated `session.close`.
Expand Down
58 changes: 58 additions & 0 deletions tests/server/server-search.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,64 @@ test("an account-qualified search model uses that exact account and sends the ba
}
});

test("an account-qualified search leaves through its selected account route", async () => {
const accountProxy = "http://127.0.0.1:9/";
const providerProxy = "http://127.0.0.1:11/";
const config = exactSearchConfig();
config.providers.openai!.proxy = providerProxy;
config.codexAccounts = config.codexAccounts?.map(account => account.id === "pool-a"
? { ...account, egress: { proxy: accountProxy } }
: account);
saveExactSearchCredentials();
const sends: Array<{ proxy: unknown; authorization: string | null; account: string | null; body: unknown }> = [];
globalThis.fetch = (async (_input: RequestInfo | URL, init?: RequestInit) => {
const headers = new Headers(init?.headers);
sends.push({
proxy: (init as { proxy?: unknown } | undefined)?.proxy,
authorization: headers.get("authorization"),
account: headers.get("chatgpt-account-id"),
body: typeof init?.body === "string" ? JSON.parse(init.body) : undefined,
});
return Response.json({ encrypted_output: "ciphertext", output: "search result" });
}) as typeof fetch;
Comment on lines +336 to +345

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Search tests check the proxy option, not the network path

The stub confirms which proxy option search passes to fetch, not which route Bun uses. The PR reports no runtime checks. Run the focused search tests and use the loopback proxy tests as a model for verifying the physical route.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.


const response = await handleSearch(
alphaSearchRequest({ id: "search-session", model: "side/gpt-test" }),
config,
{ model: "", provider: "" },
);

expect(response.status).toBe(200);
expect(sends).toEqual([{
proxy: accountProxy,
authorization: "Bearer pool-a-token",
account: "acct-pool-a",
body: { id: "search-session", model: "gpt-test" },
}]);
});

test("an invalid selected account route refuses search before dispatch", async () => {
const config = exactSearchConfig();
config.codexAccounts = config.codexAccounts?.map(account => account.id === "pool-a"
? { ...account, egress: { proxy: "not-a-proxy-route" } }
: account);
saveExactSearchCredentials();
let sends = 0;
globalThis.fetch = (async () => {
sends += 1;
return Response.json({ output: "must not dispatch" });
}) as typeof fetch;

const response = await handleSearch(
alphaSearchRequest({ id: "search-session", model: "side/gpt-test" }),
config,
{ model: "", provider: "" },
);

expect(response.status).toBe(502);
expect(sends).toBe(0);
});

test("an exact search 429 never switches to the active Pool account and reports only its public selector", async () => {
const captured: CapturedRequest[] = [];
const upstream = fakeSearchUpstream(captured, 429, { error: { message: "rate limited" } });
Expand Down
Loading