effect-agent 0.1.0-beta.103 → 0.1.0-beta.106

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 (166) hide show
  1. package/dist/{Agent-CM6JubNX.d.mts → Agent-Bk-mLtov.d.mts} +2 -2
  2. package/dist/{AgentError-CggcAQ7V.d.mts → AgentError-Bn1ytXRD.d.mts} +20 -4
  3. package/dist/{AgentRuntime-B1SXMVN7.d.mts → AgentRuntime-BEXToYl1.d.mts} +8 -8
  4. package/dist/{AgentRuntime-BWOnNc0d.mjs → AgentRuntime-e2M5UoXn.mjs} +4 -3
  5. package/dist/AgentRuntime-e2M5UoXn.mjs.map +1 -0
  6. package/dist/{DurableAgentRuntime-C9eRZS9N.mjs → DurableAgentRuntime-wd1x0TcB.mjs} +67 -36
  7. package/dist/DurableAgentRuntime-wd1x0TcB.mjs.map +1 -0
  8. package/dist/{EventSource-K7XUzurY.d.mts → EventSource-pH-v0k42.d.mts} +3 -3
  9. package/dist/FailureDiagnostic-BElLOoED.mjs +274 -0
  10. package/dist/FailureDiagnostic-BElLOoED.mjs.map +1 -0
  11. package/dist/FailureDiagnostic-CaAkzGHL.d.mts +223 -0
  12. package/dist/{Messaging-QMYhp297.d.mts → Messaging-Bl4SBKpR.d.mts} +3 -3
  13. package/dist/{MessagingHost-gAxs5gme.d.mts → MessagingHost-nwBMdRoh.d.mts} +3 -3
  14. package/dist/{Output-CjocJzsl.d.mts → Output-B6RQ5jRU.d.mts} +2 -2
  15. package/dist/{PreparedInputAdmission-KLk5rGFI.d.mts → PreparedInputAdmission-D3-BgmA9.d.mts} +8 -4
  16. package/dist/{Records-Bidb7ByL.d.mts → Records-B4S02MX1.d.mts} +201 -14
  17. package/dist/{RunJournal-srpbEBEy.mjs → RunJournal-BdIlgAEj.mjs} +2 -2
  18. package/dist/{RunJournal-srpbEBEy.mjs.map → RunJournal-BdIlgAEj.mjs.map} +1 -1
  19. package/dist/{RunOptions-Bruk54SE.d.mts → RunOptions-qOcPv08p.d.mts} +10 -5
  20. package/dist/{Schedule-Cy9up8Uf.d.mts → Schedule-D2TVEu3W.d.mts} +7 -2
  21. package/dist/{Scheduling-CHCsSCGo.mjs → Scheduling-DPb2QyAK.mjs} +2 -2
  22. package/dist/{Scheduling-CHCsSCGo.mjs.map → Scheduling-DPb2QyAK.mjs.map} +1 -1
  23. package/dist/{Subagent-DP0CzO16.d.mts → Subagent-BxuDuCHt.d.mts} +172 -8
  24. package/dist/{Subagent-C2s8PFrd.mjs → Subagent-uXWHXiKb.mjs} +64 -29
  25. package/dist/Subagent-uXWHXiKb.mjs.map +1 -0
  26. package/dist/{SubagentHost-CYcxkpRc.d.mts → SubagentHost-DEPw4YME.d.mts} +6 -3
  27. package/dist/{Subscription-CHyoQelH.d.mts → Subscription-nX0rz4GQ.d.mts} +3 -3
  28. package/dist/{SubscriptionInput-DqrHW-Ja.d.mts → SubscriptionInput-CAG3_pyJ.d.mts} +3 -3
  29. package/dist/{Worker--j87JI__.d.mts → Worker-Bbj9uq5H.d.mts} +5 -2
  30. package/dist/{agent-registration-ByeHejH3.mjs → agent-registration-B5CI-Ygk.mjs} +7 -5
  31. package/dist/agent-registration-B5CI-Ygk.mjs.map +1 -0
  32. package/dist/capabilities/Commands.d.mts +1 -1
  33. package/dist/capabilities/Messaging.d.mts +2 -2
  34. package/dist/capabilities/RunHooks.d.mts +1 -1
  35. package/dist/capabilities/Subagent.d.mts +2 -2
  36. package/dist/capabilities/Subagent.mjs +1 -1
  37. package/dist/core/Agent.d.mts +1 -1
  38. package/dist/core/AgentError.d.mts +2 -2
  39. package/dist/core/AgentError.mjs +19 -2
  40. package/dist/core/AgentError.mjs.map +1 -1
  41. package/dist/core/FailureDiagnostic.d.mts +2 -0
  42. package/dist/core/FailureDiagnostic.mjs +2 -0
  43. package/dist/core/Worker.d.mts +1 -1
  44. package/dist/core/Worker.mjs +4 -1
  45. package/dist/core/Worker.mjs.map +1 -1
  46. package/dist/durable/ActivityStore.d.mts +1 -1
  47. package/dist/durable/ActivityStore.mjs +1 -1
  48. package/dist/durable/Admin.d.mts +1 -1
  49. package/dist/durable/Admin.mjs +1 -1
  50. package/dist/durable/AgentRegistration.d.mts +1 -1
  51. package/dist/durable/AgentRegistration.mjs +1 -1
  52. package/dist/durable/Certification.d.mts +1 -1
  53. package/dist/durable/CommittedActivity.d.mts +1 -1
  54. package/dist/durable/CommittedActivity.mjs +1 -1
  55. package/dist/durable/Digest.d.mts +1 -1
  56. package/dist/durable/Digest.mjs +7 -7
  57. package/dist/durable/Digest.mjs.map +1 -1
  58. package/dist/durable/DurableAgentRuntime.d.mts +1 -1
  59. package/dist/durable/DurableAgentRuntime.mjs +1 -1
  60. package/dist/durable/EventSource.d.mts +1 -1
  61. package/dist/durable/EventSource.mjs +1 -1
  62. package/dist/durable/GitHubWorkflowSource.d.mts +3 -3
  63. package/dist/durable/GitHubWorkflowSource.mjs +1 -1
  64. package/dist/durable/MessageDelivery.d.mts +15 -3
  65. package/dist/durable/MessageDelivery.mjs +44 -24
  66. package/dist/durable/MessageDelivery.mjs.map +1 -1
  67. package/dist/durable/MessageDeliveryStoreConformance.d.mts +4 -1
  68. package/dist/durable/MessageDeliveryStoreConformance.mjs +1 -1
  69. package/dist/durable/PersistentHistory.d.mts +1 -1
  70. package/dist/durable/PersistentHistory.mjs +2 -2
  71. package/dist/durable/PreparedInputAdmission.d.mts +1 -1
  72. package/dist/durable/PreparedInputAdmission.mjs +8 -4
  73. package/dist/durable/PreparedInputAdmission.mjs.map +1 -1
  74. package/dist/durable/Records.d.mts +1 -1
  75. package/dist/durable/Records.mjs +831 -2
  76. package/dist/durable/Records.mjs.map +1 -0
  77. package/dist/durable/Recovery.d.mts +1 -1
  78. package/dist/durable/Recovery.mjs +1 -1
  79. package/dist/durable/RunJournal.d.mts +1 -1
  80. package/dist/durable/RunJournal.mjs +1 -1
  81. package/dist/durable/Schedule.d.mts +1 -1
  82. package/dist/durable/Schedule.mjs +12 -3
  83. package/dist/durable/Schedule.mjs.map +1 -1
  84. package/dist/durable/ScheduleStoreConformance.d.mts +1 -1
  85. package/dist/durable/ScheduleStoreConformance.mjs +1 -1
  86. package/dist/durable/ScheduleTransition.d.mts +1 -1
  87. package/dist/durable/ScheduleTransition.mjs +1 -1
  88. package/dist/durable/Scheduling.d.mts +2 -2
  89. package/dist/durable/Scheduling.mjs +1 -1
  90. package/dist/durable/SqlMessageDeliveryStore.mjs +13 -11
  91. package/dist/durable/SqlMessageDeliveryStore.mjs.map +1 -1
  92. package/dist/durable/SqlStorageV2Upgrade.d.mts +2 -2
  93. package/dist/durable/SqlStorageV2Upgrade.mjs +1 -1
  94. package/dist/durable/SqlSubscriptionStore.d.mts +2 -2
  95. package/dist/durable/SqlSubscriptionStore.mjs +1 -1
  96. package/dist/durable/SqlThreadNativeReads.d.mts +1 -1
  97. package/dist/durable/SqlThreadNativeReads.mjs +2 -2
  98. package/dist/durable/SubmissionLedger.d.mts +1 -1
  99. package/dist/durable/SubmissionLedger.mjs +6 -3
  100. package/dist/durable/SubmissionLedger.mjs.map +1 -1
  101. package/dist/durable/SubmissionLedgerConformance.d.mts +1 -1
  102. package/dist/durable/SubmissionLedgerConformance.mjs +1 -1
  103. package/dist/durable/SubmissionStatus.d.mts +1 -1
  104. package/dist/durable/Subscription.d.mts +1 -1
  105. package/dist/durable/Subscription.mjs +1 -1
  106. package/dist/durable/SubscriptionInput.d.mts +1 -1
  107. package/dist/durable/SubscriptionInput.mjs +2 -2
  108. package/dist/durable/SubscriptionStoreConformance.d.mts +1 -1
  109. package/dist/durable/SubscriptionStoreConformance.mjs +1 -1
  110. package/dist/durable/SubscriptionTools.d.mts +3 -3
  111. package/dist/durable/SubscriptionTransition.d.mts +1 -1
  112. package/dist/durable/SubscriptionTransition.mjs +1 -1
  113. package/dist/durable/Subscriptions.d.mts +5 -5
  114. package/dist/durable/Subscriptions.mjs +1 -1
  115. package/dist/durable/ThreadContextHistory.d.mts +1 -1
  116. package/dist/durable/ThreadContextHistory.mjs +1 -1
  117. package/dist/durable/ThreadContextHistoryProjection.d.mts +1 -1
  118. package/dist/durable/ThreadContextHistoryProjection.mjs +1 -1
  119. package/dist/durable/ThreadInvariants.d.mts +1 -1
  120. package/dist/durable/ThreadInvariants.mjs +2 -2
  121. package/dist/durable/ThreadProjection.d.mts +1 -1
  122. package/dist/durable/ThreadProjection.mjs +1 -1
  123. package/dist/durable/ThreadProjectionMaintenance.d.mts +1 -1
  124. package/dist/durable/ThreadStore.d.mts +1 -1
  125. package/dist/durable/ThreadStore.mjs +2 -2
  126. package/dist/durable/ThreadStoreConformance.d.mts +1 -1
  127. package/dist/durable/ThreadStoreConformance.mjs +1 -1
  128. package/dist/durable/ToolReconciler.mjs +1 -1
  129. package/dist/durable/WorkerHost.d.mts +3 -3
  130. package/dist/engine/AgentRuntime.d.mts +1 -1
  131. package/dist/engine/AgentRuntime.mjs +1 -1
  132. package/dist/engine/MessagingHost.d.mts +1 -1
  133. package/dist/engine/Output.d.mts +1 -1
  134. package/dist/engine/RunOptions.d.mts +1 -1
  135. package/dist/engine/RunOptions.mjs +2 -0
  136. package/dist/engine/RunOptions.mjs.map +1 -1
  137. package/dist/engine/SubagentHost.d.mts +1 -1
  138. package/dist/engine/SubagentHost.mjs.map +1 -1
  139. package/dist/index.d.mts +18 -17
  140. package/dist/index.mjs +8 -7
  141. package/package.json +1 -1
  142. package/src/capabilities/internal/subagent-background.ts +66 -23
  143. package/src/capabilities/internal/subagent-contract.ts +4 -0
  144. package/src/core/AgentError.ts +20 -0
  145. package/src/core/FailureDiagnostic.ts +343 -0
  146. package/src/core/Worker.ts +4 -1
  147. package/src/durable/Digest.ts +22 -28
  148. package/src/durable/DurableAgentRuntime.ts +37 -13
  149. package/src/durable/MessageDelivery.ts +82 -24
  150. package/src/durable/PreparedInputAdmission.ts +17 -4
  151. package/src/durable/Records.ts +5 -15
  152. package/src/durable/Schedule.ts +11 -2
  153. package/src/durable/SqlMessageDeliveryStore.ts +21 -9
  154. package/src/durable/SubmissionLedger.ts +4 -1
  155. package/src/durable/internal/agent-registration.ts +46 -14
  156. package/src/durable/internal/worker-host.ts +32 -19
  157. package/src/engine/RunOptions.ts +11 -3
  158. package/src/engine/SubagentHost.ts +3 -0
  159. package/src/engine/internal/agent-runtime.ts +23 -16
  160. package/src/index.ts +1 -0
  161. package/dist/AgentRuntime-BWOnNc0d.mjs.map +0 -1
  162. package/dist/DurableAgentRuntime-C9eRZS9N.mjs.map +0 -1
  163. package/dist/Records-D8167fHn.mjs +0 -844
  164. package/dist/Records-D8167fHn.mjs.map +0 -1
  165. package/dist/Subagent-C2s8PFrd.mjs.map +0 -1
  166. package/dist/agent-registration-ByeHejH3.mjs.map +0 -1
