@yielded/agent-platform-cloudflare 0.1.0-beta.185 → 0.1.0-beta.187

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 (128) hide show
  1. package/dist/{Alarm-C257DCAJ.mjs → Alarm-4qf-iCXC.mjs} +94 -54
  2. package/dist/Alarm-4qf-iCXC.mjs.map +1 -0
  3. package/dist/Alarm.d.mts +16 -9
  4. package/dist/Alarm.mjs +1 -1
  5. package/dist/{BrowserCredentials-C2rBhlUI.d.mts → BrowserCredentials-CysbK6UA.d.mts} +4 -2
  6. package/dist/BrowserCredentials.d.mts +1 -1
  7. package/dist/BrowserCredentials.mjs +2 -1
  8. package/dist/BrowserCredentials.mjs.map +1 -1
  9. package/dist/BrowserRestCapture.d.mts +4 -3
  10. package/dist/BrowserRestCapture.mjs +9 -3
  11. package/dist/BrowserRestCapture.mjs.map +1 -1
  12. package/dist/BrowserRestCrawl.d.mts +3 -2
  13. package/dist/BrowserRestCrawl.mjs +12 -2
  14. package/dist/BrowserRestCrawl.mjs.map +1 -1
  15. package/dist/{BrowserSession-mKnLSc3p.d.mts → BrowserSession-BLEG79zz.d.mts} +12 -5
  16. package/dist/{BrowserSession-CfivQ5JY.mjs → BrowserSession-CITvpByq.mjs} +17 -5
  17. package/dist/BrowserSession-CITvpByq.mjs.map +1 -0
  18. package/dist/BrowserSession.d.mts +2 -2
  19. package/dist/BrowserSession.mjs +2 -2
  20. package/dist/BrowserUse.d.mts +4 -2
  21. package/dist/BrowserUse.mjs +6 -2
  22. package/dist/BrowserUse.mjs.map +1 -1
  23. package/dist/CloudflareAiGateway.d.mts +3 -2
  24. package/dist/CloudflareAiGateway.mjs +12 -2
  25. package/dist/CloudflareAiGateway.mjs.map +1 -1
  26. package/dist/CloudflareBindings.d.mts +4 -1
  27. package/dist/CloudflareBindings.mjs +5 -1
  28. package/dist/CloudflareBindings.mjs.map +1 -1
  29. package/dist/{CloudflareBrowser-gu7gma0Y.d.mts → CloudflareBrowser-CZoXu_oS.d.mts} +5 -2
  30. package/dist/{CloudflareBrowser-Vt8qTdYW.mjs → CloudflareBrowser-Wfs-zRuk.mjs} +6 -2
  31. package/dist/CloudflareBrowser-Wfs-zRuk.mjs.map +1 -0
  32. package/dist/CloudflareBrowser.d.mts +1 -1
  33. package/dist/CloudflareBrowser.mjs +1 -1
  34. package/dist/CloudflareCodeMode.d.mts +2 -1
  35. package/dist/CloudflareCodeMode.mjs +10 -2
  36. package/dist/CloudflareCodeMode.mjs.map +1 -1
  37. package/dist/{CloudflareConfig-C9MvPbX8.d.mts → CloudflareConfig-D_-BMp4q.d.mts} +12 -6
  38. package/dist/CloudflareConfig.d.mts +2 -2
  39. package/dist/CloudflareConfig.mjs +12 -5
  40. package/dist/CloudflareConfig.mjs.map +1 -1
  41. package/dist/CloudflareMemory.d.mts +3 -1
  42. package/dist/CloudflareMemory.mjs +5 -1
  43. package/dist/CloudflareMemory.mjs.map +1 -1
  44. package/dist/CloudflareScheduling.d.mts +4 -1
  45. package/dist/CloudflareScheduling.mjs +9 -4
  46. package/dist/CloudflareScheduling.mjs.map +1 -1
  47. package/dist/CloudflareSubscriptions.d.mts +6 -1
  48. package/dist/CloudflareSubscriptions.mjs +10 -4
  49. package/dist/CloudflareSubscriptions.mjs.map +1 -1
  50. package/dist/{CloudflareThreadClient-CnvMXPmV.mjs → CloudflareThreadClient-DiV2xHn0.mjs} +16 -135
  51. package/dist/CloudflareThreadClient-DiV2xHn0.mjs.map +1 -0
  52. package/dist/CloudflareThreadClient.d.mts +2144 -2
  53. package/dist/CloudflareThreadClient.mjs +2 -1
  54. package/dist/{InteractiveBrowser-nukKxc87.mjs → InteractiveBrowser-Bh9wisQI.mjs} +18 -5
  55. package/dist/InteractiveBrowser-Bh9wisQI.mjs.map +1 -0
  56. package/dist/{InteractiveBrowser-wV2Bti5e.d.mts → InteractiveBrowser-DbYpKPA3.d.mts} +8 -3
  57. package/dist/InteractiveBrowser.d.mts +1 -1
  58. package/dist/InteractiveBrowser.mjs +1 -1
  59. package/dist/LiveText-D7WxSY-h.d.mts +96 -0
  60. package/dist/LiveText-DRzUabZi.mjs +151 -0
  61. package/dist/LiveText-DRzUabZi.mjs.map +1 -0
  62. package/dist/LiveText.d.mts +2 -0
  63. package/dist/LiveText.mjs +2 -0
  64. package/dist/{ThreadObject-Osn-FmcF.d.mts → ThreadObject-BcoRabnQ.d.mts} +27 -11
  65. package/dist/{ThreadObject-Cr1CFWXb.mjs → ThreadObject-EChaDQBT.mjs} +47 -18
  66. package/dist/ThreadObject-EChaDQBT.mjs.map +1 -0
  67. package/dist/ThreadObject.d.mts +1 -1
  68. package/dist/ThreadObject.mjs +1 -1
  69. package/dist/WakeScheduler.d.mts +1 -1
  70. package/dist/WakeScheduler.mjs +7 -3
  71. package/dist/WakeScheduler.mjs.map +1 -1
  72. package/dist/{boundary-BguazVkh.mjs → boundary-BLbZMBl2.mjs} +2 -2
  73. package/dist/boundary-BLbZMBl2.mjs.map +1 -0
  74. package/dist/{browser-failure-DECzRY3H.mjs → browser-failure-BrL9H7IG.mjs} +6 -2
  75. package/dist/browser-failure-BrL9H7IG.mjs.map +1 -0
  76. package/dist/index.d.mts +8 -7
  77. package/dist/index.mjs +7 -6
  78. package/dist/{prepared-admission-w2Kq32_k.mjs → prepared-admission-mGUYbSH_.mjs} +4 -3
  79. package/dist/prepared-admission-mGUYbSH_.mjs.map +1 -0
  80. package/package.json +1 -1
  81. package/src/Alarm.ts +128 -82
  82. package/src/BrowserCredentials.ts +3 -1
  83. package/src/BrowserRestCapture.ts +9 -2
  84. package/src/BrowserRestCrawl.ts +14 -18
  85. package/src/BrowserSession.ts +10 -12
  86. package/src/BrowserUse.ts +5 -1
  87. package/src/CloudflareAiGateway.ts +12 -8
  88. package/src/CloudflareBindings.ts +5 -1
  89. package/src/CloudflareCodeMode.ts +9 -1
  90. package/src/CloudflareConfig.ts +10 -3
  91. package/src/CloudflareMemory.ts +5 -1
  92. package/src/CloudflareScheduling.ts +7 -2
  93. package/src/CloudflareSubscriptions.ts +9 -2
  94. package/src/CloudflareThreadClient.ts +15 -148
  95. package/src/InteractiveBrowser.ts +10 -12
  96. package/src/LiveText.ts +141 -0
  97. package/src/ThreadObject.ts +13 -8
  98. package/src/WakeScheduler.ts +5 -1
  99. package/src/index.ts +1 -0
  100. package/src/internal/boundary.ts +1 -1
  101. package/src/internal/browser-binding.ts +5 -1
  102. package/src/internal/browser-credentials.ts +5 -1
  103. package/src/internal/browser-failure.ts +6 -2
  104. package/src/internal/browser-file-selection.ts +1 -1
  105. package/src/internal/browser-quick-action.ts +5 -1
  106. package/src/internal/browser-readonly-live-view.ts +9 -2
  107. package/src/internal/browser-session-lifecycle.ts +10 -2
  108. package/src/internal/crypto.ts +5 -2
  109. package/src/internal/due-queue.ts +2 -1
  110. package/src/internal/host-protocol-error.ts +23 -0
  111. package/src/internal/layers.ts +45 -22
  112. package/src/internal/live-text-observation.ts +8 -0
  113. package/src/internal/live-text-protocol.ts +10 -9
  114. package/src/internal/live-text.ts +28 -10
  115. package/src/internal/message-delivery.ts +7 -1
  116. package/src/internal/prepared-admission.ts +2 -1
  117. package/src/internal/progress-wait.ts +6 -1
  118. package/src/internal/transport.ts +2 -1
  119. package/dist/Alarm-C257DCAJ.mjs.map +0 -1
  120. package/dist/BrowserSession-CfivQ5JY.mjs.map +0 -1
  121. package/dist/CloudflareBrowser-Vt8qTdYW.mjs.map +0 -1
  122. package/dist/CloudflareThreadClient-CmlojpjC.d.mts +0 -2211
  123. package/dist/CloudflareThreadClient-CnvMXPmV.mjs.map +0 -1
  124. package/dist/InteractiveBrowser-nukKxc87.mjs.map +0 -1
  125. package/dist/ThreadObject-Cr1CFWXb.mjs.map +0 -1
  126. package/dist/boundary-BguazVkh.mjs.map +0 -1
  127. package/dist/browser-failure-DECzRY3H.mjs.map +0 -1
  128. package/dist/prepared-admission-w2Kq32_k.mjs.map +0 -1
