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/esm/runtime.js
CHANGED
|
@@ -445,6 +445,12 @@ function validateDag(raw) {
|
|
|
445
445
|
if (n.bot !== void 0) problems.push(`host node "${id}".bot is not supported \u2014 host nodes do not spawn a CLI`);
|
|
446
446
|
if (n.override !== void 0) problems.push(`host node "${id}".override is not supported`);
|
|
447
447
|
if (n.revisitTo !== void 0) problems.push(`host node "${id}".revisitTo is not supported`);
|
|
448
|
+
if (n.checkpoint !== void 0) {
|
|
449
|
+
problems.push(`host node "${id}".checkpoint is not supported \u2014 only goal nodes can be checkpoints`);
|
|
450
|
+
}
|
|
451
|
+
if (n.placement !== void 0) {
|
|
452
|
+
problems.push(`host node "${id}".placement is not supported \u2014 host nodes are executed by the main bot, never handed off`);
|
|
453
|
+
}
|
|
448
454
|
if (n.resultSchema !== void 0) {
|
|
449
455
|
problems.push(`host node "${id}".resultSchema is not supported \u2014 host output uses the trusted executor result contract`);
|
|
450
456
|
}
|
|
@@ -516,6 +522,8 @@ function validateDag(raw) {
|
|
|
516
522
|
const humanGate = normHumanGate(n.humanGate, `node "${id}"`, problems);
|
|
517
523
|
const override = normOverride(n.override, `node "${id}"`, problems);
|
|
518
524
|
const revisitTo = normRevisitTo(n.revisitTo, id, problems);
|
|
525
|
+
const checkpoint = normCheckpoint(n.checkpoint, `goal node "${id}"`, problems);
|
|
526
|
+
const placement = normPlacement(n.placement, `goal node "${id}"`, problems);
|
|
519
527
|
if (schemaVersion !== 2 && n.outputs !== void 0) {
|
|
520
528
|
problems.push(`goal node "${id}".outputs requires schemaVersion 2`);
|
|
521
529
|
}
|
|
@@ -533,7 +541,9 @@ function validateDag(raw) {
|
|
|
533
541
|
timeoutSec,
|
|
534
542
|
humanGate,
|
|
535
543
|
resultSchema,
|
|
536
|
-
...revisitTo ? { revisitTo } : {}
|
|
544
|
+
...revisitTo ? { revisitTo } : {},
|
|
545
|
+
...checkpoint ? { checkpoint } : {},
|
|
546
|
+
...placement ? { placement } : {}
|
|
537
547
|
});
|
|
538
548
|
}
|
|
539
549
|
for (const node of nodes) {
|
|
@@ -903,6 +913,18 @@ function normTimeoutSec(v, where, problems) {
|
|
|
903
913
|
}
|
|
904
914
|
return v;
|
|
905
915
|
}
|
|
916
|
+
function normPlacement(v, where, problems) {
|
|
917
|
+
if (v === void 0 || v === "topic") return void 0;
|
|
918
|
+
if (v === "main") return "main";
|
|
919
|
+
problems.push(`${where}.placement must be "topic" or "main"`);
|
|
920
|
+
return void 0;
|
|
921
|
+
}
|
|
922
|
+
function normCheckpoint(v, where, problems) {
|
|
923
|
+
if (v === void 0 || v === false) return void 0;
|
|
924
|
+
if (v === true) return true;
|
|
925
|
+
problems.push(`${where}.checkpoint must be a boolean`);
|
|
926
|
+
return void 0;
|
|
927
|
+
}
|
|
906
928
|
function normRevisitTo(v, id, problems) {
|
|
907
929
|
if (v === void 0) return void 0;
|
|
908
930
|
if (!Array.isArray(v)) {
|
|
@@ -971,6 +993,12 @@ function normLoopFields(n, id, problems, schemaVersion) {
|
|
|
971
993
|
if (n.override !== void 0) {
|
|
972
994
|
problems.push(`${where}.override is not supported \u2014 a loop composite never spawns a worker; set override on body nodes instead`);
|
|
973
995
|
}
|
|
996
|
+
if (n.checkpoint !== void 0) {
|
|
997
|
+
problems.push(`${where}.checkpoint is not supported \u2014 mark a goal node outside the loop instead`);
|
|
998
|
+
}
|
|
999
|
+
if (n.placement !== void 0) {
|
|
1000
|
+
problems.push(`${where}.placement is not supported \u2014 a loop's body nodes always run in node topics`);
|
|
1001
|
+
}
|
|
974
1002
|
let maxIterations;
|
|
975
1003
|
if (typeof n.maxIterations !== "number" || !Number.isInteger(n.maxIterations) || n.maxIterations < 1) {
|
|
976
1004
|
problems.push(`${where}.maxIterations must be a positive integer`);
|
|
@@ -1017,6 +1045,12 @@ function normLoopFields(n, id, problems, schemaVersion) {
|
|
|
1017
1045
|
if (b.triggerRule !== void 0) {
|
|
1018
1046
|
problems.push(`${where}.body node "${bid}".triggerRule is not supported inside a loop body (first cut)`);
|
|
1019
1047
|
}
|
|
1048
|
+
if (b.checkpoint !== void 0) {
|
|
1049
|
+
problems.push(`${where}.body node "${bid}".checkpoint is not supported inside a loop body (first cut)`);
|
|
1050
|
+
}
|
|
1051
|
+
if (b.placement !== void 0) {
|
|
1052
|
+
problems.push(`${where}.body node "${bid}".placement is not supported \u2014 loop body nodes always run in node topics`);
|
|
1053
|
+
}
|
|
1020
1054
|
const bdepends = normDepends(b.depends, `${where}.body node "${bid}"`, problems);
|
|
1021
1055
|
const bFromList = bdepends.map((d) => d.from);
|
|
1022
1056
|
if (bFromList.includes(bid)) problems.push(`${where}.body node "${bid}" depends on itself`);
|
|
@@ -2851,6 +2885,7 @@ function materialize(events) {
|
|
|
2851
2885
|
case "nodeHandoffPrepared":
|
|
2852
2886
|
case "nodeHandoffSent":
|
|
2853
2887
|
case "nodeHandoffAccepted":
|
|
2888
|
+
case "nodeHandoffStarted":
|
|
2854
2889
|
case "nodeStalled":
|
|
2855
2890
|
break;
|
|
2856
2891
|
case "nodeReassigned": {
|
|
@@ -3589,6 +3624,8 @@ var V3_UPDATE_NODE_FIELDS = [
|
|
|
3589
3624
|
"humanGate",
|
|
3590
3625
|
"override",
|
|
3591
3626
|
"revisitTo",
|
|
3627
|
+
"checkpoint",
|
|
3628
|
+
"placement",
|
|
3592
3629
|
"input",
|
|
3593
3630
|
"maxIterations",
|
|
3594
3631
|
"body",
|
|
@@ -3880,6 +3917,99 @@ function appendMissingV3RevisionFollowUps(journalPath, scope) {
|
|
|
3880
3917
|
});
|
|
3881
3918
|
}
|
|
3882
3919
|
|
|
3920
|
+
// src/workflows/v3/checkpoint-hold.ts
|
|
3921
|
+
function marked(dag, nodeId) {
|
|
3922
|
+
const node = dag.nodes.find((candidate) => candidate.id === nodeId);
|
|
3923
|
+
return !!node && isGoalNode(node) && node.checkpoint === true;
|
|
3924
|
+
}
|
|
3925
|
+
function v3CheckpointMarkedSince(runDir, authorizedDag, events) {
|
|
3926
|
+
const cache = /* @__PURE__ */ new Map();
|
|
3927
|
+
let revisions;
|
|
3928
|
+
const loadRevisions = () => {
|
|
3929
|
+
if (revisions !== void 0) return revisions;
|
|
3930
|
+
try {
|
|
3931
|
+
const positions = /* @__PURE__ */ new Map();
|
|
3932
|
+
events.forEach((event, index) => {
|
|
3933
|
+
if (event.type === "dagRevised") positions.set(event.revision, index + 1);
|
|
3934
|
+
});
|
|
3935
|
+
revisions = foldV3Revisions(events).applied.map((record) => ({
|
|
3936
|
+
dag: readVerifiedV3Revision(runDir, record, authorizedDag).dag,
|
|
3937
|
+
position: positions.get(record.revision) ?? 0
|
|
3938
|
+
}));
|
|
3939
|
+
} catch {
|
|
3940
|
+
revisions = null;
|
|
3941
|
+
}
|
|
3942
|
+
return revisions;
|
|
3943
|
+
};
|
|
3944
|
+
return (nodeId) => {
|
|
3945
|
+
if (cache.has(nodeId)) return cache.get(nodeId);
|
|
3946
|
+
let since = marked(authorizedDag, nodeId) ? 0 : void 0;
|
|
3947
|
+
if (events.some((event) => event.type === "dagRevised")) {
|
|
3948
|
+
const list = loadRevisions();
|
|
3949
|
+
if (list === null) since = void 0;
|
|
3950
|
+
else {
|
|
3951
|
+
for (const revision of list) {
|
|
3952
|
+
if (!marked(revision.dag, nodeId)) since = void 0;
|
|
3953
|
+
else if (since === void 0) since = revision.position;
|
|
3954
|
+
}
|
|
3955
|
+
}
|
|
3956
|
+
}
|
|
3957
|
+
cache.set(nodeId, since);
|
|
3958
|
+
return since;
|
|
3959
|
+
};
|
|
3960
|
+
}
|
|
3961
|
+
function v3CheckpointSuccesses(input) {
|
|
3962
|
+
const events = [...input.events];
|
|
3963
|
+
const snap = materialize(events);
|
|
3964
|
+
const live = snap.runStatus === "running" || snap.runStatus === "blocked";
|
|
3965
|
+
const releases = /* @__PURE__ */ new Map();
|
|
3966
|
+
for (const event of events) {
|
|
3967
|
+
if (event.type === "checkpointReleased" && !releases.has(event.attemptId)) {
|
|
3968
|
+
releases.set(event.attemptId, { reason: event.reason, at: event.ts });
|
|
3969
|
+
}
|
|
3970
|
+
}
|
|
3971
|
+
const out = [];
|
|
3972
|
+
for (const node of input.dag.nodes) {
|
|
3973
|
+
if (!isGoalNode(node) || node.checkpoint !== true) continue;
|
|
3974
|
+
const state = snap.nodes.get(node.id);
|
|
3975
|
+
if (state?.status !== "done") continue;
|
|
3976
|
+
const key = state.effectiveInstanceId ?? node.id;
|
|
3977
|
+
const attemptId = latestAttemptIdFor(events, key);
|
|
3978
|
+
if (!attemptId) continue;
|
|
3979
|
+
let index = -1;
|
|
3980
|
+
for (let i = events.length - 1; i >= 0; i--) {
|
|
3981
|
+
const event = events[i];
|
|
3982
|
+
if (event.type === "nodeSucceeded" && event.attemptId === attemptId && (event.instanceId ?? event.nodeId) === key) {
|
|
3983
|
+
index = i;
|
|
3984
|
+
break;
|
|
3985
|
+
}
|
|
3986
|
+
}
|
|
3987
|
+
if (index < 0) continue;
|
|
3988
|
+
const since = input.markedSince(node.id);
|
|
3989
|
+
if (since === void 0 || index < since) continue;
|
|
3990
|
+
const released = releases.get(attemptId);
|
|
3991
|
+
if (!released && !live) continue;
|
|
3992
|
+
out.push({
|
|
3993
|
+
nodeId: node.id,
|
|
3994
|
+
...state.effectiveInstanceId ? { instanceId: state.effectiveInstanceId } : {},
|
|
3995
|
+
attemptId,
|
|
3996
|
+
eventSeq: index + 1,
|
|
3997
|
+
at: events[index].ts,
|
|
3998
|
+
...released ? { released } : {}
|
|
3999
|
+
});
|
|
4000
|
+
}
|
|
4001
|
+
return out;
|
|
4002
|
+
}
|
|
4003
|
+
function v3CheckpointHeldNodes(dag, successes) {
|
|
4004
|
+
const unreleased = new Set(successes.filter((success) => !success.released).map((success) => success.nodeId));
|
|
4005
|
+
const held = /* @__PURE__ */ new Set();
|
|
4006
|
+
if (unreleased.size === 0) return held;
|
|
4007
|
+
for (const node of dag.nodes) {
|
|
4008
|
+
if (node.depends.some((dep) => unreleased.has(dep.from))) held.add(node.id);
|
|
4009
|
+
}
|
|
4010
|
+
return held;
|
|
4011
|
+
}
|
|
4012
|
+
|
|
3883
4013
|
// src/workflows/v3/gate-wait-store.ts
|
|
3884
4014
|
import { randomBytes } from "node:crypto";
|
|
3885
4015
|
import {
|
|
@@ -4269,10 +4399,20 @@ function foldV3ExternalAttempts(events) {
|
|
|
4269
4399
|
attempt.sessionId = event.sessionId;
|
|
4270
4400
|
attempt.acceptedAt = event.acceptedAt;
|
|
4271
4401
|
attempt.deadlineAt = event.deadlineAt;
|
|
4402
|
+
if (event.startPending) attempt.startPending = true;
|
|
4403
|
+
break;
|
|
4404
|
+
case "nodeHandoffStarted":
|
|
4405
|
+
if (attempt.phase !== "accepted" || !attempt.startPending) break;
|
|
4406
|
+
delete attempt.startPending;
|
|
4407
|
+
attempt.startedAt = event.startedAt;
|
|
4408
|
+
attempt.deadlineAt = event.deadlineAt;
|
|
4272
4409
|
break;
|
|
4273
4410
|
case "nodeStalled":
|
|
4274
4411
|
attempt.stalledAt = event.at;
|
|
4275
4412
|
break;
|
|
4413
|
+
case "nodeHandedToHuman":
|
|
4414
|
+
attempt.handedToHuman = { reason: event.reason };
|
|
4415
|
+
break;
|
|
4276
4416
|
default: {
|
|
4277
4417
|
const closure = closureOf(event);
|
|
4278
4418
|
if (closure) attempt.closed = closure;
|
|
@@ -4297,10 +4437,20 @@ var V3_EXTERNAL_ERROR_CODES = {
|
|
|
4297
4437
|
/** The executing bot's daemon would not start the node session in the
|
|
4298
4438
|
* run's Gate-2 working dir: not inside its configured range (design §15.4). */
|
|
4299
4439
|
WORKING_DIR_REFUSED: "WORKING_DIR_REFUSED",
|
|
4300
|
-
|
|
4440
|
+
/** Main-topic placement (design §5.5): the executing bot's session in the
|
|
4441
|
+
* main topic is executing another workflow node right now (another run in
|
|
4442
|
+
* the same topic); one session cannot carry two nodes at once. */
|
|
4443
|
+
MAIN_TOPIC_BUSY: "MAIN_TOPIC_BUSY",
|
|
4444
|
+
NODE_TIMEOUT: "NODE_TIMEOUT",
|
|
4445
|
+
/** The main bot (or the initiator) handed the node to a human (§13.6). */
|
|
4446
|
+
HANDED_TO_HUMAN: "HANDED_TO_HUMAN"
|
|
4301
4447
|
};
|
|
4302
4448
|
var V3_HANDOFF_IDEMPOTENCY_WINDOW_MS = 50 * 60 * 1e3;
|
|
4303
4449
|
var V3_EXTERNAL_CALL_TIMEOUT_MS = 3e4;
|
|
4450
|
+
var V3_MAIN_TOPIC_QUEUE_GRACE_MIN_MS = 60 * 60 * 1e3;
|
|
4451
|
+
function v3MainTopicQueueGraceMs(nodeTimeoutMs2) {
|
|
4452
|
+
return Math.max(nodeTimeoutMs2, V3_MAIN_TOPIC_QUEUE_GRACE_MIN_MS);
|
|
4453
|
+
}
|
|
4304
4454
|
var V3_DEFAULT_HANDOFF_ACCEPT_TIMEOUT_MS = 15e3;
|
|
4305
4455
|
|
|
4306
4456
|
// src/workflows/v3/external-control.ts
|
|
@@ -4404,6 +4554,9 @@ function classifyExternalAttempt(events, attemptId, expect = {}) {
|
|
|
4404
4554
|
if (expect.sessionId !== void 0 && attempt.sessionId !== void 0 && expect.sessionId !== attempt.sessionId) {
|
|
4405
4555
|
return { ok: false, reason: "session-mismatch", attempt };
|
|
4406
4556
|
}
|
|
4557
|
+
if (attempt.handedToHuman && expect.sessionId !== void 0) {
|
|
4558
|
+
return { ok: false, reason: "handed-to-human", attempt };
|
|
4559
|
+
}
|
|
4407
4560
|
return { ok: true, attempt, snap };
|
|
4408
4561
|
}
|
|
4409
4562
|
function externalAttemptRef(runId, attempt) {
|
|
@@ -4493,12 +4646,30 @@ function appendAcceptedLocked(events, append, dag, input, now) {
|
|
|
4493
4646
|
});
|
|
4494
4647
|
if (!current.ok) return { ok: false, reason: current.reason };
|
|
4495
4648
|
const { attempt } = current;
|
|
4649
|
+
const queued = attempt.placement === "main";
|
|
4650
|
+
const startedAt = queued && input.startedAt !== void 0 && Number.isFinite(input.startedAt) ? Math.min(input.startedAt, now) : void 0;
|
|
4496
4651
|
if (attempt.phase === "accepted") {
|
|
4652
|
+
if (attempt.startPending && startedAt !== void 0) {
|
|
4653
|
+
const started = Math.max(startedAt, attempt.acceptedAt ?? startedAt);
|
|
4654
|
+
const deadlineAt2 = started + nodeTimeoutMs(externalAttemptNode(dag, attempt));
|
|
4655
|
+
append({
|
|
4656
|
+
type: "nodeHandoffStarted",
|
|
4657
|
+
nodeId: attempt.nodeId,
|
|
4658
|
+
...attempt.instanceId ? { instanceId: attempt.instanceId } : {},
|
|
4659
|
+
attemptId: attempt.attemptId,
|
|
4660
|
+
startedAt: started,
|
|
4661
|
+
deadlineAt: deadlineAt2
|
|
4662
|
+
}, { durable: true });
|
|
4663
|
+
return { ok: true, deadlineAt: deadlineAt2, alreadyAccepted: false };
|
|
4664
|
+
}
|
|
4497
4665
|
return { ok: true, deadlineAt: attempt.deadlineAt, alreadyAccepted: true };
|
|
4498
4666
|
}
|
|
4499
4667
|
if (attempt.phase === "dispatched") return { ok: false, reason: "unknown-attempt" };
|
|
4500
4668
|
const acceptedAt = Math.min(input.acceptedAt ?? now, now);
|
|
4501
|
-
const
|
|
4669
|
+
const timeoutMs = nodeTimeoutMs(externalAttemptNode(dag, attempt));
|
|
4670
|
+
const pending = queued && startedAt === void 0;
|
|
4671
|
+
const countFrom = startedAt !== void 0 ? Math.max(startedAt, acceptedAt) : acceptedAt;
|
|
4672
|
+
const deadlineAt = countFrom + timeoutMs + (pending ? v3MainTopicQueueGraceMs(timeoutMs) : 0);
|
|
4502
4673
|
append({
|
|
4503
4674
|
type: "nodeHandoffAccepted",
|
|
4504
4675
|
nodeId: attempt.nodeId,
|
|
@@ -4506,7 +4677,8 @@ function appendAcceptedLocked(events, append, dag, input, now) {
|
|
|
4506
4677
|
attemptId: attempt.attemptId,
|
|
4507
4678
|
sessionId: input.sessionId,
|
|
4508
4679
|
acceptedAt,
|
|
4509
|
-
deadlineAt
|
|
4680
|
+
deadlineAt,
|
|
4681
|
+
...pending ? { startPending: true } : {}
|
|
4510
4682
|
}, { durable: true });
|
|
4511
4683
|
return { ok: true, deadlineAt, alreadyAccepted: false };
|
|
4512
4684
|
}
|
|
@@ -5284,6 +5456,7 @@ function mergeNodeCapability(snap, override) {
|
|
|
5284
5456
|
...override.model ? { model: override.model } : {}
|
|
5285
5457
|
};
|
|
5286
5458
|
}
|
|
5459
|
+
var V3_DEFAULT_CONCURRENCY = Object.freeze({ global: 4, perBot: 1, perCli: 2 });
|
|
5287
5460
|
function assertOrCreateFrozenJson(path, value, label, normalize = (candidate) => candidate) {
|
|
5288
5461
|
const expectedHash = computeInputHash(normalize(value));
|
|
5289
5462
|
if (!existsSync10(path)) {
|
|
@@ -5330,9 +5503,11 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
5330
5503
|
mkdirSync8(runDir, { recursive: true });
|
|
5331
5504
|
const journalPath = join10(runDir, "journal.ndjson");
|
|
5332
5505
|
const statePath = join10(runDir, "STATE");
|
|
5333
|
-
const globalCap = opts.globalConcurrency ??
|
|
5334
|
-
const perBotCap = opts.perBotConcurrency ??
|
|
5335
|
-
const
|
|
5506
|
+
const globalCap = opts.globalConcurrency ?? V3_DEFAULT_CONCURRENCY.global;
|
|
5507
|
+
const perBotCap = opts.perBotConcurrency ?? V3_DEFAULT_CONCURRENCY.perBot;
|
|
5508
|
+
const perCliDefaultCap = opts.perCliConcurrency ?? V3_DEFAULT_CONCURRENCY.perCli;
|
|
5509
|
+
const perCliById = opts.perCliConcurrencyById ?? {};
|
|
5510
|
+
const perCliCap = (cliId) => Object.prototype.hasOwnProperty.call(perCliById, cliId) ? perCliById[cliId] : perCliDefaultCap;
|
|
5336
5511
|
const gateMode = opts.gateMode ?? "blocking";
|
|
5337
5512
|
const hostResponseWaitMs = opts.hostResponseWaitMs ?? 15e3;
|
|
5338
5513
|
const executionContext = opts.executionContext ?? opts.resolvedWorkflowData;
|
|
@@ -5431,7 +5606,16 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
5431
5606
|
append(event);
|
|
5432
5607
|
return true;
|
|
5433
5608
|
});
|
|
5434
|
-
|
|
5609
|
+
let checkpointHeld = /* @__PURE__ */ new Set();
|
|
5610
|
+
const refreshCheckpointHolds = (events) => {
|
|
5611
|
+
if (!externalMode) return;
|
|
5612
|
+
checkpointHeld = v3CheckpointHeldNodes(dag, v3CheckpointSuccesses({
|
|
5613
|
+
events,
|
|
5614
|
+
dag,
|
|
5615
|
+
markedSince: v3CheckpointMarkedSince(runDir, authorizedDag, events)
|
|
5616
|
+
}));
|
|
5617
|
+
};
|
|
5618
|
+
const heldByProposal = (nodeId, loopId) => v3NodeHeldByProposal(pendingTouched, nodeId, loopId) || checkpointHeld.has(nodeId) || loopId !== void 0 && checkpointHeld.has(loopId);
|
|
5435
5619
|
const reconcileRevisionFollowUps = (events) => {
|
|
5436
5620
|
const live = new Set(dag.nodes.map((node) => node.id));
|
|
5437
5621
|
if (missingV3RevisionFollowUps(events, live).length === 0) return false;
|
|
@@ -5517,6 +5701,7 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
5517
5701
|
while (true) {
|
|
5518
5702
|
const events = readJournal(journalPath);
|
|
5519
5703
|
refreshEffectiveDag(events);
|
|
5704
|
+
refreshCheckpointHolds(events);
|
|
5520
5705
|
if (reconcileRevisionFollowUps(events)) continue;
|
|
5521
5706
|
const snap = materialize(events);
|
|
5522
5707
|
writeState(statePath, snap);
|
|
@@ -5703,7 +5888,7 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
5703
5888
|
}
|
|
5704
5889
|
const botKey = botSnap.larkAppId;
|
|
5705
5890
|
if ((botInFlight.get(botKey) ?? 0) >= perBotCap) continue;
|
|
5706
|
-
if ((cliInFlight.get(botSnap.cliId) ?? 0) >= perCliCap) continue;
|
|
5891
|
+
if ((cliInFlight.get(botSnap.cliId) ?? 0) >= perCliCap(botSnap.cliId)) continue;
|
|
5707
5892
|
if (startWork(node, botSnap, botKey, events, a.loop, a.omitted, a.instanceId)) {
|
|
5708
5893
|
startedThisTick++;
|
|
5709
5894
|
}
|
|
@@ -5712,7 +5897,7 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
5712
5897
|
if (startGate(nodesById.get(a.nodeId), a.instanceId)) startedThisTick++;
|
|
5713
5898
|
}
|
|
5714
5899
|
}
|
|
5715
|
-
const cancels = actions.filter((a) => a.kind === "cancelNode" && !heldByProposal(a.nodeId));
|
|
5900
|
+
const cancels = actions.filter((a) => a.kind === "cancelNode" && !heldByProposal(a.nodeId) && !checkpointHeld.has(a.byNodeId));
|
|
5716
5901
|
let cancelledThisTick = false;
|
|
5717
5902
|
for (const a of cancels) {
|
|
5718
5903
|
cancelledThisTick = applyCancelNode(a) || cancelledThisTick;
|
|
@@ -6846,9 +7031,8 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
6846
7031
|
type: "nodeHandoffPrepared",
|
|
6847
7032
|
...identity,
|
|
6848
7033
|
targetLarkAppId: current.assignments.get(node.id) ?? botSnap.larkAppId,
|
|
6849
|
-
|
|
7034
|
+
...externalPlacementIntent(loopRef ? void 0 : node),
|
|
6850
7035
|
revision: dagRevision,
|
|
6851
|
-
idempotency: { nodeCard: randomUUID4(), handoff: randomUUID4() },
|
|
6852
7036
|
preparedAt: clock()
|
|
6853
7037
|
}, { durable: true });
|
|
6854
7038
|
return true;
|
|
@@ -6858,6 +7042,9 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
6858
7042
|
if (attempt && !attempt.closed) startHandoffSend(attempt, false);
|
|
6859
7043
|
return true;
|
|
6860
7044
|
}
|
|
7045
|
+
function externalPlacementIntent(node) {
|
|
7046
|
+
return node && isGoalNode(node) && node.placement === "main" ? { placement: "main", idempotency: { handoff: randomUUID4() } } : { placement: "topic", idempotency: { nodeCard: randomUUID4(), handoff: randomUUID4() } };
|
|
7047
|
+
}
|
|
6861
7048
|
function appendMissingHandoffIntent(attempt) {
|
|
6862
7049
|
const node = externalNodeFor(attempt);
|
|
6863
7050
|
const frozen = node ? snapshotForSelector(botSnapshots, node.bot) : void 0;
|
|
@@ -6872,9 +7059,8 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
6872
7059
|
...attempt.instanceId ? { instanceId: attempt.instanceId } : {},
|
|
6873
7060
|
attemptId: attempt.attemptId,
|
|
6874
7061
|
targetLarkAppId: current.snap.assignments.get(attempt.nodeId) ?? frozen.larkAppId,
|
|
6875
|
-
|
|
7062
|
+
...externalPlacementIntent(attempt.loop ? void 0 : node),
|
|
6876
7063
|
revision: dispatched?.revision ?? 1,
|
|
6877
|
-
idempotency: { nodeCard: randomUUID4(), handoff: randomUUID4() },
|
|
6878
7064
|
preparedAt: clock()
|
|
6879
7065
|
}, { durable: true });
|
|
6880
7066
|
return true;
|
|
@@ -7038,6 +7224,16 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
7038
7224
|
if (handoffControllers.has(attempt.attemptId)) continue;
|
|
7039
7225
|
if (!classifyExternalAttempt(events, attempt.attemptId).ok) continue;
|
|
7040
7226
|
const now = clock();
|
|
7227
|
+
if (attempt.handedToHuman) {
|
|
7228
|
+
await blockExternalAttempt(attempt, "handedToHuman", {
|
|
7229
|
+
errorClass: "workerError",
|
|
7230
|
+
errorCode: V3_EXTERNAL_ERROR_CODES.HANDED_TO_HUMAN,
|
|
7231
|
+
message: attempt.handedToHuman.reason,
|
|
7232
|
+
recovery: "retry"
|
|
7233
|
+
});
|
|
7234
|
+
progressed = true;
|
|
7235
|
+
continue;
|
|
7236
|
+
}
|
|
7041
7237
|
if (attempt.phase === "dispatched") {
|
|
7042
7238
|
progressed = appendMissingHandoffIntent(attempt) || progressed;
|
|
7043
7239
|
} else if (attempt.phase === "prepared") {
|
|
@@ -7094,7 +7290,7 @@ async function runWorkflow(authorizedDag, deps, opts) {
|
|
|
7094
7290
|
await blockExternalAttempt(attempt, "timeout", {
|
|
7095
7291
|
errorClass: "timeout",
|
|
7096
7292
|
errorCode: V3_EXTERNAL_ERROR_CODES.NODE_TIMEOUT,
|
|
7097
|
-
message: "the node did not submit a valid result before its timeout"
|
|
7293
|
+
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"
|
|
7098
7294
|
});
|
|
7099
7295
|
progressed = true;
|
|
7100
7296
|
}
|