@caupulican/pi-adaptative 0.93.12 → 0.93.13

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 (139) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/core/agent-paths.d.ts +6 -0
  3. package/dist/core/agent-paths.d.ts.map +1 -1
  4. package/dist/core/agent-paths.js +15 -0
  5. package/dist/core/agent-paths.js.map +1 -1
  6. package/dist/core/agent-session.d.ts.map +1 -1
  7. package/dist/core/agent-session.js +2 -0
  8. package/dist/core/agent-session.js.map +1 -1
  9. package/dist/core/background-lane-controller.d.ts +2 -0
  10. package/dist/core/background-lane-controller.d.ts.map +1 -1
  11. package/dist/core/background-lane-controller.js +3 -0
  12. package/dist/core/background-lane-controller.js.map +1 -1
  13. package/dist/core/background-tool-task-controller.d.ts +4 -0
  14. package/dist/core/background-tool-task-controller.d.ts.map +1 -1
  15. package/dist/core/background-tool-task-controller.js +22 -19
  16. package/dist/core/background-tool-task-controller.js.map +1 -1
  17. package/dist/core/delegation/worker-agent-control-coordinator.d.ts +3 -1
  18. package/dist/core/delegation/worker-agent-control-coordinator.d.ts.map +1 -1
  19. package/dist/core/delegation/worker-agent-control-coordinator.js +8 -0
  20. package/dist/core/delegation/worker-agent-control-coordinator.js.map +1 -1
  21. package/dist/core/delegation/worker-attempt-executor.d.ts +2 -1
  22. package/dist/core/delegation/worker-attempt-executor.d.ts.map +1 -1
  23. package/dist/core/delegation/worker-attempt-executor.js +14 -1
  24. package/dist/core/delegation/worker-attempt-executor.js.map +1 -1
  25. package/dist/core/delegation/worker-claim.d.ts +4 -1
  26. package/dist/core/delegation/worker-claim.d.ts.map +1 -1
  27. package/dist/core/delegation/worker-claim.js +20 -2
  28. package/dist/core/delegation/worker-claim.js.map +1 -1
  29. package/dist/core/delegation/worker-delegation-controller.d.ts.map +1 -1
  30. package/dist/core/delegation/worker-delegation-controller.js +2 -0
  31. package/dist/core/delegation/worker-delegation-controller.js.map +1 -1
  32. package/dist/core/delegation/worker-lifecycle.d.ts +1 -0
  33. package/dist/core/delegation/worker-lifecycle.d.ts.map +1 -1
  34. package/dist/core/delegation/worker-lifecycle.js +3 -0
  35. package/dist/core/delegation/worker-lifecycle.js.map +1 -1
  36. package/dist/core/delegation/worker-runner.d.ts.map +1 -1
  37. package/dist/core/delegation/worker-runner.js +15 -9
  38. package/dist/core/delegation/worker-runner.js.map +1 -1
  39. package/dist/core/delegation/worker-terminal-output-artifact.d.ts +14 -0
  40. package/dist/core/delegation/worker-terminal-output-artifact.d.ts.map +1 -0
  41. package/dist/core/delegation/worker-terminal-output-artifact.js +49 -0
  42. package/dist/core/delegation/worker-terminal-output-artifact.js.map +1 -0
  43. package/dist/core/foreground-terminal-handoff-controller.d.ts +3 -0
  44. package/dist/core/foreground-terminal-handoff-controller.d.ts.map +1 -1
  45. package/dist/core/foreground-terminal-handoff-controller.js +6 -0
  46. package/dist/core/foreground-terminal-handoff-controller.js.map +1 -1
  47. package/dist/core/goals/goal-session-controller.d.ts +2 -2
  48. package/dist/core/goals/goal-session-controller.d.ts.map +1 -1
  49. package/dist/core/goals/goal-session-controller.js +2 -11
  50. package/dist/core/goals/goal-session-controller.js.map +1 -1
  51. package/dist/core/orchestration/contracts.d.ts +2 -0
  52. package/dist/core/orchestration/contracts.d.ts.map +1 -1
  53. package/dist/core/orchestration/contracts.js +3 -0
  54. package/dist/core/orchestration/contracts.js.map +1 -1
  55. package/dist/core/orchestration/task-runtime-codecs.d.ts.map +1 -1
  56. package/dist/core/orchestration/task-runtime-codecs.js +11 -2
  57. package/dist/core/orchestration/task-runtime-codecs.js.map +1 -1
  58. package/dist/core/orchestration/worker-result-adapter.d.ts +2 -1
  59. package/dist/core/orchestration/worker-result-adapter.d.ts.map +1 -1
  60. package/dist/core/orchestration/worker-result-adapter.js +41 -7
  61. package/dist/core/orchestration/worker-result-adapter.js.map +1 -1
  62. package/dist/core/runtime-builder.d.ts +5 -2
  63. package/dist/core/runtime-builder.d.ts.map +1 -1
  64. package/dist/core/runtime-builder.js +26 -8
  65. package/dist/core/runtime-builder.js.map +1 -1
  66. package/dist/core/secrets/bitwarden-credential-storage-router.d.ts +22 -0
  67. package/dist/core/secrets/bitwarden-credential-storage-router.d.ts.map +1 -0
  68. package/dist/core/secrets/bitwarden-credential-storage-router.js +59 -0
  69. package/dist/core/secrets/bitwarden-credential-storage-router.js.map +1 -0
  70. package/dist/core/secrets/bitwarden-credential-storage.d.ts +2 -8
  71. package/dist/core/secrets/bitwarden-credential-storage.d.ts.map +1 -1
  72. package/dist/core/secrets/bitwarden-credential-storage.js +23 -134
  73. package/dist/core/secrets/bitwarden-credential-storage.js.map +1 -1
  74. package/dist/core/secrets/bitwarden-secrets-manager-storage.d.ts +46 -0
  75. package/dist/core/secrets/bitwarden-secrets-manager-storage.d.ts.map +1 -0
  76. package/dist/core/secrets/bitwarden-secrets-manager-storage.js +379 -0
  77. package/dist/core/secrets/bitwarden-secrets-manager-storage.js.map +1 -0
  78. package/dist/core/secrets/credential-cli-command.d.ts +22 -0
  79. package/dist/core/secrets/credential-cli-command.d.ts.map +1 -0
  80. package/dist/core/secrets/credential-cli-command.js +82 -0
  81. package/dist/core/secrets/credential-cli-command.js.map +1 -0
  82. package/dist/core/secrets/credential-exposure-guard.d.ts +1 -1
  83. package/dist/core/secrets/credential-exposure-guard.d.ts.map +1 -1
  84. package/dist/core/secrets/credential-exposure-guard.js +5 -1
  85. package/dist/core/secrets/credential-exposure-guard.js.map +1 -1
  86. package/dist/core/secrets/credential-machine-session.d.ts +13 -0
  87. package/dist/core/secrets/credential-machine-session.d.ts.map +1 -0
  88. package/dist/core/secrets/credential-machine-session.js +139 -0
  89. package/dist/core/secrets/credential-machine-session.js.map +1 -0
  90. package/dist/core/secrets/credential-manager.d.ts +11 -1
  91. package/dist/core/secrets/credential-manager.d.ts.map +1 -1
  92. package/dist/core/secrets/credential-manager.js +44 -9
  93. package/dist/core/secrets/credential-manager.js.map +1 -1
  94. package/dist/core/secrets/credential-profile-envelope.d.ts +10 -0
  95. package/dist/core/secrets/credential-profile-envelope.d.ts.map +1 -0
  96. package/dist/core/secrets/credential-profile-envelope.js +78 -0
  97. package/dist/core/secrets/credential-profile-envelope.js.map +1 -0
  98. package/dist/core/secrets/credential-session-connection.d.ts.map +1 -1
  99. package/dist/core/secrets/credential-session-connection.js +2 -1
  100. package/dist/core/secrets/credential-session-connection.js.map +1 -1
  101. package/dist/core/secrets/credential-source-discovery.d.ts +7 -3
  102. package/dist/core/secrets/credential-source-discovery.d.ts.map +1 -1
  103. package/dist/core/secrets/credential-source-discovery.js +48 -9
  104. package/dist/core/secrets/credential-source-discovery.js.map +1 -1
  105. package/dist/core/tools/delegate-status.d.ts +4 -0
  106. package/dist/core/tools/delegate-status.d.ts.map +1 -1
  107. package/dist/core/tools/delegate-status.js +20 -4
  108. package/dist/core/tools/delegate-status.js.map +1 -1
  109. package/dist/core/tools/goal.d.ts +2 -2
  110. package/dist/core/tools/goal.d.ts.map +1 -1
  111. package/dist/core/tools/goal.js +30 -11
  112. package/dist/core/tools/goal.js.map +1 -1
  113. package/dist/core/tools/secret-store.d.ts.map +1 -1
  114. package/dist/core/tools/secret-store.js +6 -15
  115. package/dist/core/tools/secret-store.js.map +1 -1
  116. package/dist/core/tools/tool-task.d.ts.map +1 -1
  117. package/dist/core/tools/tool-task.js +6 -3
  118. package/dist/core/tools/tool-task.js.map +1 -1
  119. package/dist/core/util/bounded-value.d.ts +2 -0
  120. package/dist/core/util/bounded-value.d.ts.map +1 -1
  121. package/dist/core/util/bounded-value.js +13 -0
  122. package/dist/core/util/bounded-value.js.map +1 -1
  123. package/dist/index.d.ts +3 -1
  124. package/dist/index.d.ts.map +1 -1
  125. package/dist/index.js +2 -0
  126. package/dist/index.js.map +1 -1
  127. package/dist/utils/tools-manager.d.ts +2 -1
  128. package/dist/utils/tools-manager.d.ts.map +1 -1
  129. package/dist/utils/tools-manager.js +29 -0
  130. package/dist/utils/tools-manager.js.map +1 -1
  131. package/examples/extensions/custom-provider-anthropic/package-lock.json +2 -2
  132. package/examples/extensions/custom-provider-anthropic/package.json +1 -1
  133. package/examples/extensions/custom-provider-gitlab-duo/package.json +1 -1
  134. package/examples/extensions/sandbox/package-lock.json +2 -2
  135. package/examples/extensions/sandbox/package.json +1 -1
  136. package/examples/extensions/with-deps/package-lock.json +2 -2
  137. package/examples/extensions/with-deps/package.json +1 -1
  138. package/npm-shrinkwrap.json +12 -12
  139. package/package.json +4 -4
@@ -4,7 +4,7 @@ import type { IsolatedCompletionOptions, IsolatedCompletionResult } from "../age
4
4
  import type { WorkerRequest } from "../autonomy/contracts.ts";
5
5
  import type { LaneToolSurface } from "../autonomy/lane-tool-surface.ts";
6
6
  import type { ModelCapabilityProfile } from "../model-capability.ts";
7
- import type { AttemptUsageSnapshot, ExecutionGrant } from "../orchestration/contracts.ts";
7
+ import type { ArtifactContract, AttemptUsageSnapshot, ExecutionGrant } from "../orchestration/contracts.ts";
8
8
  import type { StartedDelegationAttempt } from "../orchestration/delegation-ledger.ts";
9
9
  import { WorkerActionJournal } from "./worker-action-journal.ts";
10
10
  import type { AppliedActionsReport, WorkerAction } from "./worker-actions.ts";
@@ -27,6 +27,7 @@ export interface WorkerAttemptExecutionResult {
27
27
  rawOutcome: WorkerRunOutcome;
28
28
  usage: AttemptUsageSnapshot;
29
29
  changedFiles: readonly string[];
30
+ outputArtifact?: ArtifactContract;
30
31
  }