@@ -4,6 +4,7 @@ import { n as utf8ByteLength } from "./utf8-DchGZRBd.mjs";
4
4
  import { AgentPolicy } from "./core/AgentPolicy.mjs";
5
5
  import { IdempotencyKey, Principal, Receipt } from "./core/Receipt.mjs";
6
6
  import { Update, UpdateError } from "./core/AgentUpdates.mjs";
7
+ import { c as captureContext, s as capture } from "./FailureDiagnostic-BElLOoED.mjs";
7
8
  import { AgentApprovalDenied, AgentApprovalPending, AgentInputError, AgentToolAuthorizationDenied, PolicyLimit } from "./core/AgentError.mjs";
8
9
  import { IdGenerator as IdGenerator$1 } from "./core/IdGenerator.mjs";
9
10
  import { DelegationDepth, SubagentBudgetReservation, SubagentDelegationCaps, SubagentGrant, SubagentParentLink, SubagentReservationAmounts, getToolExecutionKind } from "./core/SubagentContract.mjs";
@@ -14,19 +15,19 @@ import { a as PeerMessageCapacity, d as MessageAdmission, f as MessageRef, h as
14
15
  import { SubagentHost } from "./engine/SubagentHost.mjs";
15
16
  import { ThreadHistory } from "./engine/ThreadHistory.mjs";
16
17
  import { n as RunToolVisibility } from "./ToolExposure-9uF_Yo0T.mjs";
17
- import { f as renderInputPrompt, n as AgentChildPending, y as streamWithUsageAccountingUnknown } from "./AgentRuntime-BWOnNc0d.mjs";
18
+ import { f as renderInputPrompt, n as AgentChildPending, y as streamWithUsageAccountingUnknown } from "./AgentRuntime-e2M5UoXn.mjs";
18
19
  import { ContextRolloverTool } from "./engine/ContextWindow.mjs";
19
20
  import { getToolExecutionClass } from "./engine/DurableStep.mjs";
20
21
  import { CompactionError, ContextCompactor } from "./engine/ContextCompactor.mjs";
21
22
  import { RunPolicyUsage } from "./core/RunPolicyUsage.mjs";
22
23
  import { AgentUpdateAcceptance, CurrentToolFailureObserver, ModelUsageAccounting, RunContextPreparation, RunContextPreparationPassthrough, RunToolAuthorization, RunToolScheduling } from "./engine/RunOptions.mjs";
23
- import { $ as ToolCallSettled, B as SubagentJoined, E as ProducerEpoch, G as SubmissionSettledRecord, H as SubagentRequested, I as RunPolicyUsageReserved, J as ToolApprovalDecided, K as SubtreeBudgetReserved, L as RunStartedRecord, O as RecordEnvelope, P as RunDurationExhausted, Q as ToolCallResolved, R as SettlementFailureDiagnostic, T as PersistedJson, U as SubagentStarted, V as SubagentLineageRecorded, W as SubmissionSettled, X as ToolCallPrepared, Y as ToolApprovalRequested, at as WorkerAdmission, c as CanonicalRecordEnvelope, ct as WorkerOrigin, d as CompactionCreated, dt as WorkerReportRefused, et as ToolCallUnknown, ft as WorkerReportingIntent, h as Digest, i as BatchId, it as UserInputRecorded, j as RepairAnnotated, k as RecordId, lt as WorkerOriginRecorded, n as AgentUpdateEmitted, nt as ToolStepSettled, o as CanonicalBatch, ot as WorkerInputCompleted, p as DefinitionDigests, q as ThreadCreated, rt as ToolUnavailable, st as WorkerInputRequested, t as AbortRequested, tt as ToolOperation, u as CanonicalSequence, ut as WorkerReportPrepared, w as PeerMessagePrepared, x as ModelResponseInterrupted } from "./Records-D8167fHn.mjs";
24
+ import { AbortRequested, AgentUpdateEmitted, BatchId, CanonicalBatch, CanonicalRecordEnvelope, CanonicalSequence, CompactionCreated, DefinitionDigests, Digest, ModelResponseInterrupted, PeerMessagePrepared, PersistedJson, ProducerEpoch, RecordEnvelope, RecordId, RepairAnnotated, RunDurationExhausted, RunPolicyUsageReserved, RunStartedRecord, SettlementFailureDiagnostic, SubagentJoined, SubagentLineageRecorded, SubagentRequested, SubagentStarted, SubmissionSettled, SubmissionSettledRecord, SubtreeBudgetReserved, ThreadCreated, ToolApprovalDecided, ToolApprovalRequested, ToolCallPrepared, ToolCallResolved, ToolCallSettled, ToolCallUnknown, ToolOperation, ToolStepSettled, ToolUnavailable, UserInputRecorded, WorkerAdmission, WorkerInputCompleted, WorkerInputRequested, WorkerOrigin, WorkerOriginRecorded, WorkerReportPrepared, WorkerReportRefused, WorkerReportingIntent } from "./durable/Records.mjs";
24
25
  import { AbortCommand, AbortIntentRequest, AdmissionPolicyError, AdmissionRequest, ApprovalDecisionCommand, ApprovalPendingSuspension, AttachChildToReservationRequest, BeginChildBudgetReleaseRequest, ChildBudgetReservationRequest, ChildReservationId, ChildSettledNotification, ClaimJoiningRequest, ClaimRequest, LedgerError, MarkInputAppliedRequest, MarkJoinedRequest, MarkReadyRequest, MarkUnknownRequest, OwnershipToken, ParentLinkage, RecoverySnapshotRequest, ReleaseChildBudgetRequest, ReleaseOwnershipRequest, RenewOwnershipRequest, RevertJoiningRequest, Settlement, SettlementFinalization, SettlementReservation, SubmissionLedger, SubmissionLookupById, SubmissionLookupByKey, SuspendRequest, UnknownResolutionCommand, WaitingChild, WaitingForChildSuspension, submissionAbortBatchId, submissionAbortRecordId, submissionInputBatchId, submissionInputRecordId, submissionSettlementBatchId, submissionSettlementId, submissionSettlementRecordId } from "./durable/SubmissionLedger.mjs";
25
26
  import { DeclaredPendingBatchEvidence, OpenDelegationCallEvidence, OpenToolCallEvidence, PendingApprovalEvidence, RecoveryDecision, RecoveryEvidence, classifyRecovery } from "./durable/Recovery.mjs";
26
27
  import { ExplainedEvidence, ExplainedSubmission, ExplainedUnknownCall, IntegrityCheck, IntegrityReport, ObligationEntry, ObligationReport, RecoveryExplanation, RetryRefused, obligationSeverityOf, predictRecoveryDisposition, recoveryDecisionMeaning } from "./durable/Admin.mjs";
27
28
  import { digestJson } from "./durable/Digest.mjs";
28
- import { a as definitionDigestsEqual, c as resolveWorkerBinding, i as compileRegistrations, l as toolReplayContracts, o as makeLegacyWorkerBinding, s as resolveDefinitionBinding, t as BindingUnavailable } from "./agent-registration-ByeHejH3.mjs";
29
- import { $ as workerOriginRecordId, A as subagentRequestedRecordId, B as toolCallUnknownRecordId, C as runStartedBatchId, D as subagentLineageBatchId, E as subagentJoinedRecordId, F as toolCallPreparedRecordId, G as turnCanonicalBatch, H as toolStepSettledRecordId, I as toolCallResolutionBatchId, J as turnResponseBatch, K as turnIdForRun, L as toolCallResolvedRecordId, M as subagentStartedRecordId, N as toolApprovalDecisionRecordId, O as subagentLineageRecordId, P as toolApprovalRequestRecordId, Q as workerInputRecordId, R as toolCallResultBatchId, S as runIdForSubmission, T as subagentJoinBatchId, U as turnApprovalsBatchId, V as toolStepSettledBatchId, X as turnResultsBatch, a as childIdempotencyKeyFor, b as runDurationBatchId, c as compactionRecordId, d as modelResponseInterruptedBatchId, et as workerReportRecordId, f as modelResponseInterruptedRecordId, g as projectRunJournalStream, i as approvalDecisionBatchId, j as subagentStartedBatchId, k as subagentRequestedBatchId, l as firstWorkerInputRecordId, m as peerMessageRecordId, o as childThreadIdFor, p as modelResponseRecordId, q as turnPreparedBatchId, r as agentUpdateRecordId, s as compactionBatchId, t as RunJournalError, tt as makeJournalMetadata, u as markUnknownBatchId, v as runCompletedRecordId, w as runStartedRecordId, x as runDurationRecordId, y as runCompletionDigest, z as toolCallSettledRecordId } from "./RunJournal-srpbEBEy.mjs";
29
+ import { a as definitionDigestsEqual, c as resolveWorkerBinding, i as compileRegistrations, l as toolReplayContracts, o as makeLegacyWorkerBinding, s as resolveDefinitionBinding, t as BindingUnavailable } from "./agent-registration-B5CI-Ygk.mjs";
30
+ import { $ as workerOriginRecordId, A as subagentRequestedRecordId, B as toolCallUnknownRecordId, C as runStartedBatchId, D as subagentLineageBatchId, E as subagentJoinedRecordId, F as toolCallPreparedRecordId, G as turnCanonicalBatch, H as toolStepSettledRecordId, I as toolCallResolutionBatchId, J as turnResponseBatch, K as turnIdForRun, L as toolCallResolvedRecordId, M as subagentStartedRecordId, N as toolApprovalDecisionRecordId, O as subagentLineageRecordId, P as toolApprovalRequestRecordId, Q as workerInputRecordId, R as toolCallResultBatchId, S as runIdForSubmission, T as subagentJoinBatchId, U as turnApprovalsBatchId, V as toolStepSettledBatchId, X as turnResultsBatch, a as childIdempotencyKeyFor, b as runDurationBatchId, c as compactionRecordId, d as modelResponseInterruptedBatchId, et as workerReportRecordId, f as modelResponseInterruptedRecordId, g as projectRunJournalStream, i as approvalDecisionBatchId, j as subagentStartedBatchId, k as subagentRequestedBatchId, l as firstWorkerInputRecordId, m as peerMessageRecordId, o as childThreadIdFor, p as modelResponseRecordId, q as turnPreparedBatchId, r as agentUpdateRecordId, s as compactionBatchId, t as RunJournalError, tt as makeJournalMetadata, u as markUnknownBatchId, v as runCompletedRecordId, w as runStartedRecordId, x as runDurationRecordId, y as runCompletionDigest, z as toolCallSettledRecordId } from "./RunJournal-BdIlgAEj.mjs";
30
31
  import { FencedAppendRequest, LoadCheckpointRequest, MAX_THREAD_EXPORT_RECORDS, SaveRecoveryCheckpointRequest, ThreadCheckpoint, ThreadExportRequest, ThreadMaterialization, ThreadObservation, ThreadRead, ThreadStore, ThreadStoreError, ThreadTailRequest, getRecord, readWorkerState } from "./durable/ThreadStore.mjs";
31
32
  import { DurableRuntimeFailpoint } from "./durable/DurableFailpoint.mjs";
32
33
  import { ScheduledInputRefused, ScheduledInputRetryable } from "./durable/Schedule.mjs";
@@ -579,12 +580,13 @@ const makeMessagingRuntime = Effect.fn("MessagingHost.make")(function* (options)
579
580
  });
