@bastani/atomic 0.9.44-alpha.6 → 0.9.44
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/CHANGELOG.md +55 -0
- package/dist/builtin/intercom/CHANGELOG.md +18 -0
- package/dist/builtin/intercom/index.bundle.mjs +32 -4
- package/dist/builtin/intercom/package.json +1 -1
- package/dist/builtin/mcp/CHANGELOG.md +7 -0
- package/dist/builtin/mcp/package.json +1 -1
- package/dist/builtin/subagents/CHANGELOG.md +9 -0
- package/dist/builtin/subagents/package.json +1 -1
- package/dist/builtin/web-access/package.json +1 -1
- package/dist/builtin/workflows/CHANGELOG.md +31 -0
- package/dist/builtin/workflows/package.json +1 -1
- package/dist/builtin/workflows/src/extension/index.bundle.mjs +141 -38
- package/dist/builtin/workflows/src/extension/local-worker-entry.mjs +139 -30
- package/dist/builtin/workflows/src/index.js +139 -30
- package/dist/builtin/workflows/src/local-worker-entry.mjs +139 -30
- package/npm-shrinkwrap.json +32 -32
- package/package.json +3 -3
|
@@ -58349,6 +58349,9 @@ var init_workflow_stage_target = __esm(() => {
|
|
|
58349
58349
|
});
|
|
58350
58350
|
|
|
58351
58351
|
// dist/builtin/workflows/src/shared/pending-stage-status.ts
|
|
58352
|
+
function isAddressableStageStatus(status) {
|
|
58353
|
+
return ADDRESSABLE_STAGE_STATUSES.has(status);
|
|
58354
|
+
}
|
|
58352
58355
|
function workflowBoundarySegments(runs, runId) {
|
|
58353
58356
|
return createWorkflowBoundarySegmentsResolver(runs)(runId);
|
|
58354
58357
|
}
|
|
@@ -58471,9 +58474,17 @@ function createStagePathPatternIndex(patterns) {
|
|
|
58471
58474
|
}
|
|
58472
58475
|
};
|
|
58473
58476
|
}
|
|
58477
|
+
var ADDRESSABLE_STAGE_STATUSES;
|
|
58474
58478
|
var init_pending_stage_status = __esm(() => {
|
|
58475
58479
|
init_store_internal();
|
|
58476
58480
|
init_workflow_stage_target();
|
|
58481
|
+
ADDRESSABLE_STAGE_STATUSES = new Set([
|
|
58482
|
+
"pending",
|
|
58483
|
+
"running",
|
|
58484
|
+
"awaiting_input",
|
|
58485
|
+
"paused",
|
|
58486
|
+
"blocked"
|
|
58487
|
+
]);
|
|
58477
58488
|
});
|
|
58478
58489
|
|
|
58479
58490
|
// dist/builtin/workflows/src/shared/sticky-delivery-state-bound.ts
|
|
@@ -59187,7 +59198,7 @@ function registerPendingStageIntercomBridge(pi, activeStore, ownsRun = () => tru
|
|
|
59187
59198
|
stageName: stage.name,
|
|
59188
59199
|
target: stageRouteTarget(runs, rootRunId, run.id, stage.id, resolveBoundarySegments),
|
|
59189
59200
|
lifecycle: stage.sessionId === undefined && stage.sessionFile === undefined ? "pending" : "running",
|
|
59190
|
-
routeEligible: stage.pendingStageDeliveryAvailable === true && (stage.status
|
|
59201
|
+
routeEligible: stage.pendingStageDeliveryAvailable === true && isAddressableStageStatus(stage.status),
|
|
59191
59202
|
group: stage.intercomGroup ?? workflowInvocationIntercomGroup(rootRunId)
|
|
59192
59203
|
})),
|
|
59193
59204
|
...nonAgentNodes(run).map((node) => ({
|
|
@@ -59690,7 +59701,7 @@ function knownUninitializedStage(run, stageKey) {
|
|
|
59690
59701
|
if (candidates.length !== 1)
|
|
59691
59702
|
return;
|
|
59692
59703
|
const stage = candidates[0];
|
|
59693
|
-
return (stage.status
|
|
59704
|
+
return isAddressableStageStatus(stage.status) && stage.sessionId === undefined && stage.sessionFile === undefined ? stage : undefined;
|
|
59694
59705
|
}
|
|
59695
59706
|
function pendingStageDestination(run, entry) {
|
|
59696
59707
|
if (entry.stageId !== undefined) {
|
|
@@ -64371,15 +64382,74 @@ function isWorkflowPendingStageDeliveryFailure(error) {
|
|
|
64371
64382
|
return true;
|
|
64372
64383
|
return error?.code === "pending_stage_delivery_failed";
|
|
64373
64384
|
}
|
|
64374
|
-
function createWorkflowPendingStageDelivery(activeStore, runId, stageId, stageName, commit = (action) => action()) {
|
|
64385
|
+
function createWorkflowPendingStageDelivery(activeStore, runId, stageId, stageName, commit = (action) => action(), options = {}) {
|
|
64375
64386
|
let resolveReady;
|
|
64376
64387
|
let rejectReady;
|
|
64377
64388
|
let readyPromise;
|
|
64378
64389
|
let drainError;
|
|
64379
64390
|
let terminalError;
|
|
64380
64391
|
let drainPromise;
|
|
64392
|
+
let drainedSessionId;
|
|
64381
64393
|
let currentRecipient;
|
|
64382
|
-
|
|
64394
|
+
let lastProgressAt = Date.now();
|
|
64395
|
+
let stallReported = false;
|
|
64396
|
+
const progress = () => {
|
|
64397
|
+
lastProgressAt = Date.now();
|
|
64398
|
+
};
|
|
64399
|
+
const progressingCommit = async (action) => {
|
|
64400
|
+
try {
|
|
64401
|
+
return await commit(action);
|
|
64402
|
+
} finally {
|
|
64403
|
+
progress();
|
|
64404
|
+
}
|
|
64405
|
+
};
|
|
64406
|
+
const reportStall = (sessionId) => {
|
|
64407
|
+
if (stallReported)
|
|
64408
|
+
return;
|
|
64409
|
+
stallReported = true;
|
|
64410
|
+
const undelivered = [
|
|
64411
|
+
...activeStore.pendingStageMessagesFor(runId, stageId),
|
|
64412
|
+
...stageId === stageName ? [] : activeStore.pendingStageMessagesFor(runId, stageName)
|
|
64413
|
+
].map((entry) => `${entry.message.id} (direct → ${entry.stageKey})`).concat(stickyPendingStageEntriesForStage(activeStore, runId, stageId, stageName, sessionId === undefined ? undefined : { sessionId }).map((entry) => `${entry.message.id} (sticky → ${entry.targetPath ?? entry.stageKey})`));
|
|
64414
|
+
const listed = undelivered.slice(0, 10).join(", ");
|
|
64415
|
+
const more = undelivered.length > 10 ? `, and ${undelivered.length - 10} more` : "";
|
|
64416
|
+
const message = `atomic-workflows: stage "${stageName}" (${stageId}) is starting without its queued Intercom messages: ` + `no delivery progress for ${PENDING_STAGE_READY_STALL_MS / 1000}s; ` + `drain ${drainPromise === undefined ? "not running" : "running but hung"}; ` + `undelivered: ${listed.length === 0 ? "none" : `${listed}${more}`}. ` + "They stay queued and arrive live or on the stage's next drain.";
|
|
64417
|
+
try {
|
|
64418
|
+
(options.reportStall ?? console.warn)(message);
|
|
64419
|
+
} catch {}
|
|
64420
|
+
};
|
|
64421
|
+
const watchStall = (pending, sessionId, onStall) => {
|
|
64422
|
+
let timer;
|
|
64423
|
+
let settled = false;
|
|
64424
|
+
const check = () => {
|
|
64425
|
+
if (settled)
|
|
64426
|
+
return;
|
|
64427
|
+
const remaining = lastProgressAt + PENDING_STAGE_READY_STALL_MS - Date.now();
|
|
64428
|
+
if (remaining > 0) {
|
|
64429
|
+
timer = setTimeout(check, remaining);
|
|
64430
|
+
timer.unref?.();
|
|
64431
|
+
return;
|
|
64432
|
+
}
|
|
64433
|
+
reportStall(sessionId);
|
|
64434
|
+
onStall();
|
|
64435
|
+
};
|
|
64436
|
+
const stop = () => {
|
|
64437
|
+
settled = true;
|
|
64438
|
+
clearTimeout(timer);
|
|
64439
|
+
};
|
|
64440
|
+
pending.then(stop, stop);
|
|
64441
|
+
check();
|
|
64442
|
+
};
|
|
64443
|
+
const boundedDrain = (drain, sessionId) => {
|
|
64444
|
+
const waiting = new Promise((resolve, reject) => {
|
|
64445
|
+
drain.then(resolve, reject);
|
|
64446
|
+
watchStall(drain, sessionId, resolve);
|
|
64447
|
+
});
|
|
64448
|
+
waiting.catch(() => {});
|
|
64449
|
+
return waiting;
|
|
64450
|
+
};
|
|
64451
|
+
const hasUndeliveredExact = () => activeStore.pendingStageMessagesFor(runId, stageId).length > 0 || stageId !== stageName && activeStore.pendingStageMessagesFor(runId, stageName).length > 0;
|
|
64452
|
+
const hasUndelivered = (sessionId) => hasUndeliveredExact() || stickyPendingStageEntriesForStage(activeStore, runId, stageId, stageName, sessionId === undefined ? undefined : { sessionId }).length > 0;
|
|
64383
64453
|
const pendingReady = () => {
|
|
64384
64454
|
if (readyPromise === undefined) {
|
|
64385
64455
|
readyPromise = new Promise((resolve, reject) => {
|
|
@@ -64389,35 +64459,64 @@ function createWorkflowPendingStageDelivery(activeStore, runId, stageId, stageNa
|
|
|
64389
64459
|
}
|
|
64390
64460
|
return readyPromise;
|
|
64391
64461
|
};
|
|
64462
|
+
let followUp;
|
|
64463
|
+
const startDrain = (deliver, recipient) => {
|
|
64464
|
+
if (terminalError !== undefined)
|
|
64465
|
+
return Promise.resolve();
|
|
64466
|
+
drainError = undefined;
|
|
64467
|
+
progress();
|
|
64468
|
+
const attempt = deliverPendingStageMessages(activeStore, runId, stageId, stageName, async (from, message) => {
|
|
64469
|
+
progress();
|
|
64470
|
+
await deliver(from, message);
|
|
64471
|
+
progress();
|
|
64472
|
+
}, progressingCommit, recipient);
|
|
64473
|
+
const drain = attempt.then(() => {
|
|
64474
|
+
progress();
|
|
64475
|
+
drainedSessionId = recipient?.sessionId;
|
|
64476
|
+
resolveReady?.();
|
|
64477
|
+
readyPromise = undefined;
|
|
64478
|
+
resolveReady = undefined;
|
|
64479
|
+
rejectReady = undefined;
|
|
64480
|
+
if (drainPromise === drain)
|
|
64481
|
+
drainPromise = undefined;
|
|
64482
|
+
}, (error) => {
|
|
64483
|
+
progress();
|
|
64484
|
+
drainError = error;
|
|
64485
|
+
rejectReady?.(error);
|
|
64486
|
+
readyPromise = undefined;
|
|
64487
|
+
resolveReady = undefined;
|
|
64488
|
+
rejectReady = undefined;
|
|
64489
|
+
if (drainPromise === drain)
|
|
64490
|
+
drainPromise = undefined;
|
|
64491
|
+
throw error;
|
|
64492
|
+
});
|
|
64493
|
+
drainPromise = drain;
|
|
64494
|
+
return boundedDrain(drain, recipient?.sessionId);
|
|
64495
|
+
};
|
|
64496
|
+
const requestDrain = (deliver, recipient) => {
|
|
64497
|
+
const running = drainPromise;
|
|
64498
|
+
if (running === undefined)
|
|
64499
|
+
return startDrain(deliver, recipient);
|
|
64500
|
+
if (followUp !== undefined) {
|
|
64501
|
+
followUp.deliver = deliver;
|
|
64502
|
+
followUp.recipient = recipient;
|
|
64503
|
+
return boundedDrain(followUp.settled.promise, recipient?.sessionId);
|
|
64504
|
+
}
|
|
64505
|
+
const next = { deliver, recipient, settled: Promise.withResolvers() };
|
|
64506
|
+
next.settled.promise.catch(() => {});
|
|
64507
|
+
followUp = next;
|
|
64508
|
+
running.catch(() => {}).then(() => {
|
|
64509
|
+
if (followUp === next)
|
|
64510
|
+
followUp = undefined;
|
|
64511
|
+
return requestDrain(next.deliver, next.recipient);
|
|
64512
|
+
}).then(next.settled.resolve, next.settled.reject);
|
|
64513
|
+
return boundedDrain(next.settled.promise, recipient?.sessionId);
|
|
64514
|
+
};
|
|
64392
64515
|
return {
|
|
64393
64516
|
routeCapability: workflowPendingStageRouteCapability(activeStore, runId),
|
|
64394
64517
|
deliverPending(deliver, recipient) {
|
|
64395
64518
|
currentRecipient = recipient;
|
|
64396
|
-
|
|
64397
|
-
return drainPromise;
|
|
64398
|
-
if (terminalError !== undefined)
|
|
64399
|
-
return Promise.resolve();
|
|
64400
|
-
drainError = undefined;
|
|
64401
|
-
const attempt = deliverPendingStageMessages(activeStore, runId, stageId, stageName, deliver, commit, recipient);
|
|
64402
|
-
const drain = attempt.then(() => {
|
|
64403
|
-
resolveReady?.();
|
|
64404
|
-
readyPromise = undefined;
|
|
64405
|
-
resolveReady = undefined;
|
|
64406
|
-
rejectReady = undefined;
|
|
64407
|
-
if (drainPromise === drain)
|
|
64408
|
-
drainPromise = undefined;
|
|
64409
|
-
}, (error) => {
|
|
64410
|
-
drainError = error;
|
|
64411
|
-
rejectReady?.(error);
|
|
64412
|
-
readyPromise = undefined;
|
|
64413
|
-
resolveReady = undefined;
|
|
64414
|
-
rejectReady = undefined;
|
|
64415
|
-
if (drainPromise === drain)
|
|
64416
|
-
drainPromise = undefined;
|
|
64417
|
-
throw error;
|
|
64418
|
-
});
|
|
64419
|
-
drainPromise = drain;
|
|
64420
|
-
return drainPromise;
|
|
64519
|
+
return requestDrain(deliver, recipient);
|
|
64421
64520
|
},
|
|
64422
64521
|
ready(sessionId) {
|
|
64423
64522
|
if (!hasUndelivered(sessionId)) {
|
|
@@ -64427,6 +64526,8 @@ function createWorkflowPendingStageDelivery(activeStore, runId, stageId, stageNa
|
|
|
64427
64526
|
return Promise.reject(terminalError);
|
|
64428
64527
|
if (drainError !== undefined)
|
|
64429
64528
|
return Promise.reject(drainError);
|
|
64529
|
+
if (drainPromise === undefined && sessionId !== undefined && drainedSessionId === sessionId && !hasUndeliveredExact())
|
|
64530
|
+
return;
|
|
64430
64531
|
const ready = pendingReady();
|
|
64431
64532
|
if (sessionId !== undefined && activeStore.pendingStageMessagesFor(runId, stageId).length === 0 && activeStore.pendingStageMessagesFor(runId, stageName).length === 0) {
|
|
64432
64533
|
const entries = stickyPendingStageEntriesForStage(activeStore, runId, stageId, stageName, { sessionId });
|
|
@@ -64450,6 +64551,14 @@ function createWorkflowPendingStageDelivery(activeStore, runId, stageId, stageNa
|
|
|
64450
64551
|
rejectReady?.(error);
|
|
64451
64552
|
});
|
|
64452
64553
|
}
|
|
64554
|
+
watchStall(ready, sessionId, () => {
|
|
64555
|
+
if (readyPromise !== ready)
|
|
64556
|
+
return;
|
|
64557
|
+
resolveReady?.();
|
|
64558
|
+
readyPromise = undefined;
|
|
64559
|
+
resolveReady = undefined;
|
|
64560
|
+
rejectReady = undefined;
|
|
64561
|
+
});
|
|
64453
64562
|
return ready;
|
|
64454
64563
|
},
|
|
64455
64564
|
fail(reason) {
|
|
@@ -64577,7 +64686,7 @@ function toPendingStageSender(entry) {
|
|
|
64577
64686
|
lastActivity: entry.from.lastActivity ?? entry.message.timestamp
|
|
64578
64687
|
};
|
|
64579
64688
|
}
|
|
64580
|
-
var pendingDeliveryClaims, WorkflowPendingStageDeliveryFailedError;
|
|
64689
|
+
var pendingDeliveryClaims, WorkflowPendingStageDeliveryFailedError, PENDING_STAGE_READY_STALL_MS = 60000;
|
|
64581
64690
|
var init_pending_stage_delivery2 = __esm(() => {
|
|
64582
64691
|
init_run_owner_backend();
|
|
64583
64692
|
init_store_backend();
|
|
@@ -59243,6 +59243,9 @@ var init_workflow_stage_target = __esm(() => {
|
|
|
59243
59243
|
});
|
|
59244
59244
|
|
|
59245
59245
|
// dist/builtin/workflows/src/shared/pending-stage-status.ts
|
|
59246
|
+
function isAddressableStageStatus(status) {
|
|
59247
|
+
return ADDRESSABLE_STAGE_STATUSES.has(status);
|
|
59248
|
+
}
|
|
59246
59249
|
function workflowBoundarySegments(runs, runId) {
|
|
59247
59250
|
return createWorkflowBoundarySegmentsResolver(runs)(runId);
|
|
59248
59251
|
}
|
|
@@ -59365,9 +59368,17 @@ function createStagePathPatternIndex(patterns) {
|
|
|
59365
59368
|
}
|
|
59366
59369
|
};
|
|
59367
59370
|
}
|
|
59371
|
+
var ADDRESSABLE_STAGE_STATUSES;
|
|
59368
59372
|
var init_pending_stage_status = __esm(() => {
|
|
59369
59373
|
init_store_internal();
|
|
59370
59374
|
init_workflow_stage_target();
|
|
59375
|
+
ADDRESSABLE_STAGE_STATUSES = new Set([
|
|
59376
|
+
"pending",
|
|
59377
|
+
"running",
|
|
59378
|
+
"awaiting_input",
|
|
59379
|
+
"paused",
|
|
59380
|
+
"blocked"
|
|
59381
|
+
]);
|
|
59371
59382
|
});
|
|
59372
59383
|
|
|
59373
59384
|
// dist/builtin/workflows/src/shared/sticky-delivery-state-bound.ts
|
|
@@ -60081,7 +60092,7 @@ function registerPendingStageIntercomBridge(pi, activeStore, ownsRun = () => tru
|
|
|
60081
60092
|
stageName: stage.name,
|
|
60082
60093
|
target: stageRouteTarget(runs, rootRunId, run.id, stage.id, resolveBoundarySegments),
|
|
60083
60094
|
lifecycle: stage.sessionId === undefined && stage.sessionFile === undefined ? "pending" : "running",
|
|
60084
|
-
routeEligible: stage.pendingStageDeliveryAvailable === true && (stage.status
|
|
60095
|
+
routeEligible: stage.pendingStageDeliveryAvailable === true && isAddressableStageStatus(stage.status),
|
|
60085
60096
|
group: stage.intercomGroup ?? workflowInvocationIntercomGroup(rootRunId)
|
|
60086
60097
|
})),
|
|
60087
60098
|
...nonAgentNodes(run).map((node) => ({
|
|
@@ -60584,7 +60595,7 @@ function knownUninitializedStage(run, stageKey) {
|
|
|
60584
60595
|
if (candidates.length !== 1)
|
|
60585
60596
|
return;
|
|
60586
60597
|
const stage = candidates[0];
|
|
60587
|
-
return (stage.status
|
|
60598
|
+
return isAddressableStageStatus(stage.status) && stage.sessionId === undefined && stage.sessionFile === undefined ? stage : undefined;
|
|
60588
60599
|
}
|
|
60589
60600
|
function pendingStageDestination(run, entry) {
|
|
60590
60601
|
if (entry.stageId !== undefined) {
|
|
@@ -64158,15 +64169,74 @@ function isWorkflowPendingStageDeliveryFailure(error) {
|
|
|
64158
64169
|
return true;
|
|
64159
64170
|
return error?.code === "pending_stage_delivery_failed";
|
|
64160
64171
|
}
|
|
64161
|
-
function createWorkflowPendingStageDelivery(activeStore, runId, stageId, stageName, commit = (action) => action()) {
|
|
64172
|
+
function createWorkflowPendingStageDelivery(activeStore, runId, stageId, stageName, commit = (action) => action(), options = {}) {
|
|
64162
64173
|
let resolveReady;
|
|
64163
64174
|
let rejectReady;
|
|
64164
64175
|
let readyPromise;
|
|
64165
64176
|
let drainError;
|
|
64166
64177
|
let terminalError;
|
|
64167
64178
|
let drainPromise;
|
|
64179
|
+
let drainedSessionId;
|
|
64168
64180
|
let currentRecipient;
|
|
64169
|
-
|
|
64181
|
+
let lastProgressAt = Date.now();
|
|
64182
|
+
let stallReported = false;
|
|
64183
|
+
const progress = () => {
|
|
64184
|
+
lastProgressAt = Date.now();
|
|
64185
|
+
};
|
|
64186
|
+
const progressingCommit = async (action) => {
|
|
64187
|
+
try {
|
|
64188
|
+
return await commit(action);
|
|
64189
|
+
} finally {
|
|
64190
|
+
progress();
|
|
64191
|
+
}
|
|
64192
|
+
};
|
|
64193
|
+
const reportStall = (sessionId) => {
|
|
64194
|
+
if (stallReported)
|
|
64195
|
+
return;
|
|
64196
|
+
stallReported = true;
|
|
64197
|
+
const undelivered = [
|
|
64198
|
+
...activeStore.pendingStageMessagesFor(runId, stageId),
|
|
64199
|
+
...stageId === stageName ? [] : activeStore.pendingStageMessagesFor(runId, stageName)
|
|
64200
|
+
].map((entry) => `${entry.message.id} (direct → ${entry.stageKey})`).concat(stickyPendingStageEntriesForStage(activeStore, runId, stageId, stageName, sessionId === undefined ? undefined : { sessionId }).map((entry) => `${entry.message.id} (sticky → ${entry.targetPath ?? entry.stageKey})`));
|
|
64201
|
+
const listed = undelivered.slice(0, 10).join(", ");
|
|
64202
|
+
const more = undelivered.length > 10 ? `, and ${undelivered.length - 10} more` : "";
|
|
64203
|
+
const message = `atomic-workflows: stage "${stageName}" (${stageId}) is starting without its queued Intercom messages: ` + `no delivery progress for ${PENDING_STAGE_READY_STALL_MS / 1000}s; ` + `drain ${drainPromise === undefined ? "not running" : "running but hung"}; ` + `undelivered: ${listed.length === 0 ? "none" : `${listed}${more}`}. ` + "They stay queued and arrive live or on the stage's next drain.";
|
|
64204
|
+
try {
|
|
64205
|
+
(options.reportStall ?? console.warn)(message);
|
|
64206
|
+
} catch {}
|
|
64207
|
+
};
|
|
64208
|
+
const watchStall = (pending, sessionId, onStall) => {
|
|
64209
|
+
let timer;
|
|
64210
|
+
let settled = false;
|
|
64211
|
+
const check = () => {
|
|
64212
|
+
if (settled)
|
|
64213
|
+
return;
|
|
64214
|
+
const remaining = lastProgressAt + PENDING_STAGE_READY_STALL_MS - Date.now();
|
|
64215
|
+
if (remaining > 0) {
|
|
64216
|
+
timer = setTimeout(check, remaining);
|
|
64217
|
+
timer.unref?.();
|
|
64218
|
+
return;
|
|
64219
|
+
}
|
|
64220
|
+
reportStall(sessionId);
|
|
64221
|
+
onStall();
|
|
64222
|
+
};
|
|
64223
|
+
const stop = () => {
|
|
64224
|
+
settled = true;
|
|
64225
|
+
clearTimeout(timer);
|
|
64226
|
+
};
|
|
64227
|
+
pending.then(stop, stop);
|
|
64228
|
+
check();
|
|
64229
|
+
};
|
|
64230
|
+
const boundedDrain = (drain, sessionId) => {
|
|
64231
|
+
const waiting = new Promise((resolve, reject) => {
|
|
64232
|
+
drain.then(resolve, reject);
|
|
64233
|
+
watchStall(drain, sessionId, resolve);
|
|
64234
|
+
});
|
|
64235
|
+
waiting.catch(() => {});
|
|
64236
|
+
return waiting;
|
|
64237
|
+
};
|
|
64238
|
+
const hasUndeliveredExact = () => activeStore.pendingStageMessagesFor(runId, stageId).length > 0 || stageId !== stageName && activeStore.pendingStageMessagesFor(runId, stageName).length > 0;
|
|
64239
|
+
const hasUndelivered = (sessionId) => hasUndeliveredExact() || stickyPendingStageEntriesForStage(activeStore, runId, stageId, stageName, sessionId === undefined ? undefined : { sessionId }).length > 0;
|
|
64170
64240
|
const pendingReady = () => {
|
|
64171
64241
|
if (readyPromise === undefined) {
|
|
64172
64242
|
readyPromise = new Promise((resolve, reject) => {
|
|
@@ -64176,35 +64246,64 @@ function createWorkflowPendingStageDelivery(activeStore, runId, stageId, stageNa
|
|
|
64176
64246
|
}
|
|
64177
64247
|
return readyPromise;
|
|
64178
64248
|
};
|
|
64249
|
+
let followUp;
|
|
64250
|
+
const startDrain = (deliver, recipient) => {
|
|
64251
|
+
if (terminalError !== undefined)
|
|
64252
|
+
return Promise.resolve();
|
|
64253
|
+
drainError = undefined;
|
|
64254
|
+
progress();
|
|
64255
|
+
const attempt = deliverPendingStageMessages(activeStore, runId, stageId, stageName, async (from, message) => {
|
|
64256
|
+
progress();
|
|
64257
|
+
await deliver(from, message);
|
|
64258
|
+
progress();
|
|
64259
|
+
}, progressingCommit, recipient);
|
|
64260
|
+
const drain = attempt.then(() => {
|
|
64261
|
+
progress();
|
|
64262
|
+
drainedSessionId = recipient?.sessionId;
|
|
64263
|
+
resolveReady?.();
|
|
64264
|
+
readyPromise = undefined;
|
|
64265
|
+
resolveReady = undefined;
|
|
64266
|
+
rejectReady = undefined;
|
|
64267
|
+
if (drainPromise === drain)
|
|
64268
|
+
drainPromise = undefined;
|
|
64269
|
+
}, (error) => {
|
|
64270
|
+
progress();
|
|
64271
|
+
drainError = error;
|
|
64272
|
+
rejectReady?.(error);
|
|
64273
|
+
readyPromise = undefined;
|
|
64274
|
+
resolveReady = undefined;
|
|
64275
|
+
rejectReady = undefined;
|
|
64276
|
+
if (drainPromise === drain)
|
|
64277
|
+
drainPromise = undefined;
|
|
64278
|
+
throw error;
|
|
64279
|
+
});
|
|
64280
|
+
drainPromise = drain;
|
|
64281
|
+
return boundedDrain(drain, recipient?.sessionId);
|
|
64282
|
+
};
|
|
64283
|
+
const requestDrain = (deliver, recipient) => {
|
|
64284
|
+
const running = drainPromise;
|
|
64285
|
+
if (running === undefined)
|
|
64286
|
+
return startDrain(deliver, recipient);
|
|
64287
|
+
if (followUp !== undefined) {
|
|
64288
|
+
followUp.deliver = deliver;
|
|
64289
|
+
followUp.recipient = recipient;
|
|
64290
|
+
return boundedDrain(followUp.settled.promise, recipient?.sessionId);
|
|
64291
|
+
}
|
|
64292
|
+
const next = { deliver, recipient, settled: Promise.withResolvers() };
|
|
64293
|
+
next.settled.promise.catch(() => {});
|
|
64294
|
+
followUp = next;
|
|
64295
|
+
running.catch(() => {}).then(() => {
|
|
64296
|
+
if (followUp === next)
|
|
64297
|
+
followUp = undefined;
|
|
64298
|
+
return requestDrain(next.deliver, next.recipient);
|
|
64299
|
+
}).then(next.settled.resolve, next.settled.reject);
|
|
64300
|
+
return boundedDrain(next.settled.promise, recipient?.sessionId);
|
|
64301
|
+
};
|
|
64179
64302
|
return {
|
|
64180
64303
|
routeCapability: workflowPendingStageRouteCapability(activeStore, runId),
|
|
64181
64304
|
deliverPending(deliver, recipient) {
|
|
64182
64305
|
currentRecipient = recipient;
|
|
64183
|
-
|
|
64184
|
-
return drainPromise;
|
|
64185
|
-
if (terminalError !== undefined)
|
|
64186
|
-
return Promise.resolve();
|
|
64187
|
-
drainError = undefined;
|
|
64188
|
-
const attempt = deliverPendingStageMessages(activeStore, runId, stageId, stageName, deliver, commit, recipient);
|
|
64189
|
-
const drain = attempt.then(() => {
|
|
64190
|
-
resolveReady?.();
|
|
64191
|
-
readyPromise = undefined;
|
|
64192
|
-
resolveReady = undefined;
|
|
64193
|
-
rejectReady = undefined;
|
|
64194
|
-
if (drainPromise === drain)
|
|
64195
|
-
drainPromise = undefined;
|
|
64196
|
-
}, (error) => {
|
|
64197
|
-
drainError = error;
|
|
64198
|
-
rejectReady?.(error);
|
|
64199
|
-
readyPromise = undefined;
|
|
64200
|
-
resolveReady = undefined;
|
|
64201
|
-
rejectReady = undefined;
|
|
64202
|
-
if (drainPromise === drain)
|
|
64203
|
-
drainPromise = undefined;
|
|
64204
|
-
throw error;
|
|
64205
|
-
});
|
|
64206
|
-
drainPromise = drain;
|
|
64207
|
-
return drainPromise;
|
|
64306
|
+
return requestDrain(deliver, recipient);
|
|
64208
64307
|
},
|
|
64209
64308
|
ready(sessionId) {
|
|
64210
64309
|
if (!hasUndelivered(sessionId)) {
|
|
@@ -64214,6 +64313,8 @@ function createWorkflowPendingStageDelivery(activeStore, runId, stageId, stageNa
|
|
|
64214
64313
|
return Promise.reject(terminalError);
|
|
64215
64314
|
if (drainError !== undefined)
|
|
64216
64315
|
return Promise.reject(drainError);
|
|
64316
|
+
if (drainPromise === undefined && sessionId !== undefined && drainedSessionId === sessionId && !hasUndeliveredExact())
|
|
64317
|
+
return;
|
|
64217
64318
|
const ready = pendingReady();
|
|
64218
64319
|
if (sessionId !== undefined && activeStore.pendingStageMessagesFor(runId, stageId).length === 0 && activeStore.pendingStageMessagesFor(runId, stageName).length === 0) {
|
|
64219
64320
|
const entries = stickyPendingStageEntriesForStage(activeStore, runId, stageId, stageName, { sessionId });
|
|
@@ -64237,6 +64338,14 @@ function createWorkflowPendingStageDelivery(activeStore, runId, stageId, stageNa
|
|
|
64237
64338
|
rejectReady?.(error);
|
|
64238
64339
|
});
|
|
64239
64340
|
}
|
|
64341
|
+
watchStall(ready, sessionId, () => {
|
|
64342
|
+
if (readyPromise !== ready)
|
|
64343
|
+
return;
|
|
64344
|
+
resolveReady?.();
|
|
64345
|
+
readyPromise = undefined;
|
|
64346
|
+
resolveReady = undefined;
|
|
64347
|
+
rejectReady = undefined;
|
|
64348
|
+
});
|
|
64240
64349
|
return ready;
|
|
64241
64350
|
},
|
|
64242
64351
|
fail(reason) {
|
|
@@ -64364,7 +64473,7 @@ function toPendingStageSender(entry) {
|
|
|
64364
64473
|
lastActivity: entry.from.lastActivity ?? entry.message.timestamp
|
|
64365
64474
|
};
|
|
64366
64475
|
}
|
|
64367
|
-
var pendingDeliveryClaims, WorkflowPendingStageDeliveryFailedError;
|
|
64476
|
+
var pendingDeliveryClaims, WorkflowPendingStageDeliveryFailedError, PENDING_STAGE_READY_STALL_MS = 60000;
|
|
64368
64477
|
var init_pending_stage_delivery2 = __esm(() => {
|
|
64369
64478
|
init_run_owner_backend();
|
|
64370
64479
|
init_store_backend();
|