@desplega.ai/agent-swarm 2.8.0 → 2.8.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/{acp-adapter-t949vbbp.js → acp-adapter-pdy3qsvg.js} +1 -1
- package/dist/{actions-7e9czc7s.js → actions-pwjpn0j6.js} +18 -18
- package/dist/{amp-adapter-gv6cbb7d.js → amp-adapter-cq9jgj6x.js} +1 -1
- package/dist/{app-b9fbkp9v.js → app-cnfffgwg.js} +3 -3
- package/dist/{assistant-wjb7v4c7.js → assistant-kpn317y1.js} +19 -19
- package/dist/{boot-args-schema-2t37e0fe.js → boot-args-schema-pbbnhmc3.js} +1 -1
- package/dist/{boot-reembed-gka3zas7.js → boot-reembed-9m0ysxma.js} +1 -1
- package/dist/{boot-reembed-a35nkyr1.js → boot-reembed-majbn53m.js} +1 -1
- package/dist/{boot-scrub-sweep-65sdnp6c.js → boot-scrub-sweep-app8g8ym.js} +2 -2
- package/dist/{boot-seeds-x42tzytw.js → boot-seeds-pbtmvcjm.js} +4 -4
- package/dist/{claude-adapter-v221b2fd.js → claude-adapter-wn1g3qp5.js} +2 -2
- package/dist/{claude-managed-adapter-29eq09wd.js → claude-managed-adapter-jh6c523j.js} +2 -2
- package/dist/{claude-managed-setup-9m6450zk.js → claude-managed-setup-pd47nzch.js} +4 -4
- package/dist/{claude-sdk-session-0q0ptaba.js → claude-sdk-session-3a2a6589.js} +2 -2
- package/dist/{cli-j790gp2w.js → cli-0ntbxyaa.js} +5 -5
- package/dist/{cli-c55z5chy.js → cli-1xh9a7hn.js} +2 -2
- package/dist/{cli-p1bq50aa.js → cli-4r05hnqa.js} +10 -10
- package/dist/{cli-qa4wdgsy.js → cli-6mma83xa.js} +1 -1
- package/dist/{cli-tph5wt3y.js → cli-6wj7p986.js} +1 -1
- package/dist/{cli-t73cas91.js → cli-7349va39.js} +8100 -7620
- package/dist/{cli-h38x262p.js → cli-7w69ne2f.js} +7 -7
- package/dist/{cli-qwca7s44.js → cli-89cqnasv.js} +2 -2
- package/dist/{cli-rfywm85n.js → cli-93k32c37.js} +31 -31
- package/dist/{cli-2wnq8jkz.js → cli-9vhebtjz.js} +1 -1
- package/dist/{cli-m23zjcy2.js → cli-9wngrawf.js} +1 -1
- package/dist/{cli-f3vq58d2.js → cli-a3b239vq.js} +1 -1
- package/dist/{cli-abejgen1.js → cli-b085njxz.js} +9 -9
- package/dist/{cli-m28atx8q.js → cli-b5rs97a6.js} +4 -4
- package/dist/{cli-qsnnd04k.js → cli-b8e9nb04.js} +1 -1
- package/dist/{cli-p2gfst4m.js → cli-bb431xey.js} +18 -18
- package/dist/{cli-deefvewm.js → cli-cyhbbd1z.js} +1 -1
- package/dist/{cli-y97qxcfx.js → cli-d3p5vwbk.js} +2 -2
- package/dist/{cli-a7wvp2km.js → cli-dy32zecz.js} +1 -1
- package/dist/{cli-yq3zak69.js → cli-gax7fk3t.js} +1 -1
- package/dist/{cli-ee0b971j.js → cli-jcpr5smb.js} +2 -2
- package/dist/{cli-6t09sdhy.js → cli-jywyhqws.js} +3 -3
- package/dist/{cli-6wxjceza.js → cli-k0615eh8.js} +6 -6
- package/dist/{cli-4txa0ter.js → cli-k26bkr9t.js} +2 -2
- package/dist/{cli-8kzasymh.js → cli-k93bq1wq.js} +2 -2
- package/dist/{cli-gpwhbgx0.js → cli-m9s2qff2.js} +57 -25
- package/dist/{cli-wcg8x116.js → cli-pcad4cb1.js} +1 -1
- package/dist/{cli-gxkx0zzp.js → cli-re4raaj0.js} +1 -1
- package/dist/{cli-rzsy6nc6.js → cli-sn7rtnj4.js} +1 -1
- package/dist/{cli-8fknbnhw.js → cli-syybb0p1.js} +7 -7
- package/dist/{cli-rmmpt0wm.js → cli-tacge1w0.js} +6 -6
- package/dist/{cli-pasjcnmj.js → cli-vbh10fqa.js} +2 -2
- package/dist/{cli-ffhtssbp.js → cli-vj75tyaw.js} +1 -1
- package/dist/{cli-qfedvmcr.js → cli-vqptjbr7.js} +8 -8
- package/dist/{cli-n9ftpys4.js → cli-x6t50dmw.js} +7 -7
- package/dist/{cli-sdtt3men.js → cli-yn2bbre9.js} +1 -1
- package/dist/{cli-334z18y3.js → cli-yncmerje.js} +2 -2
- package/dist/{cli-s7t6p9my.js → cli-zcsw143p.js} +1 -1
- package/dist/cli.js +13 -13
- package/dist/{codex-adapter-30j9bpzd.js → codex-adapter-nha71q3n.js} +1 -1
- package/dist/{codex-session-runner-8vp57v8w.js → codex-session-runner-ak9x1k1h.js} +1 -1
- package/dist/{commands-bngnz9g7.js → commands-f587qpq8.js} +3 -3
- package/dist/{controllers-connect-e2b4gyxc.js → controllers-connect-k5sg9m9h.js} +18 -18
- package/dist/{db-c6np41ca.js → db-amm8w15a.js} +1 -1
- package/dist/{db-bgm7vkc0.js → db-nzf8zb5z.js} +3 -3
- package/dist/{dispatcher-jnybck15.js → dispatcher-89zrts8f.js} +17 -17
- package/dist/{embedding-space-crsm2zp0.js → embedding-space-ezwenjmj.js} +6 -6
- package/dist/{embeddings-e7z3f27f.js → embeddings-np74ht6g.js} +1 -1
- package/dist/{external-channel-m77wf5z3.js → external-channel-z46yx9d7.js} +2 -2
- package/dist/{fx-adapter-b6w0kf56.js → fx-adapter-3q12snn6.js} +2 -2
- package/dist/{grok-adapter-4sqtebdk.js → grok-adapter-ahb1w033.js} +2 -2
- package/dist/handlers-vbww69re.js +32 -0
- package/dist/{heartbeat-xgb036sx.js → heartbeat-dt9qw9c8.js} +19 -19
- package/dist/{hook-xsk1jbha.js → hook-8k6fbz9b.js} +1 -1
- package/dist/{hook-5h02c9ga.js → hook-jgcgygex.js} +1 -1
- package/dist/{http-txe7qhvn.js → http-haw4r8ne.js} +40 -40
- package/dist/{index-0eny15vj.js → index-2skqtd76.js} +2 -2
- package/dist/index-4xwaf5th.js +32 -0
- package/dist/{index-ysvbhg5m.js → index-5gk12my8.js} +1 -1
- package/dist/{index-w7em4ktq.js → index-d6wkh8ar.js} +2 -2
- package/dist/index-f0hcrs8e.js +33 -0
- package/dist/{index-rvccek1w.js → index-gjwaqaq8.js} +5 -5
- package/dist/{index-e5pfbsys.js → index-hjhfk3ra.js} +3 -3
- package/dist/{index-1qw6f2dc.js → index-khe3gp0k.js} +4 -4
- package/dist/index-s4ewdma4.js +37 -0
- package/dist/{index-vk63emp7.js → index-tez78qj3.js} +11 -11
- package/dist/{keepalive-4zsrce78.js → keepalive-xn6s7rmg.js} +3 -3
- package/dist/{lead-yqt47dkr.js → lead-6ygbfhbh.js} +28 -28
- package/dist/{maintenance-86jvartk.js → maintenance-vdts800b.js} +1 -1
- package/dist/{node-je82wjet.js → node-4c5jqxr3.js} +1 -1
- package/dist/{oauth-refresh-sweep-j52kg9pr.js → oauth-refresh-sweep-094c8wfk.js} +2 -2
- package/dist/{onboard-c2aj5p8q.js → onboard-v99eh56m.js} +2 -2
- package/dist/{otel-impl-yyy203z8.js → otel-impl-q7yr9yp0.js} +1 -1
- package/dist/{pricing-refresh-1rgzqyzz.js → pricing-refresh-7dh2yase.js} +2 -2
- package/dist/{rbac-roles-q89qe8er.js → rbac-roles-mdmc96p4.js} +3 -3
- package/dist/{rbac-roles-e70xfeyj.js → rbac-roles-npbmdh77.js} +2 -2
- package/dist/{render-v2-k6tt107q.js → render-v2-twhhwmms.js} +3 -3
- package/dist/{resume-cnnrjfxa.js → resume-5gsrjd5e.js} +6 -6
- package/dist/{session-access-xkxkjw3n.js → session-access-m191x30x.js} +4 -4
- package/dist/{session-source-backfill-1d5pdwww.js → session-source-backfill-nt923ask.js} +1 -1
- package/dist/{setup-se8q7gkc.js → setup-wv467afy.js} +1 -1
- package/dist/{work-objects-1kxnbzy5.js → work-objects-8zkrpy13.js} +20 -20
- package/dist/{worker-follow-up-zqm8apt4.js → worker-follow-up-cecqszem.js} +17 -17
- package/dist/{worker-j6xxtq7p.js → worker-mz5z7kj0.js} +28 -28
- package/openapi.json +1 -1
- package/package.json +2 -2
- package/src/providers/amp-adapter.ts +1 -1
- package/src/scripts-runtime/eval-harness.ts +14 -1
- package/src/scripts-runtime/executors/types.ts +3 -0
- package/src/tests/mcp-tools.test.ts +1 -1
- package/src/tests/script-native-unawaited-drain.test.ts +167 -0
- package/src/tools/script-run.ts +1 -1
- package/templates/skills/swarm-scripts/SKILL.md +1 -1
- package/templates/skills/swarm-scripts/content.md +1 -1
- package/dist/handlers-kdjcyzdj.js +0 -32
- package/dist/index-835xdgnm.js +0 -33
- package/dist/index-d469300x.js +0 -37
- package/dist/index-rzqwp11g.js +0 -32
|
@@ -10,24 +10,24 @@ import {
|
|
|
10
10
|
createRerouteDecisionTask2,
|
|
11
11
|
createPoolStarvationDecisionTask2,
|
|
12
12
|
init_worker_follow_up
|
|
13
|
-
} from "./cli-
|
|
14
|
-
import"./cli-
|
|
15
|
-
import"./cli-
|
|
16
|
-
import"./cli-
|
|
17
|
-
import"./cli-
|
|
13
|
+
} from "./cli-93k32c37.js";
|
|
14
|
+
import"./cli-k26bkr9t.js";
|
|
15
|
+
import"./cli-a3b239vq.js";
|
|
16
|
+
import"./cli-0ntbxyaa.js";
|
|
17
|
+
import"./cli-yn2bbre9.js";
|
|
18
18
|
import"./cli-7cp6aa1q.js";
|
|
19
|
-
import"./cli-
|
|
20
|
-
import"./cli-
|
|
21
|
-
import"./cli-
|
|
22
|
-
import"./cli-
|
|
23
|
-
import"./cli-
|
|
24
|
-
import"./cli-
|
|
25
|
-
import"./cli-
|
|
26
|
-
import"./cli-
|
|
27
|
-
import"./cli-
|
|
28
|
-
import"./cli-
|
|
29
|
-
import"./cli-
|
|
30
|
-
import"./cli-
|
|
19
|
+
import"./cli-b5rs97a6.js";
|
|
20
|
+
import"./cli-x6t50dmw.js";
|
|
21
|
+
import"./cli-vbh10fqa.js";
|
|
22
|
+
import"./cli-vqptjbr7.js";
|
|
23
|
+
import"./cli-4r05hnqa.js";
|
|
24
|
+
import"./cli-dy32zecz.js";
|
|
25
|
+
import"./cli-b8e9nb04.js";
|
|
26
|
+
import"./cli-zcsw143p.js";
|
|
27
|
+
import"./cli-k93bq1wq.js";
|
|
28
|
+
import"./cli-1xh9a7hn.js";
|
|
29
|
+
import"./cli-re4raaj0.js";
|
|
30
|
+
import"./cli-7w69ne2f.js";
|
|
31
31
|
import"./cli-eddnyg3t.js";
|
|
32
32
|
init_worker_follow_up();
|
|
33
33
|
|
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
import"./cli-
|
|
2
|
-
import"./cli-
|
|
3
|
-
import"./cli-
|
|
4
|
-
import"./cli-
|
|
1
|
+
import"./cli-7w69ne2f.js";
|
|
2
|
+
import"./cli-1xh9a7hn.js";
|
|
3
|
+
import"./cli-k26bkr9t.js";
|
|
4
|
+
import"./cli-a3b239vq.js";
|
|
5
5
|
import"./cli-eddnyg3t.js";
|
|
6
|
-
import"./cli-
|
|
7
|
-
import"./cli-
|
|
8
|
-
import"./cli-
|
|
6
|
+
import"./cli-b8e9nb04.js";
|
|
7
|
+
import"./cli-4r05hnqa.js";
|
|
8
|
+
import"./cli-vbh10fqa.js";
|
|
9
9
|
import {
|
|
10
10
|
getEnabledCapabilities,
|
|
11
11
|
init_server
|
|
12
|
-
} from "./cli-
|
|
12
|
+
} from "./cli-93k32c37.js";
|
|
13
13
|
import"./cli-7cp6aa1q.js";
|
|
14
|
-
import"./cli-
|
|
15
|
-
import"./cli-
|
|
16
|
-
import"./cli-
|
|
17
|
-
import"./cli-
|
|
14
|
+
import"./cli-x6t50dmw.js";
|
|
15
|
+
import"./cli-k93bq1wq.js";
|
|
16
|
+
import"./cli-b5rs97a6.js";
|
|
17
|
+
import"./cli-jcpr5smb.js";
|
|
18
18
|
import"./cli-2gxeg5gr.js";
|
|
19
19
|
import {
|
|
20
20
|
runAgent
|
|
21
|
-
} from "./cli-
|
|
21
|
+
} from "./cli-bb431xey.js";
|
|
22
22
|
import"./cli-jrzkw01m.js";
|
|
23
23
|
import"./cli-77cd6gy8.js";
|
|
24
24
|
import"./cli-kc7v1nfv.js";
|
|
25
25
|
import"./cli-d6521kb5.js";
|
|
26
26
|
import"./cli-xzm9vcfg.js";
|
|
27
|
-
import"./cli-
|
|
27
|
+
import"./cli-9wngrawf.js";
|
|
28
28
|
import"./cli-qmqk2yc2.js";
|
|
29
29
|
import"./cli-8aes17e4.js";
|
|
30
30
|
import"./cli-g70vxtjh.js";
|
|
31
31
|
import"./cli-d82btycs.js";
|
|
32
32
|
import"./cli-0726awxw.js";
|
|
33
|
-
import"./cli-
|
|
34
|
-
import"./cli-
|
|
33
|
+
import"./cli-6mma83xa.js";
|
|
34
|
+
import"./cli-d3p5vwbk.js";
|
|
35
35
|
import"./cli-4bd1rck6.js";
|
|
36
36
|
import"./cli-98rwmcyc.js";
|
|
37
|
-
import"./cli-
|
|
38
|
-
import"./cli-
|
|
37
|
+
import"./cli-7349va39.js";
|
|
38
|
+
import"./cli-vj75tyaw.js";
|
|
39
39
|
import"./cli-m5akxq8q.js";
|
|
40
40
|
import"./cli-kr5tjjtz.js";
|
|
41
|
-
import"./cli-
|
|
41
|
+
import"./cli-9vhebtjz.js";
|
|
42
42
|
import"./cli-7b8sbmag.js";
|
|
43
43
|
import"./cli-mrt48bx7.js";
|
|
44
44
|
import"./cli-wk18cm92.js";
|
|
45
|
-
import"./cli-
|
|
45
|
+
import"./cli-sn7rtnj4.js";
|
|
46
46
|
import"./cli-tqegb8eq.js";
|
|
47
47
|
import"./cli-7p1kvkck.js";
|
|
48
|
-
import"./cli-
|
|
49
|
-
import"./cli-
|
|
50
|
-
import"./cli-
|
|
51
|
-
import"./cli-
|
|
52
|
-
import"./cli-
|
|
53
|
-
import"./cli-
|
|
54
|
-
import"./cli-
|
|
55
|
-
import"./cli-
|
|
48
|
+
import"./cli-gax7fk3t.js";
|
|
49
|
+
import"./cli-pcad4cb1.js";
|
|
50
|
+
import"./cli-0ntbxyaa.js";
|
|
51
|
+
import"./cli-yn2bbre9.js";
|
|
52
|
+
import"./cli-vqptjbr7.js";
|
|
53
|
+
import"./cli-dy32zecz.js";
|
|
54
|
+
import"./cli-zcsw143p.js";
|
|
55
|
+
import"./cli-re4raaj0.js";
|
|
56
56
|
|
|
57
57
|
// src/commands/worker.ts
|
|
58
58
|
init_server();
|
package/openapi.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"openapi": "3.1.0",
|
|
3
3
|
"info": {
|
|
4
4
|
"title": "Agent Swarm API",
|
|
5
|
-
"version": "2.8.
|
|
5
|
+
"version": "2.8.1",
|
|
6
6
|
"description": "Multi-agent orchestration API for Claude Code, Codex, and Gemini CLI. Enables task distribution, agent communication, and service discovery.\n\nMCP tools are documented separately in [MCP.md](./MCP.md)."
|
|
7
7
|
},
|
|
8
8
|
"servers": [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@desplega.ai/agent-swarm",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.1",
|
|
4
4
|
"description": "agent-swarm.dev — an open-source operating system for AI work: a lead agent breaks goals into tasks, routes them to specialized workers such as Claude Code or Codex, runs each worker in an isolated container, and preserves shared memory, tools, schedules, and review gates so delegated work compounds across sessions.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"agent-swarm.dev",
|
|
@@ -205,7 +205,7 @@
|
|
|
205
205
|
"@agentclientprotocol/sdk": "2.4.0",
|
|
206
206
|
"@ai-sdk/openai": "^3.0.41",
|
|
207
207
|
"@anthropic-ai/claude-agent-sdk": "0.3.318",
|
|
208
|
-
"@anthropic-ai/sdk": "^1.
|
|
208
|
+
"@anthropic-ai/sdk": "^1.5.0",
|
|
209
209
|
"@asteasolutions/zod-to-openapi": "^8.0.0",
|
|
210
210
|
"@aws-sdk/client-bedrock": "3.1048.0",
|
|
211
211
|
"@boxd-sh/sdk": "0.2.20",
|
|
@@ -45,7 +45,7 @@ import type {
|
|
|
45
45
|
* default; the image installs exactly this version and the per-task settings
|
|
46
46
|
* set `amp.updates.mode: "disabled"`. Bump it deliberately, with a live run.
|
|
47
47
|
*/
|
|
48
|
-
export const AMP_PACKAGE = "@ampcode/cli@0.0.
|
|
48
|
+
export const AMP_PACKAGE = "@ampcode/cli@0.0.1793851242-g61361b";
|
|
49
49
|
|
|
50
50
|
/** MCP server name. Amp exposes its tools as `agent_swarm` / `store_progress` (dashes become underscores). */
|
|
51
51
|
const AMP_MCP_SERVER_NAME = "agent-swarm";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { buildCtx } from "./ctx";
|
|
2
2
|
import { patchFetchWithEgressSubstitution } from "./egress-secrets";
|
|
3
|
-
import type
|
|
3
|
+
import { type SwarmConfigPayload, UNAWAITED_WORK_DRAIN_MS } from "./executors/types";
|
|
4
4
|
import { isHostValidationEquivalent } from "./host-validated-args";
|
|
5
5
|
import { ctxSignatureHintFor } from "./script-error-hints";
|
|
6
6
|
import { SwarmConfig } from "./swarm-config";
|
|
@@ -167,6 +167,19 @@ try {
|
|
|
167
167
|
|
|
168
168
|
const result = await mod.default(validatedArgs, ctx);
|
|
169
169
|
await Bun.write(requiredEnv("SWARM_SCRIPT_RESULT_FILE"), JSON.stringify(result ?? null));
|
|
170
|
+
// The run settles once the entry function resolves. Bun would otherwise keep
|
|
171
|
+
// the process alive while any call the script did not await is pending (a
|
|
172
|
+
// nested script_run that lost a Promise.race, a fire-and-forget kv_set), so
|
|
173
|
+
// the executor kept waiting until that call settled or the wall-clock
|
|
174
|
+
// watchdog killed the run and discarded the result. The timer is unref'd:
|
|
175
|
+
// with nothing pending the process exits at once, as before. Un-awaited work
|
|
176
|
+
// gets this window to finish; whatever is still pending then is stopped.
|
|
177
|
+
setTimeout(() => {
|
|
178
|
+
console.error(
|
|
179
|
+
`[swarm-script] the script returned, but un-awaited calls were still pending ${UNAWAITED_WORK_DRAIN_MS} ms later; they were stopped. Await every call whose effect must land.`,
|
|
180
|
+
);
|
|
181
|
+
process.exit(0);
|
|
182
|
+
}, UNAWAITED_WORK_DRAIN_MS).unref();
|
|
170
183
|
} catch (error) {
|
|
171
184
|
await emitError(error);
|
|
172
185
|
process.exit(1);
|
|
@@ -121,6 +121,9 @@ export interface ScriptExecutor {
|
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
export const MIN_SCRIPT_WALL_CLOCK_MS = 1_000;
|
|
124
|
+
// native: how long calls a script did not await may keep running after its
|
|
125
|
+
// default export resolves, before the harness exits (see eval-harness.ts).
|
|
126
|
+
export const UNAWAITED_WORK_DRAIN_MS = 2_000;
|
|
124
127
|
// Above 2m, steer authors toward durable journaled steps before they reach the
|
|
125
128
|
// 5m hard cap and keep a blocking workflow node open for several minutes.
|
|
126
129
|
export const SCRIPT_LONG_TIMEOUT_HINT_MS = 120_000;
|
|
@@ -48,7 +48,7 @@ describe("script MCP tools", () => {
|
|
|
48
48
|
"script-search":
|
|
49
49
|
"Semantic search over swarm-shared TypeScript scripts (catalog persisted in the agent-swarm DB; callable from agents and workflows). For ephemeral throwaway TS on your local machine, use code-mode instead.",
|
|
50
50
|
"script-run":
|
|
51
|
-
"Run a named swarm-shared script (callable across agents and from workflow `swarm-script` nodes), OR inline source (auto-saved as scratch to the catalog). Inline source executes without the `script-upsert` compile-time typecheck. Use for swarm-visible, durable scripts. For local-only throwaway TS, use code-mode `run`.",
|
|
51
|
+
"Run a named swarm-shared script (callable across agents and from workflow `swarm-script` nodes), OR inline source (auto-saved as scratch to the catalog). Inline source executes without the `script-upsert` compile-time typecheck. Use for swarm-visible, durable scripts. For local-only throwaway TS, use code-mode `run`. The run ends when the script's default export resolves: a call it did not await gets 2 s more, then is stopped (native) or aborted at once (quickjs), so await every write that must land. A `Promise.race` deadline therefore bounds the run; a nested `script_run` that lost the race keeps running on the server under its own wall.",
|
|
52
52
|
"script-upsert":
|
|
53
53
|
'Typecheck and persist a TypeScript script to the swarm catalog under your agent scope (or global if you\'re a lead). Import `ScriptContext` from "swarm-sdk" for a real context type. Other agents and workflow nodes will be able to find and run it. For local-only scripts, use code-mode `save`.',
|
|
54
54
|
"script-delete":
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { afterAll, beforeAll, beforeEach, describe, expect, test } from "bun:test";
|
|
2
|
+
import { NativeScriptExecutor } from "../scripts-runtime/executors/native";
|
|
3
|
+
import {
|
|
4
|
+
DEFAULT_SCRIPT_RESOURCES,
|
|
5
|
+
type ExecutorInput,
|
|
6
|
+
UNAWAITED_WORK_DRAIN_MS,
|
|
7
|
+
} from "../scripts-runtime/executors/types";
|
|
8
|
+
import { SKIP_SANDBOX_SPAWN_TESTS } from "./sandbox-spawn-test-helpers";
|
|
9
|
+
|
|
10
|
+
// A native run used to stay open until every call the script started had
|
|
11
|
+
// settled, even after its default export resolved. A parent that raced a slow
|
|
12
|
+
// nested `ctx.swarm.script_run` against a 100 ms deadline therefore still ran
|
|
13
|
+
// to the 30 s wall, was classified `timeout`, and lost its result. These tests
|
|
14
|
+
// drive the real swarm-sdk against a stand-in API: the nested script_run
|
|
15
|
+
// request is held open for 40 s, like a child that sleeps 40 s.
|
|
16
|
+
|
|
17
|
+
const CHILD_HOLD_MS = 40_000;
|
|
18
|
+
// The production wall. Keeping it here makes the old behaviour fail this file
|
|
19
|
+
// the same way the measured runs failed: at 30 s, with error "timeout".
|
|
20
|
+
const WALL_CLOCK_MS = DEFAULT_SCRIPT_RESOURCES.wallClockMs;
|
|
21
|
+
const TEST_BUDGET_MS = WALL_CLOCK_MS + 15_000;
|
|
22
|
+
|
|
23
|
+
let server: ReturnType<typeof Bun.serve>;
|
|
24
|
+
const held = new Set<() => void>();
|
|
25
|
+
let scriptRunRequests = 0;
|
|
26
|
+
let kvWrites: Array<{ path: string; body: unknown }> = [];
|
|
27
|
+
|
|
28
|
+
beforeAll(() => {
|
|
29
|
+
server = Bun.serve({
|
|
30
|
+
port: 0,
|
|
31
|
+
async fetch(req) {
|
|
32
|
+
const url = new URL(req.url);
|
|
33
|
+
if (req.method === "POST" && url.pathname === "/api/scripts/run") {
|
|
34
|
+
scriptRunRequests++;
|
|
35
|
+
await new Promise<void>((resolve) => {
|
|
36
|
+
const release = () => {
|
|
37
|
+
clearTimeout(timer);
|
|
38
|
+
held.delete(release);
|
|
39
|
+
resolve();
|
|
40
|
+
};
|
|
41
|
+
const timer = setTimeout(release, CHILD_HOLD_MS);
|
|
42
|
+
held.add(release);
|
|
43
|
+
});
|
|
44
|
+
return Response.json({ result: "child-finished" });
|
|
45
|
+
}
|
|
46
|
+
if (req.method === "PUT" && url.pathname.startsWith("/api/kv/")) {
|
|
47
|
+
const body = await req.json();
|
|
48
|
+
// Answer slowly so the write is still in flight when the script returns.
|
|
49
|
+
await Bun.sleep(300);
|
|
50
|
+
kvWrites.push({ path: url.pathname, body });
|
|
51
|
+
return Response.json({ ok: true });
|
|
52
|
+
}
|
|
53
|
+
return new Response("not found", { status: 404 });
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
afterAll(() => {
|
|
59
|
+
for (const release of [...held]) release();
|
|
60
|
+
server.stop(true);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
beforeEach(() => {
|
|
64
|
+
scriptRunRequests = 0;
|
|
65
|
+
kvWrites = [];
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
function input(source: string): ExecutorInput {
|
|
69
|
+
return {
|
|
70
|
+
source,
|
|
71
|
+
args: {},
|
|
72
|
+
configPayload: {
|
|
73
|
+
system: {
|
|
74
|
+
apiKey: { value: "drain-test-secret", isSecret: true },
|
|
75
|
+
agentId: { value: "00000000-0000-4000-8000-000000000001", isSecret: false },
|
|
76
|
+
mcpBaseUrl: { value: `http://127.0.0.1:${server.port}`, isSecret: false },
|
|
77
|
+
},
|
|
78
|
+
user: {},
|
|
79
|
+
},
|
|
80
|
+
resources: { ...DEFAULT_SCRIPT_RESOURCES, memoryMb: 2048, wallClockMs: WALL_CLOCK_MS },
|
|
81
|
+
fsMode: "none",
|
|
82
|
+
network: "open",
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const spawnTest = test.skipIf(SKIP_SANDBOX_SPAWN_TESTS);
|
|
87
|
+
|
|
88
|
+
describe("native run settles when the entry function resolves", () => {
|
|
89
|
+
spawnTest(
|
|
90
|
+
"a Promise.race deadline bounds a run whose nested script_run is still pending",
|
|
91
|
+
async () => {
|
|
92
|
+
const output = await new NativeScriptExecutor().run(
|
|
93
|
+
input(`
|
|
94
|
+
export default async (_args, ctx) => {
|
|
95
|
+
const child = ctx.swarm
|
|
96
|
+
.script_run({ source: "export default async () => { await Bun.sleep(40000); return 1; }", args: {} })
|
|
97
|
+
.then(() => "child");
|
|
98
|
+
const deadline = new Promise((resolve) => setTimeout(() => resolve("deadline"), 100));
|
|
99
|
+
return { winner: await Promise.race([child, deadline]) };
|
|
100
|
+
};
|
|
101
|
+
`),
|
|
102
|
+
);
|
|
103
|
+
|
|
104
|
+
expect(scriptRunRequests).toBe(1);
|
|
105
|
+
expect(output.error).toBeUndefined();
|
|
106
|
+
expect(output.exitCode).toBe(0);
|
|
107
|
+
expect(output.result).toEqual({ winner: "deadline" });
|
|
108
|
+
expect(output.durationMs).toBeLessThan(5_000);
|
|
109
|
+
expect(output.stderr).toContain("un-awaited calls were still pending");
|
|
110
|
+
},
|
|
111
|
+
TEST_BUDGET_MS,
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
spawnTest(
|
|
115
|
+
"an un-awaited kv_set still lands, and a run with nothing pending exits without waiting",
|
|
116
|
+
async () => {
|
|
117
|
+
const output = await new NativeScriptExecutor().run(
|
|
118
|
+
input(`
|
|
119
|
+
export default async (_args, ctx) => {
|
|
120
|
+
// Fired without await: the request is in flight when the script returns.
|
|
121
|
+
void ctx.swarm.kv_set({ key: "fired-at-return", value: "a" });
|
|
122
|
+
// Started later, still inside the drain window.
|
|
123
|
+
void (async () => {
|
|
124
|
+
await Bun.sleep(500);
|
|
125
|
+
await ctx.swarm.kv_set({ key: "fired-after-500ms", value: "b" });
|
|
126
|
+
})();
|
|
127
|
+
return "returned";
|
|
128
|
+
};
|
|
129
|
+
`),
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
expect(output.error).toBeUndefined();
|
|
133
|
+
expect(output.result).toBe("returned");
|
|
134
|
+
expect(kvWrites.map((w) => w.path).sort()).toEqual([
|
|
135
|
+
"/api/kv/fired-after-500ms",
|
|
136
|
+
"/api/kv/fired-at-return",
|
|
137
|
+
]);
|
|
138
|
+
// Both writes settled on their own, so the drain timer never fired.
|
|
139
|
+
expect(output.stderr).not.toContain("un-awaited calls were still pending");
|
|
140
|
+
expect(output.durationMs).toBeLessThan(UNAWAITED_WORK_DRAIN_MS + 2_000);
|
|
141
|
+
},
|
|
142
|
+
TEST_BUDGET_MS,
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
spawnTest(
|
|
146
|
+
"an un-awaited call that starts after the drain window is stopped and reported",
|
|
147
|
+
async () => {
|
|
148
|
+
const output = await new NativeScriptExecutor().run(
|
|
149
|
+
input(`
|
|
150
|
+
export default async (_args, ctx) => {
|
|
151
|
+
void (async () => {
|
|
152
|
+
await Bun.sleep(${UNAWAITED_WORK_DRAIN_MS + 1_500});
|
|
153
|
+
await ctx.swarm.kv_set({ key: "too-late", value: "c" });
|
|
154
|
+
})();
|
|
155
|
+
return "returned";
|
|
156
|
+
};
|
|
157
|
+
`),
|
|
158
|
+
);
|
|
159
|
+
|
|
160
|
+
expect(output.error).toBeUndefined();
|
|
161
|
+
expect(output.result).toBe("returned");
|
|
162
|
+
expect(kvWrites).toEqual([]);
|
|
163
|
+
expect(output.stderr).toContain("un-awaited calls were still pending");
|
|
164
|
+
},
|
|
165
|
+
TEST_BUDGET_MS,
|
|
166
|
+
);
|
|
167
|
+
});
|
package/src/tools/script-run.ts
CHANGED
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from "./script-common";
|
|
12
12
|
|
|
13
13
|
export const SCRIPT_RUN_DESCRIPTION =
|
|
14
|
-
"Run a named swarm-shared script (callable across agents and from workflow `swarm-script` nodes), OR inline source (auto-saved as scratch to the catalog). Inline source executes without the `script-upsert` compile-time typecheck. Use for swarm-visible, durable scripts. For local-only throwaway TS, use code-mode `run`.";
|
|
14
|
+
"Run a named swarm-shared script (callable across agents and from workflow `swarm-script` nodes), OR inline source (auto-saved as scratch to the catalog). Inline source executes without the `script-upsert` compile-time typecheck. Use for swarm-visible, durable scripts. For local-only throwaway TS, use code-mode `run`. The run ends when the script's default export resolves: a call it did not await gets 2 s more, then is stopped (native) or aborted at once (quickjs), so await every write that must land. A `Promise.race` deadline therefore bounds the run; a nested `script_run` that lost the race keeps running on the server under its own wall.";
|
|
15
15
|
|
|
16
16
|
function renderRunOutput(data: unknown): string | undefined {
|
|
17
17
|
if (typeof data !== "object" || data === null) return undefined;
|
|
@@ -73,7 +73,7 @@ export default async function (args: z.infer<typeof argsSchema>, ctx: ScriptCont
|
|
|
73
73
|
- `agentId` is propagated through the `X-Agent-ID` header, so SDK calls run as you. `taskId` is not ambient: pass it in `args` when the script calls `task_storeProgress`.
|
|
74
74
|
- A script invoked from a workflow node may run under a workflow identity. The node may also supply arguments the script needs: when you run that script directly, pass the same arguments the node maps. A script without a strict `argsSchema` then fails deeper in, often as a not-found or resource error instead of a validation error.
|
|
75
75
|
- Return compact structured data. Raw logs, full HTML, big JSON arrays, and file contents stay inside the script.
|
|
76
|
-
- Limits: about 30 s wall clock (up to 5 minutes where the tool exposes it), 1 MB stdout. Never sleep or loop past about 25 s. Chain `wait-for-task` calls instead. The cap also applies to a script called through `ctx.step.swarmScript`; the step's `timeoutMs` does not extend it. A long LLM call, such as a 2,000-word draft, goes in a `ctx.step.rawLlm` step inside `launch-script-run`, never in a called script. A `targetType: "script"` schedule gets 60 s; a manual `script-run` gets 30 s, so a candidate that finishes well under 30 s by hand has margin on the schedule. A nested `ctx.swarm.script_run` gets its own 30 s but runs inside its caller's remaining time: run slow children as sibling calls from the outer script, not deeper in the chain.
|
|
76
|
+
- Limits: about 30 s wall clock (up to 5 minutes where the tool exposes it), 1 MB stdout. Never sleep or loop past about 25 s. Chain `wait-for-task` calls instead. The cap also applies to a script called through `ctx.step.swarmScript`; the step's `timeoutMs` does not extend it. A long LLM call, such as a 2,000-word draft, goes in a `ctx.step.rawLlm` step inside `launch-script-run`, never in a called script. A `targetType: "script"` schedule gets 60 s; a manual `script-run` gets 30 s, so a candidate that finishes well under 30 s by hand has margin on the schedule. A nested `ctx.swarm.script_run` gets its own 30 s but runs inside its caller's remaining time: run slow children as sibling calls from the outer script, not deeper in the chain. The run ends when your default export resolves. A call you did not await gets about 2 s more and is then stopped (`quickjs` aborts it at once), so await every write that must land. That makes a `Promise.race` deadline bound the run; a nested `script_run` that lost the race keeps running on the server under its own 30 s.
|
|
77
77
|
|
|
78
78
|
### What `ctx` holds
|
|
79
79
|
|
|
@@ -68,7 +68,7 @@ export default async function (args: z.infer<typeof argsSchema>, ctx: ScriptCont
|
|
|
68
68
|
- `agentId` is propagated through the `X-Agent-ID` header, so SDK calls run as you. `taskId` is not ambient: pass it in `args` when the script calls `task_storeProgress`.
|
|
69
69
|
- A script invoked from a workflow node may run under a workflow identity. The node may also supply arguments the script needs: when you run that script directly, pass the same arguments the node maps. A script without a strict `argsSchema` then fails deeper in, often as a not-found or resource error instead of a validation error.
|
|
70
70
|
- Return compact structured data. Raw logs, full HTML, big JSON arrays, and file contents stay inside the script.
|
|
71
|
-
- Limits: about 30 s wall clock (up to 5 minutes where the tool exposes it), 1 MB stdout. Never sleep or loop past about 25 s. Chain `wait-for-task` calls instead. The cap also applies to a script called through `ctx.step.swarmScript`; the step's `timeoutMs` does not extend it. A long LLM call, such as a 2,000-word draft, goes in a `ctx.step.rawLlm` step inside `launch-script-run`, never in a called script. A `targetType: "script"` schedule gets 60 s; a manual `script-run` gets 30 s, so a candidate that finishes well under 30 s by hand has margin on the schedule. A nested `ctx.swarm.script_run` gets its own 30 s but runs inside its caller's remaining time: run slow children as sibling calls from the outer script, not deeper in the chain.
|
|
71
|
+
- Limits: about 30 s wall clock (up to 5 minutes where the tool exposes it), 1 MB stdout. Never sleep or loop past about 25 s. Chain `wait-for-task` calls instead. The cap also applies to a script called through `ctx.step.swarmScript`; the step's `timeoutMs` does not extend it. A long LLM call, such as a 2,000-word draft, goes in a `ctx.step.rawLlm` step inside `launch-script-run`, never in a called script. A `targetType: "script"` schedule gets 60 s; a manual `script-run` gets 30 s, so a candidate that finishes well under 30 s by hand has margin on the schedule. A nested `ctx.swarm.script_run` gets its own 30 s but runs inside its caller's remaining time: run slow children as sibling calls from the outer script, not deeper in the chain. The run ends when your default export resolves. A call you did not await gets about 2 s more and is then stopped (`quickjs` aborts it at once), so await every write that must land. That makes a `Promise.race` deadline bound the run; a nested `script_run` that lost the race keeps running on the server under its own 30 s.
|
|
72
72
|
|
|
73
73
|
### What `ctx` holds
|
|
74
74
|
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
isUserAllowed2,
|
|
3
|
-
registerMessageHandler2,
|
|
4
|
-
init_handlers
|
|
5
|
-
} from "./cli-8fknbnhw.js";
|
|
6
|
-
import"./cli-rmmpt0wm.js";
|
|
7
|
-
import"./cli-6t09sdhy.js";
|
|
8
|
-
import"./cli-rfywm85n.js";
|
|
9
|
-
import"./cli-4txa0ter.js";
|
|
10
|
-
import"./cli-f3vq58d2.js";
|
|
11
|
-
import"./cli-j790gp2w.js";
|
|
12
|
-
import"./cli-sdtt3men.js";
|
|
13
|
-
import"./cli-7cp6aa1q.js";
|
|
14
|
-
import"./cli-m28atx8q.js";
|
|
15
|
-
import"./cli-n9ftpys4.js";
|
|
16
|
-
import"./cli-pasjcnmj.js";
|
|
17
|
-
import"./cli-qfedvmcr.js";
|
|
18
|
-
import"./cli-p1bq50aa.js";
|
|
19
|
-
import"./cli-a7wvp2km.js";
|
|
20
|
-
import"./cli-qsnnd04k.js";
|
|
21
|
-
import"./cli-s7t6p9my.js";
|
|
22
|
-
import"./cli-8kzasymh.js";
|
|
23
|
-
import"./cli-c55z5chy.js";
|
|
24
|
-
import"./cli-gxkx0zzp.js";
|
|
25
|
-
import"./cli-h38x262p.js";
|
|
26
|
-
import"./cli-eddnyg3t.js";
|
|
27
|
-
init_handlers();
|
|
28
|
-
|
|
29
|
-
export {
|
|
30
|
-
isUserAllowed2 as isUserAllowed,
|
|
31
|
-
registerMessageHandler2 as registerMessageHandler
|
|
32
|
-
};
|
package/dist/index-835xdgnm.js
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
calculateNextRun2,
|
|
3
|
-
startScheduler2,
|
|
4
|
-
stopScheduler2,
|
|
5
|
-
runScheduleNow2,
|
|
6
|
-
init_scheduler2
|
|
7
|
-
} from "./cli-rfywm85n.js";
|
|
8
|
-
import"./cli-4txa0ter.js";
|
|
9
|
-
import"./cli-f3vq58d2.js";
|
|
10
|
-
import"./cli-j790gp2w.js";
|
|
11
|
-
import"./cli-sdtt3men.js";
|
|
12
|
-
import"./cli-7cp6aa1q.js";
|
|
13
|
-
import"./cli-m28atx8q.js";
|
|
14
|
-
import"./cli-n9ftpys4.js";
|
|
15
|
-
import"./cli-pasjcnmj.js";
|
|
16
|
-
import"./cli-qfedvmcr.js";
|
|
17
|
-
import"./cli-p1bq50aa.js";
|
|
18
|
-
import"./cli-a7wvp2km.js";
|
|
19
|
-
import"./cli-qsnnd04k.js";
|
|
20
|
-
import"./cli-s7t6p9my.js";
|
|
21
|
-
import"./cli-8kzasymh.js";
|
|
22
|
-
import"./cli-c55z5chy.js";
|
|
23
|
-
import"./cli-gxkx0zzp.js";
|
|
24
|
-
import"./cli-h38x262p.js";
|
|
25
|
-
import"./cli-eddnyg3t.js";
|
|
26
|
-
init_scheduler2();
|
|
27
|
-
|
|
28
|
-
export {
|
|
29
|
-
calculateNextRun2 as calculateNextRun,
|
|
30
|
-
runScheduleNow2 as runScheduleNow,
|
|
31
|
-
startScheduler2 as startScheduler,
|
|
32
|
-
stopScheduler2 as stopScheduler
|
|
33
|
-
};
|
package/dist/index-d469300x.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
getExecutorRegistry2,
|
|
3
|
-
initWorkflows2,
|
|
4
|
-
init_workflows
|
|
5
|
-
} from "./cli-rfywm85n.js";
|
|
6
|
-
import"./cli-4txa0ter.js";
|
|
7
|
-
import"./cli-f3vq58d2.js";
|
|
8
|
-
import"./cli-j790gp2w.js";
|
|
9
|
-
import"./cli-sdtt3men.js";
|
|
10
|
-
import"./cli-7cp6aa1q.js";
|
|
11
|
-
import"./cli-m28atx8q.js";
|
|
12
|
-
import"./cli-n9ftpys4.js";
|
|
13
|
-
import {
|
|
14
|
-
retryFailedRun2,
|
|
15
|
-
cancelWorkflowRun2
|
|
16
|
-
} from "./cli-pasjcnmj.js";
|
|
17
|
-
import {
|
|
18
|
-
startWorkflowExecution2
|
|
19
|
-
} from "./cli-qfedvmcr.js";
|
|
20
|
-
import"./cli-p1bq50aa.js";
|
|
21
|
-
import"./cli-a7wvp2km.js";
|
|
22
|
-
import"./cli-qsnnd04k.js";
|
|
23
|
-
import"./cli-s7t6p9my.js";
|
|
24
|
-
import"./cli-8kzasymh.js";
|
|
25
|
-
import"./cli-c55z5chy.js";
|
|
26
|
-
import"./cli-gxkx0zzp.js";
|
|
27
|
-
import"./cli-h38x262p.js";
|
|
28
|
-
import"./cli-eddnyg3t.js";
|
|
29
|
-
init_workflows();
|
|
30
|
-
|
|
31
|
-
export {
|
|
32
|
-
cancelWorkflowRun2 as cancelWorkflowRun,
|
|
33
|
-
getExecutorRegistry2 as getExecutorRegistry,
|
|
34
|
-
initWorkflows2 as initWorkflows,
|
|
35
|
-
retryFailedRun2 as retryFailedRun,
|
|
36
|
-
startWorkflowExecution2 as startWorkflowExecution
|
|
37
|
-
};
|
package/dist/index-rzqwp11g.js
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import"./cli-ns59dc6r.js";
|
|
2
|
-
import {
|
|
3
|
-
parseHeartbeatIntervalMs2,
|
|
4
|
-
startHeartbeat2,
|
|
5
|
-
stopHeartbeat2
|
|
6
|
-
} from "./cli-abejgen1.js";
|
|
7
|
-
import"./cli-6wxjceza.js";
|
|
8
|
-
import"./cli-m4dqmnbp.js";
|
|
9
|
-
import"./cli-rfywm85n.js";
|
|
10
|
-
import"./cli-4txa0ter.js";
|
|
11
|
-
import"./cli-f3vq58d2.js";
|
|
12
|
-
import"./cli-j790gp2w.js";
|
|
13
|
-
import"./cli-sdtt3men.js";
|
|
14
|
-
import"./cli-7cp6aa1q.js";
|
|
15
|
-
import"./cli-m28atx8q.js";
|
|
16
|
-
import"./cli-n9ftpys4.js";
|
|
17
|
-
import"./cli-pasjcnmj.js";
|
|
18
|
-
import"./cli-qfedvmcr.js";
|
|
19
|
-
import"./cli-p1bq50aa.js";
|
|
20
|
-
import"./cli-a7wvp2km.js";
|
|
21
|
-
import"./cli-qsnnd04k.js";
|
|
22
|
-
import"./cli-s7t6p9my.js";
|
|
23
|
-
import"./cli-8kzasymh.js";
|
|
24
|
-
import"./cli-c55z5chy.js";
|
|
25
|
-
import"./cli-gxkx0zzp.js";
|
|
26
|
-
import"./cli-h38x262p.js";
|
|
27
|
-
import"./cli-eddnyg3t.js";
|
|
28
|
-
export {
|
|
29
|
-
parseHeartbeatIntervalMs2 as parseHeartbeatIntervalMs,
|
|
30
|
-
startHeartbeat2 as startHeartbeat,
|
|
31
|
-
stopHeartbeat2 as stopHeartbeat
|
|
32
|
-
};
|