@yielded/agent 0.1.0-beta.181 → 0.1.0-beta.182

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 (100) hide show
  1. package/dist/{Admin-NvXFPDIM.d.mts → Admin-C4mPa0M2.d.mts} +5 -5
  2. package/dist/{AgentRuntime-BAExRlgu.mjs → AgentRuntime-1OjlOCa9.mjs} +10 -6
  3. package/dist/AgentRuntime-1OjlOCa9.mjs.map +1 -0
  4. package/dist/{AgentRuntime-Dx5u_FJD.d.mts → AgentRuntime-CVsnQBPe.d.mts} +4 -4
  5. package/dist/{DurableAgentRuntime-HH2muFrT.mjs → DurableAgentRuntime-D2I_T2Yt.mjs} +12 -7
  6. package/dist/DurableAgentRuntime-D2I_T2Yt.mjs.map +1 -0
  7. package/dist/{EventSource-DNyaWmyQ.d.mts → EventSource-gc82d-f6.d.mts} +2 -2
  8. package/dist/InMemory.d.mts +1 -1
  9. package/dist/{MessageDelivery-CLzWJImC.d.mts → MessageDelivery-DrQKvh93.d.mts} +4 -4
  10. package/dist/{PreparedInputAdmission-BQ9UCLFS.d.mts → PreparedInputAdmission-CrqdFUd8.d.mts} +3 -3
  11. package/dist/{RunContinuation-CL0wBsQE.d.mts → RunContinuation-DMbA81sZ.d.mts} +4 -3
  12. package/dist/{RunContinuation-BF95Ncv2.mjs → RunContinuation-DWiO2K9D.mjs} +6 -1
  13. package/dist/{RunContinuation-BF95Ncv2.mjs.map → RunContinuation-DWiO2K9D.mjs.map} +1 -1
  14. package/dist/{RunEvent-C5jVQZ6K.d.mts → RunEvent-Bh1p4zAO.d.mts} +2 -2
  15. package/dist/{RunOptions-BANtohGk.d.mts → RunOptions-aBHR-Eqm.d.mts} +6 -3
  16. package/dist/{Subagent-D68fe7mr.mjs → Subagent-BRiDyUS4.mjs} +2 -2
  17. package/dist/{Subagent-D68fe7mr.mjs.map → Subagent-BRiDyUS4.mjs.map} +1 -1
  18. package/dist/{Subagent-5ulnV6An.d.mts → Subagent-FypBXZP1.d.mts} +4 -4
  19. package/dist/{Subscription-D2yn6Eo3.d.mts → Subscription-Bx0LiX3x.d.mts} +2 -2
  20. package/dist/{SubscriptionInput-Cog4x7Rd.d.mts → SubscriptionInput-CBFCfuOF.d.mts} +2 -2
  21. package/dist/{ThreadHistory-KPPBJLJb.d.mts → ThreadHistory-ajQhqZDY.d.mts} +2 -2
  22. package/dist/{ThreadImport-em89zmM-.d.mts → ThreadImport-DTV_ario.d.mts} +4 -4
  23. package/dist/{ThreadImport-BoTfjjrz.mjs → ThreadImport-DlCLjRHK.mjs} +2 -2
  24. package/dist/{ThreadImport-BoTfjjrz.mjs.map → ThreadImport-DlCLjRHK.mjs.map} +1 -1
  25. package/dist/{WorkerAdmission-DrxDrLII.mjs → WorkerAdmission-Cxg_REhE.mjs} +2 -2
  26. package/dist/{WorkerAdmission-DrxDrLII.mjs.map → WorkerAdmission-Cxg_REhE.mjs.map} +1 -1
  27. package/dist/{agent-registration-BovXT8jc.mjs → agent-registration-C6tkQz8r.mjs} +2 -2
  28. package/dist/{agent-registration-BovXT8jc.mjs.map → agent-registration-C6tkQz8r.mjs.map} +1 -1
  29. package/dist/capabilities/Commands.d.mts +1 -1
  30. package/dist/capabilities/Redaction.d.mts +1 -1
  31. package/dist/capabilities/RunHooks.d.mts +1 -1
  32. package/dist/capabilities/Subagent.d.mts +1 -1
  33. package/dist/capabilities/Subagent.mjs +1 -1
  34. package/dist/core/RunEvent.d.mts +1 -1
  35. package/dist/core/RunEvent.mjs +1 -1
  36. package/dist/core/RunEvent.mjs.map +1 -1
  37. package/dist/durable/Admin.d.mts +1 -1
  38. package/dist/durable/AgentRegistration.d.mts +1 -1
  39. package/dist/durable/AgentRegistration.mjs +1 -1
  40. package/dist/durable/Certification.d.mts +1 -1
  41. package/dist/durable/CommittedActivity.d.mts +1 -1
  42. package/dist/durable/DurableAgentRuntime.d.mts +1 -1
  43. package/dist/durable/DurableAgentRuntime.mjs +2 -2
  44. package/dist/durable/EventSource.d.mts +1 -1
  45. package/dist/durable/GitHubWorkflowSource.d.mts +3 -3
  46. package/dist/durable/LifecyclePublication.d.mts +1 -1
  47. package/dist/durable/MessageDelivery.d.mts +1 -1
  48. package/dist/durable/MessageDeliveryStoreConformance.d.mts +40 -40
  49. package/dist/durable/PersistentHistory.d.mts +2 -2
  50. package/dist/durable/PreparedInputAdmission.d.mts +1 -1
  51. package/dist/durable/Recovery.d.mts +1 -1
  52. package/dist/durable/RunContinuation.d.mts +2 -2
  53. package/dist/durable/RunContinuation.mjs +1 -1
  54. package/dist/durable/RunJournal.d.mts +1 -1
  55. package/dist/durable/RunStorage.d.mts +1 -1
  56. package/dist/durable/Scheduling.d.mts +1 -1
  57. package/dist/durable/SettlementPublisher.d.mts +1 -1
  58. package/dist/durable/SubmissionLedger.d.mts +1 -1
  59. package/dist/durable/SubmissionLedgerConformance.d.mts +1 -1
  60. package/dist/durable/SubmissionStatus.d.mts +1 -1
  61. package/dist/durable/Subscription.d.mts +1 -1
  62. package/dist/durable/SubscriptionInput.d.mts +1 -1
  63. package/dist/durable/SubscriptionInput.mjs +1 -1
  64. package/dist/durable/SubscriptionStoreConformance.d.mts +1 -1
  65. package/dist/durable/SubscriptionTools.d.mts +2 -2
  66. package/dist/durable/SubscriptionTransition.d.mts +1 -1
  67. package/dist/durable/Subscriptions.d.mts +5 -5
  68. package/dist/durable/ThreadArchiveRange.d.mts +1 -1
  69. package/dist/durable/ThreadContextHistory.d.mts +1 -1
  70. package/dist/durable/ThreadImport.d.mts +1 -1
  71. package/dist/durable/ThreadImport.mjs +1 -1
  72. package/dist/durable/ThreadInvariants.d.mts +3 -3
  73. package/dist/durable/ThreadInvariants.mjs +2 -2
  74. package/dist/durable/ThreadProjectionMaintenance.d.mts +1 -1
  75. package/dist/durable/ThreadReader.d.mts +1 -1
  76. package/dist/durable/ThreadStore.d.mts +1 -1
  77. package/dist/durable/ThreadStoreConformance.d.mts +1 -1
  78. package/dist/durable/ThreadStoreConformance.mjs +1 -1
  79. package/dist/durable/ThreadTransfer.d.mts +1 -1
  80. package/dist/durable/ThreadWork.d.mts +1 -1
  81. package/dist/durable/ThreadWork.mjs +1 -1
  82. package/dist/durable/WorkerAdmission.d.mts +1 -1
  83. package/dist/durable/WorkerAdmission.mjs +1 -1
  84. package/dist/durable/WorkerHost.d.mts +1 -1
  85. package/dist/engine/AgentRuntime.d.mts +1 -1
  86. package/dist/engine/AgentRuntime.mjs +1 -1
  87. package/dist/engine/RunOptions.d.mts +1 -1
  88. package/dist/engine/RunOptions.mjs.map +1 -1
  89. package/dist/engine/ThreadHistory.d.mts +1 -1
  90. package/dist/index.d.mts +13 -13
  91. package/dist/index.mjs +6 -6
  92. package/dist/{run-context-reader-kpO9xhP2.d.mts → run-context-reader-CIdG5tdJ.d.mts} +2 -2
  93. package/package.json +1 -1
  94. package/src/core/RunEvent.ts +1 -1
  95. package/src/durable/DurableAgentRuntime.ts +40 -4
  96. package/src/durable/RunContinuation.ts +10 -0
  97. package/src/engine/RunOptions.ts +4 -1
  98. package/src/engine/internal/agent-runtime.ts +43 -6
  99. package/dist/AgentRuntime-BAExRlgu.mjs.map +0 -1
  100. package/dist/DurableAgentRuntime-HH2muFrT.mjs.map +0 -1
