botmux-workflow-core 3.57.0 → 3.57.1
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/cjs/control.cjs.map +1 -1
- package/dist/cjs/engine.cjs.map +2 -2
- package/dist/cjs/gate-policy.cjs.map +1 -1
- package/dist/cjs/index.cjs +35 -1
- package/dist/cjs/index.cjs.map +2 -2
- package/dist/cjs/runtime.cjs +211 -15
- package/dist/cjs/runtime.cjs.map +4 -4
- package/dist/cjs/schema.cjs +35 -1
- package/dist/cjs/schema.cjs.map +2 -2
- package/dist/esm/control.js.map +1 -1
- package/dist/esm/engine.js.map +2 -2
- package/dist/esm/gate-policy.js.map +1 -1
- package/dist/esm/index.js +35 -1
- package/dist/esm/index.js.map +2 -2
- package/dist/esm/runtime.js +211 -15
- package/dist/esm/runtime.js.map +4 -4
- package/dist/esm/schema.js +35 -1
- package/dist/esm/schema.js.map +2 -2
- package/dist/types/src/workflows/v3/dag.d.ts +16 -0
- package/dist/types/src/workflows/v3/event-contract.d.ts +62 -4
- package/package.json +1 -1
package/dist/cjs/runtime.cjs
CHANGED
|
@@ -479,6 +479,12 @@ function validateDag(raw) {
|
|
|
479
479
|
if (n.bot !== void 0) problems.push(`host node "${id}".bot is not supported \u2014 host nodes do not spawn a CLI`);
|
|
480
480
|
if (n.override !== void 0) problems.push(`host node "${id}".override is not supported`);
|
|
481
481
|
if (n.revisitTo !== void 0) problems.push(`host node "${id}".revisitTo is not supported`);
|
|
482
|
+
if (n.checkpoint !== void 0) {
|
|
483
|
+
problems.push(`host node "${id}".checkpoint is not supported \u2014 only goal nodes can be checkpoints`);
|
|
484
|
+
}
|
|
485
|
+
if (n.placement !== void 0) {
|
|
486
|
+
problems.push(`host node "${id}".placement is not supported \u2014 host nodes are executed by the main bot, never handed off`);
|
|
487
|
+
}
|
|
482
488
|
if (n.resultSchema !== void 0) {
|
|
483
489
|
problems.push(`host node "${id}".resultSchema is not supported \u2014 host output uses the trusted executor result contract`);
|
|
484
490
|
}
|
|
@@ -550,6 +556,8 @@ function validateDag(raw) {
|
|
|
550
556
|
const humanGate = normHumanGate(n.humanGate, `node "${id}"`, problems);
|
|
551
557
|
const override = normOverride(n.override, `node "${id}"`, problems);
|
|
552
558
|
const revisitTo = normRevisitTo(n.revisitTo, id, problems);
|
|
559
|
+
const checkpoint = normCheckpoint(n.checkpoint, `goal node "${id}"`, problems);
|
|
560
|
+
const placement = normPlacement(n.placement, `goal node "${id}"`, problems);
|
|
553
561
|
if (schemaVersion !== 2 && n.outputs !== void 0) {
|
|
554
562
|
problems.push(`goal node "${id}".outputs requires schemaVersion 2`);
|
|
555
563
|
}
|
|
@@ -567,7 +575,9 @@ function validateDag(raw) {
|
|
|
567
575
|
timeoutSec,
|
|
568
576
|
humanGate,
|
|
569
577
|
resultSchema,
|
|
570
|
-
...revisitTo ? { revisitTo } : {}
|
|
578
|
+
...revisitTo ? { revisitTo } : {},
|
|
579
|
+
...checkpoint ? { checkpoint } : {},
|
|
580
|
+
...placement ? { placement } : {}
|
|
571
581
|
});
|
|
572
582
|
}
|
|
573
583
|
for (const node of nodes) {
|
|
@@ -937,6 +947,18 @@ function normTimeoutSec(v, where, problems) {
|
|
|
937
947
|
}
|
|
938
948
|
return v;
|
|
939
949
|
}
|
|
950
|
+
function normPlacement(v, where, problems) {
|
|
951
|
+
if (v === void 0 || v === "topic") return void 0;
|
|
952
|
+
if (v === "main") return "main";
|
|
953
|
+
problems.push(`${where}.placement must be "topic" or "main"`);
|
|
954
|
+
return void 0;
|
|
955
|
+
}
|
|
956
|
+
function normCheckpoint(v, where, problems) {
|
|
957
|
+
if (v === void 0 || v === false) return void 0;
|
|
958
|
+
if (v === true) return true;
|
|
959
|
+
problems.push(`${where}.checkpoint must be a boolean`);
|
|
960
|
+
return void 0;
|
|
961
|
+
}
|
|
940
962
|
function normRevisitTo(v, id, problems) {
|
|
941
963
|
if (v === void 0) return void 0;
|
|
942
964
|
if (!Array.isArray(v)) {
|
|
@@ -1005,6 +1027,12 @@ function normLoopFields(n, id, problems, schemaVersion) {
|
|
|
1005
1027
|
if (n.override !== void 0) {
|
|
1006
1028
|
problems.push(`${where}.override is not supported \u2014 a loop composite never spawns a worker; set override on body nodes instead`);
|
|
1007
1029
|
}
|
|
1030
|
+
if (n.checkpoint !== void 0) {
|
|
1031
|
+
problems.push(`${where}.checkpoint is not supported \u2014 mark a goal node outside the loop instead`);
|
|
1032
|
+
}
|
|
1033
|
+
if (n.placement !== void 0) {
|
|
1034
|
+
problems.push(`${where}.placement is not supported \u2014 a loop's body nodes always run in node topics`);
|
|
1035
|
+
}
|
|
1008
1036
|
let maxIterations;
|
|
1009
1037
|
if (typeof n.maxIterations !== "number" || !Number.isInteger(n.maxIterations) || n.maxIterations < 1) {
|
|
1010
1038
|
problems.push(`${where}.maxIterations must be a positive integer`);
|
|
@@ -1051,6 +1079,12 @@ function normLoopFields(n, id, problems, schemaVersion) {
|
|
|
1051
1079
|
if (b.triggerRule !== void 0) {
|
|
1052
1080
|
problems.push(`${where}.body node "${bid}".triggerRule is not supported inside a loop body (first cut)`);
|
|
1053
1081
|
}
|
|
1082
|
+
if (b.checkpoint !== void 0) {
|
|
1083
|
+
problems.push(`${where}.body node "${bid}".checkpoint is not supported inside a loop body (first cut)`);
|
|
1084
|
+
}
|
|
1085
|
+
if (b.placement !== void 0) {
|
|
1086
|
+
problems.push(`${where}.body node "${bid}".placement is not supported \u2014 loop body nodes always run in node topics`);
|
|
1087
|
+
}
|
|
1054
1088
|
const bdepends = normDepends(b.depends, `${where}.body node "${bid}"`, problems);
|
|
1055
1089
|
const bFromList = bdepends.map((d) => d.from);
|
|
1056
1090
|
if (bFromList.includes(bid)) problems.push(`${where}.body node "${bid}" depends on itself`);
|
|
@@ -2848,6 +2882,7 @@ function materialize(events) {
|
|
|
2848
2882
|
case "nodeHandoffPrepared":
|
|
2849
2883
|
case "nodeHandoffSent":
|
|
2850
2884
|
case "nodeHandoffAccepted":
|
|
2885
|
+
case "nodeHandoffStarted":
|
|
2851
2886
|
case "nodeStalled":
|
|
2852
2887
|
break;
|
|
2853
2888
|
case "nodeReassigned": {
|
|
@@ -3581,6 +3616,8 @@ var V3_UPDATE_NODE_FIELDS = [
|
|
|
3581
3616
|
"humanGate",
|
|
3582
3617
|
"override",
|
|
3583
3618
|
"revisitTo",
|
|
3619
|
+
"checkpoint",
|
|
3620
|
+
"placement",
|
|
3584
3621
|
"input",
|
|
3585
3622
|
"maxIterations",
|
|
3586
3623
|
"body",
|
|
@@ -3872,6 +3909,99 @@ function appendMissingV3RevisionFollowUps(journalPath, scope) {
|
|
|
3872
3909
|
});
|
|
3873
3910
|
}
|
|
3874
3911
|
|
|
3912
|
+
// src/workflows/v3/checkpoint-hold.ts
|
|
3913
|
+
function marked(dag, nodeId) {
|
|
3914
|
+
const node = dag.nodes.find((candidate) => candidate.id === nodeId);
|
|
3915
|
+
return !!node && isGoalNode(node) && node.checkpoint === true;
|
|
3916
|
+
}
|
|
3917
|
+
function v3CheckpointMarkedSince(runDir, authorizedDag, events) {
|
|
3918
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3919
|
+
let revisions;
|
|
3920
|
+
const loadRevisions = () => {
|
|
3921
|
+
if (revisions !== void 0) return revisions;
|
|
3922
|
+
try {
|
|
3923
|
+
const positions = /* @__PURE__ */ new Map();
|
|
3924
|
+
events.forEach((event, index) => {
|
|
3925
|
+
if (event.type === "dagRevised") positions.set(event.revision, index + 1);
|
|
3926
|
+
});
|
|
3927
|
+
revisions = foldV3Revisions(events).applied.map((record) => ({
|
|
3928
|
+
dag: readVerifiedV3Revision(runDir, record, authorizedDag).dag,
|
|
3929
|
+
position: positions.get(record.revision) ?? 0
|
|
3930
|
+
}));
|
|
3931
|
+
} catch {
|
|
3932
|
+
revisions = null;
|
|
3933
|
+
}
|
|
3934
|
+
return revisions;
|
|
3935
|
+
};
|
|
3936
|
+
return (nodeId) => {
|
|
3937
|
+
if (cache.has(nodeId)) return cache.get(nodeId);
|
|
3938
|
+
let since = marked(authorizedDag, nodeId) ? 0 : void 0;
|
|
3939
|
+
if (events.some((event) => event.type === "dagRevised")) {
|
|
3940
|
+
const list = loadRevisions();
|
|
3941
|
+
if (list === null) since = void 0;
|
|
3942
|
+
else {
|
|
3943
|
+
for (const revision of list) {
|
|
3944
|
+
if (!marked(revision.dag, nodeId)) since = void 0;
|
|
3945
|
+
else if (since === void 0) since = revision.position;
|
|
3946
|
+
}
|
|
3947
|
+
}
|
|
3948
|
+
}
|
|
3949
|
+
cache.set(nodeId, since);
|
|
3950
|
+
return since;
|
|
3951
|
+
};
|
|
3952
|
+
}
|
|
3953
|
+
function v3CheckpointSuccesses(input) {
|
|
3954
|
+
const events = [...input.events];
|
|
3955
|
+
const snap = materialize(events);
|
|
3956
|
+
const live = snap.runStatus === "running" || snap.runStatus === "blocked";
|
|
3957
|
+
const releases = /* @__PURE__ */ new Map();
|
|
3958
|
+
for (const event of events) {
|
|
3959
|
+
if (event.type === "checkpointReleased" && !releases.has(event.attemptId)) {
|
|
3960
|
+
releases.set(event.attemptId, { reason: event.reason, at: event.ts });
|
|
3961
|
+
}
|
|
3962
|
+
}
|
|
3963
|
+
const out = [];
|
|
3964
|
+
for (const node of input.dag.nodes) {
|
|
3965
|
+
if (!isGoalNode(node) || node.checkpoint !== true) continue;
|
|
3966
|
+
const state = snap.nodes.get(node.id);
|
|
3967
|
+
if (state?.status !== "done") continue;
|
|
3968
|
+
const key = state.effectiveInstanceId ?? node.id;
|
|
3969
|
+
const attemptId = latestAttemptIdFor(events, key);
|
|
3970
|
+
if (!attemptId) continue;
|
|
3971
|
+
let index = -1;
|
|
3972
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
3973
|
+
const event = events[i];
|
|
3974
|
+
if (event.type === "nodeSucceeded" && event.attemptId === attemptId && (event.instanceId ?? event.nodeId) === key) {
|
|
3975
|
+
index = i;
|
|
3976
|
+
break;
|
|
3977
|
+
}
|
|
3978
|
+
}
|
|
3979
|
+
if (index < 0) continue;
|
|
3980
|
+
const since = input.markedSince(node.id);
|
|
3981
|
+
if (since === void 0 || index < since) continue;
|
|
3982
|
+
const released = releases.get(attemptId);
|
|
3983
|
+
if (!released && !live) continue;
|
|
3984
|
+
out.push({
|
|
3985
|
+
nodeId: node.id,
|
|
3986
|
+
...state.effectiveInstanceId ? { instanceId: state.effectiveInstanceId } : {},
|
|
3987
|
+
attemptId,
|
|
3988
|
+
eventSeq: index + 1,
|
|
3989
|
+
at: events[index].ts,
|
|
3990
|
+
...released ? { released } : {}
|
|
3991
|
+
});
|
|
3992
|
+
}
|
|
3993
|
+
return out;
|
|
3994
|
+
}
|
|
3995
|
+
function v3CheckpointHeldNodes(dag, successes) {
|
|
3996
|
+
const unreleased = new Set(successes.filter((success) => !success.released).map((success) => success.nodeId));
|
|
3997
|
+
const held = /* @__PURE__ */ new Set();
|
|
3998
|
+
if (unreleased.size === 0) return held;
|
|
3999
|
+
for (const node of dag.nodes) {
|
|
4000
|
+
if (node.depends.some((dep) => unreleased.has(dep.from))) held.add(node.id);
|
|
4001
|
+
}
|
|
4002
|
+
return held;
|
|
4003
|
+
}
|
|
4004
|
+
|
|
3875
4005
|
// src/workflows/v3/gate-wait-store.ts
|
|
3876
4006
|
var import_node_crypto5 = require("node:crypto");
|
|
3877
4007
|
var import_node_fs11 = require("node:fs");
|
|
@@ -4247,10 +4377,20 @@ function foldV3ExternalAttempts(events) {
|
|
|
4247
4377
|
attempt.sessionId = event.sessionId;
|
|
4248
4378
|
attempt.acceptedAt = event.acceptedAt;
|
|
4249
4379
|
attempt.deadlineAt = event.deadlineAt;
|
|
4380
|
+
if (event.startPending) attempt.startPending = true;
|
|
4381
|
+
break;
|
|
4382
|
+
case "nodeHandoffStarted":
|
|
4383
|
+
if (attempt.phase !== "accepted" || !attempt.startPending) break;
|
|
4384
|
+
delete attempt.startPending;
|
|
4385
|
+
attempt.startedAt = event.startedAt;
|
|
4386
|
+
attempt.deadlineAt = event.deadlineAt;
|
|
4250
4387
|
break;
|
|
4251
4388
|
case "nodeStalled":
|
|
4252
4389
|
attempt.stalledAt = event.at;
|
|
4253
4390
|
break;
|
|
4391
|
+
case "nodeHandedToHuman":
|
|
4392
|
+
attempt.handedToHuman = { reason: event.reason };
|
|
4393
|
+
break;
|
|
4254
4394
|
default: {
|
|
4255
4395
|
const closure = closureOf(event);
|
|
4256
4396
|
if (closure) attempt.closed = closure;
|
|
@@ -4275,10 +4415,20 @@ var V3_EXTERNAL_ERROR_CODES = {
|
|
|
4275
4415
|
/** The executing bot's daemon would not start the node session in the
|
|
4276
4416
|
* run's Gate-2 working dir: not inside its configured range (design §15.4). */
|
|
4277
4417
|
WORKING_DIR_REFUSED: "WORKING_DIR_REFUSED",
|
|
4278
|
-
|
|
4418
|
+
/** Main-topic placement (design §5.5): the executing bot's session in the
|
|
4419
|
+
* main topic is executing another workflow node right now (another run in
|
|
4420
|
+
* the same topic); one session cannot carry two nodes at once. */
|
|
4421
|
+
MAIN_TOPIC_BUSY: "MAIN_TOPIC_BUSY",
|
|
4422
|
+
NODE_TIMEOUT: "NODE_TIMEOUT",
|
|
4423
|
+
/** The main bot (or the initiator) handed the node to a human (§13.6). */
|
|
4424
|
+
HANDED_TO_HUMAN: "HANDED_TO_HUMAN"
|
|
4279
4425
|
};
|
|
4280
4426
|
var V3_HANDOFF_IDEMPOTENCY_WINDOW_MS = 50 * 60 * 1e3;
|
|
4281
4427
|
var V3_EXTERNAL_CALL_TIMEOUT_MS = 3e4;
|
|
4428
|
+
var V3_MAIN_TOPIC_QUEUE_GRACE_MIN_MS = 60 * 60 * 1e3;
|
|
4429
|
+
function v3MainTopicQueueGraceMs(nodeTimeoutMs2) {
|
|
4430
|
+
return Math.max(nodeTimeoutMs2, V3_MAIN_TOPIC_QUEUE_GRACE_MIN_MS);
|
|
4431
|
+
}
|
|
4282
4432
|
var V3_DEFAULT_HANDOFF_ACCEPT_TIMEOUT_MS = 15e3;
|
|
4283
4433
|
|
|
4284
4434
|
// src/workflows/v3/external-control.ts
|
|
@@ -4373,6 +4523,9 @@ function classifyExternalAttempt(events, attemptId, expect = {}) {
|
|
|
4373
4523
|
if (expect.sessionId !== void 0 && attempt.sessionId !== void 0 && expect.sessionId !== attempt.sessionId) {
|
|
4374
4524
|
return { ok: false, reason: "session-mismatch", attempt };
|
|
4375
4525
|
}
|
|
4526
|
+
if (attempt.handedToHuman && expect.sessionId !== void 0) {
|
|
4527
|
+
return { ok: false, reason: "handed-to-human", attempt };
|
|
4528
|
+
}
|
|
4376
4529
|
return { ok: true, attempt, snap };
|
|
4377
4530
|
}
|
|
4378
4531
|
function externalAttemptRef(runId, attempt) {
|
|
@@ -4462,12 +4615,30 @@ function appendAcceptedLocked(events, append, dag, input, now) {
|
|
|
4462
4615
|
});
|
|
4463
4616
|
if (!current.ok) return { ok: false, reason: current.reason };
|
|
4464
4617
|
const { attempt } = current;
|
|
4618
|
+
const queued = attempt.placement === "main";
|
|
4619
|
+
const startedAt = queued && input.startedAt !== void 0 && Number.isFinite(input.startedAt) ? Math.min(input.startedAt, now) : void 0;
|
|
4465
4620
|
if (attempt.phase === "accepted") {
|
|
4621
|
+
if (attempt.startPending && startedAt !== void 0) {
|
|
4622
|
+
const started = Math.max(startedAt, attempt.acceptedAt ?? startedAt);
|
|
4623
|
+
const deadlineAt2 = started + nodeTimeoutMs(externalAttemptNode(dag, attempt));
|
|
4624
|
+
append({
|
|
4625
|
+
type: "nodeHandoffStarted",
|
|
4626
|
+
nodeId: attempt.nodeId,
|
|
4627
|
+
...attempt.instanceId ? { instanceId: attempt.instanceId } : {},
|
|
4628
|
+
attemptId: attempt.attemptId,
|
|
4629
|
+
startedAt: started,
|
|
4630
|
+
deadlineAt: deadlineAt2
|
|
4631
|
+
}, { durable: true });
|
|
4632
|
+
return { ok: true, deadlineAt: deadlineAt2, alreadyAccepted: false };
|
|
4633
|
+
}
|
|
4466
4634
|
return { ok: true, deadlineAt: attempt.deadlineAt, alreadyAccepted: true };
|
|
4467
4635
|
}
|
|
4468
4636
|
if (attempt.phase === "dispatched") return { ok: false, reason: "unknown-attempt" };
|
|
4469
4637
|
const acceptedAt = Math.min(input.acceptedAt ?? now, now);
|
|
4470
|
-
const
|
|
4638
|
+
const timeoutMs = nodeTimeoutMs(externalAttemptNode(dag, attempt));
|
|
4639
|
+
const pending = queued && startedAt === void 0;
|
|
4640
|
+
const countFrom = startedAt !== void 0 ? Math.max(startedAt, acceptedAt) : acceptedAt;
|
|
4641
|
+
const deadlineAt = countFrom + timeoutMs + (pending ? v3MainTopicQueueGraceMs(timeoutMs) : 0);
|
|
4471
4642
|
append({
|
|
4472
4643
|
type: "nodeHandoffAccepted",
|
|
4473
4644
|
nodeId: attempt.nodeId,
|
|
@@ -4475,7 +4646,8 @@ function appendAcceptedLocked(events, append, dag, input, now) {
|
|
|
4475
4646
|
attemptId: attempt.attemptId,
|
|
4476
4647
|
sessionId: input.sessionId,
|
|
4477
4648
|
acceptedAt,
|
|
4478
|
-
deadlineAt
|
|
4649
|
+
deadlineAt,
|
|
4650
|
+
...pending ? { startPending: true } : {}
|
|
4479
4651
|
}, { durable: true });
|
|
4480
4652
|
return { ok: true, deadlineAt, alreadyAccepted: false };
|
|
4481
4653
|
}
|
|
@@ -5241,6 +5413,7 @@ function mergeNodeCapability(snap, override) {
|
|
|
5241
5413
|
...override.model ? { model: override.model } : {}
|
|
5242
5414
|
};
|
|
5243
5415
|
}
|
|
5416
|
+
var V3_DEFAULT_CONCURRENCY = Object.freeze({ global: 4, perBot: 1, perCli: 2 });
|
|
5244
5417
|
function assertOrCreateFrozenJson(path, value, label, normalize = (candidate) => candidate) {
|
|
5245
5418
|
const expectedHash = computeInputHash(normalize(value));
|
|
5246
5419
|
if (!(0, import_node_fs15.existsSync)(path)) {
|
|
@@ -5287,9 +5460,11 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
5287
5460
|
(0, import_node_fs15.mkdirSync)(runDir, { recursive: true });
|
|
5288
5461
|
const journalPath = (0, import_node_path13.join)(runDir, "journal.ndjson");
|
|
5289
5462
|
const statePath = (0, import_node_path13.join)(runDir, "STATE");
|
|
5290
|
-
const globalCap = opts.globalConcurrency ??
|
|
5291
|
-
const perBotCap = opts.perBotConcurrency ??
|
|
5292
|
-
const
|
|
5463
|
+
const globalCap = opts.globalConcurrency ?? V3_DEFAULT_CONCURRENCY.global;
|
|
5464
|
+
const perBotCap = opts.perBotConcurrency ?? V3_DEFAULT_CONCURRENCY.perBot;
|
|
5465
|
+
const perCliDefaultCap = opts.perCliConcurrency ?? V3_DEFAULT_CONCURRENCY.perCli;
|
|
5466
|
+
const perCliById = opts.perCliConcurrencyById ?? {};
|
|
5467
|
+
const perCliCap = (cliId) => Object.prototype.hasOwnProperty.call(perCliById, cliId) ? perCliById[cliId] : perCliDefaultCap;
|
|
5293
5468
|
const gateMode = opts.gateMode ?? "blocking";
|
|
5294
5469
|
const hostResponseWaitMs = opts.hostResponseWaitMs ?? 15e3;
|
|
5295
5470
|
const executionContext = opts.executionContext ?? opts.resolvedWorkflowData;
|
|
@@ -5388,7 +5563,16 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
5388
5563
|
append(event);
|
|
5389
5564
|
return true;
|
|
5390
5565
|
});
|
|
5391
|
-
|
|
5566
|
+
let checkpointHeld = /* @__PURE__ */ new Set();
|
|
5567
|
+
const refreshCheckpointHolds = (events) => {
|
|
5568
|
+
if (!externalMode) return;
|
|
5569
|
+
checkpointHeld = v3CheckpointHeldNodes(dag, v3CheckpointSuccesses({
|
|
5570
|
+
events,
|
|
5571
|
+
dag,
|
|
5572
|
+
markedSince: v3CheckpointMarkedSince(runDir, authorizedDag, events)
|
|
5573
|
+
}));
|
|
5574
|
+
};
|
|
5575
|
+
const heldByProposal = (nodeId, loopId) => v3NodeHeldByProposal(pendingTouched, nodeId, loopId) || checkpointHeld.has(nodeId) || loopId !== void 0 && checkpointHeld.has(loopId);
|
|
5392
5576
|
const reconcileRevisionFollowUps = (events) => {
|
|
5393
5577
|
const live = new Set(dag.nodes.map((node) => node.id));
|
|
5394
5578
|
if (missingV3RevisionFollowUps(events, live).length === 0) return false;
|
|
@@ -5474,6 +5658,7 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
5474
5658
|
while (true) {
|
|
5475
5659
|
const events = readJournal(journalPath);
|
|
5476
5660
|
refreshEffectiveDag(events);
|
|
5661
|
+
refreshCheckpointHolds(events);
|
|
5477
5662
|
if (reconcileRevisionFollowUps(events)) continue;
|
|
5478
5663
|
const snap = materialize(events);
|
|
5479
5664
|
writeState(statePath, snap);
|
|
@@ -5660,7 +5845,7 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
5660
5845
|
}
|
|
5661
5846
|
const botKey = botSnap.larkAppId;
|
|
5662
5847
|
if ((botInFlight.get(botKey) ?? 0) >= perBotCap) continue;
|
|
5663
|
-
if ((cliInFlight.get(botSnap.cliId) ?? 0) >= perCliCap) continue;
|
|
5848
|
+
if ((cliInFlight.get(botSnap.cliId) ?? 0) >= perCliCap(botSnap.cliId)) continue;
|
|
5664
5849
|
if (startWork(node, botSnap, botKey, events, a.loop, a.omitted, a.instanceId)) {
|
|
5665
5850
|
startedThisTick++;
|
|
5666
5851
|
}
|
|
@@ -5669,7 +5854,7 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
5669
5854
|
if (startGate(nodesById.get(a.nodeId), a.instanceId)) startedThisTick++;
|
|
5670
5855
|
}
|
|
5671
5856
|
}
|
|
5672
|
-
const cancels = actions.filter((a) => a.kind === "cancelNode" && !heldByProposal(a.nodeId));
|
|
5857
|
+
const cancels = actions.filter((a) => a.kind === "cancelNode" && !heldByProposal(a.nodeId) && !checkpointHeld.has(a.byNodeId));
|
|
5673
5858
|
let cancelledThisTick = false;
|
|
5674
5859
|
for (const a of cancels) {
|
|
5675
5860
|
cancelledThisTick = applyCancelNode(a) || cancelledThisTick;
|
|
@@ -6803,9 +6988,8 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
6803
6988
|
type: "nodeHandoffPrepared",
|
|
6804
6989
|
...identity,
|
|
6805
6990
|
targetLarkAppId: current.assignments.get(node.id) ?? botSnap.larkAppId,
|
|
6806
|
-
|
|
6991
|
+
...externalPlacementIntent(loopRef ? void 0 : node),
|
|
6807
6992
|
revision: dagRevision,
|
|
6808
|
-
idempotency: { nodeCard: (0, import_node_crypto9.randomUUID)(), handoff: (0, import_node_crypto9.randomUUID)() },
|
|
6809
6993
|
preparedAt: clock()
|
|
6810
6994
|
}, { durable: true });
|
|
6811
6995
|
return true;
|
|
@@ -6815,6 +6999,9 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
6815
6999
|
if (attempt && !attempt.closed) startHandoffSend(attempt, false);
|
|
6816
7000
|
return true;
|
|
6817
7001
|
}
|
|
7002
|
+
function externalPlacementIntent(node) {
|
|
7003
|
+
return node && isGoalNode(node) && node.placement === "main" ? { placement: "main", idempotency: { handoff: (0, import_node_crypto9.randomUUID)() } } : { placement: "topic", idempotency: { nodeCard: (0, import_node_crypto9.randomUUID)(), handoff: (0, import_node_crypto9.randomUUID)() } };
|
|
7004
|
+
}
|
|
6818
7005
|
function appendMissingHandoffIntent(attempt) {
|
|
6819
7006
|
const node = externalNodeFor(attempt);
|
|
6820
7007
|
const frozen = node ? snapshotForSelector(botSnapshots, node.bot) : void 0;
|
|
@@ -6829,9 +7016,8 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
6829
7016
|
...attempt.instanceId ? { instanceId: attempt.instanceId } : {},
|
|
6830
7017
|
attemptId: attempt.attemptId,
|
|
6831
7018
|
targetLarkAppId: current.snap.assignments.get(attempt.nodeId) ?? frozen.larkAppId,
|
|
6832
|
-
|
|
7019
|
+
...externalPlacementIntent(attempt.loop ? void 0 : node),
|
|
6833
7020
|
revision: dispatched?.revision ?? 1,
|
|
6834
|
-
idempotency: { nodeCard: (0, import_node_crypto9.randomUUID)(), handoff: (0, import_node_crypto9.randomUUID)() },
|
|
6835
7021
|
preparedAt: clock()
|
|
6836
7022
|
}, { durable: true });
|
|
6837
7023
|
return true;
|
|
@@ -6995,6 +7181,16 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
6995
7181
|
if (handoffControllers.has(attempt.attemptId)) continue;
|
|
6996
7182
|
if (!classifyExternalAttempt(events, attempt.attemptId).ok) continue;
|
|
6997
7183
|
const now = clock();
|
|
7184
|
+
if (attempt.handedToHuman) {
|
|
7185
|
+
await blockExternalAttempt(attempt, "handedToHuman", {
|
|
7186
|
+
errorClass: "workerError",
|
|
7187
|
+
errorCode: V3_EXTERNAL_ERROR_CODES.HANDED_TO_HUMAN,
|
|
7188
|
+
message: attempt.handedToHuman.reason,
|
|
7189
|
+
recovery: "retry"
|
|
7190
|
+
});
|
|
7191
|
+
progressed = true;
|
|
7192
|
+
continue;
|
|
7193
|
+
}
|
|
6998
7194
|
if (attempt.phase === "dispatched") {
|
|
6999
7195
|
progressed = appendMissingHandoffIntent(attempt) || progressed;
|
|
7000
7196
|
} else if (attempt.phase === "prepared") {
|
|
@@ -7051,7 +7247,7 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
7051
7247
|
await blockExternalAttempt(attempt, "timeout", {
|
|
7052
7248
|
errorClass: "timeout",
|
|
7053
7249
|
errorCode: V3_EXTERNAL_ERROR_CODES.NODE_TIMEOUT,
|
|
7054
|
-
message: "the node did not submit a valid result before its timeout"
|
|
7250
|
+
message: attempt.startPending ? "\u5230\u671F\u9650\u8FD8\u6CA1\u6536\u5230\u8FD9\u4E00\u8F6E\u5F00\u59CB\u7684\u4FE1\u53F7\uFF1A\u591A\u534A\u662F\u4E00\u76F4\u5728\u6267\u884C Bot \u7684\u4E3B\u8BDD\u9898\u4F1A\u8BDD\u91CC\u6392\u961F\uFF08\u5B83\u524D\u9762\u7684\u56DE\u5408\u4E00\u76F4\u6CA1\u7ED3\u675F\uFF09\uFF0C\u4E5F\u53EF\u80FD\u662F\u5F00\u59CB\u4FE1\u53F7\u6CA1\u9001\u5230\uFF1B\u53EF\u4EE5\u91CD\u8BD5\uFF0C\u6216\u628A\u8282\u70B9\u6539\u6210\u8282\u70B9\u8BDD\u9898" : "the node did not submit a valid result before its timeout"
|
|
7055
7251
|
});
|
|
7056
7252
|
progressed = true;
|
|
7057
7253
|
}
|