@bitkyc08/opencodex 2.95.0 → 2.97.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 +214 -19
- package/gui/dist/assets/{App-8yedBkhm.js → App-DuNhggE1.js} +18 -18
- package/gui/dist/assets/{Tray-erSMzxPG.js → Tray-CEw0y0jR.js} +1 -1
- package/gui/dist/assets/index-CynE_Rue.js +94 -0
- package/gui/dist/assets/{quota-summary-BK4VuQNc.js → quota-summary-VHFSlUuM.js} +1 -1
- package/gui/dist/index.html +1 -1
- package/package.json +1 -1
- package/src/adapters/command-code.ts +15 -16
- package/src/adapters/cursor/transport-retry.ts +2 -2
- package/src/adapters/devin/cloud-direct/chat.ts +15 -6
- package/src/adapters/kiro/stream.ts +63 -4
- package/src/adapters/kiro-constants.ts +15 -1
- package/src/adapters/kiro-events.ts +31 -1
- package/src/adapters/kiro-retry.ts +3 -3
- package/src/adapters/ollama-native.ts +21 -7
- package/src/adapters/openai-responses/canonical-forward.ts +50 -13
- package/src/adapters/openai-responses/empty-assistant.ts +15 -3
- package/src/adapters/openai-responses/passthrough.ts +8 -8
- package/src/adapters/openai-responses/reasoning.ts +9 -4
- package/src/adapters/openai-responses/request-strips.ts +1 -1
- package/src/adapters/openai-responses/transport.ts +17 -26
- package/src/adapters/physical-send.ts +3 -3
- package/src/adapters/qoder/adapter.ts +1 -1
- package/src/adapters/qoder/image-input.ts +5 -2
- package/src/adapters/zed-openai-stream.ts +2 -1
- package/src/bridge/errors.ts +11 -2
- package/src/bridge/response-json.ts +2 -1
- package/src/bridge/sse.ts +14 -6
- package/src/chat/failure-verdict.ts +21 -0
- package/src/chat/outbound.ts +139 -21
- package/src/claude/outbound.ts +49 -2
- package/src/cli/agent.ts +44 -15
- package/src/cli/capabilities-agents-routing.ts +9 -0
- package/src/cli/capabilities-base.ts +25 -3
- package/src/cli/capabilities-command.ts +12 -3
- package/src/cli/capability-contracts.ts +2 -0
- package/src/cli/codex-launch-auth.ts +30 -1
- package/src/cli/codex-launcher.ts +12 -5
- package/src/cli/codex-shim-autorestore.ts +5 -4
- package/src/cli/dispatch.ts +11 -176
- package/src/cli/ensure-desired-integrations.ts +4 -3
- package/src/cli/help.ts +2 -2
- package/src/cli/index.ts +9 -2
- package/src/cli/link.ts +1 -1
- package/src/cli/message-command.ts +2 -1
- package/src/cli/message-mcp-command.ts +29 -0
- package/src/cli/registry.ts +12 -4
- package/src/cli/root.ts +8 -0
- package/src/cli/sync-command.ts +243 -0
- package/src/cli/sync-fanout-process.ts +92 -0
- package/src/cli/sync-fanout.ts +150 -0
- package/src/cli/sync-flags.ts +10 -0
- package/src/cli/sync-link-status.ts +39 -0
- package/src/cli/sync-update-guard.ts +18 -0
- package/src/client/connect.ts +31 -14
- package/src/client/link-home.ts +3 -2
- package/src/client/machine-listener.ts +3 -0
- package/src/client/restore-ownership.ts +19 -1
- package/src/client/runtime-restart.ts +12 -4
- package/src/client/runtime.ts +40 -11
- package/src/client/stop-routing.ts +62 -0
- package/src/client/sync-runtime.ts +65 -0
- package/src/clients/config-export.ts +32 -3
- package/src/codex/account-store.ts +1 -0
- package/src/codex/auth-context-provider.ts +15 -0
- package/src/codex/auth-context.ts +59 -122
- package/src/codex/catalog/antigravity-discovery.ts +16 -5
- package/src/codex/catalog/provider-models.ts +6 -8
- package/src/codex/forward-transport-headers.ts +65 -36
- package/src/codex/inject/config-toml.ts +88 -0
- package/src/codex/inject/multi-agent-v2.ts +30 -4
- package/src/codex/inject/plan.ts +34 -7
- package/src/codex/inject-coordination.ts +11 -0
- package/src/codex/inject.ts +18 -7
- package/src/codex/installation-id.ts +72 -0
- package/src/codex/lineage.ts +13 -7
- package/src/codex/quota.ts +22 -6
- package/src/codex/request-owned-affinity-key.ts +11 -0
- package/src/codex/request-owned-affinity.ts +118 -0
- package/src/codex/request-owned-main-pin.ts +86 -0
- package/src/codex/role-capability.ts +52 -41
- package/src/codex/routing/active-account.ts +13 -5
- package/src/codex/routing/selection.ts +40 -1
- package/src/codex/routing/thread-affinity-store.ts +916 -0
- package/src/codex/routing/thread-affinity.ts +90 -12
- package/src/codex/toml-source-lines.ts +72 -13
- package/src/combos/failover.ts +6 -109
- package/src/combos/request.ts +2 -2
- package/src/combos/resolve.ts +29 -11
- package/src/config/process-state.ts +5 -0
- package/src/config/schema/leaf-validators.ts +1 -0
- package/src/generated/compatibility-version.json +496 -192
- package/src/grok/sync.ts +10 -1
- package/src/images/loop.ts +2 -1
- package/src/lib/client-error-body.ts +184 -0
- package/src/lib/client-retry-after.ts +66 -0
- package/src/lib/config-ownership.ts +4 -0
- package/src/lib/context-overflow-verdict.ts +113 -0
- package/src/lib/desktop-cli-handoff.d.mts +1 -1
- package/src/lib/desktop-cli-handoff.mjs +11 -1
- package/src/lib/empty-tool-catalog.ts +25 -3
- package/src/lib/error-destination.ts +47 -0
- package/src/lib/failure-detail.ts +66 -0
- package/src/lib/model-identity.ts +44 -0
- package/src/lib/private-sqlite-path.ts +124 -0
- package/src/lib/response-service-tier.ts +17 -0
- package/src/lib/retry-after.ts +3 -0
- package/src/lib/spend-ledger-owner.ts +43 -4
- package/src/lib/upstream-condition.ts +142 -0
- package/src/lib/upstream-retry.ts +14 -11
- package/src/lib/windows-owner-acl.ts +13 -6
- package/src/lib/windows-secret-acl.ts +2 -2
- package/src/link/remote-platform.ts +14 -0
- package/src/link/remote-windows.ts +51 -9
- package/src/link/ssh-argv.ts +63 -10
- package/src/messaging/mcp-queue-rpc.ts +102 -0
- package/src/messaging/mcp-queue-server.ts +42 -0
- package/src/messaging/mcp-queue-tools.ts +39 -0
- package/src/oauth/anthropic-identity.ts +2 -6
- package/src/oauth/generic-account-failover.ts +13 -11
- package/src/oauth/index.ts +41 -74
- package/src/oauth/oauth-errors.ts +67 -0
- package/src/oauth/store.ts +1 -1
- package/src/protocols/codecs/ollama.ts +197 -0
- package/src/protocols/encoders/adapter-events.ts +4 -0
- package/src/protocols/encoders/chat.ts +18 -10
- package/src/protocols/trace.ts +18 -0
- package/src/providers/anthropic-subscription.ts +25 -0
- package/src/providers/claude-cli-usage.ts +15 -67
- package/src/providers/fastwire.ts +3 -2
- package/src/providers/quota/anthropic-decision-windows.ts +5 -19
- package/src/providers/quota/anthropic-usage-windows.ts +65 -0
- package/src/providers/quota/vendor-probes-key.ts +60 -24
- package/src/providers/request-pacing.ts +3 -2
- package/src/responses/apply-patch-envelope.ts +45 -19
- package/src/responses/compaction-history-framing.ts +5 -1
- package/src/responses/freeform-wrapper-scan.ts +5 -3
- package/src/responses/parser-tools.ts +1 -0
- package/src/responses/progressive-freeform-input.ts +354 -45
- package/src/responses/schema.ts +5 -2
- package/src/routing/fallback-policy.ts +3 -1
- package/src/server/admission-model-scope.ts +17 -6
- package/src/server/admitted-http-turn.ts +56 -0
- package/src/server/audio-dictation.ts +3 -0
- package/src/server/audio-live.ts +8 -2
- package/src/server/audio-upstream.ts +2 -0
- package/src/server/auth-cors.ts +5 -0
- package/src/server/chat-completions.ts +45 -20
- package/src/server/chat-native-sse.ts +52 -7
- package/src/server/chat-native.ts +60 -35
- package/src/server/claude-bridge-pool-session.ts +59 -0
- package/src/server/claude-messages.ts +57 -27
- package/src/server/context-history.ts +14 -7
- package/src/server/images.ts +14 -5
- package/src/server/inbound-body-admission.ts +11 -4
- package/src/server/index/live-sideband.ts +16 -2
- package/src/server/index/ollama-routes.ts +89 -0
- package/src/server/index/serve-options.ts +22 -4
- package/src/server/index/websocket-handler.ts +5 -3
- package/src/server/index.ts +6 -36
- package/src/server/inference/client-encoder-delivery.ts +4 -2
- package/src/server/json-serialized-bytes.ts +44 -0
- package/src/server/live.ts +30 -5
- package/src/server/management/agent-settings-routes.ts +24 -21
- package/src/server/management/codex-cli-update-routes.ts +2 -1
- package/src/server/management/route-registry.ts +1 -1
- package/src/server/messages-native-scope.ts +2 -1
- package/src/server/messages-native-tool-guard.ts +1 -1
- package/src/server/messages-native.ts +12 -7
- package/src/server/messages-shared.ts +6 -2
- package/src/server/native-final-log.ts +93 -0
- package/src/server/ollama-inbound.ts +349 -0
- package/src/server/ollama-native-paths.ts +21 -0
- package/src/server/ollama-route-policy.ts +73 -0
- package/src/server/relay.ts +22 -3
- package/src/server/request-decompress.ts +4 -2
- package/src/server/request-log-failure-attribution.ts +22 -0
- package/src/server/request-log-failure-detail.ts +80 -0
- package/src/server/request-log-terminal-status.ts +4 -2
- package/src/server/request-log.ts +79 -42
- package/src/server/response-log-body.ts +6 -1
- package/src/server/responses/account-change-state.ts +17 -6
- package/src/server/responses/adapter-continuation.ts +9 -4
- package/src/server/responses/adapter-delivery.ts +5 -4
- package/src/server/responses/adapter-dispatch.ts +36 -30
- package/src/server/responses/anthropic-thinking-recovery.ts +3 -0
- package/src/server/responses/codex-auth-error.ts +22 -17
- package/src/server/responses/codex-ws-exchange.ts +11 -8
- package/src/server/responses/codex-ws-metadata.ts +94 -21
- package/src/server/responses/codex-ws-request.ts +3 -1
- package/src/server/responses/combo-required-tool-contract.ts +24 -12
- package/src/server/responses/compact.ts +89 -41
- package/src/server/responses/compaction-recovery.ts +4 -2
- package/src/server/responses/compaction-routing.ts +9 -4
- package/src/server/responses/core-auth.ts +32 -14
- package/src/server/responses/core-codex-account.ts +34 -12
- package/src/server/responses/core-combo-failure.ts +5 -1
- package/src/server/responses/core-combo-native.ts +2 -1
- package/src/server/responses/core-combo.ts +51 -33
- package/src/server/responses/core-errors.ts +22 -20
- package/src/server/responses/core-lifetime.ts +6 -3
- package/src/server/responses/core-normalize.ts +8 -1
- package/src/server/responses/core-options.ts +7 -0
- package/src/server/responses/core-pipeline.ts +4 -3
- package/src/server/responses/fetch-helpers.ts +7 -1
- package/src/server/responses/input-admission.ts +28 -2
- package/src/server/responses/native-injection.ts +1 -1
- package/src/server/responses/native-response-json.ts +13 -4
- package/src/server/responses/native-response-output.ts +1 -2
- package/src/server/responses/non-replayable-error.ts +2 -1
- package/src/server/responses/pacing-overload.ts +3 -2
- package/src/server/responses/passthrough-build-error.ts +36 -0
- package/src/server/responses/passthrough-delivery.ts +55 -14
- package/src/server/responses/passthrough-dispatch.ts +26 -39
- package/src/server/responses/passthrough-error.ts +9 -9
- package/src/server/responses/policy-fallback.ts +2 -1
- package/src/server/responses/request-prepare.ts +67 -48
- package/src/server/responses/request-sidecar-auth.ts +3 -1
- package/src/server/responses/request-transport.ts +35 -31
- package/src/server/responses/run-turn-execution.ts +6 -6
- package/src/server/responses/sidecar-execution.ts +16 -12
- package/src/server/responses/spend-storage-error.ts +2 -1
- package/src/server/responses/ws-upstream.ts +9 -0
- package/src/server/responses-custom-tool-repair.ts +14 -3
- package/src/server/responses-terminal-repair.ts +5 -2
- package/src/server/responses-undeclared-tool-guard.ts +39 -16
- package/src/server/safe-response-headers.ts +162 -13
- package/src/server/search.ts +13 -4
- package/src/server/turn-state-handles.ts +164 -0
- package/src/server/workflow-refusal.ts +2 -1
- package/src/server/ws-bridge.ts +5 -2
- package/src/service/ownership-mutation-lease.d.mts +11 -2
- package/src/service/ownership-mutation-lease.mjs +53 -11
- package/src/types/config.ts +2 -0
- package/src/update/index.ts +133 -25
- package/src/update/npm-install.d.mts +8 -0
- package/src/update/npm-install.mjs +20 -1
- package/src/update/orchestrated-admission.d.mts +4 -0
- package/src/update/orchestrated-admission.mjs +12 -0
- package/src/update/orchestrated-arguments.d.mts +12 -0
- package/src/update/orchestrated-arguments.mjs +64 -0
- package/src/update/orchestrated-child.d.mts +12 -0
- package/src/update/orchestrated-child.mjs +70 -0
- package/src/update/orchestrated-entry.ts +234 -0
- package/src/update/orchestrated-identity-probe-entry.ts +20 -0
- package/src/update/orchestrated-identity.ts +53 -0
- package/src/update/orchestrated-live-identity.ts +48 -0
- package/src/update/orchestrated-node-driver.mjs +99 -0
- package/src/update/orchestrated-outcome.d.mts +21 -0
- package/src/update/orchestrated-outcome.mjs +40 -0
- package/src/update/orchestrated-plan.ts +49 -0
- package/src/update/orchestrated-pnpm.d.mts +8 -0
- package/src/update/orchestrated-pnpm.mjs +33 -0
- package/src/update/orchestrated-session.d.mts +37 -0
- package/src/update/orchestrated-session.mjs +264 -0
- package/src/update/orchestrated-token.d.mts +10 -0
- package/src/update/orchestrated-token.mjs +21 -0
- package/src/update/orchestrated-token.ts +3 -0
- package/src/update/orchestrated-tree.d.mts +1 -0
- package/src/update/orchestrated-tree.mjs +14 -0
- package/src/update/pnpm-global-install.d.mts +6 -0
- package/src/update/pnpm-global-install.mjs +9 -2
- package/src/update/posix-install-supervisor-entry.mjs +6 -0
- package/src/update/posix-install-supervisor.d.mts +10 -0
- package/src/update/posix-install-supervisor.mjs +88 -0
- package/src/update/sync-update-mutex.d.mts +10 -0
- package/src/update/sync-update-mutex.mjs +164 -0
- package/src/update/sync-update-mutex.ts +1 -0
- package/src/update/test-home-guard.mjs +33 -0
- package/src/update/transactional-install.mjs +2 -2
- package/src/usage/error-detail.ts +225 -0
- package/src/usage/log.ts +60 -27
- package/src/vision/describe.ts +4 -7
- package/src/web-search/executor.ts +4 -7
- package/src/web-search/loop.ts +31 -5
- package/gui/dist/assets/index-D7DCm5eQ.js +0 -94
package/src/server/live.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CodexInstallationIdUnavailableError } from "../codex/installation-id";
|
|
2
|
+
import { isolateCodexPoolClientMetadata, mergeCodexSelectedHeaders } from "../codex/forward-transport-headers";
|
|
1
3
|
import { codexCompatibleUrl } from "../codex/context-compat";
|
|
2
4
|
/**
|
|
3
5
|
* /v1/live and /v1/realtime/calls relay (issue #371).
|
|
@@ -38,6 +40,7 @@ import {
|
|
|
38
40
|
CodexModelAvailabilityError,
|
|
39
41
|
CodexPoolAuthenticationError,
|
|
40
42
|
CodexThreadAffinityExpiredError,
|
|
43
|
+
type CodexAuthContext,
|
|
41
44
|
} from "../codex/auth-context";
|
|
42
45
|
import { formatCodexProviderForLog } from "../codex/routing";
|
|
43
46
|
import { cancelBodyOnAbort, signalWithTimeout } from "../lib/abort";
|
|
@@ -315,10 +318,12 @@ export type LiveSidebandTarget =
|
|
|
315
318
|
|
|
316
319
|
export type LiveRelayTarget = {
|
|
317
320
|
headers: Record<string, string>;
|
|
321
|
+
authContext?: CodexAuthContext;
|
|
318
322
|
providerBaseUrl: string;
|
|
319
323
|
usesBackendShape: boolean;
|
|
320
324
|
keyed: boolean;
|
|
321
325
|
recordOutcome?: (status: number | "timeout" | "connect_error") => void;
|
|
326
|
+
releaseProbeLease?: () => void;
|
|
322
327
|
};
|
|
323
328
|
|
|
324
329
|
function isChatGptBackendBaseUrl(baseUrl: string): boolean {
|
|
@@ -723,7 +728,9 @@ export async function resolveLiveRelay(
|
|
|
723
728
|
);
|
|
724
729
|
}
|
|
725
730
|
} catch (err) {
|
|
726
|
-
if (err instanceof
|
|
731
|
+
if (err instanceof CodexInstallationIdUnavailableError) {
|
|
732
|
+
forwardAuthError = formatErrorResponse(503, "server_busy", err.message);
|
|
733
|
+
} else if (err instanceof CodexAccountCooldownError) {
|
|
727
734
|
forwardAuthError = cooldownErrorResponse(err);
|
|
728
735
|
} else if (err instanceof CodexMainProfileDrainingError) {
|
|
729
736
|
forwardAuthError = codexMainProfileDrainingResponse();
|
|
@@ -769,11 +776,12 @@ export async function resolveLiveRelay(
|
|
|
769
776
|
forward.releaseProbeLease?.();
|
|
770
777
|
return denial;
|
|
771
778
|
}
|
|
772
|
-
|
|
773
|
-
for (const [name, value] of forward.headers) headers[name] = value;
|
|
779
|
+
const selectedHeaders = mergeCodexSelectedHeaders({ ...headers, ...provider.headers }, forward.headers);
|
|
774
780
|
logCtx.model = "gpt-live";
|
|
775
781
|
return {
|
|
776
|
-
headers,
|
|
782
|
+
headers: Object.fromEntries(selectedHeaders),
|
|
783
|
+
authContext: forward.authContext,
|
|
784
|
+
releaseProbeLease: forward.releaseProbeLease,
|
|
777
785
|
providerBaseUrl: provider.baseUrl,
|
|
778
786
|
usesBackendShape: isChatGptBackendBaseUrl(provider.baseUrl),
|
|
779
787
|
keyed: false,
|
|
@@ -855,6 +863,18 @@ export async function handleLive(
|
|
|
855
863
|
const linkedSignal = signalWithTimeout(LIVE_UPSTREAM_TIMEOUT_MS, req.signal);
|
|
856
864
|
const sidecarExit = sidecarEnter("live");
|
|
857
865
|
try {
|
|
866
|
+
if (relay.authContext?.kind === "pool") {
|
|
867
|
+
let parsed: unknown;
|
|
868
|
+
try { parsed = JSON.parse(new TextDecoder().decode(outboundBody)); } catch { /* Upstream owns invalid JSON. */ }
|
|
869
|
+
const accountId = relay.authContext.chatgptAccountId;
|
|
870
|
+
let isolated = isolateCodexPoolClientMetadata(parsed, accountId);
|
|
871
|
+
if (isolated && typeof isolated === "object" && !Array.isArray(isolated)) {
|
|
872
|
+
const record = isolated as Record<string, unknown>;
|
|
873
|
+
const session = isolateCodexPoolClientMetadata(record.session, accountId);
|
|
874
|
+
if (session !== record.session) isolated = { ...record, session };
|
|
875
|
+
}
|
|
876
|
+
if (isolated !== parsed) outboundBody = new TextEncoder().encode(JSON.stringify(isolated)).buffer as ArrayBuffer;
|
|
877
|
+
}
|
|
858
878
|
const upstreamResponse = await fetch(url, {
|
|
859
879
|
method: "POST",
|
|
860
880
|
headers,
|
|
@@ -901,6 +921,10 @@ export async function handleLive(
|
|
|
901
921
|
if (req.signal.aborted) {
|
|
902
922
|
return formatErrorResponse(499, "client_closed_request", "live request canceled by client");
|
|
903
923
|
}
|
|
924
|
+
if (err instanceof CodexInstallationIdUnavailableError) {
|
|
925
|
+
relay.releaseProbeLease?.();
|
|
926
|
+
return formatErrorResponse(503, "server_busy", err.message);
|
|
927
|
+
}
|
|
904
928
|
if (err instanceof Error && err.name === "TimeoutError") {
|
|
905
929
|
relay.recordOutcome?.("timeout");
|
|
906
930
|
return formatErrorResponse(504, "upstream_error", "live upstream timed out");
|
|
@@ -925,7 +949,7 @@ export async function resolveLiveSidebandUpgrade(
|
|
|
925
949
|
target: LiveSidebandTarget,
|
|
926
950
|
turnAdmissionLease?: AdmissionLease,
|
|
927
951
|
admission?: DataPlaneAdmission,
|
|
928
|
-
): Promise<{ headers: Record<string, string>; upstreamWsUrl: string; recordOutcome?: LiveRelayTarget["recordOutcome"] } | Response> {
|
|
952
|
+
): Promise<{ headers: Record<string, string>; upstreamWsUrl: string; authContext?: CodexAuthContext; recordOutcome?: LiveRelayTarget["recordOutcome"] } | Response> {
|
|
929
953
|
const relay = await resolveLiveRelay(req, config, logCtx, turnAdmissionLease, {
|
|
930
954
|
admission,
|
|
931
955
|
model: liveSidebandModel(target),
|
|
@@ -933,6 +957,7 @@ export async function resolveLiveSidebandUpgrade(
|
|
|
933
957
|
});
|
|
934
958
|
if (relay instanceof Response) return relay;
|
|
935
959
|
return {
|
|
960
|
+
authContext: relay.authContext,
|
|
936
961
|
headers: relay.headers,
|
|
937
962
|
upstreamWsUrl: buildLiveSidebandUpstreamWsUrl(target, config.experimentalRealtimeWsBaseUrl),
|
|
938
963
|
recordOutcome: relay.recordOutcome,
|
|
@@ -562,26 +562,28 @@ async function handleAgentSettingsRoutesImpl(ctx: ManagementContext): Promise<Re
|
|
|
562
562
|
const body = parsedBody as { enabled?: unknown };
|
|
563
563
|
if (typeof body.enabled !== "boolean") return jsonResponse({ error: "body.enabled must be a boolean" }, 400);
|
|
564
564
|
const { isDefaultModeRequestUserInputEnabled, DEFAULT_MODE_REQUEST_USER_INPUT_FEATURE_KEY, activeCodexConfigPath } = await import("../../codex/features");
|
|
565
|
-
const
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
565
|
+
const selectionWrite = await beginCodexCliSelectionParentWriteAsync({ signal: req.signal });
|
|
566
|
+
if (!selectionWrite.entered) return jsonResponse({ error: "codex_cli_selection_busy", retryable: true }, 503);
|
|
567
|
+
try {
|
|
568
|
+
const before = isDefaultModeRequestUserInputEnabled();
|
|
569
|
+
let toggle = deps.toggleDefaultModeRequestUserInput;
|
|
570
|
+
if (!toggle) {
|
|
571
|
+
try {
|
|
572
|
+
const { codexFeaturesInvocation, runCodexFeaturesCommand } = await import("../../cli/v2");
|
|
573
|
+
const action = body.enabled ? "enable" : "disable";
|
|
574
|
+
const invocation = selectionWrite.commit(() => codexFeaturesInvocation(action, DEFAULT_MODE_REQUEST_USER_INPUT_FEATURE_KEY, process.platform, { requireAvailable: true }));
|
|
575
|
+
toggle = (_enabled, env, validate) => runCodexFeaturesCommand(action, DEFAULT_MODE_REQUEST_USER_INPUT_FEATURE_KEY, env, validate, invocation);
|
|
576
|
+
} catch (error) {
|
|
577
|
+
if (error instanceof CodexCliSelectionMutationBusyError) throw error;
|
|
578
|
+
return jsonResponse({ error: `default_mode_request_user_input toggle failed: ${error instanceof Error ? error.message : String(error)}` }, 502);
|
|
579
|
+
}
|
|
575
580
|
}
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
// Preserve native home creation only after executable resolution succeeds.
|
|
583
|
-
prepareCodexHome(dirname(configPath));
|
|
584
|
-
{
|
|
581
|
+
// Keep selection ownership across the config-lock await and the whole
|
|
582
|
+
// synchronous child execution: an updater must not replace this command.
|
|
583
|
+
const { acquireConfigWriteLock, releaseConfigWriteLock, configWriteLockFailureMessage, runConfigWriteChild, ConfigWriteDestinationChanged } = await import("../../codex/config-write-lock");
|
|
584
|
+
const configPath = activeCodexConfigPath();
|
|
585
|
+
// Preserve native home creation only after executable resolution succeeds.
|
|
586
|
+
selectionWrite.commit(() => prepareCodexHome(dirname(configPath)));
|
|
585
587
|
const configLock = await acquireConfigWriteLock(configPath);
|
|
586
588
|
if (!configLock.ok) {
|
|
587
589
|
return jsonResponse({ error: configWriteLockFailureMessage(configLock), retryable: configLock.error === "locked" }, 502);
|
|
@@ -589,8 +591,9 @@ async function handleAgentSettingsRoutesImpl(ctx: ManagementContext): Promise<Re
|
|
|
589
591
|
let toggleError: string | null = null;
|
|
590
592
|
let destinationChanged = false;
|
|
591
593
|
try {
|
|
592
|
-
runConfigWriteChild(configPath, configLock.handle, (env, validate) => toggle!(body.enabled as boolean, env, validate));
|
|
594
|
+
selectionWrite.commit(() => runConfigWriteChild(configPath, configLock.handle, (env, validate) => toggle!(body.enabled as boolean, env, validate)));
|
|
593
595
|
} catch (error) {
|
|
596
|
+
if (error instanceof CodexCliSelectionMutationBusyError) throw error;
|
|
594
597
|
destinationChanged = error instanceof ConfigWriteDestinationChanged;
|
|
595
598
|
const err = error as { stderr?: unknown; message?: string };
|
|
596
599
|
const raw = err.stderr;
|
|
@@ -613,7 +616,7 @@ async function handleAgentSettingsRoutesImpl(ctx: ManagementContext): Promise<Re
|
|
|
613
616
|
warnings.push("Applies to new sessions; restart the Codex app or wait out its picker cache to see the change.");
|
|
614
617
|
}
|
|
615
618
|
return jsonResponse({ ok: true, enabled, changed: enabled !== before, warnings });
|
|
616
|
-
}
|
|
619
|
+
} finally { selectionWrite.exit(); }
|
|
617
620
|
}
|
|
618
621
|
|
|
619
622
|
// Subagent prompt injection model: single native or routed model whose info is
|
|
@@ -25,7 +25,8 @@ export async function handleCodexCliUpdateRoutes(ctx: ManagementContext): Promis
|
|
|
25
25
|
}
|
|
26
26
|
if (ctx.url.pathname !== "/api/codex/cli-update/apply") return null;
|
|
27
27
|
if (ctx.req.method !== "POST") return jsonResponse({ error: "method_not_allowed" }, 405, ctx.req, ctx.config);
|
|
28
|
-
if (!hasHumanDashboardSession(ctx) || !ctx.trustedLoopbackIngress
|
|
28
|
+
if (!hasHumanDashboardSession(ctx) || !ctx.trustedLoopbackIngress
|
|
29
|
+
|| ctx.sessionControl?.isPaired(ctx.req, ctx.config) !== true) {
|
|
29
30
|
return jsonResponse({ error: "local_dashboard_confirmation_required" }, 403, ctx.req, ctx.config);
|
|
30
31
|
}
|
|
31
32
|
let body: unknown;
|
|
@@ -180,7 +180,7 @@ export const MANAGEMENT_ROUTES: readonly ManagementRoute[] = [
|
|
|
180
180
|
{ method: "POST", path: "/api/codex/desktop-compatibility/settings", module: "server/management/desktop-compatibility-settings-routes", mutates: true, mechanism: "path-constant", exempt: { reason: "session-only", why: "Saved native observation intent requires an operator-paired local GUI action and fresh field revision." } },
|
|
181
181
|
// server/management/codex-cli-update-routes
|
|
182
182
|
{ method: "GET", path: "/api/codex/cli-update/plan", module: "server/management/codex-cli-update-routes", mutates: false, exempt: { reason: "local-transport", why: "The CLI runs the same proof-bound plan builder locally; the authenticated route also supplies the dashboard plan." } },
|
|
183
|
-
{ method: "POST", path: "/api/codex/cli-update/apply", module: "server/management/codex-cli-update-routes", mutates: true, exempt: { reason: "session-only", why: "HTTP apply requires a
|
|
183
|
+
{ method: "POST", path: "/api/codex/cli-update/apply", module: "server/management/codex-cli-update-routes", mutates: true, exempt: { reason: "session-only", why: "HTTP apply requires a current paired dashboard session on trusted loopback ingress, matching origin, CSRF and confirmed: true; the local CLI uses --yes independently." } },
|
|
184
184
|
{ method: "GET", path: "/api/codex/cli-update/jobs/{jobId}", module: "server/management/codex-cli-update-routes", mutates: false, mechanism: "regex", exempt: { reason: "local-transport", why: "The CLI status command reads the same protected job record directly and does not use job IDs as authorization." } },
|
|
185
185
|
{ method: "PUT", path: "/api/codex-auth/features/default-mode-request-user-input", module: "server/management/agent-settings-routes", mutates: true },
|
|
186
186
|
{ method: "PUT", path: "/api/effort-caps", module: "server/management/agent-settings-routes", mutates: true },
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { clientFacingModelLabel } from "../lib/error-destination";
|
|
1
2
|
import {
|
|
2
3
|
AdmissionModelDeniedError, routeAllowedByScope, UNNAMED_DESTINATION_MODEL, type AdmissionModelScope,
|
|
3
4
|
} from "./admission-model-scope";
|
|
@@ -58,7 +59,7 @@ export function nativeMessagesToolScopeDenial(
|
|
|
58
59
|
if (!isAdvisor(tool)) continue;
|
|
59
60
|
const modelId = typeof tool.model === "string" && tool.model.trim() ? tool.model : undefined;
|
|
60
61
|
if (modelId === undefined || !routeAllowedByScope(scope, { providerName, modelId })) {
|
|
61
|
-
return new AdmissionModelDeniedError(requestedModel, { providerName, modelId: modelId ?? UNNAMED_DESTINATION_MODEL });
|
|
62
|
+
return new AdmissionModelDeniedError(clientFacingModelLabel(requestedModel), { providerName, modelId: modelId ?? UNNAMED_DESTINATION_MODEL });
|
|
62
63
|
}
|
|
63
64
|
}
|
|
64
65
|
return undefined;
|
|
@@ -110,7 +110,7 @@ export function guardNativeMessagesEmptyToolCatalog(
|
|
|
110
110
|
&& (index === undefined || !permittedInputBlocks.has(index))) name ??= "<unnamed>";
|
|
111
111
|
if (name !== undefined) {
|
|
112
112
|
clear();
|
|
113
|
-
const message = redactSecretString(undeclaredToolCallMessage(
|
|
113
|
+
const message = redactSecretString(undeclaredToolCallMessage());
|
|
114
114
|
onRefusal(message);
|
|
115
115
|
enqueue(controller, `event: error\ndata: ${JSON.stringify(anthropicErrorBody(502, message, "api_error", UNDECLARED_TOOL_CALL_ERROR_CODE))}\n\n`);
|
|
116
116
|
settled = true;
|
|
@@ -44,7 +44,7 @@ import { readBoundedResponseBody } from "../lib/bounded-body";
|
|
|
44
44
|
import { classifyError } from "../lib/errors";
|
|
45
45
|
import { relaySseWithPayloadRewrite } from "./sse-payload-rewrite";
|
|
46
46
|
import { redactSecretString } from "../lib/redact";
|
|
47
|
-
import { resolveClientRetryAfter } from "../lib/retry-after";
|
|
47
|
+
import { formatClientRetryAfter, resolveClientRetryAfter } from "../lib/retry-after";
|
|
48
48
|
import { enrichOpenCodeZenUpstreamMessage } from "../providers/opencode-zen-rate-limit";
|
|
49
49
|
import { isTranslatorBudgetExceededError, type TranslatorBudget } from "../lib/translator-budget";
|
|
50
50
|
import {
|
|
@@ -130,7 +130,7 @@ import { linkAbortSignal } from "./responses/core-lifetime";
|
|
|
130
130
|
import { attachRequestSpendTracker } from "./responses/request-spend";
|
|
131
131
|
import { workflowRefusalResponse } from "./workflow-refusal";
|
|
132
132
|
import { sseFieldValue } from "../lib/sse-decoder";
|
|
133
|
-
import { admissionModelDeniedResponse, type AdmissionModelScope } from "./admission-model-scope";
|
|
133
|
+
import { admissionModelDeniedResponse, projectAdmissionModelDeniedLog, type AdmissionModelScope } from "./admission-model-scope";
|
|
134
134
|
import { nativeMessagesToolScopeDenial } from "./messages-native-scope";
|
|
135
135
|
import { retainUpstreamMessagesRequestId } from "./messages-response-headers";
|
|
136
136
|
|
|
@@ -380,7 +380,8 @@ export async function handleNativeMessages(options: HandleNativeMessagesOptions)
|
|
|
380
380
|
const localOAuthFailure = (error: unknown): Response | null => {
|
|
381
381
|
if (error instanceof AnthropicAccountCooldownError) {
|
|
382
382
|
const response = fail(429, error.message, "rate_limit_error");
|
|
383
|
-
|
|
383
|
+
const advice = error.retryAfterSeconds !== null ? formatClientRetryAfter(error.retryAfterSeconds) : undefined;
|
|
384
|
+
if (advice !== undefined) response.headers.set("retry-after", advice);
|
|
384
385
|
return response;
|
|
385
386
|
}
|
|
386
387
|
if (error instanceof OAuthAccountPausedError) return fail(403, publicOAuthAuthenticationErrorMessage(error), "permission_error");
|
|
@@ -394,6 +395,7 @@ export async function handleNativeMessages(options: HandleNativeMessagesOptions)
|
|
|
394
395
|
|
|
395
396
|
const toolScopeDenial = nativeMessagesToolScopeDenial(options.modelScope, route.providerName, requestedModel, body);
|
|
396
397
|
if (toolScopeDenial) {
|
|
398
|
+
projectAdmissionModelDeniedLog(toolScopeDenial, logCtx);
|
|
397
399
|
finishLog(403, toolScopeDenial.message);
|
|
398
400
|
return admissionModelDeniedResponse(toolScopeDenial);
|
|
399
401
|
}
|
|
@@ -454,7 +456,8 @@ export async function handleNativeMessages(options: HandleNativeMessagesOptions)
|
|
|
454
456
|
cleanupAbort(); upstream.abort();
|
|
455
457
|
if (!(error instanceof RequestPacingQueueOverloadError)) throw error;
|
|
456
458
|
const refusal = fail(429, error.message, "rate_limit_error");
|
|
457
|
-
|
|
459
|
+
const advice = formatClientRetryAfter(error.retryAfterSeconds);
|
|
460
|
+
if (advice !== undefined) refusal.headers.set("Retry-After", advice);
|
|
458
461
|
return refusal;
|
|
459
462
|
}
|
|
460
463
|
}
|
|
@@ -835,7 +838,8 @@ export async function handleNativeMessages(options: HandleNativeMessagesOptions)
|
|
|
835
838
|
const sendError = error instanceof UpstreamRetryEvidenceError ? error.cause : error;
|
|
836
839
|
if (sendError instanceof RequestPacingQueueOverloadError) {
|
|
837
840
|
const refusal = fail(429, sendError.message, "rate_limit_error");
|
|
838
|
-
|
|
841
|
+
const advice = formatClientRetryAfter(sendError.retryAfterSeconds);
|
|
842
|
+
if (advice !== undefined) refusal.headers.set("Retry-After", advice);
|
|
839
843
|
return refusal;
|
|
840
844
|
}
|
|
841
845
|
if (sendError instanceof SendBudgetExhaustedError) return fail(429, sendError.message, "send_budget_exhausted", "send_budget_exhausted");
|
|
@@ -1002,7 +1006,7 @@ export async function handleNativeMessages(options: HandleNativeMessagesOptions)
|
|
|
1002
1006
|
const undeclaredTool = clientDeclaredEmptyToolCatalog ? nativeMessagesClientToolName(message, declaredInlineTools) : undefined;
|
|
1003
1007
|
if (undeclaredTool !== undefined) {
|
|
1004
1008
|
logCtx.errorCode = UNDECLARED_TOOL_CALL_ERROR_CODE;
|
|
1005
|
-
return fail(502, undeclaredToolCallMessage(
|
|
1009
|
+
return fail(502, undeclaredToolCallMessage(), "api_error", UNDECLARED_TOOL_CALL_ERROR_CODE);
|
|
1006
1010
|
}
|
|
1007
1011
|
bindUsage(anthropicUsageToOcx(isRec(message.usage) ? message.usage : undefined));
|
|
1008
1012
|
if (logIds) recordFirstOutput(logCtx, logIds.start);
|
|
@@ -1085,7 +1089,8 @@ function nativeMessagesErrorResponse(response: Response, bodyText: string, finis
|
|
|
1085
1089
|
?? (upstreamRetryAfter?.trim() === "0" ? "0" : undefined);
|
|
1086
1090
|
finishLog(response.status, safeMessage);
|
|
1087
1091
|
const headers = new Headers({ "Content-Type": "application/json" });
|
|
1088
|
-
|
|
1092
|
+
const clientRetryAfter = formatClientRetryAfter(retryAfter);
|
|
1093
|
+
if (clientRetryAfter) headers.set("Retry-After", clientRetryAfter);
|
|
1089
1094
|
else if (transient) headers.set("Retry-After", "2");
|
|
1090
1095
|
if (replayRefusal) applyReplayRefusalClientHeaders(headers);
|
|
1091
1096
|
// The native envelope keeps its shape (no added code); only an overflow's wording changes, so
|
|
@@ -28,6 +28,7 @@ import { isTranslatorBudgetExceededError } from "../lib/translator-budget";
|
|
|
28
28
|
import { AnthropicRequestError, isRec, type Rec } from "../claude/inbound-records";
|
|
29
29
|
import type { RequestLogContext } from "./request-log";
|
|
30
30
|
import { recordGenerationEvent } from "./request-log-generation-window";
|
|
31
|
+
import { recordLocalFailureDetail } from "./request-log-failure-detail";
|
|
31
32
|
import type { OcxConfig } from "../types";
|
|
32
33
|
|
|
33
34
|
export function anthropicUsageToOcx(usage: Rec | undefined): { inputTokens: number; outputTokens: number; cachedInputTokens?: number; cacheReadInputTokens?: number; cacheCreationInputTokens?: number; cacheCreation1hInputTokens?: number } | undefined {
|
|
@@ -267,7 +268,8 @@ export function tapAnthropicSseForLog(
|
|
|
267
268
|
// A cut-short turn, logged as the Responses relay logs a stall-timeout incomplete
|
|
268
269
|
// (httpStatusForRequestLogTerminal: only a max_output_tokens incomplete is a 200). A 200
|
|
269
270
|
// row with no terminalStatus also lost its failure diagnostics in usage.jsonl.
|
|
270
|
-
logCtx
|
|
271
|
+
recordLocalFailureDetail(logCtx, message, closeReason === "body_stall"
|
|
272
|
+
? { code: "body_stall", value: guard?.stallMs ?? 0 } : { code: "body_overflow", value: guard?.maxBytes ?? 0 });
|
|
271
273
|
finalize(502, { terminalStatus: "incomplete", closeReason });
|
|
272
274
|
closeWithErrorFrame(errType, message);
|
|
273
275
|
}
|
|
@@ -350,7 +352,7 @@ export function tapAnthropicSseForLog(
|
|
|
350
352
|
// reset (below), so the client never reads a partial answer as a finished message.
|
|
351
353
|
logCtx.transportPhase = "mid_stream";
|
|
352
354
|
logCtx.terminalSource = "synthetic";
|
|
353
|
-
logCtx
|
|
355
|
+
recordLocalFailureDetail(logCtx, failure, { code: lastDeliveredStop === "error" ? "stream_error_stop" : "stream_ended_early" });
|
|
354
356
|
if (logCtx.activeAttempt) logCtx.activeAttempt.streamAborted = true;
|
|
355
357
|
finalize(502, { terminalStatus: "failed", closeReason: "terminal" });
|
|
356
358
|
closeWithErrorFrame("api_error", failure);
|
|
@@ -411,6 +413,8 @@ export function tapAnthropicSseForLog(
|
|
|
411
413
|
const message = redactSecretString(`anthropic passthrough upstream stream failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
412
414
|
logCtx.transportPhase = "mid_stream";
|
|
413
415
|
logCtx.terminalSource = "synthetic";
|
|
416
|
+
// The runtime error text stays internal; the row keeps the fixed sentence only.
|
|
417
|
+
recordLocalFailureDetail(logCtx, "anthropic passthrough upstream stream failed", { code: "stream_failed" });
|
|
414
418
|
logCtx.upstreamError = message.slice(0, 500);
|
|
415
419
|
if (logCtx.activeAttempt) logCtx.activeAttempt.streamAborted = true;
|
|
416
420
|
finalize(502, { terminalStatus: "failed", closeReason: "terminal" });
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Final request-log ownership for a native ingress that converts an inner Chat response.
|
|
3
|
+
*
|
|
4
|
+
* The inner Chat path keeps its own observation, attempt and usage accounting and its own
|
|
5
|
+
* callback ordering. Its final-log requests are intercepted: the first one is recorded as the
|
|
6
|
+
* physical attempt's settlement and nothing is written. The native handler, which alone knows
|
|
7
|
+
* whether its conversion succeeded or the client went away, commits exactly once through the
|
|
8
|
+
* ordinary writer. Later inner requests stay inert, so a delayed callback cannot add a row.
|
|
9
|
+
*/
|
|
10
|
+
import type { ResponsesTerminalStatus } from "../bridge";
|
|
11
|
+
import {
|
|
12
|
+
addRequestLog,
|
|
13
|
+
commitInterceptedFinalRequestLog,
|
|
14
|
+
interceptFinalRequestLog,
|
|
15
|
+
type RequestLogContext,
|
|
16
|
+
type RequestLogEntry,
|
|
17
|
+
} from "./request-log";
|
|
18
|
+
|
|
19
|
+
/** How long a known outer outcome waits for a missing inner settlement before cutting off. */
|
|
20
|
+
export const NATIVE_FINAL_LOG_FALLBACK_MS = 100;
|
|
21
|
+
export const NATIVE_FINAL_LOG_CUTOFF_CODE = "observation_barrier_timeout";
|
|
22
|
+
|
|
23
|
+
export interface NativeFinalOutcome {
|
|
24
|
+
status: number;
|
|
25
|
+
terminalStatus?: ResponsesTerminalStatus;
|
|
26
|
+
closeReason: NonNullable<RequestLogEntry["closeReason"]>;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export interface NativeFinalLog {
|
|
30
|
+
/** True once the inner path requested its final log. */
|
|
31
|
+
innerSettled(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Call once the outer outcome is known. Resolves true when the inner path has settled, or
|
|
34
|
+
* false when the bounded fallback elapsed first. Never waits on an upstream cancellation.
|
|
35
|
+
*/
|
|
36
|
+
waitForInner(): Promise<boolean>;
|
|
37
|
+
/** Write the single row. Returns false when a row was already committed. */
|
|
38
|
+
commit(outcome: NativeFinalOutcome): boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function createNativeFinalLog(
|
|
42
|
+
requestId: string,
|
|
43
|
+
start: number,
|
|
44
|
+
logCtx: RequestLogContext,
|
|
45
|
+
options: { fallbackMs?: number; addLog?: (entry: RequestLogEntry) => void } = {},
|
|
46
|
+
): NativeFinalLog {
|
|
47
|
+
const fallbackMs = options.fallbackMs ?? NATIVE_FINAL_LOG_FALLBACK_MS;
|
|
48
|
+
let innerStatus: number | undefined;
|
|
49
|
+
let wake: (() => void) | undefined;
|
|
50
|
+
let waiting: Promise<boolean> | undefined;
|
|
51
|
+
let committed = false;
|
|
52
|
+
interceptFinalRequestLog(logCtx, status => {
|
|
53
|
+
if (innerStatus !== undefined) return;
|
|
54
|
+
innerStatus = status;
|
|
55
|
+
// Resolved on a later microtask, so observations the inner producer makes later in the same
|
|
56
|
+
// synchronous pass (a relay's completed-response hook, for example) land before the commit.
|
|
57
|
+
wake?.();
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
innerSettled: () => innerStatus !== undefined,
|
|
61
|
+
waitForInner() {
|
|
62
|
+
waiting ??= innerStatus !== undefined
|
|
63
|
+
? Promise.resolve(true)
|
|
64
|
+
: new Promise<boolean>(resolve => {
|
|
65
|
+
const timer = setTimeout(() => { wake = undefined; resolve(innerStatus !== undefined); }, fallbackMs);
|
|
66
|
+
wake = () => { clearTimeout(timer); wake = undefined; resolve(true); };
|
|
67
|
+
});
|
|
68
|
+
return waiting;
|
|
69
|
+
},
|
|
70
|
+
commit(outcome) {
|
|
71
|
+
if (committed) return false;
|
|
72
|
+
committed = true;
|
|
73
|
+
// Upstream evidence stays on the context so the final writer can classify it; the row
|
|
74
|
+
// projection (src/usage/error-detail.ts) removes upstream-authored text before any writer.
|
|
75
|
+
let { status, terminalStatus } = outcome;
|
|
76
|
+
if (innerStatus === undefined) {
|
|
77
|
+
// Cut off before the inner path settled: what it observed so far is not a complete
|
|
78
|
+
// account. Drop it, so the row reads unreported and the terminal send settles as
|
|
79
|
+
// unresolved rather than being priced from a partial count, and never report success.
|
|
80
|
+
delete logCtx.usage;
|
|
81
|
+
delete logCtx.usageLogInputTokens;
|
|
82
|
+
if (logCtx.activeAttempt) delete logCtx.activeAttempt.usage;
|
|
83
|
+
logCtx.errorCode = NATIVE_FINAL_LOG_CUTOFF_CODE;
|
|
84
|
+
if (status < 400) { status = 502; terminalStatus = "failed"; }
|
|
85
|
+
}
|
|
86
|
+
commitInterceptedFinalRequestLog(requestId, start, logCtx, status, {
|
|
87
|
+
...(terminalStatus ? { terminalStatus } : {}),
|
|
88
|
+
closeReason: status === 499 ? "client_cancel" : outcome.closeReason,
|
|
89
|
+
}, innerStatus ?? status, options.addLog ?? addRequestLog);
|
|
90
|
+
return true;
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
}
|