maka-agent 0.2.0-dev.34.20260915 → 0.2.0-dev.36.20260915

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.
Files changed (62) hide show
  1. package/native/runtime-host-windows-task-launcher/prebuilds/win32-x64/maka-runtime-host-task-launcher.exe +0 -0
  2. package/node_modules/@maka/core/dist/model-metadata.generated.js +175 -116
  3. package/node_modules/@maka/core/dist/models-dev-projection.js +1 -0
  4. package/node_modules/@maka/core/dist/provider-registry.js +17 -0
  5. package/node_modules/@maka/eval/dist/harbor-maka-subject.js +13 -3
  6. package/node_modules/@maka/eval/dist/maka-artifacts.js +28 -14
  7. package/node_modules/@maka/eval/dist/maka-subject.js +28 -3
  8. package/node_modules/@maka/eval/harbor/relay_agent.py +42 -2
  9. package/node_modules/@maka/runtime/dist/ai-sdk-backend.js +0 -1
  10. package/node_modules/@maka/runtime/dist/ai-sdk-compaction.js +40 -53
  11. package/node_modules/@maka/runtime/dist/ai-sdk-turn.js +28 -47
  12. package/node_modules/@maka/runtime/dist/builtin-tools.js +20 -12
  13. package/node_modules/@maka/runtime/dist/openai-codex-history-compactor.js +1 -2
  14. package/node_modules/@maka/runtime/dist/provider-error-classification.js +29 -38
  15. package/node_modules/@maka/runtime/dist/runtime-kernel.js +1 -0
  16. package/node_modules/@maka/runtime/dist/telemetry/model-pricing.generated.js +144 -77
  17. package/node_modules/@maka/runtime/node_modules/@ai-sdk/code-mode/dist/run-code-mode.js +6 -19
  18. package/node_modules/@maka/runtime-host/dist/client/connect-or-spawn.js +28 -4
  19. package/node_modules/@maka/runtime-host/dist/client/connection.js +20 -2
  20. package/node_modules/@maka/runtime-host/dist/client/hosted-execution-target.js +27 -6
  21. package/node_modules/@maka/runtime-host/dist/client/hosted-execution.js +10 -28
  22. package/node_modules/@maka/runtime-host/dist/client/startup-error.js +1 -1
  23. package/node_modules/@maka/runtime-host/dist/client/wait-for-ready.js +1 -1
  24. package/node_modules/@maka/runtime-host/dist/control/endpoint.js +7 -6
  25. package/node_modules/@maka/runtime-host/dist/execution-candidate-main.js +8 -1
  26. package/node_modules/@maka/runtime-host/dist/protocol/agent-graph.js +1 -11
  27. package/node_modules/@maka/runtime-host/dist/protocol/client-capability.js +2 -2
  28. package/node_modules/@maka/runtime-host/dist/protocol/codec.js +11 -0
  29. package/node_modules/@maka/runtime-host/dist/protocol/index.js +1 -1
  30. package/node_modules/@maka/runtime-host/dist/protocol/workhub-coordination.js +10 -2
  31. package/node_modules/@maka/runtime-host/dist/server/bootstrap-runtime-policy.js +65 -0
  32. package/node_modules/@maka/runtime-host/dist/server/execution-candidate.js +4 -1
  33. package/node_modules/@maka/runtime-host/dist/server/execution-composition-factory.js +9 -3
  34. package/node_modules/@maka/runtime-host/dist/server/execution-composition.js +13 -2
  35. package/node_modules/@maka/runtime-host/dist/server/hosted-execution-tool-profile.js +3 -15
  36. package/node_modules/@maka/runtime-host/dist/server/interactive-run-composer.js +9 -4
  37. package/node_modules/@maka/runtime-host/dist/server/message-coordinator.js +1 -2
  38. package/node_modules/@maka/runtime-host/dist/server/session-catalog-coordinator.js +4 -1
  39. package/node_modules/@maka/runtime-host/dist/server/workhub-message-attachments.js +1 -0
  40. package/node_modules/@maka/storage/dist/agent-run-store-contract.js +945 -0
  41. package/node_modules/@maka/storage/dist/agent-run-store.js +3 -923
  42. package/node_modules/@maka/storage/dist/artifact-store.js +63 -7
  43. package/node_modules/@maka/storage/dist/execution-persistence-provider.js +54 -0
  44. package/node_modules/@maka/storage/dist/execution-stores.js +182 -59
  45. package/node_modules/@maka/storage/dist/goal-authority.js +39 -8
  46. package/node_modules/@maka/storage/dist/graph-control-values.js +126 -0
  47. package/node_modules/@maka/storage/dist/interaction-store-contract.js +231 -0
  48. package/node_modules/@maka/storage/dist/interaction-store.js +62 -217
  49. package/node_modules/@maka/storage/dist/local-execution-persistence.js +80 -0
  50. package/node_modules/@maka/storage/dist/message-admission-store.js +5 -3
  51. package/node_modules/@maka/storage/dist/root-authority.js +4 -0
  52. package/node_modules/@maka/{eval/dist/maka-runtime-policy.js → storage/dist/runtime-event-store-contract.js} +1 -24
  53. package/node_modules/@maka/storage/dist/runtime-partial-values.js +114 -0
  54. package/node_modules/@maka/storage/dist/session-store-contract.js +61 -0
  55. package/node_modules/@maka/storage/dist/session-store-values.js +342 -0
  56. package/node_modules/@maka/storage/dist/session-store.js +7 -351
  57. package/node_modules/@maka/storage/dist/sqlite-runtime-store.js +4 -185
  58. package/node_modules/@maka/storage/dist/sqlite-session-metadata-store.js +23 -135
  59. package/node_modules/@maka/storage/dist/storage-writer-composition.js +2 -3
  60. package/node_modules/@maka/storage/dist/tool-commit-validation.js +111 -0
  61. package/node_modules/@maka/storage/package.json +1 -0
  62. package/package.json +1 -1