580
581
  //#endregion
581
582
  //#region src/durable/internal/worker-host.ts
582
- const failure = (operation, reason) => WorkerError.make({
583
+ const failure = (operation, reason, cause) => WorkerError.make({
583
584
  operation,
584
- reason
585
+ reason,
586
+ ...cause === void 0 ? {} : { cause }
585
587
  });
586
- const storageFailure = (operation) => () => failure(operation, "storage");
587
- const decode = (schema, value, operation) => Schema.decodeUnknownEffect(Schema.toType(schema))(value).pipe(Effect.mapError(() => failure(operation, "corrupt")));
588
+ const storageFailure = (operation) => (cause) => failure(operation, "storage", cause);
589
+ const decode = (schema, value, operation) => Schema.decodeUnknownEffect(Schema.toType(schema))(value).pipe(Effect.mapError((cause) => failure(operation, "corrupt", cause)));
588
590
  const sameOrigin = Schema.toEquivalence(WorkerOrigin);
589
591
  const sameAdmission = Schema.toEquivalence(WorkerAdmission);
590
592
  const sameReporting = Schema.toEquivalence(Schema.UndefinedOr(WorkerReportingIntent));
@@ -880,7 +882,7 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
880
882
  const sourceBinding = source.binding;
881
883
  const targetBinding = currentBinding(origin.worker.targetAgentId);
882
884
  if (sourceBinding === void 0 || targetBinding === void 0) return yield* failure("start", "declaration-unavailable");
883
- if (!retainedFrameworkInput) yield* Schema.decodeEffect(Schema.toEncoded(targetBinding.definition.input))(input).pipe(Effect.mapError(() => failure("start", "corrupt")));
885
+ if (!retainedFrameworkInput) yield* Schema.decodeEffect(Schema.toEncoded(targetBinding.definition.input))(input).pipe(Effect.mapError((cause) => failure("start", "corrupt", cause)));
884
886
  const targetRequest = {
885
887
  definition: targetBinding.definition,
886
888
  definitions: targetBinding.digests,
@@ -1059,7 +1061,8 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
1059
1061
  };
1060
1062
  }, Effect.mapError((error) => error.reason === "storage" || error.reason === "corrupt" ? LedgerError.make({
1061
1063
  operation: "worker-update",
1062
- message: error.reason
1064
+ message: error.reason,
1065
+ cause: error
1063
1066
  }) : UpdateError.make({ reason: error.reason === "denied" ? "denied" : "unavailable" })));
