Skip to content

Commit 880d2e6

Browse files
authored
Merge pull request #973 from lidge-jun/codex/stack6-overnight-triage
stack 6/7: triage the overnight PRs and fix the #955 defects they found
2 parents eb2ceb2 + dbe935a commit 880d2e6

10 files changed

Lines changed: 573 additions & 22 deletions

File tree

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
# 000 — Overnight PR triage: nine PRs, four verdicts
2+
3+
Nine pull requests arrived overnight while the #951–#955 stack was in review.
4+
The question for each: does it duplicate work already on the stack, is it a real
5+
independent defect, or does it belong somewhere else entirely.
6+
7+
Measured 2026-08-04 against `origin/dev` and the stack head
8+
`codex/915-cooldown-recovery-probe` at `493329df0`.
9+
10+
## Verdicts
11+
12+
| PR | Author | Verdict | Action |
13+
|---|---|---|---|
14+
| #967 | @Yuxin-Qiao | **two real defects in OUR #955** | carry onto layer 6 |
15+
| #965 | @Yuxin-Qiao | correct fix for #962 | carry onto layer 6 |
16+
| #963 | @MarcTCruz | duplicate of #965, broader and weaker | close, name #965 |
17+
| #968 | @DevMello | real independent defect | carry onto layer 6 |
18+
| #964 | @Yuxin-Qiao | real independent defect (#956) | leave open, own review |
19+
| #966 | @Yuxin-Qiao | partial fix, fifth falsified design | leave open, request changes |
20+
| #970 | @stephen-drew | real, out of stack scope | leave open |
21+
| #961 | @Yuxin-Qiao | feature, not a bug | leave open |
22+
| #969 | @Wibias | CI governance policy | out of scope |
23+
24+
## #967 — the one that matters most
25+
26+
@Yuxin-Qiao reviewed #955 and found two defects **in my own code**. Both verify.
27+
28+
**P1: monthly-classified snapshots were rejected.** My
29+
`isCompleteCodexQuotaRecoverySnapshot()` picked the required window from the
30+
plan NAME. The parser picks it from the window DURATION
31+
(`isExplicitMonthlyWindow()`, `src/codex/quota.ts:104-109`), and a Team response
32+
whose primary window is explicitly monthly parses to `monthlyPercent` only. So
33+
the probe rejected every successful fresh read for those accounts:
34+
35+
```console
36+
$ bun run .tmp/probe_967.ts # on the stack head, BEFORE the fix
37+
parsed = {"monthlyPercent":12,"monthlyResetAt":1900000000}
38+
recoverable? = false <-- Team monthly account can never recover
39+
weekly parsed = {"weeklyPercent":12,"weeklyResetAt":1900000000}
40+
recoverable? = true
41+
```
42+
43+
That is the same "cooled forever" failure #915 exists to fix, reintroduced for
44+
monthly-window plans. It is also the *third* time this predicate has been wrong
45+
in the same direction — first the plan allowlist, then `prolite`, now the
46+
window-classification mismatch. The lesson has been consistent and I kept
47+
missing it: this predicate must read what the parser actually wrote, never
48+
re-derive the classification itself.
49+
50+
**P2: the probe's own token refresh looked like a replacement.**
51+
`getValidCodexToken()` refreshes a near-expiry token inside the probe fetch and
52+
advances the credential generation by exactly one
53+
(`src/codex/account-store.ts:415-421`). My settle required the claim-time
54+
generation to match exactly, so a successful fresh read under the refreshed
55+
generation was thrown away and recovery waited another five minutes.
56+
57+
The fix fences the +1 transition on `replacedAt`, which is the right
58+
discriminator:
59+
`saveCodexAccountCredentialIfGeneration()` **preserves** `replacedAt`
60+
(`:195-217`) while `saveCodexAccountCredential()` **stamps a fresh one**
61+
(`:131-146`). So a probe-owned refresh and an external replacement are
62+
distinguishable even though both bump the generation.
63+
64+
Verified after the fix — every fail-closed guard still holds:
65+
66+
```console
67+
credits-only -> false windowless {} -> false null -> false
68+
exhausted 100 -> false go+weeklyOnly -> false
69+
team monthly -> true team weekly -> true
70+
```
71+
72+
Red-green: ablating P1 fails 2 tests, ablating P2 fails 1 different test.
73+
74+
## #963 vs #965 — the duplicate pair
75+
76+
Both claim "Fixes #962", both edit `src/codex/catalog/provider-fetch.ts`.
77+
**#965 wins.**
78+
79+
#962 is specifically about a custom row *replacing* a same-slug provider row.
80+
#965 models exactly that: it indexes the rows deduplication will replace and
81+
fills only undefined capability fields from the replaced row, so it also
82+
inherits live `/models` metadata such as normalized `capabilities`.
83+
84+
#963 instead recomputes `catalogHintsFromProviderConfig()` for **every** custom
85+
row, including custom-only rows with no provider counterpart — broader than
86+
#962 requires. It cannot retain discovered metadata, since it rebuilds from
87+
config rather than inheriting. And it rewrites an existing regression contract
88+
to fit: `tests/catalog-vision-sidecar-modalities.test.ts` changes from "no
89+
registry reasoning metadata leaks onto an unmatched custom override" to
90+
expecting that leak, and drops three `fetch should not be called` guards.
91+
92+
Changing a test that encodes a deliberate prior decision, in order to make a
93+
broader change pass, is the part that decides this. #965's ablation fails
94+
exactly one test — the #962 regression — which is what a focused fix looks like.
95+
96+
## #966 — a fifth design, still falsified
97+
98+
#966 targets #914, which four prior designs already failed at an audit gate
99+
(`devlog/_plan/260803_transport_attribution/000_plan.md`). It is a genuine
100+
advance: it uses the real Bun 1.3.14 error labels including both alternating
101+
ones, it does **not** repeat the hostname-resolution design, and it closes the
102+
redirect counterexample on the pool Responses and Compact paths with manual
103+
redirects. TLS/fake-IP codes correctly stay account-scoped.
104+
105+
But two falsifications survive, both reproduced live:
106+
107+
**Mixed 5xx → rejection still loses the attributable failure.**
108+
`fetchWithTransientRetry()` discards prior transient responses when a later
109+
attempt rejects (`src/lib/upstream-retry.ts:220-236`), so a genuine 503 followed
110+
by a connection refusal is recorded as account-neutral. That is precisely the
111+
hole the earlier audit documented.
112+
113+
**Falsification 3 survives on five expanded surfaces.** Manual redirects were
114+
added only to Responses and Compact; the five sidecar paths #966 newly
115+
classifies still use default-follow fetch, so a credential-bearing sidecar that
116+
receives a 307 to a dead host is misclassified as neutral — after the origin
117+
already read the `Authorization` header:
118+
119+
```text
120+
redirect:"follow" serverSawAuthorization:"Bearer credential-follow" resolved:false
121+
redirect:"manual" serverSawAuthorization:"Bearer credential-manual" resolved:true 307
122+
```
123+
124+
So #966 is not mergeable as-is, and its sidecar expansion carries the unresolved
125+
hole *beyond* #914's original sites. It does supersede #922 (which misses one
126+
Bun label entirely, keeps default redirects, and bundles unrelated probe-lease
127+
work while sitting at `CHANGES_REQUESTED`).
128+
129+
Neither lands on our stack. #914 remains open with a fifth design on record.
130+
131+
## The rest
132+
133+
**#968** (@DevMello) — the google adapter dropped `tool_choice` entirely: `none`,
134+
`required`, and a forced tool all produced a wire body identical to `auto`, with
135+
only a prose nudge in the system prompt. The wire compiler already validated
136+
`toolConfig.functionCallingConfig`; the adapter simply never built it. Carries
137+
cleanly onto the stack; same author as the already-carried #943.
138+
139+
**#964** (@Yuxin-Qiao) — the `nvidia` registry entry lacks `noVisionModels`, so
140+
the vision sidecar never activates for NIM text-only models and raw image parts
141+
reach a text-only upstream. Real, but it is a registry/provider change with no
142+
relationship to this stack's theme; it deserves its own review rather than a
143+
ride on a bug stack.
144+
145+
**#970** (@stephen-drew) — service re-registration during self-update. Real, but
146+
30 files across CLI, GUI, and five docs locales, touching a
147+
permission-sensitive install path. Out of scope here.
148+
149+
**#961** — provider custom headers via PATCH. A feature, not a bug.
150+
151+
**#969** (@Wibias, collaborator) — CI policy that auto-drafts contributor PRs
152+
until a checklist is complete. Out of scope: it is a workflow change requiring
153+
security review per `AGENTS.md`, and it encodes a contribution policy that is
154+
the maintainer's call, not a bug fix. Worth noting the history — the #900–#905
155+
stack was closed on exactly this kind of policy question, not on its mechanics.
156+
157+
## Layer 6 contents
158+
159+
Carry, in order: #967 (fixes our own defects), #965 (catalog), #968 (google
160+
tool_choice). Everything else stays where it is, with a reason on record.