@@ -20,6 +20,7 @@ import { DEFAULT_TOOL_MODE, isToolMode } from '@maka/core/tool-mode';
20
20
  import { resolveEffectiveOrchestration, } from '@maka/core/orchestration';
21
21
  import { stripUndefinedDeep } from '@maka/core/tool-args-identity';
22
22
  import { YIELD_AGENT_GRAPH_TOOL_NAME, } from './stream-graph-supervisor-tools.js';
23
+ import { providerRetryReason } from './provider-error-classification.js';
23
24
  import Ajv from 'ajv';
24
25
  import Ajv2019 from 'ajv/dist/2019.js';
25
26
  import Ajv2020 from 'ajv/dist/2020.js';
@@ -355,20 +356,6 @@ function providerRetryDelayMs(failedAttempt, retryAfterMs) {
355
356
  const base = Math.min(PROVIDER_RETRY_BASE_DELAY_MS * 2 ** Math.max(0, failedAttempt - 1), PROVIDER_RETRY_MAX_DELAY_MS);
356
357
  return Math.ceil(base + Math.random() * PROVIDER_RETRY_JITTER_FACTOR * base);
357
358
  }
358
- function providerRetryReason(kind) {
359
- switch (kind) {
360
- case 'stream_truncated':
361
- case 'network':
362
- case 'provider_unavailable':
363
- case 'rate_limit':
364
- case 'timeout':
365
- return kind;
366
- case 'provider_capacity':
367
- return 'provider_capacity';
368
- default:
369
- return 'unknown';
370
- }
371
- }
372
359
  /**
373
360
  * The mutable state of ONE `send()`.
374
361
  *
@@ -739,10 +726,6 @@ export class AiSdkTurn {
739
726
  contextCompactedNoteWritten = await this.recordSystemNote('context_compacted', turnId);
740
727
  }
741
728
  };
742
- // Request index (0-based) at which the active prune last rewrote the
743
- // request. A step Maka pruned is not append-only, so usage may legitimately
744
- // shrink.
745
- let pruneAppliedAtStep;
746
729
  const trace = new RunTrace({
747
730
  sessionId: this.deps.backend.sessionId,
748
731
  turnId,
@@ -901,7 +884,7 @@ export class AiSdkTurn {
901
884
  // Roll-forward seed: the latest durable checkpoint (loaded or written at
902
885
  // turn start) so a mid-turn summary only re-reads the newly folded span.
903
886
  const checkpoint = priorReplay.latestHistoryCompactCheckpoint;
904
- midTurnState.previousCheckpoint =
887
+ midTurnState.seedCheckpoint =
905
888
  checkpoint &&
906
889
  canContinueHistoryCompactCheckpointForModel(checkpoint, this.deps.backend.connection, this.deps.backend.header.llmConnectionId, this.deps.backend.modelId)
907
890
  ? checkpoint
@@ -990,7 +973,7 @@ export class AiSdkTurn {
990
973
  const pruned = await this.deps.compaction.pruneToolResults(turnEvents, turnId);
991
974
  if (pruned.stats) {
992
975
  if (pruned.stats.prunedToolResults > 0)
993
- pruneAppliedAtStep = runtimeSteps;
976
+ midTurnState?.stepShaping.add('prune');
994
977
  contextBudgetForTelemetry = addToolResultPruneStats(contextBudgetForTelemetry ?? minimalContextBudgetDiagnostic(), pruned.stats);
995
978
  }
996
979
  const projectionCheckpoint = midTurnState?.projectionCheckpoint;
@@ -1145,6 +1128,14 @@ export class AiSdkTurn {
1145
1128
  : undefined;
1146
1129
  const projectedMessages = shaped?.messages ?? contextualRequestMessages;
1147
1130
  const activeToolsForRequest = resolveDispatch(shaped?.activeTools).activeTools;
1131
+ // A finalization step resolves an empty tool set, so its request
1132
+ // legitimately drops several thousand schema tokens with no fold,
1133
+ // prune or image omission. Maka shaped that request; the provider did
1134
+ // not drop anything.
1135
+ if (lastStepActiveToolCount !== undefined &&
1136
+ activeToolsForRequest.length < lastStepActiveToolCount) {
1137
+ midTurnState?.stepShaping.add('tools');
1138
+ }
1148
1139
  const requestCompositionId = this.runId && this.deps.backend.recordRequestComposition
1149
1140
  ? await this.deps.backend.recordRequestComposition(this.runId, {
1150
1141
  compositionId: this.deps.newId(),
@@ -1429,12 +1420,6 @@ export class AiSdkTurn {
1429
1420
  // reply's reasoning may not be resent, so input + output is
1430
1421
  // not the floor of the next input on every wire.
1431
1422
  const completedRequestIndex = runtimeSteps - 1;
1432
- // A finalization step resolves an empty tool set, so its
1433
- // request legitimately drops several thousand schema tokens
1434
- // with no fold, prune or image omission. Maka shaped that
1435
- // request; the provider did not drop anything.
1436
- const toolSchemaShrank = lastStepActiveToolCount !== undefined &&
1437
- activeToolsForRequest.length < lastStepActiveToolCount;
1438
1423
  // Across the send boundary the comparison is the same one,
1439
1424
  // against the last request a provider accepted before this
1440
1425
  // send. A provider that truncates to a fixed window reports
@@ -1444,21 +1429,15 @@ export class AiSdkTurn {
1444
1429
  // input tokens across eight turns with nothing reported
1445
1430
  // (#4623). The first request of a send therefore compares
1446
1431
  // against the persisted anchor, which is route-validated
1447
- // where it is read; a fold before that request would explain
1448
- // a smaller input by itself, so it disables the comparison.
1432
+ // where it is read.
1449
1433
  const acrossSends = completedRequestIndex === 0;
1450
1434
  const priorInput = acrossSends
1451
- ? midTurnState?.compactionAppliedThisSend === true
1452
- ? undefined
1453
- : midTurnState?.priorAcceptedInputTokens
1435
+ ? midTurnState?.priorAcceptedInputTokens
1454
1436
  : lastStepInputTokens;
1455
1437
  if (!this.deps.session.contextProviderDroppingReported &&
1456
- !toolSchemaShrank &&
1457
1438
  midTurnState &&
1458
1439
  priorInput !== undefined &&
1459
- midTurnState.replacedStepNumber !== completedRequestIndex &&
1460
- pruneAppliedAtStep !== completedRequestIndex &&
1461
- midTurnState.omittedImageToolResults.size === 0 &&
1440
+ midTurnState.stepShaping.size === 0 &&
1462
1441
  stepUsage !== undefined &&
1463
1442
  Number.isFinite(stepUsage.inputTokens) &&
1464
1443
  stepUsage.inputTokens > 0 &&
@@ -1480,6 +1459,11 @@ export class AiSdkTurn {
1480
1459
  priorInputTokens: priorInput,
1481
1460
  });
1482
1461
  }
1462
+ // Clear here, not at the top of the next step: the continuation
1463
+ // lane archives its prune below, after this point, and archiving
1464
+ // is idempotent — the next step's re-projection reports no prune,
1465
+ // so a clear above it would lose the only record of this one.
1466
+ midTurnState?.stepShaping.clear();
1483
1467
  // Fail closed: reset on every step boundary so a missing final
1484
1468
  // step's usage does not leave a stale value from an earlier step.
1485
1469
  // The reply needed more room than the declared window had
@@ -1594,10 +1578,10 @@ export class AiSdkTurn {
1594
1578
  // nothing left to grant it, so the error is terminal.
1595
1579
  const stepBudgetRemains = maxSteps === undefined || runtimeSteps < maxSteps;
1596
1580
  const recovered = stepBudgetRemains &&
1581
+ failure.kind === 'context_overflow' &&
1597
1582
  providerAttempt < MAX_PROVIDER_ATTEMPTS_PER_STEP &&
1598
1583
  attemptHasNoObservableOutput()
1599
1584
  ? await this.deps.compaction.recoverFromOverflowError({
1600
- error: failure,
1601
1585
  midTurnState,
1602
1586
  turnId,
1603
1587
  stepNumber: runtimeSteps,
@@ -1620,8 +1604,8 @@ export class AiSdkTurn {
1620
1604
  continue;
1621
1605
  }
1622
1606
  // Window suggestion (#4559): the provider rejected a request and
1623
- // no recovery is left — the one fold is spent, or there was no
1624
- // seam. The baseline is a proven-fit total (input + output of an
1607
+ // no recovery is left — this step's fold is spent, or there was
1608
+ // no seam. The baseline is a proven-fit total (input + output of an
1625
1609
  // accepted request), so it is a number the user can declare; the
1626
1610
  // trigger is `>=`, so declaring exactly it folds before this
1627
1611
  // point next time. Once per send, and only when the turn is
@@ -1650,7 +1634,7 @@ export class AiSdkTurn {
1650
1634
  // its size can be concluded (#4559).
1651
1635
  if (!contextOverflowAfterCompactionNoteWritten &&
1652
1636
  failure.kind === 'context_overflow' &&
1653
- midTurnState?.compactionAppliedThisSend === true) {
1637
+ midTurnState?.projectionCheckpoint !== undefined) {
1654
1638
  contextOverflowAfterCompactionNoteWritten = true;
1655
1639
  await this.recordSystemNote('context_overflow_after_compaction', turnId);
1656
1640
  }
@@ -1669,9 +1653,6 @@ export class AiSdkTurn {
1669
1653
  else if (providerAttempt >= MAX_PROVIDER_ATTEMPTS_PER_STEP) {
1670
1654
  retry = { decision: 'exhausted', attempts: providerAttempt };
1671
1655
  }
1672
- else if (failure.kind === 'context_overflow') {
1673
- retry = { decision: 'declined', because: 'policy' };
1674
- }
1675
1656
  else if (!failure.retryable) {
1676
1657
  retry = { decision: 'declined', because: 'policy' };
1677
1658
  }
@@ -1686,7 +1667,7 @@ export class AiSdkTurn {
1686
1667
  const delayMs = providerRetryDelayMs(providerAttempt, failure.retryAfterMs);
1687
1668
  const nextAttempt = providerAttempt + 1;
1688
1669
  const maxAttempts = MAX_PROVIDER_ATTEMPTS_PER_STEP;
1689
- const reason = providerRetryReason(failure.kind);
1670
+ const reason = providerRetryReason(failure.kind) ?? 'unknown';
1690
1671
  queue.push({
1691
1672
  type: 'provider_retry',
1692
1673
  id: this.deps.newId(),
@@ -1712,10 +1693,10 @@ export class AiSdkTurn {
1712
1693
  });
1713
1694
  continue;
1714
1695
  }
1715
- // Unrecoverable (not context-length, latch spent, no seam, or no
1716
- // safe fold): surface the real provider error via the terminal
1717
- // handler after settling any authoritative usage — never a
1718
- // fabricated success.
1696
+ // Unrecoverable (not context-length, this step's attempt spent,
1697
+ // no seam, or no safe fold): surface the real provider error via
1698
+ // the terminal handler after settling any authoritative usage —
1699
+ // never a fabricated success.
1719
1700
  terminalProviderError = failure;
1720
1701
  terminalRetry = { error: terminalProviderError, retry };
1721
1702
  terminalProviderErrorReason =
@@ -113,6 +113,7 @@ export function buildBuiltinTools(options = {}) {
113
113
  buildManagedBashTool(options.shellRuns, {
114
114
  executionFacts,
115
115
  shell,
116
+ declareSandboxBoundary: options.declareSandboxBoundary !== false,
116
117
  ...(options.sandboxManager
117
118
  ? {
118
119
  transformCommand: ({ command, pty, requiredBoundary, ctx }) => {
@@ -143,6 +144,7 @@ export function buildBuiltinTools(options = {}) {
143
144
  buildExecutorBashTool(executor, shell, {
144
145
  ...(options.permissionProfile ? { permissionProfile: options.permissionProfile } : {}),
145
146
  ...(options.sandboxManager ? { sandboxManager: options.sandboxManager } : {}),
147
+ declareSandboxBoundary: options.declareSandboxBoundary !== false,
146
148
  sandboxPlatform,
147
149
  }),
148
150
  ];
@@ -451,22 +453,28 @@ function filesystemCall(ctx) {
451
453
  };
452
454
  }
453
455
  function buildExecutorBashTool(executor, shell, sandboxOptions) {
456
+ const declareSandboxBoundary = sandboxOptions.declareSandboxBoundary !== false;
457
+ const executorBashFields = {
458
+ command: z.string().describe('The shell command to execute'),
459
+ timeout_ms: z.number().int().positive().max(600_000).optional(),
460
+ };
454
461
  return {
455
462
  name: 'Bash',
456
463
  activityKind: 'command',
457
464
  description: withTurnShellGuidance('Run a shell command in the session cwd.', shell) +
458
- ' Enforced by the current session sandbox boundary.',
459
- parameters: preprocessBashBoundaryDeclaration(z
460
- .object({
461
- command: z.string().describe('The shell command to execute'),
462
- timeout_ms: z.number().int().positive().max(600_000).optional(),
463
- boundary_intent: bashBoundaryIntentSchema,
464
- required_boundary: sandboxBoundaryExpansionSchema
465
- .optional()
466
- .describe(BASH_REQUIRED_BOUNDARY_DESCRIPTION),
467
- })
468
- .strict()
469
- .superRefine(refineBashBoundaryDeclaration)),
465
+ (declareSandboxBoundary ? ' Enforced by the current session sandbox boundary.' : ''),
466
+ parameters: declareSandboxBoundary
467
+ ? preprocessBashBoundaryDeclaration(z
468
+ .object({
469
+ ...executorBashFields,
470
+ boundary_intent: bashBoundaryIntentSchema,
471
+ required_boundary: sandboxBoundaryExpansionSchema
472
+ .optional()
473
+ .describe(BASH_REQUIRED_BOUNDARY_DESCRIPTION),
474
+ })
475
+ .strict()
476
+ .superRefine(refineBashBoundaryDeclaration))
477
+ : z.object(executorBashFields).strict(),
470
478
  toModelOutput: ({ output }) => bashToolResultToModelOutput(output),
471
479
  executionFacts: executor.facts,
472
480
  impl: async (input, ctx) => {
@@ -125,8 +125,7 @@ export function shouldFallbackFromOpenAiCodexHistoryCompaction(error, abortSigna
125
125
  return true;
126
126
  if (error.reason !== 'provider_error')
127
127
  return false;
128
- const diagnostic = providerFailureDiagnostic(error);
129
- return diagnostic.errorClass === 'request_rejected' && !diagnostic.retryable;
128
+ return providerFailureDiagnostic(error).errorClass === 'request_rejected';
130
129
  }
131
130
  function hasAbortCause(error) {
132
131
  const seen = new Set();
@@ -64,6 +64,7 @@ const PROVIDER_BILLING_PROVIDER_CODES = new Set([
64
64
  'insufficient_quota', // OpenAI & OpenAI-compatible: error.code
65
65
  'insufficient_balance', // DeepSeek: error.code
66
66
  'quota_exceeded', // OpenAI-compatible variants: error.code
67
+ 'freeusagelimiterror', // OpenCode Zen free tier exhausted (HTTP 429): error.type
67
68
  ]);
68
69
  /**
69
70
  * Free-text usage/billing wording that overrides a credential-shaped HTTP
@@ -83,12 +84,29 @@ const USAGE_LIMIT_TEXT_PATTERNS = [
83
84
  ];
84
85
  const PROVIDER_FAILURE_FIELD_MAX_BYTES = 256;
85
86
  const MAX_SAFE_TIMER_DELAY_MS = 2_147_483_647;
86
- const OPENAI_RESPONSES_WEBSOCKET_TRANSPORT_ERROR = 'OPENAI_RESPONSES_WEBSOCKET_TRANSPORT_ERROR';
87
- const RUNTIME_RETRYABLE_ERROR_CODES = new Set([
88
- 'MODEL_STREAM_TIMEOUT',
89
- OPENAI_RESPONSES_WEBSOCKET_TRANSPORT_ERROR,
87
+ /** Codes the incremental Responses transport raises before any HTTP response. */
88
+ const OPENAI_RESPONSES_TRANSPORT_CODES = new Set([
89
+ 'OPENAI_RESPONSES_WEBSOCKET_TRANSPORT_ERROR',
90
90
  'OPENAI_RESPONSES_CONTINUATION_UNAVAILABLE',
91
91
  ]);