1064
1067
  const reportRun = Effect.fn("WorkerHost.reportRun")(function* (submission, history) {
1065
1068
  const admission = submission.workerAdmission;
@@ -1127,6 +1130,7 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
1127
1130
  outcome: host.outcome,
1128
1131
  encodedParameters: hostAdmission.parameters,
1129
1132
  encodedResult: host.result ?? null,
1133
+ ...host.outcome === "failed" ? { diagnostic: host.result } : {},
1130
1134
  budgetExhausted: host.finishReason === "budget-exhausted"
1131
1135
  }
1132
1136
  };
@@ -1217,7 +1221,7 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
1217
1221
  }
1218
1222
  if (decision?._tag !== "WorkerReportPrepared") return;
1219
1223
  if (Option.isNone(deps.deliveries)) return yield* failure("inspect", "unavailable");
1220
- const envelope = yield* Schema.decodeUnknownEffect(PreparedInput)(decision.envelope).pipe(Effect.mapError(() => failure("inspect", "corrupt")));
1224
+ const envelope = yield* Schema.decodeUnknownEffect(PreparedInput)(decision.envelope).pipe(Effect.mapError((cause) => failure("inspect", "corrupt", cause)));
1221
1225
  const prepared = yield* withCrypto(prepareMessageDelivery({
1222
1226
  key: {
1223
1227
  ownerThreadId: submission.threadId,
@@ -1279,10 +1283,10 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
1279
1283
  access,
1280
1284
  ...worker === void 0 ? {} : { worker }
1281
1285
  });
1282
- const binding = (target, operation) => resolveDefinitionBinding(deps.bindings, target).pipe(Effect.mapError(() => failure(operation, "declaration-unavailable")));
1286
+ const binding = (target, operation) => resolveDefinitionBinding(deps.bindings, target).pipe(Effect.mapError((cause) => failure(operation, "declaration-unavailable", cause)));
1283
1287
  const preparedTarget = Effect.fn("WorkerHost.preparedTarget")(function* (target, encodedInput) {
1284
1288
  const resolved = yield* binding(target, "start");
1285
- yield* Schema.decodeUnknownEffect(Schema.toEncoded(target.input))(encodedInput).pipe(Effect.mapError(() => failure("start", "corrupt")));
1289
+ yield* Schema.decodeUnknownEffect(Schema.toEncoded(target.input))(encodedInput).pipe(Effect.mapError((cause) => failure("start", "corrupt", cause)));
1286
1290
  const input = yield* decode(PersistedJson, encodedInput, "start");
1287
1291
  const inputDigest = yield* withCrypto(digestJson(input)).pipe(Effect.mapError(storageFailure("start")));
1288
1292
  const source = yield* sourceAuthority(context.source.threadId, sourceSubmissionId);
@@ -1337,6 +1341,7 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
1337
1341
  outcome: settlement.outcome,
1338
1342
  encodedParameters: admission.parameters,
1339
1343
  encodedResult: result.result ?? null,
1344
+ ...result.outcome === "failed" ? { diagnostic: result.result } : {},
1340
1345
  budgetExhausted: result.finishReason === "budget-exhausted"
1341
1346
  };
1342
1347
  });
@@ -1386,21 +1391,33 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
1386
1391
  createdAtMillis: now,
1387
1392
  deadlineAtMillis: origin.expiresAtMillis
1388
1393
  })).pipe(Effect.mapError(storageFailure(operation)));
