@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.
- package/dist/{Alarm-C257DCAJ.mjs → Alarm-4qf-iCXC.mjs} +94 -54
- package/dist/Alarm-4qf-iCXC.mjs.map +1 -0
- package/dist/Alarm.d.mts +16 -9
- package/dist/Alarm.mjs +1 -1
- package/dist/{BrowserCredentials-C2rBhlUI.d.mts → BrowserCredentials-CysbK6UA.d.mts} +4 -2
- package/dist/BrowserCredentials.d.mts +1 -1
- package/dist/BrowserCredentials.mjs +2 -1
- package/dist/BrowserCredentials.mjs.map +1 -1
- package/dist/BrowserRestCapture.d.mts +4 -3
- package/dist/BrowserRestCapture.mjs +9 -3
- package/dist/BrowserRestCapture.mjs.map +1 -1
- package/dist/BrowserRestCrawl.d.mts +3 -2
- package/dist/BrowserRestCrawl.mjs +12 -2
- package/dist/BrowserRestCrawl.mjs.map +1 -1
- package/dist/{BrowserSession-mKnLSc3p.d.mts → BrowserSession-BLEG79zz.d.mts} +12 -5
- package/dist/{BrowserSession-CfivQ5JY.mjs → BrowserSession-CITvpByq.mjs} +17 -5
- package/dist/BrowserSession-CITvpByq.mjs.map +1 -0
- package/dist/BrowserSession.d.mts +2 -2
- package/dist/BrowserSession.mjs +2 -2
- package/dist/BrowserUse.d.mts +4 -2
- package/dist/BrowserUse.mjs +6 -2
- package/dist/BrowserUse.mjs.map +1 -1
- package/dist/CloudflareAiGateway.d.mts +3 -2
- package/dist/CloudflareAiGateway.mjs +12 -2
- package/dist/CloudflareAiGateway.mjs.map +1 -1
- package/dist/CloudflareBindings.d.mts +4 -1
- package/dist/CloudflareBindings.mjs +5 -1
- package/dist/CloudflareBindings.mjs.map +1 -1
- package/dist/{CloudflareBrowser-gu7gma0Y.d.mts → CloudflareBrowser-CZoXu_oS.d.mts} +5 -2
- package/dist/{CloudflareBrowser-Vt8qTdYW.mjs → CloudflareBrowser-Wfs-zRuk.mjs} +6 -2
- package/dist/CloudflareBrowser-Wfs-zRuk.mjs.map +1 -0
- package/dist/CloudflareBrowser.d.mts +1 -1
- package/dist/CloudflareBrowser.mjs +1 -1
- package/dist/CloudflareCodeMode.d.mts +2 -1
- package/dist/CloudflareCodeMode.mjs +10 -2
- package/dist/CloudflareCodeMode.mjs.map +1 -1
- package/dist/{CloudflareConfig-C9MvPbX8.d.mts → CloudflareConfig-D_-BMp4q.d.mts} +12 -6
- package/dist/CloudflareConfig.d.mts +2 -2
- package/dist/CloudflareConfig.mjs +12 -5
- package/dist/CloudflareConfig.mjs.map +1 -1
- package/dist/CloudflareMemory.d.mts +3 -1
- package/dist/CloudflareMemory.mjs +5 -1
- package/dist/CloudflareMemory.mjs.map +1 -1
- package/dist/CloudflareScheduling.d.mts +4 -1
- package/dist/CloudflareScheduling.mjs +9 -4
- package/dist/CloudflareScheduling.mjs.map +1 -1
- package/dist/CloudflareSubscriptions.d.mts +6 -1
- package/dist/CloudflareSubscriptions.mjs +10 -4
- package/dist/CloudflareSubscriptions.mjs.map +1 -1
- package/dist/{CloudflareThreadClient-CnvMXPmV.mjs → CloudflareThreadClient-DiV2xHn0.mjs} +16 -135
- package/dist/CloudflareThreadClient-DiV2xHn0.mjs.map +1 -0
- package/dist/CloudflareThreadClient.d.mts +2144 -2
- package/dist/CloudflareThreadClient.mjs +2 -1
- package/dist/{InteractiveBrowser-nukKxc87.mjs → InteractiveBrowser-Bh9wisQI.mjs} +18 -5
- package/dist/InteractiveBrowser-Bh9wisQI.mjs.map +1 -0
- package/dist/{InteractiveBrowser-wV2Bti5e.d.mts → InteractiveBrowser-DbYpKPA3.d.mts} +8 -3
- package/dist/InteractiveBrowser.d.mts +1 -1
- package/dist/InteractiveBrowser.mjs +1 -1
- package/dist/LiveText-D7WxSY-h.d.mts +96 -0
- package/dist/LiveText-DRzUabZi.mjs +151 -0
- package/dist/LiveText-DRzUabZi.mjs.map +1 -0
- package/dist/LiveText.d.mts +2 -0
- package/dist/LiveText.mjs +2 -0
- package/dist/{ThreadObject-Osn-FmcF.d.mts → ThreadObject-BcoRabnQ.d.mts} +27 -11
- package/dist/{ThreadObject-Cr1CFWXb.mjs → ThreadObject-EChaDQBT.mjs} +47 -18
- package/dist/ThreadObject-EChaDQBT.mjs.map +1 -0
- package/dist/ThreadObject.d.mts +1 -1
- package/dist/ThreadObject.mjs +1 -1
- package/dist/WakeScheduler.d.mts +1 -1
- package/dist/WakeScheduler.mjs +7 -3
- package/dist/WakeScheduler.mjs.map +1 -1
- package/dist/{boundary-BguazVkh.mjs → boundary-BLbZMBl2.mjs} +2 -2
- package/dist/boundary-BLbZMBl2.mjs.map +1 -0
- package/dist/{browser-failure-DECzRY3H.mjs → browser-failure-BrL9H7IG.mjs} +6 -2
- package/dist/browser-failure-BrL9H7IG.mjs.map +1 -0
- package/dist/index.d.mts +8 -7
- package/dist/index.mjs +7 -6
- package/dist/{prepared-admission-w2Kq32_k.mjs → prepared-admission-mGUYbSH_.mjs} +4 -3
- package/dist/prepared-admission-mGUYbSH_.mjs.map +1 -0
- package/package.json +1 -1
- package/src/Alarm.ts +128 -82
- package/src/BrowserCredentials.ts +3 -1
- package/src/BrowserRestCapture.ts +9 -2
- package/src/BrowserRestCrawl.ts +14 -18
- package/src/BrowserSession.ts +10 -12
- package/src/BrowserUse.ts +5 -1
- package/src/CloudflareAiGateway.ts +12 -8
- package/src/CloudflareBindings.ts +5 -1
- package/src/CloudflareCodeMode.ts +9 -1
- package/src/CloudflareConfig.ts +10 -3
- package/src/CloudflareMemory.ts +5 -1
- package/src/CloudflareScheduling.ts +7 -2
- package/src/CloudflareSubscriptions.ts +9 -2
- package/src/CloudflareThreadClient.ts +15 -148
- package/src/InteractiveBrowser.ts +10 -12
- package/src/LiveText.ts +141 -0
- package/src/ThreadObject.ts +13 -8
- package/src/WakeScheduler.ts +5 -1
- package/src/index.ts +1 -0
- package/src/internal/boundary.ts +1 -1
- package/src/internal/browser-binding.ts +5 -1
- package/src/internal/browser-credentials.ts +5 -1
- package/src/internal/browser-failure.ts +6 -2
- package/src/internal/browser-file-selection.ts +1 -1
- package/src/internal/browser-quick-action.ts +5 -1
- package/src/internal/browser-readonly-live-view.ts +9 -2
- package/src/internal/browser-session-lifecycle.ts +10 -2
- package/src/internal/crypto.ts +5 -2
- package/src/internal/due-queue.ts +2 -1
- package/src/internal/host-protocol-error.ts +23 -0
- package/src/internal/layers.ts +45 -22
- package/src/internal/live-text-observation.ts +8 -0
- package/src/internal/live-text-protocol.ts +10 -9
- package/src/internal/live-text.ts +28 -10
- package/src/internal/message-delivery.ts +7 -1
- package/src/internal/prepared-admission.ts +2 -1
- package/src/internal/progress-wait.ts +6 -1
- package/src/internal/transport.ts +2 -1
- package/dist/Alarm-C257DCAJ.mjs.map +0 -1
- package/dist/BrowserSession-CfivQ5JY.mjs.map +0 -1
- package/dist/CloudflareBrowser-Vt8qTdYW.mjs.map +0 -1
- package/dist/CloudflareThreadClient-CmlojpjC.d.mts +0 -2211
- package/dist/CloudflareThreadClient-CnvMXPmV.mjs.map +0 -1
- package/dist/InteractiveBrowser-nukKxc87.mjs.map +0 -1
- package/dist/ThreadObject-Cr1CFWXb.mjs.map +0 -1
- package/dist/boundary-BguazVkh.mjs.map +0 -1
- package/dist/browser-failure-DECzRY3H.mjs.map +0 -1
- package/dist/prepared-admission-w2Kq32_k.mjs.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.mjs";
|
|
2
2
|
import { DurableAlarmError, DurableObjectContext, ThreadObjectPlacement } from "./CloudflareBindings.mjs";
|
|
3
3
|
import { AuxiliaryDispatchMillis, CloudflareDurableRuntimeConfig } from "./CloudflareConfig.mjs";
|
|
4
|
-
import { r as safeCauseMessage } from "./boundary-
|
|
4
|
+
import { r as safeCauseMessage } from "./boundary-BLbZMBl2.mjs";
|
|
5
5
|
import { CurrentNativeSource } from "@yielded/agent-storage-cloudflare/port-routing";
|
|
6
6
|
import "@yielded/agent/agent-registration";
|
|
7
7
|
import { DurableAgentRuntime, DurableRuntimeConfig, RecoveryBlocked, RecoveryFailure, RecoverySweepResult, isolateRecovery } from "@yielded/agent/durable-agent-runtime";
|
|
@@ -9,10 +9,29 @@ import { SubmissionId, ThreadId } from "@yielded/agent/identifiers";
|
|
|
9
9
|
import { AbortIntentRequest, SubmissionLedger } from "@yielded/agent/submission-ledger";
|
|
10
10
|
import { ThreadProjectionMaintenance } from "@yielded/agent/thread-projection-maintenance";
|
|
11
11
|
import { WakeScheduler } from "@yielded/agent/wake-scheduler";
|
|
12
|
-
import {
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import
|
|
12
|
+
import { DurableObjectAlarm, DurableObjectState, DurableObjectStorage } from "effect-cf";
|
|
13
|
+
import * as Cause from "effect/Cause";
|
|
14
|
+
import * as Clock from "effect/Clock";
|
|
15
|
+
import * as Context from "effect/Context";
|
|
16
|
+
import * as DateTime from "effect/DateTime";
|
|
17
|
+
import * as Deferred from "effect/Deferred";
|
|
18
|
+
import * as Effect from "effect/Effect";
|
|
19
|
+
import * as ErrorReporter from "effect/ErrorReporter";
|
|
20
|
+
import * as Exit from "effect/Exit";
|
|
21
|
+
import * as Fiber from "effect/Fiber";
|
|
22
|
+
import * as Layer from "effect/Layer";
|
|
23
|
+
import * as Option from "effect/Option";
|
|
24
|
+
import * as Random from "effect/Random";
|
|
25
|
+
import * as Ref from "effect/Ref";
|
|
26
|
+
import * as Result from "effect/Result";
|
|
27
|
+
import * as Scheduler from "effect/Scheduler";
|
|
28
|
+
import * as Schema from "effect/Schema";
|
|
29
|
+
import * as Scope from "effect/Scope";
|
|
30
|
+
import * as Semaphore from "effect/Semaphore";
|
|
31
|
+
import * as SqlClient from "effect/sql/SqlClient";
|
|
32
|
+
import * as SqlError from "effect/sql/SqlError";
|
|
33
|
+
import * as Stream from "effect/Stream";
|
|
34
|
+
import * as Struct from "effect/Struct";
|
|
16
35
|
//#region src/internal/due-queue.ts
|
|
17
36
|
const LaneId = Schema.NonEmptyString.check(Schema.isMaxLength(256));
|
|
18
37
|
const HostLaneId = LaneId.check(Schema.isPattern(/^(?!effect-agent:)/, { message: "The effect-agent: namespace is reserved for framework maintenance lanes" }));
|
|
@@ -334,7 +353,7 @@ const alarmFailure = (operation) => (cause) => DurableAlarmError.make({
|
|
|
334
353
|
cause
|
|
335
354
|
});
|
|
336
355
|
const makeStorageEffect = Effect.gen(function* () {
|
|
337
|
-
const sql = yield* SqlClient;
|
|
356
|
+
const sql = yield* SqlClient.SqlClient;
|
|
338
357
|
const { ctx } = yield* DurableObjectContext;
|
|
339
358
|
const invalidate$1 = Effect.sync(() => invalidate(ctx.storage));
|
|
340
359
|
return (operation, execute) => Effect.flatMap(Effect.serviceOption(sql.transactionService), (current) => {
|
|
@@ -394,7 +413,7 @@ const CurrentCheckpoint = Context.Reference("@yielded/agent/cloudflare/CurrentCh
|
|
|
394
413
|
/** One source transaction owns queue intent and the library checkpoint through commit. */
|
|
395
414
|
const makeAlarmOperation = Effect.gen(function* () {
|
|
396
415
|
const alarms = yield* ThreadMaintenanceAlarm;
|
|
397
|
-
const sql = yield* SqlClient;
|
|
416
|
+
const sql = yield* SqlClient.SqlClient;
|
|
398
417
|
const { ctx } = yield* DurableObjectContext;
|
|
399
418
|
const queue = make(ctx.storage);
|
|
400
419
|
const transaction = (body) => alarms.transaction((mutations) => Effect.withFiber((owner) => {
|
|
@@ -405,14 +424,14 @@ const makeAlarmOperation = Effect.gen(function* () {
|
|
|
405
424
|
})), () => {
|
|
406
425
|
active = false;
|
|
407
426
|
});
|
|
408
|
-
}), { sqlClient: sql }).pipe(Effect.mapError((cause) => cause instanceof DurableObjectStorage.StorageOperationError ? SqlError.make({ reason: UnknownError.make({
|
|
427
|
+
}), { sqlClient: sql }).pipe(Effect.mapError((cause) => cause instanceof DurableObjectStorage.StorageOperationError ? SqlError.SqlError.make({ reason: SqlError.UnknownError.make({
|
|
409
428
|
operation: "commit maintenance checkpoint",
|
|
410
429
|
message: "Source facts and maintenance checkpoint could not commit",
|
|
411
430
|
cause
|
|
412
431
|
}) }) : cause));
|
|
413
432
|
const withTransaction = (body) => Effect.withFiber((fiber) => {
|
|
414
433
|
const ambient = Context.getOption(fiber.context, sql.transactionService);
|
|
415
|
-
if (ambient._tag === "Some" && !ownsTransaction(ctx.storage, ambient.value[1])) return Effect.fail(SqlError.make({ reason: UnknownError.make({
|
|
434
|
+
if (ambient._tag === "Some" && !ownsTransaction(ctx.storage, ambient.value[1])) return Effect.fail(SqlError.SqlError.make({ reason: SqlError.UnknownError.make({
|
|
416
435
|
operation: "begin maintenance source transaction",
|
|
417
436
|
message: "Use ThreadMutationGate.withTransaction at the outermost source transaction",
|
|
418
437
|
cause: "Unwrapped SQL transaction cannot own buffered maintenance intent"
|
|
@@ -420,7 +439,7 @@ const makeAlarmOperation = Effect.gen(function* () {
|
|
|
420
439
|
let frame;
|
|
421
440
|
return Effect.uninterruptibleMask((restore) => Effect.onExitPrimitive(transaction((owner) => {
|
|
422
441
|
const current = Context.getOption(owner.context, sql.transactionService);
|
|
423
|
-
if (current._tag === "None") return SqlError.make({ reason: UnknownError.make({
|
|
442
|
+
if (current._tag === "None") return SqlError.SqlError.make({ reason: SqlError.UnknownError.make({
|
|
424
443
|
operation: "begin maintenance source transaction",
|
|
425
444
|
message: "SQL transaction unavailable",
|
|
426
445
|
cause: "SQL transaction unavailable"
|
|
@@ -432,7 +451,7 @@ const makeAlarmOperation = Effect.gen(function* () {
|
|
|
432
451
|
queue.flush(started);
|
|
433
452
|
return value;
|
|
434
453
|
},
|
|
435
|
-
catch: (cause) => SqlError.make({ reason: UnknownError.make({
|
|
454
|
+
catch: (cause) => SqlError.SqlError.make({ reason: SqlError.UnknownError.make({
|
|
436
455
|
cause,
|
|
437
456
|
operation: "flush maintenance due queue",
|
|
438
457
|
message: "Maintenance intent could not commit"
|
|
@@ -441,7 +460,7 @@ const makeAlarmOperation = Effect.gen(function* () {
|
|
|
441
460
|
}), (exit) => {
|
|
442
461
|
if (frame !== void 0) queue.finish(frame, Exit.isSuccess(exit));
|
|
443
462
|
}).pipe(Effect.provideService(Scheduler.PreventSchedulerYield, true)));
|
|
444
|
-
}).pipe(Effect.provideService(SqlClient, sql));
|
|
463
|
+
}).pipe(Effect.provideService(SqlClient.SqlClient, sql));
|
|
445
464
|
const run = (operation, execute) => {
|
|
446
465
|
const commit = Effect.withFiber((fiber) => {
|
|
447
466
|
const tx = fiber.getRef(CurrentCheckpoint);
|
|
@@ -697,7 +716,7 @@ const CurrentMutationLanes = Context.Reference("@effect-agent/platform-cloudflar
|
|
|
697
716
|
var ThreadMutationGate = class ThreadMutationGate extends Context.Service()("@effect-agent/platform-cloudflare/internal/ThreadMutationGate") {
|
|
698
717
|
static layer = Layer.effect(this)(Effect.gen(function* () {
|
|
699
718
|
const { ctx } = yield* DurableObjectContext;
|
|
700
|
-
const sql = yield* SqlClient;
|
|
719
|
+
const sql = yield* SqlClient.SqlClient;
|
|
701
720
|
const dueQueue = make(ctx.storage);
|
|
702
721
|
const placement = yield* Effect.serviceOption(ThreadObjectPlacement);
|
|
703
722
|
const singleThread = Option.isSome(placement) && placement.value.threadId !== void 0;
|
|
@@ -725,6 +744,7 @@ var ThreadMutationGate = class ThreadMutationGate extends Context.Service()("@ef
|
|
|
725
744
|
for (const listener of pending) listener();
|
|
726
745
|
});
|
|
727
746
|
const minimumAlarmDelay = Math.max(1, Math.ceil(config.alarmBackoffBase / 2));
|
|
747
|
+
const recoveryDelay = config.recoveryWindowMillis || minimumAlarmDelay;
|
|
728
748
|
const runTransaction = yield* makeStorageOperation;
|
|
729
749
|
const { run: runAlarmTransaction, withTransaction } = yield* makeAlarmOperation;
|
|
730
750
|
const validateSourceBoundary = Effect.flatMap(Effect.serviceOption(sql.transactionService), (current) => current._tag === "Some" && buffering(ctx.storage) && !ownsTransaction(ctx.storage, current.value[1]) ? Effect.fail(DurableAlarmError.make({
|
|
@@ -738,6 +758,7 @@ var ThreadMutationGate = class ThreadMutationGate extends Context.Service()("@ef
|
|
|
738
758
|
const schedule = Effect.fnUntraced(function* (id, dueAt, progressCursor) {
|
|
739
759
|
yield* validateSourceBoundary;
|
|
740
760
|
const now = yield* Clock.currentTimeMillis;
|
|
761
|
+
const scheduling = yield* DurableObjectAlarm.ScheduleConfiguration;
|
|
741
762
|
const enroll = async (transaction, checkpoint) => {
|
|
742
763
|
if (progressCursor === void 0) dueQueue.dirty(id, dueAt);
|
|
743
764
|
else if (dueQueue.progress(id, dueAt, progressCursor) && (id === "effect-agent:native" || id === "effect-agent:publication")) {
|
|
@@ -748,8 +769,8 @@ var ThreadMutationGate = class ThreadMutationGate extends Context.Service()("@ef
|
|
|
748
769
|
dirty: state.dirty + 1n
|
|
749
770
|
})));
|
|
750
771
|
}
|
|
751
|
-
const next$
|
|
752
|
-
if (Number.isFinite(next$
|
|
772
|
+
const next$3 = next(dueQueue.read());
|
|
773
|
+
if (Number.isFinite(next$3)) checkpoint.earlier(Math.max(next$3, now + (scheduling.dispatchAfterEvent === true ? 0 : minimumAlarmDelay)));
|
|
753
774
|
};
|
|
754
775
|
yield* runAlarmTransaction("schedule maintenance lane", enroll);
|
|
755
776
|
yield* notify;
|
|
@@ -771,7 +792,7 @@ var ThreadMutationGate = class ThreadMutationGate extends Context.Service()("@ef
|
|
|
771
792
|
dirty: state.dirty + (invalidatesRecovery && !nativeSource ? 1n : 0n)
|
|
772
793
|
})));
|
|
773
794
|
const deadline = next(dueQueue.read());
|
|
774
|
-
if (Number.isFinite(deadline)) checkpoint.earlier(Math.max(deadline, now +
|
|
795
|
+
if (Number.isFinite(deadline)) checkpoint.earlier(Math.max(deadline, now + recoveryDelay));
|
|
775
796
|
});
|
|
776
797
|
yield* failpoint.hit("maintenance:dirty:after");
|
|
777
798
|
yield* Ref.update(activeMutations, (active) => active + 1);
|
|
@@ -868,6 +889,7 @@ var ThreadMaintenance = class ThreadMaintenance extends Context.Service()("@effe
|
|
|
868
889
|
const alarms = yield* ThreadMaintenanceAlarm;
|
|
869
890
|
const config = yield* CloudflareDurableRuntimeConfig;
|
|
870
891
|
const { ctx } = yield* DurableObjectContext;
|
|
892
|
+
const execution = DurableObjectState.fromDurableObjectState(ctx);
|
|
871
893
|
const dueQueue = make(ctx.storage);
|
|
872
894
|
const storage = DurableObjectStorage.fromDurableObjectStorage(ctx.storage);
|
|
873
895
|
const runStorage = yield* makeStorageEffect;
|
|
@@ -930,8 +952,8 @@ var ThreadMaintenance = class ThreadMaintenance extends Context.Service()("@effe
|
|
|
930
952
|
const now = yield* Clock.currentTimeMillis;
|
|
931
953
|
const claimed = yield* runAlarmTransaction("charge maintenance attempt", async (_transaction, checkpoint) => {
|
|
932
954
|
const claimed = dueQueue.claim(selected, now);
|
|
933
|
-
const next$
|
|
934
|
-
if (Number.isFinite(next$
|
|
955
|
+
const next$4 = next(dueQueue.read());
|
|
956
|
+
if (Number.isFinite(next$4)) checkpoint.at(Math.max(now + minimumAlarmDelay, next$4));
|
|
935
957
|
else checkpoint.cancel();
|
|
936
958
|
return claimed;
|
|
937
959
|
});
|
|
@@ -1141,8 +1163,8 @@ var ThreadMaintenance = class ThreadMaintenance extends Context.Service()("@effe
|
|
|
1141
1163
|
if (!initialized) await transaction.put(MAINTENANCE_STATE_KEY, encodeMaintenanceState(state));
|
|
1142
1164
|
const native = state.dirty > state.processed ? state.retry?.generation === state.dirty ? state.retry.notBefore : rows.find((row) => row.id === "effect-agent:native")?.dueAt ?? now + minimumAlarmDelay : null;
|
|
1143
1165
|
dueQueue.checkpointNative(native);
|
|
1144
|
-
const next$
|
|
1145
|
-
if (Number.isFinite(next$
|
|
1166
|
+
const next$1 = next(dueQueue.read());
|
|
1167
|
+
if (Number.isFinite(next$1)) checkpoint.earlier(Math.max(now + minimumAlarmDelay, next$1));
|
|
1146
1168
|
});
|
|
1147
1169
|
yield* failpoint.hit("maintenance:ensure:after");
|
|
1148
1170
|
});
|
|
@@ -1216,8 +1238,8 @@ var ThreadMaintenance = class ThreadMaintenance extends Context.Service()("@effe
|
|
|
1216
1238
|
const charged = observed.charged.get(row.id) === row.revision ? row : dueQueue.claim(row, now);
|
|
1217
1239
|
if (charged !== void 0) dueQueue.complete(charged, now + backoffDelay(charged.stalls, jitter));
|
|
1218
1240
|
}
|
|
1219
|
-
const next$
|
|
1220
|
-
if (Number.isFinite(next$
|
|
1241
|
+
const next$5 = next(dueQueue.read());
|
|
1242
|
+
if (Number.isFinite(next$5)) checkpoint.at(Math.max(now + minimumAlarmDelay, next$5));
|
|
1221
1243
|
else checkpoint.cancel();
|
|
1222
1244
|
});
|
|
1223
1245
|
}));
|
|
@@ -1234,10 +1256,13 @@ var ThreadMaintenance = class ThreadMaintenance extends Context.Service()("@effe
|
|
|
1234
1256
|
activeAtStart
|
|
1235
1257
|
};
|
|
1236
1258
|
}));
|
|
1237
|
-
const attemptSelected = Effect.fnUntraced(function* (selected, previousWaits, yieldAfter, recovery) {
|
|
1238
|
-
yield* recoverThread(selected.threadId, recovery);
|
|
1259
|
+
const attemptSelected = Effect.fnUntraced(function* (selected, previousWaits, yieldAfter, recovery, admitted = false) {
|
|
1260
|
+
if (!admitted) yield* recoverThread(selected.threadId, recovery);
|
|
1239
1261
|
let bindingFailure;
|
|
1240
|
-
const settlement = recovery.faults.has(selected.threadId) ? Option.none() : yield* runtime.processThreadHead(selected.threadId, {
|
|
1262
|
+
const settlement = recovery.faults.has(selected.threadId) ? Option.none() : yield* runtime.processThreadHead(selected.threadId, {
|
|
1263
|
+
yieldAfter,
|
|
1264
|
+
...admitted ? { admittedSubmissionId: selected.submissionId } : {}
|
|
1265
|
+
}).pipe(Effect.provideService(CurrentNativeSource, true), Effect.catchTag("BindingUnavailable", (failure) => {
|
|
1241
1266
|
bindingFailure = failure;
|
|
1242
1267
|
return Effect.succeed(Option.none());
|
|
1243
1268
|
}));
|
|
@@ -1513,7 +1538,7 @@ var ThreadMaintenance = class ThreadMaintenance extends Context.Service()("@effe
|
|
|
1513
1538
|
message: `No handler registered for scheduled lane: ${row.id}`
|
|
1514
1539
|
});
|
|
1515
1540
|
});
|
|
1516
|
-
const dispatch = Effect.fnUntraced(function* (yieldAfter, dispatchUntil, observed) {
|
|
1541
|
+
const dispatch = Effect.fnUntraced(function* (yieldAfter, dispatchUntil, observed, admission) {
|
|
1517
1542
|
const leanSelection = framework.singleThreadRuntime === runtime && publication === emptyPublication && host.lanes.length === 0 && framework.lanes.length === 0;
|
|
1518
1543
|
const notified = leanSelection ? Effect.never : (yield* Stream.toPull(wakes.wakes)).pipe(Effect.asVoid, Effect.catch(() => Effect.never));
|
|
1519
1544
|
const started = yield* beginNative(observed);
|
|
@@ -1566,7 +1591,16 @@ var ThreadMaintenance = class ThreadMaintenance extends Context.Service()("@effe
|
|
|
1566
1591
|
let native;
|
|
1567
1592
|
let result;
|
|
1568
1593
|
let backlog;
|
|
1569
|
-
if (leanSelection) {
|
|
1594
|
+
if (leanSelection && admission !== void 0 && started._tag === "Actionable") {
|
|
1595
|
+
dispatch.dispatched++;
|
|
1596
|
+
dispatch.active.set(admission.threadId, yield* fork(attemptSelected(admission, [], yieldAfter, recovery, true)));
|
|
1597
|
+
result = {
|
|
1598
|
+
phase: "actionable",
|
|
1599
|
+
nonterminal: started.nonterminal,
|
|
1600
|
+
nextAttemptAt: void 0,
|
|
1601
|
+
dispatched: true
|
|
1602
|
+
};
|
|
1603
|
+
} else if (leanSelection) {
|
|
1570
1604
|
result = yield* advance(started, yieldAfter, observed, recovery, dispatch);
|
|
1571
1605
|
recovery.started = true;
|
|
1572
1606
|
yield* Deferred.succeed(recovery.queue, []);
|
|
@@ -1759,8 +1793,8 @@ var ThreadMaintenance = class ThreadMaintenance extends Context.Service()("@effe
|
|
|
1759
1793
|
settled: dispatch.settled
|
|
1760
1794
|
};
|
|
1761
1795
|
});
|
|
1762
|
-
const pass = Effect.fnUntraced(function* (yieldAfter, dispatchUntil, observed) {
|
|
1763
|
-
const concurrent = yield* Effect.exit(Effect.scoped(dispatch(yieldAfter, dispatchUntil, observed)).pipe(Effect.provideService(ThreadMutationGate, mutations)));
|
|
1796
|
+
const pass = Effect.fnUntraced(function* (yieldAfter, dispatchUntil, observed, admission) {
|
|
1797
|
+
const concurrent = yield* Effect.exit(Effect.scoped(dispatch(yieldAfter, dispatchUntil, observed, admission)).pipe(Effect.provideService(ThreadMutationGate, mutations)));
|
|
1764
1798
|
const afterNative = yield* Effect.gen(function* () {
|
|
1765
1799
|
const lanes = [
|
|
1766
1800
|
recoveryEventLane,
|
|
@@ -1831,9 +1865,13 @@ var ThreadMaintenance = class ThreadMaintenance extends Context.Service()("@effe
|
|
|
1831
1865
|
const { state } = await readMaintenanceState(transaction);
|
|
1832
1866
|
const native = active > 0 || state.dirty > state.processed ? state.retry?.generation === state.dirty && active === 0 ? Math.max(now + minimumAlarmDelay, state.retry.notBefore) : state.dirty === observed.generation && active === 0 ? result.nextAttemptAt ?? now + minimumAlarmDelay : now + minimumAlarmDelay : Infinity;
|
|
1833
1867
|
dueQueue.checkpointNative(Number.isFinite(native) ? native : null);
|
|
1834
|
-
const next$
|
|
1835
|
-
if (Number.isFinite(next$
|
|
1836
|
-
checkpoint.at(Math.max(now + minimumAlarmDelay, next$
|
|
1868
|
+
const next$2 = next(dueQueue.read());
|
|
1869
|
+
if (Number.isFinite(next$2)) {
|
|
1870
|
+
checkpoint.at(Math.max(now + minimumAlarmDelay, next$2));
|
|
1871
|
+
return "rearmed";
|
|
1872
|
+
}
|
|
1873
|
+
if (config.recoveryWindowMillis > 0 && observed.charged.size > 0) {
|
|
1874
|
+
checkpoint.at(now + config.recoveryWindowMillis);
|
|
1837
1875
|
return "rearmed";
|
|
1838
1876
|
}
|
|
1839
1877
|
checkpoint.cancel();
|
|
@@ -1857,28 +1895,30 @@ var ThreadMaintenance = class ThreadMaintenance extends Context.Service()("@effe
|
|
|
1857
1895
|
});
|
|
1858
1896
|
return report;
|
|
1859
1897
|
});
|
|
1898
|
+
const runPass = Effect.fnUntraced(function* (admission) {
|
|
1899
|
+
const now = yield* Clock.currentTimeMillis;
|
|
1900
|
+
const yieldAfter = DateTime.makeUnsafe(now + 6e5);
|
|
1901
|
+
const dispatchUntil = DateTime.makeUnsafe(now + 84e4);
|
|
1902
|
+
const observed = {
|
|
1903
|
+
nativeOnly: false,
|
|
1904
|
+
queue: /* @__PURE__ */ new Map(),
|
|
1905
|
+
charged: /* @__PURE__ */ new Map(),
|
|
1906
|
+
available: /* @__PURE__ */ new Map()
|
|
1907
|
+
};
|
|
1908
|
+
return yield* alarms.deferWakes(maintenancePassGate.withPermit(dueQueue.withView(Effect.scoped(pass(yieldAfter, dispatchUntil, observed, admission))).pipe(Effect.onErrorIf(() => true, () => rearmFailure(observed))))).pipe(hints.withHintsDeferred, Effect.catchTags({
|
|
1909
|
+
StorageOperationError: (error) => alarmFailure("defer maintenance wakes")(error),
|
|
1910
|
+
InvalidScheduleConfigurationError: (error) => alarmFailure("defer maintenance wakes")(error)
|
|
1911
|
+
}));
|
|
1912
|
+
}, Effect.timeoutOrElse({
|
|
1913
|
+
duration: "14 minutes",
|
|
1914
|
+
orElse: () => DurableAlarmError.make({
|
|
1915
|
+
operation: "maintenance pass deadline",
|
|
1916
|
+
message: "The maintenance event exceeded its 14 minute deadline; durable recovery remains pending"
|
|
1917
|
+
})
|
|
1918
|
+
}), Effect.ensuring(reportParked));
|
|
1860
1919
|
return ThreadMaintenance.of({
|
|
1861
|
-
pass:
|
|
1862
|
-
|
|
1863
|
-
const yieldAfter = DateTime.makeUnsafe(now + 6e5);
|
|
1864
|
-
const dispatchUntil = DateTime.makeUnsafe(now + 84e4);
|
|
1865
|
-
const observed = {
|
|
1866
|
-
nativeOnly: false,
|
|
1867
|
-
queue: /* @__PURE__ */ new Map(),
|
|
1868
|
-
charged: /* @__PURE__ */ new Map(),
|
|
1869
|
-
available: /* @__PURE__ */ new Map()
|
|
1870
|
-
};
|
|
1871
|
-
return yield* alarms.deferWakes(maintenancePassGate.withPermit(dueQueue.withView(Effect.scoped(pass(yieldAfter, dispatchUntil, observed))).pipe(Effect.onErrorIf(() => true, () => rearmFailure(observed))))).pipe(hints.withHintsDeferred, Effect.catchTags({
|
|
1872
|
-
StorageOperationError: (error) => alarmFailure("defer maintenance wakes")(error),
|
|
1873
|
-
InvalidScheduleConfigurationError: (error) => alarmFailure("defer maintenance wakes")(error)
|
|
1874
|
-
}));
|
|
1875
|
-
}).pipe(Effect.timeoutOrElse({
|
|
1876
|
-
duration: "14 minutes",
|
|
1877
|
-
orElse: () => DurableAlarmError.make({
|
|
1878
|
-
operation: "maintenance pass deadline",
|
|
1879
|
-
message: "The maintenance event exceeded its 14 minute deadline; durable recovery remains pending"
|
|
1880
|
-
})
|
|
1881
|
-
}), Effect.ensuring(reportParked)),
|
|
1920
|
+
pass: runPass(void 0),
|
|
1921
|
+
start: (admission) => execution.waitUntil(runPass(admission)),
|
|
1882
1922
|
ensureAlarm: mutations.withSnapshot(() => ensureAlarm()).pipe(Effect.tap(() => reportParked)),
|
|
1883
1923
|
withMutation: (body) => mutations.withMutation(body.pipe(Effect.tap(() => publishCommitted.pipe(Effect.provide(publicationContext)))))
|
|
1884
1924
|
});
|
|
@@ -1887,4 +1927,4 @@ var ThreadMaintenance = class ThreadMaintenance extends Context.Service()("@effe
|
|
|
1887
1927
|
//#endregion
|
|
1888
1928
|
export { Messages as _, ThreadMaintenance as a, Publication as b, ThreadMessageDelivery as c, ThreadPublication as d, ThreadRecoveryEvents as f, Lifecycle as g, HostLaneId as h, ThreadHostMaintenance as i, ThreadMutationGate as l, publishCommitted as m, DurableAlarmService as n, ThreadMaintenanceAlarm as o, ThreadRecoveryFaultEvent as p, MaintenancePassReport as r, ThreadMaintenanceFailpoint as s, Alarm_exports as t, ThreadNativeMaintenance as u, Native as v, Projection as y };
|
|
1889
1929
|
|
|
1890
|
-
//# sourceMappingURL=Alarm-
|
|
1930
|
+
//# sourceMappingURL=Alarm-4qf-iCXC.mjs.map
|