92
+ /** Retryability follows the kind alone; never re-derive it from a status or header. */
93
+ const MODEL_FAILURE_RETRY = {
94
+ abort: null,
95
+ auth: null,
96
+ context_overflow: null,
97
+ network: 'network',
98
+ provider_billing: null,
99
+ provider_capacity: 'provider_capacity',
100
+ provider_unavailable: 'provider_unavailable',
101
+ rate_limit: 'rate_limit',
102
+ request_rejected: null,
103
+ stream_truncated: 'stream_truncated',
104
+ timeout: 'timeout',
105
+ unknown: null,
106
+ };
107
+ export function providerRetryReason(kind) {
108
+ return MODEL_FAILURE_RETRY[kind];
109
+ }
92
110
  function providerErrorTarget(error) {
93
111
  return RetryError.isInstance(error) && error.lastError !== undefined && error.lastError !== error
94
112
  ? error.lastError
@@ -150,49 +168,22 @@ function parseRetryAfterMs(headers) {
150
168
  const seconds = Number(rawRetryAfter);
151
169
  delayMs = Number.isFinite(seconds) ? seconds * 1_000 : Date.parse(rawRetryAfter) - Date.now();
152
170
  }
153
- if (!Number.isFinite(delayMs) || delayMs <= 0 || delayMs > MAX_SAFE_TIMER_DELAY_MS)
154
- return null;
171
+ if (!Number.isFinite(delayMs) || delayMs <= 0 || delayMs > MAX_SAFE_TIMER_DELAY_MS) {
172
+ return undefined;
173
+ }
155
174
  return Math.ceil(delayMs);
156
175
  }
