@bitkyc08/opencodex 2.98.0 → 2.99.0-preview.20261108
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 +6 -19
- package/gui/dist/assets/{App-6TFtZsUF.css → App-C1hGwaN1.css} +1 -1
- package/gui/dist/assets/App-CWz0areF.js +59 -0
- package/gui/dist/assets/Tray-BosDoskm.js +1 -0
- package/gui/dist/assets/{brand-mark-A03mw_9y.js → brand-mark-DpiBmFGI.js} +1 -1
- package/gui/dist/assets/{index-BjTIN4to.js → index-CAxjGWkm.js} +13 -13
- package/gui/dist/assets/index-bnUWypyz.css +2 -0
- package/gui/dist/assets/{segment-thumb-features-Bf6vpwf8.js → segment-thumb-features-JcszQ18T.js} +1 -1
- package/gui/dist/classic/assets/App-BOEsFmiN.js +58 -0
- package/gui/dist/classic/assets/Tray-5v86r9Az.js +1 -0
- package/gui/dist/classic/assets/{index-DFAFnven.js → index-ClZ_zZ77.js} +13 -13
- package/gui/dist/classic/assets/{quota-summary-C-4HP4_5.js → quota-summary-xwvDtvu7.js} +1 -1
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/package.json +1 -1
- package/src/adapters/coding-agent/protocol.ts +8 -3
- package/src/adapters/coding-agent/turn.ts +6 -2
- package/src/adapters/command-code.ts +8 -5
- package/src/adapters/devin.ts +11 -1
- package/src/adapters/kiro/stream.ts +5 -4
- package/src/adapters/openai-chat/destination-policy.ts +25 -0
- package/src/adapters/openai-chat/native-content.ts +32 -0
- package/src/adapters/openai-chat/passthrough.ts +14 -1
- package/src/adapters/openai-chat/reasoning-wire.ts +42 -1
- package/src/adapters/openai-chat.ts +2 -2
- package/src/adapters/qoder/adapter.ts +9 -0
- package/src/bridge/response-json.ts +13 -1
- package/src/bridge/sse.ts +112 -22
- package/src/cli/account-affinity-reset.ts +42 -0
- package/src/cli/account.ts +5 -0
- package/src/cli/capabilities-accounts.ts +8 -0
- package/src/cli/capabilities-agents-routing.ts +5 -4
- package/src/cli/message-command.ts +1 -1
- package/src/cli/message-mcp-command.ts +8 -5
- package/src/client/orphan-token-recovery.ts +1 -1
- package/src/codex/autostart-health.ts +4 -2
- package/src/generated/compatibility-version.json +128 -76
- package/src/lib/desktop-cli-handoff.mjs +5 -8
- package/src/lib/failure-detail.ts +5 -2
- package/src/lib/launcher-signal-forwarding.d.mts +8 -0
- package/src/lib/launcher-signal-forwarding.mjs +36 -0
- package/src/lib/privacy.ts +6 -0
- package/src/lib/request-execution-budget.ts +188 -33
- package/src/lib/upstream-validation-detail.ts +47 -0
- package/src/lib/workflow-budget.ts +35 -16
- package/src/messaging/mcp-queue-rpc.ts +7 -3
- package/src/messaging/mcp-queue-server.ts +6 -0
- package/src/messaging/mcp-reply-cursor.ts +34 -0
- package/src/messaging/mcp-reply-tools.ts +93 -0
- package/src/oauth/anthropic-routing.ts +46 -3
- package/src/oauth/anthropic-session-affinity-store.ts +23 -10
- package/src/protocols/codecs/ollama.ts +22 -12
- package/src/providers/registry/entries-extended.ts +14 -0
- package/src/remote/hub-usage.ts +7 -0
- package/src/responses/parser.ts +27 -0
- package/src/responses/reasoning-envelope.ts +4 -0
- package/src/responses/schema.ts +1 -0
- package/src/server/chat-completions.ts +3 -0
- package/src/server/chat-native-sse.ts +14 -10
- package/src/server/chat-native.ts +24 -11
- package/src/server/index/websocket-handler.ts +12 -1
- package/src/server/management/oauth-account-routes.ts +65 -13
- package/src/server/management/route-registry.ts +1 -0
- package/src/server/messages-native.ts +21 -5
- package/src/server/request-log-attempt-recovery.ts +17 -0
- package/src/server/request-log-failure-detail.ts +18 -1
- package/src/server/request-log.ts +5 -18
- package/src/server/responses/account-auto-pause-recovery.ts +29 -1
- package/src/server/responses/adapter-continuation.ts +12 -5
- package/src/server/responses/adapter-dispatch.ts +50 -51
- package/src/server/responses/antigravity-model-denial-recovery.ts +4 -2
- package/src/server/responses/codex-ws-exchange.ts +13 -4
- package/src/server/responses/combo-required-tool-contract.ts +22 -3
- package/src/server/responses/core-codex-account.ts +92 -86
- package/src/server/responses/core-combo-failure.ts +7 -0
- package/src/server/responses/core-combo.ts +11 -4
- package/src/server/responses/core-lifetime.ts +3 -0
- package/src/server/responses/deferred-send-reporter.ts +18 -1
- package/src/server/responses/fetch-helpers.ts +9 -3
- package/src/server/responses/native-continuation-refusal.ts +8 -0
- package/src/server/responses/native-continuation-send.ts +34 -0
- package/src/server/responses/passthrough-delivery.ts +6 -2
- package/src/server/responses/passthrough-dispatch.ts +48 -33
- package/src/server/responses/passthrough-execution.ts +1 -0
- package/src/server/responses/policy-fallback.ts +32 -5
- package/src/server/responses/policy-request-scope.ts +26 -0
- package/src/server/responses/request-prepare.ts +11 -2
- package/src/server/responses/request-send-budget.ts +96 -14
- package/src/server/responses/request-spend-target.ts +19 -0
- package/src/server/responses/request-spend.ts +80 -28
- package/src/server/responses/request-transport.ts +106 -53
- package/src/server/responses/run-turn-execution.ts +3 -0
- package/src/server/responses/sidecar-execution.ts +2 -1
- package/src/server/responses/ws-upstream.ts +2 -1
- package/src/server/workflow-refusal.ts +38 -4
- package/src/server/ws-bridge.ts +10 -3
- package/src/service/desktop-startup.ts +76 -13
- package/src/types/request.ts +2 -1
- package/src/usage/app-breakdown.ts +23 -0
- package/src/usage/summary.ts +34 -1
- package/src/web-search/anthropic-executor.ts +25 -9
- package/src/web-search/loop.ts +3 -1
- package/src/web-search/passthrough-bridge.ts +3 -0
- package/src/web-search/run-turn-loop.ts +3 -1
- package/gui/dist/assets/App-FQ0OtiMJ.js +0 -59
- package/gui/dist/assets/Tray-D2d5wqLq.js +0 -1
- package/gui/dist/assets/index-5REODpG3.css +0 -2
- package/gui/dist/classic/assets/App-C9Eg3nUo.js +0 -58
- package/gui/dist/classic/assets/Tray-B8P8cokE.js +0 -1
|
@@ -65,10 +65,13 @@ import { resolveContextPrincipal } from "../auth-cors";
|
|
|
65
65
|
import { tryKiroAlternateAfterTerminalRefresh } from "../../oauth/kiro-terminal-failover";
|
|
66
66
|
import { classifyModelFamilyForQuota } from "../../oauth/account-quota-rank";
|
|
67
67
|
import { expandInferenceOAuthSendBudget } from "../inference/context";
|
|
68
|
-
import { stampOAuthAccountLabel, usesApiKeyAccount } from "../../providers/label";
|
|
68
|
+
import { stampOAuthAccountLabel, stampApiKeyAccountLabel, usesApiKeyAccount } from "../../providers/label";
|
|
69
|
+
import { bindResponsesSpendTarget, responsesSpendTarget } from "./request-spend-target";
|
|
69
70
|
import { isXaiResponsesDestination, resolveProviderTransport } from "../../providers/xai-transport";
|
|
70
71
|
import { captureRouteStaticPolicy } from "../../router";
|
|
71
72
|
import { CopilotAutoHttpError, resolveCopilotAuto } from "../../providers/github-copilot-auto";
|
|
73
|
+
import { PolicyCandidateUnavailableError, MandatoryToolChoiceUnavailableError, mandatoryToolChoiceUnavailableResponse, policyCandidateRefusalResponse } from "./policy-request-scope";
|
|
74
|
+
import { chatCanPreserveMandatoryToolChoice } from "./combo-required-tool-contract";
|
|
72
75
|
import {
|
|
73
76
|
AdmissionModelDeniedError,
|
|
74
77
|
admissionModelDeniedResponse, projectAdmissionModelDeniedLog,
|
|
@@ -140,6 +143,13 @@ export async function prepareResponsesTransport(
|
|
|
140
143
|
) {
|
|
141
144
|
const { config, logCtx, options, req } = requestContext;
|
|
142
145
|
const { route, parsed, inboundWire, translatorBudget } = requestState;
|
|
146
|
+
const deferPhysicalAttribution = route.providerName === "github-copilot" && route.provider.authMode !== "forward";
|
|
147
|
+
let copilotCandidate: { model: string; adapter: string; accountLogLabel?: string } | undefined;
|
|
148
|
+
bindResponsesSpendTarget(logCtx);
|
|
149
|
+
if (deferPhysicalAttribution) bindResponsesSpendTarget(logCtx, () => ({
|
|
150
|
+
poolId: logCtx.spendPoolId ?? route.providerName,
|
|
151
|
+
identityId: copilotCandidate ? copilotCandidate.accountLogLabel : logCtx.accountLogLabel,
|
|
152
|
+
}));
|
|
143
153
|
const genericAffinityMode = genericSessionAffinityEnabled(config, route.providerName);
|
|
144
154
|
const anthropicInstance = route.provider.authMode === "oauth"
|
|
145
155
|
? configuredAnthropicInstance(config, route.providerName) : undefined;
|
|
@@ -214,6 +224,7 @@ export async function prepareResponsesTransport(
|
|
|
214
224
|
let genericFailovers = 0;
|
|
215
225
|
let oauthSelection = route.provider.authMode === "oauth"
|
|
216
226
|
? captureOAuthAccountSelection(route.providerName) : null;
|
|
227
|
+
const anthropicManualSelectionGeneration = anthropicRouting?.captureAnthropicManualSelectionGeneration();
|
|
217
228
|
let servingOAuthSnapshot: OAuthAccessSnapshot | undefined;
|
|
218
229
|
// These owners also serve early passthrough and sidecar sends. A dispatch-time
|
|
219
230
|
// rebuild must update every later builder, without entering a later block's TDZ.
|
|
@@ -263,6 +274,7 @@ export async function prepareResponsesTransport(
|
|
|
263
274
|
// #7500: no admission, initial or a recovery/failover rebind, may land on an Antigravity
|
|
264
275
|
// account whose own roster omits the model. Callers abandon the send on null.
|
|
265
276
|
if (antigravityModelRefusal(config, route.providerName, candidate.accountId, route.modelId)) return null;
|
|
277
|
+
if (anthropicRouting && anthropicManualSelectionGeneration !== anthropicRouting.captureAnthropicManualSelectionGeneration()) return null;
|
|
266
278
|
const committed = genericAffinityMode
|
|
267
279
|
? admitGenericSessionAccount(config, route.providerName, oauthSelection, candidate, route.modelId, genericAffinityMode)
|
|
268
280
|
: await commitOAuthAccountSelection(route.providerName, candidate.accountId, {
|
|
@@ -271,6 +283,8 @@ export async function prepareResponsesTransport(
|
|
|
271
283
|
requireUsableAccount: true,
|
|
272
284
|
});
|
|
273
285
|
requireAnthropicAdmission();
|
|
286
|
+
// Reset-only publication does not change the OAuth revision, but must fence old bindings.
|
|
287
|
+
if (anthropicRouting && anthropicManualSelectionGeneration !== anthropicRouting.captureAnthropicManualSelectionGeneration()) return null;
|
|
274
288
|
if (committed) {
|
|
275
289
|
if (anthropicInstance) anthropicRouteDecision = currentAnthropicRouteDecision();
|
|
276
290
|
if (anthropicInstance !== undefined && !anthropicRouting!.commitAnthropicSelectionRouting(
|
|
@@ -334,8 +348,10 @@ export async function prepareResponsesTransport(
|
|
|
334
348
|
options.accountLoad.lease?.release();
|
|
335
349
|
options.accountLoad.lease = replayLease;
|
|
336
350
|
}
|
|
337
|
-
|
|
338
|
-
|
|
351
|
+
if (route.providerName !== "github-copilot") {
|
|
352
|
+
genericFailoverAccountId = admitted.accountId;
|
|
353
|
+
stampOAuthAccountLabel(logCtx, route.providerName, route.provider, admitted.accountId);
|
|
354
|
+
}
|
|
339
355
|
return admitted;
|
|
340
356
|
};
|
|
341
357
|
/**
|
|
@@ -349,6 +365,10 @@ export async function prepareResponsesTransport(
|
|
|
349
365
|
/** Project only bounded Copilot refusal metadata; upstream bodies and session tokens never reach the client. */
|
|
350
366
|
const copilotRefusalResponse = (error: unknown): Response | undefined => {
|
|
351
367
|
if (error instanceof AdmissionModelDeniedError) return admissionModelDeniedResponse(projectAdmissionModelDeniedLog(error, logCtx));
|
|
368
|
+
if (error instanceof PolicyCandidateUnavailableError) {
|
|
369
|
+
if (options.comboAttempt || options.policyRequestScope?.eligibility) return policyCandidateRefusalResponse(error);
|
|
370
|
+
return mandatoryToolChoiceUnavailableResponse();
|
|
371
|
+
}
|
|
352
372
|
if (!(error instanceof CopilotAutoHttpError) || ![401, 403, 429].includes(error.status)) return;
|
|
353
373
|
const response = markProxyError(formatErrorResponse(error.status, error.status === 429 ? "rate_limit_error" : "authentication_error",
|
|
354
374
|
error.message), "copilot");
|
|
@@ -379,20 +399,21 @@ export async function prepareResponsesTransport(
|
|
|
379
399
|
return base;
|
|
380
400
|
};
|
|
381
401
|
/** Resolve the request's ephemeral wire selection and recover at most one OAuth negotiation 401. */
|
|
382
|
-
const resolveCopilotSelection = async (requestParsed: OcxParsedRequest, insideDispatch = false): Promise<void> => {
|
|
383
|
-
if (route.providerName !== "github-copilot" ||
|
|
402
|
+
const resolveCopilotSelection = async (requestParsed: OcxParsedRequest, insideDispatch = false, candidateProvider: OcxProviderConfig = route.provider): Promise<void> => {
|
|
403
|
+
if (route.providerName !== "github-copilot" || candidateProvider.authMode === "forward") { route.provider = candidateProvider; return; }
|
|
404
|
+
let provider = candidateProvider;
|
|
384
405
|
copilotConfiguredWire ??= {
|
|
385
|
-
adapter:
|
|
386
|
-
responsesPath:
|
|
387
|
-
chatCompletionsPath:
|
|
388
|
-
apiVersion: new Headers(
|
|
406
|
+
adapter: provider.adapter,
|
|
407
|
+
responsesPath: provider.responsesPath,
|
|
408
|
+
chatCompletionsPath: provider.chatCompletionsPath,
|
|
409
|
+
apiVersion: new Headers(provider.headers).get("X-GitHub-Api-Version") ?? undefined,
|
|
389
410
|
};
|
|
390
411
|
/** Fence control-plane sends to the captured credential; reuse an already-held dispatch concurrency lease. */
|
|
391
412
|
const negotiate = () => {
|
|
392
413
|
const binding: DispatchBinding | undefined = oauthSelection && servingOAuthSnapshot
|
|
393
414
|
? { kind: "oauth", selection: { ...oauthSelection }, snapshot: servingOAuthSnapshot }
|
|
394
|
-
: { kind: "api-key", provider: { ...
|
|
395
|
-
return resolveCopilotAuto(copilotNegotiationBase(
|
|
415
|
+
: { kind: "api-key", provider: { ...provider } };
|
|
416
|
+
return resolveCopilotAuto(copilotNegotiationBase(provider), copilotRequestedModel, requestParsed,
|
|
396
417
|
options.abortSignal ?? req.signal, /** Fence each negotiation send against the captured credential binding before touching the network. */
|
|
397
418
|
() => selectionIsCurrent(binding), !insideDispatch);
|
|
398
419
|
};
|
|
@@ -400,14 +421,12 @@ export async function prepareResponsesTransport(
|
|
|
400
421
|
try { selected = await negotiate(); }
|
|
401
422
|
catch (error) {
|
|
402
423
|
if (!(error instanceof CopilotAutoHttpError) || error.status !== 401 || copilotNegotiationRefreshed
|
|
403
|
-
|| oauth401ReplayAttempted ||
|
|
424
|
+
|| oauth401ReplayAttempted || provider.authMode !== "oauth" || !servingOAuthSnapshot) throw error;
|
|
404
425
|
copilotNegotiationRefreshed = true;
|
|
405
426
|
const refreshed = await refreshResolvedOAuthSelection(servingOAuthSnapshot);
|
|
406
|
-
|
|
407
|
-
{ ...
|
|
427
|
+
provider = resolveProviderTransport(route.providerName,
|
|
428
|
+
{ ...provider, apiKey: refreshed.accessToken }, parsed.options.promptCacheKey,
|
|
408
429
|
resolveCopilotApiBaseUrl(refreshed.apiBaseUrl));
|
|
409
|
-
sentOAuthSnapshot = refreshed;
|
|
410
|
-
replayOAuthCredentialSnapshot = { accountId: refreshed.accountId, generation: refreshed.generation };
|
|
411
430
|
selected = await negotiate();
|
|
412
431
|
}
|
|
413
432
|
assertRouteAllowedByScope(
|
|
@@ -417,20 +436,40 @@ export async function prepareResponsesTransport(
|
|
|
417
436
|
requestState.inboundSelector,
|
|
418
437
|
{ providerName: route.providerName, modelId: selected.modelId },
|
|
419
438
|
);
|
|
439
|
+
const staticPolicy = captureRouteStaticPolicy(route.providerName, selected.modelId, selected.provider,
|
|
440
|
+
route.staticPolicy.effectiveAlias, inboundWire);
|
|
441
|
+
const autoAdapter = selected.auto ? selected.provider.adapter : undefined;
|
|
442
|
+
const negotiatedWire = autoAdapter === undefined
|
|
443
|
+
? resolveWireProtocolOverride(route.providerName, selected.modelId, selected.provider, inboundWire, staticPolicy)
|
|
444
|
+
: { ...selected.provider, adapter: autoAdapter };
|
|
445
|
+
if (negotiatedWire.adapter === "openai-chat"
|
|
446
|
+
&& !chatCanPreserveMandatoryToolChoice(requestParsed._rawBody, negotiatedWire, selected.modelId, requestParsed.context.tools ?? [])) {
|
|
447
|
+
throw new MandatoryToolChoiceUnavailableError();
|
|
448
|
+
}
|
|
449
|
+
// Credential admission may persist a refresh or newer manual selection. Publish request-local
|
|
450
|
+
// routing and accepted attribution only after this candidate's wire and scope both pass.
|
|
420
451
|
copilotSessionExpiresAt = selected.expiresAt ?? Infinity;
|
|
421
452
|
route.provider = selected.provider;
|
|
422
453
|
route.modelId = selected.modelId;
|
|
423
|
-
route.staticPolicy =
|
|
424
|
-
|
|
425
|
-
copilotAutoAdapter = selected.auto ? selected.provider.adapter : undefined;
|
|
454
|
+
route.staticPolicy = staticPolicy;
|
|
455
|
+
copilotAutoAdapter = autoAdapter;
|
|
426
456
|
for (const target of new Set([parsed, requestParsed])) {
|
|
427
457
|
target.modelId = selected.modelId;
|
|
428
458
|
if (target._rawBody && typeof target._rawBody === "object")
|
|
429
459
|
(target._rawBody as { model?: string }).model = selected.modelId;
|
|
430
460
|
target.context = renameRoutedIdentityInContext(target.context, selected.modelId);
|
|
431
461
|
}
|
|
432
|
-
|
|
433
|
-
|
|
462
|
+
const identity: { accountLogLabel?: string } = {};
|
|
463
|
+
stampApiKeyAccountLabel(identity, route.providerName, route.provider);
|
|
464
|
+
stampOAuthAccountLabel(identity, route.providerName, route.provider, servingOAuthSnapshot?.accountId);
|
|
465
|
+
copilotCandidate = { model: selected.modelId, adapter: negotiatedWire.adapter, ...identity };
|
|
466
|
+
if (servingOAuthSnapshot) {
|
|
467
|
+
// Recovery controllers snapshot admitted credentials before dispatch. Physical log
|
|
468
|
+
// attribution remains deferred, but these legacy recovery bindings must be available.
|
|
469
|
+
genericFailoverAccountId = servingOAuthSnapshot.accountId;
|
|
470
|
+
sentOAuthSnapshot = servingOAuthSnapshot;
|
|
471
|
+
replayOAuthCredentialSnapshot = { accountId: servingOAuthSnapshot.accountId, generation: servingOAuthSnapshot.generation };
|
|
472
|
+
}
|
|
434
473
|
};
|
|
435
474
|
/**
|
|
436
475
|
* Apply a rotated account's FULL credential snapshot to the live route (#2568d).
|
|
@@ -493,8 +532,7 @@ export async function prepareResponsesTransport(
|
|
|
493
532
|
) as OcxProviderConfig;
|
|
494
533
|
}
|
|
495
534
|
if (snapshot.projectId) rotatedProvider = { ...rotatedProvider, project: snapshot.projectId };
|
|
496
|
-
|
|
497
|
-
await resolveCopilotSelection(retryParsed, insideDispatch);
|
|
535
|
+
await resolveCopilotSelection(retryParsed, insideDispatch, rotatedProvider);
|
|
498
536
|
// Negotiation itself may have recovered a 401 with a newer committed credential.
|
|
499
537
|
if (route.providerName === "github-copilot" && servingOAuthSnapshot) snapshot = servingOAuthSnapshot;
|
|
500
538
|
if (route.providerName === "kiro") {
|
|
@@ -518,28 +556,40 @@ export async function prepareResponsesTransport(
|
|
|
518
556
|
// Re-stamp: a request that rotated accounts must be attributed to the account that actually
|
|
519
557
|
// served it. All three rotation sites funnel through here, so this is the only re-stamp
|
|
520
558
|
// needed -- and putting it anywhere else would let one of the three drift.
|
|
521
|
-
stampOAuthAccountLabel(logCtx, route.providerName, route.provider, snapshot.accountId);
|
|
559
|
+
if (!deferPhysicalAttribution) stampOAuthAccountLabel(logCtx, route.providerName, route.provider, snapshot.accountId);
|
|
522
560
|
if (anthropicInstance !== undefined) {
|
|
523
561
|
anthropicPoolAccountId = snapshot.accountId;
|
|
524
562
|
logCtx.provider = formatAnthropicProviderForLog(anthropicInstance!, snapshot.accountId, config);
|
|
525
|
-
} else {
|
|
563
|
+
} else if (!deferPhysicalAttribution) {
|
|
526
564
|
genericFailoverAccountId = snapshot.accountId;
|
|
527
565
|
}
|
|
528
|
-
sentOAuthSnapshot = snapshot;
|
|
566
|
+
if (!deferPhysicalAttribution) sentOAuthSnapshot = snapshot;
|
|
529
567
|
replayOAuthCredentialSnapshot = { accountId: snapshot.accountId, generation: snapshot.generation };
|
|
530
568
|
return snapshot;
|
|
531
569
|
};
|
|
532
|
-
// Key sends may be rebuilt while queued. Keep metadata pending
|
|
533
|
-
//
|
|
570
|
+
// Key and Copilot sends may be rebuilt or refused while queued. Keep metadata pending
|
|
571
|
+
// until the guarded dispatch binds it to the selection that reaches the upstream.
|
|
572
|
+
const attemptSendDeferred = (): boolean => usesApiKeyAccount(route.provider)
|
|
573
|
+
|| (route.providerName === "github-copilot" && route.provider.authMode !== "forward");
|
|
534
574
|
let pendingKeySend: { estimate: number | undefined; recovery?: AttemptRecoveryKind } | undefined;
|
|
535
575
|
const noteRoutedAttemptSend = (estimate: number | undefined, recovery?: AttemptRecoveryKind): void => {
|
|
536
|
-
if (
|
|
576
|
+
if (attemptSendDeferred()) pendingKeySend = { estimate, recovery };
|
|
537
577
|
else noteProviderAttemptSend(logCtx, route.providerName, route.provider, estimate, recovery);
|
|
538
578
|
};
|
|
539
579
|
const commitKeyAttemptSend = (): void => {
|
|
540
|
-
if (!
|
|
580
|
+
if (!attemptSendDeferred()) return;
|
|
581
|
+
if (copilotCandidate) {
|
|
582
|
+
logCtx.model = copilotCandidate.model;
|
|
583
|
+
logCtx.providerAdapter = copilotCandidate.adapter;
|
|
584
|
+
if (copilotCandidate.accountLogLabel) logCtx.accountLogLabel = copilotCandidate.accountLogLabel;
|
|
585
|
+
else delete logCtx.accountLogLabel;
|
|
586
|
+
if (servingOAuthSnapshot) {
|
|
587
|
+
genericFailoverAccountId = servingOAuthSnapshot.accountId;
|
|
588
|
+
sentOAuthSnapshot = servingOAuthSnapshot;
|
|
589
|
+
}
|
|
590
|
+
}
|
|
541
591
|
noteProviderAttemptSend(logCtx, route.providerName, route.provider,
|
|
542
|
-
pendingKeySend?.estimate ?? logCtx.usageLogInputTokens, pendingKeySend?.recovery);
|
|
592
|
+
pendingKeySend?.estimate ?? logCtx.usageLogInputTokens, pendingKeySend?.recovery, copilotCandidate);
|
|
543
593
|
pendingKeySend = undefined;
|
|
544
594
|
};
|
|
545
595
|
const bindKeyUsageFromBridge = (usage: OcxUsage | undefined): void => {
|
|
@@ -739,8 +789,7 @@ export async function prepareResponsesTransport(
|
|
|
739
789
|
if (fresh) current = selectProactiveApiKeyTransport(config, route.providerName, fresh) ?? fresh;
|
|
740
790
|
}
|
|
741
791
|
if (!current) throw new Error("API key selection is unavailable before dispatch");
|
|
742
|
-
|
|
743
|
-
await resolveCopilotSelection(requestParsed, true);
|
|
792
|
+
await resolveCopilotSelection(requestParsed, true, current);
|
|
744
793
|
}
|
|
745
794
|
adapter = activeAdapter = runTurnAdapter = resolveSelectionAdapter(
|
|
746
795
|
resolveWireProtocolOverride(route.providerName, route.modelId, route.provider, inboundWire, route.staticPolicy),
|
|
@@ -886,8 +935,7 @@ export async function prepareResponsesTransport(
|
|
|
886
935
|
let physicalOwner: AnthropicPhysicalSendOwnership | null = null;
|
|
887
936
|
try {
|
|
888
937
|
requireAnthropicAdmission();
|
|
889
|
-
if (!rebindPhysicalSend(options.sendBudget,
|
|
890
|
-
identityId: logCtx.accountLogLabel })) throw new SendBudgetExhaustedError();
|
|
938
|
+
if (!rebindPhysicalSend(options.sendBudget, responsesSpendTarget(logCtx, route.providerName))) throw new SendBudgetExhaustedError();
|
|
891
939
|
if (snapshot) {
|
|
892
940
|
// Reserve the incarnation at this synchronous send boundary, never on return.
|
|
893
941
|
physicalOwner = captureAnthropicPhysicalSendOwnership(snapshot);
|
|
@@ -897,7 +945,10 @@ export async function prepareResponsesTransport(
|
|
|
897
945
|
sentOAuthSnapshot = snapshot;
|
|
898
946
|
passiveQuotaWriterGeneration = writerGeneration;
|
|
899
947
|
}
|
|
900
|
-
|
|
948
|
+
// Copilot's local negotiation may refuse before this point, and spend admission
|
|
949
|
+
// may still refuse at the HTTP executor. Its note follows that final admission.
|
|
950
|
+
const deferredCopilotNote = route.providerName === "github-copilot" && route.provider.authMode !== "forward";
|
|
951
|
+
if (!deferredCopilotNote) commitKeyAttemptSend();
|
|
901
952
|
// The WS executor dials its own socket: HTTP connection policy and body coding do not apply.
|
|
902
953
|
// WS eligibility (egress, pacing, URL) was checked for the provider it was built for; a
|
|
903
954
|
// provider reselected above was not, so it takes the HTTP fallback under its own route.
|
|
@@ -905,7 +956,7 @@ export async function prepareResponsesTransport(
|
|
|
905
956
|
distributedKeyPhysicalFetch(anthropicBillingPhysicalFetch(fetchImpl, route.providerName, route.provider), route.providerName, route.provider, target),
|
|
906
957
|
input,
|
|
907
958
|
{ ...physicalInit, redirect: "manual",
|
|
908
|
-
...physicalSendObserverInit(observeAutoPause, destination instanceof Request ? destination.url : String(destination)) },
|
|
959
|
+
...physicalSendObserverInit(observeAutoPause, destination instanceof Request ? destination.url : String(destination), deferredCopilotNote ? commitKeyAttemptSend : undefined) },
|
|
909
960
|
{ providerName: route.providerName, provider: route.provider },
|
|
910
961
|
)) as typeof globalThis.fetch;
|
|
911
962
|
response = await fetchWithHeaderTimeout(target, dispatchInit, dispatchInit.signal ?? options.abortSignal ?? req.signal,
|
|
@@ -1126,20 +1177,18 @@ export async function prepareResponsesTransport(
|
|
|
1126
1177
|
}
|
|
1127
1178
|
if (admitted.accountId !== resolved.accountId) usedPreferredAccount = true;
|
|
1128
1179
|
resolved = admitted;
|
|
1129
|
-
replayOAuthCredentialSnapshot = {
|
|
1130
|
-
accountId: resolved.accountId,
|
|
1131
|
-
generation: resolved.generation,
|
|
1132
|
-
};
|
|
1133
|
-
if (isOAuth401ReplayProvider) sentOAuthSnapshot = resolved;
|
|
1134
1180
|
route.provider = { ...route.provider, apiKey: resolved.accessToken };
|
|
1135
|
-
//
|
|
1136
|
-
//
|
|
1137
|
-
|
|
1138
|
-
|
|
1181
|
+
// Copilot publishes accepted attribution after negotiation. Other providers retain
|
|
1182
|
+
// snapshot-based attribution independently of the failover predicate (#2699).
|
|
1183
|
+
if (route.providerName !== "github-copilot") {
|
|
1184
|
+
replayOAuthCredentialSnapshot = { accountId: resolved.accountId, generation: resolved.generation };
|
|
1185
|
+
if (isOAuth401ReplayProvider) sentOAuthSnapshot = resolved;
|
|
1186
|
+
stampOAuthAccountLabel(logCtx, route.providerName, route.provider, resolved.accountId);
|
|
1187
|
+
}
|
|
1139
1188
|
// Remember which account actually served this request so a 429 cools THAT one, not
|
|
1140
1189
|
// whichever account is active by the time the response comes back (#2568).
|
|
1141
1190
|
if (isGenericFailoverProvider(route.providerName, route.provider)) {
|
|
1142
|
-
genericFailoverAccountId = resolved.accountId;
|
|
1191
|
+
if (route.providerName !== "github-copilot") genericFailoverAccountId = resolved.accountId;
|
|
1143
1192
|
// Advance the pool cursor only now that this account is actually admitted. The
|
|
1144
1193
|
// helper returns immediately unless the kernel is on AND the strategy is
|
|
1145
1194
|
// round-robin, so quota and fill-first pools reach it without being touched.
|
|
@@ -1218,7 +1267,7 @@ export async function prepareResponsesTransport(
|
|
|
1218
1267
|
route.provider,
|
|
1219
1268
|
parsed.options.promptCacheKey,
|
|
1220
1269
|
route.providerName === "github-copilot" && route.provider.authMode === "oauth"
|
|
1221
|
-
? resolveCopilotApiBaseUrl(
|
|
1270
|
+
? resolveCopilotApiBaseUrl(servingOAuthSnapshot?.apiBaseUrl)
|
|
1222
1271
|
: undefined,
|
|
1223
1272
|
);
|
|
1224
1273
|
try { await resolveCopilotSelection(parsed); }
|
|
@@ -1259,7 +1308,7 @@ export async function prepareResponsesTransport(
|
|
|
1259
1308
|
forwardHeaders: requestState.selectedForwardHeaders,
|
|
1260
1309
|
});
|
|
1261
1310
|
assignNativeLogConversationId(logCtx, normalizeLogConversationId(parsed._cursorConversationId));
|
|
1262
|
-
logCtx.providerAdapter = adapter.name;
|
|
1311
|
+
if (!deferPhysicalAttribution) logCtx.providerAdapter = adapter.name;
|
|
1263
1312
|
// Ordinary requests receive one durable attempt only after their final initial
|
|
1264
1313
|
// adapter is resolved. Combo children own their attempt and retries keep it.
|
|
1265
1314
|
if (!options.comboAttempt && !logCtx.activeAttempt) {
|
|
@@ -1273,7 +1322,7 @@ export async function prepareResponsesTransport(
|
|
|
1273
1322
|
logCtx.activeAttemptStartedAt = Date.now();
|
|
1274
1323
|
(logCtx.attempts ??= []).push(attempt);
|
|
1275
1324
|
}
|
|
1276
|
-
sealRequestAttemptIdentity(logCtx.activeAttempt, logCtx.provider, adapter.name, logCtx.accountLogLabel);
|
|
1325
|
+
if (!deferPhysicalAttribution) sealRequestAttemptIdentity(logCtx.activeAttempt, logCtx.provider, adapter.name, logCtx.accountLogLabel);
|
|
1277
1326
|
recordAttemptCredentialSource(logCtx.activeAttempt, route.providerName, adapterProvider, adapter.name);
|
|
1278
1327
|
runTurnAdapter = adapter;
|
|
1279
1328
|
if (adapter.runTurn) {
|
|
@@ -1309,13 +1358,15 @@ export async function prepareResponsesTransport(
|
|
|
1309
1358
|
// Freeze the request ceiling before any 429 writes cooldowns. Selection still reads
|
|
1310
1359
|
// live eligibility on every hop; cooled accounts cannot shorten this request's allowance.
|
|
1311
1360
|
// The snapshot is clamped: a larger roster must not raise one request's hops or sends.
|
|
1312
|
-
const
|
|
1313
|
-
genericFailoverAccountId
|
|
1361
|
+
const fundingAccountId = deferPhysicalAttribution && isGenericFailoverProvider(route.providerName, route.provider)
|
|
1362
|
+
? servingOAuthSnapshot?.accountId : genericFailoverAccountId;
|
|
1363
|
+
const genericRosterSize = fundingAccountId ? new Set([
|
|
1364
|
+
fundingAccountId,
|
|
1314
1365
|
...eligibleFailoverAccounts(route.providerName, Date.now(), classifyModelFamilyForQuota(route.providerName, route.modelId)),
|
|
1315
1366
|
]).size : 0;
|
|
1316
1367
|
const fundedAccounts = Math.min(genericRosterSize, GENERIC_OAUTH_MAX_ACCOUNTS_PER_REQUEST);
|
|
1317
1368
|
const genericFailoverLimit = Math.max(GENERIC_OAUTH_MAX_FAILOVERS_PER_REQUEST, fundedAccounts - 1);
|
|
1318
|
-
if (
|
|
1369
|
+
if (fundingAccountId) expandInferenceOAuthSendBudget(options.sendBudget, fundedAccounts);
|
|
1319
1370
|
|
|
1320
1371
|
return {
|
|
1321
1372
|
genericFailoverLimit,
|
|
@@ -1423,6 +1474,8 @@ export async function prepareResponsesTransport(
|
|
|
1423
1474
|
refreshRunTurnAdapter,
|
|
1424
1475
|
oauthDispatch,
|
|
1425
1476
|
noteRoutedAttemptSend,
|
|
1477
|
+
attemptSendDeferred,
|
|
1478
|
+
deferPhysicalAttribution,
|
|
1426
1479
|
commitKeyAttemptSend,
|
|
1427
1480
|
recoverAutoPausedSelection,
|
|
1428
1481
|
bindKeyUsageFromBridge,
|
|
@@ -132,6 +132,7 @@ export async function executeResponsesRunTurn(
|
|
|
132
132
|
| "noteAdapterRecoveryWithheld"
|
|
133
133
|
| "reserveCredentialHop"
|
|
134
134
|
| "pendingHopPermit"
|
|
135
|
+
| "dispatchSidecarSend"
|
|
135
136
|
>,
|
|
136
137
|
completionPolicy: Pick<ResponsesCompletionPolicy, "emptyCompletionGuardEnabled">,
|
|
137
138
|
): Promise<Response> {
|
|
@@ -858,6 +859,7 @@ export async function executeResponsesRunTurn(
|
|
|
858
859
|
// iterations; terminal output keeps flowing through the same queue/bridge.
|
|
859
860
|
if (wsPlan) {
|
|
860
861
|
eventSource = runTurnWebSearchLoop(eventSource, {
|
|
862
|
+
dispatchSidecarSend: sendBudgetState.dispatchSidecarSend,
|
|
861
863
|
parsed,
|
|
862
864
|
plan: wsPlan,
|
|
863
865
|
translatorBudget,
|
|
@@ -1009,6 +1011,7 @@ export async function executeResponsesRunTurn(
|
|
|
1009
1011
|
{
|
|
1010
1012
|
parsed,
|
|
1011
1013
|
plan: wsPlan,
|
|
1014
|
+
dispatchSidecarSend: sendBudgetState.dispatchSidecarSend,
|
|
1012
1015
|
translatorBudget,
|
|
1013
1016
|
emptyCompletionRetry: emptyCompletionGuardEnabled,
|
|
1014
1017
|
forwardProvider: wsPlan.forwardSidecar?.provider,
|
|
@@ -107,7 +107,7 @@ export async function executeResponsesSidecars(
|
|
|
107
107
|
| "notifyResponseComplete"
|
|
108
108
|
| "cancelResponseCompletion"
|
|
109
109
|
>,
|
|
110
|
-
sendBudgetState: Pick<ResponsesSendBudget, "sendBudgetExhausted" | "reserveCredentialHop" | "refundableAdapterDispatchBudget" | "adapterDispatchBudget" | "noteInitialDispatch" | "noteAdapterPhysicalSend" | "noteAdapterRecoveryWithheld" | "pendingHopPermit">,
|
|
110
|
+
sendBudgetState: Pick<ResponsesSendBudget, "sendBudgetExhausted" | "reserveCredentialHop" | "refundableAdapterDispatchBudget" | "adapterDispatchBudget" | "noteInitialDispatch" | "noteAdapterPhysicalSend" | "noteAdapterRecoveryWithheld" | "pendingHopPermit" | "dispatchSidecarSend">,
|
|
111
111
|
) {
|
|
112
112
|
const { config, options, logCtx } = requestContext;
|
|
113
113
|
const antigravityPoolActivated = requestState.route.providerName === "google-antigravity"
|
|
@@ -685,6 +685,7 @@ export async function executeResponsesSidecars(
|
|
|
685
685
|
...sidecarBudget.fetchOptions(transportState.adapter),
|
|
686
686
|
})(input, init)) as typeof globalThis.fetch;
|
|
687
687
|
const loopResponse = await runWithWebSearch({
|
|
688
|
+
dispatchSidecarSend: sendBudgetState.dispatchSidecarSend,
|
|
688
689
|
parsed, adapter: transportState.adapter,
|
|
689
690
|
...(webSearchAdvisor ? { advisor: createAdvisorSidecarStep(webSearchAdvisor as Parameters<typeof createAdvisorSidecarStep>[0]) } : {}),
|
|
690
691
|
chatRawReasoningVisible: options.chatRawReasoningVisible,
|
|
@@ -166,6 +166,7 @@ export async function codexWsUpstreamFetch(
|
|
|
166
166
|
onPhysicalDispatch?: () => void,
|
|
167
167
|
/** Opt-in pre-output refusal hold (#6969); see codexWsExchange. */
|
|
168
168
|
preOutputRefusalHold?: CodexWsPreOutputRefusalHold,
|
|
169
|
+
onContinuationDispatch?: (frame: { body: Record<string, unknown>; text: string }) => void,
|
|
169
170
|
): Promise<Response> {
|
|
170
171
|
const prepared = prepareCodexWsRequest(url, init);
|
|
171
172
|
if (!prepared) return sseFallback(url, prepareCodexHttpInit(url, init));
|
|
@@ -250,7 +251,7 @@ export async function codexWsUpstreamFetch(
|
|
|
250
251
|
return codexWsExchange({
|
|
251
252
|
session, url, init, prepared, sseFallback, onQuota, beforeDispatch,
|
|
252
253
|
nativeControl: control,
|
|
253
|
-
beforeContinuation, onPhysicalDispatch,
|
|
254
|
+
beforeContinuation, onPhysicalDispatch, onContinuationDispatch,
|
|
254
255
|
preOutputRefusalHold,
|
|
255
256
|
bunVersion: typeof runtime === "string" ? runtime : runtime.version,
|
|
256
257
|
metadataContext: codexWsMetadataContext(init, prepared.model),
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { markProxyError } from "../lib/client-error-body";
|
|
1
|
+
import { carryProxyError, isProxyError, markProxyError } from "../lib/client-error-body";
|
|
2
2
|
import { sharedPoolContinuityDenial } from "../lib/spend-reservation-ledger";
|
|
3
|
+
import { markResponseNonReplayable } from "../lib/upstream-retry";
|
|
3
4
|
/**
|
|
4
5
|
* The one place that knows how this proxy refuses a turn on its own workflow budget.
|
|
5
6
|
*
|
|
@@ -21,6 +22,7 @@ import {
|
|
|
21
22
|
import {
|
|
22
23
|
WORKFLOW_LOCAL_REFUSAL_HEADER,
|
|
23
24
|
admitWorkflowTurn,
|
|
25
|
+
workflowSendCeilingReached,
|
|
24
26
|
workflowDenialSummary,
|
|
25
27
|
recordWorkflowRefusalEvent,
|
|
26
28
|
type WorkflowDenial,
|
|
@@ -54,8 +56,8 @@ export interface WorkflowRefusalLog {
|
|
|
54
56
|
* 429 to `rate_limit_error` / `rate_limit_exceeded`, so the body is shaped exactly like a
|
|
55
57
|
* provider rate limit. That is a deliberate wire contract -- changing it would change how every
|
|
56
58
|
* client retries -- which leaves two places to carry the truth. The message names the ceiling
|
|
57
|
-
* that fired and
|
|
58
|
-
* name.
|
|
59
|
+
* that fired and distinguishes admission from refusing a later send, and the header carries
|
|
60
|
+
* the machine-readable name. The in-process proxy marker establishes its local provenance.
|
|
59
61
|
*
|
|
60
62
|
* The row is where an operator actually looks, so it gets the same treatment #4639 established:
|
|
61
63
|
* `terminalSource: "synthetic"`, a local reason, and an error code naming the ceiling. Pass
|
|
@@ -78,6 +80,12 @@ export function workflowRefusalResponse(
|
|
|
78
80
|
// records its own denials, so passing one there would double-count them.
|
|
79
81
|
if (rootId) recordWorkflowRefusalEvent(rootId, reason, Date.now(), spend);
|
|
80
82
|
const recordOn = logCtx ?? refusalLog?.logCtx;
|
|
83
|
+
const sentPreviously = (recordOn?.activeAttempt?.sendCount ?? 0) > 0
|
|
84
|
+
|| recordOn?.attempts?.some(attempt => attempt.sendCount > 0) === true;
|
|
85
|
+
const message = sentPreviously ? summary.message
|
|
86
|
+
.replace("refused the request locally", "refused an additional send locally")
|
|
87
|
+
.replace("no provider was contacted", "no additional provider request was sent")
|
|
88
|
+
.replace("No provider was contacted", "No additional provider request was sent") : summary.message;
|
|
81
89
|
if (recordOn) {
|
|
82
90
|
markLocalRequestLogRefusal(recordOn, summary.code);
|
|
83
91
|
// A locally assigned code wins in addFinalRequestLog, so this is what names the ceiling in
|
|
@@ -93,15 +101,41 @@ export function workflowRefusalResponse(
|
|
|
93
101
|
const refusal = formatErrorResponse(
|
|
94
102
|
429,
|
|
95
103
|
reason === "workflow-sends-exhausted" ? "workflow_budget_exhausted" : "queue_capacity_exceeded",
|
|
96
|
-
|
|
104
|
+
message,
|
|
97
105
|
);
|
|
98
106
|
refusal.headers.set(WORKFLOW_LOCAL_REFUSAL_HEADER, summary.code);
|
|
99
107
|
// Without this a browser dashboard cannot read the header at all: the data plane never sets
|
|
100
108
|
// Access-Control-Expose-Headers, so a cross-origin reader sees only the CORS-safelisted ones.
|
|
101
109
|
refusal.headers.set("Access-Control-Expose-Headers", WORKFLOW_LOCAL_REFUSAL_HEADER);
|
|
110
|
+
// No Combo target has an allowance after a root send denial; do not classify it as quota.
|
|
111
|
+
if (reason === "workflow-sends-exhausted") markResponseNonReplayable(refusal);
|
|
102
112
|
return markProxyError(refusal, reason === "workflow-spend-exhausted" && spend && Object.hasOwn({ root: 1, identity: 1, pool: 1 }, spend.scope) ? (spend.includesUnboundPoolHistory ? "workflow_unbound" : "workflow") : undefined);
|
|
103
113
|
}
|
|
104
114
|
|
|
115
|
+
/** Preserve only a locally constructed workflow refusal across response projections. */
|
|
116
|
+
export function carryWorkflowRefusal(source: Response, target: Response): Response {
|
|
117
|
+
const code = isProxyError(source) ? source.headers.get(WORKFLOW_LOCAL_REFUSAL_HEADER) : null;
|
|
118
|
+
if (!code) return target;
|
|
119
|
+
target.headers.set(WORKFLOW_LOCAL_REFUSAL_HEADER, code);
|
|
120
|
+
const exposed = target.headers.get("Access-Control-Expose-Headers");
|
|
121
|
+
if (!exposed?.split(",").some(name => name.trim().toLowerCase() === WORKFLOW_LOCAL_REFUSAL_HEADER)) {
|
|
122
|
+
target.headers.set("Access-Control-Expose-Headers", exposed ? `${exposed}, ${WORKFLOW_LOCAL_REFUSAL_HEADER}` : WORKFLOW_LOCAL_REFUSAL_HEADER);
|
|
123
|
+
}
|
|
124
|
+
return carryProxyError(source, target);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Distinguish an exhausted live root from the request's independent send allowance. */
|
|
128
|
+
export function workflowSendCeilingRefusalResponse(
|
|
129
|
+
logCtx: RequestLogContext,
|
|
130
|
+
rootId?: string,
|
|
131
|
+
recordedOn: Pick<RequestLogContext, "localTerminalReason"> = logCtx,
|
|
132
|
+
): Response | undefined {
|
|
133
|
+
if (!workflowSendCeilingReached(rootId, currentWorkflowBudgetPolicy())) return undefined;
|
|
134
|
+
// Observer-backed admission already records its denial; legacy budgets need the event here.
|
|
135
|
+
return workflowRefusalResponse("workflow-sends-exhausted", logCtx, undefined,
|
|
136
|
+
recordedOn.localTerminalReason === "workflow_sends_exhausted" ? undefined : rootId);
|
|
137
|
+
}
|
|
138
|
+
|
|
105
139
|
/** Render the approved conservative-overlay explanation after a dispatch reservation refuses. */
|
|
106
140
|
export function unboundPoolSpendRefusalMessage(
|
|
107
141
|
logCtx: Pick<RequestLogContext, "spendRefusalDetail">,
|
package/src/server/ws-bridge.ts
CHANGED
|
@@ -14,6 +14,9 @@ import { safeResponseHeaders } from "./safe-response-headers";
|
|
|
14
14
|
import type { AudioSocketTarget } from "./audio-dictation";
|
|
15
15
|
import type { CodexWebSocketActivity } from "../codex/websocket-activity";
|
|
16
16
|
import { AGENT_ASSERTION_HEADER } from "../lib/authorization-scheme";
|
|
17
|
+
import { isProxyError } from "../lib/client-error-body";
|
|
18
|
+
import { WORKFLOW_LOCAL_REFUSAL_HEADER } from "../lib/workflow-budget";
|
|
19
|
+
import { NativeContinuationRefusalError } from "./responses/native-continuation-refusal";
|
|
17
20
|
import type { UsageClient } from "../usage/client";
|
|
18
21
|
|
|
19
22
|
export { safeResponseHeaders } from "./safe-response-headers";
|
|
@@ -337,9 +340,10 @@ export async function pumpResponsesSseToWebSocket(
|
|
|
337
340
|
&& isCurrent()
|
|
338
341
|
&& ws.readyState === OPEN
|
|
339
342
|
&& !(err instanceof WsSendDroppedError)) {
|
|
340
|
-
reportTerminal("incomplete");
|
|
343
|
+
reportTerminal(err instanceof NativeContinuationRefusalError ? "failed" : "incomplete");
|
|
341
344
|
try {
|
|
342
|
-
|
|
345
|
+
if (err instanceof NativeContinuationRefusalError) await sendResponseToWebSocket(ws, err.response, isCurrent);
|
|
346
|
+
else sendUpstreamError(ws, 502, err);
|
|
343
347
|
} catch (sendErr) {
|
|
344
348
|
// If delivery is already dropped, there is no useful error frame left
|
|
345
349
|
// to send. Swallow only that expected transport signal; other failures
|
|
@@ -413,7 +417,10 @@ export async function sendResponseToWebSocket(
|
|
|
413
417
|
if (!response.ok) {
|
|
414
418
|
const text = await response.text().catch(() => "");
|
|
415
419
|
if (!isCurrent()) return;
|
|
416
|
-
|
|
420
|
+
const frame = buildWsErrorFrame(response.status, errorPayloadFromText(text), response.headers);
|
|
421
|
+
const refusal = isProxyError(response) ? response.headers.get(WORKFLOW_LOCAL_REFUSAL_HEADER) : null;
|
|
422
|
+
if (refusal) (frame.headers as Record<string, string>)[WORKFLOW_LOCAL_REFUSAL_HEADER] = refusal;
|
|
423
|
+
sendJsonFrame(ws, frame);
|
|
417
424
|
return;
|
|
418
425
|
}
|
|
419
426
|
|