package/src/Alarm.ts CHANGED
@@ -21,31 +21,29 @@ import {
21
21
  type ThreadProjectionError,
22
22
  } from "@yielded/agent/thread-projection-maintenance";
23
23
  import { WakeScheduler } from "@yielded/agent/wake-scheduler";
24
- import {
25
- Cause,
26
- Clock,
27
- Context,
28
- DateTime,
29
- Deferred,
30
- Effect,
31
- ErrorReporter,
32
- Exit,
33
- Fiber,
34
- Layer,
35
- Option,
36
- Random,
37
- Ref,
38
- Result,
39
- Scheduler,
40
- Schema,
41
- Scope,
42
- Semaphore,
43
- Stream,
44
- Struct,
45
- } from "effect";
46
- import { DurableObjectAlarm, DurableObjectStorage } from "effect-cf";
47
- import { SqlClient } from "effect/sql/SqlClient";
48
- import { SqlError, UnknownError } from "effect/sql/SqlError";
24
+ import { DurableObjectAlarm, DurableObjectState, DurableObjectStorage } from "effect-cf";
25
+ import * as Cause from "effect/Cause";
26
+ import * as Clock from "effect/Clock";
27
+ import * as Context from "effect/Context";
28
+ import * as DateTime from "effect/DateTime";
29
+ import * as Deferred from "effect/Deferred";
30
+ import * as Effect from "effect/Effect";
31
+ import * as ErrorReporter from "effect/ErrorReporter";
32
+ import * as Exit from "effect/Exit";
33
+ import * as Fiber from "effect/Fiber";
34
+ import * as Layer from "effect/Layer";
35
+ import * as Option from "effect/Option";
36
+ import * as Random from "effect/Random";
37
+ import * as Ref from "effect/Ref";
38
+ import * as Result from "effect/Result";
39
+ import * as Scheduler from "effect/Scheduler";
40
+ import * as Schema from "effect/Schema";
41
+ import * as Scope from "effect/Scope";
42
+ import * as Semaphore from "effect/Semaphore";
43
+ import * as SqlClient from "effect/sql/SqlClient";
44
+ import * as SqlError from "effect/sql/SqlError";
45
+ import * as Stream from "effect/Stream";
46
+ import * as Struct from "effect/Struct";
49
47
 