31
32
  export declare function runProviderCompletionWithBackoff(args: {
32
33
  attempt: () => Promise<IsolatedCompletionResult>;
@@ -1 +1 @@
1
- {"version":3,"file":"worker-attempt-executor.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-attempt-executor.ts"],"names":[],"mappings":"AAUA,OAAO,KAAK,EAAgB,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAEnF,OAAO,KAAK,EAAE,GAAG,EAA6B,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AACtF,OAAO,KAAK,EAAE,yBAAyB,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AgFD;;;;GAIG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,EAAE,4BAA4B,GAAG;IACnF,MAAM,EAAE,4BAA4B,CAAC;IACrC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,oBAAoB,CAAC;IACvD,GAAG,IAAI,OAAO,CAAC,4BAA4B,CAAC,CAAC;CAC7C,CA4iBA"}
@@ -13,6 +13,7 @@ import { WorkerConversationOwnershipError } from "./worker-conversation-revision
13
13
  import { WorkerCompletionProtocolError, WorkerProviderTurnProtocol } from "./worker-provider-turn-protocol.js";
14
14
  import { runWorker } from "./worker-runner.js";
15
15
  import { buildWorkerSystemPrompt } from "./worker-system-prompt.js";
16
+ import { captureWorkerTerminalOutputArtifact } from "./worker-terminal-output-artifact.js";
16
17
  import { WorkerTreeBudgetExceededError } from "./worker-tree-budget-coordinator.js";
17
18
  /**
18
19
  * Backoff policy for transient worker provider failures. Without it, a dropped provider socket
@@ -150,6 +151,7 @@ export function createWorkerAttemptExecutor(options) {
150
151
  let retentionWarningEmitted = false;
151
152
  let firstMailboxPoll = true;
152
153
  let ran = false;
154
+ let terminalOutput;
153
155
  const currentUsage = () => attemptUsageFromGatewayUsage(options.toolSurface.gateway?.getUsage() ?? {
154
156
  ...EMPTY_ATTEMPT_USAGE,
155
157
  wallClockMs: options.initialUsage.activeWallClockMs,
@@ -325,6 +327,7 @@ export function createWorkerAttemptExecutor(options) {
325
327
  : {}),
326
328
  complete: async ({ systemPrompt, userPrompt, signal }) => {
327
329
  if (options.recoveredTerminal) {
330
+ terminalOutput = options.recoveredTerminal.text;
328
331
  checkpointUsage("Reused the persisted terminal worker assistant response after recovery.");
329
332
  return {
330
333
  text: options.recoveredTerminal.text,
@@ -618,6 +621,7 @@ export function createWorkerAttemptExecutor(options) {
618
621
  closeActiveProviderTurn();
619
622
  }
620
623
  const cumulativeUsage = checkpointUsage("Verified the callback-persisted worker conversation terminal suffix.");
624
+ terminalOutput = completion.text;
621
625
  return {
622
626
  text: completion.text,
623
627
  costUsd: cumulativeUsage.costUsd,
@@ -628,7 +632,16 @@ export function createWorkerAttemptExecutor(options) {
628
632
  },
629
633
  });
630
634
  const usage = checkpointUsage("Persisted final cumulative worker usage before terminal result.");
631
- return { rawOutcome, usage, changedFiles: [...changedFiles] };
635
+ const outputArtifact = terminalOutput
636
+ ? captureWorkerTerminalOutputArtifact({
637
+ agentDir: options.agentDir,
638
+ parentSessionId: options.parentSessionId,
639
+ attemptId: options.durableHandle.attemptId,
640
+ text: terminalOutput,
641
+ createdAt: new Date().toISOString(),
642
+ })
643
+ : undefined;
644
+ return { rawOutcome, usage, changedFiles: [...changedFiles], ...(outputArtifact ? { outputArtifact } : {}) };
632
645
  },
633
646
  };
634
647
  }
@@ -1 +1 @@
1
- {"version":3,"file":"worker-attempt-executor.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-attempt-executor.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,iDAAiD,CAAC;AAC1E,OAAO,EACN,eAAe,EACf,mBAAmB,EAEnB,cAAc,GACd,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,0BAA0B,EAAE,MAAM,+CAA+C,CAAC;AAE3F,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAG7E,OAAO,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AAGlF,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,OAAO,EAAE,4BAA4B,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACtG,OAAO,EAAE,4BAA4B,EAAkC,MAAM,wCAAwC,CAAC;AAGtH,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGjE,OAAO,EAAE,gCAAgC,EAAE,MAAM,mCAAmC,CAAC;AAI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C,IAAI;4BAClB,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;yBAC7B,CAAC,CAAC;oBACJ,CAAC;4BAAS,CAAC;wBACV,uBAAuB,EAAE,CAAC;oBAC3B,CAAC;oBACD,MAAM,eAAe,GAAG,eAAe,CACtC,sEAAsE,CACtE,CAAC;oBACF,OAAO;wBACN,IAAI,EAAE,UAAU,CAAC,IAAI;wBACrB,OAAO,EAAE,eAAe,CAAC,OAAO;wBAChC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC;wBACzC,YAAY,EAAE,CAAC,GAAG,YAAY,CAAC;wBAC/B,QAAQ,EAAE,CAAC,GAAG,UAAU,CAAC;qBACzB,CAAC;gBACH,CAAC;aACD,CAAC,CAAC;YACH,MAAM,KAAK,GAAG,eAAe,CAAC,iEAAiE,CAAC,CAAC;YACjG,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,GAAG,YAAY,CAAC,EAAE,CAAC;QAC/D,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import path from \"node:path\";\nimport { isDeepStrictEqual } from \"node:util\";\nimport { compact } from \"@caupulican/pi-agent-core/compaction/compaction\";\nimport {\n\tclassifyFailure,\n\tcomputeRetryDelayMs,\n\ttype RetryPolicy,\n\tsleepAbortable,\n} from \"@caupulican/pi-agent-core/reliability\";\nimport { sanitizeToolFailureContext } from \"@caupulican/pi-agent-core/tool-failure-memory\";\nimport type { AgentMessage, ThinkingLevel } from \"@caupulican/pi-agent-core/types\";\nimport { addUsage, createEmptyUsage } from \"@caupulican/pi-agent-core/usage\";\nimport type { Api, AssistantMessage, Message, Model, Usage } from \"@caupulican/pi-ai\";\nimport type { IsolatedCompletionOptions, IsolatedCompletionResult } from \"../agent-session-contracts.ts\";\nimport { BoundedCompletionFailureError } from \"../autonomy/bounded-completion.ts\";\nimport type { WorkerRequest } from \"../autonomy/contracts.ts\";\nimport type { LaneToolSurface } from \"../autonomy/lane-tool-surface.ts\";\nimport { safeRealpathSync } from \"../autonomy/path-scope.ts\";\nimport type { ModelCapabilityProfile } from \"../model-capability.ts\";\nimport { attemptUsageFromGatewayUsage, EMPTY_ATTEMPT_USAGE } from \"../orchestration/attempt-usage.ts\";\nimport { CapabilityGatewayDeniedError, type ProviderBudgetReservation } from \"../orchestration/capability-gateway.ts\";\nimport type { AttemptUsageSnapshot, ExecutionGrant } from \"../orchestration/contracts.ts\";\nimport type { StartedDelegationAttempt } from \"../orchestration/delegation-ledger.ts\";\nimport { WorkerActionJournal } from \"./worker-action-journal.ts\";\nimport type { AppliedActionsReport, WorkerAction } from \"./worker-actions.ts\";\nimport type { WorkerAgentControlCoordinator } from \"./worker-agent-control-coordinator.ts\";\nimport { WorkerConversationOwnershipError } from \"./worker-conversation-revision.ts\";\nimport type { WorkerConversation, WorkerConversationRetentionPolicy } from \"./worker-conversation-store.ts\";\nimport type { WorkerExecutionPlan } from \"./worker-execution-policy.ts\";\nimport type { WorkerLifecycle } from \"./worker-lifecycle.ts\";\nimport { WorkerCompletionProtocolError, WorkerProviderTurnProtocol } from \"./worker-provider-turn-protocol.ts\";\nimport { runWorker, type WorkerRunOutcome } from \"./worker-runner.ts\";\nimport { buildWorkerSystemPrompt } from \"./worker-system-prompt.ts\";\nimport { WorkerTreeBudgetExceededError } from \"./worker-tree-budget-coordinator.ts\";\n\nexport interface RecoveredWorkerTerminalCompletion {\n\ttext: string;\n\tusage: Usage;\n\tstopReason: string;\n}\n\n/** The live mutable state that must be visible to session disposal before provider work yields. */\nexport interface WorkerAttemptExecutionLedger {\n\tchangedFiles: Set<string>;\n\tgetUsage(): AttemptUsageSnapshot;\n}\n\nexport interface WorkerAttemptExecutionResult {\n\trawOutcome: WorkerRunOutcome;\n\tusage: AttemptUsageSnapshot;\n\tchangedFiles: readonly string[];\n}\n\n/**\n * Backoff policy for transient worker provider failures. Without it, a dropped provider socket\n * kills the attempt instantly at $0 spend and an immediate re-dispatch hits the same dead\n * connection (field session 019fd4dc: paired $0 `completion_error` lanes ~10s apart). Jitter\n * de-synchronizes sibling workers that all lost the same connection at once.\n */\nconst WORKER_PROVIDER_RETRY_POLICY: RetryPolicy = {\n\tmaxAttempts: 3,\n\tbaseDelayMs: 2_000,\n\tmaxDelayMs: 30_000,\n\tjitterRatio: 0.2,\n};\n\nexport async function runProviderCompletionWithBackoff(args: {\n\tattempt: () => Promise<IsolatedCompletionResult>;\n\t/** Release per-attempt provider reservations before waiting; the final failure is rethrown. */\n\tonAttemptFailure: () => void;\n\tprovider: string;\n\tlaneId: string;\n\twarn: (message: string) => void;\n\tsignal?: AbortSignal;\n}): Promise<IsolatedCompletionResult> {\n\tfor (let attempt = 1; ; attempt++) {\n\t\ttry {\n\t\t\tconst completion = await args.attempt();\n\t\t\tif (completion.stopReason !== \"error\") return completion;\n\t\t\tthrow new Error(\n\t\t\t\tcompletion.errorMessage?.trim() || \"Provider completion stopped with an error without diagnostic detail.\",\n\t\t\t);\n\t\t} catch (error) {\n\t\t\targs.onAttemptFailure();\n\t\t\tif (args.signal?.aborted) throw error;\n\t\t\tif (error instanceof WorkerCompletionProtocolError) {\n\t\t\t\tthrow new BoundedCompletionFailureError(\"failed\", \"worker_protocol_error\", error.message, error);\n\t\t\t}\n\t\t\tif (\n\t\t\t\terror instanceof WorkerConversationOwnershipError ||\n\t\t\t\terror instanceof CapabilityGatewayDeniedError ||\n\t\t\t\terror instanceof WorkerTreeBudgetExceededError ||\n\t\t\t\terror instanceof BoundedCompletionFailureError\n\t\t\t) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tconst classified = classifyFailure({\n\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\tprovider: args.provider,\n\t\t\t});\n\t\t\tif (!classified.retryable || attempt >= WORKER_PROVIDER_RETRY_POLICY.maxAttempts) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\tthrow new BoundedCompletionFailureError(\"failed\", \"completion_error\", message, error);\n\t\t\t}\n\t\t\tconst delayMs = computeRetryDelayMs(WORKER_PROVIDER_RETRY_POLICY, attempt, {\n\t\t\t\t...(classified.retryAfterMs !== undefined ? { retryAfterMs: classified.retryAfterMs } : {}),\n\t\t\t});\n\t\t\targs.warn(\n\t\t\t\t`Worker ${args.laneId} provider request failed (${classified.reason}); retrying in ${Math.ceil(delayMs / 1000)}s (attempt ${attempt + 1}/${WORKER_PROVIDER_RETRY_POLICY.maxAttempts}).`,\n\t\t\t);\n\t\t\tawait sleepAbortable(delayMs, args.signal);\n\t\t}\n\t}\n}\n\n/**\n * The provider/tool-loop portion of a prepared worker attempt.\n *\n * Admission, durable leasing, grant compilation, terminalization, notification, verification, and\n * scheduling remain outside this boundary. This unit owns only the ordered child conversation:\n * persist assistant tool requests before execution, append messages before mailbox acknowledgements,\n * checkpoint cumulative usage before later boundaries, and compact only the provider projection.\n */\nexport interface WorkerAttemptExecutorOptions {\n\trequest: WorkerRequest;\n\tgrant: ExecutionGrant;\n\texecutionPlan: WorkerExecutionPlan;\n\ttoolSurface: LaneToolSurface;\n\tconversation: WorkerConversation;\n\tlifecycle: Pick<WorkerLifecycle, \"checkpoint\">;\n\tlaneId: string;\n\tagentId: string;\n\tdurableHandle: StartedDelegationAttempt;\n\tparentSessionId: string;\n\tagentDir: string;\n\tcwd: string;\n\tmodel: Model<Api>;\n\tthinkingLevel?: ThinkingLevel;\n\tlaneCapability: Pick<ModelCapabilityProfile, \"laneMaxOutputTokens\">;\n\tsoul?: string;\n\tworkerResourceSystemPrompt: string;\n\tinitialUsage: AttemptUsageSnapshot;\n\thasPersistedUsageCheckpoint: boolean;\n\tusageReportId: string;\n\tprocessCapable: boolean;\n\tverificationSubjectTaskId?: string;\n\trecoveredTerminal?: RecoveredWorkerTerminalCompletion;\n\tretentionPolicy?: WorkerConversationRetentionPolicy;\n\tsignal?: AbortSignal;\n\trunIsolatedCompletion(options: IsolatedCompletionOptions): Promise<IsolatedCompletionResult>;\n\tagentControl: Pick<WorkerAgentControlCoordinator, \"acknowledgeMailboxMessage\" | \"mailboxMessagesForConversation\">;\n\tapplyActions?(actions: readonly WorkerAction[], actionJournal?: WorkerActionJournal): AppliedActionsReport;\n\twarn(message: string): void;\n}\n\nfunction isToolRequest(message: Message): boolean {\n\treturn message.role === \"assistant\" && message.content.some((content) => content.type === \"toolCall\");\n}\n\nfunction workerCompletionCallbackFailure(error: unknown): Error {\n\tif (\n\t\terror instanceof WorkerCompletionProtocolError ||\n\t\terror instanceof WorkerConversationOwnershipError ||\n\t\terror instanceof CapabilityGatewayDeniedError ||\n\t\terror instanceof WorkerTreeBudgetExceededError\n\t) {\n\t\treturn error;\n\t}\n\treturn new WorkerCompletionProtocolError(\n\t\t\"Worker completion callback failed before its authority and durable transcript were verified.\",\n\t);\n}\n\nfunction callbackEvidencedCompletion(\n\tresult: IsolatedCompletionResult,\n\thistoryLength: number,\n\temittedMessages: readonly Message[],\n): { completion: IsolatedCompletionResult; suffix: Message[] } {\n\tif (result.messages !== undefined && result.messages.length < historyLength) {\n\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\"Worker completion protocol returned fewer messages than its input history.\",\n\t\t);\n\t}\n\tlet suffix: Message[];\n\tif (result.messages !== undefined) {\n\t\tsuffix = result.messages.slice(historyLength);\n\t\tif (!isDeepStrictEqual(suffix, emittedMessages)) {\n\t\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\t\"Worker completion protocol returned a suffix without exact callback evidence.\",\n\t\t\t);\n\t\t}\n\t} else {\n\t\tsuffix = [...emittedMessages];\n\t}\n\tif (suffix.length === 0) {\n\t\tthrow new WorkerCompletionProtocolError(\"Worker completion protocol returned no durable message suffix.\");\n\t}\n\tif (!suffix.some((message) => message.role === \"assistant\")) {\n\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\"Worker completion protocol returned no assistant in its durable suffix.\",\n\t\t);\n\t}\n\tconst assistants = emittedMessages.filter((message): message is AssistantMessage => message.role === \"assistant\");\n\tconst finalMessage = emittedMessages.at(-1);\n\tif (!finalMessage || finalMessage.role !== \"assistant\") {\n\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\"Worker completion protocol did not durably emit an assistant as its terminal message.\",\n\t\t);\n\t}\n\tconst usage = createEmptyUsage();\n\tfor (const assistant of assistants) addUsage(usage, assistant.usage);\n\tconst text = finalMessage.content.flatMap((content) => (content.type === \"text\" ? [content.text] : [])).join(\"\");\n\tif (\n\t\tresult.text !== text ||\n\t\tresult.stopReason !== finalMessage.stopReason ||\n\t\t!isDeepStrictEqual(result.usage, usage) ||\n\t\tresult.errorMessage !== finalMessage.errorMessage\n\t) {\n\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\"Worker completion result disagrees with its durable callback-evidenced terminal assistant.\",\n\t\t);\n\t}\n\treturn {\n\t\tsuffix,\n\t\tcompletion: {\n\t\t\ttext,\n\t\t\tusage,\n\t\t\tstopReason: finalMessage.stopReason,\n\t\t\t...(finalMessage.errorMessage ? { errorMessage: finalMessage.errorMessage } : {}),\n\t\t},\n\t};\n}\n\n/**\n * Constructs one execution exactly once. The caller registers {@link ledger} before calling\n * {@link run}, allowing synchronous disposal to observe mutations and cumulative usage while the\n * provider/tool loop is suspended.\n */\nexport function createWorkerAttemptExecutor(options: WorkerAttemptExecutorOptions): {\n\tledger: WorkerAttemptExecutionLedger;\n\tcheckpointUsage(summary: string): AttemptUsageSnapshot;\n\trun(): Promise<WorkerAttemptExecutionResult>;\n} {\n\tconst changedFiles = new Set(options.conversation.getChangedFiles(options.durableHandle.attemptId));\n\tconst toolIssues = new Set<string>();\n\tconst recordChangedFile = (filePath: string): void => {\n\t\tchangedFiles.add(filePath);\n\t\ttry {\n\t\t\toptions.conversation.recordChangedFile(options.durableHandle.attemptId, filePath);\n\t\t} catch (error) {\n\t\t\ttoolIssues.add(\"worker changed-file progress could not be persisted; parent review is required\");\n\t\t\toptions.warn(\n\t\t\t\t`Worker changed-file progress persistence failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t};\n\tconst actionJournal = options.request.envelope.capabilities.includes(\"filesystem.write\")\n\t\t? new WorkerActionJournal({\n\t\t\t\tagentDir: options.agentDir,\n\t\t\t\tparentSessionId: options.parentSessionId,\n\t\t\t\ttaskId: options.durableHandle.taskId,\n\t\t\t\tattemptId: options.durableHandle.attemptId,\n\t\t\t\tfencingToken: options.durableHandle.fencingToken,\n\t\t\t})\n\t\t: undefined;\n\tlet retentionWarningEmitted = false;\n\tlet firstMailboxPoll = true;\n\tlet ran = false;\n\n\tconst currentUsage = (): AttemptUsageSnapshot =>\n\t\tattemptUsageFromGatewayUsage(\n\t\t\toptions.toolSurface.gateway?.getUsage() ?? {\n\t\t\t\t...EMPTY_ATTEMPT_USAGE,\n\t\t\t\twallClockMs: options.initialUsage.activeWallClockMs,\n\t\t\t},\n\t\t);\n\tconst checkpointUsage = (summary: string): AttemptUsageSnapshot => {\n\t\tconst usage = currentUsage();\n\t\toptions.lifecycle.checkpoint(options.laneId, { summary, usage });\n\t\treturn usage;\n\t};\n\tconst remainingAttemptTokens = (): number | undefined => options.toolSurface.gateway?.remainingAttemptTokenBudget();\n\tconst reserveProviderBudget = async (\n\t\trequestedMaxTokens: number,\n\t\tsubject: string,\n\t\tsignal?: AbortSignal,\n\t): Promise<ProviderBudgetReservation> => {\n\t\tif (options.toolSurface.gateway) {\n\t\t\treturn options.toolSurface.gateway.reserveProviderBudget(requestedMaxTokens, subject, signal);\n\t\t}\n\t\tif (signal?.aborted) throw signal.reason;\n\t\treturn { maxTokens: requestedMaxTokens, release: () => undefined };\n\t};\n\tconst createRetentionPolicy = (completeSignal: AbortSignal): WorkerConversationRetentionPolicy | undefined => {\n\t\tif (!options.retentionPolicy) return undefined;\n\t\tlet failedCompactionUsage: Usage | undefined;\n\t\treturn {\n\t\t\t...options.retentionPolicy,\n\t\t\tgenerateVerifiedCompaction: async (preparation: Parameters<typeof compact>[0]) => {\n\t\t\t\tconst compactionUsage = createEmptyUsage();\n\t\t\t\tfailedCompactionUsage = compactionUsage;\n\t\t\t\treturn compact(\n\t\t\t\t\tpreparation,\n\t\t\t\t\toptions.model,\n\t\t\t\t\tundefined,\n\t\t\t\t\tundefined,\n\t\t\t\t\tundefined,\n\t\t\t\t\tcompleteSignal,\n\t\t\t\t\toptions.thinkingLevel,\n\t\t\t\t\tundefined,\n\t\t\t\t\tundefined,\n\t\t\t\t\t{\n\t\t\t\t\t\tcompletion: async (model, context, requestOptions): Promise<AssistantMessage> => {\n\t\t\t\t\t\t\tconst requestSignal = requestOptions.signal ?? completeSignal;\n\t\t\t\t\t\t\trequestSignal.throwIfAborted();\n\t\t\t\t\t\t\tif (model.provider !== options.model.provider || model.id !== options.model.id) {\n\t\t\t\t\t\t\t\tthrow new Error(\"Worker compaction attempted to select a model outside the lane binding.\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\toptions.toolSurface.gateway?.assertBudgetAvailable(\"worker_compaction_provider_completion\");\n\t\t\t\t\t\t\tconst availableTokens = remainingAttemptTokens();\n\t\t\t\t\t\t\tif (availableTokens !== undefined && availableTokens <= 0) {\n\t\t\t\t\t\t\t\tthrow new Error(\"Worker token budget exhausted before compaction provider completion.\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst requestedMaxTokens = requestOptions.maxTokens;\n\t\t\t\t\t\t\tconst configuredMaxTokens =\n\t\t\t\t\t\t\t\ttypeof requestedMaxTokens === \"number\" &&\n\t\t\t\t\t\t\t\tNumber.isSafeInteger(requestedMaxTokens) &&\n\t\t\t\t\t\t\t\trequestedMaxTokens > 0\n\t\t\t\t\t\t\t\t\t? requestedMaxTokens\n\t\t\t\t\t\t\t\t\t: options.laneCapability.laneMaxOutputTokens;\n\t\t\t\t\t\t\tconst maxTokens = Math.min(configuredMaxTokens, availableTokens ?? configuredMaxTokens);\n\t\t\t\t\t\t\tif (!Number.isSafeInteger(maxTokens) || maxTokens <= 0) {\n\t\t\t\t\t\t\t\tthrow new Error(\"Worker compaction provider completion has no valid remaining token budget.\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tlet preflightFailed = false;\n\t\t\t\t\t\t\tlet preflightFailure: unknown;\n\t\t\t\t\t\t\tconst providerTurn = new WorkerProviderTurnProtocol({\n\t\t\t\t\t\t\t\tacquireReservation: () =>\n\t\t\t\t\t\t\t\t\treserveProviderBudget(maxTokens, \"worker_compaction_provider_completion\", requestSignal),\n\t\t\t\t\t\t\t\tsignal: requestSignal,\n\t\t\t\t\t\t\t\tonFailure: (error) => {\n\t\t\t\t\t\t\t\t\tif (preflightFailed) return;\n\t\t\t\t\t\t\t\t\tpreflightFailed = true;\n\t\t\t\t\t\t\t\t\tpreflightFailure = error;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t...(options.toolSurface.gateway\n\t\t\t\t\t\t\t\t\t? { recordUsage: (delta) => options.toolSurface.gateway?.recordUsage(delta) }\n\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tlet completion: IsolatedCompletionResult;\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tcompletion = await options.runIsolatedCompletion({\n\t\t\t\t\t\t\t\t\t\tsystemPrompt: context.systemPrompt ?? \"\",\n\t\t\t\t\t\t\t\t\t\tmessages: context.messages,\n\t\t\t\t\t\t\t\t\t\tmodel: options.model,\n\t\t\t\t\t\t\t\t\t\tthinkingLevel: options.thinkingLevel,\n\t\t\t\t\t\t\t\t\t\tmaxTokens,\n\t\t\t\t\t\t\t\t\t\trequestPreflight: () => providerTurn.requestPreflight(),\n\t\t\t\t\t\t\t\t\t\tsignal: requestSignal,\n\t\t\t\t\t\t\t\t\t\tcacheRetention: \"none\",\n\t\t\t\t\t\t\t\t\t\tlaneKind: \"worker-compaction\",\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\t\t\trequestSignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\tif (preflightFailed) throw workerCompletionCallbackFailure(preflightFailure);\n\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\trequestSignal.throwIfAborted();\n\t\t\t\t\t\t\t\tconst response: AssistantMessage = {\n\t\t\t\t\t\t\t\t\trole: \"assistant\",\n\t\t\t\t\t\t\t\t\tcontent: completion.text ? [{ type: \"text\", text: completion.text }] : [],\n\t\t\t\t\t\t\t\t\tapi: options.model.api,\n\t\t\t\t\t\t\t\t\tprovider: options.model.provider,\n\t\t\t\t\t\t\t\t\tmodel: options.model.id,\n\t\t\t\t\t\t\t\t\tusage: completion.usage,\n\t\t\t\t\t\t\t\t\tstopReason: completion.stopReason,\n\t\t\t\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t\t\t\t\t...(completion.stopReason === \"error\"\n\t\t\t\t\t\t\t\t\t\t? { errorMessage: completion.text || \"Worker compaction provider request failed.\" }\n\t\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\taddUsage(compactionUsage, completion.usage);\n\t\t\t\t\t\t\t\tif (providerTurn.hasOutstandingAssistantReservation()) {\n\t\t\t\t\t\t\t\t\tproviderTurn.accountAssistantUsage(completion.usage);\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tproviderTurn.accountUnverifiedResultUsageDelta(completion.usage);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcheckpointUsage(\"Persisted worker compaction provider usage before verification.\");\n\t\t\t\t\t\t\t\tif (providerTurn.hasSuccessfulPreflight()) {\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tproviderTurn.consumeTerminalAssistantAndHold();\n\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\tif (!preflightFailed) {\n\t\t\t\t\t\t\t\t\t\t\tpreflightFailed = true;\n\t\t\t\t\t\t\t\t\t\t\tpreflightFailure = error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\t\trequestSignal.throwIfAborted();\n\t\t\t\t\t\t\t\tif (preflightFailed) throw workerCompletionCallbackFailure(preflightFailure);\n\t\t\t\t\t\t\t\tproviderTurn.assertProviderOutputPreflight(\"compaction\");\n\t\t\t\t\t\t\t\treturn response;\n\t\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t},\n\t\t\tgetFailedCompactionUsage: () => failedCompactionUsage,\n\t\t};\n\t};\n\tconst ledger: WorkerAttemptExecutionLedger = {\n\t\tchangedFiles,\n\t\tgetUsage: currentUsage,\n\t};\n\n\treturn {\n\t\tledger,\n\t\tcheckpointUsage,\n\t\tasync run(): Promise<WorkerAttemptExecutionResult> {\n\t\t\tif (ran) throw new Error(\"A worker attempt executor may run only once.\");\n\t\t\tran = true;\n\t\t\toptions.conversation.beginAttemptUsage(options.durableHandle.attemptId);\n\t\t\tif (!options.hasPersistedUsageCheckpoint) {\n\t\t\t\tcheckpointUsage(\"Persisted deterministic cumulative usage baseline for the durable worker transcript.\");\n\t\t\t}\n\t\t\tconst rawOutcome = await runWorker({\n\t\t\t\trequest: options.request,\n\t\t\t\tmaxUsd: options.grant.budget.maxCostUsd,\n\t\t\t\tmaxWallClockMs: options.grant.budget.maxWallClockMs ?? 0,\n\t\t\t\tusageReportId: options.usageReportId,\n\t\t\t\tgetChangedFiles: () => [...changedFiles],\n\t\t\t\tsignal: options.signal,\n\t\t\t\tcwd: options.cwd,\n\t\t\t\tprocessCapable: options.processCapable,\n\t\t\t\tdelegationCapable: options.toolSurface.allowedTools.includes(\"delegate\"),\n\t\t\t\t...(options.verificationSubjectTaskId\n\t\t\t\t\t? { verificationSubjectTaskId: options.verificationSubjectTaskId }\n\t\t\t\t\t: {}),\n\t\t\t\t...(options.applyActions\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tapplyActions: (actions: readonly WorkerAction[]) => {\n\t\t\t\t\t\t\t\tconst report = options.applyActions!(actions, actionJournal);\n\t\t\t\t\t\t\t\tfor (const filePath of report.changedFiles) recordChangedFile(filePath);\n\t\t\t\t\t\t\t\treturn report;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\tcomplete: async ({ systemPrompt, userPrompt, signal }) => {\n\t\t\t\t\tif (options.recoveredTerminal) {\n\t\t\t\t\t\tcheckpointUsage(\"Reused the persisted terminal worker assistant response after recovery.\");\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttext: options.recoveredTerminal.text,\n\t\t\t\t\t\t\tcostUsd: options.initialUsage.costUsd,\n\t\t\t\t\t\t\tstopReason: options.recoveredTerminal.stopReason,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst retentionPolicy = createRetentionPolicy(signal);\n\t\t\t\t\tconst persistedToolAssistantIds = new Set<string>();\n\t\t\t\t\tconst pendingToolAssistants = new Map<string, AssistantMessage>();\n\t\t\t\t\tlet activeProviderTurn: WorkerProviderTurnProtocol | undefined;\n\t\t\t\t\tconst closeActiveProviderTurn = (): void => {\n\t\t\t\t\t\tconst active = activeProviderTurn;\n\t\t\t\t\t\tactiveProviderTurn = undefined;\n\t\t\t\t\t\tactive?.close();\n\t\t\t\t\t};\n\t\t\t\t\toptions.toolSurface.gateway?.assertBudgetAvailable(\"worker_provider_completion\");\n\t\t\t\t\tconst availableTokens = remainingAttemptTokens();\n\t\t\t\t\tif (availableTokens !== undefined && availableTokens <= 0) {\n\t\t\t\t\t\tthrow new Error(\"Worker token budget exhausted before provider completion.\");\n\t\t\t\t\t}\n\t\t\t\t\toptions.conversation.ensureAttemptUserPrompt(options.durableHandle.attemptId, userPrompt);\n\t\t\t\t\tlet history: Message[] = [];\n\t\t\t\t\tlet completion: IsolatedCompletionResult;\n\t\t\t\t\tconst attemptProviderCompletion = async (): Promise<IsolatedCompletionResult> => {\n\t\t\t\t\t\t// Later attempts resume from the durably persisted transcript, not a stale snapshot.\n\t\t\t\t\t\tconst transcriptCommit = options.conversation.beginTranscriptCommit();\n\t\t\t\t\t\thistory = transcriptCommit.history;\n\t\t\t\t\t\tconst historyLength = history.length;\n\t\t\t\t\t\tconst transcriptCursor = transcriptCommit.cursor;\n\t\t\t\t\t\tconst durableCallbackMessages: Message[] = [];\n\t\t\t\t\t\tlet callbackFailed = false;\n\t\t\t\t\t\tlet callbackFailure: unknown;\n\t\t\t\t\t\tconst retainCallbackFailure = (error: unknown): void => {\n\t\t\t\t\t\t\tif (callbackFailed) return;\n\t\t\t\t\t\t\tcallbackFailed = true;\n\t\t\t\t\t\t\tcallbackFailure = error;\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst providerTurn = new WorkerProviderTurnProtocol({\n\t\t\t\t\t\t\tacquireReservation: () =>\n\t\t\t\t\t\t\t\treserveProviderBudget(\n\t\t\t\t\t\t\t\t\toptions.laneCapability.laneMaxOutputTokens,\n\t\t\t\t\t\t\t\t\t\"worker_provider_completion\",\n\t\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\tonFailure: retainCallbackFailure,\n\t\t\t\t\t\t\t...(options.toolSurface.gateway\n\t\t\t\t\t\t\t\t? { recordUsage: (delta) => options.toolSurface.gateway?.recordUsage(delta) }\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tactiveProviderTurn = providerTurn;\n\t\t\t\t\t\tconst persistToolRequest = (message: AssistantMessage): void => {\n\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\tconst toolCallIds = message.content.flatMap((content) =>\n\t\t\t\t\t\t\t\tcontent.type === \"toolCall\" ? [content.id] : [],\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (toolCallIds.length === 0 || toolCallIds.every((id) => persistedToolAssistantIds.has(id)))\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\tproviderTurn.accountAssistantUsage(message.usage);\n\t\t\t\t\t\t\toptions.conversation.appendMessage(message);\n\t\t\t\t\t\t\tfor (const id of toolCallIds) {\n\t\t\t\t\t\t\t\tpersistedToolAssistantIds.add(id);\n\t\t\t\t\t\t\t\tpendingToolAssistants.delete(id);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcheckpointUsage(\"Persisted worker assistant tool request and its cumulative provider usage.\");\n\t\t\t\t\t\t\tproviderTurn.consumeToolAssistantAndRelease();\n\t\t\t\t\t\t\tdurableCallbackMessages.push(message);\n\t\t\t\t\t\t};\n\t\t\t\t\t\tlet committed = false;\n\t\t\t\t\t\tconst abortTranscriptCursor = (): void => {\n\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\toptions.conversation.abortTranscriptCommit(transcriptCursor);\n\t\t\t\t\t\t};\n\t\t\t\t\t\tsignal.addEventListener(\"abort\", abortTranscriptCursor, { once: true });\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\tlet result: IsolatedCompletionResult;\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tresult = await options.runIsolatedCompletion({\n\t\t\t\t\t\t\t\t\tsystemPrompt: buildWorkerSystemPrompt({\n\t\t\t\t\t\t\t\t\t\tsoul: options.soul,\n\t\t\t\t\t\t\t\t\t\trolePrompt: systemPrompt,\n\t\t\t\t\t\t\t\t\t\tworkerResourceSystemPrompt: options.workerResourceSystemPrompt,\n\t\t\t\t\t\t\t\t\t\tagentDir: options.agentDir,\n\t\t\t\t\t\t\t\t\t\tmodel: options.model,\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\thistory,\n\t\t\t\t\t\t\t\t\tmessages: [],\n\t\t\t\t\t\t\t\t\tmodel: options.model,\n\t\t\t\t\t\t\t\t\tthinkingLevel: options.thinkingLevel,\n\t\t\t\t\t\t\t\t\tmaxTokens: Math.min(\n\t\t\t\t\t\t\t\t\t\toptions.laneCapability.laneMaxOutputTokens,\n\t\t\t\t\t\t\t\t\t\tavailableTokens ?? Number.POSITIVE_INFINITY,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\ttools: options.toolSurface.tools,\n\t\t\t\t\t\t\t\t\trequestPreflight: () => providerTurn.requestPreflight(),\n\t\t\t\t\t\t\t\t\tbeforeToolCall: async (context, toolSignal) => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tpersistToolRequest(context.assistantMessage);\n\t\t\t\t\t\t\t\t\t\t\tconst decision = await options.toolSurface.beforeToolCall(context, toolSignal);\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tif (!decision?.block) {\n\t\t\t\t\t\t\t\t\t\t\t\tcheckpointUsage(\n\t\t\t\t\t\t\t\t\t\t\t\t\t`Authorized worker tool '${context.toolCall.name}' under its durable grant.`,\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\treturn decision;\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tafterToolCall: async ({ toolCall, args }) => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t(toolCall.name === \"write\" || toolCall.name === \"edit\") &&\n\t\t\t\t\t\t\t\t\t\t\t\targs &&\n\t\t\t\t\t\t\t\t\t\t\t\ttypeof args === \"object\" &&\n\t\t\t\t\t\t\t\t\t\t\t\t!Array.isArray(args)\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tconst rawPath = (args as Record<string, unknown>).path;\n\t\t\t\t\t\t\t\t\t\t\t\tif (typeof rawPath === \"string\" && rawPath.length > 0) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tconst absolutePath = path.isAbsolute(rawPath)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t? path.resolve(rawPath)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t: path.resolve(options.cwd, rawPath);\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet canonicalPath = absolutePath;\n\t\t\t\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcanonicalPath = safeRealpathSync(absolutePath);\n\t\t\t\t\t\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t// The operation entered execution; retain its lexical target if canonicalization failed.\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\trecordChangedFile(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tpath.relative(options.cwd, canonicalPath).split(path.sep).join(\"/\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tonMessage: (message, origin) => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tif (message.role === \"assistant\" && isToolRequest(message)) {\n\t\t\t\t\t\t\t\t\t\t\t\t// Known calls are normalized before beforeToolCall and persist from that hook.\n\t\t\t\t\t\t\t\t\t\t\t\t// Retain the request only so immediate unknown/malformed results can close the\n\t\t\t\t\t\t\t\t\t\t\t\t// transcript without freezing pre-repair arguments into durable history.\n\t\t\t\t\t\t\t\t\t\t\t\tfor (const content of message.content) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (content.type === \"toolCall\") pendingToolAssistants.set(content.id, message);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\tmessage.role === \"toolResult\" &&\n\t\t\t\t\t\t\t\t\t\t\t\t!persistedToolAssistantIds.has(message.toolCallId)\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tconst pending = pendingToolAssistants.get(message.toolCallId);\n\t\t\t\t\t\t\t\t\t\t\t\tif (pending) persistToolRequest(pending);\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tif (message.role === \"assistant\" && origin !== \"local\") {\n\t\t\t\t\t\t\t\t\t\t\t\tproviderTurn.accountAssistantUsage(message.usage);\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\toptions.conversation.appendMessage(message);\n\t\t\t\t\t\t\t\t\t\t\toptions.agentControl.acknowledgeMailboxMessage(options.agentId, message);\n\t\t\t\t\t\t\t\t\t\t\tif (message.role === \"assistant\" && origin !== \"local\") {\n\t\t\t\t\t\t\t\t\t\t\t\tcheckpointUsage(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Persisted worker assistant response and its cumulative provider usage.\",\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\tproviderTurn.consumeTerminalAssistantAndHold();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tif (message.role === \"toolResult\")\n\t\t\t\t\t\t\t\t\t\t\t\tcheckpointUsage(`Persisted worker tool result '${message.toolCallId}'.`);\n\t\t\t\t\t\t\t\t\t\t\tdurableCallbackMessages.push(message);\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tgetSteeringMessages: async (): Promise<AgentMessage[]> => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tconst includeFollowUp = firstMailboxPoll;\n\t\t\t\t\t\t\t\t\t\t\tfirstMailboxPoll = false;\n\t\t\t\t\t\t\t\t\t\t\tconst messages = options.agentControl.mailboxMessagesForConversation(\n\t\t\t\t\t\t\t\t\t\t\t\toptions.agentId,\n\t\t\t\t\t\t\t\t\t\t\t\toptions.conversation,\n\t\t\t\t\t\t\t\t\t\t\t\tincludeFollowUp,\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\treturn messages;\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tgetFollowUpMessages: async (): Promise<AgentMessage[]> => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tconst messages = options.agentControl.mailboxMessagesForConversation(\n\t\t\t\t\t\t\t\t\t\t\t\toptions.agentId,\n\t\t\t\t\t\t\t\t\t\t\t\toptions.conversation,\n\t\t\t\t\t\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\treturn messages;\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t...(retentionPolicy\n\t\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\t\ttransformContext: async (messages: AgentMessage[]) => {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tconst retained = await options.conversation.compactProviderContext(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretentionPolicy,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretained.contextUsage.tokens > retentionPolicy.maxContextTokens &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t!retentionWarningEmitted\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretentionWarningEmitted = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\toptions.warn(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`Worker ${options.laneId} has one retained turn larger than its context policy; provider overflow recovery may be required.`,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretained.status !== \"compacted_verified\" &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretained.status !== \"compacted_deterministic\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn messages;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn sanitizeToolFailureContext(retained.context.messages, \"\").messages;\n\t\t\t\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (signal.aborted) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (error instanceof WorkerConversationOwnershipError) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (!retentionWarningEmitted) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretentionWarningEmitted = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\toptions.warn(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`Worker context retention failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn messages;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\t\tcacheRetention: \"short\",\n\t\t\t\t\t\t\t\t\tlaneKind: \"worker\",\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\t\tif (signal.aborted) throw error;\n\t\t\t\t\t\t\t\tif (callbackFailed) throw workerCompletionCallbackFailure(callbackFailure);\n\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tproviderTurn.assertEverySuccessfulPreflightConsumed();\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\tif (providerTurn.accountUnverifiedResultUsageDelta(result.usage)) {\n\t\t\t\t\t\t\t\tcheckpointUsage(\n\t\t\t\t\t\t\t\t\t\"Persisted supplemental provider result usage before rejecting unverified completion evidence.\",\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\tif (callbackFailed) throw workerCompletionCallbackFailure(callbackFailure);\n\t\t\t\t\t\t\tproviderTurn.assertProviderOutputPreflight();\n\t\t\t\t\t\t\tconst evidenced = callbackEvidencedCompletion(result, historyLength, durableCallbackMessages);\n\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\tconst appended = options.conversation.commitTranscript(transcriptCursor, evidenced.suffix, {\n\t\t\t\t\t\t\t\tappendMissing: false,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (appended !== 0) {\n\t\t\t\t\t\t\t\tthrow new WorkerConversationOwnershipError(\n\t\t\t\t\t\t\t\t\t\"Worker callback transcript verification unexpectedly appended missing messages.\",\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcommitted = true;\n\t\t\t\t\t\t\treturn evidenced.completion;\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tsignal.removeEventListener(\"abort\", abortTranscriptCursor);\n\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\tif (activeProviderTurn === providerTurn) activeProviderTurn = undefined;\n\t\t\t\t\t\t\tif (!committed) options.conversation.abortTranscriptCommit(transcriptCursor);\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t\ttry {\n\t\t\t\t\t\tcompletion = await runProviderCompletionWithBackoff({\n\t\t\t\t\t\t\tattempt: attemptProviderCompletion,\n\t\t\t\t\t\t\tonAttemptFailure: closeActiveProviderTurn,\n\t\t\t\t\t\t\tprovider: options.model.provider,\n\t\t\t\t\t\t\tlaneId: options.laneId,\n\t\t\t\t\t\t\twarn: options.warn,\n\t\t\t\t\t\t\t...(signal ? { signal } : {}),\n\t\t\t\t\t\t});\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tcloseActiveProviderTurn();\n\t\t\t\t\t}\n\t\t\t\t\tconst cumulativeUsage = checkpointUsage(\n\t\t\t\t\t\t\"Verified the callback-persisted worker conversation terminal suffix.\",\n\t\t\t\t\t);\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttext: completion.text,\n\t\t\t\t\t\tcostUsd: cumulativeUsage.costUsd,\n\t\t\t\t\t\tstopReason: String(completion.stopReason),\n\t\t\t\t\t\tchangedFiles: [...changedFiles],\n\t\t\t\t\t\tblockers: [...toolIssues],\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst usage = checkpointUsage(\"Persisted final cumulative worker usage before terminal result.\");\n\t\t\treturn { rawOutcome, usage, changedFiles: [...changedFiles] };\n\t\t},\n\t};\n}\n"]}
1
+ {"version":3,"file":"worker-attempt-executor.js","sourceRoot":"","sources":["../../../src/core/delegation/worker-attempt-executor.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,iDAAiD,CAAC;AAC1E,OAAO,EACN,eAAe,EACf,mBAAmB,EAEnB,cAAc,GACd,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,0BAA0B,EAAE,MAAM,+CAA+C,CAAC;AAE3F,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAG7E,OAAO,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AAGlF,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAE7D,OAAO,EAAE,4BAA4B,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACtG,OAAO,EAAE,4BAA4B,EAAkC,MAAM,wCAAwC,CAAC;AAGtH,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAGjE,OAAO,EAAE,gCAAgC,EAAE,MAAM,mCAAmC,CAAC;AAIrF,OAAO,EAAE,6BAA6B,EAAE,0BAA0B,EAAE,MAAM,oCAAoC,CAAC;AAC/G,OAAO,EAAE,SAAS,EAAyB,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,mCAAmC,EAAE,MAAM,sCAAsC,CAAC;AAC3F,OAAO,EAAE,6BAA6B,EAAE,MAAM,qCAAq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;4BAAS,CAAC;wBACV,uBAAuB,EAAE,CAAC;oBAC3B,CAAC;oBACD,MAAM,eAAe,GAAG,eAAe,CACtC,sEAAsE,CACtE,CAAC;oBACF,cAAc,GAAG,UAAU,CAAC,IAAI,CAAC;oBACjC,OAAO;wBACN,IAAI,EAAE,UAAU,CAAC,IAAI;wBACrB,OAAO,EAAE,eAAe,CAAC,OAAO;wBAChC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,UAAU,CAAC;wBACzC,YAAY,EAAE,CAAC,GAAG,YAAY,CAAC;wBAC/B,QAAQ,EAAE,CAAC,GAAG,UAAU,CAAC;qBACzB,CAAC;gBACH,CAAC;aACD,CAAC,CAAC;YACH,MAAM,KAAK,GAAG,eAAe,CAAC,iEAAiE,CAAC,CAAC;YACjG,MAAM,cAAc,GAAG,cAAc;gBACpC,CAAC,CAAC,mCAAmC,CAAC;oBACpC,QAAQ,EAAE,OAAO,CAAC,QAAQ;oBAC1B,eAAe,EAAE,OAAO,CAAC,eAAe;oBACxC,SAAS,EAAE,OAAO,CAAC,aAAa,CAAC,SAAS;oBAC1C,IAAI,EAAE,cAAc;oBACpB,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;iBACnC,CAAC;gBACH,CAAC,CAAC,SAAS,CAAC;YACb,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,GAAG,YAAY,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC;QAC9G,CAAC;KACD,CAAC;AACH,CAAC","sourcesContent":["import path from \"node:path\";\nimport { isDeepStrictEqual } from \"node:util\";\nimport { compact } from \"@caupulican/pi-agent-core/compaction/compaction\";\nimport {\n\tclassifyFailure,\n\tcomputeRetryDelayMs,\n\ttype RetryPolicy,\n\tsleepAbortable,\n} from \"@caupulican/pi-agent-core/reliability\";\nimport { sanitizeToolFailureContext } from \"@caupulican/pi-agent-core/tool-failure-memory\";\nimport type { AgentMessage, ThinkingLevel } from \"@caupulican/pi-agent-core/types\";\nimport { addUsage, createEmptyUsage } from \"@caupulican/pi-agent-core/usage\";\nimport type { Api, AssistantMessage, Message, Model, Usage } from \"@caupulican/pi-ai\";\nimport type { IsolatedCompletionOptions, IsolatedCompletionResult } from \"../agent-session-contracts.ts\";\nimport { BoundedCompletionFailureError } from \"../autonomy/bounded-completion.ts\";\nimport type { WorkerRequest } from \"../autonomy/contracts.ts\";\nimport type { LaneToolSurface } from \"../autonomy/lane-tool-surface.ts\";\nimport { safeRealpathSync } from \"../autonomy/path-scope.ts\";\nimport type { ModelCapabilityProfile } from \"../model-capability.ts\";\nimport { attemptUsageFromGatewayUsage, EMPTY_ATTEMPT_USAGE } from \"../orchestration/attempt-usage.ts\";\nimport { CapabilityGatewayDeniedError, type ProviderBudgetReservation } from \"../orchestration/capability-gateway.ts\";\nimport type { ArtifactContract, AttemptUsageSnapshot, ExecutionGrant } from \"../orchestration/contracts.ts\";\nimport type { StartedDelegationAttempt } from \"../orchestration/delegation-ledger.ts\";\nimport { WorkerActionJournal } from \"./worker-action-journal.ts\";\nimport type { AppliedActionsReport, WorkerAction } from \"./worker-actions.ts\";\nimport type { WorkerAgentControlCoordinator } from \"./worker-agent-control-coordinator.ts\";\nimport { WorkerConversationOwnershipError } from \"./worker-conversation-revision.ts\";\nimport type { WorkerConversation, WorkerConversationRetentionPolicy } from \"./worker-conversation-store.ts\";\nimport type { WorkerExecutionPlan } from \"./worker-execution-policy.ts\";\nimport type { WorkerLifecycle } from \"./worker-lifecycle.ts\";\nimport { WorkerCompletionProtocolError, WorkerProviderTurnProtocol } from \"./worker-provider-turn-protocol.ts\";\nimport { runWorker, type WorkerRunOutcome } from \"./worker-runner.ts\";\nimport { buildWorkerSystemPrompt } from \"./worker-system-prompt.ts\";\nimport { captureWorkerTerminalOutputArtifact } from \"./worker-terminal-output-artifact.ts\";\nimport { WorkerTreeBudgetExceededError } from \"./worker-tree-budget-coordinator.ts\";\n\nexport interface RecoveredWorkerTerminalCompletion {\n\ttext: string;\n\tusage: Usage;\n\tstopReason: string;\n}\n\n/** The live mutable state that must be visible to session disposal before provider work yields. */\nexport interface WorkerAttemptExecutionLedger {\n\tchangedFiles: Set<string>;\n\tgetUsage(): AttemptUsageSnapshot;\n}\n\nexport interface WorkerAttemptExecutionResult {\n\trawOutcome: WorkerRunOutcome;\n\tusage: AttemptUsageSnapshot;\n\tchangedFiles: readonly string[];\n\toutputArtifact?: ArtifactContract;\n}\n\n/**\n * Backoff policy for transient worker provider failures. Without it, a dropped provider socket\n * kills the attempt instantly at $0 spend and an immediate re-dispatch hits the same dead\n * connection (field session 019fd4dc: paired $0 `completion_error` lanes ~10s apart). Jitter\n * de-synchronizes sibling workers that all lost the same connection at once.\n */\nconst WORKER_PROVIDER_RETRY_POLICY: RetryPolicy = {\n\tmaxAttempts: 3,\n\tbaseDelayMs: 2_000,\n\tmaxDelayMs: 30_000,\n\tjitterRatio: 0.2,\n};\n\nexport async function runProviderCompletionWithBackoff(args: {\n\tattempt: () => Promise<IsolatedCompletionResult>;\n\t/** Release per-attempt provider reservations before waiting; the final failure is rethrown. */\n\tonAttemptFailure: () => void;\n\tprovider: string;\n\tlaneId: string;\n\twarn: (message: string) => void;\n\tsignal?: AbortSignal;\n}): Promise<IsolatedCompletionResult> {\n\tfor (let attempt = 1; ; attempt++) {\n\t\ttry {\n\t\t\tconst completion = await args.attempt();\n\t\t\tif (completion.stopReason !== \"error\") return completion;\n\t\t\tthrow new Error(\n\t\t\t\tcompletion.errorMessage?.trim() || \"Provider completion stopped with an error without diagnostic detail.\",\n\t\t\t);\n\t\t} catch (error) {\n\t\t\targs.onAttemptFailure();\n\t\t\tif (args.signal?.aborted) throw error;\n\t\t\tif (error instanceof WorkerCompletionProtocolError) {\n\t\t\t\tthrow new BoundedCompletionFailureError(\"failed\", \"worker_protocol_error\", error.message, error);\n\t\t\t}\n\t\t\tif (\n\t\t\t\terror instanceof WorkerConversationOwnershipError ||\n\t\t\t\terror instanceof CapabilityGatewayDeniedError ||\n\t\t\t\terror instanceof WorkerTreeBudgetExceededError ||\n\t\t\t\terror instanceof BoundedCompletionFailureError\n\t\t\t) {\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t\tconst classified = classifyFailure({\n\t\t\t\tmessage: error instanceof Error ? error.message : String(error),\n\t\t\t\tprovider: args.provider,\n\t\t\t});\n\t\t\tif (!classified.retryable || attempt >= WORKER_PROVIDER_RETRY_POLICY.maxAttempts) {\n\t\t\t\tconst message = error instanceof Error ? error.message : String(error);\n\t\t\t\tthrow new BoundedCompletionFailureError(\"failed\", \"completion_error\", message, error);\n\t\t\t}\n\t\t\tconst delayMs = computeRetryDelayMs(WORKER_PROVIDER_RETRY_POLICY, attempt, {\n\t\t\t\t...(classified.retryAfterMs !== undefined ? { retryAfterMs: classified.retryAfterMs } : {}),\n\t\t\t});\n\t\t\targs.warn(\n\t\t\t\t`Worker ${args.laneId} provider request failed (${classified.reason}); retrying in ${Math.ceil(delayMs / 1000)}s (attempt ${attempt + 1}/${WORKER_PROVIDER_RETRY_POLICY.maxAttempts}).`,\n\t\t\t);\n\t\t\tawait sleepAbortable(delayMs, args.signal);\n\t\t}\n\t}\n}\n\n/**\n * The provider/tool-loop portion of a prepared worker attempt.\n *\n * Admission, durable leasing, grant compilation, terminalization, notification, verification, and\n * scheduling remain outside this boundary. This unit owns only the ordered child conversation:\n * persist assistant tool requests before execution, append messages before mailbox acknowledgements,\n * checkpoint cumulative usage before later boundaries, and compact only the provider projection.\n */\nexport interface WorkerAttemptExecutorOptions {\n\trequest: WorkerRequest;\n\tgrant: ExecutionGrant;\n\texecutionPlan: WorkerExecutionPlan;\n\ttoolSurface: LaneToolSurface;\n\tconversation: WorkerConversation;\n\tlifecycle: Pick<WorkerLifecycle, \"checkpoint\">;\n\tlaneId: string;\n\tagentId: string;\n\tdurableHandle: StartedDelegationAttempt;\n\tparentSessionId: string;\n\tagentDir: string;\n\tcwd: string;\n\tmodel: Model<Api>;\n\tthinkingLevel?: ThinkingLevel;\n\tlaneCapability: Pick<ModelCapabilityProfile, \"laneMaxOutputTokens\">;\n\tsoul?: string;\n\tworkerResourceSystemPrompt: string;\n\tinitialUsage: AttemptUsageSnapshot;\n\thasPersistedUsageCheckpoint: boolean;\n\tusageReportId: string;\n\tprocessCapable: boolean;\n\tverificationSubjectTaskId?: string;\n\trecoveredTerminal?: RecoveredWorkerTerminalCompletion;\n\tretentionPolicy?: WorkerConversationRetentionPolicy;\n\tsignal?: AbortSignal;\n\trunIsolatedCompletion(options: IsolatedCompletionOptions): Promise<IsolatedCompletionResult>;\n\tagentControl: Pick<WorkerAgentControlCoordinator, \"acknowledgeMailboxMessage\" | \"mailboxMessagesForConversation\">;\n\tapplyActions?(actions: readonly WorkerAction[], actionJournal?: WorkerActionJournal): AppliedActionsReport;\n\twarn(message: string): void;\n}\n\nfunction isToolRequest(message: Message): boolean {\n\treturn message.role === \"assistant\" && message.content.some((content) => content.type === \"toolCall\");\n}\n\nfunction workerCompletionCallbackFailure(error: unknown): Error {\n\tif (\n\t\terror instanceof WorkerCompletionProtocolError ||\n\t\terror instanceof WorkerConversationOwnershipError ||\n\t\terror instanceof CapabilityGatewayDeniedError ||\n\t\terror instanceof WorkerTreeBudgetExceededError\n\t) {\n\t\treturn error;\n\t}\n\treturn new WorkerCompletionProtocolError(\n\t\t\"Worker completion callback failed before its authority and durable transcript were verified.\",\n\t);\n}\n\nfunction callbackEvidencedCompletion(\n\tresult: IsolatedCompletionResult,\n\thistoryLength: number,\n\temittedMessages: readonly Message[],\n): { completion: IsolatedCompletionResult; suffix: Message[] } {\n\tif (result.messages !== undefined && result.messages.length < historyLength) {\n\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\"Worker completion protocol returned fewer messages than its input history.\",\n\t\t);\n\t}\n\tlet suffix: Message[];\n\tif (result.messages !== undefined) {\n\t\tsuffix = result.messages.slice(historyLength);\n\t\tif (!isDeepStrictEqual(suffix, emittedMessages)) {\n\t\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\t\"Worker completion protocol returned a suffix without exact callback evidence.\",\n\t\t\t);\n\t\t}\n\t} else {\n\t\tsuffix = [...emittedMessages];\n\t}\n\tif (suffix.length === 0) {\n\t\tthrow new WorkerCompletionProtocolError(\"Worker completion protocol returned no durable message suffix.\");\n\t}\n\tif (!suffix.some((message) => message.role === \"assistant\")) {\n\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\"Worker completion protocol returned no assistant in its durable suffix.\",\n\t\t);\n\t}\n\tconst assistants = emittedMessages.filter((message): message is AssistantMessage => message.role === \"assistant\");\n\tconst finalMessage = emittedMessages.at(-1);\n\tif (!finalMessage || finalMessage.role !== \"assistant\") {\n\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\"Worker completion protocol did not durably emit an assistant as its terminal message.\",\n\t\t);\n\t}\n\tconst usage = createEmptyUsage();\n\tfor (const assistant of assistants) addUsage(usage, assistant.usage);\n\tconst text = finalMessage.content.flatMap((content) => (content.type === \"text\" ? [content.text] : [])).join(\"\");\n\tif (\n\t\tresult.text !== text ||\n\t\tresult.stopReason !== finalMessage.stopReason ||\n\t\t!isDeepStrictEqual(result.usage, usage) ||\n\t\tresult.errorMessage !== finalMessage.errorMessage\n\t) {\n\t\tthrow new WorkerCompletionProtocolError(\n\t\t\t\"Worker completion result disagrees with its durable callback-evidenced terminal assistant.\",\n\t\t);\n\t}\n\treturn {\n\t\tsuffix,\n\t\tcompletion: {\n\t\t\ttext,\n\t\t\tusage,\n\t\t\tstopReason: finalMessage.stopReason,\n\t\t\t...(finalMessage.errorMessage ? { errorMessage: finalMessage.errorMessage } : {}),\n\t\t},\n\t};\n}\n\n/**\n * Constructs one execution exactly once. The caller registers {@link ledger} before calling\n * {@link run}, allowing synchronous disposal to observe mutations and cumulative usage while the\n * provider/tool loop is suspended.\n */\nexport function createWorkerAttemptExecutor(options: WorkerAttemptExecutorOptions): {\n\tledger: WorkerAttemptExecutionLedger;\n\tcheckpointUsage(summary: string): AttemptUsageSnapshot;\n\trun(): Promise<WorkerAttemptExecutionResult>;\n} {\n\tconst changedFiles = new Set(options.conversation.getChangedFiles(options.durableHandle.attemptId));\n\tconst toolIssues = new Set<string>();\n\tconst recordChangedFile = (filePath: string): void => {\n\t\tchangedFiles.add(filePath);\n\t\ttry {\n\t\t\toptions.conversation.recordChangedFile(options.durableHandle.attemptId, filePath);\n\t\t} catch (error) {\n\t\t\ttoolIssues.add(\"worker changed-file progress could not be persisted; parent review is required\");\n\t\t\toptions.warn(\n\t\t\t\t`Worker changed-file progress persistence failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t);\n\t\t}\n\t};\n\tconst actionJournal = options.request.envelope.capabilities.includes(\"filesystem.write\")\n\t\t? new WorkerActionJournal({\n\t\t\t\tagentDir: options.agentDir,\n\t\t\t\tparentSessionId: options.parentSessionId,\n\t\t\t\ttaskId: options.durableHandle.taskId,\n\t\t\t\tattemptId: options.durableHandle.attemptId,\n\t\t\t\tfencingToken: options.durableHandle.fencingToken,\n\t\t\t})\n\t\t: undefined;\n\tlet retentionWarningEmitted = false;\n\tlet firstMailboxPoll = true;\n\tlet ran = false;\n\tlet terminalOutput: string | undefined;\n\n\tconst currentUsage = (): AttemptUsageSnapshot =>\n\t\tattemptUsageFromGatewayUsage(\n\t\t\toptions.toolSurface.gateway?.getUsage() ?? {\n\t\t\t\t...EMPTY_ATTEMPT_USAGE,\n\t\t\t\twallClockMs: options.initialUsage.activeWallClockMs,\n\t\t\t},\n\t\t);\n\tconst checkpointUsage = (summary: string): AttemptUsageSnapshot => {\n\t\tconst usage = currentUsage();\n\t\toptions.lifecycle.checkpoint(options.laneId, { summary, usage });\n\t\treturn usage;\n\t};\n\tconst remainingAttemptTokens = (): number | undefined => options.toolSurface.gateway?.remainingAttemptTokenBudget();\n\tconst reserveProviderBudget = async (\n\t\trequestedMaxTokens: number,\n\t\tsubject: string,\n\t\tsignal?: AbortSignal,\n\t): Promise<ProviderBudgetReservation> => {\n\t\tif (options.toolSurface.gateway) {\n\t\t\treturn options.toolSurface.gateway.reserveProviderBudget(requestedMaxTokens, subject, signal);\n\t\t}\n\t\tif (signal?.aborted) throw signal.reason;\n\t\treturn { maxTokens: requestedMaxTokens, release: () => undefined };\n\t};\n\tconst createRetentionPolicy = (completeSignal: AbortSignal): WorkerConversationRetentionPolicy | undefined => {\n\t\tif (!options.retentionPolicy) return undefined;\n\t\tlet failedCompactionUsage: Usage | undefined;\n\t\treturn {\n\t\t\t...options.retentionPolicy,\n\t\t\tgenerateVerifiedCompaction: async (preparation: Parameters<typeof compact>[0]) => {\n\t\t\t\tconst compactionUsage = createEmptyUsage();\n\t\t\t\tfailedCompactionUsage = compactionUsage;\n\t\t\t\treturn compact(\n\t\t\t\t\tpreparation,\n\t\t\t\t\toptions.model,\n\t\t\t\t\tundefined,\n\t\t\t\t\tundefined,\n\t\t\t\t\tundefined,\n\t\t\t\t\tcompleteSignal,\n\t\t\t\t\toptions.thinkingLevel,\n\t\t\t\t\tundefined,\n\t\t\t\t\tundefined,\n\t\t\t\t\t{\n\t\t\t\t\t\tcompletion: async (model, context, requestOptions): Promise<AssistantMessage> => {\n\t\t\t\t\t\t\tconst requestSignal = requestOptions.signal ?? completeSignal;\n\t\t\t\t\t\t\trequestSignal.throwIfAborted();\n\t\t\t\t\t\t\tif (model.provider !== options.model.provider || model.id !== options.model.id) {\n\t\t\t\t\t\t\t\tthrow new Error(\"Worker compaction attempted to select a model outside the lane binding.\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\toptions.toolSurface.gateway?.assertBudgetAvailable(\"worker_compaction_provider_completion\");\n\t\t\t\t\t\t\tconst availableTokens = remainingAttemptTokens();\n\t\t\t\t\t\t\tif (availableTokens !== undefined && availableTokens <= 0) {\n\t\t\t\t\t\t\t\tthrow new Error(\"Worker token budget exhausted before compaction provider completion.\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tconst requestedMaxTokens = requestOptions.maxTokens;\n\t\t\t\t\t\t\tconst configuredMaxTokens =\n\t\t\t\t\t\t\t\ttypeof requestedMaxTokens === \"number\" &&\n\t\t\t\t\t\t\t\tNumber.isSafeInteger(requestedMaxTokens) &&\n\t\t\t\t\t\t\t\trequestedMaxTokens > 0\n\t\t\t\t\t\t\t\t\t? requestedMaxTokens\n\t\t\t\t\t\t\t\t\t: options.laneCapability.laneMaxOutputTokens;\n\t\t\t\t\t\t\tconst maxTokens = Math.min(configuredMaxTokens, availableTokens ?? configuredMaxTokens);\n\t\t\t\t\t\t\tif (!Number.isSafeInteger(maxTokens) || maxTokens <= 0) {\n\t\t\t\t\t\t\t\tthrow new Error(\"Worker compaction provider completion has no valid remaining token budget.\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tlet preflightFailed = false;\n\t\t\t\t\t\t\tlet preflightFailure: unknown;\n\t\t\t\t\t\t\tconst providerTurn = new WorkerProviderTurnProtocol({\n\t\t\t\t\t\t\t\tacquireReservation: () =>\n\t\t\t\t\t\t\t\t\treserveProviderBudget(maxTokens, \"worker_compaction_provider_completion\", requestSignal),\n\t\t\t\t\t\t\t\tsignal: requestSignal,\n\t\t\t\t\t\t\t\tonFailure: (error) => {\n\t\t\t\t\t\t\t\t\tif (preflightFailed) return;\n\t\t\t\t\t\t\t\t\tpreflightFailed = true;\n\t\t\t\t\t\t\t\t\tpreflightFailure = error;\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t...(options.toolSurface.gateway\n\t\t\t\t\t\t\t\t\t? { recordUsage: (delta) => options.toolSurface.gateway?.recordUsage(delta) }\n\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tlet completion: IsolatedCompletionResult;\n\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\tcompletion = await options.runIsolatedCompletion({\n\t\t\t\t\t\t\t\t\t\tsystemPrompt: context.systemPrompt ?? \"\",\n\t\t\t\t\t\t\t\t\t\tmessages: context.messages,\n\t\t\t\t\t\t\t\t\t\tmodel: options.model,\n\t\t\t\t\t\t\t\t\t\tthinkingLevel: options.thinkingLevel,\n\t\t\t\t\t\t\t\t\t\tmaxTokens,\n\t\t\t\t\t\t\t\t\t\trequestPreflight: () => providerTurn.requestPreflight(),\n\t\t\t\t\t\t\t\t\t\tsignal: requestSignal,\n\t\t\t\t\t\t\t\t\t\tcacheRetention: \"none\",\n\t\t\t\t\t\t\t\t\t\tlaneKind: \"worker-compaction\",\n\t\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\t\t\trequestSignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\tif (preflightFailed) throw workerCompletionCallbackFailure(preflightFailure);\n\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\trequestSignal.throwIfAborted();\n\t\t\t\t\t\t\t\tconst response: AssistantMessage = {\n\t\t\t\t\t\t\t\t\trole: \"assistant\",\n\t\t\t\t\t\t\t\t\tcontent: completion.text ? [{ type: \"text\", text: completion.text }] : [],\n\t\t\t\t\t\t\t\t\tapi: options.model.api,\n\t\t\t\t\t\t\t\t\tprovider: options.model.provider,\n\t\t\t\t\t\t\t\t\tmodel: options.model.id,\n\t\t\t\t\t\t\t\t\tusage: completion.usage,\n\t\t\t\t\t\t\t\t\tstopReason: completion.stopReason,\n\t\t\t\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t\t\t\t\t...(completion.stopReason === \"error\"\n\t\t\t\t\t\t\t\t\t\t? { errorMessage: completion.text || \"Worker compaction provider request failed.\" }\n\t\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\taddUsage(compactionUsage, completion.usage);\n\t\t\t\t\t\t\t\tif (providerTurn.hasOutstandingAssistantReservation()) {\n\t\t\t\t\t\t\t\t\tproviderTurn.accountAssistantUsage(completion.usage);\n\t\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\t\tproviderTurn.accountUnverifiedResultUsageDelta(completion.usage);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tcheckpointUsage(\"Persisted worker compaction provider usage before verification.\");\n\t\t\t\t\t\t\t\tif (providerTurn.hasSuccessfulPreflight()) {\n\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\tproviderTurn.consumeTerminalAssistantAndHold();\n\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\tif (!preflightFailed) {\n\t\t\t\t\t\t\t\t\t\t\tpreflightFailed = true;\n\t\t\t\t\t\t\t\t\t\t\tpreflightFailure = error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\t\trequestSignal.throwIfAborted();\n\t\t\t\t\t\t\t\tif (preflightFailed) throw workerCompletionCallbackFailure(preflightFailure);\n\t\t\t\t\t\t\t\tproviderTurn.assertProviderOutputPreflight(\"compaction\");\n\t\t\t\t\t\t\t\treturn response;\n\t\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t},\n\t\t\tgetFailedCompactionUsage: () => failedCompactionUsage,\n\t\t};\n\t};\n\tconst ledger: WorkerAttemptExecutionLedger = {\n\t\tchangedFiles,\n\t\tgetUsage: currentUsage,\n\t};\n\n\treturn {\n\t\tledger,\n\t\tcheckpointUsage,\n\t\tasync run(): Promise<WorkerAttemptExecutionResult> {\n\t\t\tif (ran) throw new Error(\"A worker attempt executor may run only once.\");\n\t\t\tran = true;\n\t\t\toptions.conversation.beginAttemptUsage(options.durableHandle.attemptId);\n\t\t\tif (!options.hasPersistedUsageCheckpoint) {\n\t\t\t\tcheckpointUsage(\"Persisted deterministic cumulative usage baseline for the durable worker transcript.\");\n\t\t\t}\n\t\t\tconst rawOutcome = await runWorker({\n\t\t\t\trequest: options.request,\n\t\t\t\tmaxUsd: options.grant.budget.maxCostUsd,\n\t\t\t\tmaxWallClockMs: options.grant.budget.maxWallClockMs ?? 0,\n\t\t\t\tusageReportId: options.usageReportId,\n\t\t\t\tgetChangedFiles: () => [...changedFiles],\n\t\t\t\tsignal: options.signal,\n\t\t\t\tcwd: options.cwd,\n\t\t\t\tprocessCapable: options.processCapable,\n\t\t\t\tdelegationCapable: options.toolSurface.allowedTools.includes(\"delegate\"),\n\t\t\t\t...(options.verificationSubjectTaskId\n\t\t\t\t\t? { verificationSubjectTaskId: options.verificationSubjectTaskId }\n\t\t\t\t\t: {}),\n\t\t\t\t...(options.applyActions\n\t\t\t\t\t? {\n\t\t\t\t\t\t\tapplyActions: (actions: readonly WorkerAction[]) => {\n\t\t\t\t\t\t\t\tconst report = options.applyActions!(actions, actionJournal);\n\t\t\t\t\t\t\t\tfor (const filePath of report.changedFiles) recordChangedFile(filePath);\n\t\t\t\t\t\t\t\treturn report;\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t}\n\t\t\t\t\t: {}),\n\t\t\t\tcomplete: async ({ systemPrompt, userPrompt, signal }) => {\n\t\t\t\t\tif (options.recoveredTerminal) {\n\t\t\t\t\t\tterminalOutput = options.recoveredTerminal.text;\n\t\t\t\t\t\tcheckpointUsage(\"Reused the persisted terminal worker assistant response after recovery.\");\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\ttext: options.recoveredTerminal.text,\n\t\t\t\t\t\t\tcostUsd: options.initialUsage.costUsd,\n\t\t\t\t\t\t\tstopReason: options.recoveredTerminal.stopReason,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\tconst retentionPolicy = createRetentionPolicy(signal);\n\t\t\t\t\tconst persistedToolAssistantIds = new Set<string>();\n\t\t\t\t\tconst pendingToolAssistants = new Map<string, AssistantMessage>();\n\t\t\t\t\tlet activeProviderTurn: WorkerProviderTurnProtocol | undefined;\n\t\t\t\t\tconst closeActiveProviderTurn = (): void => {\n\t\t\t\t\t\tconst active = activeProviderTurn;\n\t\t\t\t\t\tactiveProviderTurn = undefined;\n\t\t\t\t\t\tactive?.close();\n\t\t\t\t\t};\n\t\t\t\t\toptions.toolSurface.gateway?.assertBudgetAvailable(\"worker_provider_completion\");\n\t\t\t\t\tconst availableTokens = remainingAttemptTokens();\n\t\t\t\t\tif (availableTokens !== undefined && availableTokens <= 0) {\n\t\t\t\t\t\tthrow new Error(\"Worker token budget exhausted before provider completion.\");\n\t\t\t\t\t}\n\t\t\t\t\toptions.conversation.ensureAttemptUserPrompt(options.durableHandle.attemptId, userPrompt);\n\t\t\t\t\tlet history: Message[] = [];\n\t\t\t\t\tlet completion: IsolatedCompletionResult;\n\t\t\t\t\tconst attemptProviderCompletion = async (): Promise<IsolatedCompletionResult> => {\n\t\t\t\t\t\t// Later attempts resume from the durably persisted transcript, not a stale snapshot.\n\t\t\t\t\t\tconst transcriptCommit = options.conversation.beginTranscriptCommit();\n\t\t\t\t\t\thistory = transcriptCommit.history;\n\t\t\t\t\t\tconst historyLength = history.length;\n\t\t\t\t\t\tconst transcriptCursor = transcriptCommit.cursor;\n\t\t\t\t\t\tconst durableCallbackMessages: Message[] = [];\n\t\t\t\t\t\tlet callbackFailed = false;\n\t\t\t\t\t\tlet callbackFailure: unknown;\n\t\t\t\t\t\tconst retainCallbackFailure = (error: unknown): void => {\n\t\t\t\t\t\t\tif (callbackFailed) return;\n\t\t\t\t\t\t\tcallbackFailed = true;\n\t\t\t\t\t\t\tcallbackFailure = error;\n\t\t\t\t\t\t};\n\t\t\t\t\t\tconst providerTurn = new WorkerProviderTurnProtocol({\n\t\t\t\t\t\t\tacquireReservation: () =>\n\t\t\t\t\t\t\t\treserveProviderBudget(\n\t\t\t\t\t\t\t\t\toptions.laneCapability.laneMaxOutputTokens,\n\t\t\t\t\t\t\t\t\t\"worker_provider_completion\",\n\t\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\tonFailure: retainCallbackFailure,\n\t\t\t\t\t\t\t...(options.toolSurface.gateway\n\t\t\t\t\t\t\t\t? { recordUsage: (delta) => options.toolSurface.gateway?.recordUsage(delta) }\n\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t});\n\t\t\t\t\t\tactiveProviderTurn = providerTurn;\n\t\t\t\t\t\tconst persistToolRequest = (message: AssistantMessage): void => {\n\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\tconst toolCallIds = message.content.flatMap((content) =>\n\t\t\t\t\t\t\t\tcontent.type === \"toolCall\" ? [content.id] : [],\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tif (toolCallIds.length === 0 || toolCallIds.every((id) => persistedToolAssistantIds.has(id)))\n\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\tproviderTurn.accountAssistantUsage(message.usage);\n\t\t\t\t\t\t\toptions.conversation.appendMessage(message);\n\t\t\t\t\t\t\tfor (const id of toolCallIds) {\n\t\t\t\t\t\t\t\tpersistedToolAssistantIds.add(id);\n\t\t\t\t\t\t\t\tpendingToolAssistants.delete(id);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcheckpointUsage(\"Persisted worker assistant tool request and its cumulative provider usage.\");\n\t\t\t\t\t\t\tproviderTurn.consumeToolAssistantAndRelease();\n\t\t\t\t\t\t\tdurableCallbackMessages.push(message);\n\t\t\t\t\t\t};\n\t\t\t\t\t\tlet committed = false;\n\t\t\t\t\t\tconst abortTranscriptCursor = (): void => {\n\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\toptions.conversation.abortTranscriptCommit(transcriptCursor);\n\t\t\t\t\t\t};\n\t\t\t\t\t\tsignal.addEventListener(\"abort\", abortTranscriptCursor, { once: true });\n\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\tlet result: IsolatedCompletionResult;\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tresult = await options.runIsolatedCompletion({\n\t\t\t\t\t\t\t\t\tsystemPrompt: buildWorkerSystemPrompt({\n\t\t\t\t\t\t\t\t\t\tsoul: options.soul,\n\t\t\t\t\t\t\t\t\t\trolePrompt: systemPrompt,\n\t\t\t\t\t\t\t\t\t\tworkerResourceSystemPrompt: options.workerResourceSystemPrompt,\n\t\t\t\t\t\t\t\t\t\tagentDir: options.agentDir,\n\t\t\t\t\t\t\t\t\t\tmodel: options.model,\n\t\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t\t\thistory,\n\t\t\t\t\t\t\t\t\tmessages: [],\n\t\t\t\t\t\t\t\t\tmodel: options.model,\n\t\t\t\t\t\t\t\t\tthinkingLevel: options.thinkingLevel,\n\t\t\t\t\t\t\t\t\tmaxTokens: Math.min(\n\t\t\t\t\t\t\t\t\t\toptions.laneCapability.laneMaxOutputTokens,\n\t\t\t\t\t\t\t\t\t\tavailableTokens ?? Number.POSITIVE_INFINITY,\n\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\ttools: options.toolSurface.tools,\n\t\t\t\t\t\t\t\t\trequestPreflight: () => providerTurn.requestPreflight(),\n\t\t\t\t\t\t\t\t\tbeforeToolCall: async (context, toolSignal) => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tpersistToolRequest(context.assistantMessage);\n\t\t\t\t\t\t\t\t\t\t\tconst decision = await options.toolSurface.beforeToolCall(context, toolSignal);\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tif (!decision?.block) {\n\t\t\t\t\t\t\t\t\t\t\t\tcheckpointUsage(\n\t\t\t\t\t\t\t\t\t\t\t\t\t`Authorized worker tool '${context.toolCall.name}' under its durable grant.`,\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\treturn decision;\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tafterToolCall: async ({ toolCall, args }) => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t(toolCall.name === \"write\" || toolCall.name === \"edit\") &&\n\t\t\t\t\t\t\t\t\t\t\t\targs &&\n\t\t\t\t\t\t\t\t\t\t\t\ttypeof args === \"object\" &&\n\t\t\t\t\t\t\t\t\t\t\t\t!Array.isArray(args)\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tconst rawPath = (args as Record<string, unknown>).path;\n\t\t\t\t\t\t\t\t\t\t\t\tif (typeof rawPath === \"string\" && rawPath.length > 0) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tconst absolutePath = path.isAbsolute(rawPath)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t? path.resolve(rawPath)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t: path.resolve(options.cwd, rawPath);\n\t\t\t\t\t\t\t\t\t\t\t\t\tlet canonicalPath = absolutePath;\n\t\t\t\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcanonicalPath = safeRealpathSync(absolutePath);\n\t\t\t\t\t\t\t\t\t\t\t\t\t} catch {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t// The operation entered execution; retain its lexical target if canonicalization failed.\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\trecordChangedFile(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tpath.relative(options.cwd, canonicalPath).split(path.sep).join(\"/\"),\n\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\treturn undefined;\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tonMessage: (message, origin) => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tif (message.role === \"assistant\" && isToolRequest(message)) {\n\t\t\t\t\t\t\t\t\t\t\t\t// Known calls are normalized before beforeToolCall and persist from that hook.\n\t\t\t\t\t\t\t\t\t\t\t\t// Retain the request only so immediate unknown/malformed results can close the\n\t\t\t\t\t\t\t\t\t\t\t\t// transcript without freezing pre-repair arguments into durable history.\n\t\t\t\t\t\t\t\t\t\t\t\tfor (const content of message.content) {\n\t\t\t\t\t\t\t\t\t\t\t\t\tif (content.type === \"toolCall\") pendingToolAssistants.set(content.id, message);\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\treturn;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\tmessage.role === \"toolResult\" &&\n\t\t\t\t\t\t\t\t\t\t\t\t!persistedToolAssistantIds.has(message.toolCallId)\n\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\tconst pending = pendingToolAssistants.get(message.toolCallId);\n\t\t\t\t\t\t\t\t\t\t\t\tif (pending) persistToolRequest(pending);\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tif (message.role === \"assistant\" && origin !== \"local\") {\n\t\t\t\t\t\t\t\t\t\t\t\tproviderTurn.accountAssistantUsage(message.usage);\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\toptions.conversation.appendMessage(message);\n\t\t\t\t\t\t\t\t\t\t\toptions.agentControl.acknowledgeMailboxMessage(options.agentId, message);\n\t\t\t\t\t\t\t\t\t\t\tif (message.role === \"assistant\" && origin !== \"local\") {\n\t\t\t\t\t\t\t\t\t\t\t\tcheckpointUsage(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\"Persisted worker assistant response and its cumulative provider usage.\",\n\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\tproviderTurn.consumeTerminalAssistantAndHold();\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\tif (message.role === \"toolResult\")\n\t\t\t\t\t\t\t\t\t\t\t\tcheckpointUsage(`Persisted worker tool result '${message.toolCallId}'.`);\n\t\t\t\t\t\t\t\t\t\t\tdurableCallbackMessages.push(message);\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tgetSteeringMessages: async (): Promise<AgentMessage[]> => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tconst includeFollowUp = firstMailboxPoll;\n\t\t\t\t\t\t\t\t\t\t\tfirstMailboxPoll = false;\n\t\t\t\t\t\t\t\t\t\t\tconst messages = options.agentControl.mailboxMessagesForConversation(\n\t\t\t\t\t\t\t\t\t\t\t\toptions.agentId,\n\t\t\t\t\t\t\t\t\t\t\t\toptions.conversation,\n\t\t\t\t\t\t\t\t\t\t\t\tincludeFollowUp,\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\treturn messages;\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\tgetFollowUpMessages: async (): Promise<AgentMessage[]> => {\n\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\tconst messages = options.agentControl.mailboxMessagesForConversation(\n\t\t\t\t\t\t\t\t\t\t\t\toptions.agentId,\n\t\t\t\t\t\t\t\t\t\t\t\toptions.conversation,\n\t\t\t\t\t\t\t\t\t\t\t\ttrue,\n\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\treturn messages;\n\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t...(retentionPolicy\n\t\t\t\t\t\t\t\t\t\t? {\n\t\t\t\t\t\t\t\t\t\t\t\ttransformContext: async (messages: AgentMessage[]) => {\n\t\t\t\t\t\t\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tconst retained = await options.conversation.compactProviderContext(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretentionPolicy,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretained.contextUsage.tokens > retentionPolicy.maxContextTokens &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t!retentionWarningEmitted\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretentionWarningEmitted = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\toptions.warn(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`Worker ${options.laneId} has one retained turn larger than its context policy; provider overflow recovery may be required.`,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretained.status !== \"compacted_verified\" &&\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretained.status !== \"compacted_deterministic\"\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn messages;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn sanitizeToolFailureContext(retained.context.messages, \"\").messages;\n\t\t\t\t\t\t\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (signal.aborted) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (error instanceof WorkerConversationOwnershipError) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif (!retentionWarningEmitted) {\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tretentionWarningEmitted = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\toptions.warn(\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t`Worker context retention failed: ${error instanceof Error ? error.message : String(error)}`,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t\treturn messages;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t: {}),\n\t\t\t\t\t\t\t\t\tsignal,\n\t\t\t\t\t\t\t\t\tcacheRetention: \"short\",\n\t\t\t\t\t\t\t\t\tlaneKind: \"worker\",\n\t\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\t\tif (signal.aborted) throw error;\n\t\t\t\t\t\t\t\tif (callbackFailed) throw workerCompletionCallbackFailure(callbackFailure);\n\t\t\t\t\t\t\t\tthrow error;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\ttry {\n\t\t\t\t\t\t\t\tproviderTurn.assertEverySuccessfulPreflightConsumed();\n\t\t\t\t\t\t\t} catch (error) {\n\t\t\t\t\t\t\t\tretainCallbackFailure(error);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\tif (providerTurn.accountUnverifiedResultUsageDelta(result.usage)) {\n\t\t\t\t\t\t\t\tcheckpointUsage(\n\t\t\t\t\t\t\t\t\t\"Persisted supplemental provider result usage before rejecting unverified completion evidence.\",\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\tif (callbackFailed) throw workerCompletionCallbackFailure(callbackFailure);\n\t\t\t\t\t\t\tproviderTurn.assertProviderOutputPreflight();\n\t\t\t\t\t\t\tconst evidenced = callbackEvidencedCompletion(result, historyLength, durableCallbackMessages);\n\t\t\t\t\t\t\tsignal.throwIfAborted();\n\t\t\t\t\t\t\tconst appended = options.conversation.commitTranscript(transcriptCursor, evidenced.suffix, {\n\t\t\t\t\t\t\t\tappendMissing: false,\n\t\t\t\t\t\t\t});\n\t\t\t\t\t\t\tif (appended !== 0) {\n\t\t\t\t\t\t\t\tthrow new WorkerConversationOwnershipError(\n\t\t\t\t\t\t\t\t\t\"Worker callback transcript verification unexpectedly appended missing messages.\",\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tcommitted = true;\n\t\t\t\t\t\t\treturn evidenced.completion;\n\t\t\t\t\t\t} finally {\n\t\t\t\t\t\t\tsignal.removeEventListener(\"abort\", abortTranscriptCursor);\n\t\t\t\t\t\t\tproviderTurn.close();\n\t\t\t\t\t\t\tif (activeProviderTurn === providerTurn) activeProviderTurn = undefined;\n\t\t\t\t\t\t\tif (!committed) options.conversation.abortTranscriptCommit(transcriptCursor);\n\t\t\t\t\t\t}\n\t\t\t\t\t};\n\t\t\t\t\ttry {\n\t\t\t\t\t\tcompletion = await runProviderCompletionWithBackoff({\n\t\t\t\t\t\t\tattempt: attemptProviderCompletion,\n\t\t\t\t\t\t\tonAttemptFailure: closeActiveProviderTurn,\n\t\t\t\t\t\t\tprovider: options.model.provider,\n\t\t\t\t\t\t\tlaneId: options.laneId,\n\t\t\t\t\t\t\twarn: options.warn,\n\t\t\t\t\t\t\t...(signal ? { signal } : {}),\n\t\t\t\t\t\t});\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tcloseActiveProviderTurn();\n\t\t\t\t\t}\n\t\t\t\t\tconst cumulativeUsage = checkpointUsage(\n\t\t\t\t\t\t\"Verified the callback-persisted worker conversation terminal suffix.\",\n\t\t\t\t\t);\n\t\t\t\t\tterminalOutput = completion.text;\n\t\t\t\t\treturn {\n\t\t\t\t\t\ttext: completion.text,\n\t\t\t\t\t\tcostUsd: cumulativeUsage.costUsd,\n\t\t\t\t\t\tstopReason: String(completion.stopReason),\n\t\t\t\t\t\tchangedFiles: [...changedFiles],\n\t\t\t\t\t\tblockers: [...toolIssues],\n\t\t\t\t\t};\n\t\t\t\t},\n\t\t\t});\n\t\t\tconst usage = checkpointUsage(\"Persisted final cumulative worker usage before terminal result.\");\n\t\t\tconst outputArtifact = terminalOutput\n\t\t\t\t? captureWorkerTerminalOutputArtifact({\n\t\t\t\t\t\tagentDir: options.agentDir,\n\t\t\t\t\t\tparentSessionId: options.parentSessionId,\n\t\t\t\t\t\tattemptId: options.durableHandle.attemptId,\n\t\t\t\t\t\ttext: terminalOutput,\n\t\t\t\t\t\tcreatedAt: new Date().toISOString(),\n\t\t\t\t\t})\n\t\t\t\t: undefined;\n\t\t\treturn { rawOutcome, usage, changedFiles: [...changedFiles], ...(outputArtifact ? { outputArtifact } : {}) };\n\t\t},\n\t};\n}\n"]}
@@ -1,5 +1,6 @@
1
1
  import type { CapabilityEnvelope, GateOutcome, WorkerClaim, WorkerRequest } from "../autonomy/contracts.ts";
2
- export declare const MAX_WORKER_CLAIM_SUMMARY_CHARS = 8000;
2
+ export declare const MAX_WORKER_CLAIM_SUMMARY_CHARS: number;
3
+ export declare const MAX_WORKER_CLAIM_SUMMARY_BYTES: number;
3
4
  export declare const MAX_WORKER_CLAIM_BLOCKERS = 32;
4
5
  export declare const MAX_WORKER_CLAIM_BLOCKER_CHARS = 1000;
5
6
  export declare const MAX_WORKER_CLAIM_CHANGED_FILES = 128;
@@ -19,6 +20,8 @@ export interface BoundedWorkerClaimStrings {
19
20
  export declare function collectBoundedWorkerClaimBlockers(values: readonly string[]): BoundedWorkerClaimStrings;
20
21
  /** Changed paths preserve their exact spelling; trimming a real path could change its meaning. */
21
22
  export declare function collectBoundedWorkerClaimChangedFiles(values: readonly string[]): BoundedWorkerClaimStrings;
23
+ /** Bound a host-produced claim summary without splitting a UTF-8 code point. */
24
+ export declare function clipWorkerClaimSummary(value: string, suffix?: string): string;
22
25
  export declare function boundedWorkerClaimStrings(values: readonly string[], maximumCount: number, maximumChars: number): string[];
23
26
  export declare function boundedWorkerClaimBlockers(values: readonly string[]): string[];
24
27
  export declare function boundedWorkerClaimChangedFiles(values: readonly string[]): string[];
@@ -1 +1 @@
1
- {"version":3,"file":"worker-claim.d.ts","sourceRoot":"","sources":["../../../src/core/delegation/worker-claim.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAK5G,eAAO,MAAM,8BAA8B,OAAQ,CAAC;AACpD,eAAO,MAAM,yBAAyB,KAAK,CAAC;AAC5C,eAAO,MAAM,8BAA8B,OAAQ,CAAC;AACpD,eAAO,MAAM,8BAA8B,MAAM,CAAC;AAClD,eAAO,MAAM,mCAAmC,OAAQ,CAAC;AACzD,eAAO,MAAM,iCAAiC,MAAM,CAAC;AACrD,eAAO,MAAM,0CAA0C,MAAM,CAAC;AAC9D,eAAO,MAAM,sCAAsC,MAAM,CAAC;AAC1D,eAAO,MAAM,gCAAgC,MAAM,CAAC;AACpD,eAAO,MAAM,8CAA8C,MAAM,CAAC;AAClE,eAAO,MAAM,6BAA6B,KAAK,CAAC;AAChD,eAAO,MAAM,kCAAkC,MAAM,CAAC;AA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,CAAC,EAAE,MAAM,CAAC;CACb,GAAG,WAAW,CAwId;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE;IACnD,YAAY,EAAE,SAAS,MAAM,EAAE,CAAC;IAChC;+FAC2F;IAC3F,QAAQ,EAAE,IAAI,CAAC,kBAAkB,EAAE,cAAc,GAAG,aAAa,CAAC,CAAC;IACnE,GAAG,CAAC,EAAE,MAAM,CAAC;CACb,GAAG;IAAE,cAAc,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAwClD"}
@@ -1,8 +1,11 @@
1
1
  import path from "node:path";
2
+ import { DEFAULT_MAX_BYTES } from "@caupulican/pi-agent-core/truncate";
2
3
  import { checkPathScope } from "../autonomy/path-scope.js";
3
4
  import { normalizeEvidenceBundleForStorage } from "../research/evidence-bundle.js";
5
+ import { utf8PrefixByBytes } from "../util/bounded-value.js";
4
6
  import { isPlainRecord } from "../util/value-guards.js";
5
- export const MAX_WORKER_CLAIM_SUMMARY_CHARS = 8_000;
7
+ export const MAX_WORKER_CLAIM_SUMMARY_CHARS = DEFAULT_MAX_BYTES;
8
+ export const MAX_WORKER_CLAIM_SUMMARY_BYTES = DEFAULT_MAX_BYTES;
6
9
  export const MAX_WORKER_CLAIM_BLOCKERS = 32;
7
10
  export const MAX_WORKER_CLAIM_BLOCKER_CHARS = 1_000;
8
11
  export const MAX_WORKER_CLAIM_CHANGED_FILES = 128;
@@ -66,6 +69,21 @@ function requiredWorkerClaimString(value, label, maximumChars) {
66
69
  invalidWorkerClaim(`${label} exceeds ${maximumChars} characters.`);
67
70
  return value;
68
71
  }
72
+ function requiredWorkerClaimSummary(value) {
73
+ const summary = requiredWorkerClaimString(value, "claim.summary", MAX_WORKER_CLAIM_SUMMARY_CHARS);
74
+ if (Buffer.byteLength(summary, "utf8") > MAX_WORKER_CLAIM_SUMMARY_BYTES) {
75
+ invalidWorkerClaim(`claim.summary exceeds ${MAX_WORKER_CLAIM_SUMMARY_BYTES} bytes.`);
76
+ }
77
+ return summary;
78
+ }
79
+ /** Bound a host-produced claim summary without splitting a UTF-8 code point. */
80
+ export function clipWorkerClaimSummary(value, suffix = "") {
81
+ const suffixBytes = Buffer.byteLength(suffix, "utf8");
82
+ if (suffixBytes > MAX_WORKER_CLAIM_SUMMARY_BYTES) {
83
+ throw new TypeError("Worker claim summary suffix exceeds the inline output ceiling.");
84
+ }
85
+ return `${utf8PrefixByBytes(value, MAX_WORKER_CLAIM_SUMMARY_BYTES - suffixBytes)}${suffix}`;
86
+ }
69
87
  function optionalWorkerClaimString(value, label, maximumChars) {
70
88
  if (value === undefined)
71
89
  return undefined;
@@ -153,7 +171,7 @@ export function normalizeWorkerClaimForHost(value) {
153
171
  }
154
172
  : {}),
155
173
  status,
156
- summary: requiredWorkerClaimString(claim.summary, "claim.summary", MAX_WORKER_CLAIM_SUMMARY_CHARS),
174
+ summary: requiredWorkerClaimSummary(claim.summary),
157
175
  ...(claim.outputFormat !== undefined ? { outputFormat: claim.outputFormat } : {}),
158
176
  ...(claim.evidence !== undefined ? { evidence: normalizeEvidenceBundleForStorage(claim.evidence) } : {}),
159
177
  changedFiles: workerClaimStringArray(claim.changedFiles, "claim.changedFiles", MAX_WORKER_CLAIM_CHANGED_FILES, MAX_WORKER_CLAIM_CHANGED_FILE_CHARS),