@@ -1155,6 +1155,15 @@ const isCoordinatorHaltCause = (
1155
1155
  (reason) => reason._tag !== "Fail" || reason.error instanceof CoordinatorHalt,
1156
1156
  );
1157
1157
 
1158
+ const isPersistenceCapacityCause = (cause: Cause.Cause<unknown>): boolean =>
1159
+ cause.reasons.length > 0 &&
1160
+ cause.reasons.every(
1161
+ (reason) =>
1162
+ Cause.isFailReason(reason) &&
1163
+ reason.error instanceof ThreadStoreError &&
1164
+ reason.error.cause instanceof AgentPersistenceCapacityError,
1165
+ );
1166
+
1158
1167
  const PolicyFailure = Schema.TaggedStruct("AgentPolicyError", {
1159
1168
  limit: PolicyLimit,
1160
1169
  });
@@ -6150,6 +6159,26 @@ const make = Effect.fnUntraced(function* (bindings: ReadonlyArray<ResolvedBindin
6150
6159
  return "committed" as const;
6151
6160
  }
6152
6161
 
6162
+ if (
6163
+ commit._tag === "Response" &&
6164
+ commit.defer !== true &&
6165
+ response !== undefined &&
6166
+ progress !== undefined
6167
+ ) {
6168
+ // This read-only preflight proves that no append or Tool dispatch began.
6169
+ // Append failures and recovered declarations retain their existing uncertainty.
6170
+ const admissible = yield* progress.preflight(yield* turnResponseBatch(input)).pipe(
6171
+ Effect.provideService(CurrentRunWriter, ctx),
6172
+ Effect.as(true),
6173
+ Effect.catchCauseIf(
6174
+ (cause) => isPersistenceCapacityCause(cause),
6175
+ () => Effect.succeed(false),
6176
+ ),
6177
+ );
6178
+
6179
+ if (!admissible) return "capacity-refused" as const;
6180
+ }
6181
+
6153
6182
  if (commit._tag === "Response" && commit.defer === true) {
6154
6183
  if (
6155
6184
  toolOperations.length === 0 ||
@@ -6216,11 +6245,18 @@ const make = Effect.fnUntraced(function* (bindings: ReadonlyArray<ResolvedBindin
6216
6245
  message: "Dispatch has no scoped progress writer",
6217
6246
  });
6218
6247
 
6219
- const batch = yield* progress
6220
- .defer(candidate.batch)
6221
- .pipe(Effect.provideService(CurrentRunWriter, ctx));
6248
+ const batch = yield* progress.defer(candidate.batch).pipe(
6249
+ Effect.provideService(CurrentRunWriter, ctx),
6250
+ Effect.asSome,
6251
+ Effect.catchCauseIf(
6252
+ (cause) => isPersistenceCapacityCause(cause),
6253
+ () => Effect.succeedNone,
6254
+ ),
6255
+ );
6222
6256
 
6223
- deferredResponse = { ...candidate, batch };
6257
+ // Deferral does not append, and installs its reservation only after every check.
6258
+ if (Option.isNone(batch)) return "capacity-refused" as const;
6259
+ deferredResponse = { ...candidate, batch: batch.value };
6224
6260
 
6225
6261
  return "deferred" as const;
6226
6262
  }
@@ -1840,6 +1840,15 @@ export const makeProgressWriter = Effect.fnUntraced(function* (
1840
1840
  const publish = (batch: CanonicalBatch) =>
1841
1841
  captureFacts(batch).pipe(Effect.flatMap(publishCaptured));
1842
1842
 
1843
+ const preflight = (batch: CanonicalBatch) =>
1844
+ gate.withPermits(1)(
1845
+ Effect.gen(function* () {
1846
+ const owned = yield* captureFacts(batch);
1847
+
1848
+ yield* prepare(owned, yield* tail, "preflight");
1849
+ }),
1850
+ );
1851
+
1843
1852
  const reserve = (runId: RunId, probe: CanonicalBatch, bytes: number) =>
1844
1853
  gate.withPermits(1)(
1845
1854
  Effect.gen(function* () {
@@ -1952,6 +1961,7 @@ export const makeProgressWriter = Effect.fnUntraced(function* (
1952
1961
  return {
1953
1962
  commit,
1954
1963
  publish,
1964
+ preflight,
1955
1965
  reserve,
1956
1966
  defer,
1957
1967
  check,
@@ -688,10 +688,13 @@ export interface RunDurabilityHook<Error = never, Requirements = never> {
688
688
  * `committed` accepts the supplied facts canonically. `deferred` is valid only for a Response
689
689
  * with `defer: true`: validation and ownership succeeded, but no canonical acceptance occurred.
690
690
  * The interpreter retains its response and inputs until the Settled commit is accepted.
691
+ * `capacity-refused` is valid only for a fresh Response rejected before any storage append or
692
+ * Tool work. The interpreter settles every application call as not dispatched, atomically with
693
+ * that response. A failed append or an already accepted response must never return this value.
691
694
  */
692
695
  readonly commitTurn: (
693
696
  commit: RunTurnCommit,
694
- ) => Effect.Effect<"committed" | "deferred", Error, Requirements>;
697
+ ) => Effect.Effect<"committed" | "deferred" | "capacity-refused", Error, Requirements>;
695
698
  /** Check the writer fence after approval/authorization and before handler permits; no write. */
696
699
  readonly checkToolDispatch: Effect.Effect<void, Error, Requirements>;
697
700
  readonly step: RunStepHook<Error, Requirements>;
@@ -757,7 +757,7 @@ const acceptTurnCommit = <E, R>(
757
757
  trace: TurnTrace,
758
758
  durability: RunDurabilityHook<E, R> | undefined,
759
759
  commit: RunTurnCommit,
760
- ): Effect.Effect<void, E | ModelProtocolError | AgentPolicyError, R> =>
760
+ ): Effect.Effect<void | "capacity-refused", E | ModelProtocolError | AgentPolicyError, R> =>
761
761
  Effect.suspend(() => {
762
762
  if (trace.commitFailed) return Effect.void;
763
763
 
@@ -767,6 +767,15 @@ const acceptTurnCommit = <E, R>(
767
767
 
768
768
  return Effect.onExitPrimitive(
769
769
  Effect.flatMap(accepted, (receipt) => {
770
+ if (receipt === "capacity-refused")
771
+ return commit._tag === "Response" && trace.responseCommitted !== true
772
+ ? Effect.succeed(receipt)
773
+ : Effect.fail(
774
+ ModelProtocolError.make({
775
+ message: "Durability refused capacity after response acceptance",
776
+ }),
777
+ );
778
+
770
779
  if (receipt === "deferred")
771
780
  return commit._tag === "Response" && commit.defer === true
772
781
  ? Effect.void
@@ -837,7 +846,7 @@ const settleTurn = <E, R>(
837
846
  ...(response === undefined ? {} : { response }),
838
847
  results,
839
848
  ...(completion === undefined ? {} : { completion }),
840
- }),
849
+ }).pipe(Effect.asVoid),
841
850
  );
842
851
  });
843
852
 
@@ -1663,7 +1672,7 @@ const makeToolFailedEvent = Effect.fnUntraced(function* (
1663
1672
  /**
1664
1673
  * Settle a rejected Tool batch without starting any handler: every open
1665
1674
  * application call receives the encoded failure as its model-visible result.
1666
- * Only budget rejections (RUN-018) are exempt from repeated-failure folding;
1675
+ * Policy and persistence budget rejections are exempt from repeated-failure folding;
1667
1676
  * correctable model declarations count as ordinary failed calls. Emit one
1668
1677
  * `ToolCallFailed` per call with no `ToolCallStarted` (the
1669
1678
  * approval-denied precedent). The caller hands the trace to
@@ -1676,10 +1685,10 @@ const settleRejectedBatch = Effect.fnUntraced(function* (
1676
1685
  context: RunContext,
1677
1686
  turnId: TurnId,
1678
1687
  trace: TurnTrace,
1679
- error: AgentPolicyError | ModelProtocolError,
1688
+ error: AgentPolicyError | AgentPersistenceCapacityError | ModelProtocolError,
1680
1689
  alreadySettled?: ReadonlySet<string>,
1681
1690
  ): Effect.fn.Return<ReadonlyArray<RunEvent>, ModelProtocolError> {
1682
- const budgetRejected = error._tag === "AgentPolicyError" ? true : undefined;
1691
+ const budgetRejected = error._tag !== "ModelProtocolError" ? true : undefined;
1683
1692
 
1684
1693
  const encodedResult = {
1685
1694
  _tag: error._tag,
@@ -7349,9 +7358,10 @@ const makeTurn = <
7349
7358
  return yield* ModelProtocolError.make({
7350
7359
  message: "Tool dispatch has no validated response facts",
7351
7360
  });
7361
+
7352
7362
  // Idempotency only permits replay of the original operation. Re-asking the
7353
7363
  // model could choose different arguments or a new key, so it keeps the barrier.
7354
- yield* acceptTurnCommit(context, trace, options.durability, {
7364
+ const admission = yield* acceptTurnCommit(context, trace, options.durability, {
7355
7365
  _tag: "Response",
7356
7366
  turn,
7357
7367
  turnId,
@@ -7370,6 +7380,33 @@ const makeTurn = <
7370
7380
  ? { defer: true as const }
7371
7381
  : {}),
7372
7382
  });
7383
+
7384
+ if (admission === "capacity-refused") {
7385
+ const rejection = yield* settleRejectedBatch(
7386
+ context,
7387
+ turnId,
7388
+ trace,
7389
+ AgentPersistenceCapacityError.make({
7390
+ message:
7391
+ "This application tool batch was not dispatched because its durable results exceed available capacity. Retry the needed application tools in smaller batches. Earlier tool results remain valid.",
7392
+ }),
7393
+ );
7394
+
7395
+ return publishEvents(context, rejection).pipe(
7396
+ Effect.andThen(
7397
+ toolBatchContinuation(
7398
+ agent,
7399
+ context,
7400
+ trace,
7401
+ prompt,
7402
+ turn,
7403
+ turnId,
7404
+ toolCalls,
7405
+ options,
7406
+ ),
7407
+ ),
7408
+ );
7409
+ }
7373
7410
  }
7374
7411
 
7375
7412
  const toolResults = executeToolBatch(