1389
- yield* deliveries.insert(prepared).pipe(Effect.mapError((error) => failure(operation, error._tag === "MessageDeliveryError" && error.reason === "capacity" ? "capacity" : "storage")));
1394
+ yield* deliveries.insert(prepared).pipe(Effect.mapError((error) => failure(operation, error._tag === "MessageDeliveryError" && error.reason === "capacity" ? "capacity" : "storage", error)));
1390
1395
  }
1391
1396
  const processed = yield* MessageDeliveryDriver.pipe(Effect.flatMap((driver) => driver.process(key)), Effect.provide(MessageDeliveryDriver.layer({
1392
1397
  batchSize: 1,
1393
1398
  concurrency: 1
1394
1399
  })), Effect.provideService(MessageDeliveryStore, deliveries), Effect.provideService(PreparedInputAdmission, {
1395
- submit: (prepared) => deps.submit(prepared).pipe(Effect.mapError((error) => error._tag === "AdmissionConflict" || error._tag === "AgentInputError" ? ScheduledInputRefused.make({ code: error._tag }) : error._tag === "AdmissionPolicyError" && error.reason === "refused" ? ScheduledInputRefused.make({ code: error.code }) : ScheduledInputRetryable.make({ reason: "storage" }))),
1396
- submissionStatus: (receipt) => deps.status(receipt).pipe(Effect.mapError(() => ScheduledInputRetryable.make({ reason: "storage" })))
1400
+ submit: (prepared) => deps.submit(prepared).pipe(Effect.mapError((error) => error._tag === "AdmissionConflict" || error._tag === "AgentInputError" ? ScheduledInputRefused.make({
1401
+ code: error._tag,
1402
+ cause: error
1403
+ }) : error._tag === "AdmissionPolicyError" && error.reason === "refused" ? ScheduledInputRefused.make({
1404
+ code: error.code,
1405
+ cause: error
1406
+ }) : ScheduledInputRetryable.make({
1407
+ reason: "storage",
1408
+ cause: error
1409
+ }))),
1410
+ submissionStatus: (receipt) => deps.status(receipt).pipe(Effect.mapError((error) => ScheduledInputRetryable.make({
1411
+ reason: "storage",
1412
+ cause: error
1413
+ })))
1397
1414
  }), Effect.provideService(Crypto.Crypto, deps.crypto), Effect.mapError(storageFailure(operation)));