157
176
  function retryMetadataFromFacts(facts, errorClass = classifyProviderFacts(facts)) {
158
177
  if (facts.aborted)
159
178
  return { retryable: false };
160
- const { evidence } = facts;
161
- if (RUNTIME_RETRYABLE_ERROR_CODES.has(evidence.code))
162
- return { retryable: true };
163
179
  // The Codex transport already spent its complete 2/10/30-second budget.
164
180
  // Do not let the outer model loop restart that same transport budget.
165
181
  if (isTrustedCodexEdgeRejection(facts))
166
182
  return { retryable: false };
167
- const status = Number(evidence.statusCode || evidence.code);
168
- const retryAfterMs = parseRetryAfterMs(facts.responseHeaders ?? {});
169
- if (errorClass === 'provider_capacity') {
170
- // Capacity is transient even when the provider sends a malformed delay;
171
- // fall back to the adapter's bounded local backoff in that case.
172
- return {
173
- retryable: true,
174
- ...(retryAfterMs !== undefined && retryAfterMs !== null ? { retryAfterMs } : {}),
175
- };
176
- }
177
- if (errorClass === 'rate_limit' || status === 429) {
178
- if (retryAfterMs === undefined || retryAfterMs === null)
179
- return { retryable: false };
180
- return { retryable: true, retryAfterMs };
181
- }
182
- const retryable = errorClass === 'stream_truncated' ||
183
- errorClass === 'network' ||
184
- errorClass === 'provider_unavailable' ||
185
- status === 408 ||
186
- status === 409 ||
187
- (status >= 500 && status <= 599);
188
- if (!retryable)
189
- return { retryable: false };
190
- if (retryAfterMs === null)
183
+ if (MODEL_FAILURE_RETRY[errorClass] === null)
191
184
  return { retryable: false };
192
- return {
193
- retryable: true,
194
- ...(retryAfterMs !== undefined ? { retryAfterMs } : {}),
195
- };
185
+ const retryAfterMs = parseRetryAfterMs(facts.responseHeaders ?? {});
186
+ return { retryable: true, ...(retryAfterMs === undefined ? {} : { retryAfterMs }) };
196
187
  }
197
188
  /** Collects `code`/`type` strings from a payload and from its `error` wrapper. */
198
189
  function collectStructuredCodes(payload, out) {
@@ -606,7 +597,7 @@ function classifyProviderFacts(facts) {
606
597
  const { evidence } = facts;
607
598
  const { text, statusCode, code, structuredCodes } = evidence;
608
599
  const normalizedCode = code.toLowerCase();
609
- if (code === OPENAI_RESPONSES_WEBSOCKET_TRANSPORT_ERROR)
600
+ if (OPENAI_RESPONSES_TRANSPORT_CODES.has(code))
610
601
  return 'network';
611
602
  if (code === 'MODEL_STREAM_TIMEOUT')
612
603
  return 'timeout';
@@ -316,6 +316,7 @@ export class RuntimeKernel {
316
316
  const run = new AgentRun({
317
317
  sessionId,
318
318
  header,
319
+ effectiveToolMode: await this.deps.resolveFreshTurnToolMode?.(header),
319
320
  userInput: input,
320
321
  runId: options.runId,
321
322
  userMessageId: options.userMessageId,