@opengeni/worker-bundle 0.7.3 → 0.7.5
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/index.js +43 -22
- package/dist/index.js.map +1 -1
- package/package.json +9 -9
- package/src/activities/agent-turn.ts +8 -10
- package/src/activities/parent-wake.ts +48 -38
- package/src/activities/session-state.ts +11 -11
package/dist/index.js
CHANGED
|
@@ -1657,30 +1657,31 @@ import {
|
|
|
1657
1657
|
addSessionSystemUpdateWithSourceMutation,
|
|
1658
1658
|
claimPendingSessionSystemUpdateOutbox,
|
|
1659
1659
|
claimPendingSessionWorkflowWakes,
|
|
1660
|
+
getSessionSystemUpdateOutboxByDedupeKey,
|
|
1660
1661
|
getOrCreateSessionSystemUpdateOutbox,
|
|
1661
1662
|
markSessionWorkflowWakeFailed,
|
|
1662
1663
|
markSessionSystemUpdateOutboxDeliveredInTransaction,
|
|
1663
1664
|
markSessionSystemUpdateOutboxFailed
|
|
1664
1665
|
} from "@opengeni/db";
|
|
1665
|
-
async function
|
|
1666
|
+
async function notifyParentOfChildIdle(svc, workspaceId, childSessionId, episodeKey) {
|
|
1666
1667
|
try {
|
|
1667
1668
|
const child = await getSession(svc.db, workspaceId, childSessionId);
|
|
1668
1669
|
if (!child || !child.parentSessionId) {
|
|
1669
1670
|
return;
|
|
1670
1671
|
}
|
|
1671
1672
|
const goal = await getSessionGoal2(svc.db, workspaceId, childSessionId);
|
|
1672
|
-
const clientEventId = `child-completion:${childSessionId}:${episodeKey
|
|
1673
|
-
const payload = childCompletionPayload(child, goal
|
|
1673
|
+
const clientEventId = `child-completion:${childSessionId}:${episodeKey}`;
|
|
1674
|
+
const payload = childCompletionPayload(child, goal);
|
|
1674
1675
|
const outbox = await getOrCreateSessionSystemUpdateOutbox(svc.db, {
|
|
1675
1676
|
accountId: child.accountId,
|
|
1676
1677
|
workspaceId,
|
|
1677
1678
|
sourceSessionId: child.id,
|
|
1678
1679
|
targetSessionId: child.parentSessionId,
|
|
1679
1680
|
kind: "child_terminal_result",
|
|
1680
|
-
classification:
|
|
1681
|
+
classification: goal?.status === "paused" ? "action_required" : "success",
|
|
1681
1682
|
sourceId: child.id,
|
|
1682
1683
|
dedupeKey: clientEventId,
|
|
1683
|
-
summary: childCompletionSummary(child, goal,
|
|
1684
|
+
summary: childCompletionSummary(child, goal, "idle"),
|
|
1684
1685
|
payload,
|
|
1685
1686
|
lineage: { childSessionId: child.id, parentSessionId: child.parentSessionId }
|
|
1686
1687
|
});
|
|
@@ -1689,12 +1690,35 @@ async function notifyParentOfChildTerminal(svc, workspaceId, childSessionId, ter
|
|
|
1689
1690
|
}
|
|
1690
1691
|
await deliverParentSystemUpdateOutbox(svc, outbox);
|
|
1691
1692
|
} catch (error) {
|
|
1692
|
-
svc.observability.error("Failed to wake parent session on worker
|
|
1693
|
+
svc.observability.error("Failed to wake parent session on worker idle boundary", {
|
|
1693
1694
|
childSessionId,
|
|
1694
1695
|
error: error instanceof Error ? error.message : String(error)
|
|
1695
1696
|
});
|
|
1696
1697
|
}
|
|
1697
1698
|
}
|
|
1699
|
+
async function deliverFailedChildTurnToParent(svc, workspaceId, childSessionId, turnId) {
|
|
1700
|
+
try {
|
|
1701
|
+
const child = await getSession(svc.db, workspaceId, childSessionId);
|
|
1702
|
+
if (!child || !child.parentSessionId) return;
|
|
1703
|
+
const dedupeKey = `child-completion:${childSessionId}:turn:${turnId}`;
|
|
1704
|
+
const outbox = await getSessionSystemUpdateOutboxByDedupeKey(svc.db, {
|
|
1705
|
+
accountId: child.accountId,
|
|
1706
|
+
workspaceId,
|
|
1707
|
+
dedupeKey
|
|
1708
|
+
});
|
|
1709
|
+
if (!outbox) {
|
|
1710
|
+
throw new Error(`Committed failed-child outbox disappeared: ${dedupeKey}`);
|
|
1711
|
+
}
|
|
1712
|
+
if (outbox.status === "delivered") return;
|
|
1713
|
+
await deliverParentSystemUpdateOutbox(svc, outbox);
|
|
1714
|
+
} catch (error) {
|
|
1715
|
+
svc.observability.error("Failed to deliver committed child-turn failure", {
|
|
1716
|
+
childSessionId,
|
|
1717
|
+
turnId,
|
|
1718
|
+
error: error instanceof Error ? error.message : String(error)
|
|
1719
|
+
});
|
|
1720
|
+
}
|
|
1721
|
+
}
|
|
1698
1722
|
async function deliverParentSystemUpdateOutbox(svc, outbox) {
|
|
1699
1723
|
try {
|
|
1700
1724
|
const result = await addSessionSystemUpdateWithSourceMutation(
|
|
@@ -1798,11 +1822,11 @@ async function reconcilePendingSessionWorkflowWakes(svc, limit = 1e3, overrides
|
|
|
1798
1822
|
await Promise.all(workers);
|
|
1799
1823
|
return { claimed: repairs.length, delivered, failed };
|
|
1800
1824
|
}
|
|
1801
|
-
function childCompletionPayload(child, goal
|
|
1825
|
+
function childCompletionPayload(child, goal) {
|
|
1802
1826
|
return {
|
|
1803
1827
|
type: "child_terminal_result",
|
|
1804
1828
|
childSessionId: child.id,
|
|
1805
|
-
status:
|
|
1829
|
+
status: "idle",
|
|
1806
1830
|
...goal ? {
|
|
1807
1831
|
goal: {
|
|
1808
1832
|
status: goal.status,
|
|
@@ -7278,12 +7302,11 @@ function createRunAgentTurnActivity(services) {
|
|
|
7278
7302
|
if (settlement.action === "failed") {
|
|
7279
7303
|
activityStatus = "failed";
|
|
7280
7304
|
turnMetricOutcome = "failed";
|
|
7281
|
-
await
|
|
7305
|
+
await deliverFailedChildTurnToParent(
|
|
7282
7306
|
{ db, bus, settings, observability, wakeSessionWorkflow },
|
|
7283
7307
|
input.workspaceId,
|
|
7284
7308
|
input.sessionId,
|
|
7285
|
-
|
|
7286
|
-
`turn:${lostTurnId}`
|
|
7309
|
+
lostTurnId
|
|
7287
7310
|
);
|
|
7288
7311
|
return claimedResult({ status: "failed" });
|
|
7289
7312
|
}
|
|
@@ -7774,12 +7797,11 @@ function createRunAgentTurnActivity(services) {
|
|
|
7774
7797
|
return claimedResult({ status: "cancelled" });
|
|
7775
7798
|
}
|
|
7776
7799
|
turnMetricOutcome = "failed";
|
|
7777
|
-
await
|
|
7800
|
+
await deliverFailedChildTurnToParent(
|
|
7778
7801
|
{ db, bus, settings, observability, wakeSessionWorkflow },
|
|
7779
7802
|
input.workspaceId,
|
|
7780
7803
|
input.sessionId,
|
|
7781
|
-
|
|
7782
|
-
`turn:${turnId}`
|
|
7804
|
+
turnId
|
|
7783
7805
|
);
|
|
7784
7806
|
return claimedResult({ status: "failed" });
|
|
7785
7807
|
} finally {
|
|
@@ -9313,7 +9335,8 @@ function createSessionStateActivities(services, overrides = {}) {
|
|
|
9313
9335
|
const requireSessionFn = overrides.requireSession ?? requireSession4;
|
|
9314
9336
|
const settleSessionIdleWithParentOutboxFn = overrides.settleSessionIdleWithParentOutbox ?? settleSessionIdleWithParentOutbox;
|
|
9315
9337
|
const publishDurableSessionEventsFn = overrides.publishDurableSessionEvents ?? publishDurableSessionEvents3;
|
|
9316
|
-
const
|
|
9338
|
+
const deliverFailedChildTurnToParentFn = overrides.deliverFailedChildTurnToParent ?? deliverFailedChildTurnToParent;
|
|
9339
|
+
const notifyParentOfChildIdleFn = overrides.notifyParentOfChildIdle ?? notifyParentOfChildIdle;
|
|
9317
9340
|
const recordTurnsQueuedGaugeFn = overrides.recordTurnsQueuedGauge ?? recordTurnsQueuedGauge;
|
|
9318
9341
|
async function failSessionAttempt2(input) {
|
|
9319
9342
|
const { db, bus, settings, observability, wakeSessionWorkflow } = await services();
|
|
@@ -9353,11 +9376,11 @@ function createSessionStateActivities(services, overrides = {}) {
|
|
|
9353
9376
|
return;
|
|
9354
9377
|
}
|
|
9355
9378
|
await publishDurableSessionEventsFn(bus, input.workspaceId, input.sessionId, result.events);
|
|
9356
|
-
await
|
|
9379
|
+
await deliverFailedChildTurnToParentFn(
|
|
9357
9380
|
{ db, bus, settings, observability, wakeSessionWorkflow },
|
|
9358
9381
|
input.workspaceId,
|
|
9359
9382
|
input.sessionId,
|
|
9360
|
-
|
|
9383
|
+
turn.id
|
|
9361
9384
|
);
|
|
9362
9385
|
}
|
|
9363
9386
|
async function settleSessionInterruptions2(input) {
|
|
@@ -9388,12 +9411,11 @@ function createSessionStateActivities(services, overrides = {}) {
|
|
|
9388
9411
|
await publishDurableSessionEventsFn(bus, input.workspaceId, input.sessionId, result.events);
|
|
9389
9412
|
await refreshQueuedTurnsGauge(db, observability, countQueuedTurnsFn, recordTurnsQueuedGaugeFn);
|
|
9390
9413
|
if (result.action === "exceeded") {
|
|
9391
|
-
await
|
|
9414
|
+
await deliverFailedChildTurnToParentFn(
|
|
9392
9415
|
{ db, bus, settings, observability, wakeSessionWorkflow },
|
|
9393
9416
|
input.workspaceId,
|
|
9394
9417
|
input.sessionId,
|
|
9395
|
-
|
|
9396
|
-
`turn:${result.turnId}`
|
|
9418
|
+
result.turnId
|
|
9397
9419
|
);
|
|
9398
9420
|
return {
|
|
9399
9421
|
action: "exceeded",
|
|
@@ -9427,11 +9449,10 @@ function createSessionStateActivities(services, overrides = {}) {
|
|
|
9427
9449
|
if (settled.action === "stale") {
|
|
9428
9450
|
return;
|
|
9429
9451
|
}
|
|
9430
|
-
await
|
|
9452
|
+
await notifyParentOfChildIdleFn(
|
|
9431
9453
|
{ db, bus, settings, observability, wakeSessionWorkflow },
|
|
9432
9454
|
input.workspaceId,
|
|
9433
9455
|
input.sessionId,
|
|
9434
|
-
"idle",
|
|
9435
9456
|
settled.episodeKey
|
|
9436
9457
|
);
|
|
9437
9458
|
}
|