1398
1415
  if (processed.receipt !== null) return processed.receipt;
1399
1416
  if (processed.status === "refused") {
1400
1417
  const reason = Schema.decodeUnknownOption(WorkerError.fields.reason)(processed.refusal?.startsWith("worker-") ? processed.refusal.slice(7) : processed.refusal === "AdmissionConflict" ? "idempotency-conflict" : processed.refusal === "AgentInputError" ? "corrupt" : void 0);
1401
- return yield* failure(operation, Option.getOrElse(reason, () => "denied"));
1418
+ return yield* failure(operation, Option.getOrElse(reason, () => "denied"), processed.lastFailureDiagnostic);
1402
1419
  }
1403
- return yield* failure(operation, processed.status === "pending" && processed.retry.lastFailure === null ? "delivery-pending" : "storage");
1420
+ return yield* failure(operation, processed.status === "pending" && processed.retry.lastFailure === null ? "delivery-pending" : "storage", processed.lastFailureDiagnostic);
1404
1421
  });
1405
1422
  const messageIdFor = (parts) => withCrypto(digestJson(parts)).pipe(Effect.map((digest) => Schema.decodeSync(IdempotencyKey)(`worker:${digest}`)), Effect.mapError(storageFailure("start")));
1406
1423
  const summarize = Effect.fn("WorkerHost.summarize")(function* (origin, all, operation) {
@@ -1458,7 +1475,7 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
1458
1475
  const prepared = yield* preparedTarget(request.target, request.encodedInput);
1459
1476
  const resolved = prepared.resolved;
1460
1477
  const sourcePolicy = Option.getOrElse(prepared.source.policyOverride, () => context.policy);
1461
- const grant = yield* Schema.decodeUnknownEffect(SubagentGrant)(request.encodedGrant).pipe(Effect.mapError(() => failure("start", "corrupt")));
1478
+ const grant = yield* Schema.decodeUnknownEffect(SubagentGrant)(request.encodedGrant).pipe(Effect.mapError((cause) => failure("start", "corrupt", cause)));
1462
1479
  const messageId = yield* messageIdFor([
1463
1480
  context.source.threadId,
1464
1481
  request.delegationId,
@@ -1514,7 +1531,7 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
1514
1531
  source: origin.source,
1515
1532
  origin
1516
1533
  });
1517
- yield* Schema.decodeUnknownEffect(Schema.toEncoded(request.target.input))(request.encodedInput).pipe(Effect.mapError(() => failure("followUp", "corrupt")));
1534
+ yield* Schema.decodeUnknownEffect(Schema.toEncoded(request.target.input))(request.encodedInput).pipe(Effect.mapError((cause) => failure("followUp", "corrupt", cause)));
1518
1535
  const messageId = yield* messageIdFor([
1519
1536
  context.source.threadId,
1520
1537
  request.worker.threadId,
@@ -1557,7 +1574,7 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
1557
1574
  sequence: entry.sequence,
1558
1575
  recordId: entry.record.recordId,
1559
1576
  record
1560
- })), Effect.mapError(() => failure("observe", "corrupt"))));
1577
+ })), Effect.mapError((cause) => failure("observe", "corrupt", cause))));
1561
1578
  const next = cursor + page.length;
1562
1579
  return [entries, next >= tail.tailSequence ? Option.none() : Option.some(next)];
1563
1580
  }));
@@ -1591,18 +1608,18 @@ const makeWorkerRuntime = Effect.fn("WorkerHost.make")(function* (options) {
1591
1608
  submissionId: request.receipt.submissionId,
1592
1609
  author: principal,
1593
1610
  reason: "Worker owner requested cancellation of this Receipt"
1594
- })).pipe(Effect.mapError((error) => error._tag === "JoinedToHost" ? error : failure("cancel", "storage")));
1611
+ })).pipe(Effect.mapError((error) => error._tag === "JoinedToHost" ? error : failure("cancel", "storage", error)));
1595
1612
  })
