@bitkyc08/opencodex 2.92.0 → 2.93.0
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 +10 -5
- package/gui/dist/assets/{App-sUf_8afJ.js → App-CizjBqyk.js} +18 -18
- package/gui/dist/assets/{Tray-BSsxznDm.js → Tray-DamiMqcX.js} +1 -1
- package/gui/dist/assets/{index-BlFE_VB_.js → index-DQsht3vH.js} +12 -12
- package/gui/dist/assets/index-DRe8Hhfz.css +1 -0
- package/gui/dist/assets/{quota-summary-BRlbXgw0.js → quota-summary-BXu4zE8H.js} +1 -1
- package/gui/dist/index.html +2 -2
- package/package.json +5 -5
- 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-wire-compiler.ts +1 -2
- 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.ts +7 -8
- 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 +1 -1
- 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/tool-call-id.ts +1 -3
- package/src/bridge/errors.ts +27 -0
- package/src/bridge.ts +1 -1
- package/src/chat/inbound.ts +4 -1
- package/src/chat/outbound.ts +9 -2
- 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 +2 -2
- 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-shim-autorestore.ts +9 -0
- package/src/cli/combo-result.ts +7 -0
- package/src/cli/combo.ts +18 -0
- 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/opencode.ts +20 -9
- 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/client/connect.ts +40 -3
- package/src/client/link-home.ts +10 -1
- package/src/client/machine-api.ts +3 -1
- 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/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 +44 -10
- package/src/codex/catalog/gather-capture.ts +1 -0
- 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 +4 -5
- 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/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-compatibility/installed-build.ts +88 -12
- package/src/codex/desktop-compatibility/runtime.ts +29 -5
- package/src/codex/desktop-compatibility/usage-controller.ts +2 -0
- 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/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/combos/failover.ts +17 -2
- package/src/combos/jev-decision-contract.ts +22 -1
- package/src/combos/jev-service-exchange.ts +3 -1
- package/src/combos/jev.ts +95 -9
- package/src/combos/resolve.ts +45 -1
- package/src/combos/types.ts +24 -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 +15 -4
- package/src/config/removed-opencode-free.ts +11 -0
- package/src/config/schema/leaf-validators.ts +5 -0
- package/src/generated/compatibility-version.json +314 -230
- 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/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/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/ssh-config.ts +35 -3
- package/src/providers/account-quota-disk.ts +12 -4
- package/src/providers/codebuddy-models.ts +6 -0
- package/src/providers/codex-capacity.ts +3 -1
- package/src/providers/derive.ts +28 -0
- package/src/providers/kiro-models.ts +3 -0
- package/src/providers/mimo-thinking.ts +12 -0
- package/src/providers/model-rename-fields.ts +1 -0
- package/src/providers/model-rename-migration.ts +10 -0
- package/src/providers/openai-sidecar-credit.ts +2 -2
- package/src/providers/reasoning-capabilities.ts +76 -0
- package/src/providers/registry/entries-core.ts +14 -12
- package/src/providers/registry/entries-extended.ts +63 -20
- package/src/providers/registry/model-ids.ts +2 -0
- package/src/providers/registry/model-seeds.ts +93 -28
- package/src/providers/registry/types.ts +10 -1
- package/src/providers/resolved-model-policy.ts +26 -6
- package/src/providers/routed-config.ts +9 -1
- package/src/providers/stale-model-roster-migration.ts +44 -7
- 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/schema.ts +1 -0
- package/src/responses/thought-signature-replay.ts +10 -2
- package/src/routing/capability.ts +8 -2
- package/src/routing/history/ingest.ts +28 -3
- package/src/server/auth-cors.ts +3 -2
- package/src/server/chat-completions.ts +7 -0
- package/src/server/chat-native-eligibility.ts +7 -0
- package/src/server/chat-native-reasoning.ts +14 -4
- package/src/server/direct-local-http.ts +5 -2
- package/src/server/effort-policy.ts +5 -1
- package/src/server/index/live-sideband.ts +18 -15
- package/src/server/index/serve-options.ts +5 -4
- package/src/server/management/agent-settings-routes.ts +27 -15
- package/src/server/management/combo-routes.ts +4 -0
- 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/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/route-registry.ts +4 -0
- package/src/server/management-api.ts +5 -0
- package/src/server/models-capabilities.ts +21 -3
- package/src/server/responses/adapter-delivery.ts +11 -1
- package/src/server/responses/adapter-dispatch.ts +2 -2
- 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 +4 -3
- 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 +23 -15
- package/src/server/responses/core-lifetime.ts +3 -0
- package/src/server/responses/core-normalize.ts +11 -1
- package/src/server/responses/core-options.ts +2 -0
- package/src/server/responses/main-hard-lock-routing.ts +60 -44
- package/src/server/responses/passthrough-delivery.ts +40 -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 +22 -2
- package/src/server/responses/request-sidecar-auth.ts +2 -0
- package/src/server/responses/response-effects.ts +22 -10
- package/src/server/responses/sidecar-execution.ts +11 -3
- package/src/server/stop-teardown.ts +36 -1
- package/src/server/ws-bridge.ts +1 -1
- 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 +8 -2
- package/src/types/provider.ts +20 -6
- package/src/types/request.ts +10 -0
- package/src/types.ts +1 -0
- package/src/update/bind-probe.ts +29 -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/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/index-DPeB9HpV.css +0 -1
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
* and config already in hand.
|
|
17
17
|
*/
|
|
18
18
|
import { enrichProviderFromRegistry } from "../../providers/derive";
|
|
19
|
+
import { reasoningCapabilitiesFromConfig } from "../../providers/reasoning-capabilities";
|
|
19
20
|
import { modelRecordValue } from "../../reasoning-effort";
|
|
20
21
|
import { configuredReasoningSummarySupport } from "../../codex/catalog/model-hints";
|
|
21
22
|
import type { CatalogModel } from "../../codex/catalog";
|
|
@@ -87,24 +88,42 @@ export function customRowExportMetadata(
|
|
|
87
88
|
// same reader the materializer uses answers from the provider config, so both paths agree.
|
|
88
89
|
const supportsReasoningSummaries = catalogRow?.supportsReasoningSummaries
|
|
89
90
|
?? configuredReasoningSummarySupport(provider, source.id);
|
|
91
|
+
// The effective ladder below already includes custom overrides; do not derive new axes
|
|
92
|
+
// from a provider-wide legacy ladder that a custom row may explicitly have cleared.
|
|
93
|
+
const configured = enriched === undefined ? undefined : reasoningCapabilitiesFromConfig({
|
|
94
|
+
...enriched, modelReasoningEfforts: undefined, reasoningEfforts: undefined,
|
|
95
|
+
}, source.id);
|
|
96
|
+
const supportsThinkingToggle = configured?.supportsThinkingToggle === false ? false
|
|
97
|
+
: catalogRow?.supportsThinkingToggle ?? configured?.supportsThinkingToggle;
|
|
98
|
+
const supportsReasoningEffort = configured?.supportsReasoningEffort === false ? false
|
|
99
|
+
: catalogRow?.supportsReasoningEffort ?? configured?.supportsReasoningEffort;
|
|
100
|
+
const defaultThinkingEnabled = configured?.defaultThinkingEnabled === false ? false
|
|
101
|
+
: catalogRow?.defaultThinkingEnabled ?? configured?.defaultThinkingEnabled;
|
|
102
|
+
const supportsReasoning = configured?.supportsReasoning === false ? false : catalogRow?.supportsReasoning
|
|
103
|
+
?? configured?.supportsReasoning
|
|
104
|
+
?? knownReasoningSupport({ reasoningEfforts: effectiveReasoningEfforts, supportsReasoningSummaries,
|
|
105
|
+
supportsThinkingToggle, supportsReasoningEffort });
|
|
106
|
+
const reasoningEfforts = supportsReasoningEffort === false || supportsReasoning === false
|
|
107
|
+
? (effectiveReasoningEfforts === undefined ? undefined : []) : effectiveReasoningEfforts;
|
|
90
108
|
const defaultReasoningEffort = declaredDefaultWithin(
|
|
91
|
-
|
|
92
|
-
defaultEffort(source, catalogRow, provider),
|
|
109
|
+
reasoningEfforts,
|
|
110
|
+
supportsReasoningEffort === false || supportsReasoning === false ? undefined : defaultEffort(source, catalogRow, provider),
|
|
93
111
|
);
|
|
94
112
|
return {
|
|
95
113
|
...(contextWindow !== undefined ? { contextWindow } : {}),
|
|
96
114
|
...(catalogRow?.maxInputTokens !== undefined ? { maxInputTokens: catalogRow.maxInputTokens } : {}),
|
|
97
115
|
...(catalogRow?.maxOutputTokens !== undefined ? { maxTokens: catalogRow.maxOutputTokens } : {}),
|
|
98
116
|
...(inputModalities !== undefined ? { inputModalities: [...inputModalities] } : {}),
|
|
99
|
-
...(
|
|
117
|
+
...(reasoningEfforts !== undefined ? { reasoningEfforts: [...reasoningEfforts] } : {}),
|
|
118
|
+
...(supportsThinkingToggle !== undefined ? { supportsThinkingToggle } : {}),
|
|
119
|
+
...(supportsReasoningEffort !== undefined ? { supportsReasoningEffort } : {}),
|
|
120
|
+
...(defaultThinkingEnabled !== undefined ? { defaultThinkingEnabled } : {}),
|
|
100
121
|
...(defaultReasoningEffort !== undefined ? { defaultReasoningEffort } : {}),
|
|
101
122
|
...(knownToolsSupport({
|
|
102
123
|
capabilities: catalogRow?.capabilities,
|
|
103
124
|
parallelToolCalls: catalogRow?.parallelToolCalls,
|
|
104
125
|
}) === true ? { supportsTools: true } : {}),
|
|
105
|
-
...(
|
|
106
|
-
? { supportsReasoning: true }
|
|
107
|
-
: {}),
|
|
126
|
+
...(typeof supportsReasoning === "boolean" ? { supportsReasoning } : {}),
|
|
108
127
|
...(supportsReasoningSummaries !== undefined ? { supportsReasoningSummaries } : {}),
|
|
109
128
|
};
|
|
110
129
|
}
|
|
@@ -39,6 +39,7 @@ import {
|
|
|
39
39
|
type ExportModel,
|
|
40
40
|
} from "../../clients/config-export/contracts";
|
|
41
41
|
import { customRowExportMetadata } from "./model-row-export-metadata";
|
|
42
|
+
import { resolveExportReasoningAxes } from "../../clients/config-export/reasoning-metadata";
|
|
42
43
|
import { providerContextCap } from "../../providers/context-cap";
|
|
43
44
|
import { isVisionReasoningEffort, modelRecordValue, sanitizeCodexReasoningEfforts } from "../../reasoning-effort";
|
|
44
45
|
import { routedSlug, slugEquals } from "../../providers/slug-codec";
|
|
@@ -104,9 +105,9 @@ export type ManagementModelRow = Partial<CatalogModel> & {
|
|
|
104
105
|
*/
|
|
105
106
|
supportsTools?: boolean;
|
|
106
107
|
/**
|
|
107
|
-
*
|
|
108
|
-
* or delivered
|
|
109
|
-
*
|
|
108
|
+
* A canonical source's explicit capability, or positive evidence from reasoning efforts
|
|
109
|
+
* or delivered summaries. Absent means unknown; an empty ladder alone says only that
|
|
110
|
+
* effort is not adjustable, not that the model cannot reason.
|
|
110
111
|
*/
|
|
111
112
|
supportsReasoning?: boolean;
|
|
112
113
|
/**
|
|
@@ -460,9 +461,11 @@ export async function listManagementModelRows(
|
|
|
460
461
|
const routed = m.provider !== "combo";
|
|
461
462
|
// Resolved once each: the spread below used to evaluate the same helpers again for the guard.
|
|
462
463
|
const reasoningEfforts = routed
|
|
463
|
-
?
|
|
464
|
+
? m.supportsReasoningEffort === false || m.supportsReasoning === false ? []
|
|
465
|
+
: effectiveModelReasoningEfforts(config, m.provider, m.id, m.reasoningEfforts, catalogLadders)
|
|
464
466
|
: undefined;
|
|
465
467
|
const defaultReasoningEffort = routed
|
|
468
|
+
&& m.supportsReasoningEffort !== false && m.supportsReasoning !== false
|
|
466
469
|
? effectiveModelDefaultReasoningEffort(config, m.provider, m.id, m.defaultReasoningEffort, reasoningEfforts)
|
|
467
470
|
: undefined;
|
|
468
471
|
const inputModalitiesDeclared = routed ? declaredModelInputModalities(config, m.provider, m.id) : undefined;
|
|
@@ -524,10 +527,7 @@ export async function listManagementModelRows(
|
|
|
524
527
|
});
|
|
525
528
|
const supportsReasoning = row.exportMetadata?.supportsReasoning
|
|
526
529
|
?? row.supportsReasoning
|
|
527
|
-
?? knownReasoningSupport(
|
|
528
|
-
reasoningEfforts: row.reasoningEfforts,
|
|
529
|
-
supportsReasoningSummaries: row.supportsReasoningSummaries,
|
|
530
|
-
});
|
|
530
|
+
?? knownReasoningSupport(row);
|
|
531
531
|
return {
|
|
532
532
|
...row,
|
|
533
533
|
// One shared definition with the request path: the GUI must not re-derive consumer
|
|
@@ -560,14 +560,8 @@ export function toExportModel(row: ManagementModelRow): ExportModel {
|
|
|
560
560
|
const maxTokens = effective?.maxTokens ?? row.maxOutputTokens;
|
|
561
561
|
const maxInputTokens = effective?.maxInputTokens ?? row.maxInputTokens;
|
|
562
562
|
const inputModalities = effective?.inputModalities ?? row.inputModalities;
|
|
563
|
-
const
|
|
564
|
-
|
|
565
|
-
// NO declared default — falling back to the row would reintroduce the picker's synthetic
|
|
566
|
-
// medium/low value, which is exactly what this projection exists to keep out of exports.
|
|
567
|
-
// Rows without a projection (native-era shapes, hand-built rows) keep the row's own value.
|
|
568
|
-
const defaultReasoningEffort = effective !== undefined
|
|
569
|
-
? effective.defaultReasoningEffort
|
|
570
|
-
: row.defaultReasoningEffort;
|
|
563
|
+
const { supportsThinkingToggle, supportsReasoningEffort, defaultThinkingEnabled,
|
|
564
|
+
reasoningEfforts, defaultReasoningEffort } = resolveExportReasoningAxes(effective, row);
|
|
571
565
|
const supportsReasoningSummaries = effective?.supportsReasoningSummaries ?? row.supportsReasoningSummaries;
|
|
572
566
|
// Projection first, then the row's own explicit boolean (an external producer may state
|
|
573
567
|
// false, which is evidence), and only then derivation from positive evidence.
|
|
@@ -580,10 +574,8 @@ export function toExportModel(row: ManagementModelRow): ExportModel {
|
|
|
580
574
|
});
|
|
581
575
|
const supportsReasoning = effective?.supportsReasoning
|
|
582
576
|
?? row.supportsReasoning
|
|
583
|
-
?? knownReasoningSupport({
|
|
584
|
-
reasoningEfforts
|
|
585
|
-
supportsReasoningSummaries: row.supportsReasoningSummaries,
|
|
586
|
-
});
|
|
577
|
+
?? knownReasoningSupport({ ...row, supportsThinkingToggle, supportsReasoningEffort,
|
|
578
|
+
reasoningEfforts, supportsReasoningSummaries });
|
|
587
579
|
return {
|
|
588
580
|
namespaced: row.namespaced,
|
|
589
581
|
provider: row.provider,
|
|
@@ -597,6 +589,9 @@ export function toExportModel(row: ManagementModelRow): ExportModel {
|
|
|
597
589
|
...(inputModalities ? { inputModalities } : {}),
|
|
598
590
|
// An empty array is a declaration ("no rungs"), and `[]` is truthy: it survives here.
|
|
599
591
|
...(reasoningEfforts ? { reasoningEfforts } : {}),
|
|
592
|
+
...(typeof supportsThinkingToggle === "boolean" ? { supportsThinkingToggle } : {}),
|
|
593
|
+
...(typeof supportsReasoningEffort === "boolean" ? { supportsReasoningEffort } : {}),
|
|
594
|
+
...(typeof defaultThinkingEnabled === "boolean" ? { defaultThinkingEnabled } : {}),
|
|
600
595
|
...(defaultReasoningEffort ? { defaultReasoningEffort } : {}),
|
|
601
596
|
// An explicit false is evidence and survives; only derivation is true-or-nothing.
|
|
602
597
|
...(typeof supportsTools === "boolean" ? { supportsTools } : {}),
|
|
@@ -30,14 +30,15 @@ import { providerContextCap } from "../../providers/context-cap";
|
|
|
30
30
|
import { OPENAI_CODEX_PROVIDER_ID } from "../../providers/openai-tiers";
|
|
31
31
|
import { inspectDesktop3pConfigLibrary, removeDesktop3pStandardPivot, writeDesktop3pConfig } from "../../claude/desktop-3p";
|
|
32
32
|
import {
|
|
33
|
-
applyDesktopFirstParty,
|
|
33
|
+
applyDesktopFirstParty, withFirstPartySecretsSettled,
|
|
34
34
|
captureDesktopFirstPartyRollback,
|
|
35
35
|
inspectDesktopFirstParty,
|
|
36
36
|
observeClaudeDesktopMode,
|
|
37
37
|
recordClaudeDesktopMode,
|
|
38
|
-
removeDesktopFirstParty,
|
|
38
|
+
removeDesktopFirstParty, removeDesktopFirstPartySettled,
|
|
39
39
|
resolveClaudeDesktopApplyMode,
|
|
40
40
|
type ClaudeDesktopMode,
|
|
41
|
+
type InterceptSecretDiagnostic,
|
|
41
42
|
} from "../../claude/desktop-first-party";
|
|
42
43
|
import { FIRST_PARTY_ACCOUNT_RISK } from "../../claude/desktop-risk";
|
|
43
44
|
import type { DesktopPickerStatus } from "../../claude/desktop-picker";
|
|
@@ -49,6 +50,7 @@ import { grokConfigPath } from "../../grok/status";
|
|
|
49
50
|
import { assertNativeTeardownOwned } from "../../integrations/native/ownership-preflight";
|
|
50
51
|
import type { CodexNativeRestoreResult } from "../../codex/inject";
|
|
51
52
|
import type { OcxConfig } from "../../types";
|
|
53
|
+
import { getConfigDir, withConfigDirHardeningSettled } from "../../config/paths";
|
|
52
54
|
import { jsonResponse } from "../auth-cors";
|
|
53
55
|
import { readManagementJsonBody, rethrowManagementBodyTooLarge } from "./body";
|
|
54
56
|
import { managementInferencePort, type ManagementContext } from "./context";
|
|
@@ -108,6 +110,7 @@ export interface NativeRefusalEnvelope {
|
|
|
108
110
|
/** Present on every post-commit refusal; absent only for pre-commit refusals. */
|
|
109
111
|
desiredEnabled?: boolean;
|
|
110
112
|
residualPaths?: string[];
|
|
113
|
+
diagnostic?: InterceptSecretDiagnostic;
|
|
111
114
|
}
|
|
112
115
|
|
|
113
116
|
export type NativePostCommitRefusalEnvelope = Omit<NativeRefusalEnvelope, "desiredEnabled"> & {
|
|
@@ -133,7 +136,7 @@ function postCommitRefusal(
|
|
|
133
136
|
clientId: NativeIntegrationClientId,
|
|
134
137
|
reason: NativeRefusalReason,
|
|
135
138
|
message: string,
|
|
136
|
-
extra: Pick<NativePostCommitRefusalEnvelope, "desiredEnabled" | "residualPaths">,
|
|
139
|
+
extra: Pick<NativePostCommitRefusalEnvelope, "desiredEnabled" | "residualPaths" | "diagnostic">,
|
|
137
140
|
): Response {
|
|
138
141
|
return jsonResponse({
|
|
139
142
|
error: status >= 500 ? "native integration change failed" : "native integration change refused",
|
|
@@ -717,7 +720,7 @@ async function handleClaudeDesktopToggle(ctx: ManagementContext): Promise<Respon
|
|
|
717
720
|
// Picker mode goes first: stop terminating claude.ai, drop its profile and trust.
|
|
718
721
|
return await runPickerTransition(current, async ops => {
|
|
719
722
|
const pickerOff = await ops.disableLocked({ persist: false });
|
|
720
|
-
const firstPartyRemoved =
|
|
723
|
+
const firstPartyRemoved = await removeDesktopFirstPartySettled(loadConfig);
|
|
721
724
|
if (!firstPartyRemoved.ok) {
|
|
722
725
|
return postCommitRefusal(409, "claude-desktop", "write_failed",
|
|
723
726
|
`Claude Code settings could not be read (${firstPartyRemoved.path}); the first-party proxy env was left in place.`, { desiredEnabled });
|
|
@@ -755,17 +758,17 @@ async function handleClaudeDesktopToggle(ctx: ManagementContext): Promise<Respon
|
|
|
755
758
|
// The whole switch runs under the picker lock, in today's order: env first, then gateway cleanup.
|
|
756
759
|
return await runPickerTransition(current, async ops => {
|
|
757
760
|
const rollback = captureDesktopFirstPartyRollback(current);
|
|
758
|
-
const applied = applyDesktopFirstParty(current);
|
|
761
|
+
const applied = await withFirstPartySecretsSettled(getConfigDir(), () => applyDesktopFirstParty(current));
|
|
759
762
|
if (!applied.ok) {
|
|
760
763
|
const reason = applied.reason === "foreign_env" || applied.reason === "intercept_disabled" ? applied.reason : "write_failed";
|
|
761
764
|
return postCommitRefusal(applied.reason === "unreadable" || applied.reason === "ca_unavailable" ? 500 : 409, "claude-desktop", reason,
|
|
762
|
-
firstPartyRefusalMessage(applied.reason, applied.path), { desiredEnabled });
|
|
765
|
+
firstPartyRefusalMessage(applied.reason, applied.path), { desiredEnabled, ...(applied.diagnostic ? { diagnostic: applied.diagnostic } : {}) });
|
|
763
766
|
}
|
|
764
767
|
const library = inspectDesktop3pConfigLibrary({ appliedFingerprint: fingerprint });
|
|
765
768
|
let gatewayRemoved = false;
|
|
766
769
|
if (library.kind === "gateway_ours" || library.kind === "gateway_drifted") {
|
|
767
770
|
const removed = (ctx.deps.removeDesktop3pStandardPivot ?? removeDesktop3pStandardPivot)({ appliedFingerprint: fingerprint, replaceWhileEnabled: true });
|
|
768
|
-
if (!removed.ok && !removed.changed && applied.changed && !
|
|
771
|
+
if (!removed.ok && !removed.changed && applied.changed && !await withConfigDirHardeningSettled(getConfigDir(), rollback)) {
|
|
769
772
|
return postCommitRefusal(500, "claude-desktop", "write_failed",
|
|
770
773
|
"Gateway cleanup and first-party settings rollback did not complete.", { desiredEnabled });
|
|
771
774
|
}
|
|
@@ -830,7 +833,7 @@ async function handleClaudeDesktopToggle(ctx: ManagementContext): Promise<Respon
|
|
|
830
833
|
if (!result.written) return postCommitRefusal(500, "claude-desktop", "write_failed", "Claude Desktop apply failed.", { desiredEnabled: latestDesiredEnabled });
|
|
831
834
|
const committed = persistCommittedDesktopGateway(ctx.config, latest.claudeCode?.desktopProfile, result.fingerprint);
|
|
832
835
|
const stateWarning = committed.ok ? "" : " The committed gateway mode/profile state was not saved.";
|
|
833
|
-
const removed =
|
|
836
|
+
const removed = await removeDesktopFirstPartySettled(loadConfig);
|
|
834
837
|
if (!removed.ok) return postCommitRefusal(500, "claude-desktop", "write_failed", "Gateway applied, but first-party settings cleanup did not complete." + stateWarning, { desiredEnabled: latestDesiredEnabled });
|
|
835
838
|
return jsonResponse({
|
|
836
839
|
ok: true, clientId: "claude-desktop", changed: true, state: "current", desiredEnabled: latestDesiredEnabled,
|
|
@@ -53,6 +53,8 @@ export type ExemptionReason =
|
|
|
53
53
|
| "dead"
|
|
54
54
|
/** Desktop shell internal display-state POST; the CLI has no app updater state to publish. */
|
|
55
55
|
| "desktop-internal"
|
|
56
|
+
/** Dashboard-only discovery for an interaction the CLI does not expose. */
|
|
57
|
+
| "gui-only"
|
|
56
58
|
/**
|
|
57
59
|
* A verb is owed but belongs to a later work-phase. BOUNDED: requires `owner` and
|
|
58
60
|
* `ownerDoc`, and the parity test asserts that tracked doc exists and names the route.
|
|
@@ -95,6 +97,7 @@ export interface ManagementRoute {
|
|
|
95
97
|
/** Every reachable management route. */
|
|
96
98
|
export const MANAGEMENT_ROUTES: readonly ManagementRoute[] = [
|
|
97
99
|
// server/management-api
|
|
100
|
+
{ method: "GET", path: "/api/stop", module: "server/management-api", mutates: false },
|
|
98
101
|
{ method: "POST", path: "/api/stop", module: "server/management-api", mutates: true },
|
|
99
102
|
// codex/auth-api
|
|
100
103
|
{ method: "GET", path: "/api/codex-auth/preserve-signed-in", module: "codex/auth-api/routes", mutates: false },
|
|
@@ -444,6 +447,7 @@ export const MANAGEMENT_ROUTES: readonly ManagementRoute[] = [
|
|
|
444
447
|
{ method: "GET", path: "/api/system/codex-app-server", module: "server/management/system-routes", mutates: false, mechanism: "path-constant" },
|
|
445
448
|
{ method: "POST", path: "/api/system/codex-restart", module: "server/management/system-routes", mutates: true, mechanism: "path-constant" },
|
|
446
449
|
{ method: "POST", path: "/api/providers/reload", module: "server/management/provider-routes", mutates: true, mechanism: "path-constant", exempt: { reason: "capability-principal", why: "Gated on the local-provider-reload-capability principal (provider-routes.ts:467), not an operator action." } },
|
|
450
|
+
{ method: "GET", path: "/api/client-integrations/hermes/profiles", module: "server/management/hermes-profile-routes", mutates: false, mechanism: "path-constant", exempt: { reason: "gui-only", why: "The dashboard discovers selectable Hermes profiles; the CLI intentionally has no Hermes profile selector." } },
|
|
447
451
|
{ method: "GET", path: "/api/client-integrations/{clientId}", module: "server/management/integration-routes", mutates: false, mechanism: "prefix-decode" },
|
|
448
452
|
{ method: "PUT", path: "/api/client-integrations/{clientId}", module: "server/management/integration-routes", mutates: true, mechanism: "prefix-decode" },
|
|
449
453
|
{ method: "GET", path: "/api/request-history/{id}", module: "server/management/request-history-routes", mutates: false, mechanism: "slice" },
|
|
@@ -411,6 +411,11 @@ export async function handleManagementAPI(
|
|
|
411
411
|
}
|
|
412
412
|
if (routed) return routed;
|
|
413
413
|
|
|
414
|
+
if (url.pathname === "/api/stop" && req.method === "GET") {
|
|
415
|
+
const response = jsonResponse((await import("./stop-teardown")).stopCapabilities(), 200, req, config);
|
|
416
|
+
response.headers.set("Cache-Control", "no-store");
|
|
417
|
+
return response;
|
|
418
|
+
}
|
|
414
419
|
if (url.pathname === "/api/stop" && req.method === "POST") {
|
|
415
420
|
const { installedServiceRespawnRisk, stopServiceIfInstalledDetailed, isServiceOwnershipError } = await import("../service");
|
|
416
421
|
// `ocx stop` performs its own shared teardown AFTER verifying the scheduler did not
|
|
@@ -110,6 +110,10 @@ export function predictCursorEffort(
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
export interface ModelCapabilityInput {
|
|
113
|
+
supportsReasoning?: boolean;
|
|
114
|
+
supportsThinkingToggle?: boolean;
|
|
115
|
+
supportsReasoningEffort?: boolean;
|
|
116
|
+
defaultThinkingEnabled?: boolean;
|
|
113
117
|
reasoningEfforts?: readonly string[];
|
|
114
118
|
contextWindow?: number;
|
|
115
119
|
/**
|
|
@@ -133,7 +137,10 @@ export interface ModelCapabilityFields {
|
|
|
133
137
|
input_modalities?: string[];
|
|
134
138
|
supports_tool_use: true;
|
|
135
139
|
supports_streaming: true;
|
|
136
|
-
supports_reasoning
|
|
140
|
+
supports_reasoning?: boolean;
|
|
141
|
+
supports_thinking_toggle?: boolean;
|
|
142
|
+
supports_reasoning_effort?: boolean;
|
|
143
|
+
default_thinking_enabled?: boolean;
|
|
137
144
|
supports_vision?: boolean;
|
|
138
145
|
reasoning_effort?: string[];
|
|
139
146
|
};
|
|
@@ -166,7 +173,15 @@ function positiveInt(value: unknown): number | undefined {
|
|
|
166
173
|
}
|
|
167
174
|
|
|
168
175
|
export function modelCapabilityFields(input: ModelCapabilityInput): ModelCapabilityFields {
|
|
169
|
-
const efforts =
|
|
176
|
+
const efforts = input.supportsReasoning === false || input.supportsReasoningEffort === false ? []
|
|
177
|
+
: (input.reasoningEfforts ?? []).filter(effort => typeof effort === "string" && effort.length > 0);
|
|
178
|
+
// Legacy discovery used an explicit empty ladder to withhold Cursor reasoning controls.
|
|
179
|
+
// Independent capability declarations replace that compatibility inference per axis.
|
|
180
|
+
const legacyEmptyLadder = input.reasoningEfforts?.length === 0
|
|
181
|
+
&& input.supportsThinkingToggle === undefined && input.supportsReasoningEffort === undefined;
|
|
182
|
+
const supportsReasoning = input.supportsReasoning
|
|
183
|
+
?? (input.supportsThinkingToggle === true || input.supportsReasoningEffort === true || efforts.length > 0
|
|
184
|
+
? true : legacyEmptyLadder ? false : undefined);
|
|
170
185
|
const contextLength = positiveInt(input.contextWindow);
|
|
171
186
|
const longContextLength = positiveInt(input.longContextWindow);
|
|
172
187
|
const maxOutputTokens = positiveInt(input.maxOutputTokens);
|
|
@@ -187,7 +202,10 @@ export function modelCapabilityFields(input: ModelCapabilityInput): ModelCapabil
|
|
|
187
202
|
...(modalities !== undefined && modalities.length > 0 ? { input_modalities: [...modalities] } : {}),
|
|
188
203
|
supports_tool_use: true,
|
|
189
204
|
supports_streaming: true,
|
|
190
|
-
supports_reasoning:
|
|
205
|
+
...(supportsReasoning !== undefined ? { supports_reasoning: supportsReasoning } : {}),
|
|
206
|
+
...(input.supportsThinkingToggle !== undefined ? { supports_thinking_toggle: input.supportsThinkingToggle } : {}),
|
|
207
|
+
...(input.supportsReasoningEffort !== undefined ? { supports_reasoning_effort: input.supportsReasoningEffort } : {}),
|
|
208
|
+
...(input.defaultThinkingEnabled !== undefined ? { default_thinking_enabled: input.defaultThinkingEnabled } : {}),
|
|
191
209
|
...(supportsVision !== undefined ? { supports_vision: supportsVision } : {}),
|
|
192
210
|
...(efforts.length > 0 ? { reasoning_effort: [...efforts] } : {}),
|
|
193
211
|
},
|
|
@@ -28,6 +28,7 @@ import { sanitizeNonReplayableUpstreamError } from "./non-replayable-error";
|
|
|
28
28
|
import { isNonReplayableResponse } from "../../lib/upstream-retry";
|
|
29
29
|
import { isCanonicalOpenAiForwardProvider } from "../../providers/openai-tiers";
|
|
30
30
|
import { guardEmptyToolCatalogEvents, guardEmptyToolCatalogStream } from "../../lib/empty-tool-catalog";
|
|
31
|
+
import { guardCompactionSummary } from "../../responses/compaction-summary";
|
|
31
32
|
|
|
32
33
|
/** One responsibility of the Responses request pipeline; state owners are explicit. */
|
|
33
34
|
export async function deliverAdapterResponse(
|
|
@@ -183,7 +184,9 @@ export async function deliverAdapterResponse(
|
|
|
183
184
|
continuation: fetchGuardedEmptyCompletionRetry,
|
|
184
185
|
})
|
|
185
186
|
: advisorStream;
|
|
186
|
-
const
|
|
187
|
+
const catalogGuardedEventStream = guardEmptyToolCatalogStream(completionGuardedEventStream, clientToolCatalog, translatorBudget);
|
|
188
|
+
const guardedEventStream = routedCompaction && transportState.activeAdapter.name === "anthropic"
|
|
189
|
+
? guardCompactionSummary(catalogGuardedEventStream, translatorBudget) : catalogGuardedEventStream;
|
|
187
190
|
const { toolNsMap, declaredToolNames, toolParameterSchemas, freeformToolNames, bareCustomToolNames, toolSearchToolNames } = deliveryToolBridgeMaps;
|
|
188
191
|
// One completion owner for both deliveries: the bridge calls it from its terminal, the
|
|
189
192
|
// direct client encoder from the fold of the same events.
|
|
@@ -329,6 +332,13 @@ export async function deliverAdapterResponse(
|
|
|
329
332
|
} else {
|
|
330
333
|
events = guardedEvents;
|
|
331
334
|
}
|
|
335
|
+
if (routedCompaction && transportState.activeAdapter.name === "anthropic") {
|
|
336
|
+
const summaryEvents: AdapterEvent[] = [];
|
|
337
|
+
for await (const event of guardCompactionSummary((async function* () { yield* events; })(), translatorBudget)) {
|
|
338
|
+
summaryEvents.push(event);
|
|
339
|
+
}
|
|
340
|
+
events = summaryEvents;
|
|
341
|
+
}
|
|
332
342
|
} catch (error) {
|
|
333
343
|
if (error instanceof ResponseBodyInactivityError) {
|
|
334
344
|
return formatErrorResponse(504, "upstream_error", "Upstream response body stalled before completing");
|
|
@@ -20,7 +20,7 @@ import type { ResponsesSendBudget } from "./request-send-budget";
|
|
|
20
20
|
import { linkAbortSignal } from "./core-lifetime";
|
|
21
21
|
import type { AdapterRequest } from "../../adapters/base";
|
|
22
22
|
import type { AdapterEvent } from "../../types";
|
|
23
|
-
import { bridgeToResponsesSSE, buildResponseJSON, formatErrorResponse } from "../../bridge";
|
|
23
|
+
import { bridgeToResponsesSSE, buildResponseJSON, formatErrorResponse, formatUpstreamFailureResponse } from "../../bridge";
|
|
24
24
|
import { trackStreamLifetime } from "../lifecycle";
|
|
25
25
|
import {
|
|
26
26
|
recordAdapterReasoning,
|
|
@@ -1962,7 +1962,7 @@ export async function prepareAdapterExchange(
|
|
|
1962
1962
|
upstreamRetryAfter,
|
|
1963
1963
|
includeDefault: !(transportState.anthropicPoolAccountId && classifyAnthropic429(upstreamResponse.headers) === "request-scoped-unknown"),
|
|
1964
1964
|
});
|
|
1965
|
-
return
|
|
1965
|
+
return formatUpstreamFailureResponse(upstreamResponse, normalized.code,
|
|
1966
1966
|
upstreamResponse.status,
|
|
1967
1967
|
normalized.cyberPolicy ? (normalized.type ?? CYBER_POLICY_ERROR_CODE) : "upstream_error",
|
|
1968
1968
|
message,
|
|
@@ -8,7 +8,8 @@ import { CodexWsMetadata, type CodexWsQuotaObserver } from "./codex-ws-metadata"
|
|
|
8
8
|
import { CODEX_RESPONSES_HTTP_URL, type PreparedCodexWsRequest } from "./codex-ws-request";
|
|
9
9
|
import { CodexWsCorrelation } from "./codex-ws-correlation";
|
|
10
10
|
import type { CodexWsSession } from "./codex-ws-session";
|
|
11
|
-
import { UPGRADE_DEADLINE_MS, CODEX_WS_LIVENESS_PING_INTERVAL_MS, CODEX_WS_RESPONSE_PRELUDE_TIMEOUT_MS,
|
|
11
|
+
import { UPGRADE_DEADLINE_MS, CODEX_WS_LIVENESS_PING_INTERVAL_MS, CODEX_WS_RESPONSE_PRELUDE_TIMEOUT_MS,
|
|
12
|
+
CODEX_WS_COMMITTED_SILENT_INTERVALS, MAX_CODEX_WS_FRAME_BYTES,
|
|
12
13
|
MAX_CODEX_WS_QUEUE_BYTES, markCodexWsResponse, markCodexWsPreludeProjection, normalizeResponsesWsRelayEvent, closedBeforeTerminalMessage,
|
|
13
14
|
codexWsCreateFrameExceedsLimit, codexWsFailureDetail, codexWsPreResponseFailure, markCodexWsStage, codexWsOcxVersion,
|
|
14
15
|
markCodexWsSocketDeath, codexWsWrapperStatus, isCodexWsTerminalEvent, type CodexWsFailureStage, type CodexWsStageRecord,
|
|
@@ -155,8 +156,11 @@ export function codexWsExchange(options: ExchangeOptions): Promise<Response> {
|
|
|
155
156
|
// Liveness while waiting for the first response event (metadata path only): the
|
|
156
157
|
// silence timer is re-armed by every inbound frame or pong; the pinger runs on a fixed
|
|
157
158
|
// interval so a peer that answers pings can never trip the silence bound while alive.
|
|
159
|
+
// After the commit, each ping tick checks whether any frame or pong arrived since the last.
|
|
158
160
|
let silenceTimer: ReturnType<typeof setTimeout> | undefined;
|
|
159
161
|
let pingTimer: ReturnType<typeof setTimeout> | undefined;
|
|
162
|
+
let inboundAtLastTick = 0;
|
|
163
|
+
let silentIntervals = 0;
|
|
160
164
|
// The resolved 200, retained so a later body failure can replace its
|
|
161
165
|
// success-shaped stage record with the failure-shaped one (#4191).
|
|
162
166
|
let committedResponse: Response | null = null;
|
|
@@ -260,6 +264,7 @@ export function codexWsExchange(options: ExchangeOptions): Promise<Response> {
|
|
|
260
264
|
markCodexWsStage(response, stageRecord(null));
|
|
261
265
|
committedResponse = response;
|
|
262
266
|
resolve(response);
|
|
267
|
+
startCommittedLiveness();
|
|
263
268
|
};
|
|
264
269
|
|
|
265
270
|
/**
|
|
@@ -377,18 +382,40 @@ export function codexWsExchange(options: ExchangeOptions): Promise<Response> {
|
|
|
377
382
|
CODEX_WS_RESPONSE_PRELUDE_TIMEOUT_MS,
|
|
378
383
|
);
|
|
379
384
|
};
|
|
380
|
-
|
|
385
|
+
const pingable = () => typeof (ws as WebSocket & { ping?: unknown }).ping === "function";
|
|
386
|
+
/** False when ping() threw. It may also close the socket and settle the exchange. */
|
|
387
|
+
const sendPing = (): boolean => {
|
|
388
|
+
if (!pingable()) return false;
|
|
389
|
+
try { (ws as WebSocket & { ping: (data?: string) => void }).ping(); } catch { return false; }
|
|
390
|
+
pings += 1;
|
|
391
|
+
return true;
|
|
392
|
+
};
|
|
393
|
+
/** Ping on a fixed interval for the life of the exchange; a socket without ping() is never pinged. */
|
|
381
394
|
const schedulePing = () => {
|
|
382
|
-
|
|
383
|
-
if (typeof ping !== "function" || responseCommitted || terminal) return;
|
|
395
|
+
if (!pingable() || terminal) return;
|
|
384
396
|
pingTimer = setTimeout(() => {
|
|
385
|
-
if (
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
397
|
+
if (terminal) return;
|
|
398
|
+
if (responseCommitted && pongs > 0) {
|
|
399
|
+
const inbound = upstreamFrames + pongs;
|
|
400
|
+
silentIntervals = inbound === inboundAtLastTick ? silentIntervals + 1 : 0;
|
|
401
|
+
inboundAtLastTick = inbound;
|
|
402
|
+
if (silentIntervals >= CODEX_WS_COMMITTED_SILENT_INTERVALS) {
|
|
403
|
+
failStream(`codex websocket stopped answering after the response started${codexWsFailureDetail(failureStage())}`);
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
sendPing();
|
|
389
408
|
if (!terminal) schedulePing();
|
|
390
409
|
}, CODEX_WS_LIVENESS_PING_INTERVAL_MS);
|
|
391
410
|
};
|
|
411
|
+
/** Only a peer that has ponged is judged by its silence, so probe again if none has yet. */
|
|
412
|
+
const startCommittedLiveness = () => {
|
|
413
|
+
if (!metadata || terminal || !pingable()) return;
|
|
414
|
+
inboundAtLastTick = upstreamFrames + pongs;
|
|
415
|
+
silentIntervals = 0;
|
|
416
|
+
if (pongs === 0) sendPing();
|
|
417
|
+
if (!terminal) schedulePing();
|
|
418
|
+
};
|
|
392
419
|
const onPong = () => {
|
|
393
420
|
if (terminal) return;
|
|
394
421
|
pongs += 1;
|
|
@@ -559,7 +586,10 @@ export function codexWsExchange(options: ExchangeOptions): Promise<Response> {
|
|
|
559
586
|
if (!metadata) commitResponse();
|
|
560
587
|
else if (!responseCommitted && !terminal) {
|
|
561
588
|
armSilence();
|
|
562
|
-
|
|
589
|
+
// Probe now, not one interval in: the path can die seconds after the send, before a
|
|
590
|
+
// held commit, and the committed check needs a pong from before that.
|
|
591
|
+
sendPing();
|
|
592
|
+
if (!terminal) schedulePing();
|
|
563
593
|
}
|
|
564
594
|
};
|
|
565
595
|
|
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
import { readCodexWsUpgradeHeaders } from "./codex-ws-metadata";
|
|
2
2
|
|
|
3
3
|
export const MAX_CODEX_WS_SESSION_EXCHANGES = 32;
|
|
4
|
+
export const CODEX_WS_SESSION_CLOSE_GRACE_MS = 1_000;
|
|
5
|
+
|
|
6
|
+
/** A disposed lease must not leave a private socket waiting on an unresponsive peer. */
|
|
7
|
+
function closeSessionSocket(socket: WebSocket & { terminate?: () => void }, immediate: boolean): void {
|
|
8
|
+
if (immediate) {
|
|
9
|
+
// Preserve the retained pool's immediate physical-capacity release.
|
|
10
|
+
try { socket.close(); } catch { /* already closing */ }
|
|
11
|
+
try { socket.terminate?.(); } catch { /* already closed */ }
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (socket.readyState === 3) return;
|
|
15
|
+
if (typeof socket.terminate !== "function") {
|
|
16
|
+
// A close observer cannot force teardown without the optional native method.
|
|
17
|
+
try { socket.close(); } catch { /* best-effort graceful teardown */ }
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
let timer: ReturnType<typeof setTimeout> | undefined;
|
|
21
|
+
const cleanup = (): void => {
|
|
22
|
+
if (timer !== undefined) clearTimeout(timer);
|
|
23
|
+
timer = undefined;
|
|
24
|
+
socket.removeEventListener("close", cleanup);
|
|
25
|
+
};
|
|
26
|
+
const terminate = (): void => {
|
|
27
|
+
cleanup();
|
|
28
|
+
if (socket.readyState !== 3) {
|
|
29
|
+
try { socket.terminate?.(); } catch { /* best-effort physical teardown */ }
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
// Install before close(): older runtimes and test peers may close synchronously.
|
|
33
|
+
// Capture only the socket, not the disposed session or its former exchange owner.
|
|
34
|
+
socket.addEventListener("close", cleanup, { once: true });
|
|
35
|
+
timer = setTimeout(terminate, CODEX_WS_SESSION_CLOSE_GRACE_MS);
|
|
36
|
+
timer.unref?.();
|
|
37
|
+
try { socket.close(); } catch { terminate(); }
|
|
38
|
+
// close() may synchronously change the state narrowed by the earlier guard.
|
|
39
|
+
if ((socket.readyState as number) === 3) cleanup();
|
|
40
|
+
}
|
|
4
41
|
|
|
5
42
|
/** Owns one physical socket; request listeners belong to the exchange, not this object. */
|
|
6
43
|
export class CodexWsSession {
|
|
@@ -69,10 +106,7 @@ export class CodexWsSession {
|
|
|
69
106
|
try { owner?.(reason); } finally {
|
|
70
107
|
this.busy = false;
|
|
71
108
|
this.completedIds.clear();
|
|
72
|
-
|
|
73
|
-
if (this.retainable) {
|
|
74
|
-
try { (this.socket as WebSocket & { terminate?: () => void }).terminate?.(); } catch { /* already closed */ }
|
|
75
|
-
}
|
|
109
|
+
closeSessionSocket(this.socket, this.retainable);
|
|
76
110
|
this.changed();
|
|
77
111
|
}
|
|
78
112
|
}
|
|
@@ -25,6 +25,11 @@ export const UPGRADE_DEADLINE_MS = 10_000;
|
|
|
25
25
|
// keeps exactly the previous 90 s bound; a peer that does can never trip it while alive.
|
|
26
26
|
export const CODEX_WS_LIVENESS_PING_INTERVAL_MS = 15_000;
|
|
27
27
|
export const CODEX_WS_RESPONSE_PRELUDE_TIMEOUT_MS = 90_000;
|
|
28
|
+
// The pinger keeps running after the commit: a tunnel restart or Wi-Fi rejoin can drop the path
|
|
29
|
+
// without a FIN or RST, and codex-rs would wait out its 300 s idle timeout. A peer that has ponged
|
|
30
|
+
// and then sends no frame and no pong for this many intervals is gone, and the stream fails so the
|
|
31
|
+
// client retries. One missed pong is not a verdict.
|
|
32
|
+
export const CODEX_WS_COMMITTED_SILENT_INTERVALS = 2;
|
|
28
33
|
// Keep the push-based WS transport inside the same memory envelope as the
|
|
29
34
|
// bounded SSE relays that consume this response. Unlike fetch response bodies,
|
|
30
35
|
// a WebSocket cannot be paused when a ReadableStream applies backpressure, so
|
|
@@ -404,7 +409,7 @@ export type CodexWsFailureStage = {
|
|
|
404
409
|
firstResponseMs: number | null;
|
|
405
410
|
/** Milliseconds from send to this failure; null when the failure predates the send. */
|
|
406
411
|
elapsedMs: number | null;
|
|
407
|
-
/** Liveness pings the exchange sent
|
|
412
|
+
/** Liveness pings the exchange sent, before and after the first response event. */
|
|
408
413
|
pings: number;
|
|
409
414
|
/** Pongs the peer answered with; zero on a peer that never answers pings. */
|
|
410
415
|
pongs: number;
|