@bitkyc08/opencodex 2.91.0 → 2.93.0-preview.20261027
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.
- package/bin/ocx.mjs +47 -8
- package/gui/dist/assets/App-CJZoq-uF.js +58 -0
- package/gui/dist/assets/{Tray-BuLy7hL1.js → Tray-BWQPcgZn.js} +1 -1
- package/gui/dist/assets/index-DRe8Hhfz.css +1 -0
- package/gui/dist/assets/index-Xfct8owH.js +94 -0
- package/gui/dist/assets/quota-summary-DxToX1rV.js +1 -0
- package/gui/dist/index.html +2 -2
- package/gui/dist/provider-icons/workbuddy-color.svg +29 -0
- package/package.json +8 -7
- package/src/adapters/anthropic.ts +28 -5
- package/src/adapters/coding-agent/batch-dispatcher.ts +122 -0
- package/src/adapters/coding-agent/profile.ts +54 -16
- package/src/adapters/coding-agent/turn.ts +30 -2
- package/src/adapters/command-code.ts +114 -7
- package/src/adapters/cursor/native-exec-fs.ts +11 -9
- package/src/adapters/devin/live-models.ts +4 -0
- package/src/adapters/google-vertex-endpoint.ts +9 -1
- package/src/adapters/google-vertex-key-project.ts +223 -0
- package/src/adapters/google-wire-compiler.ts +1 -2
- package/src/adapters/google.ts +13 -3
- package/src/adapters/kiro/reasoning.ts +2 -0
- package/src/adapters/kiro-refusal.ts +6 -1
- package/src/adapters/kiro-wire.ts +1 -1
- package/src/adapters/openai-chat/messages.ts +8 -2
- package/src/adapters/openai-chat/passthrough.ts +35 -14
- package/src/adapters/openai-chat/reasoning-replay.ts +27 -16
- package/src/adapters/openai-chat/reasoning-wire.ts +117 -8
- package/src/adapters/openai-chat/required-tool-result.ts +64 -0
- package/src/adapters/openai-chat/tool-name-registry.ts +3 -1
- package/src/adapters/openai-chat.ts +9 -10
- package/src/adapters/openai-responses/passthrough.ts +7 -4
- package/src/adapters/openai-responses/reasoning.ts +13 -0
- package/src/adapters/openai-responses/request-strips.ts +60 -0
- package/src/adapters/qoder/adapter.ts +129 -8
- package/src/adapters/qoder/scaffold-guard.ts +5 -0
- package/src/adapters/reasoning-controls.ts +16 -0
- package/src/adapters/registry.ts +5 -0
- package/src/adapters/tool-call-id.ts +1 -3
- package/src/adapters/workbuddy-schema.ts +61 -0
- package/src/adapters/workbuddy.ts +68 -0
- package/src/bridge/errors.ts +27 -0
- package/src/bridge/response-json.ts +1 -1
- package/src/bridge/sse.ts +1 -1
- package/src/bridge.ts +1 -1
- package/src/chat/inbound.ts +4 -1
- package/src/chat/outbound.ts +20 -6
- package/src/chat/reasoning-details.ts +28 -5
- package/src/claude/desktop-first-party.ts +54 -4
- package/src/claude/desktop-picker.ts +11 -8
- package/src/claude/first-party-settings.ts +3 -1
- package/src/claude/inbound.ts +2 -1
- package/src/claude/intercept/local-ca.ts +2 -1
- package/src/claude/intercept/picker-ca-cleanup.ts +4 -2
- package/src/claude/intercept/picker-ca-startup.ts +3 -1
- package/src/claude/intercept/picker-models.ts +6 -3
- package/src/claude/intercept/picker-runtime.ts +3 -2
- package/src/claude/intercept/runtime.ts +6 -3
- package/src/claude/model-info.ts +31 -8
- package/src/cli/account-api.ts +11 -0
- package/src/cli/capabilities-agents-routing.ts +3 -3
- package/src/cli/capabilities-base.ts +7 -1
- package/src/cli/capabilities-observe-system.ts +10 -0
- package/src/cli/claude-desktop.ts +9 -8
- package/src/cli/claude.ts +3 -2
- package/src/cli/codex-cli-update.ts +8 -0
- package/src/cli/codex-shim-autorestore.ts +9 -0
- package/src/cli/combo-result.ts +13 -0
- package/src/cli/combo-stats.ts +3 -0
- package/src/cli/combo.ts +83 -41
- package/src/cli/cross-home-owner.ts +13 -1
- package/src/cli/dispatch.ts +25 -6
- package/src/cli/ensure-desired-integrations.ts +8 -6
- package/src/cli/export-command.ts +4 -1
- package/src/cli/help.ts +2 -1
- package/src/cli/index.ts +45 -45
- package/src/cli/integration-plan-dto.ts +4 -0
- package/src/cli/launcher-context.ts +49 -2
- package/src/cli/link.ts +45 -32
- package/src/cli/opencode.ts +20 -9
- package/src/cli/provider.ts +2 -1
- package/src/cli/registry.ts +6 -4
- package/src/cli/root.ts +9 -0
- package/src/cli/status.ts +59 -1
- package/src/cli/stop-restore.ts +113 -0
- package/src/cli/sync-expectation.ts +60 -0
- package/src/cli/uninstall-integrations.ts +41 -7
- package/src/cli/usage-compare.ts +68 -12
- package/src/client/connect.ts +40 -3
- package/src/client/link-home.ts +10 -1
- package/src/client/link-ingress.ts +1 -1
- package/src/client/link-readiness.ts +97 -0
- package/src/client/link-relay-transport.ts +79 -11
- package/src/client/link-relay.ts +74 -15
- package/src/client/link-tunnel.ts +45 -18
- package/src/client/machine-api.ts +3 -1
- package/src/client/machine-listener.ts +20 -2
- package/src/client/runtime.ts +20 -2
- package/src/client/sync-expectation.ts +118 -0
- package/src/clients/config-export/agent-clients.ts +96 -0
- package/src/clients/config-export/contracts.ts +25 -7
- package/src/clients/config-export/qoder.ts +38 -23
- package/src/clients/config-export/reasoning-metadata.ts +55 -8
- package/src/clients/config-export.ts +12 -0
- package/src/clients/lazycodex.ts +7 -2
- package/src/clients/reasoning-controls.ts +49 -0
- package/src/codex/account-store.ts +17 -3
- package/src/codex/app-server-restart-service.ts +6 -5
- package/src/codex/auth-api/account-identity.ts +14 -0
- package/src/codex/auth-api/account-list.ts +29 -2
- package/src/codex/auth-api/http.ts +13 -0
- package/src/codex/auth-api/main-account-probe.ts +2 -2
- package/src/codex/auth-api/pool-mode-gate.ts +16 -3
- package/src/codex/auth-api/pool-quota-probe.ts +15 -0
- package/src/codex/auth-context.ts +15 -12
- package/src/codex/catalog/build-entries.ts +22 -0
- package/src/codex/catalog/configured-tiers.ts +70 -0
- package/src/codex/catalog/effort.ts +52 -11
- package/src/codex/catalog/gather-capture.ts +5 -2
- package/src/codex/catalog/heal-observation.ts +155 -13
- package/src/codex/catalog/metadata.ts +6 -0
- package/src/codex/catalog/model-hints.ts +60 -11
- package/src/codex/catalog/model-visibility.ts +3 -2
- package/src/codex/catalog/native-models.ts +18 -3
- package/src/codex/catalog/parsing.ts +10 -8
- package/src/codex/catalog/pinned-models.ts +2 -1
- package/src/codex/catalog/provider-models.ts +18 -13
- package/src/codex/catalog/retained-sync.ts +2 -1
- package/src/codex/catalog/routed-gather.ts +19 -20
- package/src/codex/catalog/write-audit.ts +3 -2
- package/src/codex/catalog-self-heal.ts +43 -23
- package/src/codex/chatgpt-refresh-failure.ts +6 -2
- package/src/codex/cli-install-provenance.ts +418 -0
- package/src/codex/cli-installation-targets.ts +5 -1
- package/src/codex/cli-update-plan.ts +43 -16
- package/src/codex/collision-identity.ts +30 -5
- package/src/codex/convergence.ts +4 -3
- package/src/codex/data/roster-pinned-models.json +177 -1
- package/src/codex/desired-state.ts +6 -1
- package/src/codex/desktop-app/picker-freshness.ts +10 -8
- package/src/codex/desktop-compatibility/installed-build.ts +88 -12
- package/src/codex/desktop-compatibility/runtime.ts +29 -5
- package/src/codex/desktop-compatibility/usage-activation.ts +2 -1
- package/src/codex/desktop-compatibility/usage-controller.ts +9 -1
- package/src/codex/desktop-compatibility/windows-certificate-trust.ts +46 -12
- package/src/codex/inject/config-toml.ts +0 -18
- package/src/codex/inject/plan.ts +18 -3
- package/src/codex/inject/remove.ts +6 -2
- package/src/codex/inject.ts +1 -1
- package/src/codex/journal.ts +61 -1
- package/src/codex/model-entitlements.ts +1 -1
- package/src/codex/native-main-owner.ts +27 -1
- package/src/codex/native-profile-store.ts +2 -1
- package/src/codex/pool-credit-policy.ts +35 -1
- package/src/codex/pool-refresh-backoff.ts +3 -1
- package/src/codex/quota-types.ts +3 -0
- package/src/codex/quota.ts +24 -4
- package/src/codex/role-auto-assign.ts +6 -2
- package/src/codex/subagent-defaults.ts +49 -4
- package/src/codex/user-identity.ts +35 -6
- package/src/codex/windows-current-sid.ts +162 -0
- package/src/combos/failover.ts +17 -2
- package/src/combos/jev-decision-contract.ts +22 -1
- package/src/combos/jev-quota-activation.ts +5 -1
- package/src/combos/jev-quota-route.ts +1 -1
- package/src/combos/jev-quota.ts +9 -1
- package/src/combos/jev-service-exchange.ts +3 -1
- package/src/combos/jev-session-pin-config.ts +51 -0
- package/src/combos/jev.ts +101 -9
- package/src/combos/resolve.ts +45 -1
- package/src/combos/types.ts +43 -0
- package/src/config/load-degrade.ts +5 -0
- package/src/config/paths.ts +19 -3
- package/src/config/pending-teardown.ts +22 -1
- package/src/config/provider-validation.ts +22 -4
- package/src/config/removed-opencode-free.ts +11 -0
- package/src/config/schema/leaf-validators.ts +6 -0
- package/src/generated/compatibility-version.json +467 -311
- package/src/generated/model-metadata.ts +5 -5
- package/src/images/loop.ts +16 -2
- package/src/integrations/catalog-refresh.ts +1 -1
- package/src/integrations/hermes-profiles.ts +251 -0
- package/src/integrations/merge.ts +8 -0
- package/src/integrations/mutation-plan.ts +19 -4
- package/src/integrations/registry.ts +5 -0
- package/src/integrations/state.ts +36 -1
- package/src/integrations/writer.ts +18 -4
- package/src/lib/bun-path-runtime.mjs +2 -1
- package/src/lib/decision-quota-sink.ts +10 -0
- package/src/lib/errors.ts +62 -0
- package/src/lib/eventstream-decoder.ts +81 -37
- package/src/lib/opaque-proxy-tunnel.ts +32 -8
- package/src/lib/pinned-http.ts +35 -2
- package/src/lib/process-control.ts +13 -1
- package/src/lib/socks5-fetch.ts +59 -64
- package/src/lib/socks5-upload-waiter.ts +50 -0
- package/src/lib/sse-decoder.ts +7 -2
- package/src/lib/state-store-sweeper.ts +40 -14
- package/src/lib/translator-budget.ts +4 -4
- package/src/lib/upstream-retry.ts +4 -1
- package/src/lib/windows-native-principal-worker.ts +14 -0
- package/src/lib/windows-native-principal.ts +188 -0
- package/src/lib/windows-secret-acl.ts +39 -3
- package/src/lib/windows-user-principal.ts +62 -18
- package/src/link/diagnostics.ts +193 -0
- package/src/link/relay-auth.ts +6 -0
- package/src/link/ssh-config.ts +35 -3
- package/src/link/status-projection.ts +39 -0
- package/src/link/supervisor.ts +45 -12
- package/src/link/tunnel-history.ts +109 -0
- package/src/link/tunnel-state.ts +80 -17
- package/src/messaging/remote-files.ts +24 -1
- package/src/oauth/generic-account-failover.ts +91 -7
- package/src/oauth/index.ts +15 -0
- package/src/oauth/model-discovery-auth.ts +5 -0
- package/src/oauth/store.ts +4 -1
- package/src/oauth/token-guardian.ts +7 -0
- package/src/oauth/types.ts +9 -0
- package/src/oauth/workbuddy.ts +139 -0
- package/src/providers/account-quota-disk.ts +12 -4
- package/src/providers/antigravity-quota-identity.ts +37 -0
- package/src/providers/base-url-choices.ts +8 -5
- package/src/providers/codebuddy-models.ts +6 -0
- package/src/providers/codex-capacity.ts +3 -1
- package/src/providers/derive.ts +51 -3
- package/src/providers/kiro-models.ts +3 -0
- package/src/providers/mimo-thinking.ts +12 -0
- package/src/providers/model-discovery.ts +2 -0
- package/src/providers/model-rename-fields.ts +2 -0
- package/src/providers/model-rename-migration.ts +10 -0
- package/src/providers/openai-sidecar-credit.ts +2 -2
- package/src/providers/quota/account-cache.ts +3 -2
- package/src/providers/quota/antigravity.ts +25 -14
- package/src/providers/quota/report-cache.ts +13 -4
- package/src/providers/quota/vendor-probes-key.ts +60 -0
- package/src/providers/quota/workbuddy.ts +83 -0
- package/src/providers/quota-decision-antigravity.ts +64 -0
- package/src/providers/quota-decision-publication.ts +11 -0
- package/src/providers/quota-decision-snapshot.ts +21 -4
- package/src/providers/quota-types.ts +2 -0
- package/src/providers/quota.ts +3 -1
- package/src/providers/reasoning-capabilities.ts +76 -0
- package/src/providers/registry/entries-core.ts +23 -12
- package/src/providers/registry/entries-extended.ts +83 -27
- package/src/providers/registry/model-ids.ts +5 -0
- package/src/providers/registry/model-seeds.ts +120 -56
- package/src/providers/registry/types.ts +29 -2
- package/src/providers/resolved-model-policy.ts +30 -10
- package/src/providers/routed-config.ts +24 -1
- package/src/providers/stale-model-roster-migration.ts +123 -18
- package/src/providers/workbuddy-credit-balance.ts +81 -0
- package/src/providers/workbuddy-models.ts +37 -0
- package/src/providers/workbuddy.ts +60 -0
- package/src/remote-control/workspace-pi-runtime.ts +11 -6
- package/src/responses/compaction-summary.ts +45 -0
- package/src/responses/muse-tool-name-alias.ts +1 -2
- package/src/responses/parser.ts +3 -2
- package/src/responses/reasoning-replay-cache.ts +18 -14
- package/src/responses/schema.ts +1 -0
- package/src/responses/thought-signature-replay.ts +10 -2
- package/src/router.ts +2 -0
- package/src/routing/analytics.ts +2 -3
- package/src/routing/capability.ts +8 -2
- package/src/routing/fallback-policy.ts +3 -3
- package/src/routing/history/ingest.ts +28 -3
- package/src/server/auth-cors.ts +4 -2
- package/src/server/chat-completions.ts +21 -1
- package/src/server/chat-native-eligibility.ts +7 -0
- package/src/server/chat-native-reasoning.ts +24 -7
- package/src/server/chat-native.ts +13 -2
- package/src/server/claude-messages.ts +3 -0
- package/src/server/direct-local-http.ts +5 -2
- package/src/server/effort-policy.ts +5 -1
- package/src/server/index/link-relay-sessions.ts +9 -5
- package/src/server/index/live-sideband.ts +18 -15
- package/src/server/index/optional-listeners.ts +4 -0
- package/src/server/index/serve-options.ts +5 -4
- package/src/server/local-management-read-client.ts +3 -1
- package/src/server/management/agent-settings-routes.ts +27 -15
- package/src/server/management/combo-routes.ts +14 -4
- package/src/server/management/config-routes.ts +2 -2
- package/src/server/management/decision-discovery.ts +12 -2
- package/src/server/management/hermes-profile-routes.ts +156 -0
- package/src/server/management/integration-routes.ts +85 -24
- package/src/server/management/link-routes.ts +5 -2
- package/src/server/management/model-routes.ts +2 -2
- package/src/server/management/model-row-export-metadata.ts +25 -6
- package/src/server/management/model-rows.ts +15 -20
- package/src/server/management/native-integration-routes.ts +11 -8
- package/src/server/management/provider-routes.ts +1 -1
- package/src/server/management/route-registry.ts +4 -0
- package/src/server/management-api.ts +5 -0
- package/src/server/models-capabilities.ts +21 -3
- package/src/server/port-reclaim.ts +51 -9
- package/src/server/request-log-conversation.ts +49 -0
- package/src/server/request-log.ts +2 -0
- package/src/server/responses/adapter-delivery.ts +11 -1
- package/src/server/responses/adapter-dispatch.ts +2 -2
- package/src/server/responses/anthropic-thinking-recovery.ts +1 -0
- package/src/server/responses/codex-ws-exchange.ts +39 -9
- package/src/server/responses/codex-ws-session.ts +38 -4
- package/src/server/responses/codex-ws-wire.ts +6 -1
- package/src/server/responses/combo-required-tool-contract.ts +103 -0
- package/src/server/responses/combo-stream-preflight.ts +8 -1
- package/src/server/responses/compact.ts +14 -5
- package/src/server/responses/context-overflow.ts +8 -1
- package/src/server/responses/core-combo-failure.ts +10 -0
- package/src/server/responses/core-combo.ts +74 -44
- package/src/server/responses/core-lifetime.ts +5 -2
- package/src/server/responses/core-normalize.ts +17 -4
- package/src/server/responses/core-opaque-recovery.ts +1 -0
- package/src/server/responses/core-options.ts +7 -0
- package/src/server/responses/core-replay.ts +2 -1
- package/src/server/responses/jev-combo-choice.ts +39 -0
- package/src/server/responses/jev-session-pin.ts +203 -0
- package/src/server/responses/main-hard-lock-routing.ts +60 -44
- package/src/server/responses/passthrough-delivery.ts +44 -2
- package/src/server/responses/policy-fallback.ts +6 -1
- package/src/server/responses/request-compression.ts +12 -7
- package/src/server/responses/request-prepare.ts +32 -7
- package/src/server/responses/request-sidecar-auth.ts +2 -0
- package/src/server/responses/request-transport.ts +25 -6
- package/src/server/responses/response-effects.ts +22 -10
- package/src/server/responses/run-turn-execution.ts +2 -4
- package/src/server/responses/sidecar-execution.ts +13 -7
- package/src/server/responses-phase-inference.ts +267 -0
- package/src/server/sse-payload-rewrite.ts +14 -1
- package/src/server/stop-teardown.ts +36 -1
- package/src/server/ws-bridge.ts +1 -1
- package/src/service/definition.ts +20 -8
- package/src/service/desktop-supervision.d.mts +7 -4
- package/src/service/desktop-supervision.mjs +90 -13
- package/src/service/ownership-mutation-lease.mjs +21 -7
- package/src/types/config.ts +14 -2
- package/src/types/provider.ts +29 -7
- package/src/types/request.ts +11 -0
- package/src/types/wire.ts +1 -0
- package/src/types.ts +1 -0
- package/src/update/bind-probe.ts +29 -0
- package/src/update/codex-cli-update-launch-policy.d.mts +9 -0
- package/src/update/codex-cli-update-launch-policy.mjs +30 -0
- package/src/update/job.ts +10 -29
- package/src/update/npm-install-job.ps1 +173 -0
- package/src/update/npm-install.mjs +70 -0
- package/src/update/stop-contract.d.mts +1 -0
- package/src/update/stop-contract.mjs +14 -0
- package/src/update/stop-decision.d.mts +1 -1
- package/src/update/stop-decision.mjs +13 -3
- package/src/update/teardown-handover.ts +166 -0
- package/src/update/transactional-install.d.mts +14 -3
- package/src/update/transactional-install.mjs +33 -7
- package/src/usage/expected-prices.ts +64 -31
- package/src/usage/jev-stats.ts +54 -14
- package/src/usage/timeline.ts +19 -9
- package/src/vision/eligibility.ts +15 -5
- package/src/vision/plan.ts +2 -2
- package/src/web-search/loop.ts +16 -2
- package/gui/dist/assets/App-nZ34cR5G.js +0 -58
- package/gui/dist/assets/index-DGXS51sp.js +0 -94
- package/gui/dist/assets/index-DPeB9HpV.css +0 -1
- package/gui/dist/assets/quota-summary-DO1Sx5TM.js +0 -1
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { OcxProviderConfig } from "../types";
|
|
2
|
+
import { isDeclaredReasoningEffort, isReasoningEffortOmitted, modelRecordValue, reasoningEffortMapFor } from "../reasoning-effort";
|
|
3
|
+
import { resolveReasoningCapabilities } from "../providers/reasoning-capabilities";
|
|
4
|
+
|
|
5
|
+
function mappedClientEffort(provider: OcxProviderConfig, modelId: string, requested: string | undefined): string | undefined {
|
|
6
|
+
if (requested === undefined || !isDeclaredReasoningEffort(requested)) return undefined;
|
|
7
|
+
const key = requested === "ultra" ? "max" : requested;
|
|
8
|
+
const map = reasoningEffortMapFor(provider, modelId);
|
|
9
|
+
return map && Object.hasOwn(map, key) ? map[key] : requested;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
/** Decode an effort-only client's switch without turning it into a model strength. */
|
|
13
|
+
export function resolveThinkingEnabled(
|
|
14
|
+
provider: OcxProviderConfig,
|
|
15
|
+
modelId: string,
|
|
16
|
+
options: { thinkingEnabled?: boolean; reasoning?: string },
|
|
17
|
+
): boolean | undefined {
|
|
18
|
+
const capabilities = resolveReasoningCapabilities(provider, modelId);
|
|
19
|
+
if (capabilities.supportsReasoning === false || capabilities.supportsThinkingToggle !== true) return undefined;
|
|
20
|
+
if (typeof options.thinkingEnabled === "boolean") return options.thinkingEnabled;
|
|
21
|
+
// Effort-enum clients select a switch and, when supported, a real positive strength.
|
|
22
|
+
// An explicit boolean above remains independent and takes precedence over that shorthand.
|
|
23
|
+
const effort = options.reasoning ?? (capabilities.supportsReasoningEffort === false
|
|
24
|
+
? modelRecordValue(provider.modelDefaultReasoningEfforts, modelId) : undefined);
|
|
25
|
+
const value = mappedClientEffort(provider, modelId, effort);
|
|
26
|
+
if (value !== undefined) {
|
|
27
|
+
// Legacy adaptive wire policy cannot be represented by a boolean; leave its serializer in charge.
|
|
28
|
+
if (isReasoningEffortOmitted(value) || value === "adaptive") return undefined;
|
|
29
|
+
return value !== "none" && value !== "disabled";
|
|
30
|
+
}
|
|
31
|
+
return capabilities.defaultThinkingEnabled;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Resolve client aliases before strength-only policy can strip or clamp them. */
|
|
35
|
+
export function normalizeThinkingOptions(provider: OcxProviderConfig, modelId: string, options: { thinkingEnabled?: boolean; reasoning?: string }): void {
|
|
36
|
+
const capabilities = resolveReasoningCapabilities(provider, modelId);
|
|
37
|
+
if (capabilities.supportsReasoning === false) {
|
|
38
|
+
delete options.thinkingEnabled;
|
|
39
|
+
delete options.reasoning;
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
const enabled = resolveThinkingEnabled(provider, modelId, options);
|
|
43
|
+
if (enabled !== undefined) options.thinkingEnabled = enabled;
|
|
44
|
+
else if (capabilities.supportsThinkingToggle === false) delete options.thinkingEnabled;
|
|
45
|
+
const mapped = mappedClientEffort(provider, modelId, options.reasoning);
|
|
46
|
+
const preserveWirePolicy = capabilities.supportsThinkingToggle === true
|
|
47
|
+
&& (mapped === "adaptive" || isReasoningEffortOmitted(mapped));
|
|
48
|
+
if (capabilities.supportsReasoningEffort === false && !preserveWirePolicy) delete options.reasoning;
|
|
49
|
+
}
|
|
@@ -12,13 +12,15 @@ import {
|
|
|
12
12
|
backupInvalidConfig,
|
|
13
13
|
hardenConfigDir,
|
|
14
14
|
hardenExistingSecret,
|
|
15
|
+
loadConfig,
|
|
15
16
|
withConfigMutationLockSync,
|
|
16
17
|
} from "../config";
|
|
17
18
|
import { notifyCodexStoreLoaded } from "../lib/decision-quota-sink";
|
|
18
19
|
import { assertNotRealHomeUnderTest } from "../lib/test-home-guard";
|
|
19
|
-
import type { CodexAccountCredentialRecord, CodexAccountCredentials } from "../types";
|
|
20
|
+
import type { CodexAccount, CodexAccountCredentialRecord, CodexAccountCredentials } from "../types";
|
|
20
21
|
import { advanceCodexCredentialMutationEpoch } from "./credential-mutation-epoch";
|
|
21
22
|
import { isValidCodexAccountId } from "./account-id";
|
|
23
|
+
import { codexAccountLogLabel, fallbackCodexAccountLogLabel } from "./account-label";
|
|
22
24
|
import type { PoolQuotaWriter } from "./quota-types";
|
|
23
25
|
import { CODEX_REFRESH_FLIGHT_CEILING_MS } from "./quota-recovery-timing";
|
|
24
26
|
|
|
@@ -183,6 +185,18 @@ function persistCredentialMutation(store: CodexAccountStore): void {
|
|
|
183
185
|
advanceCodexCredentialMutationEpoch();
|
|
184
186
|
}
|
|
185
187
|
|
|
188
|
+
/**
|
|
189
|
+
* The durable `p<hex6>` label the dashboard and usage log show for this pool account, so a refresh
|
|
190
|
+
* failure line can be matched to the account row (#7592). The id hash is only the label of a
|
|
191
|
+
* legacy row that never received one. A config read failure must not replace the refresh error
|
|
192
|
+
* being reported, so it degrades to that same hash.
|
|
193
|
+
*/
|
|
194
|
+
function poolAccountLogLabel(id: string): string {
|
|
195
|
+
let account: CodexAccount | undefined;
|
|
196
|
+
try { account = loadConfig().codexAccounts?.find(row => row.id === id); } catch { account = undefined; }
|
|
197
|
+
return account ? codexAccountLogLabel(account) : fallbackCodexAccountLogLabel(id);
|
|
198
|
+
}
|
|
199
|
+
|
|
186
200
|
/**
|
|
187
201
|
* Validation metadata that survives a credential write.
|
|
188
202
|
*
|
|
@@ -1055,7 +1069,7 @@ export async function forceRefreshCodexPoolToken(
|
|
|
1055
1069
|
if (isTerminalCodexPoolRefreshFailure(error) || isOperationalCodexPoolRefreshFailure(error)) {
|
|
1056
1070
|
if (isTerminalCodexPoolRefreshFailure(error)) clearCodexPoolRefreshFailure(id);
|
|
1057
1071
|
} else {
|
|
1058
|
-
noteCodexPoolRefreshFailure(id, classifyCodexPoolRefreshFailureReason(error), undefined, refreshFence);
|
|
1072
|
+
noteCodexPoolRefreshFailure(id, classifyCodexPoolRefreshFailureReason(error), undefined, refreshFence, poolAccountLogLabel);
|
|
1059
1073
|
}
|
|
1060
1074
|
settle({ kind: "failed", error });
|
|
1061
1075
|
},
|
|
@@ -1376,7 +1390,7 @@ async function resolveCodexToken(
|
|
|
1376
1390
|
.catch(() => undefined);
|
|
1377
1391
|
const failure = classifyChatgptRefreshFailure(res.status, body?.displaySafe ? body.text : "");
|
|
1378
1392
|
const { reason } = failure;
|
|
1379
|
-
noteChatgptRefreshFailure("pool", res.status, failure);
|
|
1393
|
+
noteChatgptRefreshFailure("pool", res.status, failure, poolAccountLogLabel(id));
|
|
1380
1394
|
throw new TokenRefreshError(reason, `Codex token refresh failed (${reason}); reauthenticate the account.`, res.status, failure.code);
|
|
1381
1395
|
}
|
|
1382
1396
|
const data = (await res.json()) as { access_token: string; refresh_token?: string; expires_in: number };
|
|
@@ -182,11 +182,12 @@ async function runCodexRestart(io: CodexRestartServiceIo): Promise<CodexRestartR
|
|
|
182
182
|
// Decided here, before the early returns, because the model picker lives in the DESKTOP
|
|
183
183
|
// app: "no app-server is running" is not a reason to leave a stale roster on screen.
|
|
184
184
|
//
|
|
185
|
-
// The shell
|
|
186
|
-
//
|
|
187
|
-
//
|
|
188
|
-
//
|
|
189
|
-
//
|
|
185
|
+
// The shell gets a restart attempt whenever its picker cannot be proven current: at
|
|
186
|
+
// or before the catalog mtime it is stale, and newer is unknown because an earlier
|
|
187
|
+
// sync may have rebound an already-existing catalog file (#4761). Quitting it
|
|
188
|
+
// discards composer drafts, unsent picker selections and pending approvals. The
|
|
189
|
+
// attempt is explicit, not a guarantee: the restart helper can refuse or partially
|
|
190
|
+
// fail, and desktopApp reports that outcome.
|
|
190
191
|
//
|
|
191
192
|
// allowHandoff is false and that is deliberate. The handoff waits for the CALLING
|
|
192
193
|
// process to exit, and this runs inside a long-lived proxy that does not, so every
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { createHmac } from "node:crypto";
|
|
2
|
+
|
|
3
|
+
/** A local, versioned join key for two slots backed by the same upstream user. */
|
|
4
|
+
export function codexUpstreamAccountKey(
|
|
5
|
+
adminToken: string | null,
|
|
6
|
+
accountId: string | null | undefined,
|
|
7
|
+
userId: string | null | undefined,
|
|
8
|
+
): string | undefined {
|
|
9
|
+
if (!adminToken || !accountId || !userId || accountId.length > 512 || userId.length > 512) return undefined;
|
|
10
|
+
return `uai1_${createHmac("sha256", adminToken)
|
|
11
|
+
.update("opencodex-upstream-account-v1\0")
|
|
12
|
+
.update(JSON.stringify([accountId, userId]))
|
|
13
|
+
.digest("hex")}`;
|
|
14
|
+
}
|
|
@@ -28,12 +28,16 @@ import type { OAuthAccountHealth, OAuthHealthLabel } from "../../oauth/health";
|
|
|
28
28
|
import { isSelectableCodexPoolAccount } from "../account-id";
|
|
29
29
|
import type { AdmissionLease } from "../../lib/admission";
|
|
30
30
|
import { tryAcquireNativeMainProfileClaim } from "../native-main-admission";
|
|
31
|
-
import { withNativeMainCredentialClaim, isNativeMainClaimUnavailable } from "./http";
|
|
31
|
+
import { withNativeMainCredentialClaim, isNativeMainClaimUnavailable, isNativeMainObservationUnavailable } from "./http";
|
|
32
32
|
import { fetchMainAccountInfoAttempt, EMPTY_MAIN_ACCOUNT_INFO, mainResetCreditsForCurrentIdentity } from "./main-account-probe";
|
|
33
33
|
import { fetchPoolAccountQuota, PoolQuotaProbeBusyError, POOL_QUOTA_REFRESH_CONCURRENCY } from "./pool-quota-probe";
|
|
34
34
|
import type { PoolQuotaResult } from "./pool-quota-probe";
|
|
35
35
|
import { getRuntimeConfig, configuredPoolAccount, mapWithConcurrency } from "./runtime-config";
|
|
36
36
|
import { isPassiveRead } from "../../lib/passive-read";
|
|
37
|
+
import { configuredAdminToken } from "../../lib/admin-secrets";
|
|
38
|
+
import { nativeUserIdClaims } from "../reserve-availability";
|
|
39
|
+
import { extractAccountIdClaims } from "../../oauth/chatgpt";
|
|
40
|
+
import { codexUpstreamAccountKey } from "./account-identity";
|
|
37
41
|
import { CODEX_MAIN_DUPLICATE_ACTION, configuredCodexMainDuplicate, getObservedMainCodexCollisionIdentity } from "../collision-identity";
|
|
38
42
|
|
|
39
43
|
export function quotaForPlan<T extends Omit<StoredAccountQuota, "updatedAt"> | StoredAccountQuota | null>(
|
|
@@ -109,6 +113,7 @@ export function poolAccountDto(
|
|
|
109
113
|
paused: boolean,
|
|
110
114
|
priority: number,
|
|
111
115
|
maskEmails: boolean,
|
|
116
|
+
upstreamAccountKey?: string,
|
|
112
117
|
): CodexAuthAccountDto {
|
|
113
118
|
const plan = codexPlanValue(account.plan);
|
|
114
119
|
const quota = quotaForPlan(quotaResult.quota, plan);
|
|
@@ -136,6 +141,9 @@ export function poolAccountDto(
|
|
|
136
141
|
const duplicateMain = configuredCodexMainDuplicate(config, account.id);
|
|
137
142
|
return {
|
|
138
143
|
id: account.id,
|
|
144
|
+
slotId: account.id,
|
|
145
|
+
slotKind: "pool",
|
|
146
|
+
...(upstreamAccountKey ? { upstreamAccountKey } : {}),
|
|
139
147
|
email: projectEmail(account.email, maskEmails) ?? account.email,
|
|
140
148
|
...(account.alias !== undefined ? { alias: account.alias } : {}),
|
|
141
149
|
...(plan !== undefined ? { plan } : {}),
|
|
@@ -166,6 +174,11 @@ export function poolAccountDto(
|
|
|
166
174
|
|
|
167
175
|
export interface CodexAuthAccountDto {
|
|
168
176
|
id: string;
|
|
177
|
+
/** Registered slot identity; equal to id, including __main__ for native Codex. */
|
|
178
|
+
slotId: string;
|
|
179
|
+
slotKind: "native-main" | "pool";
|
|
180
|
+
/** Opaque local join key, present only with account and user claims. */
|
|
181
|
+
upstreamAccountKey?: string;
|
|
169
182
|
alias?: string;
|
|
170
183
|
email: string;
|
|
171
184
|
plan?: string | null;
|
|
@@ -285,6 +298,7 @@ export async function listCodexAuthAccountsSnapshot(
|
|
|
285
298
|
pruneCodexCredits([MAIN_CODEX_ACCOUNT_ID, ...poolAccounts.map(account => account.id)]);
|
|
286
299
|
// One redaction decision for the whole snapshot, read once from the operator's config (#3859).
|
|
287
300
|
const maskEmails = emailMaskingEnabled(runtimeConfig);
|
|
301
|
+
const identitySecret = configuredAdminToken();
|
|
288
302
|
// A passive read (a Remote Link Child's, #6959) reports what this machine already observed: no
|
|
289
303
|
// token refresh, no WHAM probe, and so none of the plan or credential writes they make.
|
|
290
304
|
const passive = isPassiveRead();
|
|
@@ -292,6 +306,7 @@ export async function listCodexAuthAccountsSnapshot(
|
|
|
292
306
|
? { info: getMainAccountInfoCache() ?? EMPTY_MAIN_ACCOUNT_INFO, credentialChecked: false, hasCredential: false,
|
|
293
307
|
identityGeneration: captureMainAccountIdentityGeneration() }
|
|
294
308
|
: await fetchMainAccountInfoAttempt(forceRefresh, 1, undefined, false, forceRefresh, false, runtimeConfig);
|
|
309
|
+
const observedMainIdentity = getObservedMainCodexCollisionIdentity();
|
|
295
310
|
const refreshedPool = await mapWithConcurrency(poolAccounts, POOL_QUOTA_REFRESH_CONCURRENCY, async account => {
|
|
296
311
|
const cred = getCodexAccountCredential(account.id);
|
|
297
312
|
let quotaResult: PoolQuotaResult;
|
|
@@ -363,6 +378,10 @@ export async function listCodexAuthAccountsSnapshot(
|
|
|
363
378
|
const dtoAccount = generationLive && quotaResult.freshPlan
|
|
364
379
|
? { ...currentAccount, plan: quotaResult.freshPlan }
|
|
365
380
|
: currentAccount;
|
|
381
|
+
const user = nativeUserIdClaims(currentCredential.accessToken);
|
|
382
|
+
const accountClaim = extractAccountIdClaims(currentCredential.accessToken);
|
|
383
|
+
const verifiedAccountId = !accountClaim.conflict && accountClaim.accountId === currentCredential.chatgptAccountId
|
|
384
|
+
? accountClaim.accountId : undefined;
|
|
366
385
|
return [poolAccountDto(
|
|
367
386
|
runtimeConfig,
|
|
368
387
|
dtoAccount,
|
|
@@ -371,6 +390,8 @@ export async function listCodexAuthAccountsSnapshot(
|
|
|
371
390
|
isCodexAccountPaused(runtimeConfig, accountId),
|
|
372
391
|
getCodexAccountPriority(runtimeConfig, accountId),
|
|
373
392
|
maskEmails,
|
|
393
|
+
codexUpstreamAccountKey(identitySecret, verifiedAccountId,
|
|
394
|
+
user.conflict ? undefined : user.userId),
|
|
374
395
|
)];
|
|
375
396
|
});
|
|
376
397
|
const projectSnapshot = (mainRefreshRefused = false): CodexAuthAccountsSnapshot => {
|
|
@@ -402,8 +423,14 @@ export async function listCodexAuthAccountsSnapshot(
|
|
|
402
423
|
? mainResult.terminalAuthFailure === true && liveQuotaRefresh?.status === "http_error"
|
|
403
424
|
? "unauthorized" : "refresh_failed"
|
|
404
425
|
: mainHealth.status === "reauth_required" ? mainHealth.reason : undefined;
|
|
426
|
+
const mainIdentity = mainSnapshotLive && getObservedMainCodexCollisionIdentity() === observedMainIdentity
|
|
427
|
+
? observedMainIdentity : undefined;
|
|
428
|
+
const mainAccountKey = codexUpstreamAccountKey(identitySecret, mainIdentity?.accountId, mainIdentity?.userId);
|
|
405
429
|
const main: CodexAuthAccountDto = {
|
|
406
430
|
id: MAIN_CODEX_ACCOUNT_ID,
|
|
431
|
+
slotId: MAIN_CODEX_ACCOUNT_ID,
|
|
432
|
+
slotKind: "native-main",
|
|
433
|
+
...(mainAccountKey ? { upstreamAccountKey: mainAccountKey } : {}),
|
|
407
434
|
email: projectEmail(mainInfo.email, maskEmails) ?? "Codex App login",
|
|
408
435
|
plan: mainInfo.plan,
|
|
409
436
|
...(liveQuotaRefresh ? { quotaRefresh: liveQuotaRefresh } : {}),
|
|
@@ -442,7 +469,7 @@ export async function listCodexAuthAccountsSnapshot(
|
|
|
442
469
|
try {
|
|
443
470
|
return await withNativeMainCredentialClaim(async () => projectSnapshot(isMainAccountRefreshGrantRejected()));
|
|
444
471
|
} catch (error) {
|
|
445
|
-
if (
|
|
472
|
+
if (isNativeMainObservationUnavailable(error)) return projectSnapshot();
|
|
446
473
|
throw error;
|
|
447
474
|
} finally {
|
|
448
475
|
projectionLease.release();
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { codexHomeIsAbsent } from "../codex-home-owner";
|
|
2
|
+
import { getCodexHome } from "../paths";
|
|
1
3
|
import { withNativeMainSharedClaim } from "../native-main-claim";
|
|
2
4
|
import { resolveNativeProfileContext } from "../native-profile-store";
|
|
3
5
|
import { NativeProfileError } from "../native-profile-types";
|
|
@@ -7,6 +9,17 @@ export function isNativeMainClaimUnavailable(error: unknown): error is NativePro
|
|
|
7
9
|
&& (error.code === "NATIVE_MAIN_CLAIM_BUSY" || error.code === "NATIVE_MAIN_CLAIM_UNAVAILABLE");
|
|
8
10
|
}
|
|
9
11
|
|
|
12
|
+
/** Missing native homes leave reads unobserved; credential operations still require their claim. */
|
|
13
|
+
export function isNativeMainObservationUnavailable(error: unknown): error is NativeProfileError {
|
|
14
|
+
if (isNativeMainClaimUnavailable(error)) return true;
|
|
15
|
+
if (!(error instanceof NativeProfileError) || error.code !== "CODEX_HOME_UNAVAILABLE") return false;
|
|
16
|
+
try {
|
|
17
|
+
return codexHomeIsAbsent(getCodexHome());
|
|
18
|
+
} catch {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
10
23
|
export function withNativeMainCredentialClaim<T>(operation: () => Promise<T>): Promise<T> {
|
|
11
24
|
return withNativeMainSharedClaim(resolveNativeProfileContext(), operation);
|
|
12
25
|
}
|
|
@@ -23,7 +23,7 @@ import type { AdmissionLease } from "../../lib/admission";
|
|
|
23
23
|
import { nonEmptyPlan } from "./runtime-config";
|
|
24
24
|
import { tryAcquireNativeMainProfileClaim } from "../native-main-admission";
|
|
25
25
|
import { WHAM_REQUEST_TIMEOUT_MS } from "../quota-recovery-timing";
|
|
26
|
-
import { withNativeMainCredentialClaim,
|
|
26
|
+
import { withNativeMainCredentialClaim, isNativeMainObservationUnavailable } from "./http";
|
|
27
27
|
import { readMainAuthErrorCode, currentQuotaDispatchSequence, nextQuotaDispatchSequence, isQuotaDispatchCurrent, publishQuotaDispatch } from "./pool-quota-probe";
|
|
28
28
|
|
|
29
29
|
/**
|
|
@@ -198,7 +198,7 @@ export async function fetchMainAccountInfoAttempt(
|
|
|
198
198
|
try {
|
|
199
199
|
return await withNativeMainCredentialClaim(operation);
|
|
200
200
|
} catch (error) {
|
|
201
|
-
if (
|
|
201
|
+
if (isNativeMainObservationUnavailable(error)) {
|
|
202
202
|
return {
|
|
203
203
|
info: EMPTY_MAIN_ACCOUNT_INFO,
|
|
204
204
|
credentialChecked: false,
|
|
@@ -2,7 +2,7 @@ import { codexAccountUsesCreditsAfterLimit, codexUsageLimitResetAt } from "../ac
|
|
|
2
2
|
import { nextCodexUsageQueryAt, nextQuotaQueryDelay, pruneRemovedCodexPoolUsageAccounts } from "../quota-query-backoff";
|
|
3
3
|
import { CODEX_PRIORITY_FAILBACK_REFRESH_MS } from "../account-priority";
|
|
4
4
|
import { codexQuotaHasFreshUsage } from "../quota-observation-freshness";
|
|
5
|
-
import { getCodexAccountCredential, getValidCodexToken, readCodexAccountRecord } from "../account-store";
|
|
5
|
+
import { getCodexAccountCredential, getValidCodexToken, isCodexAccountGenerationLive, readCodexAccountRecord } from "../account-store";
|
|
6
6
|
import { getAccountQuota, getMainPolicyQuota, isCompleteCodexQuotaRecoverySnapshot } from "../quota";
|
|
7
7
|
import { isCodexAccountPaused } from "../account-pause";
|
|
8
8
|
import { hasSpendableCodexCredits } from "../quota-types";
|
|
@@ -80,6 +80,13 @@ const MAIN_CREDIT_RENEWAL_AGE_MS = 3 * 60_000;
|
|
|
80
80
|
|
|
81
81
|
/** Traffic headers renew usage, never the independent credit observation (#7377). */
|
|
82
82
|
function poolCreditRenewalDue(config: OcxConfig, accountId: string, now = Date.now()): boolean {
|
|
83
|
+
const openai = config.providers[OPENAI_CODEX_PROVIDER_ID];
|
|
84
|
+
if (!openai || openai.disabled === true || !isCanonicalOpenAiForwardProvider(openai)) return false;
|
|
85
|
+
const mode = providerCodexAccountMode(OPENAI_CODEX_PROVIDER_ID, openai);
|
|
86
|
+
// Direct may renew only explicitly bound stored accounts. Check queued work too:
|
|
87
|
+
// credit opt-in alone does not authorize reads for every saved login.
|
|
88
|
+
if (mode !== "pool" && (mode !== "direct"
|
|
89
|
+
|| !Object.values(config.codexAccountNamespaces ?? {}).includes(accountId))) return false;
|
|
83
90
|
const account = configuredPoolAccount(config, accountId);
|
|
84
91
|
if (!account || !codexAccountUsesCreditsAfterLimit(config, accountId)
|
|
85
92
|
|| isCodexAccountPaused(config, accountId) || isAccountNeedsReauth(accountId)) return false;
|
|
@@ -313,7 +320,9 @@ export async function primeCodexPoolQuotas(
|
|
|
313
320
|
!openai
|
|
314
321
|
|| openai.disabled === true
|
|
315
322
|
|| !isCanonicalOpenAiForwardProvider(openai)
|
|
316
|
-
|| providerCodexAccountMode(OPENAI_CODEX_PROVIDER_ID, openai) !== "pool"
|
|
323
|
+
|| (providerCodexAccountMode(OPENAI_CODEX_PROVIDER_ID, openai) !== "pool"
|
|
324
|
+
&& !(reason === "credit-renewal"
|
|
325
|
+
&& providerCodexAccountMode(OPENAI_CODEX_PROVIDER_ID, openai) === "direct"))
|
|
317
326
|
) return;
|
|
318
327
|
if (primeInFlight) return primeInFlight;
|
|
319
328
|
// Count attempted passes, including failed reads; incoming traffic must not flood WHAM.
|
|
@@ -384,7 +393,11 @@ export async function primeCodexPoolQuotas(
|
|
|
384
393
|
const quota = getAccountQuota(a.id);
|
|
385
394
|
const bypassCachedQuota = reason === "credit-renewal" || (reason === "priority-failback" && quota !== null
|
|
386
395
|
&& !codexQuotaHasFreshUsage(quota, a.plan, Date.now(), CODEX_PRIORITY_FAILBACK_REFRESH_MS));
|
|
387
|
-
result = await fetchPoolAccountQuota(a.id, bypassCachedQuota, a.plan, getValidPoolTokenForPrime
|
|
396
|
+
result = await fetchPoolAccountQuota(a.id, bypassCachedQuota, a.plan, getValidPoolTokenForPrime,
|
|
397
|
+
false, undefined, undefined, false, reason === "credit-renewal"
|
|
398
|
+
? generation => isCodexAccountGenerationLive(a.id, generation)
|
|
399
|
+
&& poolCreditRenewalDue(getRuntimeConfig(config), a.id)
|
|
400
|
+
: undefined);
|
|
388
401
|
} catch (error) {
|
|
389
402
|
// Local quota-flight saturation proves no WHAM request existed for this account.
|
|
390
403
|
// Consume it per item so sibling workers remain inside the shared prime lifetime.
|
|
@@ -88,6 +88,8 @@ export function publishQuotaDispatch(sequence: number): void {
|
|
|
88
88
|
|
|
89
89
|
export interface PoolQuotaProbeEvidence {
|
|
90
90
|
onDispatch?: (sequence: number) => void;
|
|
91
|
+
/** Optional caller authority rechecked after token preparation, including 401 replay. */
|
|
92
|
+
mayDispatch?: (credentialGeneration: number) => boolean;
|
|
91
93
|
mayPublish?: () => boolean;
|
|
92
94
|
attempted?: NonNullable<PoolQuotaResult["quotaProbeAttempted"]>;
|
|
93
95
|
}
|
|
@@ -109,6 +111,7 @@ export function withQuotaProbeEvidence(
|
|
|
109
111
|
|
|
110
112
|
export interface PoolQuotaRefreshFlight {
|
|
111
113
|
state: {
|
|
114
|
+
dispatchGuarded?: boolean;
|
|
112
115
|
dispatchSequence?: number;
|
|
113
116
|
superseded?: boolean;
|
|
114
117
|
startCredentialGeneration?: number;
|
|
@@ -255,6 +258,10 @@ export async function recoverPoolQuotaFrom401(ctx: {
|
|
|
255
258
|
// generation and opens a redundant flight.
|
|
256
259
|
ctx.onCredentialGeneration?.(refreshed.generation);
|
|
257
260
|
|
|
261
|
+
if (ctx.quotaProbeEvidence.mayDispatch?.(refreshed.generation) === false) {
|
|
262
|
+
return { quota: getAccountQuota(accountId), needsReauth: false, credentialGeneration: refreshed.generation, quotaProbeSkipped: true };
|
|
263
|
+
}
|
|
264
|
+
|
|
258
265
|
const writerGeneration = captureConfigGeneration();
|
|
259
266
|
const poolWriter = capturePoolQuotaWriter(accountId, refreshed);
|
|
260
267
|
const replayRead = await fetchCodexUsage<PoolQuotaResult>(`pool:${accountId}:${writerGeneration}:${refreshed.generation}`, {
|
|
@@ -403,6 +410,9 @@ export async function fetchFreshPoolAccountQuota(
|
|
|
403
410
|
const poolWriter = capturePoolQuotaWriter(accountId, { accessToken, chatgptAccountId, generation });
|
|
404
411
|
requestCredentialGeneration = generation;
|
|
405
412
|
onCredentialGeneration?.(generation);
|
|
413
|
+
if (quotaProbeEvidence.mayDispatch?.(generation) === false) {
|
|
414
|
+
return { quota: getAccountQuota(accountId), needsReauth: false, credentialGeneration: generation, quotaProbeSkipped: true };
|
|
415
|
+
}
|
|
406
416
|
const admission = await fetchCodexUsage<PoolQuotaResult>(
|
|
407
417
|
`pool:${accountId}:${writerGeneration}:${generation}${afterDispatchSequence === undefined ? "" : `:post-reset:${afterDispatchSequence}`}`, {
|
|
408
418
|
headers: { Authorization: `Bearer ${accessToken}`, "ChatGPT-Account-Id": chatgptAccountId },
|
|
@@ -496,6 +506,7 @@ export async function fetchPoolAccountQuota(
|
|
|
496
506
|
afterDispatchSequence?: number,
|
|
497
507
|
recoveryProbeNow?: number,
|
|
498
508
|
explicitRefresh = false,
|
|
509
|
+
mayDispatch?: PoolQuotaProbeEvidence["mayDispatch"],
|
|
499
510
|
): Promise<PoolQuotaResult> {
|
|
500
511
|
const existing = getAccountQuota(accountId);
|
|
501
512
|
if (afterDispatchSequence === undefined && !forceRefresh && existing && Date.now() - existing.updatedAt < POOL_CACHE_TTL) {
|
|
@@ -527,6 +538,8 @@ export async function fetchPoolAccountQuota(
|
|
|
527
538
|
const generation = flight.state.resolvedCredentialGeneration
|
|
528
539
|
?? flight.state.startCredentialGeneration;
|
|
529
540
|
return !flight.state.superseded
|
|
541
|
+
// An ordinary read must not inherit a renewal owner's revocable authority.
|
|
542
|
+
&& (mayDispatch !== undefined || !flight.state.dispatchGuarded)
|
|
530
543
|
&& (afterDispatchSequence === undefined || (flight.state.dispatchSequence ?? 0) > afterDispatchSequence)
|
|
531
544
|
&& generation !== undefined && isCodexAccountGenerationLive(accountId, generation);
|
|
532
545
|
});
|
|
@@ -543,6 +556,7 @@ export async function fetchPoolAccountQuota(
|
|
|
543
556
|
for (const flight of flights ?? []) flight.state.superseded = true;
|
|
544
557
|
}
|
|
545
558
|
const state: PoolQuotaRefreshFlight["state"] = {
|
|
559
|
+
dispatchGuarded: mayDispatch !== undefined,
|
|
546
560
|
startCredentialGeneration: record?.generation,
|
|
547
561
|
validatePending,
|
|
548
562
|
};
|
|
@@ -554,6 +568,7 @@ export async function fetchPoolAccountQuota(
|
|
|
554
568
|
getValidToken,
|
|
555
569
|
{
|
|
556
570
|
onDispatch: sequence => { state.dispatchSequence = sequence; },
|
|
571
|
+
mayDispatch,
|
|
557
572
|
mayPublish: () => state.superseded !== true,
|
|
558
573
|
},
|
|
559
574
|
afterDispatchSequence,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { bindPoolCreditPolicy, poolCreditHoldResetAt, poolContextCreditHoldResetAt } from "./pool-credit-policy";
|
|
1
|
+
import { bindPoolCreditPolicy, poolCreditHoldResetAt, poolContextCreditHoldResetAt, poolCreditRecoveryNeeded, poolContextCreditRecoveryNeeded, poolCreditRecoveryRetryAt } from "./pool-credit-policy";
|
|
2
2
|
import { hasSpendableCodexCredits } from "./quota-types";
|
|
3
3
|
import { nextQuotaQueryDelay } from "./quota-query-backoff";
|
|
4
4
|
import { noteMainAccountActivity } from "./main-account-external-usage";
|
|
@@ -548,17 +548,20 @@ export class CodexMainAccountHardLockError extends CodexAccountCooldownError {
|
|
|
548
548
|
export class CodexPoolAccountCreditsOffError extends CodexAccountCooldownError {
|
|
549
549
|
readonly resetAt: number;
|
|
550
550
|
|
|
551
|
-
constructor(accountId: string, resetAt: number) {
|
|
552
|
-
|
|
551
|
+
constructor(accountId: string, resetAt: number, creditRecovery = false, quotaScope?: CodexQuotaScope) {
|
|
552
|
+
// Keep the included reset; a metadata hint neither admits nor clears an upstream hold.
|
|
553
|
+
super(accountId, creditRecovery ? poolCreditRecoveryRetryAt(accountId, resetAt, quotaScope) : resetAt);
|
|
553
554
|
this.name = "CodexPoolAccountCreditsOffError";
|
|
554
555
|
this.resetAt = resetAt;
|
|
555
|
-
this.message =
|
|
556
|
+
this.message = creditRecovery
|
|
557
|
+
? "The selected Codex account reached its usage limit and needs a fresh credit observation. Retry later; spending remains blocked until fresh spendable credits are observed."
|
|
558
|
+
: "The selected Codex account reached its usage limit, and spending credits is off or no fresh spendable balance is available."
|
|
556
559
|
+ " Wait for the limit to reset, choose another account, or explicitly allow credits for this account in Codex Auth.";
|
|
557
560
|
}
|
|
558
561
|
}
|
|
559
562
|
|
|
560
|
-
function assertPoolAccountCredits(accountId: string, resetAt: number | undefined): void {
|
|
561
|
-
if (resetAt !== undefined) throw new CodexPoolAccountCreditsOffError(accountId, resetAt);
|
|
563
|
+
function assertPoolAccountCredits(accountId: string, resetAt: number | undefined, creditRecovery: boolean, quotaScope?: CodexQuotaScope): void {
|
|
564
|
+
if (resetAt !== undefined) throw new CodexPoolAccountCreditsOffError(accountId, resetAt, creditRecovery, quotaScope);
|
|
562
565
|
}
|
|
563
566
|
|
|
564
567
|
/** The main login may not spend credits and one of its usage windows is full (#6334). */
|
|
@@ -780,7 +783,7 @@ export function createCodexAuthDispatchGuard(
|
|
|
780
783
|
return headers => {
|
|
781
784
|
if (config.pausedCodexAccountIds?.includes(ctx.accountId)) throw new CodexPoolAuthenticationError("Selected Codex account is paused; resume it in account settings");
|
|
782
785
|
if (ctx.kind === "main-pool") { reserveGuard?.(headers); return; }
|
|
783
|
-
assertPoolAccountCredits(ctx.accountId, poolContextCreditHoldResetAt(ctx, config));
|
|
786
|
+
assertPoolAccountCredits(ctx.accountId, poolContextCreditHoldResetAt(ctx, config), poolContextCreditRecoveryNeeded(ctx, config), ctx.quotaScope);
|
|
784
787
|
reserveGuard?.(headers);
|
|
785
788
|
};
|
|
786
789
|
}
|
|
@@ -1569,7 +1572,7 @@ async function resolveCodexAuthContextUnannotated(
|
|
|
1569
1572
|
try {
|
|
1570
1573
|
assertCodexAccountValidationReady(accountId);
|
|
1571
1574
|
if (configuredCodexMainDuplicate(config, accountId)) throw new CodexPoolAuthenticationError(CODEX_MAIN_DUPLICATE_ACTION);
|
|
1572
|
-
assertPoolAccountCredits(accountId, poolCreditHoldResetAt(policy, accountId, config));
|
|
1575
|
+
assertPoolAccountCredits(accountId, poolCreditHoldResetAt(policy, accountId, config), poolCreditRecoveryNeeded(policy, accountId), quotaScope);
|
|
1573
1576
|
} catch (cause) {
|
|
1574
1577
|
// Nothing will reach upstream, so give the trial back instead of leaving the held account
|
|
1575
1578
|
// unprobeable until the lease deadline lapses (#4701).
|
|
@@ -1700,7 +1703,7 @@ async function resolveCodexAuthContextUnannotated(
|
|
|
1700
1703
|
const token = await getValidCodexToken(accountId, { signal: options.signal });
|
|
1701
1704
|
assertCodexAccountValidationReady(accountId);
|
|
1702
1705
|
if (configuredCodexMainDuplicate(config, accountId)) throw new CodexPoolAuthenticationError(CODEX_MAIN_DUPLICATE_ACTION);
|
|
1703
|
-
assertPoolAccountCredits(accountId, poolCreditHoldResetAt(policy, accountId, config));
|
|
1706
|
+
assertPoolAccountCredits(accountId, poolCreditHoldResetAt(policy, accountId, config), poolCreditRecoveryNeeded(policy, accountId), quotaScope);
|
|
1704
1707
|
return bindPoolCreditPolicy({
|
|
1705
1708
|
kind: "pool",
|
|
1706
1709
|
accountId,
|
|
@@ -1732,7 +1735,7 @@ async function resolveCodexAuthContextUnannotated(
|
|
|
1732
1735
|
|
|
1733
1736
|
export function assertCodexAuthContextNotCooled(ctx: CodexAuthContext | undefined): void {
|
|
1734
1737
|
if (ctx?.kind !== "pool" && ctx?.kind !== "main-pool") return;
|
|
1735
|
-
if (ctx.kind === "pool") assertPoolAccountCredits(ctx.accountId, poolContextCreditHoldResetAt(ctx));
|
|
1738
|
+
if (ctx.kind === "pool") assertPoolAccountCredits(ctx.accountId, poolContextCreditHoldResetAt(ctx), poolContextCreditRecoveryNeeded(ctx), ctx.quotaScope);
|
|
1736
1739
|
// A context holding the probe lease was deliberately admitted through the cooldown.
|
|
1737
1740
|
if (ctx.probeLeaseId) return;
|
|
1738
1741
|
const cooldown = getCodexQuotaHealthSnapshot(ctx.accountId, ctx.quotaScope);
|
|
@@ -1748,7 +1751,7 @@ export function applyCodexAuthContextToProvider(
|
|
|
1748
1751
|
): OcxRuntimeProviderConfig {
|
|
1749
1752
|
if (mode !== "pool" || (ctx.kind !== "pool" && ctx.kind !== "main-pool") || provider.authMode !== "forward") return provider;
|
|
1750
1753
|
assertCodexAccountValidationReady(ctx.accountId);
|
|
1751
|
-
if (ctx.kind === "pool") assertPoolAccountCredits(ctx.accountId, poolContextCreditHoldResetAt(ctx));
|
|
1754
|
+
if (ctx.kind === "pool") assertPoolAccountCredits(ctx.accountId, poolContextCreditHoldResetAt(ctx), poolContextCreditRecoveryNeeded(ctx), ctx.quotaScope);
|
|
1752
1755
|
return {
|
|
1753
1756
|
...provider,
|
|
1754
1757
|
_codexAccountOverride: {
|
|
@@ -1803,7 +1806,7 @@ export function materializeCodexUpstreamAuth(
|
|
|
1803
1806
|
}
|
|
1804
1807
|
if (ctx.kind === "pool" || ctx.kind === "main-pool") {
|
|
1805
1808
|
assertCodexAccountValidationReady(ctx.accountId);
|
|
1806
|
-
if (ctx.kind === "pool") assertPoolAccountCredits(ctx.accountId, poolContextCreditHoldResetAt(ctx, options.config));
|
|
1809
|
+
if (ctx.kind === "pool") assertPoolAccountCredits(ctx.accountId, poolContextCreditHoldResetAt(ctx, options.config), poolContextCreditRecoveryNeeded(ctx, options.config), ctx.quotaScope);
|
|
1807
1810
|
selected.set("authorization", `Bearer ${ctx.accessToken}`);
|
|
1808
1811
|
selected.set("chatgpt-account-id", ctx.chatgptAccountId);
|
|
1809
1812
|
if (ctx.kind === "main-pool") {
|
|
@@ -485,6 +485,8 @@ export interface ObservedCatalogMergeInput {
|
|
|
485
485
|
readonly ultraFastTier?: boolean;
|
|
486
486
|
/** Current captured wire declarations; disk rows and templates never populate this set. */
|
|
487
487
|
readonly configuredUltraFastSlugs?: ReadonlySet<string>;
|
|
488
|
+
/** Current config-only verdict for persisted rows (not authority from the old disk tier). */
|
|
489
|
+
readonly retainedFlexPolicyBySlug?: ReadonlyMap<string, boolean>;
|
|
488
490
|
readonly catalogModels: readonly RawEntry[];
|
|
489
491
|
readonly baselineCatalogModels: readonly RawEntry[];
|
|
490
492
|
readonly routedEntries: readonly RawEntry[];
|
|
@@ -532,6 +534,7 @@ export interface ObservedCatalogMergeInput {
|
|
|
532
534
|
export function mergeCatalogEntriesFromObservedState({
|
|
533
535
|
ultraFastTier = false,
|
|
534
536
|
configuredUltraFastSlugs = new Set(),
|
|
537
|
+
retainedFlexPolicyBySlug = new Map(),
|
|
535
538
|
catalogModels,
|
|
536
539
|
baselineCatalogModels,
|
|
537
540
|
routedEntries,
|
|
@@ -889,6 +892,25 @@ export function mergeCatalogEntriesFromObservedState({
|
|
|
889
892
|
|| trustedAccountBoundNativeCatalogSlug(entry) !== undefined) continue;
|
|
890
893
|
applyConfiguredUltraFast(entry, operatorRows.get(entry.slug), configuredUltraFastSlugs.has(entry.slug), ultraFastTier);
|
|
891
894
|
}
|
|
895
|
+
// Degraded discovery preserves disk rows, so they bypass fresh tier generation.
|
|
896
|
+
// Revoke only an explicitly disallowed Flex tier according to today's provider policy;
|
|
897
|
+
// a transient outage must not erase Flex while the configured wire still permits it.
|
|
898
|
+
const persistedRoutedSet = new Set(preservedRoutedEntries);
|
|
899
|
+
for (const entry of finalRoutedEntries) {
|
|
900
|
+
if (!persistedRoutedSet.has(entry)) continue;
|
|
901
|
+
const slug = typeof entry.slug === "string" ? entry.slug : "";
|
|
902
|
+
const excluded = isNativeAliasCatalogEntry(entry) || isExactComboCatalogEntry(entry, exactComboSlugs);
|
|
903
|
+
if (!excluded && retainedFlexPolicyBySlug.get(slug) !== false) continue;
|
|
904
|
+
if (Array.isArray(entry.service_tiers)) {
|
|
905
|
+
entry.service_tiers = entry.service_tiers.filter(tier => tier?.id !== "flex");
|
|
906
|
+
}
|
|
907
|
+
if (Array.isArray(entry.additional_speed_tiers)) {
|
|
908
|
+
entry.additional_speed_tiers = entry.additional_speed_tiers.filter(tier => tier !== "flex");
|
|
909
|
+
}
|
|
910
|
+
for (const field of ["service_tier", "default_service_tier"] as const) {
|
|
911
|
+
if (entry[field] === "flex") delete entry[field];
|
|
912
|
+
}
|
|
913
|
+
}
|
|
892
914
|
const finalRoutedEntrySet = new Set(finalRoutedEntries);
|
|
893
915
|
const degradedPreservedCount = preservedRoutedEntries.filter(entry => {
|
|
894
916
|
if (!finalRoutedEntrySet.has(entry)) return false;
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { COMBO_NAMESPACE } from "../../combos";
|
|
2
|
+
import type { OcxProviderConfig } from "../../types";
|
|
3
|
+
import { decodeRoutedModelId } from "../../providers/slug-codec";
|
|
4
|
+
import { fastPolicyForModel } from "../../providers/service-tier";
|
|
2
5
|
import type { ResolvedFastPolicy } from "../../providers/fastwire";
|
|
3
6
|
import { catalogModelSlug, type CatalogModel, type RawEntry } from "./parsing";
|
|
4
7
|
import { preserveOperatorUltraFastTiers } from "./operator-tiers";
|
|
5
8
|
|
|
6
9
|
const MANAGED_ULTRAFAST = "opencodex_managed_ultrafast";
|
|
7
10
|
|
|
11
|
+
/** Advertise Flex only when the final route can forward the caller's exact flex tier. */
|
|
12
|
+
export function supportsConfiguredFlex(policy: ResolvedFastPolicy | undefined): boolean {
|
|
13
|
+
return policy?.eligibility === "eligible"
|
|
14
|
+
&& policy.fastWire?.kind === "service-tier"
|
|
15
|
+
&& policy.fastWire.canonicalToWire.flex === "flex"
|
|
16
|
+
&& policy.forwardCallerTier;
|
|
17
|
+
}
|
|
18
|
+
|
|
8
19
|
/** Advertise Ultra Fast only when the eligible final wire explicitly maps that exact tier. */
|
|
9
20
|
export function supportsConfiguredUltraFast(policy: ResolvedFastPolicy | undefined): boolean {
|
|
10
21
|
return policy?.eligibility === "eligible"
|
|
@@ -48,3 +59,62 @@ export function applyConfiguredUltraFast(
|
|
|
48
59
|
// Advertising a selectable capability does not opt the user into its increased usage.
|
|
49
60
|
entry[MANAGED_ULTRAFAST] = entry.slug;
|
|
50
61
|
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Re-evaluate persisted routed Flex choices using current provider configuration. Degraded
|
|
65
|
+
* discovery keeps disk rows but cannot let a withdrawn wire declaration keep old picker tiers.
|
|
66
|
+
* Only rows tied to a configured provider are judged; unmanaged foreign rows are untouched.
|
|
67
|
+
*/
|
|
68
|
+
export function retainedFlexPolicyBySlug(
|
|
69
|
+
providers: Readonly<Record<string, OcxProviderConfig>>,
|
|
70
|
+
rows: readonly RawEntry[],
|
|
71
|
+
observedModels: readonly CatalogModel[],
|
|
72
|
+
): ReadonlyMap<string, boolean> {
|
|
73
|
+
const result = new Map<string, boolean>();
|
|
74
|
+
const currentModels = new Map<string, CatalogModel[]>();
|
|
75
|
+
for (const model of observedModels) {
|
|
76
|
+
const slug = catalogModelSlug(model);
|
|
77
|
+
const candidates = currentModels.get(slug) ?? [];
|
|
78
|
+
candidates.push(model);
|
|
79
|
+
currentModels.set(slug, candidates);
|
|
80
|
+
}
|
|
81
|
+
for (const row of rows) {
|
|
82
|
+
const slug = typeof row.slug === "string" ? row.slug : "";
|
|
83
|
+
const slash = slug.indexOf("/");
|
|
84
|
+
if (slash <= 0) continue;
|
|
85
|
+
const namespace = slug.slice(0, slash);
|
|
86
|
+
const owner = Object.entries(providers).find(([name, provider]) =>
|
|
87
|
+
name === namespace || provider.alias === namespace);
|
|
88
|
+
if (!owner) continue;
|
|
89
|
+
const [name, provider] = owner;
|
|
90
|
+
if (provider.disabled === true || namespace === COMBO_NAMESPACE || name === COMBO_NAMESPACE) {
|
|
91
|
+
result.set(slug, false);
|
|
92
|
+
continue;
|
|
93
|
+
}
|
|
94
|
+
const observed = currentModels.get(slug);
|
|
95
|
+
if (observed?.length) {
|
|
96
|
+
// The current gather re-applies captured policy hints; conflicting rows fail closed.
|
|
97
|
+
result.set(slug, observed.every(model =>
|
|
98
|
+
model.provider !== COMBO_NAMESPACE && model.nativeAlias !== true
|
|
99
|
+
&& model.supportsServiceTier === true && model.supportsFlexTier === true));
|
|
100
|
+
continue;
|
|
101
|
+
}
|
|
102
|
+
const requested = slug.slice(slash + 1);
|
|
103
|
+
const aliased = Object.entries(provider.modelAliases ?? {})
|
|
104
|
+
.filter(([, alias]) => alias === requested).map(([id]) => id);
|
|
105
|
+
// A non-unique short alias is not authority for a capability declaration.
|
|
106
|
+
if (aliased.length > 1) {
|
|
107
|
+
result.set(slug, false);
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const knownIds = [
|
|
111
|
+
...(provider.models ?? []),
|
|
112
|
+
...Object.keys(provider.modelSupportsServiceTier ?? {}),
|
|
113
|
+
...Object.keys(provider.modelAliases ?? {}),
|
|
114
|
+
...Object.keys(provider.modelAdapters ?? {}),
|
|
115
|
+
];
|
|
116
|
+
const modelId = aliased[0] ?? decodeRoutedModelId(requested, knownIds);
|
|
117
|
+
result.set(slug, supportsConfiguredFlex(fastPolicyForModel(provider, modelId, name)));
|
|
118
|
+
}
|
|
119
|
+
return result;
|
|
120
|
+
}
|