1596
1613
  };
1597
1614
  };
1598
1615
  const validateCompletion = Effect.fn("WorkerHost.validateCompletion")(function* (unvalidated, options, agentId, inputDigest) {
1599
- const message = yield* Schema.decodeEffect(FrameworkMessage)(unvalidated).pipe(Effect.mapError(() => failure("followUp", "corrupt")));
1616
+ const message = yield* Schema.decodeEffect(FrameworkMessage)(unvalidated).pipe(Effect.mapError((cause) => failure("followUp", "corrupt", cause)));
1600
1617
  const childThreadId = message._tag === "WorkerCompletion" ? message.report.worker.threadId : message.worker.threadId;
1601
1618
  const proofId = message._tag === "WorkerCompletion" ? workerReportRecordId(options.idempotencyKey) : yield* withCrypto(agentUpdateRecordId(message.update.threadId, message.update.runId, message.update.updateId)).pipe(Effect.mapError(storageFailure("followUp")));
1602
1619
  const proof = Option.getOrUndefined(yield* exactRecord(childThreadId, proofId, "followUp"))?.record.payload;
1603
1620
  const frozen = message._tag === "WorkerCompletion" ? proof?._tag === "WorkerReportPrepared" && proof.runId === message.report.runId && proof.messageId === options.idempotencyKey ? proof.envelope : void 0 : proof?._tag === "AgentUpdateEmitted" && Schema.toEquivalence(Update)(proof.update, message.update) ? proof.delivery?.envelope : void 0;
1604
1621
  if (frozen === void 0) return yield* failure("followUp", "denied");
1605
- const envelope = yield* Schema.decodeUnknownEffect(PreparedInput)(frozen).pipe(Effect.mapError(() => failure("followUp", "corrupt")));
1622
+ const envelope = yield* Schema.decodeUnknownEffect(PreparedInput)(frozen).pipe(Effect.mapError((cause) => failure("followUp", "corrupt", cause)));
1606
1623
  if (!Schema.is(FrameworkMessage)(envelope.messageAdmission) || !Schema.toEquivalence(FrameworkMessage)(envelope.messageAdmission, message) || envelope.threadId !== options.threadId || envelope.agentId !== agentId || envelope.inputDigest !== inputDigest || envelope.deliveryPrincipal !== options.principal || envelope.admissionKey !== options.idempotencyKey || !definitionDigestsEqual(envelope.definitions, options.definitions) || !Schema.toEquivalence(Schema.UndefinedOr(WorkerAdmission))(envelope.workerAdmission, options.workerAdmission)) return yield* failure("followUp", "denied");
1607
1624
  const recorded = Option.getOrUndefined(yield* exactRecord(childThreadId, workerOriginRecordId(childThreadId), "followUp"))?.record.payload;
1608
1625
  if (recorded?._tag !== "WorkerOriginRecorded" || recorded.origin.worker.threadId !== childThreadId || recorded.origin.reporting?.mode !== "standard") return yield* failure("followUp", "denied");
@@ -2931,7 +2948,8 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (bindings) {
2931
2948
  })));
2932
2949
  yield* workerRuntime.completeInput(submission).pipe(Effect.mapError((cause) => LedgerError.make({
2933
2950
  operation: "worker-completion",
2934
- message: cause.reason
2951
+ message: cause.reason,
2952
+ cause
2935
2953
  })));
2936
2954
  const linkage = submission.parentLinkage;
2937
2955
  if (linkage === void 0) return;
@@ -3640,9 +3658,11 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (bindings) {
3640
3658
  if (suspension === "suspended") return "waiting";
3641
3659
  }
3642
3660
  });
