@bitkyc08/opencodex 2.100.3 → 2.100.5-preview.20261118.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/AGENTS_INSTALL.md +23 -1
  2. package/bin/ocx.mjs +8 -1
  3. package/gui/dist/assets/{App-Dnb6VMsP.js → App-BiOGtxDS.js} +21 -20
  4. package/gui/dist/assets/{Tray-BV4ms9U9.js → Tray-BwsMejUO.js} +1 -1
  5. package/gui/dist/assets/brand-mark-BY1dgACL.js +1 -0
  6. package/gui/dist/assets/{index-DCdXsMyZ.js → index-CwHSKMdG.js} +46 -13
  7. package/gui/dist/assets/index-DJxM-imn.css +2 -0
  8. package/gui/dist/assets/{segment-thumb-features-DXSidY6D.js → segment-thumb-features-Bds9Hb_7.js} +1 -1
  9. package/gui/dist/classic/assets/{App-DA-scMPq.js → App-CGLOiqQL.js} +20 -19
  10. package/gui/dist/classic/assets/{Tray-BrHaVRAq.js → Tray-Da4r2O70.js} +1 -1
  11. package/gui/dist/classic/assets/{index-BqOaGLf5.js → index-CvoKXKL9.js} +46 -13
  12. package/gui/dist/classic/assets/quota-summary-DvqzfCmr.js +1 -0
  13. package/gui/dist/classic/index.html +1 -1
  14. package/gui/dist/index.html +2 -2
  15. package/native/ocx-child/src/cli.rs +5 -3
  16. package/native/ocx-child/src/codex_home.rs +1 -0
  17. package/native/ocx-child/src/link_ws.rs +24 -19
  18. package/native/ocx-child/src/link_ws_frame.rs +136 -50
  19. package/package.json +3 -3
  20. package/src/adapters/anthropic/per-message-effort.ts +296 -0
  21. package/src/adapters/anthropic-input-schema.ts +270 -0
  22. package/src/adapters/anthropic.ts +4 -63
  23. package/src/adapters/claude-cli/adapter.ts +1 -0
  24. package/src/adapters/command-code-tool-text.ts +9 -1
  25. package/src/adapters/command-code.ts +18 -2
  26. package/src/adapters/devin/cloud-direct/chat.ts +95 -14
  27. package/src/adapters/devin/live-models.ts +11 -1
  28. package/src/adapters/google-errors.ts +14 -2
  29. package/src/adapters/kiro/reasoning.ts +3 -0
  30. package/src/adapters/kiro-tools.ts +14 -9
  31. package/src/adapters/openai-responses/passthrough.ts +3 -1
  32. package/src/adapters/openai-responses/request-strips.ts +1 -0
  33. package/src/adapters/qoder/adapter.ts +9 -1
  34. package/src/adapters/tool-catalog-nudge.ts +1 -1
  35. package/src/adapters/zed.ts +4 -2
  36. package/src/claude/chat-tool-dispatch.ts +4 -1
  37. package/src/claude/desktop-remote-store.ts +60 -10
  38. package/src/cli/account-api.ts +4 -0
  39. package/src/cli/account-auth.ts +30 -2
  40. package/src/cli/account-extended.ts +33 -2
  41. package/src/cli/capabilities-access-remote.ts +3 -3
  42. package/src/cli/capabilities-accounts.ts +3 -3
  43. package/src/cli/capabilities-base.ts +11 -6
  44. package/src/cli/capabilities-observe-system.ts +2 -2
  45. package/src/cli/claude.ts +3 -3
  46. package/src/cli/disconnect-runtime.ts +16 -6
  47. package/src/cli/dispatch.ts +7 -1
  48. package/src/cli/index.ts +2 -2
  49. package/src/cli/link-apply-restart.ts +4 -2
  50. package/src/cli/link-routes.ts +4 -1
  51. package/src/cli/link.ts +5 -4
  52. package/src/cli/logout-command.ts +23 -4
  53. package/src/cli/preflight-exemptions.ts +3 -0
  54. package/src/cli/provider.ts +3 -2
  55. package/src/cli/registry.ts +5 -2
  56. package/src/cli/resolve.ts +23 -8
  57. package/src/cli/restart-failure.ts +11 -1
  58. package/src/cli/runtime-api.ts +4 -0
  59. package/src/cli/status.ts +4 -1
  60. package/src/cli/system-command.ts +1 -1
  61. package/src/cli/system-restart-client.ts +9 -3
  62. package/src/cli/system-settings-parity.ts +2 -1
  63. package/src/client/connect.ts +73 -11
  64. package/src/client/desktop-refusal.ts +38 -0
  65. package/src/client/lifecycle-lock.ts +29 -4
  66. package/src/client/runtime-restart.ts +27 -15
  67. package/src/client/runtime.ts +4 -2
  68. package/src/client/state.ts +14 -0
  69. package/src/clients/config-export.ts +12 -7
  70. package/src/codex/account-lifecycle.ts +3 -1
  71. package/src/codex/account-pause.ts +4 -0
  72. package/src/codex/account-runtime-state.ts +4 -0
  73. package/src/codex/auth-api/main-account-probe.ts +3 -1
  74. package/src/codex/auth-api/main-hard-lock-refusal-read.ts +172 -0
  75. package/src/codex/auth-context.ts +40 -2
  76. package/src/codex/catalog/build-entries.ts +10 -0
  77. package/src/codex/catalog/derive-entry.ts +7 -0
  78. package/src/codex/catalog/metadata.ts +8 -0
  79. package/src/codex/catalog/native-models.ts +16 -6
  80. package/src/codex/catalog/pinned-models.ts +1 -0
  81. package/src/codex/catalog/provider-models.ts +5 -5
  82. package/src/codex/catalog/reserve-warn.ts +7 -5
  83. package/src/codex/catalog/reserve.ts +4 -3
  84. package/src/codex/catalog/retained-sync.ts +2 -0
  85. package/src/codex/catalog/routed-defaults.ts +35 -0
  86. package/src/codex/catalog-auto-refresh.ts +13 -2
  87. package/src/codex/config-drift-heal.ts +40 -12
  88. package/src/codex/config-write-lock.ts +39 -1
  89. package/src/codex/convergence.ts +2 -0
  90. package/src/codex/data/roster-pinned-models.json +346 -1
  91. package/src/codex/inject/config-write-section.ts +39 -1
  92. package/src/codex/inject/plan.ts +10 -8
  93. package/src/codex/inject/remove.ts +21 -19
  94. package/src/codex/inject/restore.ts +5 -1
  95. package/src/codex/inject-coordination.ts +58 -7
  96. package/src/codex/inject.ts +10 -12
  97. package/src/codex/journal-config-restore.ts +42 -0
  98. package/src/codex/journal.ts +62 -8
  99. package/src/codex/loopback-target.ts +22 -8
  100. package/src/codex/main-account.ts +94 -30
  101. package/src/codex/native-main-auth-file.ts +14 -0
  102. package/src/codex/native-main-credentials.ts +276 -0
  103. package/src/codex/native-main-owner.ts +3 -0
  104. package/src/codex/native-main-refresh-mode.ts +14 -1
  105. package/src/codex/quota.ts +63 -14
  106. package/src/combos/failover.ts +195 -1
  107. package/src/combos/index.ts +5 -0
  108. package/src/combos/resolve.ts +115 -19
  109. package/src/config/diagnostics.ts +3 -0
  110. package/src/config/live-reconcile.ts +6 -3
  111. package/src/config/load-degrade.ts +2 -0
  112. package/src/config/persisted-mutation.ts +2 -2
  113. package/src/config/persisted-projections.ts +18 -0
  114. package/src/config/process-state.ts +4 -3
  115. package/src/config/reserve-capability.ts +96 -0
  116. package/src/config/schema/config-schema.ts +6 -0
  117. package/src/config/schema/leaf-validators.ts +2 -0
  118. package/src/config/schema/routed-catalog-defaults.ts +49 -0
  119. package/src/config/subagent-models.ts +20 -12
  120. package/src/config.ts +7 -7
  121. package/src/desktop-update/acquire.ts +202 -0
  122. package/src/desktop-update/cli.ts +168 -0
  123. package/src/desktop-update/drain.ts +40 -0
  124. package/src/desktop-update/headless.ts +285 -0
  125. package/src/desktop-update/image.ts +85 -0
  126. package/src/desktop-update/install.ts +53 -0
  127. package/src/desktop-update/msi.ts +72 -0
  128. package/src/desktop-update/release.ts +128 -0
  129. package/src/desktop-update/runtime.ts +155 -0
  130. package/src/desktop-update/staging.ts +118 -0
  131. package/src/desktop-update/trust.ts +45 -0
  132. package/src/generated/compatibility-version.json +327 -195
  133. package/src/generated/model-metadata.ts +3 -3
  134. package/src/images/fulfill-video.ts +3 -3
  135. package/src/images/loop.ts +6 -2
  136. package/src/images/plan.ts +147 -11
  137. package/src/images/types.ts +13 -4
  138. package/src/images/xai-video-client.ts +72 -10
  139. package/src/lib/client-error-body.ts +6 -0
  140. package/src/lib/developer-role-rejection.ts +15 -0
  141. package/src/lib/gcp-adc.ts +48 -4
  142. package/src/lib/offline-resend.ts +150 -0
  143. package/src/lib/paced-stream.ts +3 -3
  144. package/src/lib/provider-outbound.ts +17 -6
  145. package/src/lib/request-failure-model.ts +2 -0
  146. package/src/lib/response-body-inactivity.ts +23 -1
  147. package/src/lib/upstream-retry.ts +39 -6
  148. package/src/link/explicit-route.ts +4 -4
  149. package/src/link/remote-windows.ts +79 -31
  150. package/src/link/residual-recovery.ts +20 -8
  151. package/src/messaging/budget.ts +23 -5
  152. package/src/messaging/remote-ports.ts +22 -10
  153. package/src/messaging/rpc.ts +4 -4
  154. package/src/oauth/antigravity-risk.ts +126 -0
  155. package/src/oauth/credential-siblings.ts +32 -0
  156. package/src/oauth/generic-account-failover.ts +113 -30
  157. package/src/oauth/generic-session-affinity.ts +10 -3
  158. package/src/oauth/index.ts +22 -14
  159. package/src/oauth/login-cli.ts +35 -1
  160. package/src/oauth/pool-kernel.ts +3 -3
  161. package/src/oauth/store.ts +38 -7
  162. package/src/providers/anthropic-billing-refusal.ts +27 -3
  163. package/src/providers/anthropic-reset-grants.ts +4 -0
  164. package/src/providers/claude-cli-usage.ts +2 -0
  165. package/src/providers/codebuddy-models.ts +11 -0
  166. package/src/providers/google-vertex-model-discovery.ts +49 -15
  167. package/src/providers/kiro-models.ts +5 -0
  168. package/src/providers/model-rename-fields.ts +2 -0
  169. package/src/providers/quota/workbuddy.ts +6 -2
  170. package/src/providers/registry/entries-core.ts +9 -3
  171. package/src/providers/registry/entries-extended.ts +20 -9
  172. package/src/providers/registry/model-seeds.ts +4 -1
  173. package/src/providers/stale-context-window-migration.ts +2 -0
  174. package/src/providers/workbuddy-credit-balance.ts +125 -16
  175. package/src/responses/citation-markers.ts +26 -23
  176. package/src/responses/effort-history.ts +732 -0
  177. package/src/routing/history/integrity.ts +41 -4
  178. package/src/server/auth-cors.ts +13 -3
  179. package/src/server/codex-model-list.ts +2 -1
  180. package/src/server/direct-local-http.ts +26 -3
  181. package/src/server/index/link-listener.ts +20 -14
  182. package/src/server/index/serve-options.ts +1 -0
  183. package/src/server/index.ts +3 -2
  184. package/src/server/link-turn.ts +17 -5
  185. package/src/server/management/config-routes.ts +39 -3
  186. package/src/server/management/link-child-preflight.ts +1 -1
  187. package/src/server/management/link-enrollment.ts +3 -3
  188. package/src/server/management/link-route-edit.ts +20 -1
  189. package/src/server/management/link-route-request.ts +11 -5
  190. package/src/server/management/oauth-account-routes.ts +43 -13
  191. package/src/server/management/provider-credential-release.ts +44 -0
  192. package/src/server/management/provider-overwrite-carry.ts +3 -0
  193. package/src/server/management/provider-routes.ts +12 -12
  194. package/src/server/management/static-catalog-probe.ts +33 -0
  195. package/src/server/management/usage-aggregate-cache.ts +6 -3
  196. package/src/server/messages-native.ts +16 -2
  197. package/src/server/proxy-liveness.ts +54 -9
  198. package/src/server/relay.ts +6 -1
  199. package/src/server/request-log-conversation.ts +8 -4
  200. package/src/server/request-log-failure-detail.ts +26 -9
  201. package/src/server/request-log.ts +5 -1
  202. package/src/server/reserve-capability-startup.ts +32 -0
  203. package/src/server/responses/adapter-continuation.ts +59 -25
  204. package/src/server/responses/adapter-delivery.ts +2 -0
  205. package/src/server/responses/adapter-dispatch.ts +39 -18
  206. package/src/server/responses/antigravity-fault-rotation.ts +24 -0
  207. package/src/server/responses/antigravity-validation-refusal.ts +43 -6
  208. package/src/server/responses/codex-tool-catalog.ts +47 -10
  209. package/src/server/responses/combo-selection-keepalive.ts +254 -0
  210. package/src/server/responses/combo-session-recall.ts +26 -1
  211. package/src/server/responses/combo-stream-preflight.ts +35 -26
  212. package/src/server/responses/core-combo-failure.ts +6 -0
  213. package/src/server/responses/core-combo-native.ts +2 -1
  214. package/src/server/responses/core-combo.ts +67 -28
  215. package/src/server/responses/core-errors.ts +9 -6
  216. package/src/server/responses/core-options.ts +10 -0
  217. package/src/server/responses/core.ts +21 -0
  218. package/src/server/responses/estimated-usage.ts +115 -0
  219. package/src/server/responses/input-admission.ts +41 -3
  220. package/src/server/responses/jev-model-invoke.ts +7 -2
  221. package/src/server/responses/passthrough-completion.ts +6 -3
  222. package/src/server/responses/passthrough-delivery.ts +47 -8
  223. package/src/server/responses/passthrough-dispatch.ts +3 -0
  224. package/src/server/responses/request-prepare.ts +9 -5
  225. package/src/server/responses/request-send-budget.ts +1 -1
  226. package/src/server/responses/request-transport.ts +10 -2
  227. package/src/server/responses/sidecar-execution.ts +11 -4
  228. package/src/service/desktop-supervision.d.mts +2 -0
  229. package/src/service/desktop-supervision.mjs +5 -0
  230. package/src/service/windows-checked-stop-live.ts +28 -5
  231. package/src/stall-timeout.ts +11 -0
  232. package/src/types/config.ts +15 -92
  233. package/src/types/provider.ts +13 -0
  234. package/src/types/request.ts +23 -3
  235. package/src/types/routed-catalog-defaults.ts +17 -0
  236. package/src/types/routing-profile.ts +90 -0
  237. package/src/types.ts +1 -0
  238. package/src/update/index.ts +1 -1
  239. package/src/usage/expected-prices.ts +35 -0
  240. package/src/usage/ledger-scanner.ts +44 -10
  241. package/src/usage/log.ts +14 -4
  242. package/src/usage/telemetry-contract.ts +1 -0
  243. package/src/web-search/loop.ts +20 -2
  244. package/src/web-search/parse.ts +2 -12
  245. package/src/web-search/passthrough-bridge.ts +7 -0
  246. package/src/web-search/sources.ts +13 -0
  247. package/gui/dist/assets/brand-mark-XOLJbomA.js +0 -1
  248. package/gui/dist/assets/index-DQtCRNAw.css +0 -2
  249. package/gui/dist/classic/assets/quota-summary-Dy5_wfTT.js +0 -1
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Google Antigravity sign-in can get the Google account disabled.
3
+ *
4
+ * Antigravity's OAuth login is issued for Google's own Antigravity app. Reaching Cloud Code
5
+ * Assist through a third-party proxy with it is the pattern behind the account bans reported
6
+ * against Gemini CLI (google-gemini/gemini-cli #19501, #20813, #27199, #27388), where the
7
+ * account answers every request with {@link ANTIGRAVITY_TOS_BAN_MESSAGE}. The auto-pause policy
8
+ * (`account-auto-pause-policy.ts`) recognises that message once it happens; this module is the
9
+ * other half, making sure nobody reaches it without having been told first.
10
+ *
11
+ * Every way of adding an Antigravity account goes through the management API, except
12
+ * `ocx login`, which runs the flow in-process. The API therefore refuses an Antigravity login
13
+ * or import whose body does not carry {@link ANTIGRAVITY_RISK_ACK_FIELD} set to `true`, and each
14
+ * client sets it only after a person acknowledged the warning: the dashboard through its
15
+ * checkbox, the CLI through a y/N prompt or the explicit {@link ANTIGRAVITY_RISK_CLI_FLAG}.
16
+ * The field is consent evidence from the client, the same weight a dashboard checkbox has; it
17
+ * cannot prove a human read anything, and it is not meant to.
18
+ */
19
+
20
+ export const ANTIGRAVITY_RISK_PROVIDER = "google-antigravity";
21
+
22
+ /** Request-body field that carries the acknowledgement. Only the literal `true` counts. */
23
+ export const ANTIGRAVITY_RISK_ACK_FIELD = "acknowledgeAntigravityRisk";
24
+
25
+ /** CLI flag for non-interactive use. Without it, a CLI that cannot prompt refuses. */
26
+ export const ANTIGRAVITY_RISK_CLI_FLAG = "--accept-antigravity-risk";
27
+
28
+ /** Machine-readable refusal returned by the management API and printed by the CLI. */
29
+ export const ANTIGRAVITY_RISK_REFUSAL_CODE = "antigravity_risk_not_acknowledged";
30
+
31
+ /** The error Cloud Code Assist returns for a disabled account (see account-auto-pause-policy.ts). */
32
+ export const ANTIGRAVITY_TOS_BAN_MESSAGE = "This service has been disabled in this account for violation of Terms of Service.";
33
+
34
+ export function requiresAntigravityRiskAcknowledgement(provider: string): boolean {
35
+ return provider.trim().toLowerCase() === ANTIGRAVITY_RISK_PROVIDER;
36
+ }
37
+
38
+ export function hasAntigravityRiskAcknowledgement(body: unknown): boolean {
39
+ return typeof body === "object" && body !== null
40
+ && (body as Record<string, unknown>)[ANTIGRAVITY_RISK_ACK_FIELD] === true;
41
+ }
42
+
43
+ /** The API refusal body, shared by every route that can add an Antigravity account. */
44
+ export function antigravityRiskRefusalBody(): { error: string; code: typeof ANTIGRAVITY_RISK_REFUSAL_CODE } {
45
+ return {
46
+ error: "Google Antigravity sign-in can get Gemini and Antigravity access disabled on the Google account. Acknowledge the risk in the OpenCodex dashboard, or pass "
47
+ + ANTIGRAVITY_RISK_CLI_FLAG + " to the CLI.",
48
+ code: ANTIGRAVITY_RISK_REFUSAL_CODE,
49
+ };
50
+ }
51
+
52
+ /** Terminal warning shown before every CLI Antigravity sign-in or import, flag or not. */
53
+ export const ANTIGRAVITY_RISK_WARNING = [
54
+ "",
55
+ "WARNING: Google may permanently disable Gemini and Antigravity access on the Google account you sign in with.",
56
+ " The Antigravity login is meant for Google's own Antigravity app. OpenCodex is a third-party",
57
+ " proxy, and users of third-party tools have reported that access being disabled with:",
58
+ " \"" + ANTIGRAVITY_TOS_BAN_MESSAGE + "\"",
59
+ " - The ban applies to the Google account: its Gemini Code Assist and Antigravity access can",
60
+ " stop everywhere, including in Google's own tools.",
61
+ " - Getting access back depends on Google's appeal process and is not guaranteed.",
62
+ " - Use only a separate Google account you can afford to lose. Never use your main, personal,",
63
+ " school, or work account.",
64
+ " Safer option: use a Gemini API key (Google AI Studio or Vertex AI) instead.",
65
+ "",
66
+ ].join("\n");
67
+
68
+ export const ANTIGRAVITY_RISK_PROMPT = "Continue with Google Antigravity and accept the risk? [y/N]: ";
69
+
70
+ export type AntigravityRiskDecision = "accepted" | "declined" | "noninteractive" | "agent";
71
+
72
+ /**
73
+ * Test and platform seams for the CLI gate. Production reads the environment: a coding agent or
74
+ * CI runner is detected by {@link isAgentDriven}, and a prompt counts as visible only when the
75
+ * stream it is written to is a terminal.
76
+ */
77
+ export interface AntigravityRiskSeams {
78
+ agentDriven?: () => boolean;
79
+ promptVisible?: () => boolean;
80
+ }
81
+
82
+ /**
83
+ * The CLI gate. The warning is always shown, even with the flag, so a script's log records what
84
+ * was accepted. Adding an Antigravity account spends the user's Google identity, so the repository
85
+ * rule for such actions applies (AGENTS.md, "User-consent actions"; AGENTS_INSTALL.md): a process
86
+ * driven by a coding agent or CI runner is refused outright, flag or not, because the agent would
87
+ * be the one answering. Otherwise the flag accepts, an interactive terminal may answer, and only
88
+ * an explicit "y" or "yes" accepts: an empty line, EOF, a timeout or a read error all decline.
89
+ */
90
+ export async function resolveAntigravityRiskAcknowledgement(opts: {
91
+ flag: boolean;
92
+ interactive: boolean;
93
+ agentDriven: boolean;
94
+ warn: (text: string) => void;
95
+ ask: (question: string) => Promise<string>;
96
+ }): Promise<AntigravityRiskDecision> {
97
+ opts.warn(ANTIGRAVITY_RISK_WARNING);
98
+ if (opts.agentDriven) return "agent";
99
+ if (opts.flag) return "accepted";
100
+ if (!opts.interactive) return "noninteractive";
101
+ let answer: string;
102
+ try {
103
+ answer = await opts.ask(ANTIGRAVITY_RISK_PROMPT);
104
+ } catch {
105
+ return "declined";
106
+ }
107
+ const normalized = answer.trim().toLowerCase();
108
+ return normalized === "y" || normalized === "yes" ? "accepted" : "declined";
109
+ }
110
+
111
+ export function antigravityRiskDecisionMessage(decision: Exclude<AntigravityRiskDecision, "accepted">): string {
112
+ switch (decision) {
113
+ case "agent":
114
+ return "Refusing Google Antigravity (" + ANTIGRAVITY_RISK_REFUSAL_CODE + "): this run is driven by a coding agent or CI runner, "
115
+ + "and only the account owner can accept the risk. Run the command yourself in a terminal, or use the OpenCodex dashboard.";
116
+ case "noninteractive":
117
+ return "Refusing Google Antigravity without acknowledgement (" + ANTIGRAVITY_RISK_REFUSAL_CODE + "): no interactive terminal to confirm. "
118
+ + "Re-run in a terminal, or pass " + ANTIGRAVITY_RISK_CLI_FLAG + " to accept the risk explicitly.";
119
+ case "declined":
120
+ return "Google Antigravity cancelled: the risk was not accepted. Nothing was changed.";
121
+ default: {
122
+ const exhaustive: never = decision;
123
+ return exhaustive;
124
+ }
125
+ }
126
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * OAuth credential siblings: registry provider rows that sign in through another provider's
3
+ * login instead of owning one.
4
+ *
5
+ * The auth store holds one slot per login. A sibling row has no slot of its own; every store
6
+ * read and write addressed to its name lands in the owner's slot, and token refresh runs under
7
+ * the owner's name. One login therefore serves both rows, a rotating refresh token is never
8
+ * refreshed twice under two names, and logging out of the owner signs out both rows.
9
+ *
10
+ * The map is the registry's `oauthId !== id` rows, restated here as a plain constant so the
11
+ * dashboard can import it without pulling in the provider registry
12
+ * (tests/oauth/oauth-credential-siblings.test.ts pins the two together). Kimi (Responses) is
13
+ * the only sibling: owner decision on #8087. Other OAuth presets keep their own logins.
14
+ */
15
+ export const OAUTH_CREDENTIAL_SIBLINGS: Readonly<Record<string, string>> = Object.freeze({
16
+ "kimi-responses": "kimi",
17
+ });
18
+
19
+ /** The auth-store slot that holds this provider row's login: the owner for a sibling, else itself. */
20
+ export function oauthCredentialSlot(provider: string): string {
21
+ return Object.hasOwn(OAUTH_CREDENTIAL_SIBLINGS, provider) ? OAUTH_CREDENTIAL_SIBLINGS[provider]! : provider;
22
+ }
23
+
24
+ /** Whether `row` is a sibling row that signs in through `provider`'s login. */
25
+ export function isOAuthCredentialSiblingOf(row: string, provider: string): boolean {
26
+ return row !== provider && Object.hasOwn(OAUTH_CREDENTIAL_SIBLINGS, row) && OAUTH_CREDENTIAL_SIBLINGS[row] === provider;
27
+ }
28
+
29
+ /** Sibling rows that sign in through `provider`'s login. */
30
+ export function oauthCredentialSiblingsOf(provider: string): string[] {
31
+ return Object.keys(OAUTH_CREDENTIAL_SIBLINGS).filter(row => OAUTH_CREDENTIAL_SIBLINGS[row] === provider);
32
+ }
@@ -17,6 +17,7 @@ import { isBuiltinAnthropicInstanceRow } from "../providers/anthropic-instance";
17
17
  * Both are excluded by `isGenericFailoverProvider`.
18
18
  */
19
19
  import { credentialGeneration, getAccountSet } from "./store";
20
+ import { oauthCredentialSiblingsOf, oauthCredentialSlot } from "./credential-siblings";
20
21
  import { accountInFlight } from "./kiro-account-load";
21
22
  import type { ProviderAccount } from "./types";
22
23
  import { getValidAccessSnapshotForAccount, type OAuthAccessSnapshot } from "./index";
@@ -100,13 +101,21 @@ interface PresenceEntry {
100
101
  /** Process-local, like the Anthropic pool's: a restart is allowed to forget a cooldown. */
101
102
  const health = new Map<string, AccountHealth>();
102
103
 
103
- /** Provider -> recent eligible-account count. TTL-bounded; never holds credential material. */
104
+ /**
105
+ * Login slot -> recent eligible-account count. TTL-bounded; never holds credential material.
106
+ * Keyed like health below, so a pause through one row of a shared login invalidates the other's.
107
+ */
104
108
  const presence = new Map<string, PresenceEntry>();
109
+ const presenceKey = (provider: string) => oauthCredentialSlot(provider);
105
110
 
106
- subscribeOAuthAccountPauseChanges(provider => presence.delete(provider));
111
+ subscribeOAuthAccountPauseChanges(provider => presence.delete(presenceKey(provider)));
107
112
 
108
- const healthKey = (provider: string, accountId: string, family?: QuotaModelFamily) =>
109
- family ? `${provider}\u0000${accountId}\u0000${family}` : `${provider}\u0000${accountId}`;
113
+ // Keyed by the login slot: rows that share one login (Kimi and Kimi (Responses)) share each
114
+ // account's health, so a cooldown earned through one row is honored by the other.
115
+ const healthKey = (provider: string, accountId: string, family?: QuotaModelFamily) => {
116
+ const slot = oauthCredentialSlot(provider);
117
+ return family ? `${slot}\u0000${accountId}\u0000${family}` : `${slot}\u0000${accountId}`;
118
+ };
110
119
 
111
120
  export function quarantineKiroSuspendedAccount(accountId: string, generation?: string, now = Date.now()): void {
112
121
  const live = getAccountSet("kiro")?.accounts.find(row => row.id === accountId);
@@ -174,7 +183,7 @@ export function isGenericFailoverProvider(providerName: string, provider: OcxPro
174
183
  * needed.
175
184
  */
176
185
  function eligibleAccountCount(providerName: string, now: number): number {
177
- const cached = presence.get(providerName);
186
+ const cached = presence.get(presenceKey(providerName));
178
187
  if (cached && now >= cached.readAt && now - cached.readAt < PRESENCE_CACHE_TTL_MS) return cached.eligible;
179
188
  const set = getAccountSet(providerName);
180
189
  // Kiro terminal refresh marks the just-refused account needsReauth before the alternate
@@ -183,7 +192,7 @@ function eligibleAccountCount(providerName: string, now: number): number {
183
192
  ? set.accounts.filter(account => account.paused !== true
184
193
  && (providerName === "kiro" || account.needsReauth !== true)).length
185
194
  : 0;
186
- presence.set(providerName, { eligible, readAt: now });
195
+ presence.set(presenceKey(providerName), { eligible, readAt: now });
187
196
  return eligible;
188
197
  }
189
198
 
@@ -274,8 +283,9 @@ export function preferKiroModelSupport(
274
283
  if (!model) return ids;
275
284
  if (providerName === "google-antigravity") {
276
285
  const positive = ids.filter(id => accountListsModel(providerName, id, model) === true);
277
- if (positive.length) return positive;
278
- return ids.filter(id => accountListsModel(providerName, id, model) !== false);
286
+ const modelMatched = positive.length ? positive : ids.filter(id => accountListsModel(providerName, id, model) !== false);
287
+ const nonExhausted = modelMatched.filter(id => !isAccountQuotaExhausted(providerName, id, model));
288
+ return nonExhausted.length ? nonExhausted : modelMatched;
279
289
  }
280
290
  if (providerName !== "kiro") return ids;
281
291
  const cap = config?.providers?.kiro?.oauthAccountFailover?.maxConcurrentPerAccount;
@@ -341,7 +351,10 @@ export function routeAntigravityModel(
341
351
  const ready = new Set(eligibleFailoverAccounts(providerName, now, classifyModelFamilyForQuota(providerName, model)));
342
352
  const rank = (id: string) => (ready.has(id) ? 0 : 2) + (accountListsModel(providerName, id, model) === true ? 0 : 1);
343
353
  const tier = Math.min(...serving.map(rank));
344
- const best = rankAntigravityModelAccounts(config, serving.filter(id => rank(id) === tier), model, now)[0]!;
354
+ // Same exhaustion preference as the initial pick: a listing account whose quota family is
355
+ // spent loses to one with headroom, unless every candidate in the tier is spent.
356
+ const candidates = preferKiroModelSupport(providerName, serving.filter(id => rank(id) === tier), model, config);
357
+ const best = rankAntigravityModelAccounts(config, candidates, model, now)[0]!;
345
358
  return { kind: "reroute", accountId: best };
346
359
  }
347
360
 
@@ -351,7 +364,8 @@ function rankAntigravityModelAccounts(config: OcxConfig, ids: string[], model: s
351
364
  const rows = new Map((getAccountSet(provider)?.accounts ?? []).map(row => [row.id, row]));
352
365
  const strategy = activeGenericStrategy(config, provider);
353
366
  if (strategy === "round-robin") {
354
- const best = peekRoundRobinAccount(genericPoolKey(provider), ids, genericStickyLimit(config, provider));
367
+ const poolKey = genericPoolKey(provider, classifyModelFamilyForQuota(provider, model));
368
+ const best = peekRoundRobinAccount(poolKey, ids, genericStickyLimit(config, provider));
355
369
  return best ? [best, ...ids.filter(id => id !== best)] : ids;
356
370
  }
357
371
  if (strategy === "fill-first") return stableGenericRoster(provider).filter(id => ids.includes(id));
@@ -446,16 +460,44 @@ export function rotateAntigravityAccountOnAuthRefusal(
446
460
  const set = getAccountSet("google-antigravity");
447
461
  if (!set || set.accounts.length < 2) return null;
448
462
  const family = classifyModelFamilyForQuota("google-antigravity", requestedModelId);
463
+ coolAntigravityAccount(set, failedAccountId, sentGeneration, family, now, {
464
+ cooldownUntil: now + DEFAULT_COOLDOWN_MS, cooldownSource: "auth", identity: sentGeneration,
465
+ });
466
+ return nextAntigravitySibling(set, failedAccountId, requestedModelId, family, now);
467
+ }
468
+
469
+ /**
470
+ * The one cooldown write both Antigravity sibling rotations (403 refusal, 5xx fault) share. It is
471
+ * fenced on the sent credential generation, so a re-login that landed mid-request is never cooled,
472
+ * and it never shortens a cooldown already running for the same account and family: a 15-second
473
+ * fault window must not cut short a 60-second refusal or a quota cooldown.
474
+ */
475
+ function coolAntigravityAccount(
476
+ set: NonNullable<ReturnType<typeof getAccountSet>>,
477
+ failedAccountId: string,
478
+ sentGeneration: string,
479
+ family: QuotaModelFamily | undefined,
480
+ now: number,
481
+ entry: AccountHealth,
482
+ ): void {
449
483
  const failed = set.accounts.find(row => row.id === failedAccountId);
450
- if (failed && credentialGeneration(failed.credential) === sentGeneration) {
451
- health.set(healthKey("google-antigravity", failedAccountId, family), {
452
- cooldownUntil: now + DEFAULT_COOLDOWN_MS,
453
- cooldownSource: "auth",
454
- identity: sentGeneration,
455
- });
456
- presence.delete("google-antigravity");
457
- sweepExpiredOnWrite(now);
458
- }
484
+ if (!failed || credentialGeneration(failed.credential) !== sentGeneration) return;
485
+ const key = healthKey("google-antigravity", failedAccountId, family);
486
+ if (isCooled("google-antigravity", failedAccountId, now, family)
487
+ && (health.get(key)?.cooldownUntil ?? 0) >= entry.cooldownUntil) return;
488
+ health.set(key, entry);
489
+ presence.delete("google-antigravity");
490
+ sweepExpiredOnWrite(now);
491
+ }
492
+
493
+ /** Next live sibling after the failed account, in roster order, honouring cooldowns and model support. */
494
+ function nextAntigravitySibling(
495
+ set: NonNullable<ReturnType<typeof getAccountSet>>,
496
+ failedAccountId: string,
497
+ requestedModelId: string | null | undefined,
498
+ family: QuotaModelFamily | undefined,
499
+ now: number,
500
+ ): string | null {
459
501
  const eligible = new Set(preferKiroModelSupport("google-antigravity",
460
502
  eligibleIdsIn(set, "google-antigravity", now, family).filter(id => id !== failedAccountId), requestedModelId));
461
503
  const order = set.accounts.map(row => row.id);
@@ -464,6 +506,31 @@ export function rotateAntigravityAccountOnAuthRefusal(
464
506
  return ring.find(id => id !== failedAccountId && eligible.has(id)) ?? null;
465
507
  }
466
508
 
509
+ /**
510
+ * A 502/503/504 that survived the same-account retry ladder says this account's route to Google is
511
+ * failing right now, not that the credential is bad. Cool it for a short, fixed window (pool-wide
512
+ * capacity trouble then clears on its own within seconds) and name a live sibling to replay on.
513
+ * No stored verdict: nothing here outlives the process or the window.
514
+ */
515
+ const ANTIGRAVITY_FAULT_COOLDOWN_MS = 15_000;
516
+
517
+ export function rotateAntigravityAccountOnUpstreamFault(
518
+ poolActivated: boolean,
519
+ failedAccountId: string,
520
+ sentGeneration: string,
521
+ requestedModelId: string | null | undefined,
522
+ now = Date.now(),
523
+ ): string | null {
524
+ if (!poolActivated) return null;
525
+ const set = getAccountSet("google-antigravity");
526
+ if (!set || set.accounts.length < 2) return null;
527
+ const family = classifyModelFamilyForQuota("google-antigravity", requestedModelId);
528
+ coolAntigravityAccount(set, failedAccountId, sentGeneration, family, now, {
529
+ cooldownUntil: now + ANTIGRAVITY_FAULT_COOLDOWN_MS, cooldownSource: "default",
530
+ });
531
+ return nextAntigravitySibling(set, failedAccountId, requestedModelId, family, now);
532
+ }
533
+
467
534
  /** Generic pool strategies the kernel can actually run. `quota` IS the pre-kernel path. */
468
535
  type ActiveGenericStrategy = "round-robin" | "fill-first" | "reset-first" | "least-loaded";
469
536
 
@@ -580,10 +647,16 @@ export function noteGenericPoolSelection(
580
647
  requestedModelId?: string | null,
581
648
  ): void {
582
649
  if (activeGenericStrategy(config, providerName) !== "round-robin") return;
583
- const poolKey = genericPoolKey(providerName);
584
- const limit = genericStickyLimit(config, providerName);
585
650
  const family = classifyModelFamilyForQuota(providerName, requestedModelId);
586
- const picked = pickRoundRobinAccount(poolKey, eligibleFailoverAccounts(providerName, Date.now(), family), limit);
651
+ const poolKey = genericPoolKey(providerName, family);
652
+ const limit = genericStickyLimit(config, providerName);
653
+ const eligible = preferKiroModelSupport(
654
+ providerName,
655
+ eligibleFailoverAccounts(providerName, Date.now(), family),
656
+ requestedModelId,
657
+ config,
658
+ );
659
+ const picked = pickRoundRobinAccount(poolKey, eligible, limit);
587
660
  // The resolver may have admitted a different account than the ring proposed: a removal, a
588
661
  // reauth verdict or a manual selection can land during credential resolution. Realign the
589
662
  // cursor onto what actually served rather than leaving it on a road not taken.
@@ -658,7 +731,7 @@ export function rotateGenericOAuthAccountOnRefusal(
658
731
  if (eligible.length === 0) return null;
659
732
  // A rotation means the roster in use just changed; do not answer the next activation question
660
733
  // from a count read before the failure.
661
- presence.delete(providerName);
734
+ presence.delete(presenceKey(providerName));
662
735
  // Deterministic: start after the failed account so repeated 429s walk the roster instead of
663
736
  // hammering whichever id happens to sort first. The ring is built BEFORE ranking — ranking
664
737
  // the store's own order would change which account a quota-less provider rotates to.
@@ -684,7 +757,7 @@ export function rotateGenericOAuthAccountOnRefusal(
684
757
  // PICK here, not peek: the failure already happened and this answer is the one being used,
685
758
  // so the ring genuinely advances. A caller that only asks whether a sibling exists peeks.
686
759
  return (commit ? pickRoundRobinAccount : peekRoundRobinAccount)(
687
- genericPoolKey(providerName),
760
+ genericPoolKey(providerName, family),
688
761
  candidates,
689
762
  genericStickyLimit(config, providerName),
690
763
  );
@@ -822,7 +895,7 @@ export function preferredInitialAccount(
822
895
  // PEEK, not pick: this proposal is discardable, and advancing the ring for an account the
823
896
  // resolver then rejects would skip a turn for nothing. noteGenericPoolSelection commits.
824
897
  const picked = peekRoundRobinAccount(
825
- genericPoolKey(providerName),
898
+ genericPoolKey(providerName, family),
826
899
  eligibleNow,
827
900
  genericStickyLimit(config, providerName),
828
901
  );
@@ -880,7 +953,7 @@ export function preferredInitialAccount(
880
953
 
881
954
  /** Earliest remaining cooldown, for a client-facing Retry-After when every account is cooled. */
882
955
  export function genericFailoverRetryAfterSeconds(providerName: string, now = Date.now()): number | null {
883
- const prefix = `${providerName}\u0000`;
956
+ const prefix = `${oauthCredentialSlot(providerName)}\u0000`;
884
957
  let earliest: number | null = null;
885
958
  for (const [key, entry] of health) {
886
959
  if (!key.startsWith(prefix) || entry.cooldownUntil <= now) continue;
@@ -889,9 +962,18 @@ export function genericFailoverRetryAfterSeconds(providerName: string, now = Dat
889
962
  return earliest === null ? null : Math.max(1, Math.ceil((earliest - now) / 1000));
890
963
  }
891
964
 
965
+ /** A manual selection must win in every ring a request can read, including the per-family ones. */
966
+ export function seedGenericPoolSelection(providerName: string, accountId: string): void {
967
+ // Dispatch keys the cursor by row name, so seed every row that shares this login (kimi-responses).
968
+ const slot = oauthCredentialSlot(providerName);
969
+ for (const row of new Set([providerName, slot, ...oauthCredentialSiblingsOf(slot)])) seedPoolRotationAccount(genericPoolKey(row), accountId);
970
+ if (providerName !== "google-antigravity") return;
971
+ for (const family of ["gem", "cla"] satisfies QuotaModelFamily[]) seedPoolRotationAccount(genericPoolKey(providerName, family), accountId);
972
+ }
973
+
892
974
  /** Test seam and manual-recovery hook. */
893
975
  export function forgetGenericFailoverRoster(providerName: string): void {
894
- presence.delete(providerName);
976
+ presence.delete(presenceKey(providerName));
895
977
  }
896
978
 
897
979
  /** Test seam and manual-recovery hook. */
@@ -901,9 +983,10 @@ export function clearGenericFailoverHealth(providerName?: string): void {
901
983
  presence.clear();
902
984
  return;
903
985
  }
904
- presence.delete(providerName);
986
+ presence.delete(presenceKey(providerName));
987
+ const slot = oauthCredentialSlot(providerName);
905
988
  for (const key of [...health.keys()]) {
906
- if (key.startsWith(`${providerName}\u0000`)) health.delete(key);
989
+ if (key.startsWith(`${slot}\u0000`)) health.delete(key);
907
990
  }
908
991
  }
909
992
 
@@ -918,7 +1001,7 @@ export function clearGenericFailoverHealth(providerName?: string): void {
918
1001
  export function clearGenericFailoverHealthForAccount(providerName: string, accountId: string): void {
919
1002
  const live = getAccountSet(providerName)?.accounts.find(row => row.id === accountId);
920
1003
  const current = live ? credentialGeneration(live.credential) : undefined;
921
- const bare = `${providerName}\u0000${accountId}`;
1004
+ const bare = healthKey(providerName, accountId);
922
1005
  for (const key of [...health.keys()]) {
923
1006
  if (key !== bare && !key.startsWith(`${bare}\u0000`)) continue;
924
1007
  const entry = health.get(key);
@@ -13,7 +13,8 @@ const IDLE_TTL_MS = 24 * 60 * 60_000;
13
13
  const MAX_ENTRIES = 2_000;
14
14
  const bindings = new Map<string, { accountId: string; lastUsedAt: number; selection: OAuthAccountSelection }>();
15
15
  const prefix = (provider: string) => `${JSON.stringify([getConfigDir(), provider])}\u0000`;
16
- const key = (provider: string, session: string) => prefix(provider) + "session:" + createHash("sha256").update(session).digest("hex");
16
+ const key = (provider: string, session: string, family?: string) =>
17
+ prefix(provider) + (family ? `session:${family}:` : "session:") + createHash("sha256").update(session).digest("hex");
17
18
  const cursorKey = (provider: string) => prefix(provider) + "fill-first";
18
19
 
19
20
  /** A persisted operator/roster/policy change revokes old session choices before its writer returns. */
@@ -59,7 +60,9 @@ export function genericSessionAccount(
59
60
  config: OcxConfig, provider: string, session: string | null, model?: string | null, now = Date.now(),
60
61
  ): string | null {
61
62
  if (!genericSessionAffinityEnabled(config, provider) || !session) return null;
62
- return readBinding(config, provider, key(provider, session), model, now);
63
+ const family = classifyModelFamilyForQuota(provider, model);
64
+ return readBinding(config, provider, key(provider, session, family), model, now)
65
+ ?? (family ? readBinding(config, provider, key(provider, session), model, now) : null);
63
66
  }
64
67
 
65
68
  function readBinding(config: OcxConfig, provider: string, id: string, model: string | null | undefined, now: number): string | null {
@@ -127,6 +130,10 @@ export function bindGenericSessionAccount(
127
130
  const hit = session && genericSessionAccount(config, provider, session, model, now) === accountId;
128
131
  if (!hit && config.pool?.kernel === true && config.providers[provider]?.oauthAccountFailover?.strategy === "fill-first")
129
132
  keep(cursorKey(provider));
130
- if (session) keep(key(provider, session));
133
+ const family = classifyModelFamilyForQuota(provider, model);
134
+ if (session) {
135
+ keep(key(provider, session, family));
136
+ if (family) keep(key(provider, session));
137
+ }
131
138
  while (bindings.size > MAX_ENTRIES) bindings.delete(bindings.keys().next().value!);
132
139
  }
@@ -57,6 +57,7 @@ import { DSH_ACCOUNT_AUTH } from "./dsh";
57
57
  import { loginOrcaRouter, orcaRouterInferenceBaseUrl, refreshOrcaRouterKey } from "./orcarouter";
58
58
  import { ANTIGRAVITY_DISCOVERY_UA } from "../adapters/google-antigravity-wire";
59
59
  import { deriveOAuthDefaultModel, deriveOAuthProviderConfig } from "../providers/derive";
60
+ import { isOAuthCredentialSiblingOf, oauthCredentialSlot } from "./credential-siblings";
60
61
  import { apiKeyPoolEntryId, sanitizeApiKeyValue } from "../providers/api-keys";
61
62
  import { preservableApiKeyPool } from "./api-key-pool-preserve";
62
63
  import { effectiveGoogleMode, getProviderRegistryEntry, mergeRegistryStaticHeaders, providerMatchesRegistryTransport } from "../providers/registry";
@@ -208,6 +209,8 @@ export interface LoginOpts {
208
209
  flow?: ChatGPTLoginFlow;
209
210
  /** Code-display login: no callback server; completes from a pasted code (needs `codeRedirectUri`). */
210
211
  codeMode?: boolean;
212
+ /** Publish this sibling row (see credential-siblings.ts) instead of the login's own row. */
213
+ publishRow?: string;
211
214
  }
212
215
 
213
216
  export interface LoginFlowLifecycle {
@@ -559,9 +562,9 @@ export function observeActiveOAuthAccessToken(
559
562
  const authStore = normalizeAuthStoreBuffer(authStoreBuffer);
560
563
  if (authStore.kind === "absent") return { kind: "missing" };
561
564
  if (authStore.kind === "malformed") return { kind: "malformed" };
562
- if (!isOAuthProvider(provider)) return { kind: "unsupported" };
565
+ if (!isOAuthProvider(oauthCredentialSlot(provider))) return { kind: "unsupported" };
563
566
 
564
- const accountSet = authStore.store[provider];
567
+ const accountSet = authStore.store[oauthCredentialSlot(provider)];
565
568
  const account = accountSet?.accounts.find(candidate => candidate.id === accountSet.activeAccountId);
566
569
  if (!account) return { kind: "missing" };
567
570
  if (account.paused === true) return { kind: "paused" };
@@ -590,6 +593,9 @@ async function resolveAccessSnapshotForAccount(
590
593
  authorityCurrent?: () => boolean,
591
594
  retryCancelledDiscovery = true,
592
595
  ): Promise<OAuthAccessSnapshot> {
596
+ // A sibling row resolves, refreshes and single-flights under its owner's login, then keeps its own label.
597
+ const slot = oauthCredentialSlot(provider);
598
+ if (slot !== provider) return { ...await resolveAccessSnapshotForAccount(slot, accountId, rejectedGeneration, requireUsableAccount, oauthProvider === provider ? slot : oauthProvider, authorityCurrent, retryCancelledDiscovery), provider };
593
599
  const def = OAUTH_PROVIDERS[oauthProvider];
594
600
  if (!def) throw new UnsupportedOAuthProviderError(oauthProvider);
595
601
  // One store read answers both questions. A caller that opts in gets the account REJECTED
@@ -1532,16 +1538,16 @@ const OAUTH_LOGIN_OWNED_PROVIDER_FIELDS = [
1532
1538
  ] as const satisfies readonly (keyof OcxProviderConfig)[];
1533
1539
 
1534
1540
  /** Add/refresh only an OAuth provider's login-owned config fields (does not persist). */
1535
- export function upsertOAuthProvider(config: OcxConfig, provider: string): void {
1541
+ export function upsertOAuthProvider(config: OcxConfig, provider: string, row = provider): void {
1536
1542
  assertAnthropicInstanceLoginConfig(config, provider);
1537
1543
  if (provider === "chatgpt") return;
1538
1544
  const def = OAUTH_PROVIDERS[provider];
1539
- if (!def) return;
1545
+ if (!def || (row !== provider && !isOAuthCredentialSiblingOf(row, provider))) { if (def) throw new UnsupportedOAuthProviderError(row); return; }
1540
1546
  if (provider === GOOGLE_ANTIGRAVITY_PROVIDER) migrateLegacyAntigravityStaticCatalog(config);
1541
- const namespaceCollision = codexAccountNamespaceProviderCollisionError(config.codexAccountNamespaces, provider);
1547
+ const namespaceCollision = codexAccountNamespaceProviderCollisionError(config.codexAccountNamespaces, row);
1542
1548
  if (namespaceCollision) throw new OAuthProviderNamespaceCollisionError(namespaceCollision);
1543
- const existing = config.providers[provider];
1544
- const providerConfig = def.resolveProviderConfig?.(config) ?? def.providerConfig;
1549
+ const existing = config.providers[row];
1550
+ const providerConfig = row !== provider ? oauthConfig(row) : def.resolveProviderConfig?.(config) ?? def.providerConfig;
1545
1551
  // Clone operator state, including xAI wire choices and their migration version.
1546
1552
  const next: OcxProviderConfig = structuredClone(existing ?? providerConfig);
1547
1553
  for (const field of OAUTH_LOGIN_OWNED_PROVIDER_FIELDS) {
@@ -1568,7 +1574,7 @@ export function upsertOAuthProvider(config: OcxConfig, provider: string): void {
1568
1574
  delete next.apiKey;
1569
1575
  delete next.apiKeyPool;
1570
1576
  delete (next as unknown as Record<string, unknown>).azureCredential;
1571
- if (existing && getProviderRegistryEntry(provider)?.allowKeyAuthOverride === true) {
1577
+ if (existing && getProviderRegistryEntry(row)?.allowKeyAuthOverride === true) {
1572
1578
  // Retain stored key billing intent without resolving env references in the login process.
1573
1579
  // An explicit OAuth choice stays OAuth even when usable key material is retained.
1574
1580
  // Shared sanitizeApiKeyValue trim / no-CRLF checks from api-key pool writes.
@@ -1591,8 +1597,8 @@ export function upsertOAuthProvider(config: OcxConfig, provider: string): void {
1591
1597
  if (previousModeAllowsKey) next.authMode = "key";
1592
1598
  }
1593
1599
  }
1594
- initializeProviderModelSelection(provider, next, existing, config);
1595
- config.providers[provider] = next;
1600
+ initializeProviderModelSelection(row, next, existing, config);
1601
+ config.providers[row] = next;
1596
1602
  }
1597
1603
 
1598
1604
  interface RunLoginDeps {
@@ -1618,6 +1624,8 @@ export async function runLogin(
1618
1624
  ): Promise<OAuthCredentials> {
1619
1625
  const def = OAUTH_PROVIDERS[provider];
1620
1626
  if (!def) throw new UnsupportedOAuthProviderError(provider);
1627
+ const row = opts?.publishRow ?? provider;
1628
+ if (row !== provider && !isOAuthCredentialSiblingOf(row, provider)) throw new UnsupportedOAuthProviderError(row);
1621
1629
  const loadLatestConfig = deps.loadConfig ?? loadConfig;
1622
1630
  const saveLatestConfig = deps.saveConfig ?? saveConfig;
1623
1631
  const initialBConfigState = provider === "anthropic2" ? observeInitialConfigState() : undefined;
@@ -1635,7 +1643,7 @@ export async function runLogin(
1635
1643
  assertAnthropicInstanceLoginConfig(preflightConfig, provider);
1636
1644
  const namespaceCollision = codexAccountNamespaceProviderCollisionError(
1637
1645
  preflightConfig.codexAccountNamespaces,
1638
- provider,
1646
+ row,
1639
1647
  );
1640
1648
  if (namespaceCollision) throw new OAuthProviderNamespaceCollisionError(namespaceCollision);
1641
1649
  }
@@ -1663,7 +1671,7 @@ export async function runLogin(
1663
1671
  // credential write is handled again below before the latest row is re-upserted.
1664
1672
  if (provider !== "chatgpt") {
1665
1673
  const preCommitConfig = loadLatestConfig();
1666
- upsertOAuthProvider(preCommitConfig, provider);
1674
+ upsertOAuthProvider(preCommitConfig, provider, row);
1667
1675
  }
1668
1676
  if (opts?.reauthAccountId) {
1669
1677
  const existing = getAccountCredential(provider, opts.reauthAccountId);
@@ -1728,12 +1736,12 @@ export async function runLogin(
1728
1736
  const latestConfig = loadLatestConfig();
1729
1737
  const lateCollision = codexAccountNamespaceProviderCollisionError(
1730
1738
  latestConfig.codexAccountNamespaces,
1731
- provider,
1739
+ row,
1732
1740
  );
1733
1741
  if (lateCollision) {
1734
1742
  throw new OAuthProviderPublicationError();
1735
1743
  }
1736
- upsertOAuthProvider(latestConfig, provider);
1744
+ upsertOAuthProvider(latestConfig, provider, row);
1737
1745
  saveLatestConfig(latestConfig);
1738
1746
  }
1739
1747
  }