@bitkyc08/opencodex 2.92.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 +10 -5
- package/gui/dist/assets/App-CJZoq-uF.js +58 -0
- package/gui/dist/assets/{Tray-BSsxznDm.js → Tray-BWQPcgZn.js} +1 -1
- package/gui/dist/assets/index-DRe8Hhfz.css +1 -0
- package/gui/dist/assets/{index-BlFE_VB_.js → index-Xfct8owH.js} +12 -12
- package/gui/dist/assets/{quota-summary-BRlbXgw0.js → quota-summary-DxToX1rV.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/App-sUf_8afJ.js +0 -58
- package/gui/dist/assets/index-DPeB9HpV.css +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { splitSourceLines, type SourceLine } from "./toml-source-lines";
|
|
1
|
+
import { sourceAssignment, splitSourceLines, type SourceLine } from "./toml-source-lines";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Pure, ownership-aware edits for Codex's native `[agents]` defaults.
|
|
@@ -21,6 +21,16 @@ export interface ManagedSubagentDefaults {
|
|
|
21
21
|
reasoningEffort?: string;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
/**
|
|
25
|
+
* The exact values the last injection wrote under a marker, as recorded in the
|
|
26
|
+
* injection journal. A marker proves only that OpenCodex once wrote the line;
|
|
27
|
+
* this record proves which value it wrote. A marked value that no longer
|
|
28
|
+
* matches it was edited by someone else — the user, or a Codex settings writer
|
|
29
|
+
* that keeps comments — and is adopted as user-owned instead of reverted.
|
|
30
|
+
* Absent (`null`/`undefined`) means no evidence, and the marker alone decides.
|
|
31
|
+
*/
|
|
32
|
+
export type WrittenSubagentDefaults = Partial<Record<ManagedSubagentDefaultKey, string>>;
|
|
33
|
+
|
|
24
34
|
export interface ManagedSubagentDefaultsConflict {
|
|
25
35
|
key: ManagedSubagentDefaultKey;
|
|
26
36
|
line: number;
|
|
@@ -303,15 +313,42 @@ function invalidInput(content: string, error: string): ManagedSubagentDefaultsTr
|
|
|
303
313
|
return { ok: false, changed: false, content, conflicts: [], error };
|
|
304
314
|
}
|
|
305
315
|
|
|
316
|
+
/**
|
|
317
|
+
* Marker lines whose value differs from what OpenCodex recorded writing. The
|
|
318
|
+
* marker is dropped so the line reads as what it now is: a user-owned value.
|
|
319
|
+
*/
|
|
320
|
+
function userEditedMarkers(
|
|
321
|
+
lines: readonly SourceLine[],
|
|
322
|
+
shape: TomlShape,
|
|
323
|
+
written: WrittenSubagentDefaults | null | undefined,
|
|
324
|
+
): number[] {
|
|
325
|
+
if (!written) return [];
|
|
326
|
+
const stale: number[] = [];
|
|
327
|
+
for (const definition of shape.definitions.values()) {
|
|
328
|
+
const recorded = written[definition.key];
|
|
329
|
+
if (!definition.owned || typeof recorded !== "string") continue;
|
|
330
|
+
// The whole assignment, so a value rewritten as a multiline string still decodes. An
|
|
331
|
+
// undecodable value is not edit evidence; the single-line replace step rejects it later.
|
|
332
|
+
const current = sourceAssignment(lines, definition.index, shape.agentsEnd ?? lines.length)?.value;
|
|
333
|
+
if (typeof current === "string" && current !== recorded) stale.push(definition.index - 1);
|
|
334
|
+
}
|
|
335
|
+
return stale;
|
|
336
|
+
}
|
|
337
|
+
|
|
306
338
|
/**
|
|
307
339
|
* Add/update opencodex-owned native subagent defaults, or remove them with
|
|
308
340
|
* `defaults = null`. Unmarked target keys are user-owned: they are retained and
|
|
309
341
|
* returned as conflicts rather than overwritten. Ambiguous TOML is rejected
|
|
310
342
|
* byte-for-byte so callers never have to guess what was changed.
|
|
343
|
+
*
|
|
344
|
+
* `written` is the journal's record of the values the last injection wrote.
|
|
345
|
+
* When supplied, a marked value that differs from it is user-edited: its marker
|
|
346
|
+
* is dropped and the value is treated exactly like any other user-owned key.
|
|
311
347
|
*/
|
|
312
348
|
export function transformManagedSubagentDefaults(
|
|
313
349
|
content: string,
|
|
314
350
|
defaults: ManagedSubagentDefaults | null,
|
|
351
|
+
written?: WrittenSubagentDefaults | null,
|
|
315
352
|
): ManagedSubagentDefaultsTransformResult {
|
|
316
353
|
if (defaults !== null) {
|
|
317
354
|
if (typeof defaults.model !== "string" || defaults.model.length === 0) {
|
|
@@ -329,14 +366,20 @@ export function transformManagedSubagentDefaults(
|
|
|
329
366
|
}
|
|
330
367
|
}
|
|
331
368
|
|
|
332
|
-
|
|
369
|
+
let lines = splitSourceLines(content);
|
|
333
370
|
if (defaults === null && !lines.some(line =>
|
|
334
371
|
markerLine(line, MANAGED_SUBAGENT_DEFAULT_MARKER)
|
|
335
372
|
|| markerLine(line, MANAGED_AGENTS_TABLE_MARKER))) {
|
|
336
373
|
return { ok: true, changed: false, content, conflicts: [] };
|
|
337
374
|
}
|
|
338
|
-
|
|
375
|
+
let analysis = analyzeToml(lines);
|
|
339
376
|
if ("error" in analysis) return invalidInput(content, analysis.error);
|
|
377
|
+
const stale = new Set(userEditedMarkers(lines, analysis.shape, written));
|
|
378
|
+
if (stale.size > 0) {
|
|
379
|
+
lines = lines.filter((_, index) => !stale.has(index));
|
|
380
|
+
analysis = analyzeToml(lines);
|
|
381
|
+
if ("error" in analysis) return invalidInput(content, analysis.error);
|
|
382
|
+
}
|
|
340
383
|
const { shape } = analysis;
|
|
341
384
|
const eol = dominantEol(lines);
|
|
342
385
|
const desired = new Map<ManagedSubagentDefaultKey, string>();
|
|
@@ -361,8 +404,10 @@ export function transformManagedSubagentDefaults(
|
|
|
361
404
|
// Model and effort are one effective native-default pair. A partial write
|
|
362
405
|
// could apply a newly managed effort to a user's model (or vice versa), so
|
|
363
406
|
// any desired-key ownership conflict makes the whole enable/update a no-op.
|
|
407
|
+
// Only an adopted user edit's stale marker is dropped from the result.
|
|
364
408
|
if (conflicts.length > 0) {
|
|
365
|
-
|
|
409
|
+
const adopted = joinSourceLines(lines);
|
|
410
|
+
return { ok: true, changed: adopted !== content, content: adopted, conflicts };
|
|
366
411
|
}
|
|
367
412
|
}
|
|
368
413
|
|
package/src/combos/failover.ts
CHANGED
|
@@ -313,7 +313,8 @@ export function sweepExpiredComboTargetCooldowns(now = Date.now()): number {
|
|
|
313
313
|
return removed;
|
|
314
314
|
}
|
|
315
315
|
|
|
316
|
-
|
|
316
|
+
/** Clear all cooldowns, one combo, or only the supplied target keys within that combo. */
|
|
317
|
+
export function clearComboTargetCooldowns(comboId?: string, targetKeys?: Iterable<string>): void {
|
|
317
318
|
if (comboId === undefined) {
|
|
318
319
|
targetCooldowns.clear();
|
|
319
320
|
liveComboTargets.clear();
|
|
@@ -321,6 +322,10 @@ export function clearComboTargetCooldowns(comboId?: string): void {
|
|
|
321
322
|
return;
|
|
322
323
|
}
|
|
323
324
|
const prefix = `${comboId}\0`;
|
|
325
|
+
if (targetKeys !== undefined) {
|
|
326
|
+
for (const key of targetKeys) targetCooldowns.delete(`${prefix}${key}`);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
324
329
|
for (const key of targetCooldowns.keys()) {
|
|
325
330
|
if (key.startsWith(prefix)) targetCooldowns.delete(key);
|
|
326
331
|
}
|
|
@@ -773,7 +778,13 @@ export function codexAccountModelRefusal(
|
|
|
773
778
|
export function comboFailureDecision(
|
|
774
779
|
status: number,
|
|
775
780
|
message: string,
|
|
776
|
-
options?: {
|
|
781
|
+
options?: {
|
|
782
|
+
code?: string | null;
|
|
783
|
+
codexModelRefusal?: CodexAccountModelRefusal;
|
|
784
|
+
failedAdapter?: string;
|
|
785
|
+
/** The caller proved the failure is an adapter-normalized plan refusal (`isModelNotInPlanRefusal`). */
|
|
786
|
+
verifiedPlanRefusal?: boolean;
|
|
787
|
+
},
|
|
777
788
|
): ComboFailureDecision {
|
|
778
789
|
if (status === 499) return "stop";
|
|
779
790
|
if (message.toLowerCase().includes("origin_rejected")) return "stop";
|
|
@@ -846,6 +857,10 @@ export function comboFailureDecision(
|
|
|
846
857
|
if (["model_not_found", "model_unavailable", "unsupported_model", "unsupported_input_modality"].includes(failureCode)) {
|
|
847
858
|
return "hop";
|
|
848
859
|
}
|
|
860
|
+
// So is a plan refusal (#7684): this account's plan excludes THIS model, and it cools only the
|
|
861
|
+
// refused target because `comboFailureCooldownScope` reads a 400 as target-scoped. Unlike the
|
|
862
|
+
// codes above it is honoured only with caller-supplied provenance, never from the code alone.
|
|
863
|
+
if (failureCode === "model_not_in_plan" && options?.verifiedPlanRefusal === true) return "hop";
|
|
849
864
|
if (modelRefusal === "refusal") return "hop";
|
|
850
865
|
// `free_rate_limited` no longer routes through `isProviderScopedQuotaCap` (it is a
|
|
851
866
|
// per-request cap, not provider-wide evidence), so keep its hop verdict explicit here.
|
|
@@ -38,6 +38,27 @@ export function isSystemOneEndpoint(baseUrl: string): boolean {
|
|
|
38
38
|
*/
|
|
39
39
|
export function jevDecisionEndpointUrl(baseUrl: string): string {
|
|
40
40
|
const raw = baseUrl.trim();
|
|
41
|
-
|
|
41
|
+
let stripped = raw.replace(/\/+$/, "");
|
|
42
|
+
try {
|
|
43
|
+
const parsed = new URL(raw);
|
|
44
|
+
if (parsed.hostname === "ai-gateway.vercel.sh") {
|
|
45
|
+
if (!stripped.endsWith("/decisions")) {
|
|
46
|
+
stripped = stripped.replace(/\/systemone$/, "").replace(/\/+$/, "") + "/decisions";
|
|
47
|
+
}
|
|
48
|
+
return stripped;
|
|
49
|
+
}
|
|
50
|
+
} catch {
|
|
51
|
+
return stripped.endsWith("/systemone") ? stripped : raw;
|
|
52
|
+
}
|
|
42
53
|
return stripped.endsWith("/systemone") ? stripped : raw;
|
|
43
54
|
}
|
|
55
|
+
|
|
56
|
+
/** Check if endpoint path targets /decisions or Vercel AI Gateway */
|
|
57
|
+
export function isDecisionsEndpoint(url: string): boolean {
|
|
58
|
+
try {
|
|
59
|
+
const parsed = new URL(url.trim());
|
|
60
|
+
return parsed.hostname === "ai-gateway.vercel.sh";
|
|
61
|
+
} catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -12,6 +12,7 @@ import { providerMatchesRegistryTransport } from "../providers/registry";
|
|
|
12
12
|
import type { OcxConfig, OcxProviderConfig } from "../types";
|
|
13
13
|
import type { JevDecision, ResolveJevDecisionOptions } from "./jev";
|
|
14
14
|
import {
|
|
15
|
+
isDecisionsEndpoint,
|
|
15
16
|
isSystemOneEndpoint,
|
|
16
17
|
jevDecisionEndpointUrl,
|
|
17
18
|
JEV_DECISION_TIMEOUT_DEFAULT_MS,
|
|
@@ -48,6 +49,7 @@ export type JevServiceExchangeOptions = Pick<ResolveJevDecisionOptions,
|
|
|
48
49
|
export interface JevDecisionEndpointShape {
|
|
49
50
|
model: string;
|
|
50
51
|
descriptiveCriteria: boolean;
|
|
52
|
+
url?: string;
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
/** The decision deadline: the configured value when in bounds, otherwise the four-second default. */
|
|
@@ -208,7 +210,7 @@ export async function exchangeJevDecision<T>(
|
|
|
208
210
|
if (endpoint === null) return { gate: "invalid" };
|
|
209
211
|
if (!endpoint) return { gate: "missing_key" };
|
|
210
212
|
|
|
211
|
-
const request = prepareRequestBody(prepare, { model: endpoint.model, descriptiveCriteria: endpoint.descriptiveCriteria });
|
|
213
|
+
const request = prepareRequestBody(prepare, { model: endpoint.model, descriptiveCriteria: endpoint.descriptiveCriteria, ...(isDecisionsEndpoint(endpoint.url) ? { url: endpoint.url } : {}) });
|
|
212
214
|
if (options.signal?.aborted) throw options.signal.reason;
|
|
213
215
|
if ("gate" in request) return request;
|
|
214
216
|
const requestBody = request.body;
|
package/src/combos/jev.ts
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
JEV_MAX_CANDIDATE_FIELD_CHARS,
|
|
9
9
|
} from "./types";
|
|
10
10
|
|
|
11
|
+
import { isDecisionsEndpoint } from "./jev-decision-contract";
|
|
11
12
|
import {
|
|
12
13
|
exchangeJevDecision,
|
|
13
14
|
JEV_PROVIDER_ID,
|
|
@@ -25,6 +26,8 @@ export const JEV_MAX_CANDIDATES = 64;
|
|
|
25
26
|
/** Ollama's System One choice questions accept 2..26 options; other services share the floor. */
|
|
26
27
|
const SELF_HOSTED_MIN_OPTIONS = 2;
|
|
27
28
|
const SELF_HOSTED_MAX_OPTIONS = 26;
|
|
29
|
+
const DECISIONS_MIN_OPTIONS = 2;
|
|
30
|
+
const DECISIONS_MAX_OPTIONS = 255;
|
|
28
31
|
|
|
29
32
|
const TASK_CHARS = 500;
|
|
30
33
|
const TASK_HEAD_CHARS = 320;
|
|
@@ -570,19 +573,46 @@ export function parseJevDecision(
|
|
|
570
573
|
payload: unknown,
|
|
571
574
|
candidates: readonly JevCandidate[],
|
|
572
575
|
): Pick<JevDecision, "targetKey" | "effort" | "confidence" | "chosenProbability" | "usage"> {
|
|
573
|
-
if (!isRecord(payload)
|
|
576
|
+
if (!isRecord(payload)) {
|
|
577
|
+
throw new Error("missing JEV route decision");
|
|
578
|
+
}
|
|
579
|
+
let answer: Record<string, unknown> | undefined;
|
|
580
|
+
if (isRecord(payload.answers) && isRecord(payload.answers.route)) {
|
|
581
|
+
answer = payload.answers.route as Record<string, unknown>;
|
|
582
|
+
} else if (Array.isArray(payload.answers)) {
|
|
583
|
+
const routeAnswers = payload.answers.filter((a): a is Record<string, unknown> => isRecord(a) && a.name === "route");
|
|
584
|
+
if (routeAnswers.length === 1) {
|
|
585
|
+
answer = routeAnswers[0];
|
|
586
|
+
} else if (routeAnswers.length > 1) {
|
|
587
|
+
throw new Error("duplicate JEV route decision");
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
if (!answer) {
|
|
574
591
|
throw new Error("missing JEV route decision");
|
|
575
592
|
}
|
|
576
|
-
const answer = payload.answers.route;
|
|
577
593
|
const options = candidateOptions(candidates);
|
|
578
|
-
|
|
594
|
+
const choiceValue = typeof answer.choice === "string" ? answer.choice : (typeof answer.value === "string" ? answer.value : undefined);
|
|
595
|
+
if (!choiceValue || !options.has(choiceValue)) {
|
|
579
596
|
throw new Error("unknown JEV route choice");
|
|
580
597
|
}
|
|
581
598
|
|
|
582
599
|
let chosenProbability: number | undefined;
|
|
583
600
|
if (answer.probabilities !== undefined) {
|
|
584
|
-
|
|
585
|
-
if (
|
|
601
|
+
let probabilities: Record<string, unknown>;
|
|
602
|
+
if (Array.isArray(answer.probabilities)) {
|
|
603
|
+
probabilities = {};
|
|
604
|
+
for (const item of answer.probabilities) {
|
|
605
|
+
if (!isRecord(item)) throw new Error("invalid JEV route probabilities");
|
|
606
|
+
const k = typeof item.choice === "string" ? item.choice : (typeof item.value === "string" ? item.value : undefined);
|
|
607
|
+
if (!k) throw new Error("invalid JEV route probabilities");
|
|
608
|
+
if (Object.hasOwn(probabilities, k)) throw new Error("invalid JEV route probabilities");
|
|
609
|
+
probabilities[k] = item.probability;
|
|
610
|
+
}
|
|
611
|
+
} else if (isRecord(answer.probabilities)) {
|
|
612
|
+
probabilities = answer.probabilities as Record<string, unknown>;
|
|
613
|
+
} else {
|
|
614
|
+
throw new Error("invalid JEV route probabilities");
|
|
615
|
+
}
|
|
586
616
|
const expected = [...options.keys()].sort();
|
|
587
617
|
const actual = Object.keys(probabilities).sort();
|
|
588
618
|
if (expected.length !== actual.length || expected.some((key, index) => key !== actual[index])) {
|
|
@@ -593,7 +623,7 @@ export function parseJevDecision(
|
|
|
593
623
|
throw new Error("invalid JEV route probabilities");
|
|
594
624
|
}
|
|
595
625
|
const numeric = values as number[];
|
|
596
|
-
const selected = probabilities[
|
|
626
|
+
const selected = probabilities[choiceValue] as number;
|
|
597
627
|
if (Math.abs(numeric.reduce((sum, value) => sum + value, 0) - 1) > 0.02
|
|
598
628
|
|| selected < Math.max(...numeric) - 1e-6) {
|
|
599
629
|
throw new Error("inconsistent JEV route distribution");
|
|
@@ -601,7 +631,7 @@ export function parseJevDecision(
|
|
|
601
631
|
chosenProbability = selected;
|
|
602
632
|
}
|
|
603
633
|
|
|
604
|
-
const option = options.get(
|
|
634
|
+
const option = options.get(choiceValue)!;
|
|
605
635
|
const confidence = typeof answer.confidence === "number"
|
|
606
636
|
&& Number.isFinite(answer.confidence)
|
|
607
637
|
&& answer.confidence >= 0
|
|
@@ -634,6 +664,31 @@ export function fallbackDecision(
|
|
|
634
664
|
* Every operational or response failure returns the supplied first-eligible fallback. A caller
|
|
635
665
|
* abort is the exception: request cancellation remains cancellation and is rethrown by identity.
|
|
636
666
|
*/
|
|
667
|
+
function formatDecisionsInput(state: Record<string, unknown>): string {
|
|
668
|
+
const parts: string[] = [];
|
|
669
|
+
if (typeof state.task === "string" && state.task.trim()) {
|
|
670
|
+
parts.push(`Task: ${state.task.trim()}`);
|
|
671
|
+
}
|
|
672
|
+
if (isRecord(state.signals)) {
|
|
673
|
+
const sigs: string[] = [];
|
|
674
|
+
if (state.signals.has_image === true) sigs.push("has_image");
|
|
675
|
+
if (state.signals.tool_history === true) sigs.push("tool_history");
|
|
676
|
+
if (sigs.length > 0) parts.push(`Signals: ${sigs.join(", ")}`);
|
|
677
|
+
}
|
|
678
|
+
if (typeof state.previous_assistant === "string" && state.previous_assistant.trim()) {
|
|
679
|
+
parts.push(`Recent Assistant: ${state.previous_assistant.trim()}`);
|
|
680
|
+
}
|
|
681
|
+
if (isRecord(state.step) && state.step.type === "tool_step") {
|
|
682
|
+
const step = state.step;
|
|
683
|
+
const toolName = isRecord(step.tool_call) && typeof step.tool_call.name === "string" ? step.tool_call.name : "";
|
|
684
|
+
const toolOutput = typeof step.last_tool_output_tail === "string" ? step.last_tool_output_tail : "";
|
|
685
|
+
if (toolName || toolOutput) {
|
|
686
|
+
parts.push(`Recent Tool Call: ${toolName}\nTool Output: ${toolOutput}`.trim());
|
|
687
|
+
}
|
|
688
|
+
}
|
|
689
|
+
return parts.length > 0 ? parts.join("\n\n") : JSON.stringify(state);
|
|
690
|
+
}
|
|
691
|
+
|
|
637
692
|
export async function resolveJevDecision(options: ResolveJevDecisionOptions): Promise<JevDecision> {
|
|
638
693
|
const now = options.now ?? Date.now;
|
|
639
694
|
const startedAt = now();
|
|
@@ -647,15 +702,46 @@ export async function resolveJevDecision(options: ResolveJevDecisionOptions): Pr
|
|
|
647
702
|
|
|
648
703
|
let candidates = options.candidates;
|
|
649
704
|
const exchanged = await exchangeJevDecision(options, (endpoint) => {
|
|
650
|
-
|
|
705
|
+
const isDecisions = Boolean(endpoint.url && isDecisionsEndpoint(endpoint.url));
|
|
706
|
+
const optionCount = candidateOptions(options.candidates).size;
|
|
707
|
+
if (isDecisions) {
|
|
708
|
+
if (optionCount < DECISIONS_MIN_OPTIONS) return "no_choices";
|
|
709
|
+
if (optionCount > DECISIONS_MAX_OPTIONS) return "invalid";
|
|
710
|
+
} else if (endpoint.descriptiveCriteria) {
|
|
651
711
|
// Self-hosted choice questions accept 2..26 options; decide locally instead of spending a
|
|
652
712
|
// round-trip on a request the service will refuse.
|
|
653
|
-
const optionCount = candidateOptions(options.candidates).size;
|
|
654
713
|
if (optionCount < SELF_HOSTED_MIN_OPTIONS) return "no_choices";
|
|
655
714
|
if (optionCount > SELF_HOSTED_MAX_OPTIONS) return "invalid";
|
|
656
715
|
}
|
|
657
716
|
const state = buildJevState(options.body, options.candidates);
|
|
658
717
|
if (!hasJevDecisionState(state)) return "no_state";
|
|
718
|
+
if (isDecisions && endpoint.url) {
|
|
719
|
+
const payload = boundedJevQuotaPayload(jevQuotaCandidates(options), rows => {
|
|
720
|
+
const routeOptions = candidateOptions(rows);
|
|
721
|
+
return JSON.stringify({
|
|
722
|
+
model: endpoint.model,
|
|
723
|
+
input: formatDecisionsInput(state),
|
|
724
|
+
questions: [
|
|
725
|
+
{
|
|
726
|
+
name: "route",
|
|
727
|
+
type: "choice",
|
|
728
|
+
instructions: "Which target AND reasoning effort together best fit the next model call? Select sufficient capability and reasoning for a correct next step while avoiding unnecessary resource use.",
|
|
729
|
+
choices: [...routeOptions.entries()].map(([choice, opt]) => {
|
|
730
|
+
const cand = rows.find(r => r.key === opt.targetKey);
|
|
731
|
+
const desc = criterionDescription(opt.criterion, cand?.quota);
|
|
732
|
+
const note = cand?.modelProfile?.trim();
|
|
733
|
+
return {
|
|
734
|
+
value: choice,
|
|
735
|
+
description: note ? `${desc} (${note})` : desc,
|
|
736
|
+
};
|
|
737
|
+
}),
|
|
738
|
+
},
|
|
739
|
+
],
|
|
740
|
+
});
|
|
741
|
+
}, REQUEST_LIMIT);
|
|
742
|
+
candidates = payload.candidates;
|
|
743
|
+
return { body: payload.body };
|
|
744
|
+
}
|
|
659
745
|
const payload = boundedJevQuotaPayload(jevQuotaCandidates(options), rows => JSON.stringify({
|
|
660
746
|
model: endpoint.model, state,
|
|
661
747
|
questions: buildJevRouteQuestion(rows, { descriptiveCriteria: endpoint.descriptiveCriteria }),
|
package/src/combos/resolve.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { getCachedProviderRoutingQuota } from "../providers/quota-routing-cache"
|
|
|
3
3
|
import type { ProviderQuota, ProviderQuotaWindow } from "../providers/quota-types";
|
|
4
4
|
import { sleepWithAbort } from "../lib/upstream-retry";
|
|
5
5
|
import {
|
|
6
|
+
clearComboTargetCooldowns,
|
|
6
7
|
coolComboTarget,
|
|
7
8
|
earliestComboCooldown,
|
|
8
9
|
isComboTargetInCooldown,
|
|
@@ -26,6 +27,7 @@ export interface ComboPick {
|
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
interface SelectionState {
|
|
30
|
+
lastCooldownReprobeAt?: number;
|
|
29
31
|
activeKey?: string;
|
|
30
32
|
successes: number;
|
|
31
33
|
currentWeights: Map<string, number>;
|
|
@@ -286,12 +288,42 @@ function resetWindowIndex(
|
|
|
286
288
|
return selected;
|
|
287
289
|
}
|
|
288
290
|
|
|
291
|
+
/** Reserve one recovery pass before mutating cooldowns; preview and in-flight picks never call this. */
|
|
292
|
+
function reopenAllCooledTargets(
|
|
293
|
+
config: OcxConfig, comboId: string, now: number,
|
|
294
|
+
eligible?: (target: NormalizedComboTarget) => boolean,
|
|
295
|
+
): void {
|
|
296
|
+
const combo = getCombo(config, comboId);
|
|
297
|
+
if (!combo?.cooldownReprobe?.enabled) return;
|
|
298
|
+
const state = selectionState.get(comboId);
|
|
299
|
+
if (state?.lastCooldownReprobeAt !== undefined
|
|
300
|
+
&& now - state.lastCooldownReprobeAt < combo.cooldownReprobe.intervalMs) return;
|
|
301
|
+
const reprobeEligible = (target: NormalizedComboTarget): boolean => {
|
|
302
|
+
if (!targetProviderIsUsable(config, target, now)) return false;
|
|
303
|
+
try { return eligible?.(target) ?? true; } catch { return false; }
|
|
304
|
+
};
|
|
305
|
+
// Ordinary selection skips cooled targets without evaluating their request predicate.
|
|
306
|
+
// Preserve that behavior when a sibling is already available.
|
|
307
|
+
if (combo.targets.some(target => !isComboTargetInCooldown(comboId, target, now)
|
|
308
|
+
&& reprobeEligible(target))) return;
|
|
309
|
+
const usable = combo.targets.filter(reprobeEligible);
|
|
310
|
+
if (usable.length === 0 || !usable.every(target => isComboTargetInCooldown(comboId, target, now))) return;
|
|
311
|
+
// No await between reservation and reset: concurrent requests cannot reserve another pass.
|
|
312
|
+
const next = state ?? { successes: 0, currentWeights: new Map<string, number>(), successfulUses: new Map<string, number>() };
|
|
313
|
+
next.lastCooldownReprobeAt = now;
|
|
314
|
+
selectionState.set(comboId, next);
|
|
315
|
+
clearComboTargetCooldowns(comboId, usable.map(targetKey));
|
|
316
|
+
console.warn(`[combo] ${comboId}: reopening all-cooled targets; minimum reprobe interval ${combo.cooldownReprobe.intervalMs}ms`);
|
|
317
|
+
}
|
|
318
|
+
|
|
289
319
|
export function pickComboTarget(
|
|
290
320
|
config: OcxConfig,
|
|
291
321
|
comboId: string,
|
|
292
322
|
options: {
|
|
293
323
|
exclude?: Iterable<string>;
|
|
294
324
|
eligible?: (target: NormalizedComboTarget) => boolean;
|
|
325
|
+
/** Disable recovery for picks without request context or picks already in flight. */
|
|
326
|
+
allowCooldownReprobe?: boolean;
|
|
295
327
|
now?: number;
|
|
296
328
|
/** Inspect a round-robin choice without mutating its sticky/weight state. */
|
|
297
329
|
preview?: boolean;
|
|
@@ -302,6 +334,9 @@ export function pickComboTarget(
|
|
|
302
334
|
if (!combo) throw new UnknownComboError(comboId);
|
|
303
335
|
const excluded = new Set(options.exclude ?? []);
|
|
304
336
|
const now = options.now ?? Date.now();
|
|
337
|
+
if (options.allowCooldownReprobe !== false && !options.preview && excluded.size === 0) {
|
|
338
|
+
reopenAllCooledTargets(config, comboId, now, options.eligible);
|
|
339
|
+
}
|
|
305
340
|
const eligible = (target: NormalizedComboTarget): boolean =>
|
|
306
341
|
targetProviderIsUsable(config, target, now)
|
|
307
342
|
&& !isComboTargetInCooldown(comboId, target, now)
|
|
@@ -498,6 +533,8 @@ export async function pickComboTargetWithWait(
|
|
|
498
533
|
eligible?: (target: NormalizedComboTarget) => boolean;
|
|
499
534
|
waitForCooldownMs: number;
|
|
500
535
|
abortSignal?: AbortSignal;
|
|
536
|
+
/** Disable recovery when retrying a target after its normal cooldown. */
|
|
537
|
+
allowCooldownReprobe?: boolean;
|
|
501
538
|
now?: number;
|
|
502
539
|
sleep?: (ms: number, signal?: AbortSignal) => Promise<void>;
|
|
503
540
|
},
|
|
@@ -505,6 +542,9 @@ export async function pickComboTargetWithWait(
|
|
|
505
542
|
const now = options.now ?? Date.now();
|
|
506
543
|
const excluded = new Set(options.exclude ?? []);
|
|
507
544
|
const customEligible = options.eligible;
|
|
545
|
+
if (options.allowCooldownReprobe !== false && excluded.size === 0 && !options.abortSignal?.aborted) {
|
|
546
|
+
reopenAllCooledTargets(config, comboId, now, customEligible);
|
|
547
|
+
}
|
|
508
548
|
const eligibleAt = (target: NormalizedComboTarget, at: number): boolean =>
|
|
509
549
|
!isComboTargetInCooldown(comboId, target, at)
|
|
510
550
|
&& (customEligible?.(target) ?? true);
|
|
@@ -529,6 +569,7 @@ export async function pickComboTargetWithWait(
|
|
|
529
569
|
const normalOnly = (target: NormalizedComboTarget): boolean =>
|
|
530
570
|
!target.lastResort && eligible(target);
|
|
531
571
|
const normalPick = pickComboTarget(config, comboId, {
|
|
572
|
+
allowCooldownReprobe: false,
|
|
532
573
|
exclude: excluded,
|
|
533
574
|
eligible: normalOnly,
|
|
534
575
|
now,
|
|
@@ -559,6 +600,7 @@ export async function pickComboTargetWithWait(
|
|
|
559
600
|
// The combo can be deleted or renamed while this request sleeps.
|
|
560
601
|
if (!getCombo(config, comboId)) return null;
|
|
561
602
|
const waited = pickComboTarget(config, comboId, {
|
|
603
|
+
allowCooldownReprobe: false,
|
|
562
604
|
exclude: excluded,
|
|
563
605
|
now: now + normalDelay,
|
|
564
606
|
eligible: target => !target.lastResort
|
|
@@ -576,6 +618,7 @@ export async function pickComboTargetWithWait(
|
|
|
576
618
|
const remainingWaitMs = options.waitForCooldownMs - spentWaitMs;
|
|
577
619
|
|
|
578
620
|
const pick = pickComboTarget(config, comboId, {
|
|
621
|
+
allowCooldownReprobe: false,
|
|
579
622
|
exclude: excluded,
|
|
580
623
|
eligible: target => eligibleAt(target, clock),
|
|
581
624
|
now: clock,
|
|
@@ -610,6 +653,7 @@ export async function pickComboTargetWithWait(
|
|
|
610
653
|
if (!getCombo(config, comboId)) return null;
|
|
611
654
|
return pickComboTarget(config, comboId, {
|
|
612
655
|
exclude: excluded,
|
|
656
|
+
allowCooldownReprobe: false,
|
|
613
657
|
now: clock + delay,
|
|
614
658
|
eligible: targetCandidate => eligibleAt(targetCandidate, clock + delay),
|
|
615
659
|
});
|
|
@@ -659,7 +703,7 @@ export function tryPickComboModel(config: OcxConfig, modelId: string, preview =
|
|
|
659
703
|
const comboId = resolveComboId(config, modelId);
|
|
660
704
|
if (!comboId) return null;
|
|
661
705
|
if (!getCombo(config, comboId)) throw new UnknownComboError(comboId);
|
|
662
|
-
const picked = pickComboTarget(config, comboId, { preview });
|
|
706
|
+
const picked = pickComboTarget(config, comboId, { preview, allowCooldownReprobe: false });
|
|
663
707
|
if (!picked) throw new NoAvailableComboTargetsError(comboId, comboExclusionReasons(config, comboId));
|
|
664
708
|
return picked;
|
|
665
709
|
}
|
package/src/combos/types.ts
CHANGED
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
} from "./jev-decision-contract";
|
|
18
18
|
|
|
19
19
|
export const COMBO_DEFAULT_WAIT_FOR_COOLDOWN_MS = 0;
|
|
20
|
+
export const COMBO_DEFAULT_COOLDOWN_REPROBE_INTERVAL_MS = 300_000;
|
|
20
21
|
export const JEV_MAX_CANDIDATE_FIELD_CHARS = 512;
|
|
21
22
|
export {
|
|
22
23
|
JEV_DECISION_TIMEOUT_DEFAULT_MS,
|
|
@@ -60,6 +61,7 @@ export interface NormalizedComboConfig {
|
|
|
60
61
|
stickyLimit: number;
|
|
61
62
|
cooldownMs?: number;
|
|
62
63
|
waitForCooldownMs: number;
|
|
64
|
+
cooldownReprobe?: { enabled: true; intervalMs: number };
|
|
63
65
|
/** `before-last-resort` defers lastResort targets while a normal one can be waited out (#5691). */
|
|
64
66
|
cooldownWaitPolicy: OcxComboCooldownWaitPolicy | null;
|
|
65
67
|
defaultEffort: OcxComboDefaultEffort | null;
|
|
@@ -222,6 +224,24 @@ export function comboConfigIssues(
|
|
|
222
224
|
|| body.waitForCooldownMs > 600_000)) {
|
|
223
225
|
issues.push({ path: ["waitForCooldownMs"], message: "waitForCooldownMs must be an integer from 0 to 600000" });
|
|
224
226
|
}
|
|
227
|
+
if (body.cooldownReprobe !== undefined) {
|
|
228
|
+
const value = body.cooldownReprobe;
|
|
229
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
230
|
+
issues.push({ path: ["cooldownReprobe"], message: "cooldownReprobe must be an object" });
|
|
231
|
+
} else {
|
|
232
|
+
const reprobe = value as Record<string, unknown>;
|
|
233
|
+
if (typeof reprobe.enabled !== "boolean") {
|
|
234
|
+
issues.push({ path: ["cooldownReprobe", "enabled"], message: "cooldownReprobe.enabled must be a boolean" });
|
|
235
|
+
}
|
|
236
|
+
if (reprobe.intervalMs !== undefined && (typeof reprobe.intervalMs !== "number"
|
|
237
|
+
|| !Number.isSafeInteger(reprobe.intervalMs) || reprobe.intervalMs < 1000 || reprobe.intervalMs > 86_400_000)) {
|
|
238
|
+
issues.push({ path: ["cooldownReprobe", "intervalMs"], message: "cooldownReprobe.intervalMs must be an integer from 1000 to 86400000" });
|
|
239
|
+
}
|
|
240
|
+
if (Object.keys(reprobe).some(key => key !== "enabled" && key !== "intervalMs")) {
|
|
241
|
+
issues.push({ path: ["cooldownReprobe"], message: "cooldownReprobe supports only enabled and intervalMs" });
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
225
245
|
if (body.cooldownWaitPolicy !== undefined && body.cooldownWaitPolicy !== null
|
|
226
246
|
&& body.cooldownWaitPolicy !== "before-last-resort") {
|
|
227
247
|
issues.push({
|
|
@@ -535,6 +555,10 @@ export function normalizeComboConfig(raw: OcxComboConfig): NormalizedComboConfig
|
|
|
535
555
|
...(raw.allowMeteredTargets === true ? { allowMeteredTargets: true } : {}),
|
|
536
556
|
stickyLimit: raw.stickyLimit ?? 1,
|
|
537
557
|
cooldownMs: raw.cooldownMs,
|
|
558
|
+
...(raw.cooldownReprobe?.enabled === true ? { cooldownReprobe: {
|
|
559
|
+
enabled: true as const,
|
|
560
|
+
intervalMs: raw.cooldownReprobe.intervalMs ?? COMBO_DEFAULT_COOLDOWN_REPROBE_INTERVAL_MS,
|
|
561
|
+
} } : {}),
|
|
538
562
|
waitForCooldownMs: raw.waitForCooldownMs ?? COMBO_DEFAULT_WAIT_FOR_COOLDOWN_MS,
|
|
539
563
|
cooldownWaitPolicy: raw.cooldownWaitPolicy === "before-last-resort" ? "before-last-resort" : null,
|
|
540
564
|
defaultEffort,
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
autoReviewModelOverridesConfigError,
|
|
17
17
|
autoReviewModelTargetConfigError,
|
|
18
18
|
modelCapabilitiesConfigError,
|
|
19
|
+
providerInputModalitiesConfigError,
|
|
19
20
|
sanitizeModelCapabilitiesForLoad,
|
|
20
21
|
modelDisplayNamesConfigError,
|
|
21
22
|
} from "./provider-validation";
|
|
@@ -359,6 +360,10 @@ export function sanitizeCapabilityDeclarationsForLoad(parsed: unknown): void {
|
|
|
359
360
|
for (const [name, value] of Object.entries(providers)) {
|
|
360
361
|
if (!value || typeof value !== "object" || Array.isArray(value)) continue;
|
|
361
362
|
const provider = value as Record<string, unknown>;
|
|
363
|
+
if (providerInputModalitiesConfigError(provider.inputModalities) !== null) {
|
|
364
|
+
console.warn(`config.json provider ${JSON.stringify(redactSecretString(name))} has malformed inputModalities; restricting input modalities to text`);
|
|
365
|
+
provider.inputModalities = ["text"];
|
|
366
|
+
}
|
|
362
367
|
if (provider.modelCapabilities === undefined) continue;
|
|
363
368
|
if (modelCapabilitiesConfigError(provider.modelCapabilities) !== null) {
|
|
364
369
|
console.warn(`config.json provider ${JSON.stringify(redactSecretString(name))} has malformed modelCapabilities; retaining valid axes and restricting malformed input modalities to text`);
|
package/src/config/paths.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { chmodSync,
|
|
1
|
+
import { chmodSync, statSync } from "node:fs";
|
|
2
2
|
import { homedir } from "node:os";
|
|
3
3
|
import { join, resolve } from "node:path";
|
|
4
|
-
import { flushWindowsSecretAclReapsBeforeRemoval, hardenSecretDirAsync, windowsSecretAclApplies } from "../lib/windows-secret-acl";
|
|
4
|
+
import { flushWindowsSecretAclReapsBeforeRemoval, hardenSecretDirAsync, windowsSecretAclApplies, withWindowsSecretAclSettled } from "../lib/windows-secret-acl";
|
|
5
5
|
import { assertNotRealHomeUnderTest } from "../lib/test-home-guard";
|
|
6
6
|
import { isPassiveRead } from "../lib/passive-read";
|
|
7
7
|
import { trackBackgroundWork } from "../lib/background-work";
|
|
@@ -37,7 +37,8 @@ export function hardenConfigDir(): void {
|
|
|
37
37
|
// The guard runs before any mutation: refusing after chmod/ACL would already
|
|
38
38
|
// have changed the protected directory used by the test-home boundary.
|
|
39
39
|
assertNotRealHomeUnderTest(dir);
|
|
40
|
-
|
|
40
|
+
// Follow directory links as before, but never apply directory permissions to a file.
|
|
41
|
+
try { if (!statSync(dir).isDirectory()) return; } catch { return; }
|
|
41
42
|
// Windows privacy is enforced by NTFS ACLs. chmod only changes DOS attributes there;
|
|
42
43
|
// doing it before the ACL lookup can invalidate its ctime-based successful observation.
|
|
43
44
|
if (!windowsSecretAclApplies()) {
|
|
@@ -73,6 +74,21 @@ export async function flushConfigDirHardening(dir: string = getConfigDir()): Pro
|
|
|
73
74
|
if (flight) await flight;
|
|
74
75
|
}
|
|
75
76
|
|
|
77
|
+
/**
|
|
78
|
+
* Intercept CA/token/picker writers call this after their last unrelated await. Parent
|
|
79
|
+
* inheritable ACL propagation can overwrite a child's concurrent explicit grant. Drain the
|
|
80
|
+
* registered config flight and overlapping work (including ancestors and timeout reaps),
|
|
81
|
+
* within one ACL deadline. Timeout refuses admission without dropping child cleanup ownership.
|
|
82
|
+
* The final registry check and synchronous callback share a turn: promise continuations and
|
|
83
|
+
* newly queued hardeners cannot start icacls between that check and secret publication.
|
|
84
|
+
* Keep the callback synchronous; an await inside it would reopen the propagation race.
|
|
85
|
+
*/
|
|
86
|
+
export async function withConfigDirHardeningSettled<T>(dir: string, mutate: () => T): Promise<T> {
|
|
87
|
+
// Async work registers before its factory starts, including the optional config flight.
|
|
88
|
+
// A separate flush here would escape the registry's total admission deadline.
|
|
89
|
+
return withWindowsSecretAclSettled(dir, mutate);
|
|
90
|
+
}
|
|
91
|
+
|
|
76
92
|
/** A settled ACL deadline is not proof its child has exited; stop must drain both before removal. */
|
|
77
93
|
export async function flushConfigDirHardeningAndReaps(dir: string): Promise<void> {
|
|
78
94
|
try { await flushConfigDirHardening(dir); }
|
|
@@ -54,6 +54,15 @@ export type PendingTeardownReceipt = {
|
|
|
54
54
|
* guessed receipt therefore fails closed into manual recovery.
|
|
55
55
|
*/
|
|
56
56
|
endpointSource: "exact" | "guessed";
|
|
57
|
+
/**
|
|
58
|
+
* Set when the stop handed its teardown to a replacement proxy instead of performing it
|
|
59
|
+
* (#7423). An update that is about to restart the proxy keeps Codex routing and the
|
|
60
|
+
* routed catalog in place across the gap, so a Codex process that loads them while the
|
|
61
|
+
* package is replaced still sees the routed rows. The obligation is the same one: the
|
|
62
|
+
* replacement discharges it after its first successful publication, and if no
|
|
63
|
+
* replacement ever comes up, the next `ocx stop` finishes it like any abandoned receipt.
|
|
64
|
+
*/
|
|
65
|
+
handover?: "update-restart";
|
|
57
66
|
};
|
|
58
67
|
|
|
59
68
|
/**
|
|
@@ -111,6 +120,7 @@ function isReceipt(value: unknown, nonce: string): value is PendingTeardownRecei
|
|
|
111
120
|
&& receipt.nonce === nonce
|
|
112
121
|
&& typeof receipt.createdAt === "string"
|
|
113
122
|
&& (receipt.endpointSource === "exact" || receipt.endpointSource === "guessed")
|
|
123
|
+
&& (receipt.handover === undefined || receipt.handover === "update-restart")
|
|
114
124
|
&& endpointOk;
|
|
115
125
|
}
|
|
116
126
|
|
|
@@ -119,11 +129,15 @@ export function claimPendingTeardown(
|
|
|
119
129
|
endpoint: { hostname: string; port: number },
|
|
120
130
|
endpointSource: "exact" | "guessed",
|
|
121
131
|
ownerPid: number = process.pid,
|
|
132
|
+
handover?: "update-restart",
|
|
122
133
|
): PendingTeardownReceipt {
|
|
123
134
|
const dir = getConfigDir();
|
|
124
135
|
assertNotRealHomeUnderTest(dir);
|
|
125
136
|
const nonce = randomBytes(16).toString("hex");
|
|
126
|
-
const receipt: PendingTeardownReceipt = {
|
|
137
|
+
const receipt: PendingTeardownReceipt = {
|
|
138
|
+
ownerPid, nonce, createdAt: new Date().toISOString(), endpoint, endpointSource,
|
|
139
|
+
...(handover ? { handover } : {}),
|
|
140
|
+
};
|
|
127
141
|
atomicWriteFile(pendingTeardownPathFor(nonce), JSON.stringify(receipt, null, 2) + "\n");
|
|
128
142
|
return receipt;
|
|
129
143
|
}
|
|
@@ -323,3 +337,10 @@ export function deferralMatchesReceipt(nonce: string | null): boolean {
|
|
|
323
337
|
if (!nonce || !NONCE_RE.test(nonce)) return false;
|
|
324
338
|
return readPendingTeardown(nonce).state === "valid";
|
|
325
339
|
}
|
|
340
|
+
|
|
341
|
+
/** Does this request name a valid obligation that an update handed to its replacement (#7423)? */
|
|
342
|
+
export function isUpdateHandoverReceipt(nonce: string | null): boolean {
|
|
343
|
+
if (!nonce || !NONCE_RE.test(nonce)) return false;
|
|
344
|
+
const read = readPendingTeardown(nonce);
|
|
345
|
+
return read.state === "valid" && read.receipt.handover === "update-restart";
|
|
346
|
+
}
|