maka-agent 0.2.0-dev.23.20260906 → 0.2.0-dev.24.20260907
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/dist/acp/maka-acp-agent.js +2 -1
- package/dist/acp/session-configuration.js +143 -0
- package/dist/acp/session-registry.js +90 -4
- package/dist/cli-core.js +2 -0
- package/dist/pi-transcript.js +5 -12
- package/dist/pi-tui-runner.js +74 -4
- package/dist/runtime-host-cli-context.js +167 -78
- package/dist/runtime-host-cli-installation.js +8 -2
- package/dist/runtime-host-cli.js +31 -1
- package/dist/runtime-host-handoff-surface.js +81 -0
- package/dist/runtime-host-installed-update-bootstrap.js +13 -0
- package/dist/runtime-host-installed-update-coordinator.js +33 -0
- package/dist/runtime-host-lifecycle-transaction.js +9 -1
- package/dist/runtime-host-local-handoff.js +37 -4
- package/dist/runtime-host-local-managed-activation.js +84 -0
- package/dist/runtime-host-local-source-retirement.js +18 -2
- package/dist/runtime-host-managed-lifecycle-manager.js +1 -0
- package/dist/runtime-host-operator-retirement.js +50 -0
- package/dist/runtime-host-service-manager.js +3 -0
- package/dist/runtime-host-session-driver.js +4 -25
- package/dist/runtime-host-session-update.js +62 -0
- package/dist/runtime-host-tui-command.js +38 -73
- package/dist/runtime-host-tui-context.js +1 -0
- package/dist/runtime-host-tui-owner.js +226 -0
- package/dist/tui-copy-catalog.js +140 -3
- package/dist/tui-host-owner-copy.js +24 -0
- package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
- package/node_modules/@maka/core/dist/canonical-runtime-event.js +3 -1
- package/node_modules/@maka/core/dist/model-failure.js +40 -0
- package/node_modules/@maka/core/dist/model-metadata.generated.js +4 -4
- package/node_modules/@maka/core/dist/model-metadata.js +3 -3
- package/node_modules/@maka/core/dist/model-web-search.js +5 -4
- package/node_modules/@maka/core/dist/provider-registry.js +45 -4
- package/node_modules/@maka/core/dist/record-schema.js +9 -2
- package/node_modules/@maka/core/dist/runtime-boundary.js +31 -11
- package/node_modules/@maka/core/dist/runtime-event.js +37 -6
- package/node_modules/@maka/core/dist/runtime-handoff.js +98 -0
- package/node_modules/@maka/core/dist/runtime-invocation.js +1 -1
- package/node_modules/@maka/core/dist/runtime-logical-execution.js +112 -0
- package/node_modules/@maka/core/dist/session.js +54 -52
- package/node_modules/@maka/core/dist/slash-command-catalog.js +2 -0
- package/node_modules/@maka/core/dist/tool-result-archive-evidence.js +20 -0
- package/node_modules/@maka/core/dist/usage-record-schema.js +26 -35
- package/node_modules/@maka/core/package.json +4 -0
- package/node_modules/@maka/mcp/dist/index.js +131 -1
- package/node_modules/@maka/runtime/dist/agent-run.js +272 -105
- package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +13 -5
- package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +109 -34
- package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +127 -133
- package/node_modules/@maka/runtime/dist/context-budget.js +14 -9
- package/node_modules/@maka/runtime/dist/conversation-copy.js +5 -4
- package/node_modules/@maka/runtime/dist/goal-continuation.js +36 -4
- package/node_modules/@maka/runtime/dist/history-compact-checkpoint.js +18 -9
- package/node_modules/@maka/runtime/dist/history-compact-summarizer.js +30 -22
- package/node_modules/@maka/runtime/dist/history-compaction.js +29 -4
- package/node_modules/@maka/runtime/dist/ledger-tool-result-archive-reader.js +106 -0
- package/node_modules/@maka/runtime/dist/message-authority.js +9 -0
- package/node_modules/@maka/runtime/dist/model-adapter.js +19 -98
- package/node_modules/@maka/runtime/dist/model-factory.js +19 -81
- package/node_modules/@maka/runtime/dist/model-fetcher.js +7 -0
- package/node_modules/@maka/runtime/dist/model-runtime.js +85 -111
- package/node_modules/@maka/runtime/dist/native-web-search-tool.js +2 -1
- package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +2 -2
- package/node_modules/@maka/runtime/dist/opencode-session-header.js +4 -2
- package/node_modules/@maka/runtime/dist/provider-error-classification.js +84 -123
- package/node_modules/@maka/runtime/dist/provider-request-telemetry.js +68 -108
- package/node_modules/@maka/runtime/dist/run-handoff-gate.js +97 -0
- package/node_modules/@maka/runtime/dist/runtime-event-backfill.js +82 -54
- package/node_modules/@maka/runtime/dist/runtime-event-read-model.js +117 -159
- package/node_modules/@maka/runtime/dist/runtime-kernel.js +150 -112
- package/node_modules/@maka/runtime/dist/runtime-ledger-repair.js +160 -79
- package/node_modules/@maka/runtime/dist/runtime-read-model.js +30 -89
- package/node_modules/@maka/runtime/dist/runtime-resume.js +80 -4
- package/node_modules/@maka/runtime/dist/session-event-runtime-mapper.js +5 -0
- package/node_modules/@maka/runtime/dist/session-manager.js +171 -288
- package/node_modules/@maka/runtime/dist/session-projection-helpers.js +0 -27
- package/node_modules/@maka/runtime/dist/subscription-model-fetch.js +3 -4
- package/node_modules/@maka/runtime/dist/test-connection.js +16 -16
- package/node_modules/@maka/runtime/dist/tool-result-archive-encoding.js +38 -0
- package/node_modules/@maka/runtime/dist/tool-runtime.js +3 -61
- package/node_modules/@maka/runtime/package.json +1 -0
- package/node_modules/@maka/runtime-host/dist/adapter/session-projector.js +35 -0
- package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +9 -1
- package/node_modules/@maka/runtime-host/dist/client/connection.js +3 -0
- package/node_modules/@maka/runtime-host/dist/client/host-handoff-copy.js +156 -0
- package/node_modules/@maka/runtime-host/dist/client/host-handoff.js +273 -0
- package/node_modules/@maka/runtime-host/dist/client/host-retirement.js +26 -5
- package/node_modules/@maka/runtime-host/dist/client/index.js +2 -0
- package/node_modules/@maka/runtime-host/dist/client/launcher.js +3 -0
- package/node_modules/@maka/runtime-host/dist/client/remote-compatibility-error.js +2 -0
- package/node_modules/@maka/runtime-host/dist/client/session-subscription.js +27 -5
- package/node_modules/@maka/runtime-host/dist/operator/index.js +2 -1
- package/node_modules/@maka/runtime-host/dist/operator/retirement-cancellation.js +20 -0
- package/node_modules/@maka/runtime-host/dist/protocol/host-status.js +21 -12
- package/node_modules/@maka/runtime-host/dist/protocol/index.js +25 -1
- package/node_modules/@maka/runtime-host/dist/protocol/operations.js +1 -0
- package/node_modules/@maka/runtime-host/dist/protocol/session-continuity.js +40 -20
- package/node_modules/@maka/runtime-host/dist/protocol/session-transcript.js +0 -5
- package/node_modules/@maka/runtime-host/dist/protocol/session-turns.js +29 -58
- package/node_modules/@maka/runtime-host/dist/protocol/turn.js +11 -1
- package/node_modules/@maka/runtime-host/dist/server/access-credential-store.js +1 -0
- package/node_modules/@maka/runtime-host/dist/server/canonical-turn-snapshot.js +19 -4
- package/node_modules/@maka/runtime-host/dist/server/connection-session.js +7 -6
- package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +100 -24
- package/node_modules/@maka/runtime-host/dist/server/execution-model-authority.js +5 -5
- package/node_modules/@maka/runtime-host/dist/server/execution-model-composition.js +3 -2
- package/node_modules/@maka/runtime-host/dist/server/goal-coordinator.js +40 -1
- package/node_modules/@maka/runtime-host/dist/server/host-kernel.js +96 -17
- package/node_modules/@maka/runtime-host/dist/server/host-residency-registry.js +13 -7
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-admission-registry.js +3 -1
- package/node_modules/@maka/runtime-host/dist/server/hosted-execution-recovery.js +124 -62
- package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +76 -6
- package/node_modules/@maka/runtime-host/dist/server/root-turn-coordinator.js +325 -73
- package/node_modules/@maka/runtime-host/dist/server/scheduled-task-coordinator.js +37 -2
- package/node_modules/@maka/runtime-host/dist/server/serial-outbound-writer.js +45 -3
- package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +50 -7
- package/node_modules/@maka/runtime-host/dist/server/session-continuity-coordinator.js +87 -25
- package/node_modules/@maka/runtime-host/dist/server/session-revision-coordinator.js +8 -55
- package/node_modules/@maka/runtime-host/dist/server/session-sidecar-purge.js +1 -16
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-pager.js +0 -1
- package/node_modules/@maka/runtime-host/dist/server/session-transcript-reader.js +460 -70
- package/node_modules/@maka/runtime-host/dist/server/shared-session-transcript.js +1 -1
- package/node_modules/@maka/runtime-host/dist/server/storage-maintenance.js +109 -0
- package/node_modules/@maka/runtime-host/dist/server/workhub-coordination-coordinator.js +0 -1
- package/node_modules/@maka/storage/dist/artifact-store.js +21 -10
- package/node_modules/@maka/storage/dist/artifact-stores.js +1 -1
- package/node_modules/@maka/storage/dist/claude-code-session-adapter.js +0 -4
- package/node_modules/@maka/storage/dist/codex-session-adapter.js +0 -2
- package/node_modules/@maka/storage/dist/context-offload-snapshot.js +325 -0
- package/node_modules/@maka/storage/dist/execution-stores.js +9 -7
- package/node_modules/@maka/storage/dist/file-session-repository.js +1012 -0
- package/node_modules/@maka/storage/dist/opencode-session-adapter.js +0 -4
- package/node_modules/@maka/storage/dist/operational-state-backup.js +9 -5
- package/node_modules/@maka/storage/dist/runtime-event-persistence.js +1 -0
- package/node_modules/@maka/storage/dist/runtime-transcript-query.js +308 -0
- package/node_modules/@maka/storage/dist/session-bundle-policy.js +24 -4
- package/node_modules/@maka/storage/dist/session-message-projection.js +15 -0
- package/node_modules/@maka/storage/dist/session-repository.js +767 -0
- package/node_modules/@maka/storage/dist/session-store.js +25 -99
- package/node_modules/@maka/storage/dist/sqlite-artifact-metadata.js +10 -3
- package/node_modules/@maka/storage/dist/sqlite-context-offload-store.js +24 -8
- package/node_modules/@maka/storage/dist/sqlite-core-execution-schema.js +7 -1
- package/node_modules/@maka/storage/dist/sqlite-runtime-schema.js +44 -1
- package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +129 -25
- package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +109 -892
- package/node_modules/@maka/storage/dist/tool-result-archive-evidence.js +111 -0
- package/node_modules/@maka/storage/package.json +2 -0
- package/package.json +1 -1
|
@@ -17,8 +17,9 @@
|
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
19
|
import { RetryError } from 'ai';
|
|
20
|
+
import { MODEL_FAILURE_MESSAGE_MAX_BYTES } from '@maka/core/model-failure';
|
|
20
21
|
import { truncateUtf8 } from '@maka/core/diagnostic-log';
|
|
21
|
-
import { isAuthenticationErrorText
|
|
22
|
+
import { isAuthenticationErrorText } from '@maka/core/redaction';
|
|
22
23
|
/**
|
|
23
24
|
* Structured provider error identifiers that mean the INPUT exceeded the
|
|
24
25
|
* model's context window. These come from the provider's error JSON and are
|
|
@@ -80,7 +81,6 @@ const USAGE_LIMIT_TEXT_PATTERNS = [
|
|
|
80
81
|
/(?:credit|balance|allowance)[^.]{0,40}(?:exhaust|reached)|exhaust[^.]{0,20}(?:credit|balance)/i,
|
|
81
82
|
/subscription/i,
|
|
82
83
|
];
|
|
83
|
-
const PROVIDER_FAILURE_SUMMARY_MAX_BYTES = 2 * 1024;
|
|
84
84
|
const PROVIDER_FAILURE_FIELD_MAX_BYTES = 256;
|
|
85
85
|
const MAX_SAFE_TIMER_DELAY_MS = 2_147_483_647;
|
|
86
86
|
const OPENAI_RESPONSES_WEBSOCKET_TRANSPORT_ERROR = 'OPENAI_RESPONSES_WEBSOCKET_TRANSPORT_ERROR';
|
|
@@ -153,13 +153,8 @@ function parseRetryAfterMs(headers) {
|
|
|
153
153
|
return null;
|
|
154
154
|
return Math.ceil(delayMs);
|
|
155
155
|
}
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
* response headers across the ModelAdapter boundary.
|
|
159
|
-
*/
|
|
160
|
-
export function providerRetryMetadata(error) {
|
|
161
|
-
const facts = normalizeProviderError(error);
|
|
162
|
-
if (!facts)
|
|
156
|
+
function retryMetadataFromFacts(facts, errorClass = classifyProviderFacts(facts)) {
|
|
157
|
+
if (facts.aborted)
|
|
163
158
|
return { retryable: false };
|
|
164
159
|
const { evidence } = facts;
|
|
165
160
|
if (RUNTIME_RETRYABLE_ERROR_CODES.has(evidence.code))
|
|
@@ -169,9 +164,8 @@ export function providerRetryMetadata(error) {
|
|
|
169
164
|
if (isTrustedCodexEdgeRejection(facts))
|
|
170
165
|
return { retryable: false };
|
|
171
166
|
const status = Number(evidence.statusCode || evidence.code);
|
|
172
|
-
const errorClass = classifyProviderFacts(facts);
|
|
173
167
|
const retryAfterMs = parseRetryAfterMs(facts.responseHeaders ?? {});
|
|
174
|
-
if (errorClass === '
|
|
168
|
+
if (errorClass === 'provider_capacity') {
|
|
175
169
|
// Capacity is transient even when the provider sends a malformed delay;
|
|
176
170
|
// fall back to the adapter's bounded local backoff in that case.
|
|
177
171
|
return {
|
|
@@ -179,13 +173,13 @@ export function providerRetryMetadata(error) {
|
|
|
179
173
|
...(retryAfterMs !== undefined && retryAfterMs !== null ? { retryAfterMs } : {}),
|
|
180
174
|
};
|
|
181
175
|
}
|
|
182
|
-
if (errorClass === '
|
|
176
|
+
if (errorClass === 'rate_limit' || status === 429) {
|
|
183
177
|
if (retryAfterMs === undefined || retryAfterMs === null)
|
|
184
178
|
return { retryable: false };
|
|
185
179
|
return { retryable: true, retryAfterMs };
|
|
186
180
|
}
|
|
187
|
-
const retryable = errorClass === '
|
|
188
|
-
errorClass === '
|
|
181
|
+
const retryable = errorClass === 'network' ||
|
|
182
|
+
errorClass === 'provider_unavailable' ||
|
|
189
183
|
status === 408 ||
|
|
190
184
|
status === 409 ||
|
|
191
185
|
(status >= 500 && status <= 599);
|
|
@@ -312,15 +306,7 @@ function normalizeProviderError(error) {
|
|
|
312
306
|
}
|
|
313
307
|
return undefined;
|
|
314
308
|
}
|
|
315
|
-
|
|
316
|
-
* Retains only allowlisted provider failure fields. The provider value may also
|
|
317
|
-
* contain request bodies, headers, or credentials, so it must never be copied
|
|
318
|
-
* or serialized as diagnostic output wholesale.
|
|
319
|
-
*/
|
|
320
|
-
export function providerFailureSummary(error) {
|
|
321
|
-
const facts = normalizeProviderError(error);
|
|
322
|
-
if (!facts)
|
|
323
|
-
return undefined;
|
|
309
|
+
function failureSummaryFromFacts(facts) {
|
|
324
310
|
const sources = facts.summarySources;
|
|
325
311
|
const message = firstProviderMessage(facts);
|
|
326
312
|
const code = firstProviderField(sources, ['code']) ?? firstProviderField(sources, ['type']);
|
|
@@ -335,41 +321,25 @@ export function providerFailureSummary(error) {
|
|
|
335
321
|
if (!message && metadata.length === 0)
|
|
336
322
|
return undefined;
|
|
337
323
|
const suffix = metadata.length > 0 ? ` (${metadata.join(', ')})` : '';
|
|
338
|
-
const messageBudget = Math.max(1,
|
|
339
|
-
const summary = `${truncateUtf8(
|
|
324
|
+
const messageBudget = Math.max(1, MODEL_FAILURE_MESSAGE_MAX_BYTES - Buffer.byteLength(suffix, 'utf8'));
|
|
325
|
+
const summary = `${truncateUtf8(message ?? 'Provider request failed', messageBudget, '…')}${suffix}`;
|
|
340
326
|
return {
|
|
341
|
-
message: truncateUtf8(summary,
|
|
327
|
+
message: truncateUtf8(summary, MODEL_FAILURE_MESSAGE_MAX_BYTES, '…'),
|
|
342
328
|
...(code || statusCode ? { code: code ?? statusCode } : {}),
|
|
343
329
|
};
|
|
344
330
|
}
|
|
345
|
-
const DURABLE_PROVIDER_ERROR_CLASSES = new Set([
|
|
346
|
-
'Abort',
|
|
347
|
-
'Auth',
|
|
348
|
-
'ContextLength',
|
|
349
|
-
'Network',
|
|
350
|
-
'ProviderCapacity',
|
|
351
|
-
'ProviderBilling',
|
|
352
|
-
'ProviderUnavailable',
|
|
353
|
-
'RateLimit',
|
|
354
|
-
'Timeout',
|
|
355
|
-
]);
|
|
356
331
|
/**
|
|
357
332
|
* Projects provider errors into a small durable fingerprint. Unlike the
|
|
358
333
|
* presentation summary, this intentionally excludes provider messages and
|
|
359
|
-
* response bodies:
|
|
334
|
+
* response bodies: free text can echo prompts or credentials.
|
|
360
335
|
*/
|
|
361
336
|
export function providerFailureDiagnostic(error) {
|
|
362
|
-
const facts =
|
|
337
|
+
const facts = extractProviderErrorFacts(error);
|
|
363
338
|
if (!facts)
|
|
364
|
-
return { errorClass: '
|
|
339
|
+
return { errorClass: 'unknown', retryable: false };
|
|
365
340
|
const sources = facts.summarySources;
|
|
366
|
-
const
|
|
367
|
-
const
|
|
368
|
-
const httpStatus = Number.isInteger(numericStatus) && numericStatus >= 100 && numericStatus <= 599
|
|
369
|
-
? numericStatus
|
|
370
|
-
: undefined;
|
|
371
|
-
const classified = classifyProviderFacts(facts);
|
|
372
|
-
const errorClass = durableProviderErrorClass(facts, classified, httpStatus);
|
|
341
|
+
const httpStatus = providerHttpStatus(facts);
|
|
342
|
+
const errorClass = classifyProviderFacts(facts);
|
|
373
343
|
const providerCode = firstProviderField(sources, ['code']) ?? firstProviderField(sources, ['type']);
|
|
374
344
|
const providerRequestId = firstProviderField(sources, ['requestId', 'request_id']) ??
|
|
375
345
|
boundedProviderField(facts.responseHeaders?.['x-request-id']);
|
|
@@ -378,36 +348,14 @@ export function providerFailureDiagnostic(error) {
|
|
|
378
348
|
...(httpStatus !== undefined ? { httpStatus } : {}),
|
|
379
349
|
...(providerCode !== undefined ? { providerCode } : {}),
|
|
380
350
|
...(providerRequestId !== undefined ? { providerRequestId } : {}),
|
|
381
|
-
retryable:
|
|
351
|
+
retryable: retryMetadataFromFacts(facts, errorClass).retryable,
|
|
382
352
|
};
|
|
383
353
|
}
|
|
384
|
-
function
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
classified === 'ProviderCapacity' ||
|
|
389
|
-
(classified === 'ProviderUnavailable' && isTrustedCodexEdgeRejection(facts))) {
|
|
390
|
-
return classified;
|
|
391
|
-
}
|
|
392
|
-
if (httpStatus === 401 || httpStatus === 403)
|
|
393
|
-
return 'Auth';
|
|
394
|
-
if (httpStatus === 402)
|
|
395
|
-
return 'ProviderBilling';
|
|
396
|
-
if (httpStatus === 408)
|
|
397
|
-
return 'Timeout';
|
|
398
|
-
if (httpStatus === 413)
|
|
399
|
-
return 'ContextLength';
|
|
400
|
-
if (httpStatus === 429)
|
|
401
|
-
return 'RateLimit';
|
|
402
|
-
if (httpStatus !== undefined && httpStatus >= 400 && httpStatus <= 499) {
|
|
403
|
-
return 'RequestRejected';
|
|
404
|
-
}
|
|
405
|
-
if (httpStatus !== undefined && httpStatus >= 500 && httpStatus <= 599) {
|
|
406
|
-
return 'ProviderUnavailable';
|
|
354
|
+
function extractProviderErrorFacts(error) {
|
|
355
|
+
if (RetryError.isInstance(error) && error.reason === 'abort') {
|
|
356
|
+
const facts = normalizeProviderError(error);
|
|
357
|
+
return facts ? { ...facts, aborted: true } : undefined;
|
|
407
358
|
}
|
|
408
|
-
return DURABLE_PROVIDER_ERROR_CLASSES.has(classified) ? classified : 'Other';
|
|
409
|
-
}
|
|
410
|
-
function providerFailureDiagnosticFacts(error) {
|
|
411
359
|
let current = providerErrorTarget(error);
|
|
412
360
|
let fallback;
|
|
413
361
|
let codedFallback;
|
|
@@ -503,7 +451,7 @@ function boundedProviderField(value) {
|
|
|
503
451
|
const normalized = String(value).trim();
|
|
504
452
|
if (!normalized)
|
|
505
453
|
return undefined;
|
|
506
|
-
return truncateUtf8(
|
|
454
|
+
return truncateUtf8(normalized, PROVIDER_FAILURE_FIELD_MAX_BYTES, '…');
|
|
507
455
|
}
|
|
508
456
|
function boundedProviderMessage(value, parseJson = true) {
|
|
509
457
|
if (typeof value !== 'string')
|
|
@@ -531,7 +479,7 @@ function boundedProviderMessage(value, parseJson = true) {
|
|
|
531
479
|
}
|
|
532
480
|
if (!normalized)
|
|
533
481
|
return undefined;
|
|
534
|
-
return truncateUtf8(
|
|
482
|
+
return truncateUtf8(normalized, MODEL_FAILURE_MESSAGE_MAX_BYTES, '…');
|
|
535
483
|
}
|
|
536
484
|
/**
|
|
537
485
|
* Provider context-length overflow signatures. A request-level 400/413 whose
|
|
@@ -633,76 +581,111 @@ export function isContextOverflowErrorText(text) {
|
|
|
633
581
|
* wrap a provider failure in a misleading status or message; the weak
|
|
634
582
|
* heuristics rank last so "generate" can never become a rate limit.
|
|
635
583
|
*/
|
|
584
|
+
export function providerModelFailure(error) {
|
|
585
|
+
const facts = extractProviderErrorFacts(error);
|
|
586
|
+
const kind = facts ? classifyProviderFacts(facts) : 'unknown';
|
|
587
|
+
const summary = facts ? failureSummaryFromFacts(facts) : undefined;
|
|
588
|
+
const retry = facts ? retryMetadataFromFacts(facts, kind) : { retryable: false };
|
|
589
|
+
return {
|
|
590
|
+
type: 'model_failure',
|
|
591
|
+
kind,
|
|
592
|
+
...retry,
|
|
593
|
+
...(summary?.code !== undefined ? { code: summary.code } : {}),
|
|
594
|
+
message: summary?.message ?? 'Model request failed',
|
|
595
|
+
};
|
|
596
|
+
}
|
|
636
597
|
export function classifyError(error) {
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
const facts = normalizeProviderError(error);
|
|
640
|
-
return facts ? classifyProviderFacts(facts) : 'Other';
|
|
598
|
+
const facts = extractProviderErrorFacts(error);
|
|
599
|
+
return facts ? classifyProviderFacts(facts) : 'unknown';
|
|
641
600
|
}
|
|
642
601
|
function classifyProviderFacts(facts) {
|
|
643
|
-
|
|
602
|
+
if (facts.aborted)
|
|
603
|
+
return 'abort';
|
|
604
|
+
const { evidence } = facts;
|
|
644
605
|
const { text, statusCode, code, structuredCodes } = evidence;
|
|
645
606
|
const normalizedCode = code.toLowerCase();
|
|
646
607
|
if (code === OPENAI_RESPONSES_WEBSOCKET_TRANSPORT_ERROR)
|
|
647
|
-
return '
|
|
608
|
+
return 'network';
|
|
648
609
|
if (PROVIDER_CAPACITY_CODES.has(normalizedCode) ||
|
|
649
610
|
structuredCodes.some((c) => PROVIDER_CAPACITY_CODES.has(c))) {
|
|
650
|
-
return '
|
|
611
|
+
return 'provider_capacity';
|
|
651
612
|
}
|
|
652
613
|
// Structured provider evidence: the parsed error JSON's code/type is the
|
|
653
614
|
// only unconditional signal for a context overflow.
|
|
654
615
|
if (structuredCodes.some((c) => CONTEXT_OVERFLOW_PROVIDER_CODES.has(c)))
|
|
655
|
-
return '
|
|
616
|
+
return 'context_overflow';
|
|
656
617
|
if (PROVIDER_BILLING_PROVIDER_CODES.has(normalizedCode) ||
|
|
657
618
|
structuredCodes.some((c) => PROVIDER_BILLING_PROVIDER_CODES.has(c))) {
|
|
658
|
-
return '
|
|
619
|
+
return 'provider_billing';
|
|
659
620
|
}
|
|
660
621
|
if (text.includes('abort'))
|
|
661
|
-
return '
|
|
622
|
+
return 'abort';
|
|
662
623
|
if (statusCode === '402' || code === '402')
|
|
663
|
-
return '
|
|
624
|
+
return 'provider_billing';
|
|
664
625
|
if (statusCode === '429' || code === '429')
|
|
665
|
-
return '
|
|
626
|
+
return 'rate_limit';
|
|
666
627
|
if (structuredCodes.includes(OPENAI_CODEX_EDGE_REJECTION_CODE) &&
|
|
667
628
|
isTrustedCodexEdgeRejection(facts)) {
|
|
668
|
-
return '
|
|
629
|
+
return 'provider_unavailable';
|
|
669
630
|
}
|
|
670
631
|
if (statusCode === '401' || statusCode === '403' || code === '401' || code === '403') {
|
|
671
632
|
// Credential-shaped statuses can still carry account-level usage
|
|
672
633
|
// evidence: an exhausted plan/credit window for a validly signed-in
|
|
673
634
|
// user must not tell them to re-authenticate (#2516).
|
|
674
635
|
if (USAGE_LIMIT_TEXT_PATTERNS.some((pattern) => pattern.test(text))) {
|
|
675
|
-
return '
|
|
636
|
+
return 'provider_billing';
|
|
676
637
|
}
|
|
677
|
-
return '
|
|
638
|
+
return 'auth';
|
|
678
639
|
}
|
|
679
640
|
if (statusCode === '413' || code === '413')
|
|
680
|
-
return '
|
|
641
|
+
return 'context_overflow';
|
|
681
642
|
// Free-text overflow relations on the composite text, veto-first inside.
|
|
682
643
|
if (isContextOverflowErrorText(text))
|
|
683
|
-
return '
|
|
644
|
+
return 'context_overflow';
|
|
684
645
|
if (/^5\d\d$/.test(statusCode) || /^5\d\d$/.test(code))
|
|
685
|
-
return '
|
|
646
|
+
return 'provider_unavailable';
|
|
686
647
|
if (structuredCodes.some((c) => PROVIDER_UNAVAILABLE_PROVIDER_CODES.has(c))) {
|
|
687
|
-
return '
|
|
648
|
+
return 'provider_unavailable';
|
|
688
649
|
}
|
|
689
650
|
if (evidence.transportFailure)
|
|
690
|
-
return '
|
|
651
|
+
return 'network';
|
|
652
|
+
if (isTruncatedStreamText(text))
|
|
653
|
+
return 'stream_truncated';
|
|
654
|
+
const httpStatus = providerHttpStatus(facts);
|
|
655
|
+
if (httpStatus === 408)
|
|
656
|
+
return 'timeout';
|
|
657
|
+
if (httpStatus !== undefined && httpStatus >= 500 && httpStatus <= 599) {
|
|
658
|
+
return 'provider_unavailable';
|
|
659
|
+
}
|
|
660
|
+
if (httpStatus !== undefined && httpStatus >= 400 && httpStatus <= 499) {
|
|
661
|
+
return 'request_rejected';
|
|
662
|
+
}
|
|
691
663
|
// Weak word heuristics, last: they only catch errors that carried no
|
|
692
664
|
// stronger evidence for any other class. `rate` must be word-shaped
|
|
693
665
|
// ("generate"/"separate" are not rate limits) while still matching the
|
|
694
666
|
// rate_limit/RateLimitError identifier spellings.
|
|
695
667
|
if (/\brate\b|rate[_-]?limit/.test(text))
|
|
696
|
-
return '
|
|
668
|
+
return 'rate_limit';
|
|
697
669
|
if (isAuthenticationErrorText(text))
|
|
698
|
-
return '
|
|
670
|
+
return 'auth';
|
|
699
671
|
if (text.includes('timeout'))
|
|
700
|
-
return '
|
|
672
|
+
return 'timeout';
|
|
701
673
|
if (text.includes('network') ||
|
|
702
674
|
text.includes('fetch') ||
|
|
703
675
|
/\btypeerror\b.*\bterminated\b/.test(text))
|
|
704
|
-
return '
|
|
705
|
-
return
|
|
676
|
+
return 'network';
|
|
677
|
+
return 'unknown';
|
|
678
|
+
}
|
|
679
|
+
function isTruncatedStreamText(text) {
|
|
680
|
+
return (text.includes('response stream ended without a finish reason') ||
|
|
681
|
+
text.includes('model stream ended without a finish chunk') ||
|
|
682
|
+
(text.includes('stream disconnected before completion') &&
|
|
683
|
+
text.includes('stream closed before response.completed')));
|
|
684
|
+
}
|
|
685
|
+
function providerHttpStatus(facts) {
|
|
686
|
+
const raw = facts.evidence.statusCode || firstProviderField(facts.summarySources, ['statusCode', 'status']);
|
|
687
|
+
const numeric = Number(raw);
|
|
688
|
+
return Number.isInteger(numeric) && numeric >= 100 && numeric <= 599 ? numeric : undefined;
|
|
706
689
|
}
|
|
707
690
|
function isTrustedCodexEdgeRejection(facts) {
|
|
708
691
|
let current = facts.target;
|
|
@@ -718,25 +701,3 @@ function isTrustedCodexEdgeRejection(facts) {
|
|
|
718
701
|
}
|
|
719
702
|
return false;
|
|
720
703
|
}
|
|
721
|
-
export function errorPresentationFromClass(errorClass) {
|
|
722
|
-
switch (errorClass) {
|
|
723
|
-
case 'ContextLength':
|
|
724
|
-
return { reason: 'context_overflow', message: 'Context window exceeded' };
|
|
725
|
-
case 'Timeout':
|
|
726
|
-
return { reason: 'timeout', message: 'Request timed out' };
|
|
727
|
-
case 'Auth':
|
|
728
|
-
return { reason: 'auth', message: 'Authentication failed' };
|
|
729
|
-
case 'ProviderBilling':
|
|
730
|
-
return { reason: 'provider_billing', message: 'Provider billing required' };
|
|
731
|
-
case 'ProviderCapacity':
|
|
732
|
-
return { reason: 'provider_capacity', message: 'Model service is temporarily at capacity' };
|
|
733
|
-
case 'ProviderUnavailable':
|
|
734
|
-
return { reason: 'provider_unavailable', message: 'Provider returned an error' };
|
|
735
|
-
case 'RateLimit':
|
|
736
|
-
return { reason: 'rate_limit', message: 'Rate limit exceeded' };
|
|
737
|
-
case 'Network':
|
|
738
|
-
return { reason: 'network', message: 'Network error' };
|
|
739
|
-
default:
|
|
740
|
-
return {};
|
|
741
|
-
}
|
|
742
|
-
}
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
import { MODEL_CALL_ATTEMPT_SCHEMA_VERSION, } from '@maka/core/model-call-attempt';
|
|
20
20
|
import { preparedPromptComposition } from './request-shape.js';
|
|
21
21
|
import { rawFinishReasonString } from './model-protocol.js';
|
|
22
|
-
import { providerFailureDiagnostic
|
|
22
|
+
import { providerFailureDiagnostic } from './provider-error-classification.js';
|
|
23
23
|
import { latestContextProjectionInput } from './latest-context-snapshot.js';
|
|
24
24
|
import { computeCost } from './telemetry/cost.js';
|
|
25
25
|
/** Session-scoped construction and pricing for physical provider requests. */
|
|
@@ -149,6 +149,9 @@ export function withProviderStreamTracking(input) {
|
|
|
149
149
|
params,
|
|
150
150
|
...(input.abortSignal ? { abortSignal: input.abortSignal } : {}),
|
|
151
151
|
...(input.historyCompactRoute ? { historyCompactRoute: input.historyCompactRoute } : {}),
|
|
152
|
+
...(input.historyCompactBoundary
|
|
153
|
+
? { historyCompactBoundary: input.historyCompactBoundary }
|
|
154
|
+
: {}),
|
|
152
155
|
doStream,
|
|
153
156
|
}),
|
|
154
157
|
},
|
|
@@ -329,36 +332,72 @@ export class ProviderRequestTracker {
|
|
|
329
332
|
const usage = strictProviderRequestUsage(finish?.usage);
|
|
330
333
|
const contextWindow = positiveInteger(this.input.contextWindow);
|
|
331
334
|
const failure = finish?.error !== undefined ? providerFailureDiagnostic(finish.error) : undefined;
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
attemptId,
|
|
335
|
-
turnId: this.input.turnId,
|
|
336
|
-
step,
|
|
337
|
-
attempt,
|
|
338
|
-
providerId: input.providerId,
|
|
339
|
-
modelId: input.modelId,
|
|
340
|
-
...(contextWindow !== undefined ? { contextWindow } : {}),
|
|
341
|
-
startedAt,
|
|
342
|
-
completedAt,
|
|
343
|
-
status,
|
|
344
|
-
...(finish?.reason !== undefined ? { finishReason: finish.reason } : {}),
|
|
345
|
-
...(failure !== undefined ? { failure } : {}),
|
|
346
|
-
latencyMs: Math.max(0, completedAt - startedAt),
|
|
347
|
-
...(timeToFirstTokenMs !== undefined ? { timeToFirstTokenMs } : {}),
|
|
348
|
-
...(usage ?? {}),
|
|
349
|
-
};
|
|
335
|
+
const finishReason = finish?.reason;
|
|
336
|
+
const firstTokenMs = timeToFirstTokenMs;
|
|
350
337
|
accountingSettlement = accountingSettlement.then(async () => {
|
|
351
|
-
|
|
338
|
+
const accounting = this.input.accounting;
|
|
339
|
+
if (!accounting)
|
|
340
|
+
return;
|
|
341
|
+
const runId = accounting.resolveRunId();
|
|
342
|
+
if (runId === undefined)
|
|
343
|
+
return;
|
|
344
|
+
const usageBasis = resolveUsageBasis(usage);
|
|
345
|
+
const cost = usage ? accounting.resolveCost?.(usage) : undefined;
|
|
346
|
+
const priced = cost?.costUsd !== undefined;
|
|
347
|
+
const record = {
|
|
348
|
+
schemaVersion: MODEL_CALL_ATTEMPT_SCHEMA_VERSION,
|
|
352
349
|
logicalCallId,
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
350
|
+
attemptId,
|
|
351
|
+
traceId: this.input.traceId,
|
|
352
|
+
sessionId: accounting.sessionId,
|
|
353
|
+
runId,
|
|
354
|
+
turnId: this.input.turnId,
|
|
355
|
+
...(accounting.connectionSlug !== undefined
|
|
356
|
+
? { connectionSlug: accounting.connectionSlug }
|
|
357
|
+
: {}),
|
|
358
|
+
step: Math.max(0, step),
|
|
359
|
+
attempt: Math.max(0, attempt - 1),
|
|
360
|
+
callKind: accounting.callKind,
|
|
361
|
+
...((input.historyCompactRoute ?? accounting.historyCompactRoute) !== undefined
|
|
362
|
+
? { historyCompactRoute: input.historyCompactRoute ?? accounting.historyCompactRoute }
|
|
363
|
+
: {}),
|
|
364
|
+
providerId: accounting.providerId ?? input.providerId,
|
|
365
|
+
modelId: input.modelId,
|
|
366
|
+
...(contextWindow !== undefined ? { contextWindow } : {}),
|
|
367
|
+
...(composition ? { promptComposition: composition } : {}),
|
|
368
|
+
startedAt,
|
|
369
|
+
completedAt,
|
|
370
|
+
latencyMs: Math.max(0, completedAt - startedAt),
|
|
371
|
+
...(firstTokenMs !== undefined ? { timeToFirstTokenMs: firstTokenMs } : {}),
|
|
372
|
+
status,
|
|
373
|
+
...(finishReason !== undefined ? { finishReason } : {}),
|
|
374
|
+
...(failure ?? {}),
|
|
375
|
+
usageBasis,
|
|
376
|
+
...(usageBasis === 'missing' ? {} : modelCallUsageFields(usage)),
|
|
377
|
+
costBasis: priced ? 'priced' : 'unpriced',
|
|
378
|
+
...(priced
|
|
379
|
+
? {
|
|
380
|
+
costUsd: cost?.costUsd,
|
|
381
|
+
...(cost?.pricingRevision !== undefined
|
|
382
|
+
? { pricingRevision: cost.pricingRevision }
|
|
383
|
+
: {}),
|
|
384
|
+
...(cost?.pricingRates !== undefined ? { pricingRates: cost.pricingRates } : {}),
|
|
385
|
+
}
|
|
386
|
+
: {}),
|
|
387
|
+
};
|
|
388
|
+
// Only a completed MAIN call describes the conversation's own context, so
|
|
389
|
+
// only that one carries the derived row. A failed, aborted or compaction
|
|
390
|
+
// call commits its metering alone and leaves the last answer standing.
|
|
391
|
+
const latestContext = record.callKind === 'main' && record.status === 'completed'
|
|
392
|
+
? latestContextProjectionInput(record, record.promptComposition, input.historyCompactBoundary)
|
|
393
|
+
: undefined;
|
|
394
|
+
try {
|
|
395
|
+
await accounting.record({ attempt: record, ...(latestContext ? { latestContext } : {}) });
|
|
396
|
+
}
|
|
397
|
+
catch {
|
|
398
|
+
// Reported through the run's accounting-incomplete signal by the sink
|
|
399
|
+
// itself. Settlement must not fail the turn the call already completed.
|
|
400
|
+
}
|
|
362
401
|
});
|
|
363
402
|
await accountingSettlement;
|
|
364
403
|
};
|
|
@@ -380,85 +419,6 @@ export class ProviderRequestTracker {
|
|
|
380
419
|
}
|
|
381
420
|
return { observeOutput, finalize };
|
|
382
421
|
}
|
|
383
|
-
/**
|
|
384
|
-
* Projects a settled attempt into the canonical accounting record.
|
|
385
|
-
*
|
|
386
|
-
* Never throws. This runs from the stream's `pull` handler, where a rejection
|
|
387
|
-
* would reach `controller.error` and fail an otherwise-complete model
|
|
388
|
-
* response. The dispatch-time gate is `assertAccountingReady`; a failure here
|
|
389
|
-
* means the call happened and was billed but went unrecorded, which is
|
|
390
|
-
* reported, not raised.
|
|
391
|
-
*/
|
|
392
|
-
async emitModelCallAttempt(record, context) {
|
|
393
|
-
const accounting = this.input.accounting;
|
|
394
|
-
if (!accounting)
|
|
395
|
-
return;
|
|
396
|
-
const runId = accounting.resolveRunId();
|
|
397
|
-
if (runId === undefined)
|
|
398
|
-
return;
|
|
399
|
-
const usage = context.usage;
|
|
400
|
-
const usageBasis = resolveUsageBasis(usage);
|
|
401
|
-
const cost = usage ? accounting.resolveCost?.(usage) : undefined;
|
|
402
|
-
const priced = cost?.costUsd !== undefined;
|
|
403
|
-
const attempt = {
|
|
404
|
-
schemaVersion: MODEL_CALL_ATTEMPT_SCHEMA_VERSION,
|
|
405
|
-
logicalCallId: context.logicalCallId,
|
|
406
|
-
attemptId: record.attemptId,
|
|
407
|
-
traceId: record.traceId,
|
|
408
|
-
sessionId: accounting.sessionId,
|
|
409
|
-
runId,
|
|
410
|
-
turnId: record.turnId,
|
|
411
|
-
...(accounting.connectionSlug !== undefined
|
|
412
|
-
? { connectionSlug: accounting.connectionSlug }
|
|
413
|
-
: {}),
|
|
414
|
-
// The physical ordinals are one-based on the diagnostic record; the
|
|
415
|
-
// canonical record counts retries from zero.
|
|
416
|
-
step: Math.max(0, record.step),
|
|
417
|
-
attempt: Math.max(0, record.attempt - 1),
|
|
418
|
-
callKind: accounting.callKind,
|
|
419
|
-
...(context.historyCompactRoute !== undefined
|
|
420
|
-
? { historyCompactRoute: context.historyCompactRoute }
|
|
421
|
-
: {}),
|
|
422
|
-
providerId: accounting.providerId ?? record.providerId,
|
|
423
|
-
modelId: record.modelId,
|
|
424
|
-
...(context.contextWindow !== undefined ? { contextWindow: context.contextWindow } : {}),
|
|
425
|
-
...(context.promptComposition ? { promptComposition: context.promptComposition } : {}),
|
|
426
|
-
startedAt: record.startedAt,
|
|
427
|
-
completedAt: record.completedAt,
|
|
428
|
-
latencyMs: record.latencyMs,
|
|
429
|
-
...(record.timeToFirstTokenMs !== undefined
|
|
430
|
-
? { timeToFirstTokenMs: record.timeToFirstTokenMs }
|
|
431
|
-
: {}),
|
|
432
|
-
status: record.status,
|
|
433
|
-
...(record.finishReason !== undefined ? { finishReason: record.finishReason } : {}),
|
|
434
|
-
...(record.failure ?? {}),
|
|
435
|
-
usageBasis,
|
|
436
|
-
...(usageBasis === 'missing' ? {} : modelCallUsageFields(usage)),
|
|
437
|
-
costBasis: priced ? 'priced' : 'unpriced',
|
|
438
|
-
...(priced
|
|
439
|
-
? {
|
|
440
|
-
costUsd: cost?.costUsd,
|
|
441
|
-
...(cost?.pricingRevision !== undefined
|
|
442
|
-
? { pricingRevision: cost.pricingRevision }
|
|
443
|
-
: {}),
|
|
444
|
-
...(cost?.pricingRates !== undefined ? { pricingRates: cost.pricingRates } : {}),
|
|
445
|
-
}
|
|
446
|
-
: {}),
|
|
447
|
-
};
|
|
448
|
-
// Only a completed MAIN call describes the conversation's own context, so
|
|
449
|
-
// only that one carries the derived row. A failed, aborted or compaction
|
|
450
|
-
// call commits its metering alone and leaves the last answer standing.
|
|
451
|
-
const latestContext = attempt.callKind === 'main' && attempt.status === 'completed'
|
|
452
|
-
? latestContextProjectionInput(attempt, attempt.promptComposition, context.historyCompactBoundary)
|
|
453
|
-
: undefined;
|
|
454
|
-
try {
|
|
455
|
-
await accounting.record({ attempt, ...(latestContext ? { latestContext } : {}) });
|
|
456
|
-
}
|
|
457
|
-
catch {
|
|
458
|
-
// Reported through the run's accounting-incomplete signal by the sink
|
|
459
|
-
// itself. Settlement must not fail the turn the call already completed.
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
422
|
}
|
|
463
423
|
function throwIfAbortedBeforeDispatch(signal) {
|
|
464
424
|
if (signal?.aborted) {
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
/**
|
|
20
|
+
* One physical Run owns one gate. Before commit, cancellation resumes that same
|
|
21
|
+
* Run without a terminal fact. Durable pause/continuation authority lives in the
|
|
22
|
+
* ledger, never in this in-memory gate.
|
|
23
|
+
*/
|
|
24
|
+
export class RunHandoffGate {
|
|
25
|
+
#pending;
|
|
26
|
+
#closed = false;
|
|
27
|
+
request(signal) {
|
|
28
|
+
if (this.#pending)
|
|
29
|
+
throw new Error('This Run already has a handoff reservation');
|
|
30
|
+
if (this.#closed || signal.aborted) {
|
|
31
|
+
return { ready: Promise.resolve(false), commit: () => false, cancel() { } };
|
|
32
|
+
}
|
|
33
|
+
let markReached;
|
|
34
|
+
let releaseBoundary;
|
|
35
|
+
const cancel = () => {
|
|
36
|
+
this.#settle(pending, 'continue');
|
|
37
|
+
};
|
|
38
|
+
const pending = {
|
|
39
|
+
reached: new Promise((resolve) => {
|
|
40
|
+
markReached = resolve;
|
|
41
|
+
}),
|
|
42
|
+
release: new Promise((resolve) => {
|
|
43
|
+
releaseBoundary = resolve;
|
|
44
|
+
}),
|
|
45
|
+
markReached: (ready) => markReached(ready),
|
|
46
|
+
releaseBoundary: (decision) => releaseBoundary(decision),
|
|
47
|
+
cleanup: () => signal.removeEventListener('abort', cancel),
|
|
48
|
+
atBoundary: false,
|
|
49
|
+
};
|
|
50
|
+
this.#pending = pending;
|
|
51
|
+
signal.addEventListener('abort', cancel, { once: true });
|
|
52
|
+
return {
|
|
53
|
+
ready: pending.reached,
|
|
54
|
+
commit: () => pending.atBoundary && this.#settle(pending, 'pause'),
|
|
55
|
+
cancel,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/** Called only after the preceding step's events and tool outcomes are durable. */
|
|
59
|
+
async reachBoundary(executionSignal) {
|
|
60
|
+
const pending = this.#pending;
|
|
61
|
+
if (!pending)
|
|
62
|
+
return 'continue';
|
|
63
|
+
const abort = () => {
|
|
64
|
+
this.#settle(pending, 'continue');
|
|
65
|
+
};
|
|
66
|
+
if (executionSignal.aborted) {
|
|
67
|
+
abort();
|
|
68
|
+
return 'continue';
|
|
69
|
+
}
|
|
70
|
+
executionSignal.addEventListener('abort', abort, { once: true });
|
|
71
|
+
pending.atBoundary = true;
|
|
72
|
+
pending.markReached(true);
|
|
73
|
+
try {
|
|
74
|
+
return await pending.release;
|
|
75
|
+
}
|
|
76
|
+
finally {
|
|
77
|
+
executionSignal.removeEventListener('abort', abort);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/** Natural completion, user Stop, or failure must never leave a waiter behind. */
|
|
81
|
+
close() {
|
|
82
|
+
this.#closed = true;
|
|
83
|
+
if (this.#pending)
|
|
84
|
+
this.#settle(this.#pending, 'continue');
|
|
85
|
+
}
|
|
86
|
+
#settle(pending, decision) {
|
|
87
|
+
if (this.#pending !== pending)
|
|
88
|
+
return false;
|
|
89
|
+
this.#pending = undefined;
|
|
90
|
+
if (decision === 'pause')
|
|
91
|
+
this.#closed = true;
|
|
92
|
+
pending.cleanup();
|
|
93
|
+
pending.markReached(false);
|
|
94
|
+
pending.releaseBoundary(decision);
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
}
|