3643
- const failureOutcome = (error) => Schema.decodeEffect(SettlementFailureDiagnostic)({
3661
+ const failureOutcome = (error, cause, context) => Schema.decodeEffect(SettlementFailureDiagnostic)({
3644
3662
  errorTag: errorTagOf(error).slice(0, 256) || "UnknownError",
3645
- message: errorMessageOf(error).slice(0, MAX_FAILURE_MESSAGE_LENGTH)
3663
+ message: errorMessageOf(error).slice(0, MAX_FAILURE_MESSAGE_LENGTH),
3664
+ diagnostic: capture(cause),
3665
+ context: captureContext(context)
3646
3666
  }).pipe(Effect.orDie, Effect.map((result) => ({
3647
3667
  _tag: "failed",
3648
3668
  result,
@@ -5086,7 +5106,7 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (bindings) {
5086
5106
  yield* Ref.set(tokenRef, renewal.ownershipToken);
5087
5107
  }).pipe(Effect.uninterruptible), { schedule: Schedule.spaced(config.leaseRenewalInterval) }).pipe(Effect.andThen(Effect.never)));
5088
5108
  const execution = Effect.raceFirst(consume, Effect.raceFirst(abortWatcher, renewal));
5089
- const result = yield* (yieldAfter === void 0 ? execution : Effect.raceFirst(execution, Deferred.await(yieldSignal).pipe(Effect.as({ _tag: "yielded" })))).pipe(Effect.provideService(IdGenerator$1, idGenerator)).pipe(Effect.catch((error) => {
5109
+ const result = yield* (yieldAfter === void 0 ? execution : Effect.raceFirst(execution, Deferred.await(yieldSignal).pipe(Effect.as({ _tag: "yielded" })))).pipe(Effect.provideService(IdGenerator$1, idGenerator)).pipe(Effect.catchCauseFilter(Cause.findError, (error, cause) => {
5090
5110
  if (error instanceof CoordinatorHalt) return Effect.fail(error.failure);
5091
5111
  const approvalPending = agentApprovalPendingOption(error);
5092
5112
  if (Option.isSome(approvalPending)) return decodeToolCallIdUnknown(approvalPending.value.toolCallId).pipe(Effect.orDie, Effect.map((toolCallId) => ({
@@ -5108,7 +5128,7 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (bindings) {
5108
5128
  return { _tag: "aborted" };
5109
5129
  }
5110
5130
  }
5111
- if (!(error instanceof AgentApprovalDenied) && !(error instanceof AgentToolAuthorizationDenied)) yield* Effect.logError("Agent run failed", Cause.fail(error)).pipe(Effect.annotateLogs({
5131
+ if (cause.reasons.some((reason) => reason._tag === "Die" || reason._tag === "Fail" && !(reason.error instanceof AgentApprovalDenied) && !(reason.error instanceof AgentToolAuthorizationDenied))) yield* Effect.logError("Agent run failed", cause).pipe(Effect.annotateLogs({
5112
5132
  agentId: agent.definition.id,
5113
5133
  runId,
5114
5134
  threadId: ctx.threadId,
@@ -5117,7 +5137,13 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (bindings) {
5117
5137
  }));
5118
5138
  return {
5119
5139
  _tag: "failedRun",
5120
- outcome: yield* failureOutcome(error)
5140
+ outcome: yield* failureOutcome(error, cause, {
5141
+ agentId: agent.definition.id,
5142
+ runId,
5143
+ threadId: ctx.threadId,
5144
+ submissionId,
5145
+ attemptId: lineage.attemptId
5146
+ })
5121
5147
  };
5122
5148
  });
5123
5149
  }));
@@ -5168,7 +5194,8 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (bindings) {
5168
5194
  if (submission.workerAdmission?.origin.reporting?.mode === "standard") yield* updateRuntime.repair(threadId);
5169
5195
  if (submission.workerAdmission !== void 0) yield* workerRuntime.ensureOrigin(submission.workerAdmission.origin).pipe(Effect.mapError((cause) => LedgerError.make({
5170
5196
  operation: "worker-origin",
5171
- message: cause.reason
5197
+ message: cause.reason,
5198
+ cause
5172
5199
  })));
5173
5200
  if (submission.state === "admitted") yield* ledger.markReady(MarkReadyRequest.make({ submissionId }));
5174
5201
  const ctx = yield* attemptContextFor(threadId, claim.producerEpoch);
@@ -5787,7 +5814,8 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (bindings) {
5787
5814
  yield* ensureThreadCreated(submission.threadId, submission.agentId, submission.agentDigests);
5788
5815
  if (submission.workerAdmission !== void 0) yield* workerRuntime.ensureOrigin(submission.workerAdmission.origin).pipe(Effect.mapError((cause) => LedgerError.make({
5789
5816
  operation: "worker-origin",
5790
- message: cause.reason
5817
+ message: cause.reason,
5818
+ cause
5791
5819
  })));
5792
5820
  yield* ledger.markReady(MarkReadyRequest.make({ submissionId: submission.submissionId }));
5793
5821
  return "repaired";
@@ -6045,12 +6073,14 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (bindings) {
6045
6073
  const inputDigest = yield* withCrypto(digestJson(inputPayload));
6046
6074
  const workerAdmission = options.workerAdmission === void 0 ? void 0 : yield* workerRuntime.validateAdmission(options.workerAdmission, options, agent.definition.id, inputDigest, inputPayload).pipe(Effect.mapError((cause) => AdmissionPolicyError.make({
6047
6075
  reason: cause.reason === "storage" || cause.reason === "unavailable" ? "unavailable" : cause.reason === "capacity" && cause.retryable === true && Schema.is(FrameworkMessage)(options.messageAdmission) ? "occupied" : "refused",
6048
- code: `worker-${cause.reason}`
6076
+ code: `worker-${cause.reason}`,
6077
+ cause
6049
6078
  })));
6050
6079
  const pendingMessage = options.messageAdmission;
6051
6080
  const messageAdmission = pendingMessage === void 0 ? void 0 : yield* Effect.suspend(() => Schema.is(MessageAdmission)(pendingMessage) ? messagingRuntime.validateAdmission(pendingMessage, options, agent.definition.id, inputDigest) : workerRuntime.validateCompletion(pendingMessage, options, agent.definition.id, inputDigest)).pipe(Effect.mapError((cause) => AdmissionPolicyError.make({
6052
6081
  reason: cause.reason === "storage" || cause.reason === "unavailable" ? "unavailable" : "refused",
6053
- code: `message-${cause.reason}`
6082
+ code: `message-${cause.reason}`,
6083
+ cause
6054
6084
  })));
6055
6085
  if (options.definitions.replay !== void 0 && workerAdmission === void 0 && messageAdmission === void 0 && !registeredBindings.some((binding) => binding.agentId === agent.definition.id && definitionDigestsEqual(binding.digests, options.definitions))) {
6056
6086
  const retained = yield* ledger.lookup(SubmissionLookupByKey.make({
@@ -6095,7 +6125,8 @@ const make = Effect.fn("DurableAgentRuntime.make")(function* (bindings) {
6095
6125
  yield* ensureThreadCreated(options.threadId, agent.definition.id, options.definitions);
6096
6126
  if (workerAdmission !== void 0) yield* workerRuntime.ensureOrigin(workerAdmission.origin).pipe(Effect.mapError((cause) => LedgerError.make({
6097
6127
  operation: "worker-origin",
6098
- message: cause.reason
6128
+ message: cause.reason,
6129
+ cause
6099
6130
  })));
6100
6131
  yield* hit("submit:after-materialize");
6101
6132
  yield* ledger.markReady(MarkReadyRequest.make({ submissionId: admitted.submissionId }));
@@ -6676,4 +6707,4 @@ var DurableAgentRuntime = class DurableAgentRuntime extends Context.Service()("@
6676
6707
  //#endregion
6677
6708
  export { RecoveryReport as a, recoveryRepairRecordId as c, DurableRuntimeConfig as i, threadCreatedBatchId as l, DurableAgentRuntime_exports as n, childReservationIdFor as o, DurableApprovalResolver as r, recoveryRepairBatchId as s, DurableAgentRuntime as t, threadCreatedRecordId as u };
6678
6709
 
6679
- //# sourceMappingURL=DurableAgentRuntime-C9eRZS9N.mjs.map
6710
+ //# sourceMappingURL=DurableAgentRuntime-wd1x0TcB.mjs.map