effect-agent 0.1.0-beta.97 → 0.1.0-beta.99

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 (143) hide show
  1. package/dist/{AgentRuntime-B64362Id.d.mts → AgentRuntime-BMzrJos6.d.mts} +2 -2
  2. package/dist/{AgentRuntime-Cdvqw7l_.mjs → AgentRuntime-BWOnNc0d.mjs} +78 -42
  3. package/dist/AgentRuntime-BWOnNc0d.mjs.map +1 -0
  4. package/dist/{DurableAgentRuntime-DbUvZHDZ.mjs → DurableAgentRuntime-BE_OjQjz.mjs} +471 -252
  5. package/dist/DurableAgentRuntime-BE_OjQjz.mjs.map +1 -0
  6. package/dist/{DurableFailpoint-DQJet828.d.mts → DurableFailpoint-mx3-nsxU.d.mts} +3 -3
  7. package/dist/{EventSource-D6PAAEyK.d.mts → EventSource-BZ73J0s5.d.mts} +3 -3
  8. package/dist/{PreparedInputAdmission-omMbwd--.d.mts → PreparedInputAdmission-BkeI-Xvr.d.mts} +4 -4
  9. package/dist/{Records-CV49DgQK.d.mts → Records-BIiRLqlz.d.mts} +92 -128
  10. package/dist/{Records-BAutSSnJ.mjs → Records-DR1xtbXY.mjs} +35 -8
  11. package/dist/Records-DR1xtbXY.mjs.map +1 -0
  12. package/dist/{RunJournal-DRRRZmG7.mjs → RunJournal-DNs3PM4K.mjs} +80 -23
  13. package/dist/RunJournal-DNs3PM4K.mjs.map +1 -0
  14. package/dist/{RunOptions-Clj8cLsp.d.mts → RunOptions-Bruk54SE.d.mts} +13 -4
  15. package/dist/{Schedule-DePbGfgd.d.mts → Schedule-BNFlluAl.d.mts} +2 -2
  16. package/dist/{Scheduling-C3QpYn0W.mjs → Scheduling-HFH0pST1.mjs} +2 -2
  17. package/dist/{Scheduling-C3QpYn0W.mjs.map → Scheduling-HFH0pST1.mjs.map} +1 -1
  18. package/dist/{Subagent-Cbfzylz1.mjs → Subagent-C2s8PFrd.mjs} +2 -2
  19. package/dist/{Subagent-Cbfzylz1.mjs.map → Subagent-C2s8PFrd.mjs.map} +1 -1
  20. package/dist/{Subagent-Bm1dRecN.d.mts → Subagent-m7ywTCe4.d.mts} +3 -3
  21. package/dist/{Subscription-BR_8Cxh3.d.mts → Subscription-BCQ3L9Zp.d.mts} +3 -3
  22. package/dist/{SubscriptionInput-B95sQbuk.d.mts → SubscriptionInput-Cqu4_RW3.d.mts} +3 -3
  23. package/dist/{ToolReconciler-DQVaJfpE.d.mts → ToolReconciler-BmVRAHKs.d.mts} +8 -4
  24. package/dist/agent-registration-cXpB8cBU.mjs +199 -0
  25. package/dist/agent-registration-cXpB8cBU.mjs.map +1 -0
  26. package/dist/capabilities/Commands.d.mts +1 -1
  27. package/dist/capabilities/RunHooks.d.mts +1 -1
  28. package/dist/capabilities/Subagent.d.mts +1 -1
  29. package/dist/capabilities/Subagent.mjs +1 -1
  30. package/dist/durable/ActivityStore.d.mts +1 -1
  31. package/dist/durable/ActivityStore.mjs +1 -1
  32. package/dist/durable/Admin.d.mts +1 -1
  33. package/dist/durable/Admin.mjs +12 -10
  34. package/dist/durable/Admin.mjs.map +1 -1
  35. package/dist/durable/AgentRegistration.d.mts +2 -2
  36. package/dist/durable/AgentRegistration.mjs +4 -8
  37. package/dist/durable/AgentRegistration.mjs.map +1 -1
  38. package/dist/durable/Certification.d.mts +2 -2
  39. package/dist/durable/CommittedActivity.d.mts +1 -1
  40. package/dist/durable/CommittedActivity.mjs +1 -1
  41. package/dist/durable/Digest.d.mts +1 -1
  42. package/dist/durable/Digest.mjs +1 -1
  43. package/dist/durable/DurableAgentRuntime.d.mts +1 -1
  44. package/dist/durable/DurableAgentRuntime.mjs +1 -1
  45. package/dist/durable/DurableFailpoint.d.mts +1 -1
  46. package/dist/durable/DurableFailpoint.mjs +2 -0
  47. package/dist/durable/DurableFailpoint.mjs.map +1 -1
  48. package/dist/durable/DurableFailpointTestControl.d.mts +1 -1
  49. package/dist/durable/EventSource.d.mts +1 -1
  50. package/dist/durable/EventSource.mjs +1 -1
  51. package/dist/durable/GitHubWorkflowSource.d.mts +3 -3
  52. package/dist/durable/GitHubWorkflowSource.mjs +1 -1
  53. package/dist/durable/MessageDelivery.d.mts +3 -3
  54. package/dist/durable/MessageDelivery.mjs +1 -1
  55. package/dist/durable/MessageDeliveryStoreConformance.d.mts +39 -39
  56. package/dist/durable/MessageDeliveryStoreConformance.mjs +1 -1
  57. package/dist/durable/PersistentHistory.d.mts +1 -1
  58. package/dist/durable/PersistentHistory.mjs +2 -2
  59. package/dist/durable/PreparedInputAdmission.d.mts +1 -1
  60. package/dist/durable/Records.d.mts +2 -2
  61. package/dist/durable/Records.mjs +2 -2
  62. package/dist/durable/Recovery.d.mts +1 -1
  63. package/dist/durable/Recovery.mjs +9 -9
  64. package/dist/durable/Recovery.mjs.map +1 -1
  65. package/dist/durable/RunJournal.d.mts +2 -2
  66. package/dist/durable/RunJournal.mjs +2 -2
  67. package/dist/durable/Schedule.d.mts +1 -1
  68. package/dist/durable/Schedule.mjs +1 -1
  69. package/dist/durable/ScheduleStoreConformance.d.mts +1 -1
  70. package/dist/durable/ScheduleStoreConformance.mjs +1 -1
  71. package/dist/durable/ScheduleTransition.d.mts +1 -1
  72. package/dist/durable/ScheduleTransition.mjs +1 -1
  73. package/dist/durable/Scheduling.d.mts +2 -2
  74. package/dist/durable/Scheduling.mjs +1 -1
  75. package/dist/durable/SqlStorageV2Upgrade.d.mts +2 -2
  76. package/dist/durable/SqlStorageV2Upgrade.mjs +1 -1
  77. package/dist/durable/SqlSubscriptionStore.d.mts +2 -2
  78. package/dist/durable/SqlSubscriptionStore.mjs +1 -1
  79. package/dist/durable/SubmissionLedger.d.mts +1 -1
  80. package/dist/durable/SubmissionLedger.mjs +14 -13
  81. package/dist/durable/SubmissionLedger.mjs.map +1 -1
  82. package/dist/durable/SubmissionLedgerConformance.d.mts +1 -1
  83. package/dist/durable/SubmissionLedgerConformance.mjs +9 -2
  84. package/dist/durable/SubmissionLedgerConformance.mjs.map +1 -1
  85. package/dist/durable/SubmissionStatus.d.mts +1 -1
  86. package/dist/durable/Subscription.d.mts +1 -1
  87. package/dist/durable/Subscription.mjs +1 -1
  88. package/dist/durable/SubscriptionInput.d.mts +1 -1
  89. package/dist/durable/SubscriptionInput.mjs +2 -2
  90. package/dist/durable/SubscriptionStoreConformance.d.mts +1 -1
  91. package/dist/durable/SubscriptionStoreConformance.mjs +1 -1
  92. package/dist/durable/SubscriptionTools.d.mts +3 -3
  93. package/dist/durable/SubscriptionTransition.d.mts +1 -1
  94. package/dist/durable/SubscriptionTransition.mjs +1 -1
  95. package/dist/durable/Subscriptions.d.mts +5 -5
  96. package/dist/durable/Subscriptions.mjs +1 -1
  97. package/dist/durable/ThreadContextHistory.d.mts +1 -1
  98. package/dist/durable/ThreadContextHistory.mjs +1 -1
  99. package/dist/durable/ThreadContextHistoryProjection.d.mts +1 -1
  100. package/dist/durable/ThreadContextHistoryProjection.mjs +1 -1
  101. package/dist/durable/ThreadInvariants.d.mts +4 -2
  102. package/dist/durable/ThreadInvariants.mjs +49 -3
  103. package/dist/durable/ThreadInvariants.mjs.map +1 -1
  104. package/dist/durable/ThreadProjection.d.mts +1 -1
  105. package/dist/durable/ThreadProjection.mjs +1 -1
  106. package/dist/durable/ThreadProjectionMaintenance.d.mts +1 -1
  107. package/dist/durable/ThreadStore.d.mts +1 -1
  108. package/dist/durable/ThreadStore.mjs +1 -1
  109. package/dist/durable/ThreadStoreConformance.d.mts +1 -1
  110. package/dist/durable/ThreadStoreConformance.mjs +1 -1
  111. package/dist/durable/ToolReconciler.d.mts +1 -1
  112. package/dist/durable/ToolReconciler.mjs +9 -5
  113. package/dist/durable/ToolReconciler.mjs.map +1 -1
  114. package/dist/durable/WorkerHost.d.mts +1 -1
  115. package/dist/engine/AgentRuntime.d.mts +1 -1
  116. package/dist/engine/AgentRuntime.mjs +1 -1
  117. package/dist/engine/RunOptions.d.mts +1 -1
  118. package/dist/engine/RunOptions.mjs.map +1 -1
  119. package/dist/index.d.mts +11 -11
  120. package/dist/index.mjs +6 -6
  121. package/package.json +1 -1
  122. package/src/durable/Admin.ts +20 -11
  123. package/src/durable/AgentRegistration.ts +1 -5
  124. package/src/durable/DurableAgentRuntime.ts +947 -464
  125. package/src/durable/DurableFailpoint.ts +2 -0
  126. package/src/durable/Records.ts +30 -5
  127. package/src/durable/Recovery.ts +8 -8
  128. package/src/durable/RunJournal.ts +128 -51
  129. package/src/durable/SubmissionLedger.ts +13 -12
  130. package/src/durable/SubmissionLedgerConformance.ts +13 -2
  131. package/src/durable/ThreadInvariants.ts +70 -5
  132. package/src/durable/ToolReconciler.ts +7 -3
  133. package/src/durable/internal/agent-registration.ts +65 -414
  134. package/src/durable/internal/messaging-host.ts +0 -2
  135. package/src/durable/internal/worker-host.ts +34 -96
  136. package/src/engine/RunOptions.ts +13 -3
  137. package/src/engine/internal/agent-runtime.ts +160 -106
  138. package/dist/AgentRuntime-Cdvqw7l_.mjs.map +0 -1
  139. package/dist/DurableAgentRuntime-DbUvZHDZ.mjs.map +0 -1
  140. package/dist/Records-BAutSSnJ.mjs.map +0 -1
  141. package/dist/RunJournal-DRRRZmG7.mjs.map +0 -1
  142. package/dist/agent-registration-CXGDwvJH.mjs +0 -379
  143. package/dist/agent-registration-CXGDwvJH.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"Scheduling-C3QpYn0W.mjs","names":["ScheduleTimingRequestSchema","ScheduleDestinationSchema"],"sources":["../src/durable/internal/schedule-time.ts","../src/durable/Scheduling.ts"],"sourcesContent":["import { Cron, DateTime, Option, Result, Schema } from \"effect\";\n\nimport {\n ScheduleValidationError,\n ScheduleInstant,\n type ScheduleSkippedRange,\n type ScheduleTiming,\n type ScheduleTimingRequest,\n} from \"../Schedule.ts\";\n\nconst invalid = (message: string) => Result.fail(ScheduleValidationError.make({ message }));\n\nconst checkedInstant = (millis: number, label: string) =>\n Schema.decodeResult(ScheduleInstant)(millis).pipe(\n Result.mapError(() =>\n ScheduleValidationError.make({\n message: `${label} is outside the supported ScheduleInstant range`,\n }),\n ),\n );\n\nconst values = (set: ReadonlySet<number>, size: number): ReadonlyArray<number> =>\n set.size === 0 ? Array.from({ length: size }, (_, index) => index) : [...set];\n\n/**\n * Cron frequency proof without calendar enumeration. It checks the minimum circular spacing of\n * the allowed hour/minute pairs. Day restrictions may make a rule sparser, so this deliberately\n * rejects some safe rules when a configured minimum exceeds one minute.\n */\nconst validateCronFrequency = (\n cron: Cron.Cron,\n minimumMillis: number,\n): Result.Result<void, ScheduleValidationError> => {\n if (cron.seconds.size !== 1) {\n return invalid(\"Cron must select exactly one seconds value\");\n }\n if (minimumMillis <= 60_000) return Result.succeed(undefined);\n if (\n Option.isSome(cron.tz) &&\n DateTime.isTimeZoneNamed(cron.tz.value) &&\n cron.tz.value.id !== \"UTC\"\n ) {\n return invalid(\"Cron minimums above one minute require UTC or a fixed-offset time zone\");\n }\n\n const minuteOfDay = values(cron.hours, 24).flatMap((hour) =>\n values(cron.minutes, 60).map((minute) => hour * 60 + minute),\n );\n\n minuteOfDay.sort((left, right) => left - right);\n let minimumGap = 24 * 60;\n\n for (let index = 0; index < minuteOfDay.length; index += 1) {\n const current = minuteOfDay[index];\n const next = minuteOfDay[(index + 1) % minuteOfDay.length];\n\n if (current === undefined || next === undefined) continue;\n const gap = next > current ? next - current : 24 * 60 - current + next;\n\n minimumGap = Math.min(minimumGap, gap);\n }\n\n return minimumGap * 60_000 >= minimumMillis\n ? Result.succeed(undefined)\n : invalid(`Cron may fire more often than the configured ${minimumMillis}ms minimum`);\n};\n\nexport const parseScheduleCron = (\n expression: string,\n timeZone: string,\n minimumMillis: number,\n): Result.Result<Cron.Cron, ScheduleValidationError> => {\n const parsed = Cron.parse(expression, timeZone);\n\n if (Result.isFailure(parsed)) return invalid(parsed.failure.message);\n const frequency = validateCronFrequency(parsed.success, minimumMillis);\n\n return Result.isFailure(frequency)\n ? Result.fail(frequency.failure)\n : Result.succeed(parsed.success);\n};\n\nexport const normalizeScheduleTiming = (\n request: ScheduleTimingRequest,\n nowMillis: number,\n minimumMillis: number,\n): Result.Result<ScheduleTiming, ScheduleValidationError> => {\n switch (request._tag) {\n case \"At\":\n return Result.succeed(request);\n case \"After\": {\n const at = checkedInstant(nowMillis + request.delayMillis, \"Relative deadline\");\n\n return Result.map(at, (atMillis) => ({ _tag: \"At\" as const, atMillis }));\n }\n case \"Interval\": {\n if (request.everyMillis < minimumMillis) {\n return invalid(`Interval must be at least ${minimumMillis}ms`);\n }\n\n const anchor = checkedInstant(\n request.anchorMillis ?? nowMillis + request.everyMillis,\n \"Interval anchor\",\n );\n\n return Result.map(anchor, (anchorMillis) => ({\n _tag: \"Interval\" as const,\n everyMillis: request.everyMillis,\n anchorMillis,\n }));\n }\n case \"Cron\": {\n const timeZone = request.timeZone ?? \"UTC\";\n const cron = parseScheduleCron(request.expression, timeZone, minimumMillis);\n\n if (Result.isFailure(cron)) return Result.fail(cron.failure);\n\n return Result.succeed({ _tag: \"Cron\", expression: request.expression, timeZone });\n }\n }\n};\n\nconst parsedStoredCron = (timing: Extract<ScheduleTiming, { _tag: \"Cron\" }>) => {\n const parsed = Cron.parse(timing.expression, timing.timeZone);\n\n return Result.isFailure(parsed)\n ? invalid(`Stored cron is invalid: ${parsed.failure.message}`)\n : Result.succeed(parsed.success);\n};\n\n/** Strictly selects the first occurrence after an instant. */\nexport const scheduleNextAfter = (\n timing: ScheduleTiming,\n afterMillis: number,\n): Result.Result<number | null, ScheduleValidationError> => {\n switch (timing._tag) {\n case \"At\":\n return Result.succeed(timing.atMillis > afterMillis ? timing.atMillis : null);\n case \"Interval\": {\n if (afterMillis < timing.anchorMillis) return Result.succeed(timing.anchorMillis);\n const steps = Math.floor((afterMillis - timing.anchorMillis) / timing.everyMillis) + 1;\n const next = timing.anchorMillis + steps * timing.everyMillis;\n\n return checkedInstant(next, \"Next interval occurrence\");\n }\n case \"Cron\": {\n const cron = parsedStoredCron(timing);\n\n if (Result.isFailure(cron)) return Result.fail(cron.failure);\n\n return Result.try({\n try: () => {\n let next = Cron.next(cron.success, afterMillis).getTime();\n\n // Inside a fall fold Effect may select the first, already elapsed local instant.\n while (next <= afterMillis) {\n const following = Cron.next(cron.success, next).getTime();\n\n if (following <= next) throw new Error(\"Cron did not advance\");\n next = following;\n }\n\n return next;\n },\n catch: () => ScheduleValidationError.make({ message: \"Cron has no supported next firing\" }),\n }).pipe(Result.flatMap((next) => checkedInstant(next, \"Next cron occurrence\")));\n }\n }\n};\n\n/** Initial cursor. Past one-shots remain due; recurring rules start strictly after registration. */\nexport const scheduleInitialCursor = (\n timing: ScheduleTiming,\n nowMillis: number,\n): Result.Result<number | null, ScheduleValidationError> =>\n timing._tag === \"At\" ? Result.succeed(timing.atMillis) : scheduleNextAfter(timing, nowMillis);\n\nexport interface DueScheduleOccurrence {\n readonly intendedAtMillis: number;\n readonly nextAtMillis: number | null;\n readonly skippedRange: ScheduleSkippedRange | null;\n}\n\n/** Coalesces recurring occurrences using the same forward sequence as registration. */\nexport const scheduleDueOccurrence = (\n timing: ScheduleTiming,\n cursorMillis: number,\n nowMillis: number,\n): Result.Result<DueScheduleOccurrence | null, ScheduleValidationError> => {\n if (cursorMillis > nowMillis) return Result.succeed(null);\n if (timing._tag === \"At\") {\n return Result.succeed({\n intendedAtMillis: cursorMillis,\n nextAtMillis: null,\n skippedRange: null,\n });\n }\n\n let intendedAtMillis: number;\n\n if (timing._tag === \"Interval\") {\n const steps = Math.floor((nowMillis - timing.anchorMillis) / timing.everyMillis);\n\n intendedAtMillis = Math.max(cursorMillis, timing.anchorMillis + steps * timing.everyMillis);\n } else {\n const cron = parsedStoredCron(timing);\n\n if (Result.isFailure(cron)) return Result.fail(cron.failure);\n\n const due = Result.try({\n try: () => {\n let intended = cursorMillis;\n // Reverse traversal is safe only without offset transitions. Named-zone reverse\n // traversal has different gap/fold semantics from the forward occurrence sequence.\n const zone = Option.getOrUndefined(cron.success.tz);\n\n if (zone !== undefined && (DateTime.isTimeZoneOffset(zone) || zone.id === \"UTC\")) {\n intended = Math.max(cursorMillis, Cron.prev(cron.success, nowMillis + 1_000).getTime());\n } else {\n // Seek by calendar date in UTC, where reverse traversal has no DST ambiguity.\n // Include two prior civil days to cover even IANA date-line shifts. There are no\n // matching dates between this seed day and that boundary, so forward traversal\n // visits only the seed day and the recent days, regardless of downtime length.\n const calendar = Cron.make({\n ...cron.success,\n seconds: [0],\n minutes: [0],\n hours: [0],\n tz: DateTime.zoneMakeNamedUnsafe(\"UTC\"),\n });\n\n const localDay = DateTime.makeUnsafe(\n DateTime.toDate(DateTime.makeZonedUnsafe(nowMillis, { timeZone: zone })),\n ).pipe(DateTime.startOf(\"day\"), DateTime.subtract({ days: 2 }));\n\n const seedDay = Cron.prev(calendar, DateTime.toEpochMillis(localDay) + 1_000);\n\n const seed =\n DateTime.makeZonedUnsafe(seedDay, {\n timeZone: zone,\n adjustForTimeZone: true,\n }).pipe(DateTime.toEpochMillis) - 1_000;\n\n if (seed > cursorMillis) {\n const first = Cron.next(cron.success, seed).getTime();\n\n if (first <= nowMillis) intended = Math.max(intended, first);\n }\n }\n let next = Cron.next(cron.success, intended).getTime();\n\n while (next <= nowMillis) {\n if (next <= intended) throw new Error(\"Cron did not advance\");\n intended = next;\n next = Cron.next(cron.success, intended).getTime();\n }\n\n return { intended, next };\n },\n catch: () => ScheduleValidationError.make({ message: \"Cron has no supported due firing\" }),\n });\n\n if (Result.isFailure(due)) return Result.fail(due.failure);\n const next = checkedInstant(due.success.next, \"Next cron occurrence\");\n\n if (Result.isFailure(next)) return Result.fail(next.failure);\n\n return Result.succeed({\n intendedAtMillis: due.success.intended,\n nextAtMillis: next.success,\n skippedRange:\n due.success.intended === cursorMillis\n ? null\n : {\n fromMillis: cursorMillis,\n toMillis: due.success.intended,\n },\n });\n }\n\n const next = scheduleNextAfter(timing, nowMillis);\n\n if (Result.isFailure(next)) return Result.fail(next.failure);\n\n return Result.succeed({\n intendedAtMillis,\n nextAtMillis: next.success,\n skippedRange:\n intendedAtMillis === cursorMillis\n ? null\n : { fromMillis: cursorMillis, toMillis: intendedAtMillis },\n });\n};\n\nexport const scheduleResumeCursor = (\n timing: ScheduleTiming,\n existingCursor: number | null,\n nowMillis: number,\n): Result.Result<number | null, ScheduleValidationError> => {\n if (timing._tag === \"At\") return Result.succeed(existingCursor);\n\n return scheduleNextAfter(timing, nowMillis);\n};\n","import {\n Cause,\n Context,\n Crypto,\n DateTime,\n Effect,\n Layer,\n Option,\n Result,\n Schema,\n Semaphore,\n} from \"effect\";\n\nimport { type AgentId, ThreadId } from \"../core/Identifiers.ts\";\nimport { utf8ByteLength } from \"../core/internal/utf8.ts\";\nimport { digestJson } from \"./Digest.ts\";\nimport type { DurableSubmitAgent } from \"./DurableAgentRuntime.ts\";\nimport {\n normalizeScheduleTiming,\n scheduleDueOccurrence,\n scheduleInitialCursor,\n scheduleNextAfter,\n scheduleResumeCursor,\n} from \"./internal/schedule-time.ts\";\nimport { admitPreparedInput } from \"./PreparedInputAdmission.ts\";\nimport { DefinitionDigests, type Digest, PersistedJson } from \"./Records.ts\";\nimport {\n defaultSchedulingLimits,\n type ScheduleAuthorizationError,\n ScheduleAuthorizer,\n ScheduleConflict,\n type ScheduleConfiguration,\n ScheduleDestination as ScheduleDestinationSchema,\n type ScheduleDestination,\n ScheduleFailpoint,\n type ScheduleId,\n type ScheduleDueCursor,\n ScheduleInstant,\n type ScheduleKey,\n SchedulingLimits,\n ScheduleNotFound,\n type ScheduleOwner,\n type ScheduleRecord,\n type ScheduleRefusal,\n type ScheduleRetryReason,\n type ScheduleScope,\n type ScheduleSnapshot,\n type ScheduleSnapshotPage,\n ScheduleStorageError,\n ScheduleStore,\n type ScheduleStoreFailure,\n ScheduleTimingRequest as ScheduleTimingRequestSchema,\n type ScheduleTimingRequest,\n ScheduleValidationError,\n ScheduledInputAdmission,\n ScheduleWake,\n} from \"./Schedule.ts\";\nimport { type AdmissionFence, IdempotencyKey, type Principal } from \"./SubmissionLedger.ts\";\n\nexport interface ScheduleCreateOptions {\n readonly scope: ScheduleScope;\n readonly scheduleId: ScheduleId;\n readonly timing: ScheduleTimingRequest;\n readonly destination: ScheduleDestination;\n readonly deliveryPrincipal: Principal;\n readonly admissionGroup?: string;\n readonly admissionFence?: AdmissionFence;\n readonly definitions: DefinitionDigests;\n}\n\nexport interface ScheduleUpdateOptions extends ScheduleCreateOptions {\n readonly expectedRevision: number;\n}\n\nexport interface ScheduleListOptions {\n readonly after?: ScheduleId | undefined;\n readonly limit?: number | undefined;\n}\n\nexport type ScheduleManagementFailure =\n | ScheduleValidationError\n | ScheduleAuthorizationError\n | ScheduleStoreFailure;\n\nexport type ScheduleProcessFailure =\n | ScheduleValidationError\n | ScheduleStoreFailure\n | ScheduleStorageError;\n\nconst equivalentDefinitions = Schema.toEquivalence(DefinitionDigests);\nconst equivalentInput = Schema.toEquivalence(PersistedJson);\n\nconst keyOf = (scope: ScheduleScope, scheduleId: ScheduleId): ScheduleKey => ({\n owner: scope.owner,\n scheduleId,\n});\n\nconst notFound = (key: ScheduleKey) => ScheduleNotFound.make({ key });\n\nconst asSnapshot = (record: ScheduleRecord, observedAtMillis: number): ScheduleSnapshot => {\n const intendedAtMillis = record.pending?.envelope.intendedAtMillis ?? record.nextAtMillis;\n\n return {\n owner: record.owner,\n scheduleId: record.scheduleId,\n createdAtMillis: record.createdAtMillis,\n updatedAtMillis: record.updatedAtMillis,\n configurationRevision: record.configurationRevision,\n configuration: {\n timing: record.configuration.timing,\n destination: record.configuration.destination,\n deliveryPrincipal: record.configuration.deliveryPrincipal,\n ...(record.configuration.admissionGroup === undefined\n ? {}\n : { admissionGroup: record.configuration.admissionGroup }),\n ...(record.configuration.admissionFence === undefined\n ? {}\n : { admissionFence: record.configuration.admissionFence }),\n agentId: record.configuration.agentId,\n },\n state: record.state,\n nextAtMillis: record.nextAtMillis,\n pending:\n record.pending === null\n ? null\n : {\n intendedAtMillis: record.pending.envelope.intendedAtMillis,\n preparedAtMillis: record.pending.envelope.preparedAtMillis,\n configurationRevision: record.pending.envelope.configurationRevision,\n occurrenceId: record.pending.envelope.occurrenceId,\n retry: record.pending.retry,\n },\n lastReceipt: record.lastReceipt,\n lastRefusal: record.lastRefusal,\n lastSkippedRange: record.lastSkippedRange,\n observedAtMillis,\n pendingAgeMillis:\n record.pending === null\n ? null\n : Math.max(0, observedAtMillis - record.pending.envelope.preparedAtMillis),\n latenessMillis:\n intendedAtMillis === null ? 0 : Math.max(0, observedAtMillis - intendedAtMillis),\n };\n};\n\nconst inputByteLength = (input: PersistedJson): number => utf8ByteLength(JSON.stringify(input));\n\nconst currentMillis = DateTime.now.pipe(Effect.map(DateTime.toEpochMillis));\n\nconst validateRequestedFields = Effect.fn(\"Scheduling.validateRequestedFields\")(function* (\n options: ScheduleCreateOptions,\n) {\n yield* Schema.encodeEffect(ScheduleTimingRequestSchema)(options.timing).pipe(\n Effect.mapError(() => ScheduleValidationError.make({ message: \"Invalid timing request\" })),\n );\n yield* Schema.encodeEffect(ScheduleDestinationSchema)(options.destination).pipe(\n Effect.mapError(() => ScheduleValidationError.make({ message: \"Invalid destination\" })),\n );\n yield* Schema.encodeEffect(DefinitionDigests)(options.definitions).pipe(\n Effect.mapError(() => ScheduleValidationError.make({ message: \"Invalid definition digests\" })),\n );\n});\n\nconst resolveInput = Effect.fn(\"Scheduling.resolveInput\")(function* <\n InputSchema extends Schema.Top,\n>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n maximumBytes: number,\n): Effect.fn.Return<\n { readonly payload: PersistedJson; readonly digest: Digest },\n ScheduleValidationError,\n InputSchema[\"EncodingServices\"] | Crypto.Crypto\n> {\n const encoded = yield* Schema.encodeEffect(agent.definition.input)(input).pipe(\n Effect.mapError(() =>\n ScheduleValidationError.make({ message: \"Unable to encode Agent input\" }),\n ),\n );\n\n const payload = yield* Schema.decodeUnknownEffect(PersistedJson)(encoded).pipe(\n Effect.mapError(() =>\n ScheduleValidationError.make({\n message: \"Agent input does not satisfy the canonical persistence bounds\",\n }),\n ),\n );\n\n if (inputByteLength(payload) > maximumBytes) {\n return yield* ScheduleValidationError.make({\n message: `Encoded Agent input exceeds the configured ${maximumBytes} byte limit`,\n });\n }\n\n const digest = yield* digestJson(payload).pipe(\n Effect.mapError(() =>\n ScheduleValidationError.make({ message: \"Unable to digest encoded Agent input\" }),\n ),\n );\n\n return { payload, digest };\n});\n\nconst makeManagement = (limits: SchedulingLimits) =>\n Effect.gen(function* () {\n const nowMillis = yield* currentMillis;\n\n yield* Schema.decodeEffect(ScheduleInstant)(nowMillis + limits.recoveryPollMillis).pipe(\n Effect.mapError(() =>\n ScheduleValidationError.make({\n message: \"Scheduling recovery deadline exceeds the supported instant range\",\n }),\n ),\n );\n const store = yield* ScheduleStore;\n const authorizer = yield* ScheduleAuthorizer;\n const wake = yield* ScheduleWake;\n const crypto = yield* Crypto.Crypto;\n\n const withCrypto = <A, E>(effect: Effect.Effect<A, E, Crypto.Crypto>) =>\n Effect.provideService(effect, Crypto.Crypto, crypto);\n\n const fingerprint = Effect.fn(\"Scheduling.fingerprint\")(function* (\n agentId: AgentId,\n inputDigest: Digest,\n options: ScheduleCreateOptions,\n ) {\n const timing = yield* Schema.encodeEffect(ScheduleTimingRequestSchema)(options.timing).pipe(\n Effect.mapError(() => ScheduleValidationError.make({ message: \"Invalid timing request\" })),\n );\n\n const destination = yield* Schema.encodeEffect(ScheduleDestinationSchema)(\n options.destination,\n ).pipe(\n Effect.mapError(() => ScheduleValidationError.make({ message: \"Invalid destination\" })),\n );\n\n const definitions = yield* Schema.encodeEffect(DefinitionDigests)(options.definitions).pipe(\n Effect.mapError(() =>\n ScheduleValidationError.make({ message: \"Invalid definition digests\" }),\n ),\n );\n\n return yield* withCrypto(\n digestJson({\n schemaVersion: 1,\n owner: options.scope.owner,\n scheduleId: options.scheduleId,\n registeringPrincipal: options.scope.principal,\n deliveryPrincipal: options.deliveryPrincipal,\n ...(options.admissionGroup === undefined\n ? {}\n : { admissionGroup: options.admissionGroup }),\n ...(options.admissionFence === undefined\n ? {}\n : { admissionFence: options.admissionFence }),\n agentId,\n definitions,\n destination,\n timing,\n inputDigest,\n }),\n ).pipe(\n Effect.mapError(() =>\n ScheduleValidationError.make({ message: \"Unable to digest Schedule registration\" }),\n ),\n );\n });\n\n const configuration = (\n agentId: AgentId,\n payload: PersistedJson,\n inputDigest: Digest,\n options: ScheduleCreateOptions,\n timing: ScheduleConfiguration[\"timing\"],\n ): ScheduleConfiguration => ({\n timing,\n destination: options.destination,\n deliveryPrincipal: options.deliveryPrincipal,\n ...(options.admissionGroup === undefined ? {} : { admissionGroup: options.admissionGroup }),\n ...(options.admissionFence === undefined ? {} : { admissionFence: options.admissionFence }),\n agentId,\n definitions: options.definitions,\n input: payload,\n inputDigest,\n });\n\n const create = Effect.fn(\"Scheduling.create\")(function* <InputSchema extends Schema.Top>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n options: ScheduleCreateOptions,\n ): Effect.fn.Return<\n ScheduleSnapshot,\n ScheduleManagementFailure,\n InputSchema[\"EncodingServices\"]\n > {\n const nowMillis = yield* currentMillis;\n\n const resolvedInput = yield* resolveInput(agent, input, limits.maxInputBytes).pipe(\n Effect.provideService(Crypto.Crypto, crypto),\n );\n\n const creationFingerprint = yield* fingerprint(\n agent.definition.id,\n resolvedInput.digest,\n options,\n );\n\n const key = keyOf(options.scope, options.scheduleId);\n\n yield* authorizer.manage({\n operation: \"create\",\n scope: options.scope,\n scheduleId: options.scheduleId,\n });\n const existing = yield* store.get(key);\n\n if (existing !== null) {\n if (existing.creationFingerprint !== creationFingerprint) {\n return yield* ScheduleConflict.make({ reason: \"creation\", key });\n }\n yield* authorizer.manage({\n operation: \"create\",\n scope: options.scope,\n scheduleId: options.scheduleId,\n configuration: existing.configuration,\n });\n\n return asSnapshot(existing, nowMillis);\n }\n\n const timing = yield* Effect.fromResult(\n normalizeScheduleTiming(options.timing, nowMillis, limits.minIntervalMillis),\n );\n\n const nextAtMillis = yield* Effect.fromResult(scheduleInitialCursor(timing, nowMillis));\n\n if (nextAtMillis === null) {\n return yield* ScheduleValidationError.make({ message: \"Timing has no next occurrence\" });\n }\n\n const nextConfiguration = configuration(\n agent.definition.id,\n resolvedInput.payload,\n resolvedInput.digest,\n options,\n timing,\n );\n\n yield* authorizer.manage({\n operation: \"create\",\n scope: options.scope,\n scheduleId: options.scheduleId,\n configuration: nextConfiguration,\n });\n\n const record: ScheduleRecord = {\n schemaVersion: 1,\n owner: options.scope.owner,\n scheduleId: options.scheduleId,\n creationFingerprint,\n createdBy: options.scope.principal,\n createdAtMillis: nowMillis,\n updatedAtMillis: nowMillis,\n configurationRevision: 1,\n version: 1,\n configuration: nextConfiguration,\n state: \"active\",\n nextAtMillis,\n pending: null,\n lastReceipt: null,\n lastRefusal: null,\n lastSkippedRange: null,\n };\n\n const inserted = yield* store.insert(record, limits.maxSchedulesPerOwner);\n\n yield* wake.notify;\n\n return asSnapshot(inserted, nowMillis);\n });\n\n const update = Effect.fn(\"Scheduling.update\")(function* <InputSchema extends Schema.Top>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n options: ScheduleUpdateOptions,\n ): Effect.fn.Return<\n ScheduleSnapshot,\n ScheduleManagementFailure,\n InputSchema[\"EncodingServices\"]\n > {\n const nowMillis = yield* currentMillis;\n const key = keyOf(options.scope, options.scheduleId);\n\n yield* authorizer.manage({\n operation: \"update\",\n scope: options.scope,\n scheduleId: options.scheduleId,\n });\n yield* validateRequestedFields(options);\n const existing = yield* store.get(key);\n\n if (existing === null) return yield* notFound(key);\n if (existing.configurationRevision !== options.expectedRevision) {\n return yield* ScheduleConflict.make({ reason: \"revision\", key });\n }\n\n const resolvedInput = yield* resolveInput(agent, input, limits.maxInputBytes).pipe(\n Effect.provideService(Crypto.Crypto, crypto),\n );\n\n const timingRequest =\n options.timing._tag === \"Interval\" &&\n options.timing.anchorMillis === undefined &&\n existing.configuration.timing._tag === \"Interval\" &&\n existing.configuration.timing.everyMillis === options.timing.everyMillis\n ? { ...options.timing, anchorMillis: existing.configuration.timing.anchorMillis }\n : options.timing;\n\n const timing = yield* Effect.fromResult(\n normalizeScheduleTiming(timingRequest, nowMillis, limits.minIntervalMillis),\n );\n\n const nextAtMillis =\n timing._tag === \"At\"\n ? timing.atMillis\n : yield* Effect.fromResult(scheduleNextAfter(timing, nowMillis));\n\n if (nextAtMillis === null) {\n return yield* ScheduleValidationError.make({ message: \"Timing has no next occurrence\" });\n }\n\n const nextConfiguration = configuration(\n agent.definition.id,\n resolvedInput.payload,\n resolvedInput.digest,\n options,\n timing,\n );\n\n yield* authorizer.manage({\n operation: \"update\",\n scope: options.scope,\n scheduleId: options.scheduleId,\n configuration: nextConfiguration,\n });\n\n const changed = yield* store.change(\n key,\n {\n _tag: \"Update\",\n expectedRevision: options.expectedRevision,\n configuration: nextConfiguration,\n nextAtMillis,\n nowMillis,\n },\n limits.maxSchedulesPerOwner,\n );\n\n yield* wake.notify;\n\n return asSnapshot(changed, nowMillis);\n });\n\n const get = Effect.fn(\"Scheduling.get\")(function* (\n scope: ScheduleScope,\n scheduleId: ScheduleId,\n ) {\n yield* authorizer.manage({ operation: \"get\", scope, scheduleId });\n const key = keyOf(scope, scheduleId);\n const record = yield* store.get(key);\n\n if (record === null) return yield* notFound(key);\n\n return asSnapshot(record, yield* currentMillis);\n });\n\n const list = Effect.fn(\"Scheduling.list\")(function* (\n scope: ScheduleScope,\n options: ScheduleListOptions = {},\n ) {\n yield* authorizer.manage({ operation: \"list\", scope });\n const limit = options.limit ?? 50;\n\n if (!Number.isInteger(limit) || limit < 1 || limit > 100) {\n return yield* ScheduleValidationError.make({\n message: \"Schedule page limit must be an integer from 1 through 100\",\n });\n }\n\n const page = yield* store.list({\n owner: scope.owner,\n ...(options.after === undefined ? {} : { after: options.after }),\n limit,\n });\n\n const nowMillis = yield* currentMillis;\n\n return { items: page.items.map((record) => asSnapshot(record, nowMillis)), next: page.next };\n });\n\n const control = Effect.fn(\"Scheduling.control\")(function* (\n operation: \"pause\" | \"resume\" | \"cancel\",\n scope: ScheduleScope,\n scheduleId: ScheduleId,\n expectedRevision: number,\n ): Effect.fn.Return<ScheduleSnapshot, ScheduleManagementFailure> {\n yield* authorizer.manage({ operation, scope, scheduleId });\n const key = keyOf(scope, scheduleId);\n\n const attempt = (): Effect.Effect<ScheduleRecord, ScheduleManagementFailure> =>\n Effect.suspend(() =>\n Effect.gen(function* () {\n const record = yield* store.get(key);\n\n if (record === null) return yield* notFound(key);\n if (record.configurationRevision !== expectedRevision) {\n return yield* ScheduleConflict.make({ reason: \"revision\", key });\n }\n if (operation === \"resume\" && record.state === \"active\") return record;\n const nowMillis = yield* currentMillis;\n\n const nextAtMillis =\n operation === \"resume\"\n ? yield* Effect.fromResult(\n scheduleResumeCursor(\n record.configuration.timing,\n record.nextAtMillis,\n nowMillis,\n ),\n )\n : operation === \"cancel\"\n ? null\n : record.nextAtMillis;\n\n const skippedRange =\n operation === \"resume\" &&\n record.configuration.timing._tag !== \"At\" &&\n record.nextAtMillis !== null &&\n nextAtMillis !== null &&\n nextAtMillis > record.nextAtMillis\n ? { fromMillis: record.nextAtMillis, toMillis: nextAtMillis }\n : null;\n\n return yield* store\n .change(\n key,\n {\n _tag: \"Control\",\n expectedRevision,\n expectedVersion: record.version,\n action: operation,\n nextAtMillis,\n nowMillis,\n skippedRange,\n },\n limits.maxSchedulesPerOwner,\n )\n .pipe(\n Effect.catchTag(\"ScheduleConflict\", (error) =>\n error.reason === \"revision\" ? attempt() : Effect.fail(error),\n ),\n );\n }),\n );\n\n const changed = yield* attempt();\n\n yield* wake.notify;\n\n return asSnapshot(changed, yield* currentMillis);\n });\n\n const recover = Effect.fn(\"Scheduling.recover\")(function* (\n scope: ScheduleScope,\n scheduleId: ScheduleId,\n expectedRevision: number,\n expectedGeneration: number,\n ) {\n yield* authorizer.manage({ operation: \"recover\", scope, scheduleId });\n const key = keyOf(scope, scheduleId);\n const record = yield* store.get(key);\n\n if (record === null) return yield* notFound(key);\n if (record.configurationRevision !== expectedRevision)\n return yield* ScheduleConflict.make({ reason: \"revision\", key });\n const time = yield* currentMillis;\n\n if (record.pending === null) return asSnapshot(record, time);\n\n const recovered = yield* store.change(key, {\n _tag: \"Recover\",\n expectedGeneration,\n expectedRevision,\n occurrenceId: record.pending.envelope.occurrenceId,\n nowMillis: time,\n });\n\n yield* wake.notify;\n\n return asSnapshot(recovered, time);\n });\n\n return Scheduling.of({\n recover,\n create,\n update,\n get,\n list,\n pause: (scope, id, revision) => control(\"pause\", scope, id, revision),\n resume: (scope, id, revision) => control(\"resume\", scope, id, revision),\n cancel: (scope, id, revision) => control(\"cancel\", scope, id, revision),\n });\n });\n\nconst makeDriver = (limits: SchedulingLimits) =>\n Effect.gen(function* () {\n const store = yield* ScheduleStore;\n const authorizer = yield* ScheduleAuthorizer;\n const admission = yield* ScheduledInputAdmission;\n const failpoint = yield* ScheduleFailpoint;\n const crypto = yield* Crypto.Crypto;\n const admissionSemaphore = yield* Semaphore.make(limits.admissionConcurrency);\n\n const withCrypto = <A, E>(effect: Effect.Effect<A, E, Crypto.Crypto>) =>\n Effect.provideService(effect, Crypto.Crypto, crypto);\n\n const retry = Effect.fn(\"Scheduling.retry\")(function* (\n key: ScheduleKey,\n record: ScheduleRecord,\n reason: ScheduleRetryReason,\n nowMillis: number,\n ) {\n if (record.pending === null) return record;\n const current = record.pending.retry;\n\n const delay = Math.min(\n limits.retryBaseMillis * 2 ** Math.min(current.attempts, 52),\n limits.retryMaxMillis,\n );\n\n return yield* store.change(key, {\n _tag: \"Retry\",\n occurrenceId: record.pending.envelope.occurrenceId,\n retry: {\n generation: current.generation,\n attempts: current.attempts + 1,\n automaticAttempts: current.automaticAttempts + 1,\n parked: current.automaticAttempts + 1 >= (limits.maxAutomaticAttempts ?? 8),\n nextAttemptAtMillis: Math.min(nowMillis + delay, 8_640_000_000_000_000),\n lastAttemptAtMillis: nowMillis,\n lastFailure: reason,\n },\n nowMillis,\n });\n });\n\n const verifyPending = Effect.fn(\"Scheduling.verifyPending\")(function* (\n key: ScheduleKey,\n record: ScheduleRecord,\n ) {\n const pending = record.pending;\n\n if (pending === null) return;\n const envelope = pending.envelope;\n\n const occurrenceId = yield* withCrypto(\n digestJson({\n schemaVersion: 1,\n owner: envelope.owner,\n scheduleId: envelope.scheduleId,\n configurationRevision: envelope.configurationRevision,\n intendedAtMillis: envelope.intendedAtMillis,\n }),\n ).pipe(Effect.mapError(() => corrupt(\"process\")));\n\n const usesCurrentConfiguration =\n envelope.configurationRevision === record.configurationRevision;\n\n const expectedThreadId = usesCurrentConfiguration\n ? record.configuration.destination._tag === \"ExistingThread\"\n ? record.configuration.destination.threadId\n : Schema.decodeSync(ThreadId)(`schedule-thread:${envelope.occurrenceId}`)\n : null;\n\n const expectedAdmissionKey = Schema.decodeSync(IdempotencyKey)(\n `schedule-occurrence:${envelope.occurrenceId}`,\n );\n\n const digest = yield* withCrypto(digestJson(envelope.input)).pipe(\n Effect.mapError(() => corrupt(\"process\")),\n );\n\n if (\n envelope.schemaVersion !== 1 ||\n envelope.owner.tenantId !== key.owner.tenantId ||\n envelope.owner.ownerId !== key.owner.ownerId ||\n envelope.scheduleId !== key.scheduleId ||\n envelope.configurationRevision > record.configurationRevision ||\n envelope.occurrenceId !== occurrenceId ||\n (usesCurrentConfiguration &&\n (envelope.deliveryPrincipal !== record.configuration.deliveryPrincipal ||\n envelope.agentId !== record.configuration.agentId ||\n !equivalentDefinitions(envelope.definitions, record.configuration.definitions) ||\n !equivalentInput(envelope.input, record.configuration.input) ||\n envelope.inputDigest !== record.configuration.inputDigest)) ||\n envelope.inputDigest !== digest ||\n (expectedThreadId !== null && envelope.threadId !== expectedThreadId) ||\n envelope.admissionKey !== expectedAdmissionKey\n ) {\n return yield* corrupt(\"process\");\n }\n });\n\n const deliverPending = Effect.fn(\"Scheduling.deliverPending\")(function* (\n key: ScheduleKey,\n record: ScheduleRecord,\n nowMillis: number,\n ) {\n if (\n record.pending === null ||\n record.pending.retry.parked === true ||\n record.pending.retry.nextAttemptAtMillis > nowMillis\n ) {\n return record;\n }\n yield* verifyPending(key, record);\n const envelope = record.pending.envelope;\n\n const outcome = yield* admissionSemaphore.withPermit(\n admitPreparedInput(admission.submit(envelope), limits.admissionTimeoutMillis).pipe(\n Effect.tap((outcome) =>\n outcome._tag === \"Receipt\" ? failpoint.hit(\"schedule:admission:after\") : Effect.void,\n ),\n ),\n );\n\n const completedAtMillis = yield* currentMillis;\n\n if (outcome._tag === \"Receipt\") {\n if (outcome.receipt.threadId !== envelope.threadId) {\n return yield* corrupt(\"admission\");\n }\n\n return yield* store\n .change(key, {\n _tag: \"Complete\",\n occurrenceId: envelope.occurrenceId,\n receipt: outcome.receipt,\n nowMillis: completedAtMillis,\n })\n .pipe(\n Effect.catchTag(\"ScheduleStorageError\", (error) =>\n error.reason === \"unavailable\"\n ? retry(key, record, \"storage\", completedAtMillis)\n : Effect.fail(error),\n ),\n );\n }\n if (outcome._tag === \"Refused\") {\n const refusal: ScheduleRefusal = {\n atMillis: completedAtMillis,\n intendedAtMillis: envelope.intendedAtMillis,\n occurrenceId: envelope.occurrenceId,\n phase: \"admission\",\n code: outcome.error.code,\n };\n\n return yield* store\n .change(key, {\n _tag: \"Refuse\",\n occurrenceId: envelope.occurrenceId,\n refusal,\n nowMillis: completedAtMillis,\n })\n .pipe(\n Effect.catchTag(\"ScheduleStorageError\", (error) =>\n error.reason === \"unavailable\"\n ? retry(key, record, \"storage\", completedAtMillis)\n : Effect.fail(error),\n ),\n );\n }\n\n return yield* retry(key, record, outcome.reason, completedAtMillis);\n });\n\n const processRecord = Effect.fn(\"Scheduling.processRecord\")(function* (\n key: ScheduleKey,\n initial: ScheduleRecord,\n nowMillis: number,\n ): Effect.fn.Return<ScheduleRecord, ScheduleProcessFailure> {\n if (initial.pending !== null) return yield* deliverPending(key, initial, nowMillis);\n if (\n initial.state !== \"active\" ||\n initial.nextAtMillis === null ||\n initial.nextAtMillis > nowMillis\n ) {\n return initial;\n }\n\n const currentInputDigest = yield* withCrypto(digestJson(initial.configuration.input)).pipe(\n Effect.mapError(() =>\n ScheduleStorageError.make({ operation: \"prepare\", reason: \"unavailable\" }),\n ),\n );\n\n if (currentInputDigest !== initial.configuration.inputDigest) {\n return yield* corrupt(\"prepare\");\n }\n\n const due = yield* Effect.fromResult(\n scheduleDueOccurrence(initial.configuration.timing, initial.nextAtMillis, nowMillis),\n );\n\n if (due === null) return initial;\n\n const occurrenceId = yield* withCrypto(\n digestJson({\n schemaVersion: 1,\n owner: initial.owner,\n scheduleId: initial.scheduleId,\n configurationRevision: initial.configurationRevision,\n intendedAtMillis: due.intendedAtMillis,\n }),\n ).pipe(Effect.mapError(() => corrupt(\"prepare\")));\n\n const occurrence = {\n key,\n configurationRevision: initial.configurationRevision,\n configuration: initial.configuration,\n intendedAtMillis: due.intendedAtMillis,\n occurrenceId,\n };\n\n const authorization = yield* authorizer.prepare(occurrence).pipe(Effect.result);\n\n if (Result.isFailure(authorization)) {\n if (authorization.failure._tag === \"ScheduleStorageError\") {\n return yield* authorization.failure;\n }\n\n return yield* store.change(key, {\n _tag: \"DenyPreparation\",\n expectedRevision: initial.configurationRevision,\n expectedCursor: initial.nextAtMillis,\n refusal: {\n atMillis: nowMillis,\n intendedAtMillis: due.intendedAtMillis,\n occurrenceId,\n phase: \"preparation\",\n code: authorization.failure.code,\n },\n nowMillis,\n });\n }\n\n const threadId =\n initial.configuration.destination._tag === \"ExistingThread\"\n ? initial.configuration.destination.threadId\n : Schema.decodeSync(ThreadId)(`schedule-thread:${occurrenceId}`);\n\n const admissionKey = Schema.decodeSync(IdempotencyKey)(`schedule-occurrence:${occurrenceId}`);\n\n const prepared = yield* store.change(key, {\n _tag: \"Prepare\",\n expectedRevision: initial.configurationRevision,\n expectedCursor: initial.nextAtMillis,\n envelope: {\n schemaVersion: 1,\n owner: initial.owner,\n scheduleId: initial.scheduleId,\n configurationRevision: initial.configurationRevision,\n intendedAtMillis: due.intendedAtMillis,\n preparedAtMillis: nowMillis,\n occurrenceId,\n threadId,\n deliveryPrincipal: initial.configuration.deliveryPrincipal,\n ...(initial.configuration.admissionGroup === undefined\n ? {}\n : { admissionGroup: initial.configuration.admissionGroup }),\n ...(initial.configuration.admissionFence === undefined\n ? {}\n : { admissionFence: initial.configuration.admissionFence }),\n agentId: initial.configuration.agentId,\n definitions: initial.configuration.definitions,\n input: initial.configuration.input,\n inputDigest: initial.configuration.inputDigest,\n admissionKey,\n authorization: authorization.success,\n },\n nextAtMillis: due.nextAtMillis,\n skippedRange: due.skippedRange,\n nowMillis,\n });\n\n return yield* deliverPending(key, prepared, nowMillis);\n });\n\n const process = Effect.fn(\"Scheduling.process\")(function* (key: ScheduleKey) {\n const nowMillis = yield* currentMillis;\n const record = yield* store.get(key);\n\n if (record === null) return yield* notFound(key);\n\n const processed = yield* processRecord(key, record, nowMillis).pipe(\n Effect.catchTag(\"ScheduleConflict\", () =>\n store\n .get(key)\n .pipe(\n Effect.flatMap((current) =>\n current === null\n ? Effect.fail(notFound(key))\n : processRecord(key, current, nowMillis),\n ),\n ),\n ),\n );\n\n return processed;\n });\n\n const runDue = Effect.fn(\"ScheduleDriver.runDue\")(function* (owner?: ScheduleOwner) {\n const nowMillis = yield* currentMillis;\n let after: ScheduleDueCursor | undefined;\n let processed = 0;\n let failed = 0;\n\n while (true) {\n const due = yield* store.due(nowMillis, limits.dueBatchSize, owner, after);\n\n if (due.length === 0) break;\n yield* Effect.forEach(\n due,\n (key) =>\n process(key).pipe(\n Effect.matchCauseEffect({\n onSuccess: () =>\n Effect.sync(() => {\n processed += 1;\n }),\n onFailure: (cause) =>\n Cause.hasInterrupts(cause)\n ? Effect.interrupt\n : Effect.gen(function* () {\n failed += 1;\n yield* Effect.logWarning(\"Schedule processing failed\").pipe(\n Effect.annotateLogs({\n failureTag: Option.match(Cause.findErrorOption(cause), {\n onNone: () => \"Defect\",\n onSome: (error) => error._tag,\n }),\n }),\n );\n }),\n }),\n ),\n { concurrency: limits.admissionConcurrency },\n );\n after = due.at(-1);\n if (due.length < limits.dueBatchSize) break;\n }\n\n return { processed, failed };\n });\n\n return ScheduleDriver.of({ process, runDue });\n });\n\nconst corrupt = (operation: string): ScheduleStorageError =>\n ScheduleStorageError.make({ operation, reason: \"corrupt\" });\n\nconst validateLimits = (limits: SchedulingLimits) =>\n Schema.decodeEffect(SchedulingLimits)(limits).pipe(\n Effect.mapError((error) =>\n ScheduleValidationError.make({ message: `Invalid Scheduling limits: ${error.message}` }),\n ),\n Effect.filterOrFail(\n (validated) => validated.retryBaseMillis <= validated.retryMaxMillis,\n () =>\n ScheduleValidationError.make({\n message: \"Scheduling retryBaseMillis must not exceed retryMaxMillis\",\n }),\n ),\n );\n\nexport class Scheduling extends Context.Service<\n Scheduling,\n {\n readonly create: <InputSchema extends Schema.Top>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n options: ScheduleCreateOptions,\n ) => Effect.Effect<\n ScheduleSnapshot,\n ScheduleManagementFailure,\n InputSchema[\"EncodingServices\"]\n >;\n readonly update: <InputSchema extends Schema.Top>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n options: ScheduleUpdateOptions,\n ) => Effect.Effect<\n ScheduleSnapshot,\n ScheduleManagementFailure,\n InputSchema[\"EncodingServices\"]\n >;\n readonly get: (\n scope: ScheduleScope,\n scheduleId: ScheduleId,\n ) => Effect.Effect<ScheduleSnapshot, ScheduleManagementFailure>;\n readonly list: (\n scope: ScheduleScope,\n options?: ScheduleListOptions,\n ) => Effect.Effect<ScheduleSnapshotPage, ScheduleManagementFailure>;\n readonly pause: (\n scope: ScheduleScope,\n scheduleId: ScheduleId,\n expectedRevision: number,\n ) => Effect.Effect<ScheduleSnapshot, ScheduleManagementFailure>;\n readonly resume: (\n scope: ScheduleScope,\n scheduleId: ScheduleId,\n expectedRevision: number,\n ) => Effect.Effect<ScheduleSnapshot, ScheduleManagementFailure>;\n readonly recover: (\n scope: ScheduleScope,\n scheduleId: ScheduleId,\n expectedRevision: number,\n expectedGeneration: number,\n ) => Effect.Effect<ScheduleSnapshot, ScheduleManagementFailure>;\n readonly cancel: (\n scope: ScheduleScope,\n scheduleId: ScheduleId,\n expectedRevision: number,\n ) => Effect.Effect<ScheduleSnapshot, ScheduleManagementFailure>;\n }\n>()(\"@effect-agent/thread/Scheduling\") {\n static layer(\n limits: SchedulingLimits = defaultSchedulingLimits,\n ): Layer.Layer<\n Scheduling,\n ScheduleValidationError,\n ScheduleStore | ScheduleAuthorizer | ScheduleWake | Crypto.Crypto\n > {\n return Layer.effect(Scheduling, validateLimits(limits).pipe(Effect.flatMap(makeManagement)));\n }\n}\n\nexport const ScheduleWakeNoop: Layer.Layer<ScheduleWake> = Layer.succeed(ScheduleWake, {\n notify: Effect.void,\n await: Effect.never,\n});\n\n/** Privileged host capability. Never provide this service to management callers or model tools. */\nexport class ScheduleDriver extends Context.Service<\n ScheduleDriver,\n {\n readonly process: (key: ScheduleKey) => Effect.Effect<ScheduleRecord, ScheduleProcessFailure>;\n readonly runDue: (\n owner?: ScheduleOwner,\n ) => Effect.Effect<\n { readonly processed: number; readonly failed: number },\n ScheduleStorageError\n >;\n }\n>()(\"@effect-agent/thread/ScheduleDriver\") {\n static layer(\n limits: SchedulingLimits = defaultSchedulingLimits,\n ): Layer.Layer<\n ScheduleDriver,\n ScheduleValidationError,\n ScheduleStore | ScheduleAuthorizer | ScheduledInputAdmission | Crypto.Crypto\n > {\n return Layer.effect(ScheduleDriver, validateLimits(limits).pipe(Effect.flatMap(makeDriver)));\n }\n}\n"],"mappings":";;;;;;;;;;AAUA,MAAM,WAAW,YAAoB,OAAO,KAAK,wBAAwB,KAAK,EAAE,QAAQ,CAAC,CAAC;AAE1F,MAAM,kBAAkB,QAAgB,UACtC,OAAO,aAAa,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,KAC3C,OAAO,eACL,wBAAwB,KAAK,EAC3B,SAAS,GAAG,MAAM,iDACpB,CAAC,CACH,CACF;AAEF,MAAM,UAA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AW,QAAQ;AAAU,CAAC;AAE5D,MAAM,kBAAkB,WACtB,OAAO,aAAa,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC,KAC5C,OAAO,UAAU,UACf,wBAAwB,KAAK,EAAE,SAAS,8BAA8B,MAAM,UAAU,CAAC,CACzF,GACA,OAAO,cACJ,cAAc,UAAU,mBAAmB,UAAU,sBAEpD,wBAAwB,KAAK,EAC3B,SAAS,4DACX,CAAC,CACL,CACF;AAEF,IAAa,aAAb,MAAa,mBAAmB,QAAQ,QAmDtC,CAAC,CAAC,iCAAiC,CAAC,CAAC;CACrC,OAAO,MACL,SAA2B,yBAK3B;EACA,OAAO,MAAM,OAAO,YAAY,eAAe,MAAM,CAAC,CAAC,KAAK,OAAO,QAAQ,cAAc,CAAC,CAAC;CAC7F;AACF;AAEA,MAAa,mBAA8C,MAAM,QAAQ,cAAc;CACrF,QAAQ,OAAO;CACf,OAAO,OAAO;AAChB,CAAC;;AAGD,IAAa,iBAAb,MAAa,uBAAuB,QAAQ,QAW1C,CAAC,CAAC,qCAAqC,CAAC,CAAC;CACzC,OAAO,MACL,SAA2B,yBAK3B;EACA,OAAO,MAAM,OAAO,gBAAgB,eAAe,MAAM,CAAC,CAAC,KAAK,OAAO,QAAQ,UAAU,CAAC,CAAC;CAC7F;AACF"}