‎src/adapters/google.ts‎

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type {
1212
OcxToolCall,
1313
OcxUsage,
1414
} from "../types";
15-
import { isAllowedToolChoice, namespacedToolName, toolAllowedByChoice } from "../types";
15+
import { isAllowedToolChoice, namespacedToolName, resolveToolChoiceWireName, toolAllowedByChoice } from "../types";
1616
import { contentPartsToText, parseDataUrl } from "./image";
1717
import { getVertexAccessToken } from "../lib/gcp-adc";
1818
import { fetchAntigravityWithRetry, fetchVertexWithRetry } from "./google-http";
@@ -232,6 +232,28 @@ function toolsToGeminiFormat(parsed: OcxParsedRequest): unknown[] | undefined {
232232
}];
233233
}
234234

235+
/**
236+
* Client tool_choice enforcement on the wire. The catalog nudge states the same contract in
237+
* prose, but without functionCallingConfig the model is free to ignore it. "auto" stays absent
238+
* so the common case is byte-identical. The allowedTools variant already filters the
239+
* declarations in toolsToGeminiFormat; only its "required" half needs a wire mode.
240+
*/
241+
function toolChoiceToGeminiToolConfig(parsed: OcxParsedRequest): Record<string, unknown> | undefined {
242+
const choice = parsed.options.toolChoice;
243+
if (!choice || choice === "auto") return undefined;
244+
if (choice === "none") return { functionCallingConfig: { mode: "NONE" } };
245+
if (choice === "required") return { functionCallingConfig: { mode: "ANY" } };
246+
if (isAllowedToolChoice(choice)) {
247+
return choice.mode === "required" ? { functionCallingConfig: { mode: "ANY" } } : undefined;
248+
}
249+
return {
250+
functionCallingConfig: {
251+
mode: "ANY",
252+
allowedFunctionNames: [resolveToolChoiceWireName(parsed.context.tools, choice.name)],
253+
},
254+
};
255+
}
256+
235257
function usageFromGemini(usage: Record<string, number> | undefined): OcxUsage | undefined {
236258
if (!usage) return undefined;
237259
return {
@@ -307,6 +329,10 @@ export function createGoogleAdapter(provider: OcxProviderConfig): ProviderAdapte
307329
const body: Record<string, unknown> = { contents };
308330
if (systemInstruction) body.systemInstruction = systemInstruction;
309331
if (tools) body.tools = tools;
332+
// Only meaningful with declarations on the wire: mode ANY with an empty
333+
// catalog is a guaranteed upstream 400.
334+
const toolConfig = tools ? toolChoiceToGeminiToolConfig(parsed) : undefined;
335+
if (toolConfig) body.toolConfig = toolConfig;
310336

311337
const generationConfig: Record<string, unknown> = {};
312338
if (parsed.options.maxOutputTokens) generationConfig.maxOutputTokens = parsed.options.maxOutputTokens;
@@ -358,6 +384,12 @@ export function createGoogleAdapter(provider: OcxProviderConfig): ProviderAdapte
358384
const draftRequest: Record<string, unknown> = { ...body, sessionId };
359385
// Claude-on-Antigravity forces VALIDATED function calling (the real client always sets it).
360386
if (/claude/i.test(wireModelId)) {
387+
// VALIDATED would defeat a client's tool_choice "none": honor it by dropping the
388+
// declarations instead, the wire shape of a tool-less Claude turn.
389+
if (parsed.options.toolChoice === "none") {
390+
delete draftRequest.tools;
391+
delete draftRequest.toolConfig;
392+
}
361393
const existing = (draftRequest.toolConfig ?? {}) as Record<string, unknown>;
362394
const fcc = (existing.functionCallingConfig ?? {}) as Record<string, unknown>;
363395
draftRequest.toolConfig = { ...existing, functionCallingConfig: { ...fcc, mode: "VALIDATED" } };

‎src/codex/catalog/provider-fetch.ts‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -782,6 +782,9 @@ async function gatherRoutedModelsUncached(
782782
// Enriched (registry-hydrated) provider clones, keyed by name — the same view used above so
783783
// custom rows get the same noVisionModels / inputModalities treatment as discovered rows.
784784
const enrichedByName = new Map(activeProviders);
785+
// Provider-derived rows keyed by their Codex-facing slug: a custom override replaces the row
786+
// with the same slug below, so that row's provider capability metadata is the inheritance source.
787+
const replacedByRoutedSlug = new Map(all.map(model => [routedSlug(model.provider, model.id), model]));
785788
const customModels = (config.customModels ?? []).map(cm => {
786789
const rawProvider = config.providers[cm.provider];
787790
const supportsReasoningSummaries = configuredReasoningSummarySupport(rawProvider, cm.modelId);
@@ -794,19 +797,38 @@ async function gatherRoutedModelsUncached(
794797
...(cm.inputModalities ? { inputModalities: cm.inputModalities } : {}),
795798
...(typeof supportsReasoningSummaries === "boolean" ? { supportsReasoningSummaries } : {}),
796799
};
800+
// #962: the dedupe below drops the provider-derived row this custom row replaces. Inherit that
801+
// row's provider capability metadata (reasoning ladder, default effort, parallel tool calls,
802+
// context, ...) so the generated catalog keeps advertising what the router actually provides.
803+
// Explicit custom fields win by construction; this only fills gaps. Without it a
804+
// noReasoningModels model loses its empty ladder and the catalog synthesizes the generic one,
805+
// which Codex then rejects for spawn_agent with effort "none".
806+
const replaced = replacedByRoutedSlug.get(routedSlug(cm.provider, cm.modelId));
807+
const merged: CatalogModel = replaced ? {
808+
...base,
809+
...(base.contextWindow === undefined && replaced.contextWindow !== undefined ? { contextWindow: replaced.contextWindow } : {}),
810+
...(base.maxInputTokens === undefined && replaced.maxInputTokens !== undefined ? { maxInputTokens: replaced.maxInputTokens } : {}),
811+
...(base.inputModalities === undefined && replaced.inputModalities !== undefined ? { inputModalities: replaced.inputModalities } : {}),
812+
...(base.reasoningEfforts === undefined && replaced.reasoningEfforts !== undefined ? { reasoningEfforts: replaced.reasoningEfforts } : {}),
813+
...(base.defaultReasoningEffort === undefined && replaced.defaultReasoningEffort !== undefined ? { defaultReasoningEffort: replaced.defaultReasoningEffort } : {}),
814+
...(base.parallelToolCalls === undefined && replaced.parallelToolCalls !== undefined ? { parallelToolCalls: replaced.parallelToolCalls } : {}),
815+
...(base.supportsVerbosity === undefined && replaced.supportsVerbosity !== undefined ? { supportsVerbosity: replaced.supportsVerbosity } : {}),
816+
...(base.supportsReasoningSummaries === undefined && replaced.supportsReasoningSummaries !== undefined ? { supportsReasoningSummaries: replaced.supportsReasoningSummaries } : {}),
817+
...(base.capabilities === undefined && replaced.capabilities !== undefined ? { capabilities: replaced.capabilities } : {}),
818+
} : base;
797819
// Vision-sidecar coverage ONLY: if the custom model is in the enriched provider's
798820
// noVisionModels, advertise image input so the Codex app lets images reach the sidecar
799821
// (#349/#344). Deliberately NOT the full applyProviderConfigHints pass — custom rows are a
800822
// user override, so their explicit contextWindow / inputModalities / reasoning fields must be
801823
// preserved verbatim (the hint pass would cap context and overwrite modalities from registry).
802824
const enrichedProvider = enrichedByName.get(cm.provider) ?? rawProvider;
803-
if (enrichedProvider && modelInList(enrichedProvider.noVisionModels, base.id)) {
804-
const current = base.inputModalities ?? ["text"];
825+
if (enrichedProvider && modelInList(enrichedProvider.noVisionModels, merged.id)) {
826+
const current = merged.inputModalities ?? ["text"];
805827
if (!current.includes("image")) {
806-
return { ...base, inputModalities: [...current, "image"] };
828+
return { ...merged, inputModalities: [...current, "image"] };
807829
}
808830
}
809-
return base;
831+
return merged;
810832
});
811833
// Custom rows override discovered rows that encode to the same Codex-facing slug.
812834
const customKeys = new Set(customModels.map(c => routedSlug(c.provider, c.id)));

0 commit comments

Comments
 (0)