50
48
  import {
51
49
  DurableAlarmError,
@@ -86,7 +84,7 @@ const alarmFailure =
86
84
  // SQL and raw KV/alarm operations share one physical SQLite transaction. Reserve its
87
85
  // connection for each short storage operation, never around a mutation or snapshot body.
88
86
  const makeStorageEffect = Effect.gen(function* () {
89
- const sql = yield* SqlClient;
87
+ const sql = yield* SqlClient.SqlClient;
90
88
  const { ctx } = yield* DurableObjectContext;
91
89
  const invalidate = Effect.sync(() => DueQueue.invalidate(ctx.storage));
92
90
 
@@ -229,13 +227,13 @@ const CurrentCheckpoint = Context.Reference<MaintenanceCheckpoint | undefined>(
229
227
  /** One source transaction owns queue intent and the library checkpoint through commit. */
230
228
  const makeAlarmOperation = Effect.gen(function* () {
231
229
  const alarms = yield* ThreadMaintenanceAlarm;
232
- const sql = yield* SqlClient;
230
+ const sql = yield* SqlClient.SqlClient;
233
231
  const { ctx } = yield* DurableObjectContext;
234
232
  const queue = DueQueue.make(ctx.storage);
235
233
 
236
234
  const transaction = <A, E, R>(
237
235
  body: (owner: Fiber.Fiber<unknown, unknown>) => Effect.Effect<A, E, R>,
238
- ): Effect.Effect<A, E | SqlError, R> =>
236
+ ): Effect.Effect<A, E | SqlError.SqlError, R> =>
239
237
  alarms
240
238
  .transaction(
241
239
  (mutations) =>
@@ -261,8 +259,8 @@ const makeAlarmOperation = Effect.gen(function* () {
261
259
  .pipe(
262
260
  Effect.mapError((cause) =>
263
261
  cause instanceof DurableObjectStorage.StorageOperationError
264
- ? SqlError.make({
265
- reason: UnknownError.make({
262
+ ? SqlError.SqlError.make({
263
+ reason: SqlError.UnknownError.make({
266
264
  operation: "commit maintenance checkpoint",
267
265
  message: "Source facts and maintenance checkpoint could not commit",
268
266
  cause,
@@ -278,8 +276,8 @@ const makeAlarmOperation = Effect.gen(function* () {
278
276
 
279
277
  if (ambient._tag === "Some" && !DueQueue.ownsTransaction(ctx.storage, ambient.value[1]))
280
278
  return Effect.fail(
281
- SqlError.make({
282
- reason: UnknownError.make({
279
+ SqlError.SqlError.make({
280
+ reason: SqlError.UnknownError.make({
283
281
  operation: "begin maintenance source transaction",
284
282
  message: "Use ThreadMutationGate.withTransaction at the outermost source transaction",
285
283
  cause: "Unwrapped SQL transaction cannot own buffered maintenance intent",
@@ -294,8 +292,8 @@ const makeAlarmOperation = Effect.gen(function* () {
294
292
  const current = Context.getOption(owner.context, sql.transactionService);
295
293
 
296
294
  if (current._tag === "None")
297
- return SqlError.make({
298
- reason: UnknownError.make({
295
+ return SqlError.SqlError.make({
296
+ reason: SqlError.UnknownError.make({
299
297
  operation: "begin maintenance source transaction",
300
298
  message: "SQL transaction unavailable",
301
299
  cause: "SQL transaction unavailable",
@@ -313,8 +311,8 @@ const makeAlarmOperation = Effect.gen(function* () {
313
311
  return value;
314
312
  },
315
313
  catch: (cause) =>
316
- SqlError.make({
317
- reason: UnknownError.make({
314
+ SqlError.SqlError.make({
315
+ reason: SqlError.UnknownError.make({
318
316
  cause,
319
317
  operation: "flush maintenance due queue",
320
318
  message: "Maintenance intent could not commit",
@@ -334,7 +332,7 @@ const makeAlarmOperation = Effect.gen(function* () {
334
332
  Effect.provideService(Scheduler.PreventSchedulerYield, true),
335
333
  ),
336
334
  );
337
- }).pipe(Effect.provideService(SqlClient, sql));
335
+ }).pipe(Effect.provideService(SqlClient.SqlClient, sql));
338
336
 
339
337
  const run = <A>(
340
338
  operation: string,
@@ -895,7 +893,7 @@ export class ThreadMutationGate extends Context.Service<
895
893
  * failed or interrupted transactions discard their queue view. */
896
894
  readonly withTransaction: <A, E, R>(
897
895
  body: Effect.Effect<A, E, R>,
898
- ) => Effect.Effect<A, E | SqlError, R>;
896
+ ) => Effect.Effect<A, E | SqlError.SqlError, R>;
899
897
  readonly withMutation: <A, E, R>(
900
898
  body: Effect.Effect<A, E, R>,
901
899
  /**
@@ -943,7 +941,7 @@ export class ThreadMutationGate extends Context.Service<
943
941
  static readonly layer = Layer.effect(this)(
944
942
  Effect.gen(function* () {
945
943
  const { ctx } = yield* DurableObjectContext;
946
- const sql = yield* SqlClient;
944
+ const sql = yield* SqlClient.SqlClient;
947
945
  const dueQueue = DueQueue.make(ctx.storage);
948
946
  const placement = yield* Effect.serviceOption(ThreadObjectPlacement);
949
947
  const singleThread = Option.isSome(placement) && placement.value.threadId !== undefined;
@@ -979,6 +977,7 @@ export class ThreadMutationGate extends Context.Service<
979
977
  });
980
978
 
981
979
  const minimumAlarmDelay = Math.max(1, Math.ceil(config.alarmBackoffBase / 2));
980
+ const recoveryDelay = config.recoveryWindowMillis || minimumAlarmDelay;
982
981
 
983
982
  const runTransaction = yield* makeStorageOperation;
984
983
  const { run: runAlarmTransaction, withTransaction } = yield* makeAlarmOperation;
@@ -1010,6 +1009,7 @@ export class ThreadMutationGate extends Context.Service<
1010
1009
  ) {
1011
1010
  yield* validateSourceBoundary;
1012
1011
  const now = yield* Clock.currentTimeMillis;
1012
+ const scheduling = yield* DurableObjectAlarm.ScheduleConfiguration;
1013
1013
 
1014
1014
  const enroll = async (transaction: MaintenanceStorage, checkpoint: CheckpointIntent) => {
1015
1015
  if (progressCursor === undefined) dueQueue.dirty(id, dueAt);
@@ -1033,7 +1033,13 @@ export class ThreadMutationGate extends Context.Service<
1033
1033
  }
1034
1034
  const next = DueQueue.next(dueQueue.read());
1035
1035
 
1036
- if (Number.isFinite(next)) checkpoint.earlier(Math.max(next, now + minimumAlarmDelay));
1036
+ if (Number.isFinite(next))
1037
+ checkpoint.earlier(
1038
+ Math.max(
1039
+ next,
1040
+ now + (scheduling.dispatchAfterEvent === true ? 0 : minimumAlarmDelay),
1041
+ ),
1042
+ );
1037
1043
  };
1038
1044
 
1039
1045
  yield* runAlarmTransaction("schedule maintenance lane", enroll);
@@ -1072,12 +1078,12 @@ export class ThreadMutationGate extends Context.Service<
1072
1078
  }),
1073
1079
  ),
1074
1080
  );
1075
- // The earliest configured retry bounds a newly actionable mutation without relying
1076
- // on its best-effort immediate wake hint.
1081
+ // Commit recovery before the producer. Source progress separately starts work
1082
+ // promptly; a retained earlier wake already covers this recovery window.
1077
1083
  const deadline = DueQueue.next(dueQueue.read());
1078
1084
 
1079
1085
  if (Number.isFinite(deadline))
1080
- checkpoint.earlier(Math.max(deadline, now + minimumAlarmDelay));
1086
+ checkpoint.earlier(Math.max(deadline, now + recoveryDelay));
1081
1087
  },
1082
1088
  );
1083
1089
  yield* failpoint.hit("maintenance:dirty:after");
@@ -1268,6 +1274,10 @@ export class ThreadMaintenance extends Context.Service<
1268
1274
  {
1269
1275
  /** One idempotent pass; failures propagate after durably scheduling bounded recovery. */
1270
1276
  readonly pass: Effect.Effect<MaintenancePassReport, MaintenancePassFailure>;
1277
+ /** Start a committed admission under the same bounded processing and recovery guard. */
1278
+ readonly start: (
1279
+ admission: Pick<SubmissionWorkItem, "threadId" | "submissionId">,
1280
+ ) => Effect.Effect<void>;
1271
1281
  /**
1272
1282
  * Constructor gate: initialize/inspect only the O(1) maintenance record and ensure a dirty
1273
1283
  * generation has an alarm. It never scans the ledger or canonical history.
@@ -1298,7 +1308,7 @@ export class ThreadMaintenance extends Context.Service<
1298
1308
  | ThreadMaintenanceFailpoint
1299
1309
  | CloudflareDurableRuntimeConfig
1300
1310
  | DurableObjectContext
1301
- | SqlClient
1311
+ | SqlClient.SqlClient
1302
1312
  > = Layer.effect(ThreadMaintenance)(
1303
1313
  Effect.gen(function* () {
1304
1314
  const runtime = yield* DurableAgentRuntime;
@@ -1310,6 +1320,7 @@ export class ThreadMaintenance extends Context.Service<
1310
1320
  const alarms = yield* ThreadMaintenanceAlarm;
1311
1321
  const config = yield* CloudflareDurableRuntimeConfig;
1312
1322
  const { ctx } = yield* DurableObjectContext;
1323
+ const execution = DurableObjectState.fromDurableObjectState(ctx);
1313
1324
  const dueQueue = DueQueue.make(ctx.storage);
1314
1325
  const storage = DurableObjectStorage.fromDurableObjectStorage(ctx.storage);
1315
1326
  const runStorage = yield* makeStorageEffect;
@@ -1319,7 +1330,7 @@ export class ThreadMaintenance extends Context.Service<
1319
1330
  const publication = yield* ThreadPublication;
1320
1331
 
1321
1332
  const publicationContext = yield* Effect.context<
1322
- ThreadPublication | DurableObjectContext | SqlClient
1333
+ ThreadPublication | DurableObjectContext | SqlClient.SqlClient
1323
1334
  >();
1324
1335
 
1325
1336
  const projection = yield* ThreadProjectionMaintenance;
@@ -1982,12 +1993,13 @@ export class ThreadMaintenance extends Context.Service<
1982
1993
  );
1983
1994
 
1984
1995
  const attemptSelected = Effect.fnUntraced(function* (
1985
- selected: SubmissionWorkItem,
1996
+ selected: Pick<SubmissionWorkItem, "threadId" | "submissionId">,
1986
1997
  previousWaits: ReadonlyArray<BindingWait>,
1987
1998
  yieldAfter: DateTime.Utc,
1988
1999
  recovery: NativeRecovery,
2000
+ admitted = false,
1989
2001
  ): Effect.fn.Return<number, MaintenancePassFailure> {
1990
- yield* recoverThread(selected.threadId, recovery);
2002
+ if (!admitted) yield* recoverThread(selected.threadId, recovery);
1991
2003
 
1992
2004
  let bindingFailure: DurableBindingFailure | undefined;
1993
2005
 
@@ -1995,14 +2007,19 @@ export class ThreadMaintenance extends Context.Service<
1995
2007
  // and committing its registry wait below.
1996
2008
  const settlement = recovery.faults.has(selected.threadId)
1997
2009
  ? Option.none()
1998
- : yield* runtime.processThreadHead(selected.threadId, { yieldAfter }).pipe(
1999
- Effect.provideService(CurrentNativeSource, true),
2000
- Effect.catchTag("BindingUnavailable", (failure) => {
2001
- bindingFailure = failure;
2010
+ : yield* runtime
2011
+ .processThreadHead(selected.threadId, {
2012
+ yieldAfter,
2013
+ ...(admitted ? { admittedSubmissionId: selected.submissionId } : {}),
2014
+ })
2015
+ .pipe(
2016
+ Effect.provideService(CurrentNativeSource, true),
2017
+ Effect.catchTag("BindingUnavailable", (failure) => {
2018
+ bindingFailure = failure;
2002
2019
 
2003
- return Effect.succeed(Option.none());
2004
- }),
2005
- );
2020
+ return Effect.succeed(Option.none());
2021
+ }),
2022
+ );
2006
2023
 
2007
2024
  const previous = previousWaits.find((wait) => wait.submissionId === selected.submissionId);
2008
2025
 
@@ -2626,6 +2643,7 @@ export class ThreadMaintenance extends Context.Service<
2626
2643
  yieldAfter: DateTime.Utc,
2627
2644
  dispatchUntil: DateTime.Utc,
2628
2645
  observed: MaintenanceObservation,
2646
+ admission?: Pick<SubmissionWorkItem, "threadId" | "submissionId">,
2629
2647
  ) {
2630
2648
  const leanSelection =
2631
2649
  framework.singleThreadRuntime === runtime &&
@@ -2713,7 +2731,21 @@ export class ThreadMaintenance extends Context.Service<
2713
2731
  let result: NativePassResult;
2714
2732
  let backlog: ReadonlyArray<ThreadId> | undefined;
2715
2733
 
2716
- if (leanSelection) {
2734
+ if (leanSelection && admission !== undefined && started._tag === "Actionable") {
2735
+ // Admission already identified the work. Its exact FIFO claim and owner generation
2736
+ // remain authoritative; the normal loop discovers and acknowledges everything after it.
2737
+ dispatch.dispatched++;
2738
+ dispatch.active.set(
2739
+ admission.threadId,
2740
+ yield* fork(attemptSelected(admission, [], yieldAfter, recovery, true)),
2741
+ );
2742
+ result = {
2743
+ phase: "actionable",
2744
+ nonterminal: started.nonterminal,
2745
+ nextAttemptAt: undefined,
2746
+ dispatched: true,
2747
+ };
2748
+ } else if (leanSelection) {
2717
2749
  result = yield* advance(started, yieldAfter, observed, recovery, dispatch);
2718
2750
  recovery.started = true;
2719
2751
  yield* Deferred.succeed(recovery.queue, []);
@@ -3061,9 +3093,10 @@ export class ThreadMaintenance extends Context.Service<
3061
3093
  yieldAfter: DateTime.Utc,
3062
3094
  dispatchUntil: DateTime.Utc,
3063
3095
  observed: MaintenanceObservation,
3096
+ admission?: Pick<SubmissionWorkItem, "threadId" | "submissionId">,
3064
3097
  ): Effect.fn.Return<MaintenancePassReport, MaintenancePassFailure, Scope.Scope> {
3065
3098
  const concurrent = yield* Effect.exit(
3066
- Effect.scoped(dispatch(yieldAfter, dispatchUntil, observed)).pipe(
3099
+ Effect.scoped(dispatch(yieldAfter, dispatchUntil, observed, admission)).pipe(
3067
3100
  Effect.provideService(ThreadMutationGate, mutations),
3068
3101
  ),
3069
3102
  );
@@ -3245,6 +3278,13 @@ export class ThreadMaintenance extends Context.Service<
3245
3278
 
3246
3279
  return "rearmed" as const;
3247
3280
  }
3281
+ // A productive event retains one recovery opportunity for nearby ingress.
3282
+ // Its later empty delivery has no charged work and removes the checkpoint.
3283
+ if (config.recoveryWindowMillis > 0 && observed.charged.size > 0) {
3284
+ checkpoint.at(now + config.recoveryWindowMillis);
3285
+
3286
+ return "rearmed" as const;
3287
+ }
3248
3288
  checkpoint.cancel();
3249
3289
 
3250
3290
  return "cleared" as const;
@@ -3274,9 +3314,9 @@ export class ThreadMaintenance extends Context.Service<
3274
3314
  return report;
3275
3315
  });
3276
3316
 
3277
- return ThreadMaintenance.of({
3278
- // A mid-pass immediate hint is droppable; durable dirty state decides the final alarm.
3279
- pass: Effect.gen(function* () {
3317
+ // A mid-pass immediate hint is droppable; durable dirty state decides the final alarm.
3318
+ const runPass = Effect.fnUntraced(
3319
+ function* (admission: Pick<SubmissionWorkItem, "threadId" | "submissionId"> | undefined) {
3280
3320
  const now = yield* Clock.currentTimeMillis;
3281
3321
  const yieldAfter = DateTime.makeUnsafe(now + 10 * 60_000);
3282
3322
  const dispatchUntil = DateTime.makeUnsafe(now + 14 * 60_000);
@@ -3291,14 +3331,16 @@ export class ThreadMaintenance extends Context.Service<
3291
3331
  return yield* alarms
3292
3332
  .deferWakes(
3293
3333
  maintenancePassGate.withPermit(
3294
- dueQueue.withView(Effect.scoped(pass(yieldAfter, dispatchUntil, observed))).pipe(
3295
- // Close event-owned auxiliary work and release Attempt ownership before
3296
- // failure rearming, while still holding the pass permit.
3297
- Effect.onErrorIf(
3298
- () => true,
3299
- () => rearmFailure(observed),
3334
+ dueQueue
3335
+ .withView(Effect.scoped(pass(yieldAfter, dispatchUntil, observed, admission)))
3336
+ .pipe(
3337
+ // Close event-owned auxiliary work and release Attempt ownership before
3338
+ // failure rearming, while still holding the pass permit.
3339
+ Effect.onErrorIf(
3340
+ () => true,
3341
+ () => rearmFailure(observed),
3342
+ ),
3300
3343
  ),
3301
- ),
3302
3344
  ),
3303
3345
  )
3304
3346
  .pipe(
@@ -3309,22 +3351,26 @@ export class ThreadMaintenance extends Context.Service<
3309
3351
  alarmFailure("defer maintenance wakes")(error),
3310
3352
  }),
3311
3353
  );
3312
- }).pipe(
3313
- // Include permit waiting, recovery and acknowledgement in the event deadline.
3314
- // Interruption releases Attempt ownership, leaving the prearmed dirty generation
3315
- // for recovery. It never changes the logical Run duration or settles a policy failure.
3316
- // This cooperative timer cannot preempt synchronous CPU work or stuck finalizers.
3317
- Effect.timeoutOrElse({
3318
- duration: "14 minutes",
3319
- orElse: () =>
3320
- DurableAlarmError.make({
3321
- operation: "maintenance pass deadline",
3322
- message:
3323
- "The maintenance event exceeded its 14 minute deadline; durable recovery remains pending",
3324
- }),
3325
- }),
3326
- Effect.ensuring(reportParked),
3327
- ),
3354
+ },
3355
+ // Include permit waiting, recovery and acknowledgement in the event deadline.
3356
+ // Interruption releases Attempt ownership, leaving the prearmed dirty generation
3357
+ // for recovery. It never changes the logical Run duration or settles a policy failure.
3358
+ // This cooperative timer cannot preempt synchronous CPU work or stuck finalizers.
3359
+ Effect.timeoutOrElse({
3360
+ duration: "14 minutes",
3361
+ orElse: () =>
3362
+ DurableAlarmError.make({
3363
+ operation: "maintenance pass deadline",
3364
+ message:
3365
+ "The maintenance event exceeded its 14 minute deadline; durable recovery remains pending",
3366
+ }),
3367
+ }),
3368
+ Effect.ensuring(reportParked),
3369
+ );
3370
+
3371
+ return ThreadMaintenance.of({
3372
+ pass: runPass(undefined),
3373
+ start: (admission) => execution.waitUntil(runPass(admission)),
3328
3374
  ensureAlarm: mutations
3329
3375
  .withSnapshot(() => ensureAlarm())
3330
3376
  .pipe(Effect.tap(() => reportParked)),
@@ -1,4 +1,6 @@
1
- import { Context, type Effect, Schema } from "effect";
1
+ import * as Context from "effect/Context";
2
+ import type * as Effect from "effect/Effect";
3
+ import * as Schema from "effect/Schema";
2
4
 
3
5
  const Selector = Schema.NonEmptyString.check(Schema.isMaxLength(2048));
4
6
 
@@ -21,8 +21,15 @@ import {
21
21
  type PageCaptureRequest,
22
22
  } from "@yielded/agent/page-capture";
23
23
  import { SandboxImplementation } from "@yielded/agent/sandbox";
24
- import { Effect, Layer, Option, Redacted, Schema, Stream } from "effect";
25
- import { HttpClient, HttpClientRequest, type HttpClientError } from "effect/http";
24
+ import * as Effect from "effect/Effect";
25
+ import * as HttpClient from "effect/http/HttpClient";
26
+ import type * as HttpClientError from "effect/http/HttpClientError";
27
+ import * as HttpClientRequest from "effect/http/HttpClientRequest";
28
+ import * as Layer from "effect/Layer";
29
+ import * as Option from "effect/Option";
30
+ import * as Redacted from "effect/Redacted";
31
+ import * as Schema from "effect/Schema";
32
+ import * as Stream from "effect/Stream";
26
33
 
27
34
  import {
28
35
  BrowserQuickActionWorkersAi,
@@ -10,24 +10,20 @@ import {
10
10
  type PageCrawlRequest,
11
11
  } from "@yielded/agent/page-crawl";
12
12
  import { SandboxImplementation } from "@yielded/agent/sandbox";
13
- import {
14
- Duration,
15
- Effect,
16
- Layer,
17
- Option,
18
- Redacted,
19
- Ref,
20
- Schedule,
21
- Schema,
22
- Scope,
23
- Stream,
24
- } from "effect";
25
- import {
26
- HttpClient,
27
- HttpClientRequest,
28
- type HttpClientError,
29
- type HttpClientResponse,
30
- } from "effect/http";
13
+ import * as Duration from "effect/Duration";
14
+ import * as Effect from "effect/Effect";
15
+ import * as HttpClient from "effect/http/HttpClient";
16
+ import type * as HttpClientError from "effect/http/HttpClientError";
17
+ import * as HttpClientRequest from "effect/http/HttpClientRequest";
18
+ import type * as HttpClientResponse from "effect/http/HttpClientResponse";
19
+ import * as Layer from "effect/Layer";
20
+ import * as Option from "effect/Option";
21
+ import * as Redacted from "effect/Redacted";
22
+ import * as Ref from "effect/Ref";
23
+ import * as Schedule from "effect/Schedule";
24
+ import * as Schema from "effect/Schema";
25
+ import * as Scope from "effect/Scope";
26
+ import * as Stream from "effect/Stream";
31
27
 
32
28
  /** Node-safe REST crawl implementation. It never exposes or persists provider job identity. */
33
29
  export const browserRestCrawlImplementation = SandboxImplementation.make({
@@ -1,17 +1,15 @@
1
1
  /// <reference types="@cloudflare/workers-types" />
2
2
 
3
- import {
4
- Cause,
5
- Clock,
6
- Context,
7
- Effect,
8
- Exit,
9
- Layer,
10
- Redacted,
11
- Schema,
12
- Semaphore,
13
- Scope,
14
- } from "effect";
3
+ import * as Cause from "effect/Cause";
4
+ import * as Clock from "effect/Clock";
5
+ import * as Context from "effect/Context";
6
+ import * as Effect from "effect/Effect";
7
+ import * as Exit from "effect/Exit";
8
+ import * as Layer from "effect/Layer";
9
+ import * as Redacted from "effect/Redacted";
10
+ import * as Schema from "effect/Schema";
11
+ import * as Scope from "effect/Scope";
12
+ import * as Semaphore from "effect/Semaphore";
15
13
  import type { Browser, Page } from "puppeteer-core/lib/esm/puppeteer/puppeteer-core-browser.js";
16
14
 
17
15
  import {
package/src/BrowserUse.ts CHANGED
@@ -7,7 +7,11 @@ import {
7
7
  SendRequest,
8
8
  Tab,
9
9
  } from "@yielded/agent/browser-use";
10
- import { Cause, Effect, Layer, Schema, Semaphore } from "effect";
10
+ import * as Cause from "effect/Cause";
11
+ import * as Effect from "effect/Effect";
12
+ import * as Layer from "effect/Layer";
13
+ import * as Schema from "effect/Schema";
14
+ import * as Semaphore from "effect/Semaphore";
11
15
  import type {
12
16
  CDPSession,
13
17
  Frame,
@@ -1,11 +1,15 @@
1
- import { Context, Effect, Layer, Option, Redactable, Redacted, Schema } from "effect";
2
- import {
3
- FetchHttpClient,
4
- Headers,
5
- HttpClient,
6
- HttpClientError,
7
- HttpClientRequest,
8
- } from "effect/http";
1
+ import * as Context from "effect/Context";
2
+ import * as Effect from "effect/Effect";
3
+ import * as FetchHttpClient from "effect/http/FetchHttpClient";
4
+ import * as Headers from "effect/http/Headers";
5
+ import * as HttpClient from "effect/http/HttpClient";
6
+ import * as HttpClientError from "effect/http/HttpClientError";
7
+ import * as HttpClientRequest from "effect/http/HttpClientRequest";
8
+ import * as Layer from "effect/Layer";
9
+ import * as Option from "effect/Option";
10
+ import * as Redactable from "effect/Redactable";
11
+ import * as Redacted from "effect/Redacted";
12
+ import * as Schema from "effect/Schema";
9
13
 
10
14
  const Segment = Schema.NonEmptyString.check(
11
15
  Schema.isMaxLength(256),
@@ -1,7 +1,11 @@
1
1
  import { type ThreadId } from "@yielded/agent/identifiers";
2
2
  import { type ProducerId } from "@yielded/agent/records";
3
- import { Context, Effect, Layer, Predicate, Schema } from "effect";
4
3
  import { RpcTargets } from "effect-cf";
4
+ import * as Context from "effect/Context";
5
+ import * as Effect from "effect/Effect";
6
+ import * as Layer from "effect/Layer";
7
+ import * as Predicate from "effect/Predicate";
8
+ import * as Schema from "effect/Schema";
5
9
 
6
10
  /**
7
11
  * Cloudflare platform bindings as Effect services (DEPLOY-010: "Cloudflare platform bindings
@@ -19,7 +19,15 @@ import {
19
19
  } from "@yielded/agent/code-executor";
20
20
  import { SandboxImplementation } from "@yielded/agent/sandbox";
21
21
  import { RpcTarget } from "cloudflare:workers";
22
- import { Clock, Duration, Effect, Exit, Fiber, Layer, Option, Queue, Schema } from "effect";
22
+ import * as Clock from "effect/Clock";
23
+ import * as Duration from "effect/Duration";
24
+ import * as Effect from "effect/Effect";
25
+ import * as Exit from "effect/Exit";
26
+ import * as Fiber from "effect/Fiber";
27
+ import * as Layer from "effect/Layer";
28
+ import * as Option from "effect/Option";
29
+ import * as Queue from "effect/Queue";
30
+ import * as Schema from "effect/Schema";
23
31
 
24
32
  import { safeCauseDiagnostic, safeCauseMessage } from "./internal/boundary.ts";
25
33
 
@@ -1,6 +1,7 @@
1
1
  import { DEFAULT_MAX_STORED_VALUE_BYTES } from "@yielded/agent-storage-cloudflare/do-storage-config";
2
2
  import { DeploymentId } from "@yielded/agent/records";
3
- import { Context, Schema } from "effect";
3
+ import * as Context from "effect/Context";
4
+ import * as Schema from "effect/Schema";
4
5
 
5
6
  /**
6
7
  * Schema-validated configuration for the Cloudflare durable runtime (deployment spec §4:
@@ -14,6 +15,9 @@ const PositiveMillis = Schema.Int.check(Schema.isGreaterThan(0));
14
15
  export const AuxiliaryDispatchMillis = PositiveMillis.check(Schema.isLessThanOrEqualTo(300_000));
15
16
  const NonNegativeMillis = Schema.Int.check(Schema.isGreaterThanOrEqualTo(0));
16
17
 
18
+ /** Recovery coverage retained after activity; independent of work-start and retry deadlines. */
19
+ export const DEFAULT_RECOVERY_WINDOW_MILLIS = 60_000;
20
+
17
21
  /** The supplied Cloudflare durable runtime configuration failed validation (DEPLOY-003). */
18
22
  export class CloudflarePlatformConfigError extends Schema.TaggedError<CloudflarePlatformConfigError>()(
19
23
  "CloudflarePlatformConfigError",
@@ -87,10 +91,12 @@ export class CloudflareDurableRuntimeConfigValue extends Schema.Class<Cloudflare
87
91
  deploymentId: DeploymentId,
88
92
  /** Head of the minted producer identity `{producerPrefix}:{threadId}`. */
89
93
  producerPrefix: Schema.NonEmptyString.check(Schema.isMaxLength(256)),
94
+ /** Recovery-only window. Zero restores immediate idle cancellation and the short guards. */
95
+ recoveryWindowMillis: NonNegativeMillis,
90
96
  /**
91
97
  * Base delay of exponential backoff when a pass fails or makes no progress.
92
- * Half this delay (rounded up, at least 1ms) also pre-arms mutations, including
93
- * healthy admissions. `alarmBackoffCap` does not cap that pre-arm delay.
98
+ * Half this delay (rounded up, at least 1ms) starts alarm-driven work and recovers
99
+ * startup work. It also pre-arms mutations when the recovery window is disabled.
94
100
  */
95
101
  alarmBackoffBase: PositiveMillis,
96
102
  /** Ceiling of exponential backoff after failed or no-progress maintenance passes. */
@@ -121,6 +127,7 @@ export class CloudflareDurableRuntimeConfig extends Context.Service<
121
127
 
122
128
  /** Documented production defaults applied by `ThreadObject.layer`. */
123
129
  export const CLOUDFLARE_RUNTIME_DEFAULTS = {
130
+ recoveryWindowMillis: DEFAULT_RECOVERY_WINDOW_MILLIS,
124
131
  alarmBackoffBase: 100,
125
132
  alarmBackoffCap: 5_000,
126
133
  settlementPollInterval: 500,
@@ -36,13 +36,17 @@ import {
36
36
  } from "@yielded/agent/semantic-memory-index";
37
37
  import { type SemanticCandidateLimits } from "@yielded/agent/semantic-memory-revalidation";
38
38
  import { Principal } from "@yielded/agent/submission-ledger";
39
- import { Clock, Context, Effect, Layer, Schema } from "effect";
40
39
  import {
41
40
  DurableObject as EffectCfDurableObject,
42
41
  DurableObjectState,
43
42
  RpcTargets,
44
43
  type WorkerEnvironment,
45
44
  } from "effect-cf";
45
+ import * as Clock from "effect/Clock";
46
+ import * as Context from "effect/Context";
47
+ import * as Effect from "effect/Effect";
48
+ import * as Layer from "effect/Layer";
49
+ import * as Schema from "effect/Schema";
46
50
 
47
51
  export interface MemoryObjectRpc extends Rpc.DurableObjectBranded {
48
52
  memory(encoded: string): Promise<string>;