1
+ {"version":3,"file":"Scheduling-HFH0pST1.mjs","names":["ScheduleTimingRequestSchema","ScheduleDestinationSchema"],"sources":["../src/durable/internal/schedule-time.ts","../src/durable/Scheduling.ts"],"sourcesContent":["import { Cron, DateTime, Option, Result, Schema } from \"effect\";\n\nimport {\n ScheduleValidationError,\n ScheduleInstant,\n type ScheduleSkippedRange,\n type ScheduleTiming,\n type ScheduleTimingRequest,\n} from \"../Schedule.ts\";\n\nconst invalid = (message: string) => Result.fail(ScheduleValidationError.make({ message }));\n\nconst checkedInstant = (millis: number, label: string) =>\n Schema.decodeResult(ScheduleInstant)(millis).pipe(\n Result.mapError(() =>\n ScheduleValidationError.make({\n message: `${label} is outside the supported ScheduleInstant range`,\n }),\n ),\n );\n\nconst values = (set: ReadonlySet<number>, size: number): ReadonlyArray<number> =>\n set.size === 0 ? Array.from({ length: size }, (_, index) => index) : [...set];\n\n/**\n * Cron frequency proof without calendar enumeration. It checks the minimum circular spacing of\n * the allowed hour/minute pairs. Day restrictions may make a rule sparser, so this deliberately\n * rejects some safe rules when a configured minimum exceeds one minute.\n */\nconst validateCronFrequency = (\n cron: Cron.Cron,\n minimumMillis: number,\n): Result.Result<void, ScheduleValidationError> => {\n if (cron.seconds.size !== 1) {\n return invalid(\"Cron must select exactly one seconds value\");\n }\n if (minimumMillis <= 60_000) return Result.succeed(undefined);\n if (\n Option.isSome(cron.tz) &&\n DateTime.isTimeZoneNamed(cron.tz.value) &&\n cron.tz.value.id !== \"UTC\"\n ) {\n return invalid(\"Cron minimums above one minute require UTC or a fixed-offset time zone\");\n }\n\n const minuteOfDay = values(cron.hours, 24).flatMap((hour) =>\n values(cron.minutes, 60).map((minute) => hour * 60 + minute),\n );\n\n minuteOfDay.sort((left, right) => left - right);\n let minimumGap = 24 * 60;\n\n for (let index = 0; index < minuteOfDay.length; index += 1) {\n const current = minuteOfDay[index];\n const next = minuteOfDay[(index + 1) % minuteOfDay.length];\n\n if (current === undefined || next === undefined) continue;\n const gap = next > current ? next - current : 24 * 60 - current + next;\n\n minimumGap = Math.min(minimumGap, gap);\n }\n\n return minimumGap * 60_000 >= minimumMillis\n ? Result.succeed(undefined)\n : invalid(`Cron may fire more often than the configured ${minimumMillis}ms minimum`);\n};\n\nexport const parseScheduleCron = (\n expression: string,\n timeZone: string,\n minimumMillis: number,\n): Result.Result<Cron.Cron, ScheduleValidationError> => {\n const parsed = Cron.parse(expression, timeZone);\n\n if (Result.isFailure(parsed)) return invalid(parsed.failure.message);\n const frequency = validateCronFrequency(parsed.success, minimumMillis);\n\n return Result.isFailure(frequency)\n ? Result.fail(frequency.failure)\n : Result.succeed(parsed.success);\n};\n\nexport const normalizeScheduleTiming = (\n request: ScheduleTimingRequest,\n nowMillis: number,\n minimumMillis: number,\n): Result.Result<ScheduleTiming, ScheduleValidationError> => {\n switch (request._tag) {\n case \"At\":\n return Result.succeed(request);\n case \"After\": {\n const at = checkedInstant(nowMillis + request.delayMillis, \"Relative deadline\");\n\n return Result.map(at, (atMillis) => ({ _tag: \"At\" as const, atMillis }));\n }\n case \"Interval\": {\n if (request.everyMillis < minimumMillis) {\n return invalid(`Interval must be at least ${minimumMillis}ms`);\n }\n\n const anchor = checkedInstant(\n request.anchorMillis ?? nowMillis + request.everyMillis,\n \"Interval anchor\",\n );\n\n return Result.map(anchor, (anchorMillis) => ({\n _tag: \"Interval\" as const,\n everyMillis: request.everyMillis,\n anchorMillis,\n }));\n }\n case \"Cron\": {\n const timeZone = request.timeZone ?? \"UTC\";\n const cron = parseScheduleCron(request.expression, timeZone, minimumMillis);\n\n if (Result.isFailure(cron)) return Result.fail(cron.failure);\n\n return Result.succeed({ _tag: \"Cron\", expression: request.expression, timeZone });\n }\n }\n};\n\nconst parsedStoredCron = (timing: Extract<ScheduleTiming, { _tag: \"Cron\" }>) => {\n const parsed = Cron.parse(timing.expression, timing.timeZone);\n\n return Result.isFailure(parsed)\n ? invalid(`Stored cron is invalid: ${parsed.failure.message}`)\n : Result.succeed(parsed.success);\n};\n\n/** Strictly selects the first occurrence after an instant. */\nexport const scheduleNextAfter = (\n timing: ScheduleTiming,\n afterMillis: number,\n): Result.Result<number | null, ScheduleValidationError> => {\n switch (timing._tag) {\n case \"At\":\n return Result.succeed(timing.atMillis > afterMillis ? timing.atMillis : null);\n case \"Interval\": {\n if (afterMillis < timing.anchorMillis) return Result.succeed(timing.anchorMillis);\n const steps = Math.floor((afterMillis - timing.anchorMillis) / timing.everyMillis) + 1;\n const next = timing.anchorMillis + steps * timing.everyMillis;\n\n return checkedInstant(next, \"Next interval occurrence\");\n }\n case \"Cron\": {\n const cron = parsedStoredCron(timing);\n\n if (Result.isFailure(cron)) return Result.fail(cron.failure);\n\n return Result.try({\n try: () => {\n let next = Cron.next(cron.success, afterMillis).getTime();\n\n // Inside a fall fold Effect may select the first, already elapsed local instant.\n while (next <= afterMillis) {\n const following = Cron.next(cron.success, next).getTime();\n\n if (following <= next) throw new Error(\"Cron did not advance\");\n next = following;\n }\n\n return next;\n },\n catch: () => ScheduleValidationError.make({ message: \"Cron has no supported next firing\" }),\n }).pipe(Result.flatMap((next) => checkedInstant(next, \"Next cron occurrence\")));\n }\n }\n};\n\n/** Initial cursor. Past one-shots remain due; recurring rules start strictly after registration. */\nexport const scheduleInitialCursor = (\n timing: ScheduleTiming,\n nowMillis: number,\n): Result.Result<number | null, ScheduleValidationError> =>\n timing._tag === \"At\" ? Result.succeed(timing.atMillis) : scheduleNextAfter(timing, nowMillis);\n\nexport interface DueScheduleOccurrence {\n readonly intendedAtMillis: number;\n readonly nextAtMillis: number | null;\n readonly skippedRange: ScheduleSkippedRange | null;\n}\n\n/** Coalesces recurring occurrences using the same forward sequence as registration. */\nexport const scheduleDueOccurrence = (\n timing: ScheduleTiming,\n cursorMillis: number,\n nowMillis: number,\n): Result.Result<DueScheduleOccurrence | null, ScheduleValidationError> => {\n if (cursorMillis > nowMillis) return Result.succeed(null);\n if (timing._tag === \"At\") {\n return Result.succeed({\n intendedAtMillis: cursorMillis,\n nextAtMillis: null,\n skippedRange: null,\n });\n }\n\n let intendedAtMillis: number;\n\n if (timing._tag === \"Interval\") {\n const steps = Math.floor((nowMillis - timing.anchorMillis) / timing.everyMillis);\n\n intendedAtMillis = Math.max(cursorMillis, timing.anchorMillis + steps * timing.everyMillis);\n } else {\n const cron = parsedStoredCron(timing);\n\n if (Result.isFailure(cron)) return Result.fail(cron.failure);\n\n const due = Result.try({\n try: () => {\n let intended = cursorMillis;\n // Reverse traversal is safe only without offset transitions. Named-zone reverse\n // traversal has different gap/fold semantics from the forward occurrence sequence.\n const zone = Option.getOrUndefined(cron.success.tz);\n\n if (zone !== undefined && (DateTime.isTimeZoneOffset(zone) || zone.id === \"UTC\")) {\n intended = Math.max(cursorMillis, Cron.prev(cron.success, nowMillis + 1_000).getTime());\n } else {\n // Seek by calendar date in UTC, where reverse traversal has no DST ambiguity.\n // Include two prior civil days to cover even IANA date-line shifts. There are no\n // matching dates between this seed day and that boundary, so forward traversal\n // visits only the seed day and the recent days, regardless of downtime length.\n const calendar = Cron.make({\n ...cron.success,\n seconds: [0],\n minutes: [0],\n hours: [0],\n tz: DateTime.zoneMakeNamedUnsafe(\"UTC\"),\n });\n\n const localDay = DateTime.makeUnsafe(\n DateTime.toDate(DateTime.makeZonedUnsafe(nowMillis, { timeZone: zone })),\n ).pipe(DateTime.startOf(\"day\"), DateTime.subtract({ days: 2 }));\n\n const seedDay = Cron.prev(calendar, DateTime.toEpochMillis(localDay) + 1_000);\n\n const seed =\n DateTime.makeZonedUnsafe(seedDay, {\n timeZone: zone,\n adjustForTimeZone: true,\n }).pipe(DateTime.toEpochMillis) - 1_000;\n\n if (seed > cursorMillis) {\n const first = Cron.next(cron.success, seed).getTime();\n\n if (first <= nowMillis) intended = Math.max(intended, first);\n }\n }\n let next = Cron.next(cron.success, intended).getTime();\n\n while (next <= nowMillis) {\n if (next <= intended) throw new Error(\"Cron did not advance\");\n intended = next;\n next = Cron.next(cron.success, intended).getTime();\n }\n\n return { intended, next };\n },\n catch: () => ScheduleValidationError.make({ message: \"Cron has no supported due firing\" }),\n });\n\n if (Result.isFailure(due)) return Result.fail(due.failure);\n const next = checkedInstant(due.success.next, \"Next cron occurrence\");\n\n if (Result.isFailure(next)) return Result.fail(next.failure);\n\n return Result.succeed({\n intendedAtMillis: due.success.intended,\n nextAtMillis: next.success,\n skippedRange:\n due.success.intended === cursorMillis\n ? null\n : {\n fromMillis: cursorMillis,\n toMillis: due.success.intended,\n },\n });\n }\n\n const next = scheduleNextAfter(timing, nowMillis);\n\n if (Result.isFailure(next)) return Result.fail(next.failure);\n\n return Result.succeed({\n intendedAtMillis,\n nextAtMillis: next.success,\n skippedRange:\n intendedAtMillis === cursorMillis\n ? null\n : { fromMillis: cursorMillis, toMillis: intendedAtMillis },\n });\n};\n\nexport const scheduleResumeCursor = (\n timing: ScheduleTiming,\n existingCursor: number | null,\n nowMillis: number,\n): Result.Result<number | null, ScheduleValidationError> => {\n if (timing._tag === \"At\") return Result.succeed(existingCursor);\n\n return scheduleNextAfter(timing, nowMillis);\n};\n","import {\n Cause,\n Context,\n Crypto,\n DateTime,\n Effect,\n Layer,\n Option,\n Result,\n Schema,\n Semaphore,\n} from \"effect\";\n\nimport { type AgentId, ThreadId } from \"../core/Identifiers.ts\";\nimport { utf8ByteLength } from \"../core/internal/utf8.ts\";\nimport { digestJson } from \"./Digest.ts\";\nimport type { DurableSubmitAgent } from \"./DurableAgentRuntime.ts\";\nimport {\n normalizeScheduleTiming,\n scheduleDueOccurrence,\n scheduleInitialCursor,\n scheduleNextAfter,\n scheduleResumeCursor,\n} from \"./internal/schedule-time.ts\";\nimport { admitPreparedInput } from \"./PreparedInputAdmission.ts\";\nimport { DefinitionDigests, type Digest, PersistedJson } from \"./Records.ts\";\nimport {\n defaultSchedulingLimits,\n type ScheduleAuthorizationError,\n ScheduleAuthorizer,\n ScheduleConflict,\n type ScheduleConfiguration,\n ScheduleDestination as ScheduleDestinationSchema,\n type ScheduleDestination,\n ScheduleFailpoint,\n type ScheduleId,\n type ScheduleDueCursor,\n ScheduleInstant,\n type ScheduleKey,\n SchedulingLimits,\n ScheduleNotFound,\n type ScheduleOwner,\n type ScheduleRecord,\n type ScheduleRefusal,\n type ScheduleRetryReason,\n type ScheduleScope,\n type ScheduleSnapshot,\n type ScheduleSnapshotPage,\n ScheduleStorageError,\n ScheduleStore,\n type ScheduleStoreFailure,\n ScheduleTimingRequest as ScheduleTimingRequestSchema,\n type ScheduleTimingRequest,\n ScheduleValidationError,\n ScheduledInputAdmission,\n ScheduleWake,\n} from \"./Schedule.ts\";\nimport { type AdmissionFence, IdempotencyKey, type Principal } from \"./SubmissionLedger.ts\";\n\nexport interface ScheduleCreateOptions {\n readonly scope: ScheduleScope;\n readonly scheduleId: ScheduleId;\n readonly timing: ScheduleTimingRequest;\n readonly destination: ScheduleDestination;\n readonly deliveryPrincipal: Principal;\n readonly admissionGroup?: string;\n readonly admissionFence?: AdmissionFence;\n readonly definitions: DefinitionDigests;\n}\n\nexport interface ScheduleUpdateOptions extends ScheduleCreateOptions {\n readonly expectedRevision: number;\n}\n\nexport interface ScheduleListOptions {\n readonly after?: ScheduleId | undefined;\n readonly limit?: number | undefined;\n}\n\nexport type ScheduleManagementFailure =\n | ScheduleValidationError\n | ScheduleAuthorizationError\n | ScheduleStoreFailure;\n\nexport type ScheduleProcessFailure =\n | ScheduleValidationError\n | ScheduleStoreFailure\n | ScheduleStorageError;\n\nconst equivalentDefinitions = Schema.toEquivalence(DefinitionDigests);\nconst equivalentInput = Schema.toEquivalence(PersistedJson);\n\nconst keyOf = (scope: ScheduleScope, scheduleId: ScheduleId): ScheduleKey => ({\n owner: scope.owner,\n scheduleId,\n});\n\nconst notFound = (key: ScheduleKey) => ScheduleNotFound.make({ key });\n\nconst asSnapshot = (record: ScheduleRecord, observedAtMillis: number): ScheduleSnapshot => {\n const intendedAtMillis = record.pending?.envelope.intendedAtMillis ?? record.nextAtMillis;\n\n return {\n owner: record.owner,\n scheduleId: record.scheduleId,\n createdAtMillis: record.createdAtMillis,\n updatedAtMillis: record.updatedAtMillis,\n configurationRevision: record.configurationRevision,\n configuration: {\n timing: record.configuration.timing,\n destination: record.configuration.destination,\n deliveryPrincipal: record.configuration.deliveryPrincipal,\n ...(record.configuration.admissionGroup === undefined\n ? {}\n : { admissionGroup: record.configuration.admissionGroup }),\n ...(record.configuration.admissionFence === undefined\n ? {}\n : { admissionFence: record.configuration.admissionFence }),\n agentId: record.configuration.agentId,\n },\n state: record.state,\n nextAtMillis: record.nextAtMillis,\n pending:\n record.pending === null\n ? null\n : {\n intendedAtMillis: record.pending.envelope.intendedAtMillis,\n preparedAtMillis: record.pending.envelope.preparedAtMillis,\n configurationRevision: record.pending.envelope.configurationRevision,\n occurrenceId: record.pending.envelope.occurrenceId,\n retry: record.pending.retry,\n },\n lastReceipt: record.lastReceipt,\n lastRefusal: record.lastRefusal,\n lastSkippedRange: record.lastSkippedRange,\n observedAtMillis,\n pendingAgeMillis:\n record.pending === null\n ? null\n : Math.max(0, observedAtMillis - record.pending.envelope.preparedAtMillis),\n latenessMillis:\n intendedAtMillis === null ? 0 : Math.max(0, observedAtMillis - intendedAtMillis),\n };\n};\n\nconst inputByteLength = (input: PersistedJson): number => utf8ByteLength(JSON.stringify(input));\n\nconst currentMillis = DateTime.now.pipe(Effect.map(DateTime.toEpochMillis));\n\nconst validateRequestedFields = Effect.fn(\"Scheduling.validateRequestedFields\")(function* (\n options: ScheduleCreateOptions,\n) {\n yield* Schema.encodeEffect(ScheduleTimingRequestSchema)(options.timing).pipe(\n Effect.mapError(() => ScheduleValidationError.make({ message: \"Invalid timing request\" })),\n );\n yield* Schema.encodeEffect(ScheduleDestinationSchema)(options.destination).pipe(\n Effect.mapError(() => ScheduleValidationError.make({ message: \"Invalid destination\" })),\n );\n yield* Schema.encodeEffect(DefinitionDigests)(options.definitions).pipe(\n Effect.mapError(() => ScheduleValidationError.make({ message: \"Invalid definition digests\" })),\n );\n});\n\nconst resolveInput = Effect.fn(\"Scheduling.resolveInput\")(function* <\n InputSchema extends Schema.Top,\n>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n maximumBytes: number,\n): Effect.fn.Return<\n { readonly payload: PersistedJson; readonly digest: Digest },\n ScheduleValidationError,\n InputSchema[\"EncodingServices\"] | Crypto.Crypto\n> {\n const encoded = yield* Schema.encodeEffect(agent.definition.input)(input).pipe(\n Effect.mapError(() =>\n ScheduleValidationError.make({ message: \"Unable to encode Agent input\" }),\n ),\n );\n\n const payload = yield* Schema.decodeUnknownEffect(PersistedJson)(encoded).pipe(\n Effect.mapError(() =>\n ScheduleValidationError.make({\n message: \"Agent input does not satisfy the canonical persistence bounds\",\n }),\n ),\n );\n\n if (inputByteLength(payload) > maximumBytes) {\n return yield* ScheduleValidationError.make({\n message: `Encoded Agent input exceeds the configured ${maximumBytes} byte limit`,\n });\n }\n\n const digest = yield* digestJson(payload).pipe(\n Effect.mapError(() =>\n ScheduleValidationError.make({ message: \"Unable to digest encoded Agent input\" }),\n ),\n );\n\n return { payload, digest };\n});\n\nconst makeManagement = (limits: SchedulingLimits) =>\n Effect.gen(function* () {\n const nowMillis = yield* currentMillis;\n\n yield* Schema.decodeEffect(ScheduleInstant)(nowMillis + limits.recoveryPollMillis).pipe(\n Effect.mapError(() =>\n ScheduleValidationError.make({\n message: \"Scheduling recovery deadline exceeds the supported instant range\",\n }),\n ),\n );\n const store = yield* ScheduleStore;\n const authorizer = yield* ScheduleAuthorizer;\n const wake = yield* ScheduleWake;\n const crypto = yield* Crypto.Crypto;\n\n const withCrypto = <A, E>(effect: Effect.Effect<A, E, Crypto.Crypto>) =>\n Effect.provideService(effect, Crypto.Crypto, crypto);\n\n const fingerprint = Effect.fn(\"Scheduling.fingerprint\")(function* (\n agentId: AgentId,\n inputDigest: Digest,\n options: ScheduleCreateOptions,\n ) {\n const timing = yield* Schema.encodeEffect(ScheduleTimingRequestSchema)(options.timing).pipe(\n Effect.mapError(() => ScheduleValidationError.make({ message: \"Invalid timing request\" })),\n );\n\n const destination = yield* Schema.encodeEffect(ScheduleDestinationSchema)(\n options.destination,\n ).pipe(\n Effect.mapError(() => ScheduleValidationError.make({ message: \"Invalid destination\" })),\n );\n\n const definitions = yield* Schema.encodeEffect(DefinitionDigests)(options.definitions).pipe(\n Effect.mapError(() =>\n ScheduleValidationError.make({ message: \"Invalid definition digests\" }),\n ),\n );\n\n return yield* withCrypto(\n digestJson({\n schemaVersion: 1,\n owner: options.scope.owner,\n scheduleId: options.scheduleId,\n registeringPrincipal: options.scope.principal,\n deliveryPrincipal: options.deliveryPrincipal,\n ...(options.admissionGroup === undefined\n ? {}\n : { admissionGroup: options.admissionGroup }),\n ...(options.admissionFence === undefined\n ? {}\n : { admissionFence: options.admissionFence }),\n agentId,\n definitions,\n destination,\n timing,\n inputDigest,\n }),\n ).pipe(\n Effect.mapError(() =>\n ScheduleValidationError.make({ message: \"Unable to digest Schedule registration\" }),\n ),\n );\n });\n\n const configuration = (\n agentId: AgentId,\n payload: PersistedJson,\n inputDigest: Digest,\n options: ScheduleCreateOptions,\n timing: ScheduleConfiguration[\"timing\"],\n ): ScheduleConfiguration => ({\n timing,\n destination: options.destination,\n deliveryPrincipal: options.deliveryPrincipal,\n ...(options.admissionGroup === undefined ? {} : { admissionGroup: options.admissionGroup }),\n ...(options.admissionFence === undefined ? {} : { admissionFence: options.admissionFence }),\n agentId,\n definitions: options.definitions,\n input: payload,\n inputDigest,\n });\n\n const create = Effect.fn(\"Scheduling.create\")(function* <InputSchema extends Schema.Top>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n options: ScheduleCreateOptions,\n ): Effect.fn.Return<\n ScheduleSnapshot,\n ScheduleManagementFailure,\n InputSchema[\"EncodingServices\"]\n > {\n const nowMillis = yield* currentMillis;\n\n const resolvedInput = yield* resolveInput(agent, input, limits.maxInputBytes).pipe(\n Effect.provideService(Crypto.Crypto, crypto),\n );\n\n const creationFingerprint = yield* fingerprint(\n agent.definition.id,\n resolvedInput.digest,\n options,\n );\n\n const key = keyOf(options.scope, options.scheduleId);\n\n yield* authorizer.manage({\n operation: \"create\",\n scope: options.scope,\n scheduleId: options.scheduleId,\n });\n const existing = yield* store.get(key);\n\n if (existing !== null) {\n if (existing.creationFingerprint !== creationFingerprint) {\n return yield* ScheduleConflict.make({ reason: \"creation\", key });\n }\n yield* authorizer.manage({\n operation: \"create\",\n scope: options.scope,\n scheduleId: options.scheduleId,\n configuration: existing.configuration,\n });\n\n return asSnapshot(existing, nowMillis);\n }\n\n const timing = yield* Effect.fromResult(\n normalizeScheduleTiming(options.timing, nowMillis, limits.minIntervalMillis),\n );\n\n const nextAtMillis = yield* Effect.fromResult(scheduleInitialCursor(timing, nowMillis));\n\n if (nextAtMillis === null) {\n return yield* ScheduleValidationError.make({ message: \"Timing has no next occurrence\" });\n }\n\n const nextConfiguration = configuration(\n agent.definition.id,\n resolvedInput.payload,\n resolvedInput.digest,\n options,\n timing,\n );\n\n yield* authorizer.manage({\n operation: \"create\",\n scope: options.scope,\n scheduleId: options.scheduleId,\n configuration: nextConfiguration,\n });\n\n const record: ScheduleRecord = {\n schemaVersion: 1,\n owner: options.scope.owner,\n scheduleId: options.scheduleId,\n creationFingerprint,\n createdBy: options.scope.principal,\n createdAtMillis: nowMillis,\n updatedAtMillis: nowMillis,\n configurationRevision: 1,\n version: 1,\n configuration: nextConfiguration,\n state: \"active\",\n nextAtMillis,\n pending: null,\n lastReceipt: null,\n lastRefusal: null,\n lastSkippedRange: null,\n };\n\n const inserted = yield* store.insert(record, limits.maxSchedulesPerOwner);\n\n yield* wake.notify;\n\n return asSnapshot(inserted, nowMillis);\n });\n\n const update = Effect.fn(\"Scheduling.update\")(function* <InputSchema extends Schema.Top>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n options: ScheduleUpdateOptions,\n ): Effect.fn.Return<\n ScheduleSnapshot,\n ScheduleManagementFailure,\n InputSchema[\"EncodingServices\"]\n > {\n const nowMillis = yield* currentMillis;\n const key = keyOf(options.scope, options.scheduleId);\n\n yield* authorizer.manage({\n operation: \"update\",\n scope: options.scope,\n scheduleId: options.scheduleId,\n });\n yield* validateRequestedFields(options);\n const existing = yield* store.get(key);\n\n if (existing === null) return yield* notFound(key);\n if (existing.configurationRevision !== options.expectedRevision) {\n return yield* ScheduleConflict.make({ reason: \"revision\", key });\n }\n\n const resolvedInput = yield* resolveInput(agent, input, limits.maxInputBytes).pipe(\n Effect.provideService(Crypto.Crypto, crypto),\n );\n\n const timingRequest =\n options.timing._tag === \"Interval\" &&\n options.timing.anchorMillis === undefined &&\n existing.configuration.timing._tag === \"Interval\" &&\n existing.configuration.timing.everyMillis === options.timing.everyMillis\n ? { ...options.timing, anchorMillis: existing.configuration.timing.anchorMillis }\n : options.timing;\n\n const timing = yield* Effect.fromResult(\n normalizeScheduleTiming(timingRequest, nowMillis, limits.minIntervalMillis),\n );\n\n const nextAtMillis =\n timing._tag === \"At\"\n ? timing.atMillis\n : yield* Effect.fromResult(scheduleNextAfter(timing, nowMillis));\n\n if (nextAtMillis === null) {\n return yield* ScheduleValidationError.make({ message: \"Timing has no next occurrence\" });\n }\n\n const nextConfiguration = configuration(\n agent.definition.id,\n resolvedInput.payload,\n resolvedInput.digest,\n options,\n timing,\n );\n\n yield* authorizer.manage({\n operation: \"update\",\n scope: options.scope,\n scheduleId: options.scheduleId,\n configuration: nextConfiguration,\n });\n\n const changed = yield* store.change(\n key,\n {\n _tag: \"Update\",\n expectedRevision: options.expectedRevision,\n configuration: nextConfiguration,\n nextAtMillis,\n nowMillis,\n },\n limits.maxSchedulesPerOwner,\n );\n\n yield* wake.notify;\n\n return asSnapshot(changed, nowMillis);\n });\n\n const get = Effect.fn(\"Scheduling.get\")(function* (\n scope: ScheduleScope,\n scheduleId: ScheduleId,\n ) {\n yield* authorizer.manage({ operation: \"get\", scope, scheduleId });\n const key = keyOf(scope, scheduleId);\n const record = yield* store.get(key);\n\n if (record === null) return yield* notFound(key);\n\n return asSnapshot(record, yield* currentMillis);\n });\n\n const list = Effect.fn(\"Scheduling.list\")(function* (\n scope: ScheduleScope,\n options: ScheduleListOptions = {},\n ) {\n yield* authorizer.manage({ operation: \"list\", scope });\n const limit = options.limit ?? 50;\n\n if (!Number.isInteger(limit) || limit < 1 || limit > 100) {\n return yield* ScheduleValidationError.make({\n message: \"Schedule page limit must be an integer from 1 through 100\",\n });\n }\n\n const page = yield* store.list({\n owner: scope.owner,\n ...(options.after === undefined ? {} : { after: options.after }),\n limit,\n });\n\n const nowMillis = yield* currentMillis;\n\n return { items: page.items.map((record) => asSnapshot(record, nowMillis)), next: page.next };\n });\n\n const control = Effect.fn(\"Scheduling.control\")(function* (\n operation: \"pause\" | \"resume\" | \"cancel\",\n scope: ScheduleScope,\n scheduleId: ScheduleId,\n expectedRevision: number,\n ): Effect.fn.Return<ScheduleSnapshot, ScheduleManagementFailure> {\n yield* authorizer.manage({ operation, scope, scheduleId });\n const key = keyOf(scope, scheduleId);\n\n const attempt = (): Effect.Effect<ScheduleRecord, ScheduleManagementFailure> =>\n Effect.suspend(() =>\n Effect.gen(function* () {\n const record = yield* store.get(key);\n\n if (record === null) return yield* notFound(key);\n if (record.configurationRevision !== expectedRevision) {\n return yield* ScheduleConflict.make({ reason: \"revision\", key });\n }\n if (operation === \"resume\" && record.state === \"active\") return record;\n const nowMillis = yield* currentMillis;\n\n const nextAtMillis =\n operation === \"resume\"\n ? yield* Effect.fromResult(\n scheduleResumeCursor(\n record.configuration.timing,\n record.nextAtMillis,\n nowMillis,\n ),\n )\n : operation === \"cancel\"\n ? null\n : record.nextAtMillis;\n\n const skippedRange =\n operation === \"resume\" &&\n record.configuration.timing._tag !== \"At\" &&\n record.nextAtMillis !== null &&\n nextAtMillis !== null &&\n nextAtMillis > record.nextAtMillis\n ? { fromMillis: record.nextAtMillis, toMillis: nextAtMillis }\n : null;\n\n return yield* store\n .change(\n key,\n {\n _tag: \"Control\",\n expectedRevision,\n expectedVersion: record.version,\n action: operation,\n nextAtMillis,\n nowMillis,\n skippedRange,\n },\n limits.maxSchedulesPerOwner,\n )\n .pipe(\n Effect.catchTag(\"ScheduleConflict\", (error) =>\n error.reason === \"revision\" ? attempt() : Effect.fail(error),\n ),\n );\n }),\n );\n\n const changed = yield* attempt();\n\n yield* wake.notify;\n\n return asSnapshot(changed, yield* currentMillis);\n });\n\n const recover = Effect.fn(\"Scheduling.recover\")(function* (\n scope: ScheduleScope,\n scheduleId: ScheduleId,\n expectedRevision: number,\n expectedGeneration: number,\n ) {\n yield* authorizer.manage({ operation: \"recover\", scope, scheduleId });\n const key = keyOf(scope, scheduleId);\n const record = yield* store.get(key);\n\n if (record === null) return yield* notFound(key);\n if (record.configurationRevision !== expectedRevision)\n return yield* ScheduleConflict.make({ reason: \"revision\", key });\n const time = yield* currentMillis;\n\n if (record.pending === null) return asSnapshot(record, time);\n\n const recovered = yield* store.change(key, {\n _tag: \"Recover\",\n expectedGeneration,\n expectedRevision,\n occurrenceId: record.pending.envelope.occurrenceId,\n nowMillis: time,\n });\n\n yield* wake.notify;\n\n return asSnapshot(recovered, time);\n });\n\n return Scheduling.of({\n recover,\n create,\n update,\n get,\n list,\n pause: (scope, id, revision) => control(\"pause\", scope, id, revision),\n resume: (scope, id, revision) => control(\"resume\", scope, id, revision),\n cancel: (scope, id, revision) => control(\"cancel\", scope, id, revision),\n });\n });\n\nconst makeDriver = (limits: SchedulingLimits) =>\n Effect.gen(function* () {\n const store = yield* ScheduleStore;\n const authorizer = yield* ScheduleAuthorizer;\n const admission = yield* ScheduledInputAdmission;\n const failpoint = yield* ScheduleFailpoint;\n const crypto = yield* Crypto.Crypto;\n const admissionSemaphore = yield* Semaphore.make(limits.admissionConcurrency);\n\n const withCrypto = <A, E>(effect: Effect.Effect<A, E, Crypto.Crypto>) =>\n Effect.provideService(effect, Crypto.Crypto, crypto);\n\n const retry = Effect.fn(\"Scheduling.retry\")(function* (\n key: ScheduleKey,\n record: ScheduleRecord,\n reason: ScheduleRetryReason,\n nowMillis: number,\n ) {\n if (record.pending === null) return record;\n const current = record.pending.retry;\n\n const delay = Math.min(\n limits.retryBaseMillis * 2 ** Math.min(current.attempts, 52),\n limits.retryMaxMillis,\n );\n\n return yield* store.change(key, {\n _tag: \"Retry\",\n occurrenceId: record.pending.envelope.occurrenceId,\n retry: {\n generation: current.generation,\n attempts: current.attempts + 1,\n automaticAttempts: current.automaticAttempts + 1,\n parked: current.automaticAttempts + 1 >= (limits.maxAutomaticAttempts ?? 8),\n nextAttemptAtMillis: Math.min(nowMillis + delay, 8_640_000_000_000_000),\n lastAttemptAtMillis: nowMillis,\n lastFailure: reason,\n },\n nowMillis,\n });\n });\n\n const verifyPending = Effect.fn(\"Scheduling.verifyPending\")(function* (\n key: ScheduleKey,\n record: ScheduleRecord,\n ) {\n const pending = record.pending;\n\n if (pending === null) return;\n const envelope = pending.envelope;\n\n const occurrenceId = yield* withCrypto(\n digestJson({\n schemaVersion: 1,\n owner: envelope.owner,\n scheduleId: envelope.scheduleId,\n configurationRevision: envelope.configurationRevision,\n intendedAtMillis: envelope.intendedAtMillis,\n }),\n ).pipe(Effect.mapError(() => corrupt(\"process\")));\n\n const usesCurrentConfiguration =\n envelope.configurationRevision === record.configurationRevision;\n\n const expectedThreadId = usesCurrentConfiguration\n ? record.configuration.destination._tag === \"ExistingThread\"\n ? record.configuration.destination.threadId\n : Schema.decodeSync(ThreadId)(`schedule-thread:${envelope.occurrenceId}`)\n : null;\n\n const expectedAdmissionKey = Schema.decodeSync(IdempotencyKey)(\n `schedule-occurrence:${envelope.occurrenceId}`,\n );\n\n const digest = yield* withCrypto(digestJson(envelope.input)).pipe(\n Effect.mapError(() => corrupt(\"process\")),\n );\n\n if (\n envelope.schemaVersion !== 1 ||\n envelope.owner.tenantId !== key.owner.tenantId ||\n envelope.owner.ownerId !== key.owner.ownerId ||\n envelope.scheduleId !== key.scheduleId ||\n envelope.configurationRevision > record.configurationRevision ||\n envelope.occurrenceId !== occurrenceId ||\n (usesCurrentConfiguration &&\n (envelope.deliveryPrincipal !== record.configuration.deliveryPrincipal ||\n envelope.agentId !== record.configuration.agentId ||\n !equivalentDefinitions(envelope.definitions, record.configuration.definitions) ||\n !equivalentInput(envelope.input, record.configuration.input) ||\n envelope.inputDigest !== record.configuration.inputDigest)) ||\n envelope.inputDigest !== digest ||\n (expectedThreadId !== null && envelope.threadId !== expectedThreadId) ||\n envelope.admissionKey !== expectedAdmissionKey\n ) {\n return yield* corrupt(\"process\");\n }\n });\n\n const deliverPending = Effect.fn(\"Scheduling.deliverPending\")(function* (\n key: ScheduleKey,\n record: ScheduleRecord,\n nowMillis: number,\n ) {\n if (\n record.pending === null ||\n record.pending.retry.parked === true ||\n record.pending.retry.nextAttemptAtMillis > nowMillis\n ) {\n return record;\n }\n yield* verifyPending(key, record);\n const envelope = record.pending.envelope;\n\n const outcome = yield* admissionSemaphore.withPermit(\n admitPreparedInput(admission.submit(envelope), limits.admissionTimeoutMillis).pipe(\n Effect.tap((outcome) =>\n outcome._tag === \"Receipt\" ? failpoint.hit(\"schedule:admission:after\") : Effect.void,\n ),\n ),\n );\n\n const completedAtMillis = yield* currentMillis;\n\n if (outcome._tag === \"Receipt\") {\n if (outcome.receipt.threadId !== envelope.threadId) {\n return yield* corrupt(\"admission\");\n }\n\n return yield* store\n .change(key, {\n _tag: \"Complete\",\n occurrenceId: envelope.occurrenceId,\n receipt: outcome.receipt,\n nowMillis: completedAtMillis,\n })\n .pipe(\n Effect.catchTag(\"ScheduleStorageError\", (error) =>\n error.reason === \"unavailable\"\n ? retry(key, record, \"storage\", completedAtMillis)\n : Effect.fail(error),\n ),\n );\n }\n if (outcome._tag === \"Refused\") {\n const refusal: ScheduleRefusal = {\n atMillis: completedAtMillis,\n intendedAtMillis: envelope.intendedAtMillis,\n occurrenceId: envelope.occurrenceId,\n phase: \"admission\",\n code: outcome.error.code,\n };\n\n return yield* store\n .change(key, {\n _tag: \"Refuse\",\n occurrenceId: envelope.occurrenceId,\n refusal,\n nowMillis: completedAtMillis,\n })\n .pipe(\n Effect.catchTag(\"ScheduleStorageError\", (error) =>\n error.reason === \"unavailable\"\n ? retry(key, record, \"storage\", completedAtMillis)\n : Effect.fail(error),\n ),\n );\n }\n\n return yield* retry(key, record, outcome.reason, completedAtMillis);\n });\n\n const processRecord = Effect.fn(\"Scheduling.processRecord\")(function* (\n key: ScheduleKey,\n initial: ScheduleRecord,\n nowMillis: number,\n ): Effect.fn.Return<ScheduleRecord, ScheduleProcessFailure> {\n if (initial.pending !== null) return yield* deliverPending(key, initial, nowMillis);\n if (\n initial.state !== \"active\" ||\n initial.nextAtMillis === null ||\n initial.nextAtMillis > nowMillis\n ) {\n return initial;\n }\n\n const currentInputDigest = yield* withCrypto(digestJson(initial.configuration.input)).pipe(\n Effect.mapError(() =>\n ScheduleStorageError.make({ operation: \"prepare\", reason: \"unavailable\" }),\n ),\n );\n\n if (currentInputDigest !== initial.configuration.inputDigest) {\n return yield* corrupt(\"prepare\");\n }\n\n const due = yield* Effect.fromResult(\n scheduleDueOccurrence(initial.configuration.timing, initial.nextAtMillis, nowMillis),\n );\n\n if (due === null) return initial;\n\n const occurrenceId = yield* withCrypto(\n digestJson({\n schemaVersion: 1,\n owner: initial.owner,\n scheduleId: initial.scheduleId,\n configurationRevision: initial.configurationRevision,\n intendedAtMillis: due.intendedAtMillis,\n }),\n ).pipe(Effect.mapError(() => corrupt(\"prepare\")));\n\n const occurrence = {\n key,\n configurationRevision: initial.configurationRevision,\n configuration: initial.configuration,\n intendedAtMillis: due.intendedAtMillis,\n occurrenceId,\n };\n\n const authorization = yield* authorizer.prepare(occurrence).pipe(Effect.result);\n\n if (Result.isFailure(authorization)) {\n if (authorization.failure._tag === \"ScheduleStorageError\") {\n return yield* authorization.failure;\n }\n\n return yield* store.change(key, {\n _tag: \"DenyPreparation\",\n expectedRevision: initial.configurationRevision,\n expectedCursor: initial.nextAtMillis,\n refusal: {\n atMillis: nowMillis,\n intendedAtMillis: due.intendedAtMillis,\n occurrenceId,\n phase: \"preparation\",\n code: authorization.failure.code,\n },\n nowMillis,\n });\n }\n\n const threadId =\n initial.configuration.destination._tag === \"ExistingThread\"\n ? initial.configuration.destination.threadId\n : Schema.decodeSync(ThreadId)(`schedule-thread:${occurrenceId}`);\n\n const admissionKey = Schema.decodeSync(IdempotencyKey)(`schedule-occurrence:${occurrenceId}`);\n\n const prepared = yield* store.change(key, {\n _tag: \"Prepare\",\n expectedRevision: initial.configurationRevision,\n expectedCursor: initial.nextAtMillis,\n envelope: {\n schemaVersion: 1,\n owner: initial.owner,\n scheduleId: initial.scheduleId,\n configurationRevision: initial.configurationRevision,\n intendedAtMillis: due.intendedAtMillis,\n preparedAtMillis: nowMillis,\n occurrenceId,\n threadId,\n deliveryPrincipal: initial.configuration.deliveryPrincipal,\n ...(initial.configuration.admissionGroup === undefined\n ? {}\n : { admissionGroup: initial.configuration.admissionGroup }),\n ...(initial.configuration.admissionFence === undefined\n ? {}\n : { admissionFence: initial.configuration.admissionFence }),\n agentId: initial.configuration.agentId,\n definitions: initial.configuration.definitions,\n input: initial.configuration.input,\n inputDigest: initial.configuration.inputDigest,\n admissionKey,\n authorization: authorization.success,\n },\n nextAtMillis: due.nextAtMillis,\n skippedRange: due.skippedRange,\n nowMillis,\n });\n\n return yield* deliverPending(key, prepared, nowMillis);\n });\n\n const process = Effect.fn(\"Scheduling.process\")(function* (key: ScheduleKey) {\n const nowMillis = yield* currentMillis;\n const record = yield* store.get(key);\n\n if (record === null) return yield* notFound(key);\n\n const processed = yield* processRecord(key, record, nowMillis).pipe(\n Effect.catchTag(\"ScheduleConflict\", () =>\n store\n .get(key)\n .pipe(\n Effect.flatMap((current) =>\n current === null\n ? Effect.fail(notFound(key))\n : processRecord(key, current, nowMillis),\n ),\n ),\n ),\n );\n\n return processed;\n });\n\n const runDue = Effect.fn(\"ScheduleDriver.runDue\")(function* (owner?: ScheduleOwner) {\n const nowMillis = yield* currentMillis;\n let after: ScheduleDueCursor | undefined;\n let processed = 0;\n let failed = 0;\n\n while (true) {\n const due = yield* store.due(nowMillis, limits.dueBatchSize, owner, after);\n\n if (due.length === 0) break;\n yield* Effect.forEach(\n due,\n (key) =>\n process(key).pipe(\n Effect.matchCauseEffect({\n onSuccess: () =>\n Effect.sync(() => {\n processed += 1;\n }),\n onFailure: (cause) =>\n Cause.hasInterrupts(cause)\n ? Effect.interrupt\n : Effect.gen(function* () {\n failed += 1;\n yield* Effect.logWarning(\"Schedule processing failed\").pipe(\n Effect.annotateLogs({\n failureTag: Option.match(Cause.findErrorOption(cause), {\n onNone: () => \"Defect\",\n onSome: (error) => error._tag,\n }),\n }),\n );\n }),\n }),\n ),\n { concurrency: limits.admissionConcurrency },\n );\n after = due.at(-1);\n if (due.length < limits.dueBatchSize) break;\n }\n\n return { processed, failed };\n });\n\n return ScheduleDriver.of({ process, runDue });\n });\n\nconst corrupt = (operation: string): ScheduleStorageError =>\n ScheduleStorageError.make({ operation, reason: \"corrupt\" });\n\nconst validateLimits = (limits: SchedulingLimits) =>\n Schema.decodeEffect(SchedulingLimits)(limits).pipe(\n Effect.mapError((error) =>\n ScheduleValidationError.make({ message: `Invalid Scheduling limits: ${error.message}` }),\n ),\n Effect.filterOrFail(\n (validated) => validated.retryBaseMillis <= validated.retryMaxMillis,\n () =>\n ScheduleValidationError.make({\n message: \"Scheduling retryBaseMillis must not exceed retryMaxMillis\",\n }),\n ),\n );\n\nexport class Scheduling extends Context.Service<\n Scheduling,\n {\n readonly create: <InputSchema extends Schema.Top>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n options: ScheduleCreateOptions,\n ) => Effect.Effect<\n ScheduleSnapshot,\n ScheduleManagementFailure,\n InputSchema[\"EncodingServices\"]\n >;\n readonly update: <InputSchema extends Schema.Top>(\n agent: DurableSubmitAgent<InputSchema>,\n input: InputSchema[\"Type\"],\n options: ScheduleUpdateOptions,\n ) => Effect.Effect<\n ScheduleSnapshot,\n ScheduleManagementFailure,\n InputSchema[\"EncodingServices\"]\n >;\n readonly get: (\n scope: ScheduleScope,\n scheduleId: ScheduleId,\n ) => Effect.Effect<ScheduleSnapshot, ScheduleManagementFailure>;\n readonly list: (\n scope: ScheduleScope,\n options?: ScheduleListOptions,\n ) => Effect.Effect<ScheduleSnapshotPage, ScheduleManagementFailure>;\n readonly pause: (\n scope: ScheduleScope,\n scheduleId: ScheduleId,\n expectedRevision: number,\n ) => Effect.Effect<ScheduleSnapshot, ScheduleManagementFailure>;\n readonly resume: (\n scope: ScheduleScope,\n scheduleId: ScheduleId,\n expectedRevision: number,\n ) => Effect.Effect<ScheduleSnapshot, ScheduleManagementFailure>;\n readonly recover: (\n scope: ScheduleScope,\n scheduleId: ScheduleId,\n expectedRevision: number,\n expectedGeneration: number,\n ) => Effect.Effect<ScheduleSnapshot, ScheduleManagementFailure>;\n readonly cancel: (\n scope: ScheduleScope,\n scheduleId: ScheduleId,\n expectedRevision: number,\n ) => Effect.Effect<ScheduleSnapshot, ScheduleManagementFailure>;\n }\n>()(\"@effect-agent/thread/Scheduling\") {\n static layer(\n limits: SchedulingLimits = defaultSchedulingLimits,\n ): Layer.Layer<\n Scheduling,\n ScheduleValidationError,\n ScheduleStore | ScheduleAuthorizer | ScheduleWake | Crypto.Crypto\n > {\n return Layer.effect(Scheduling, validateLimits(limits).pipe(Effect.flatMap(makeManagement)));\n }\n}\n\nexport const ScheduleWakeNoop: Layer.Layer<ScheduleWake> = Layer.succeed(ScheduleWake, {\n notify: Effect.void,\n await: Effect.never,\n});\n\n/** Privileged host capability. Never provide this service to management callers or model tools. */\nexport class ScheduleDriver extends Context.Service<\n ScheduleDriver,\n {\n readonly process: (key: ScheduleKey) => Effect.Effect<ScheduleRecord, ScheduleProcessFailure>;\n readonly runDue: (\n owner?: ScheduleOwner,\n ) => Effect.Effect<\n { readonly processed: number; readonly failed: number },\n ScheduleStorageError\n >;\n }\n>()(\"@effect-agent/thread/ScheduleDriver\") {\n static layer(\n limits: SchedulingLimits = defaultSchedulingLimits,\n ): Layer.Layer<\n ScheduleDriver,\n ScheduleValidationError,\n ScheduleStore | ScheduleAuthorizer | ScheduledInputAdmission | Crypto.Crypto\n > {\n return Layer.effect(ScheduleDriver, validateLimits(limits).pipe(Effect.flatMap(makeDriver)));\n }\n}\n"],"mappings":";;;;;;;;;;AAUA,MAAM,WAAW,YAAoB,OAAO,KAAK,wBAAwB,KAAK,EAAE,QAAQ,CAAC,CAAC;AAE1F,MAAM,kBAAkB,QAAgB,UACtC,OAAO,aAAa,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC,KAC3C,OAAO,eACL,wBAAwB,KAAK,EAC3B,SAAS,GAAG,MAAM,iDACpB,CAAC,CACH,CACF;AAEF,MAAM,UAAU,K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QAAQ;AAAU,CAAC;AAE5D,MAAM,kBAAkB,WACtB,OAAO,aAAa,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC,KAC5C,OAAO,UAAU,UACf,wBAAwB,KAAK,EAAE,SAAS,8BAA8B,MAAM,UAAU,CAAC,CACzF,GACA,OAAO,cACJ,cAAc,UAAU,mBAAmB,UAAU,sBAEpD,wBAAwB,KAAK,EAC3B,SAAS,4DACX,CAAC,CACL,CACF;AAEF,IAAa,aAAb,MAAa,mBAAmB,QAAQ,QAmDtC,CAAC,CAAC,iCAAiC,CAAC,CAAC;CACrC,OAAO,MACL,SAA2B,yBAK3B;EACA,OAAO,MAAM,OAAO,YAAY,eAAe,MAAM,CAAC,CAAC,KAAK,OAAO,QAAQ,cAAc,CAAC,CAAC;CAC7F;AACF;AAEA,MAAa,mBAA8C,MAAM,QAAQ,cAAc;CACrF,QAAQ,OAAO;CACf,OAAO,OAAO;AAChB,CAAC;;AAGD,IAAa,iBAAb,MAAa,uBAAuB,QAAQ,QAW1C,CAAC,CAAC,qCAAqC,CAAC,CAAC;CACzC,OAAO,MACL,SAA2B,yBAK3B;EACA,OAAO,MAAM,OAAO,gBAAgB,eAAe,MAAM,CAAC,CAAC,KAAK,OAAO,QAAQ,UAAU,CAAC,CAAC;CAC7F;AACF"}
@@ -8,7 +8,7 @@ import { BackgroundSpawnTool, DelegationTool, SubagentBudgetReservation, Subagen
8
8
  import { RunUsageReport, unknownRunTotals } from "./core/Usage.mjs";
9
9
  import { WorkerCompletion, WorkerContext, WorkerError, WorkerPage, WorkerRef, WorkerReport, WorkerStarted, WorkerSummary } from "./core/Worker.mjs";
10
10
  import { BackgroundReporting, SubagentHost, WorkerReportPreparationFailure } from "./engine/SubagentHost.mjs";
11
- import { a as SubagentDurability, i as AgentSpawner, o as SubagentDurabilityError, s as ToolCallWaiting } from "./AgentRuntime-Cdvqw7l_.mjs";
11
+ import { a as SubagentDurability, i as AgentSpawner, o as SubagentDurabilityError, s as ToolCallWaiting } from "./AgentRuntime-BWOnNc0d.mjs";
12
12
  import { RunEventSink } from "./engine/RunEventSink.mjs";
13
13
  import { SubagentBudgetExhausted, SubagentObservedUsage, SubagentReservationRequest, SubagentReservations, makeBudgetReservationId } from "./capabilities/SubagentReservations.mjs";
14
14
  import { t as utf8Bytes } from "./utf8-BYfhEkcj.mjs";
@@ -1466,4 +1466,4 @@ function background(targetOrDeclaration, selected) {
1466
1466
  //#endregion
1467
1467
  export { delegationCapsFromPolicy as C, delegationAllocationFromPolicy as S, reporting as _, define as a, SubagentPrestartDenied as b, Worker as c, cancel as d, followUp as f, start as g, observe as h, background as i, WorkerObservation as l, list as m, SubagentResult as n, layer as o, inspect as p, Subagent_exports as r, make as s, SubagentDurableAccounting as t, awaitWorker as u, reportingToWorker as v, SubagentProjectionFailure as x, SubagentPolicy as y };
1468
1468
 
1469
- //# sourceMappingURL=Subagent-Cbfzylz1.mjs.map
1469
+ //# sourceMappingURL=Subagent-C2s8PFrd.mjs.map