@desplega.ai/agent-swarm 1.160.0 → 1.162.0
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/README.md +4 -3
- package/dist/{acp-adapter-2mjwcsfh.js → acp-adapter-74m73ae9.js} +163 -49
- package/dist/{actions-e43rxskr.js → actions-4sr14gnt.js} +42 -38
- package/dist/{anthropic-messages-5qx80j9k.js → anthropic-messages-8xxrzky9.js} +22 -26
- package/dist/{app-mc7xfagn.js → app-pt68fbwp.js} +17 -14
- package/dist/{artifact-3v5t9jtg.js → artifact-fey7dvj9.js} +3 -2
- package/dist/{assistant-sedkzv3b.js → assistant-cv3jytks.js} +43 -39
- package/dist/{azure-openai-responses-nfb21z9a.js → azure-openai-responses-f5cqsyj8.js} +15 -10
- package/dist/{boot-reembed-m3656j2n.js → boot-reembed-4ht4gqth.js} +17 -14
- package/dist/{boot-reembed-cqz9swn5.js → boot-reembed-nxpcvpj9.js} +16 -13
- package/dist/{boot-scrub-logs-xbxf5d7w.js → boot-scrub-logs-k93kyw8k.js} +13 -10
- package/dist/boot-seeds-1skcrs0e.js +32 -0
- package/dist/{claude-adapter-dc6289mc.js → claude-adapter-r5g0tzge.js} +39 -30
- package/dist/{claude-managed-adapter-naaw51me.js → claude-managed-adapter-yxkfxg8j.js} +6 -5
- package/dist/{claude-managed-setup-eacvchx0.js → claude-managed-setup-pkyrgshb.js} +27 -27
- package/dist/{claude-sdk-session-bqp2xvym.js → claude-sdk-session-jxyxnrwd.js} +8041 -7910
- package/dist/{cli-4derpgyk.js → cli-2hhfhfq5.js} +6 -1
- package/dist/{cli-rykfmgwg.js → cli-2x0e561b.js} +1 -1
- package/dist/{cli-tzx2ke1v.js → cli-2zy95vhm.js} +137 -64
- package/dist/{cli-0x01kwrd.js → cli-4cwxn7gp.js} +47 -186
- package/dist/{cli-xjcywfsf.js → cli-4dcpaefp.js} +12 -11
- package/dist/{cli-v7fn5gms.js → cli-4x0csdjq.js} +164 -76
- package/dist/{cli-12tszpk9.js → cli-5bcd7sfy.js} +91 -29
- package/dist/{cli-jz4w45qt.js → cli-5k6k8ta3.js} +190 -50
- package/dist/{cli-tpq83z89.js → cli-5xhpb3kv.js} +20 -19
- package/dist/{cli-r1mxd1xh.js → cli-7af8yhav.js} +6 -179
- package/dist/{cli-jajnsm8q.js → cli-7tre70zp.js} +18160 -31345
- package/dist/{cli-447dt1h3.js → cli-8ev9xqnx.js} +218 -25
- package/dist/cli-bsky8g7w.js +449 -0
- package/dist/{cli-0z2v4nhw.js → cli-cat6h73s.js} +1 -1
- package/dist/{cli-25fcq4b4.js → cli-cebmgwsc.js} +15 -11
- package/dist/{cli-shkxm1vn.js → cli-cvatsam7.js} +189 -13
- package/dist/{cli-2658f6at.js → cli-cvk6yzw5.js} +6 -8
- package/dist/cli-dbmwby6a.js +9 -0
- package/dist/{cli-ptr8h7kp.js → cli-eg0b3p0k.js} +5 -218
- package/dist/cli-f9w1semm.js +413 -0
- package/dist/{cli-523679eh.js → cli-g739zqzt.js} +6 -5
- package/dist/{cli-dv6cdjs2.js → cli-gd4favx9.js} +28 -7
- package/dist/{cli-c8a36vcc.js → cli-gpqpmns7.js} +2 -2
- package/dist/{cli-5nbmpy8w.js → cli-hb5c2x5y.js} +1 -1
- package/dist/{cli-741yb0xx.js → cli-hmsw1gpy.js} +55 -169
- package/dist/{cli-qydf22qq.js → cli-jf7wmv1r.js} +2562 -735
- package/dist/{cli-mfe5btp9.js → cli-jxs2ygaw.js} +317 -121
- package/dist/{cli-kmcpfwn2.js → cli-jyy6pm2f.js} +19 -3
- package/dist/cli-kdkwd3yr.js +615 -0
- package/dist/{cli-6cs6wzxt.js → cli-kh04eqwe.js} +2 -2
- package/dist/{cli-9hsgwz4w.js → cli-kp42yek0.js} +1309 -391
- package/dist/cli-ma3zvh39.js +10404 -0
- package/dist/{cli-ybgv4kw2.js → cli-mbssg1xv.js} +9 -2
- package/dist/{cli-jsp14b6c.js → cli-mzfth0bp.js} +38 -1
- package/dist/{cli-r2ap2czm.js → cli-nexqx4ve.js} +6 -0
- package/dist/{cli-f8gy6r2r.js → cli-nq7yqw7b.js} +19 -8
- package/dist/{cli-10nhj6xq.js → cli-nt8hecg9.js} +34 -33
- package/dist/cli-p0r8sxj5.js +303 -0
- package/dist/{cli-58e8yr0d.js → cli-pkd6s2wy.js} +4 -2
- package/dist/{cli-a8dvhzrt.js → cli-q24re23n.js} +7 -5
- package/dist/cli-qjjvzwzd.js +222 -0
- package/dist/cli-qrgt5bqf.js +189 -0
- package/dist/{cli-et8m9xsv.js → cli-rfjw9jw2.js} +22 -10
- package/dist/{cli-7e398j1h.js → cli-rj0gqwwp.js} +3 -3
- package/dist/{cli-btfv8y88.js → cli-rnyzn44p.js} +2 -2
- package/dist/{cli-d5czme6m.js → cli-s3hwpt9v.js} +4754 -4945
- package/dist/{cli-0jwe9034.js → cli-sptrj5f5.js} +3 -3
- package/dist/{cli-0q3avq3s.js → cli-sqvfa090.js} +19 -11
- package/dist/{cli-azhgzetg.js → cli-swfmp1fx.js} +27 -27
- package/dist/{cli-jyk0ynw2.js → cli-t845n9xk.js} +23 -10
- package/dist/{cli-zpep9q5e.js → cli-tcen9p5w.js} +20 -15
- package/dist/{cli-74h9hscv.js → cli-tre4bdgq.js} +1 -1
- package/dist/{cli-pm1rst0h.js → cli-twrh04ap.js} +30 -15
- package/dist/{cli-phsaj4xq.js → cli-v0pvvhfq.js} +1 -1
- package/dist/{cli-ydmcgve1.js → cli-vc9bp061.js} +5 -5
- package/dist/{cli-g2whhdrf.js → cli-vxe6qa4h.js} +1 -1
- package/dist/{cli-vctdqs5h.js → cli-vy3ed88x.js} +15 -2
- package/dist/{cli-br0qdrnp.js → cli-vyqs9ya8.js} +18 -18
- package/dist/{cli-cpvsaqsw.js → cli-w0bwte75.js} +8 -5
- package/dist/cli-wbvnn6tk.js +861 -0
- package/dist/{cli-r94z9p1z.js → cli-wgbezhw2.js} +3 -0
- package/dist/{cli-evvtk35y.js → cli-wjgs5wxe.js} +7 -7
- package/dist/cli-wxkkd0e0.js +33 -0
- package/dist/{cli-0wgxmwf6.js → cli-xk79303e.js} +20 -7
- package/dist/{cli-ktmyrtpn.js → cli-xqpk3rp7.js} +33 -10
- package/dist/{cli-ygwm91nt.js → cli-yy6dew39.js} +1 -1
- package/dist/cli-zp38xvtm.js +9487 -0
- package/dist/{cli-tfky2838.js → cli-zvhd3f64.js} +4 -4
- package/dist/{cli-jayjpjmb.js → cli-zxqx25nz.js} +66 -23
- package/dist/cli.js +40 -32
- package/dist/{cloudflare-workers-ai-system-one-k6fbxw9d.js → cloudflare-workers-ai-system-one-k8ddqjkq.js} +8 -6
- package/dist/{codex-adapter-nmxcatww.js → codex-adapter-esvmnhn7.js} +24 -23
- package/dist/{codex-hook-20me6byw.js → codex-hook-m73jmqgx.js} +19 -3
- package/dist/{codex-login-w6fz4xbz.js → codex-login-cf7mzsgg.js} +2 -2
- package/dist/{codex-session-runner-90aa80ev.js → codex-session-runner-ban9excr.js} +24 -23
- package/dist/{commands-8wcq1kn7.js → commands-75413p2n.js} +13 -10
- package/dist/{db-j40kc4se.js → db-7f5pecwg.js} +17 -10
- package/dist/{dispatcher-4zqy768d.js → dispatcher-fh9at8nz.js} +41 -37
- package/dist/dsh-adapter-wpze65d4.js +24 -0
- package/dist/{e2b-ez07znam.js → e2b-gjgdjp91.js} +12 -9
- package/dist/easter-egg-3d-3w5c2n4c.js +1057 -0
- package/dist/{execute-6e7qeyk4.js → execute-f50wg9nh.js} +203 -49
- package/dist/{google-generative-ai-k6n5nbpp.js → google-generative-ai-jxxpnegy.js} +2 -2
- package/dist/{google-vertex-44xxtcvp.js → google-vertex-x7q1angm.js} +5 -5
- package/dist/{handlers-kjdce1w5.js → handlers-w13787bb.js} +44 -40
- package/dist/{hook-r2t4bqfg.js → hook-46g1jrvx.js} +34 -20
- package/dist/{hook-czx13n12.js → hook-4tpts2ry.js} +25 -21
- package/dist/{http-3bbb19be.js → http-19pzbfrt.js} +1440 -283
- package/dist/{index-668me3f0.js → index-8fd4dm4h.js} +42 -38
- package/dist/{index-fg0dsp6c.js → index-dqmp15bq.js} +41 -37
- package/dist/{index-kkv84jq9.js → index-qb4q1y3e.js} +41 -37
- package/dist/index-s75wc4wd.js +33 -0
- package/dist/{index-zg7vp46x.js → index-scptvdxg.js} +64 -38
- package/dist/{keepalive-yra8dy57.js → keepalive-xa5ts9cd.js} +15 -12
- package/dist/{lead-va0pad2c.js → lead-qp4xkvjq.js} +59 -54
- package/dist/{maintenance-hqewtmyg.js → maintenance-rm5885hm.js} +17 -14
- package/dist/{mistral-conversations-pc3ntnxt.js → mistral-conversations-rw7fbt22.js} +4 -4
- package/dist/{node-a5e00qhp.js → node-8zkdq42h.js} +834 -833
- package/dist/node-f0ykebbv.js +2107 -0
- package/dist/node-wyamey5r.js +19 -0
- package/dist/{oauth-refresh-sweep-7rdt1m9n.js → oauth-refresh-sweep-1csdfebf.js} +14 -11
- package/dist/{onboard-j6ms6d0x.js → onboard-r6b78cs4.js} +10 -10
- package/dist/{openai-codex-responses-bbancrr0.js → openai-codex-responses-efvrgrq3.js} +4 -4
- package/dist/{openai-completions-jpaj5g2b.js → openai-completions-bbbrrz4z.js} +12 -8
- package/dist/{openai-responses-200k1wx4.js → openai-responses-9jjyrcm1.js} +15 -10
- package/dist/{opencode-adapter-89rabkw2.js → opencode-adapter-kb3g6pkf.js} +12 -9
- package/dist/{otel-impl-a792rjz0.js → otel-impl-0y9knpky.js} +6 -6
- package/dist/{pi-mono-adapter-g7qzvr3v.js → pi-mono-adapter-z6s1bme2.js} +128 -37
- package/dist/{pricing-refresh-wx0tp7cb.js → pricing-refresh-mth26tgp.js} +15 -12
- package/dist/{rbac-roles-8tzawacv.js → rbac-roles-kwntb23q.js} +17 -12
- package/dist/rbac-roles-vpk4ebm8.js +45 -0
- package/dist/{registry-v5wytg0s.js → registry-km6t1jd2.js} +1 -1
- package/dist/{render-v2-mm7zswb8.js → render-v2-hcm7h00y.js} +17 -14
- package/dist/{runtime-zyssgse0.js → runtime-vfjsfsc5.js} +5 -4
- package/dist/{setup-8y70ys6t.js → setup-hbyzd65h.js} +2 -2
- package/dist/{virtual-modules-6nmk7h3n.js → virtual-modules-9bv7ry91.js} +9 -7
- package/dist/{work-objects-fg6xkb0n.js → work-objects-m09sxnhe.js} +44 -40
- package/dist/{worker-wmwhxsph.js → worker-0h35rvk4.js} +59 -54
- package/dist/{x-n3e0v3xa.js → x-f1gt1pz3.js} +2 -2
- package/openapi.json +699 -26
- package/package.json +19 -11
- package/src/azure-devops/api.ts +121 -0
- package/src/azure-devops/auth.ts +78 -0
- package/src/azure-devops/handlers.ts +413 -0
- package/src/azure-devops/index.ts +27 -0
- package/src/azure-devops/templates.ts +108 -0
- package/src/azure-devops/types.ts +90 -0
- package/src/be/api-drain.ts +184 -0
- package/src/be/db/tasks/read.ts +32 -7
- package/src/be/db/tasks/write.ts +21 -4
- package/src/be/db-client.ts +11 -2
- package/src/be/db-retention.ts +95 -32
- package/src/be/db.ts +44 -19
- package/src/be/memory/constants.ts +16 -0
- package/src/be/memory/graph-expansion.ts +8 -1
- package/src/be/memory/index-content.ts +20 -1
- package/src/be/memory/key-guard.ts +93 -0
- package/src/be/memory/key-paths.ts +103 -0
- package/src/be/memory/link-resolver.ts +29 -3
- package/src/be/memory/providers/sqlite-store.ts +152 -45
- package/src/be/memory/raters/llm-summarizer.ts +10 -4
- package/src/be/memory/raters/llm.ts +15 -5
- package/src/be/memory/raters/store.ts +6 -3
- package/src/be/memory/raters/types.ts +11 -0
- package/src/be/memory/reranker.ts +38 -7
- package/src/be/memory/types.ts +12 -1
- package/src/be/migrations/190_memory_rating_model.sql +7 -0
- package/src/be/migrations/191_context_versions_previous_index.sql +8 -0
- package/src/be/migrations/192_favorites_agent_fs_path.sql +36 -0
- package/src/be/onboarding.ts +7 -1
- package/src/be/pricing-normalize.ts +4 -2
- package/src/be/scripts/typecheck.ts +4 -3
- package/src/be/seed-pricing.ts +16 -0
- package/src/be/seed-prompt-templates.ts +1 -0
- package/src/be/swarm-config-guard.ts +46 -17
- package/src/be/task-citations.ts +11 -5
- package/src/be/users.ts +3 -0
- package/src/cli.tsx +3 -2
- package/src/comb/agent-fs.ts +39 -0
- package/src/comb/config.ts +37 -0
- package/src/comb/markers.ts +37 -0
- package/src/comb/review-batch.ts +486 -0
- package/src/comb/templates.ts +88 -0
- package/src/commands/claude-managed-setup.ts +33 -31
- package/src/commands/context-preamble.ts +4 -1
- package/src/commands/hook.ts +2 -1
- package/src/commands/provider-credentials.ts +28 -15
- package/src/commands/runner.ts +458 -110
- package/src/commands/templates.ts +10 -0
- package/src/e2b/env.ts +2 -0
- package/src/extensions/catalog.generated.json +17 -0
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/fs/agent-fs-provider.ts +106 -2
- package/src/github/handlers.ts +10 -74
- package/src/github/reactions.ts +119 -138
- package/src/github/task-reactions.ts +34 -11
- package/src/heartbeat/heartbeat.ts +4 -0
- package/src/hooks/codex-hook.ts +25 -1
- package/src/hooks/hook.ts +14 -1
- package/src/hooks/pr-body-guard.ts +983 -0
- package/src/http/agents.ts +1 -1
- package/src/http/all-routes.ts +1 -0
- package/src/http/assets.ts +5 -17
- package/src/http/comb.ts +131 -0
- package/src/http/core.ts +14 -1
- package/src/http/extensions.ts +51 -27
- package/src/http/fs.ts +9 -17
- package/src/http/index.ts +27 -9
- package/src/http/mcp-user.ts +8 -13
- package/src/http/mcp.ts +19 -12
- package/src/http/memory.ts +80 -14
- package/src/http/onboarding.ts +21 -2
- package/src/http/poll.ts +30 -3
- package/src/http/realtime.ts +62 -0
- package/src/http/request-principal.ts +22 -0
- package/src/http/session-data.ts +6 -4
- package/src/http/stats.ts +1 -0
- package/src/http/status.ts +34 -2
- package/src/http/tasks.ts +17 -3
- package/src/http/users.ts +1 -1
- package/src/http/webhooks.ts +120 -2
- package/src/kv-reserved-namespaces.ts +10 -5
- package/src/providers/claude-adapter.ts +84 -16
- package/src/providers/claude-managed-adapter.ts +29 -2
- package/src/providers/codex-adapter.ts +1 -1
- package/src/providers/codex-skill-resolver.ts +6 -0
- package/src/providers/dsh-adapter.ts +204 -7
- package/src/providers/opencode-adapter.ts +24 -3
- package/src/providers/pi-mono-adapter.ts +154 -5
- package/src/providers/pi-mono-extension.ts +1 -1
- package/src/providers/pricing-sources.md +5 -1
- package/src/providers/reasoning-effort.ts +10 -2
- package/src/providers/types.ts +1 -1
- package/src/rbac/legacy-policy.ts +3 -0
- package/src/rbac/permissions.ts +14 -0
- package/src/realtime/auth.ts +63 -1
- package/src/realtime/tickets.ts +52 -0
- package/src/realtime/transport.ts +51 -22
- package/src/scripts-runtime/types/stdlib.d.ts +13 -5
- package/src/scripts-runtime/types/swarm-extension.d.ts +7 -3
- package/src/scripts-runtime/types/swarm-sdk.d.ts +13 -5
- package/src/tasks/context-key.ts +38 -1
- package/src/telemetry-context.ts +175 -0
- package/src/telemetry-contract/EVENTS.md +81 -0
- package/src/telemetry-contract/SOURCE.json +9 -0
- package/src/telemetry-contract/catalog.json +1335 -0
- package/src/telemetry-contract/index.ts +60 -0
- package/src/telemetry-contract/types.gen.ts +1971 -0
- package/src/telemetry-identity.ts +129 -0
- package/src/telemetry-snapshot.ts +211 -0
- package/src/telemetry-trigger.ts +125 -0
- package/src/telemetry-types.typetest.ts +40 -0
- package/src/telemetry.ts +271 -67
- package/src/tests/api-drain-e2e.test.ts +249 -0
- package/src/tests/api-drain-worker-e2e.test.ts +216 -0
- package/src/tests/api-drain.test.ts +351 -0
- package/src/tests/azure-devops-auth.test.ts +100 -0
- package/src/tests/azure-devops-handlers.test.ts +324 -0
- package/src/tests/azure-devops-webhook-malformed.test.ts +96 -0
- package/src/tests/claude-default-route.test.ts +260 -0
- package/src/tests/claude-managed-adapter.test.ts +47 -0
- package/src/tests/claude-managed-setup.test.ts +48 -0
- package/src/tests/claude-prompt-body-once.test.ts +117 -0
- package/src/tests/claude-routes-e2e.test.ts +316 -0
- package/src/tests/comb-config-guard.test.ts +38 -0
- package/src/tests/comb-links.test.ts +162 -0
- package/src/tests/comb-markers.test.ts +68 -0
- package/src/tests/comb-review-batch.test.ts +770 -0
- package/src/tests/comb-status.test.ts +152 -0
- package/src/tests/context-versions-retention.test.ts +314 -0
- package/src/tests/core-auth.test.ts +7 -0
- package/src/tests/db-retention.test.ts +14 -14
- package/src/tests/db-task-read-contract.test.ts +3 -0
- package/src/tests/db-task-write-contract.test.ts +3 -0
- package/src/tests/docs-index-footprint.test.js +3 -3
- package/src/tests/dsh-adapter.test.ts +134 -2
- package/src/tests/dsh-usage.test.ts +153 -0
- package/src/tests/extensions-catalog.test.ts +1 -0
- package/src/tests/extensions-example-deploy-awareness.test.ts +301 -0
- package/src/tests/extensions-http.test.ts +137 -10
- package/src/tests/extensions-mcp-tools.test.ts +28 -0
- package/src/tests/favorites-agent-fs-path.test.ts +226 -0
- package/src/tests/fetch-resolved-env.test.ts +24 -0
- package/src/tests/fixtures/azure-devops/pull-request-commented.json +129 -0
- package/src/tests/fixtures/azure-devops/pull-request-created.json +88 -0
- package/src/tests/fixtures/fake-claude-routes.ts +229 -0
- package/src/tests/github-handlers-reactions.test.ts +486 -0
- package/src/tests/github-reactions.test.ts +280 -0
- package/src/tests/harness-cli-version.test.ts +62 -0
- package/src/tests/http-api-integration.test.ts +21 -0
- package/src/tests/http-task-write-ownership.test.ts +24 -1
- package/src/tests/internal-ai/complete-structured.test.ts +94 -0
- package/src/tests/internal-ai/credentials.test.ts +22 -0
- package/src/tests/internal-ai/models.test.ts +36 -2
- package/src/tests/internal-ai/schema-parity.test.ts +25 -1
- package/src/tests/internal-ai/summarize-session.test.ts +23 -7
- package/src/tests/mcp-user-route.test.ts +133 -0
- package/src/tests/memory-key-paths.test.ts +1055 -0
- package/src/tests/memory-link-resolver.test.ts +34 -0
- package/src/tests/memory-rate-endpoint.test.ts +66 -0
- package/src/tests/memory-rater-llm-summarizer.test.ts +2 -1
- package/src/tests/memory-rater-llm.test.ts +73 -0
- package/src/tests/memory-rater-store.test.ts +31 -0
- package/src/tests/memory-reranker.test.ts +40 -0
- package/src/tests/onboarding.test.ts +108 -0
- package/src/tests/opencode-adapter.test.ts +57 -0
- package/src/tests/opencode-plugin.test.ts +4 -0
- package/src/tests/pi-codemode.test.ts +82 -4
- package/src/tests/pi-mono-adapter.test.ts +265 -2
- package/src/tests/pr-body-leaks.test.ts +789 -0
- package/src/tests/preload.ts +14 -0
- package/src/tests/provider-registration.test.ts +0 -2
- package/src/tests/providers/pi-cost.test.ts +190 -4
- package/src/tests/rbac-engine.test.ts +25 -1
- package/src/tests/realtime-room-auth.test.ts +104 -1
- package/src/tests/realtime-tickets.test.ts +74 -0
- package/src/tests/realtime-transport.test.ts +131 -4
- package/src/tests/runner-api-drain.test.ts +301 -0
- package/src/tests/runner-fallback-output.test.ts +61 -0
- package/src/tests/runner-fenced-json-output.test.ts +178 -0
- package/src/tests/runner-slot-reconcile.test.ts +199 -0
- package/src/tests/script-connections.test.ts +6 -0
- package/src/tests/send-task-requested-by.test.ts +133 -15
- package/src/tests/session-costs-recompute-all-providers.test.ts +23 -0
- package/src/tests/task-lifecycle-telemetry.test.ts +8 -3
- package/src/tests/task-reactions.test.ts +29 -6
- package/src/tests/telemetry-context.test.ts +314 -0
- package/src/tests/telemetry-init.test.ts +51 -19
- package/src/tests/telemetry-snapshot.test.ts +229 -0
- package/src/tests/telemetry-trigger.test.ts +200 -0
- package/src/tests/template-registry-helpers.ts +1 -0
- package/src/tests/vcs-azure-devops.test.ts +73 -0
- package/src/tests/webhooks-task-blocked.test.ts +23 -0
- package/src/tests/workflow-agent-task-retry.test.ts +363 -0
- package/src/tests/workflow-definition-telemetry.test.ts +4 -4
- package/src/tests/workflow-llm.test.ts +14 -0
- package/src/tools/context-diff.ts +20 -0
- package/src/tools/extension-install.ts +27 -16
- package/src/tools/memory-edit.ts +47 -3
- package/src/tools/memory-search.ts +13 -1
- package/src/tools/memory-store.ts +55 -3
- package/src/tools/poll-task.ts +20 -1
- package/src/tools/send-task.ts +9 -1
- package/src/tools/task-action.ts +11 -0
- package/src/types.ts +45 -8
- package/src/utils/api-drain.ts +24 -0
- package/src/utils/constants.ts +57 -16
- package/src/utils/credentials.test.ts +31 -1
- package/src/utils/credentials.ts +20 -9
- package/src/utils/dsh-usage.ts +53 -0
- package/src/utils/harness-cli-version.ts +6 -4
- package/src/utils/internal-ai/complete-structured.ts +26 -3
- package/src/utils/internal-ai/credentials.ts +23 -9
- package/src/utils/internal-ai/index.ts +8 -1
- package/src/utils/internal-ai/models.ts +34 -8
- package/src/utils/internal-ai/summarize-session.ts +22 -8
- package/src/utils/pr-body-leaks.ts +172 -0
- package/src/utils/secret-scrubber.ts +8 -0
- package/src/utils/task-attachment-links.ts +14 -8
- package/src/vcs/azure-devops.ts +80 -0
- package/src/vcs/index.ts +5 -1
- package/src/vcs/types.ts +2 -2
- package/src/workflows/recovery.ts +26 -1
- package/src/workflows/resume.ts +31 -4
- package/src/workflows/task-step-routing.ts +75 -2
- package/templates/community/open-prompt-showreel/PLAYBOOK.md +336 -0
- package/templates/community/open-prompt-showreel/README.md +33 -0
- package/templates/community/open-prompt-showreel/example/tla-races/facts.ts +145 -0
- package/templates/community/open-prompt-showreel/example/tla-races/facts.v3.json +140 -0
- package/templates/community/open-prompt-showreel/example/tla-races/music.mist-city.json +8 -0
- package/templates/community/open-prompt-showreel/example/tla-races/reel.html +805 -0
- package/templates/community/open-prompt-showreel/example/tla-races/smoke.sh +48 -0
- package/templates/community/open-prompt-showreel/lead-prompt.md +89 -0
- package/templates/community/open-prompt-showreel/setup.sh +167 -0
- package/templates/community/open-prompt-showreel/skills/motion-design-replication/SKILL.md +85 -0
- package/templates/community/open-prompt-showreel/skills/motion-design-video-analysis/SKILL.md +115 -0
- package/templates/community/open-prompt-showreel/skills/open-prompt-showreel/SKILL.md +147 -0
- package/templates/community/open-prompt-showreel/skills/video-generation/SKILL.md +195 -0
- package/templates/community/open-prompt-showreel/tools/fetch-music.sh +65 -0
- package/templates/community/open-prompt-showreel/tools/music-analyze.py +69 -0
- package/templates/community/open-prompt-showreel/tools/music-current.sh +34 -0
- package/templates/community/open-prompt-showreel/tools/music-cut.sh +36 -0
- package/templates/community/open-prompt-showreel/tools/music-refine.py +39 -0
- package/templates/community/open-prompt-showreel/tools/render.mjs +157 -0
- package/templates/community/open-prompt-showreel/tools/sheet.sh +44 -0
- package/templates/community/open-prompt-showreel/tools/web-compress.sh +17 -0
- package/templates/community/open-prompt-showreel/tools/x-reencode.sh +21 -0
- package/templates/extensions/README.md +1 -0
- package/templates/extensions/deploy-awareness/README.md +28 -0
- package/templates/extensions/deploy-awareness/hooks.ts +152 -0
- package/templates/extensions/deploy-awareness/manifest.json +8 -0
- package/templates/skills/memory/config.json +2 -2
- package/templates/skills/memory/content.md +59 -5
- package/templates/skills/swarm-extensions/config.json +1 -1
- package/templates/skills/swarm-extensions/content.md +28 -5
- package/tsconfig.json +3 -0
- package/dist/boot-seeds-gsetbs5y.js +0 -28
- package/dist/cli-j490egb5.js +0 -5632
- package/dist/cli-tjf4cn8z.js +0 -9119
- package/dist/cli-tmqt7dpj.js +0 -572
- package/dist/dsh-adapter-mpnzgztj.js +0 -19
- package/dist/index-7aj368tw.js +0 -30
package/src/commands/runner.ts
CHANGED
|
@@ -35,7 +35,9 @@ import {
|
|
|
35
35
|
} from "../providers/index.ts";
|
|
36
36
|
import type { SteerDeliveryResult } from "../providers/types.ts";
|
|
37
37
|
import { initTelemetry, telemetry } from "../telemetry.ts";
|
|
38
|
+
import { mapTriggerSurface } from "../telemetry-context.ts";
|
|
38
39
|
import {
|
|
40
|
+
isTerminalTaskStatus,
|
|
39
41
|
type ModelTierOverrides,
|
|
40
42
|
type ProviderName,
|
|
41
43
|
parseWorkerModelTierOverrides,
|
|
@@ -44,6 +46,7 @@ import {
|
|
|
44
46
|
resolveTaskModelSelection,
|
|
45
47
|
type SteeringMessage,
|
|
46
48
|
} from "../types.ts";
|
|
49
|
+
import { isApiDrainingResponse } from "../utils/api-drain.ts";
|
|
47
50
|
import { getApiKey } from "../utils/api-key.ts";
|
|
48
51
|
import { computeBudgetBackoffMs } from "../utils/budget-backoff.ts";
|
|
49
52
|
import { isCodexAuthFailureReason } from "../utils/codex-auth-failure.ts";
|
|
@@ -66,7 +69,12 @@ import { refreshSkillsIfChanged } from "../utils/skills-refresh.ts";
|
|
|
66
69
|
import { guardSpawnModel } from "../utils/spawn-model-guard.ts";
|
|
67
70
|
import { isSteeringEnabled } from "../utils/steering-enabled.ts";
|
|
68
71
|
import { interpolate } from "../utils/template.ts";
|
|
69
|
-
import {
|
|
72
|
+
import {
|
|
73
|
+
canonicalAzureDevOpsRepoUrl,
|
|
74
|
+
isAzureDevOpsUrl,
|
|
75
|
+
parseAzureDevOpsRepoUrl,
|
|
76
|
+
} from "../vcs/azure-devops.ts";
|
|
77
|
+
import { detectVcsProvider, type VcsProvider } from "../vcs/index.ts";
|
|
70
78
|
import { validateJsonSchema } from "../workflows/json-schema-validator.ts";
|
|
71
79
|
import { buildAttachmentsSection } from "./attachments-section.ts";
|
|
72
80
|
import {
|
|
@@ -267,7 +275,8 @@ async function listSwarmAutostashes(clonePath: string, role: string): Promise<Sw
|
|
|
267
275
|
* (src/agentmail/handlers.ts) — always carries `parentTaskId` pointing at
|
|
268
276
|
* the task it's continuing (as opposed to "agentmail-message", which fires
|
|
269
277
|
* only when no existing task was found for the thread).
|
|
270
|
-
* - "github-comment" / "github-review" / "gitlab-comment" / "gitlab-ci"
|
|
278
|
+
* - "github-comment" / "github-review" / "gitlab-comment" / "gitlab-ci" /
|
|
279
|
+
* "azure-devops-comment":
|
|
271
280
|
* tracker feedback on an ALREADY-OPEN PR/MR (review comments, review
|
|
272
281
|
* verdicts, CI failures) — the point is to keep working on the existing
|
|
273
282
|
* feature branch, not reset back to the default branch.
|
|
@@ -285,6 +294,7 @@ const CONTINUATION_TASK_TYPES = new Set([
|
|
|
285
294
|
"github-review",
|
|
286
295
|
"gitlab-comment",
|
|
287
296
|
"gitlab-ci",
|
|
297
|
+
"azure-devops-comment",
|
|
288
298
|
]);
|
|
289
299
|
|
|
290
300
|
/**
|
|
@@ -708,8 +718,12 @@ export function scheduleSteeringDispatch(
|
|
|
708
718
|
return true;
|
|
709
719
|
}
|
|
710
720
|
|
|
711
|
-
/**
|
|
712
|
-
|
|
721
|
+
/**
|
|
722
|
+
* Ping the server to indicate activity and update status. Resolves to whether
|
|
723
|
+
* the API is draining, or undefined when it did not answer (down, or a 5xx
|
|
724
|
+
* from a proxy), so a gap in service never reads as "stopped draining".
|
|
725
|
+
*/
|
|
726
|
+
export async function pingServer(config: ApiConfig, _role: string): Promise<boolean | undefined> {
|
|
713
727
|
const headers: Record<string, string> = {
|
|
714
728
|
"X-Agent-ID": config.agentId,
|
|
715
729
|
};
|
|
@@ -721,12 +735,15 @@ async function pingServer(config: ApiConfig, _role: string): Promise<void> {
|
|
|
721
735
|
}
|
|
722
736
|
|
|
723
737
|
try {
|
|
724
|
-
await fetch(`${config.apiUrl}/ping`, {
|
|
738
|
+
const response = await fetch(`${config.apiUrl}/ping`, {
|
|
725
739
|
method: "POST",
|
|
726
740
|
headers,
|
|
727
741
|
});
|
|
742
|
+
if (response.status >= 500) return undefined;
|
|
743
|
+
return isApiDrainingResponse(response);
|
|
728
744
|
} catch {
|
|
729
745
|
// Silently fail - server might not be running
|
|
746
|
+
return undefined;
|
|
730
747
|
}
|
|
731
748
|
}
|
|
732
749
|
|
|
@@ -1091,6 +1108,7 @@ export const RELOADABLE_ENV_KEYS: ReadonlySet<string> = new Set([
|
|
|
1091
1108
|
// pi reads these from process.env for its traits and its session.
|
|
1092
1109
|
"PI_TOOL_DEFERRAL",
|
|
1093
1110
|
"PI_CODEMODE",
|
|
1111
|
+
"PI_CODEMODE_MODELS",
|
|
1094
1112
|
]);
|
|
1095
1113
|
|
|
1096
1114
|
/**
|
|
@@ -1568,7 +1586,7 @@ async function validateProviderOutputIfNeeded(
|
|
|
1568
1586
|
config: ApiConfig,
|
|
1569
1587
|
taskId: string,
|
|
1570
1588
|
providerOutput: string,
|
|
1571
|
-
): Promise<{ ok: true } | { ok: false; failReason: string }> {
|
|
1589
|
+
): Promise<{ ok: true; output?: string } | { ok: false; failReason: string }> {
|
|
1572
1590
|
const headers: Record<string, string> = {
|
|
1573
1591
|
"Content-Type": "application/json",
|
|
1574
1592
|
};
|
|
@@ -1589,29 +1607,65 @@ async function validateProviderOutputIfNeeded(
|
|
|
1589
1607
|
return { ok: true };
|
|
1590
1608
|
}
|
|
1591
1609
|
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
}
|
|
1610
|
+
// The first candidate is the raw text, so a final message that is already
|
|
1611
|
+
// bare JSON keeps its exact bytes. Later candidates recover JSON that the
|
|
1612
|
+
// model wrapped in a ```json fence or a line of prose.
|
|
1613
|
+
let firstValidationErrors: string[] | undefined;
|
|
1614
|
+
for (const [index, candidate] of jsonOutputCandidates(providerOutput).entries()) {
|
|
1615
|
+
let parsed: unknown;
|
|
1616
|
+
try {
|
|
1617
|
+
parsed = JSON.parse(candidate);
|
|
1618
|
+
} catch {
|
|
1619
|
+
continue;
|
|
1620
|
+
}
|
|
1621
|
+
const validationErrors = validateJsonSchema(taskData.outputSchema, parsed);
|
|
1622
|
+
if (validationErrors.length === 0) {
|
|
1623
|
+
return index === 0 ? { ok: true } : { ok: true, output: candidate };
|
|
1624
|
+
}
|
|
1625
|
+
firstValidationErrors ??= validationErrors;
|
|
1601
1626
|
}
|
|
1602
1627
|
|
|
1603
|
-
|
|
1604
|
-
if (validationErrors.length > 0) {
|
|
1628
|
+
if (firstValidationErrors) {
|
|
1605
1629
|
return {
|
|
1606
1630
|
ok: false,
|
|
1607
|
-
failReason: `Structured output did not match outputSchema: ${
|
|
1631
|
+
failReason: `Structured output did not match outputSchema: ${firstValidationErrors.join("; ")}`,
|
|
1608
1632
|
};
|
|
1609
1633
|
}
|
|
1634
|
+
return {
|
|
1635
|
+
ok: false,
|
|
1636
|
+
failReason:
|
|
1637
|
+
"Structured output required by outputSchema but provider output was not valid JSON",
|
|
1638
|
+
};
|
|
1610
1639
|
} catch {
|
|
1611
1640
|
return { ok: true };
|
|
1612
1641
|
}
|
|
1642
|
+
}
|
|
1613
1643
|
|
|
1614
|
-
|
|
1644
|
+
/**
|
|
1645
|
+
* Texts that may hold the JSON in an agent's final message, in the order to
|
|
1646
|
+
* try them: the whole message, each fenced code block from last to first, then
|
|
1647
|
+
* the span from the first `{` (or `[`) to the last `}` (or `]`). Agents often
|
|
1648
|
+
* answer a schema-bound task with "Here is the result:" plus a ```json block
|
|
1649
|
+
* instead of calling store-progress, and `JSON.parse` on the whole message
|
|
1650
|
+
* fails on that. Fences run last to first because an earlier fence is often an
|
|
1651
|
+
* example or a draft that also matches the schema, and the answer comes last.
|
|
1652
|
+
*/
|
|
1653
|
+
function jsonOutputCandidates(text: string): string[] {
|
|
1654
|
+
const candidates = [text];
|
|
1655
|
+
const fenced: string[] = [];
|
|
1656
|
+
for (const match of text.matchAll(/```[a-zA-Z]*[ \t]*\r?\n([\s\S]*?)\r?\n[ \t]*```/g)) {
|
|
1657
|
+
if (match[1]?.trim()) fenced.push(match[1].trim());
|
|
1658
|
+
}
|
|
1659
|
+
candidates.push(...fenced.reverse());
|
|
1660
|
+
for (const [open, close] of [
|
|
1661
|
+
["{", "}"],
|
|
1662
|
+
["[", "]"],
|
|
1663
|
+
] as const) {
|
|
1664
|
+
const start = text.indexOf(open);
|
|
1665
|
+
const end = text.lastIndexOf(close);
|
|
1666
|
+
if (start >= 0 && end > start) candidates.push(text.slice(start, end + 1));
|
|
1667
|
+
}
|
|
1668
|
+
return [...new Set(candidates)];
|
|
1615
1669
|
}
|
|
1616
1670
|
|
|
1617
1671
|
export async function ensureTaskFinished(
|
|
@@ -1641,12 +1695,15 @@ export async function ensureTaskFinished(
|
|
|
1641
1695
|
// Exit code 0 = success, non-zero = failure
|
|
1642
1696
|
let status = exitCode === 0 ? "completed" : "failed";
|
|
1643
1697
|
const body: Record<string, string> = { status };
|
|
1698
|
+
// The server records it only when no session did, so a spawn failure is
|
|
1699
|
+
// attributed to its harness instead of leaving `provider` NULL.
|
|
1700
|
+
if (provider) body.provider = provider;
|
|
1644
1701
|
|
|
1645
1702
|
// Applies a structured-output fallback result to `body`/`status`. Shared by
|
|
1646
1703
|
// the no-providerOutput path and the providerOutput-failed-schema-validation
|
|
1647
1704
|
// path below, so a schema'd task ending in free-form prose falls through to
|
|
1648
1705
|
// the same extraction fallback instead of hard-failing.
|
|
1649
|
-
const applyFallback = (fallback: FallbackResult) => {
|
|
1706
|
+
const applyFallback = (fallback: FallbackResult, rejectedOutputReason?: string) => {
|
|
1650
1707
|
console.log(`[${role}] Task ${taskId.slice(0, 8)} fallback result: ${fallback.kind}`);
|
|
1651
1708
|
switch (fallback.kind) {
|
|
1652
1709
|
case "extracted":
|
|
@@ -1665,7 +1722,11 @@ export async function ensureTaskFinished(
|
|
|
1665
1722
|
case "schema-fail":
|
|
1666
1723
|
status = "failed";
|
|
1667
1724
|
body.status = "failed";
|
|
1668
|
-
|
|
1725
|
+
// Keep why the provider's final message was rejected; the fallback's
|
|
1726
|
+
// own reason alone ("not provided via store-progress") hides it.
|
|
1727
|
+
body.failureReason = rejectedOutputReason
|
|
1728
|
+
? `${fallback.failReason}. Final message rejected: ${rejectedOutputReason}`
|
|
1729
|
+
: fallback.failReason;
|
|
1669
1730
|
break;
|
|
1670
1731
|
case "fetch-error":
|
|
1671
1732
|
body.output = `Process completed (could not verify task state: ${fallback.error})`;
|
|
@@ -1681,7 +1742,7 @@ export async function ensureTaskFinished(
|
|
|
1681
1742
|
} else if (providerOutput) {
|
|
1682
1743
|
const validation = await validateProviderOutputIfNeeded(config, taskId, providerOutput);
|
|
1683
1744
|
if (validation.ok) {
|
|
1684
|
-
body.output = providerOutput;
|
|
1745
|
+
body.output = validation.output ?? providerOutput;
|
|
1685
1746
|
} else {
|
|
1686
1747
|
// The task declared an outputSchema but the provider's final message
|
|
1687
1748
|
// is free-form prose that doesn't satisfy it. Don't convert this into
|
|
@@ -1695,7 +1756,7 @@ export async function ensureTaskFinished(
|
|
|
1695
1756
|
adapterType,
|
|
1696
1757
|
providerOutput,
|
|
1697
1758
|
);
|
|
1698
|
-
applyFallback(fallback);
|
|
1759
|
+
applyFallback(fallback, validation.failReason);
|
|
1699
1760
|
}
|
|
1700
1761
|
} else {
|
|
1701
1762
|
// Try structured output fallback if the task has an outputSchema
|
|
@@ -2298,6 +2359,8 @@ function setupShutdownHandlers(
|
|
|
2298
2359
|
`[${role}] Superseding ${state.activeTasks.size} remaining task(s) for resume after restart...`,
|
|
2299
2360
|
);
|
|
2300
2361
|
for (const [taskId, task] of state.activeTasks) {
|
|
2362
|
+
// Already superseded (or terminal) server-side, e.g. by the API-drain handoff.
|
|
2363
|
+
if (task.serverTerminalStatus) continue;
|
|
2301
2364
|
console.log(`[${role}] Superseding task ${taskId.slice(0, 8)}`);
|
|
2302
2365
|
task.session.abort("graceful_shutdown").catch(() => {});
|
|
2303
2366
|
if (apiConfig) {
|
|
@@ -2336,6 +2399,9 @@ function setupShutdownHandlers(
|
|
|
2336
2399
|
if (apiConfig) {
|
|
2337
2400
|
telemetry.session("ended", {
|
|
2338
2401
|
agentId: apiConfig.agentId,
|
|
2402
|
+
// A runner session spans many tasks, so it belongs to none.
|
|
2403
|
+
taskId: null,
|
|
2404
|
+
trigger_surface: null,
|
|
2339
2405
|
durationMs: state ? Date.now() - state.startedAt : undefined,
|
|
2340
2406
|
tasksProcessed: state?.tasksProcessed ?? 0,
|
|
2341
2407
|
});
|
|
@@ -2400,6 +2466,10 @@ export interface RunningTask {
|
|
|
2400
2466
|
promise: Promise<ProviderResult>;
|
|
2401
2467
|
/** The trigger type that caused this task to be spawned */
|
|
2402
2468
|
triggerType?: string;
|
|
2469
|
+
/** Surface that started the task's whole chain (root task source); tags session telemetry */
|
|
2470
|
+
triggerSurface?: string | null;
|
|
2471
|
+
/** `users.id` of the requester; hashed into `user_ref` on session telemetry */
|
|
2472
|
+
requestedByUserId?: string;
|
|
2403
2473
|
/** Set when the promise resolves, enabling non-blocking completion checks */
|
|
2404
2474
|
result: ProviderResult | null;
|
|
2405
2475
|
/** Deferred cursor updates for channel_activity triggers — committed after success */
|
|
@@ -2441,6 +2511,20 @@ export interface RunningTask {
|
|
|
2441
2511
|
* adapter's `ProviderResult.output` is empty (see `trackAssistantText`).
|
|
2442
2512
|
*/
|
|
2443
2513
|
assistantText?: { value?: string };
|
|
2514
|
+
/** Last time `reconcileActiveTasks` read this task's server-side status. */
|
|
2515
|
+
lastReconcileAt?: number;
|
|
2516
|
+
/** When the runner asked the session to abort (cancel or reconcile). */
|
|
2517
|
+
abortRequestedAt?: number;
|
|
2518
|
+
/**
|
|
2519
|
+
* Terminal status the server already holds for this task, found by
|
|
2520
|
+
* `reconcileActiveTasks` or set by an API-drain handoff. Completion then only
|
|
2521
|
+
* frees the slot and leaves the server's output and failureReason alone.
|
|
2522
|
+
*/
|
|
2523
|
+
serverTerminalStatus?: string;
|
|
2524
|
+
/** API-drain handoff calls made for this task (see `handOffTasksForApiDrain`). */
|
|
2525
|
+
drainHandoffAttempts?: number;
|
|
2526
|
+
/** The API answered the drain handoff for this task, so it is not retried. */
|
|
2527
|
+
drainHandoffSettled?: boolean;
|
|
2444
2528
|
}
|
|
2445
2529
|
|
|
2446
2530
|
/** Runner state for tracking concurrent tasks */
|
|
@@ -2472,6 +2556,12 @@ export interface RunnerState {
|
|
|
2472
2556
|
* value is the reset time in ms. Read by `selectCredential` (T5).
|
|
2473
2557
|
*/
|
|
2474
2558
|
modelWindowBlocks: Map<string, number>;
|
|
2559
|
+
/**
|
|
2560
|
+
* The API is draining (it sent `X-Swarm-Draining`): in-flight tasks are handed
|
|
2561
|
+
* off and no new work is taken until a response arrives without the header.
|
|
2562
|
+
* Unset against an API that never drains.
|
|
2563
|
+
*/
|
|
2564
|
+
apiDraining?: boolean;
|
|
2475
2565
|
}
|
|
2476
2566
|
|
|
2477
2567
|
/** Buffer for session logs */
|
|
@@ -2675,10 +2765,27 @@ async function detectVcsForTask(
|
|
|
2675
2765
|
).trim();
|
|
2676
2766
|
|
|
2677
2767
|
// 4. Detect provider and check for PR/MR
|
|
2678
|
-
let vcsProvider:
|
|
2768
|
+
let vcsProvider: VcsProvider;
|
|
2679
2769
|
let prJson: string;
|
|
2680
|
-
|
|
2681
|
-
|
|
2770
|
+
let azureRepo: string | null = null;
|
|
2771
|
+
|
|
2772
|
+
if (isAzureDevOpsUrl(remoteUrl)) {
|
|
2773
|
+
const parsed = parseAzureDevOpsRepoUrl(remoteUrl);
|
|
2774
|
+
if (!parsed) return;
|
|
2775
|
+
vcsProvider = "azure-devops";
|
|
2776
|
+
azureRepo = canonicalAzureDevOpsRepoUrl(remoteUrl);
|
|
2777
|
+
const prs = JSON.parse(
|
|
2778
|
+
await Bun.$`az repos pr list --organization ${parsed.orgUrl} --project ${parsed.project} --repository ${parsed.repository} --source-branch ${branch} --status active --top 1 --output json`
|
|
2779
|
+
.quiet()
|
|
2780
|
+
.text(),
|
|
2781
|
+
) as Array<{ pullRequestId: number }>;
|
|
2782
|
+
prJson = JSON.stringify(
|
|
2783
|
+
prs.map((pr) => ({
|
|
2784
|
+
number: pr.pullRequestId,
|
|
2785
|
+
url: `${azureRepo}/pullrequest/${pr.pullRequestId}`,
|
|
2786
|
+
})),
|
|
2787
|
+
);
|
|
2788
|
+
} else if (remoteUrl.includes("github.com") || remoteUrl.includes("github")) {
|
|
2682
2789
|
vcsProvider = "github";
|
|
2683
2790
|
prJson = (
|
|
2684
2791
|
await Bun.$`gh pr list --head ${branch} --json number,url --limit 1`.quiet().text()
|
|
@@ -2703,10 +2810,11 @@ async function detectVcsForTask(
|
|
|
2703
2810
|
const vcsUrl = pr.url ?? pr.web_url;
|
|
2704
2811
|
if (!vcsNumber || !vcsUrl) return;
|
|
2705
2812
|
|
|
2706
|
-
// 6. Extract repo from remote URL
|
|
2813
|
+
// 6. Extract repo from remote URL (Azure Repos keep the canonical clone URL,
|
|
2814
|
+
// matching the vcsRepo their webhook tasks carry)
|
|
2707
2815
|
const repoMatch = remoteUrl.match(/[:/]([^/]+\/[^/.]+?)(?:\.git)?$/);
|
|
2708
|
-
|
|
2709
|
-
|
|
2816
|
+
const vcsRepo = azureRepo ?? repoMatch?.[1];
|
|
2817
|
+
if (!vcsRepo) return;
|
|
2710
2818
|
|
|
2711
2819
|
// 7. Report to API
|
|
2712
2820
|
const headers: Record<string, string> = { "Content-Type": "application/json" };
|
|
@@ -2897,6 +3005,15 @@ async function triggerHeartbeatSweep(config: ApiConfig): Promise<boolean> {
|
|
|
2897
3005
|
}
|
|
2898
3006
|
}
|
|
2899
3007
|
|
|
3008
|
+
/**
|
|
3009
|
+
* `trigger_surface` for a worker event: the server-resolved root surface of the
|
|
3010
|
+
* task, or null when the server did not send one (an older server, or a
|
|
3011
|
+
* session with no task).
|
|
3012
|
+
*/
|
|
3013
|
+
function workerTriggerSurface(raw: string | null | undefined) {
|
|
3014
|
+
return raw ? mapTriggerSurface(raw) : null;
|
|
3015
|
+
}
|
|
3016
|
+
|
|
2900
3017
|
/** Trigger types returned by the poll API */
|
|
2901
3018
|
interface Trigger {
|
|
2902
3019
|
type:
|
|
@@ -2907,6 +3024,8 @@ interface Trigger {
|
|
|
2907
3024
|
| "channel_activity"
|
|
2908
3025
|
| "budget_refused";
|
|
2909
3026
|
taskId?: string;
|
|
3027
|
+
/** Surface that started the task's whole chain (server-resolved); tags session telemetry. */
|
|
3028
|
+
triggerSurface?: string;
|
|
2910
3029
|
task?: unknown;
|
|
2911
3030
|
mentionsCount?: number;
|
|
2912
3031
|
count?: number;
|
|
@@ -2952,7 +3071,7 @@ interface Trigger {
|
|
|
2952
3071
|
}
|
|
2953
3072
|
|
|
2954
3073
|
/** Options for polling */
|
|
2955
|
-
interface PollOptions {
|
|
3074
|
+
export interface PollOptions {
|
|
2956
3075
|
apiUrl: string;
|
|
2957
3076
|
apiKey: string;
|
|
2958
3077
|
agentId: string;
|
|
@@ -2963,6 +3082,8 @@ interface PollOptions {
|
|
|
2963
3082
|
since?: string; // Optional: for filtering finished tasks
|
|
2964
3083
|
/** Live harness provider; keys the MODEL_TIER_* overrides sent with the poll. */
|
|
2965
3084
|
harnessProvider?: ProviderName;
|
|
3085
|
+
/** Told, on every answered poll, whether the API is draining. */
|
|
3086
|
+
onApiDrainSignal?: (draining: boolean) => void;
|
|
2966
3087
|
}
|
|
2967
3088
|
|
|
2968
3089
|
/**
|
|
@@ -3157,8 +3278,8 @@ export async function registerAgent(opts: {
|
|
|
3157
3278
|
return {};
|
|
3158
3279
|
}
|
|
3159
3280
|
|
|
3160
|
-
/** Poll for triggers via HTTP API */
|
|
3161
|
-
async function pollForTrigger(opts: PollOptions): Promise<Trigger | null> {
|
|
3281
|
+
/** Poll for triggers via HTTP API. Exported for tests. */
|
|
3282
|
+
export async function pollForTrigger(opts: PollOptions): Promise<Trigger | null> {
|
|
3162
3283
|
if (!isPollTracingEnabled()) {
|
|
3163
3284
|
return pollForTriggerOnce(opts);
|
|
3164
3285
|
}
|
|
@@ -3222,10 +3343,15 @@ async function pollForTriggerOnce(opts: PollOptions): Promise<Trigger | null> {
|
|
|
3222
3343
|
continue;
|
|
3223
3344
|
}
|
|
3224
3345
|
|
|
3346
|
+
const draining = isApiDrainingResponse(response);
|
|
3347
|
+
opts.onApiDrainSignal?.(draining);
|
|
3348
|
+
|
|
3225
3349
|
const data = (await response.json()) as { trigger: Trigger | null };
|
|
3226
3350
|
if (data.trigger) {
|
|
3227
3351
|
return data.trigger;
|
|
3228
3352
|
}
|
|
3353
|
+
// A draining API dispatches nothing: end the window so the loop can hand off.
|
|
3354
|
+
if (draining) return null;
|
|
3229
3355
|
} catch (error) {
|
|
3230
3356
|
console.warn(`[runner] Poll request error: ${error}`);
|
|
3231
3357
|
}
|
|
@@ -3251,8 +3377,8 @@ async function buildTaskOutputInstructions(
|
|
|
3251
3377
|
return result.text;
|
|
3252
3378
|
}
|
|
3253
3379
|
|
|
3254
|
-
/** Build prompt based on trigger type */
|
|
3255
|
-
async function buildPromptForTrigger(
|
|
3380
|
+
/** Build prompt based on trigger type. Exported for unit testing. */
|
|
3381
|
+
export async function buildPromptForTrigger(
|
|
3256
3382
|
trigger: Trigger,
|
|
3257
3383
|
defaultPrompt: string,
|
|
3258
3384
|
fmt: (cmd: string) => string = (cmd) => `/${cmd}`,
|
|
@@ -3682,6 +3808,10 @@ async function spawnProviderProcess(
|
|
|
3682
3808
|
runnerSessionId: string;
|
|
3683
3809
|
iteration: number;
|
|
3684
3810
|
taskId?: string;
|
|
3811
|
+
/** Surface that started the task chain, for session telemetry. */
|
|
3812
|
+
triggerSurface?: string | null;
|
|
3813
|
+
/** `users.id` of the requester; hashed into `user_ref` on session telemetry. */
|
|
3814
|
+
requestedByUserId?: string;
|
|
3685
3815
|
model?: string;
|
|
3686
3816
|
modelTier?: string;
|
|
3687
3817
|
/** Server claim-time resolution (task.resolvedModel); wins over the local one. */
|
|
@@ -4456,21 +4586,28 @@ async function spawnProviderProcess(
|
|
|
4456
4586
|
"gen_ai.usage.output_tokens": result.cost.outputTokens ?? 0,
|
|
4457
4587
|
"agentswarm.cost.total_usd": result.cost.totalCostUsd ?? 0,
|
|
4458
4588
|
});
|
|
4459
|
-
telemetry.session(
|
|
4460
|
-
|
|
4461
|
-
|
|
4462
|
-
|
|
4463
|
-
|
|
4464
|
-
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4589
|
+
telemetry.session(
|
|
4590
|
+
"cost",
|
|
4591
|
+
{
|
|
4592
|
+
agentId: opts.agentId,
|
|
4593
|
+
// Lets cost be split by the surface that started the work.
|
|
4594
|
+
taskId: realTaskId ?? null,
|
|
4595
|
+
trigger_surface: workerTriggerSurface(opts.triggerSurface),
|
|
4596
|
+
model: result.cost.model,
|
|
4597
|
+
provider: result.cost.provider ?? opts.harnessProvider,
|
|
4598
|
+
inputTokens: result.cost.inputTokens ?? 0,
|
|
4599
|
+
outputTokens: result.cost.outputTokens ?? 0,
|
|
4600
|
+
cacheReadTokens: result.cost.cacheReadTokens,
|
|
4601
|
+
cacheWriteTokens: result.cost.cacheWriteTokens,
|
|
4602
|
+
reasoningOutputTokens: result.cost.reasoningOutputTokens,
|
|
4603
|
+
thinkingTokens: result.cost.thinkingTokens,
|
|
4604
|
+
totalCostUsd: result.cost.totalCostUsd,
|
|
4605
|
+
durationMs: result.cost.durationMs,
|
|
4606
|
+
numTurns: result.cost.numTurns,
|
|
4607
|
+
isError: result.cost.isError,
|
|
4608
|
+
},
|
|
4609
|
+
{ userId: opts.requestedByUserId ?? null },
|
|
4610
|
+
);
|
|
4474
4611
|
try {
|
|
4475
4612
|
await saveCostData(
|
|
4476
4613
|
{ ...result.cost, taskId: realTaskId, sessionId: opts.runnerSessionId },
|
|
@@ -4595,6 +4732,8 @@ async function spawnProviderProcess(
|
|
|
4595
4732
|
startTime: new Date(),
|
|
4596
4733
|
promise,
|
|
4597
4734
|
result: null,
|
|
4735
|
+
triggerSurface: opts.triggerSurface,
|
|
4736
|
+
requestedByUserId: opts.requestedByUserId,
|
|
4598
4737
|
credentialInfo,
|
|
4599
4738
|
// Snapshot the provider + local-env trait of the adapter this session is
|
|
4600
4739
|
// spawned on, so the session-end sync decision survives a live provider
|
|
@@ -4612,18 +4751,200 @@ async function spawnProviderProcess(
|
|
|
4612
4751
|
runningTask.harnessVariantMeta = pendingHarnessVariantMeta;
|
|
4613
4752
|
}
|
|
4614
4753
|
|
|
4615
|
-
// Non-blocking completion tracking
|
|
4754
|
+
// Non-blocking completion tracking. `reconcileActiveTasks` may have settled
|
|
4755
|
+
// the task already when the session never did; keep that result.
|
|
4616
4756
|
promise
|
|
4617
4757
|
.then((r) => {
|
|
4618
|
-
runningTask.result
|
|
4758
|
+
runningTask.result ??= r;
|
|
4619
4759
|
})
|
|
4620
4760
|
.catch(() => {
|
|
4621
|
-
runningTask.result
|
|
4761
|
+
runningTask.result ??= { exitCode: 1, isError: true };
|
|
4622
4762
|
});
|
|
4623
4763
|
|
|
4624
4764
|
return runningTask;
|
|
4625
4765
|
}
|
|
4626
4766
|
|
|
4767
|
+
/** Default cadence for checking active tasks against their server-side status. */
|
|
4768
|
+
export const DEFAULT_TASK_RECONCILE_INTERVAL_MS = 30_000;
|
|
4769
|
+
/** How long an aborted session gets to settle before the runner settles it. */
|
|
4770
|
+
export const ABORT_SETTLE_GRACE_MS = 10_000;
|
|
4771
|
+
|
|
4772
|
+
/** `RUNNER_TASK_RECONCILE_INTERVAL_MS`, or the default when unset or invalid. */
|
|
4773
|
+
export function resolveTaskReconcileIntervalMs(
|
|
4774
|
+
env: Record<string, string | undefined> = process.env,
|
|
4775
|
+
): number {
|
|
4776
|
+
const raw = Number(env.RUNNER_TASK_RECONCILE_INTERVAL_MS);
|
|
4777
|
+
return Number.isFinite(raw) && raw > 0 ? raw : DEFAULT_TASK_RECONCILE_INTERVAL_MS;
|
|
4778
|
+
}
|
|
4779
|
+
|
|
4780
|
+
export interface ReconcileActiveTasksOptions {
|
|
4781
|
+
/** Tasks already aborted because the server cancelled them. */
|
|
4782
|
+
cancelledSignaled: Set<string>;
|
|
4783
|
+
/** True when the server reports the task cancelled. Checked every call. */
|
|
4784
|
+
isCancelled: (taskId: string) => Promise<boolean>;
|
|
4785
|
+
/** The task's server-side status, or null when it could not be read. */
|
|
4786
|
+
fetchStatus: (taskId: string) => Promise<string | null>;
|
|
4787
|
+
intervalMs: number;
|
|
4788
|
+
abortGraceMs?: number;
|
|
4789
|
+
now?: () => number;
|
|
4790
|
+
}
|
|
4791
|
+
|
|
4792
|
+
function requestSessionAbort(task: RunningTask, reason: string, at: number): void {
|
|
4793
|
+
task.abortRequestedAt = at;
|
|
4794
|
+
Promise.resolve()
|
|
4795
|
+
.then(() => task.session.abort(reason))
|
|
4796
|
+
.catch(() => {});
|
|
4797
|
+
}
|
|
4798
|
+
|
|
4799
|
+
/** Handoff calls per task while the API drains; a call the API answered is never repeated. */
|
|
4800
|
+
export const API_DRAIN_HANDOFF_MAX_ATTEMPTS = 3;
|
|
4801
|
+
|
|
4802
|
+
/**
|
|
4803
|
+
* Fold the API's drain signal (the `X-Swarm-Draining` header on a ping or poll
|
|
4804
|
+
* answer) into `state`. `undefined` means the API did not answer: keep the last
|
|
4805
|
+
* known state. Exported for tests.
|
|
4806
|
+
*/
|
|
4807
|
+
export function applyApiDrainSignal(
|
|
4808
|
+
state: RunnerState,
|
|
4809
|
+
role: string,
|
|
4810
|
+
draining: boolean | undefined,
|
|
4811
|
+
): void {
|
|
4812
|
+
if (draining === undefined) return;
|
|
4813
|
+
if (draining && !state.apiDraining) {
|
|
4814
|
+
console.log(`[${role}] API is draining: handing off in-flight tasks, taking no new work`);
|
|
4815
|
+
} else if (!draining && state.apiDraining) {
|
|
4816
|
+
console.log(`[${role}] API stopped draining: resuming normal polling`);
|
|
4817
|
+
}
|
|
4818
|
+
state.apiDraining = draining;
|
|
4819
|
+
}
|
|
4820
|
+
|
|
4821
|
+
/**
|
|
4822
|
+
* The API is draining, so it still serves but will stop soon: supersede each
|
|
4823
|
+
* in-flight task now, while the call can land, instead of in the SIGTERM
|
|
4824
|
+
* handler, which compose runs after the API is gone. Same API call and reason
|
|
4825
|
+
* as the SIGTERM handoff, so the resume follow-up is identical.
|
|
4826
|
+
*
|
|
4827
|
+
* A task the API superseded is marked server-terminal and its session aborted;
|
|
4828
|
+
* completion then frees the slot without a finish call. A failed call leaves
|
|
4829
|
+
* the task running, up to `API_DRAIN_HANDOFF_MAX_ATTEMPTS`, and the SIGTERM
|
|
4830
|
+
* handler stays the fallback. Exported for tests.
|
|
4831
|
+
*/
|
|
4832
|
+
export async function handOffTasksForApiDrain(
|
|
4833
|
+
state: RunnerState,
|
|
4834
|
+
role: string,
|
|
4835
|
+
apiConfig: ApiConfig,
|
|
4836
|
+
): Promise<void> {
|
|
4837
|
+
for (const [taskId, task] of state.activeTasks) {
|
|
4838
|
+
// A settled session reports its own result through `checkCompletedProcesses`.
|
|
4839
|
+
if (task.result !== null || task.drainHandoffSettled) continue;
|
|
4840
|
+
const attempts = task.drainHandoffAttempts ?? 0;
|
|
4841
|
+
if (attempts >= API_DRAIN_HANDOFF_MAX_ATTEMPTS) continue;
|
|
4842
|
+
task.drainHandoffAttempts = attempts + 1;
|
|
4843
|
+
|
|
4844
|
+
const outcome = await supersedeTaskViaAPI(apiConfig, role, taskId, "graceful_shutdown");
|
|
4845
|
+
if (!outcome.ok) {
|
|
4846
|
+
console.warn(
|
|
4847
|
+
`[${role}] Drain handoff for task ${taskId.slice(0, 8)} failed (attempt ${attempts + 1}/${API_DRAIN_HANDOFF_MAX_ATTEMPTS}); the task keeps running`,
|
|
4848
|
+
);
|
|
4849
|
+
continue;
|
|
4850
|
+
}
|
|
4851
|
+
task.drainHandoffSettled = true;
|
|
4852
|
+
if (outcome.kind === "resumed" || outcome.kind === "workflow-failed") {
|
|
4853
|
+
task.serverTerminalStatus = outcome.kind === "resumed" ? "superseded" : "failed";
|
|
4854
|
+
console.log(`[${role}] Handed off task ${taskId.slice(0, 8)} ahead of the API stopping`);
|
|
4855
|
+
requestSessionAbort(task, "graceful_shutdown", Date.now());
|
|
4856
|
+
}
|
|
4857
|
+
// "alreadyFinished": the task ended on its own. "rejected": the API refused
|
|
4858
|
+
// the supersede on purpose. Either way the session follows its normal path.
|
|
4859
|
+
}
|
|
4860
|
+
}
|
|
4861
|
+
|
|
4862
|
+
/**
|
|
4863
|
+
* Keep `state.activeTasks` in line with the server, so a session whose promise
|
|
4864
|
+
* never settles cannot hold an execution slot forever:
|
|
4865
|
+
* - a task the server cancelled gets its session aborted (every call);
|
|
4866
|
+
* - every `intervalMs`, a task the server already holds as terminal (for
|
|
4867
|
+
* example failed by the heartbeat sweep) gets its session aborted too;
|
|
4868
|
+
* - a session that has not settled `abortGraceMs` after an abort is settled
|
|
4869
|
+
* here, and `checkCompletedProcesses` frees the slot on its next pass.
|
|
4870
|
+
* Exported for tests.
|
|
4871
|
+
*/
|
|
4872
|
+
export async function reconcileActiveTasks(
|
|
4873
|
+
state: RunnerState,
|
|
4874
|
+
role: string,
|
|
4875
|
+
opts: ReconcileActiveTasksOptions,
|
|
4876
|
+
): Promise<void> {
|
|
4877
|
+
const now = opts.now ?? Date.now;
|
|
4878
|
+
const graceMs = opts.abortGraceMs ?? ABORT_SETTLE_GRACE_MS;
|
|
4879
|
+
|
|
4880
|
+
for (const [taskId, task] of state.activeTasks) {
|
|
4881
|
+
if (task.result !== null) continue;
|
|
4882
|
+
|
|
4883
|
+
if (!opts.cancelledSignaled.has(taskId)) {
|
|
4884
|
+
try {
|
|
4885
|
+
if (await opts.isCancelled(taskId)) {
|
|
4886
|
+
console.log(
|
|
4887
|
+
`[${role}] Task ${taskId.slice(0, 8)} was cancelled — sending SIGTERM to subprocess`,
|
|
4888
|
+
);
|
|
4889
|
+
requestSessionAbort(task, "cancelled", now());
|
|
4890
|
+
opts.cancelledSignaled.add(taskId);
|
|
4891
|
+
}
|
|
4892
|
+
} catch {
|
|
4893
|
+
// Non-blocking — cancellation check is best-effort
|
|
4894
|
+
}
|
|
4895
|
+
}
|
|
4896
|
+
|
|
4897
|
+
if (task.abortRequestedAt === undefined) {
|
|
4898
|
+
const lastCheck = task.lastReconcileAt ?? task.startTime.getTime();
|
|
4899
|
+
if (now() - lastCheck >= opts.intervalMs) {
|
|
4900
|
+
task.lastReconcileAt = now();
|
|
4901
|
+
const status = await opts.fetchStatus(taskId).catch(() => null);
|
|
4902
|
+
if (status && isTerminalTaskStatus(status)) {
|
|
4903
|
+
console.warn(
|
|
4904
|
+
`[${role}] Task ${taskId.slice(0, 8)} is ${status} server-side but its session is still running — aborting it`,
|
|
4905
|
+
);
|
|
4906
|
+
task.serverTerminalStatus = status;
|
|
4907
|
+
requestSessionAbort(task, `server task ${status}`, now());
|
|
4908
|
+
}
|
|
4909
|
+
}
|
|
4910
|
+
}
|
|
4911
|
+
|
|
4912
|
+
if (
|
|
4913
|
+
task.abortRequestedAt !== undefined &&
|
|
4914
|
+
task.result === null &&
|
|
4915
|
+
now() - task.abortRequestedAt >= graceMs
|
|
4916
|
+
) {
|
|
4917
|
+
console.warn(
|
|
4918
|
+
`[${role}] Task ${taskId.slice(0, 8)} session did not settle ${graceMs}ms after abort — releasing its slot`,
|
|
4919
|
+
);
|
|
4920
|
+
task.result = {
|
|
4921
|
+
exitCode: 1,
|
|
4922
|
+
isError: true,
|
|
4923
|
+
sessionId: task.session.sessionId,
|
|
4924
|
+
failureReason: "runner exited without result: provider session did not settle after abort",
|
|
4925
|
+
};
|
|
4926
|
+
}
|
|
4927
|
+
}
|
|
4928
|
+
}
|
|
4929
|
+
|
|
4930
|
+
/** Fetch whether the server holds a task as cancelled. Throws on network failure. */
|
|
4931
|
+
async function fetchTaskCancelled(
|
|
4932
|
+
apiUrl: string,
|
|
4933
|
+
apiKey: string,
|
|
4934
|
+
agentId: string,
|
|
4935
|
+
taskId: string,
|
|
4936
|
+
): Promise<boolean> {
|
|
4937
|
+
const resp = await fetch(`${apiUrl}/cancelled-tasks?taskId=${encodeURIComponent(taskId)}`, {
|
|
4938
|
+
headers: {
|
|
4939
|
+
Authorization: `Bearer ${apiKey}`,
|
|
4940
|
+
"X-Agent-ID": agentId,
|
|
4941
|
+
},
|
|
4942
|
+
});
|
|
4943
|
+
if (!resp.ok) return false;
|
|
4944
|
+
const data = (await resp.json()) as { cancelled: Array<{ id: string }> };
|
|
4945
|
+
return data.cancelled?.some((t) => t.id === taskId) ?? false;
|
|
4946
|
+
}
|
|
4947
|
+
|
|
4627
4948
|
/** Check for completed processes and remove them from active tasks. Exported for tests. */
|
|
4628
4949
|
export async function checkCompletedProcesses(
|
|
4629
4950
|
state: RunnerState,
|
|
@@ -4635,6 +4956,8 @@ export async function checkCompletedProcesses(
|
|
|
4635
4956
|
taskId: string;
|
|
4636
4957
|
result: ProviderResult;
|
|
4637
4958
|
triggerType?: string;
|
|
4959
|
+
triggerSurface?: string | null;
|
|
4960
|
+
requestedByUserId?: string;
|
|
4638
4961
|
cursorUpdates?: Array<{ channelId: string; ts: string }>;
|
|
4639
4962
|
workingDir?: string;
|
|
4640
4963
|
credentialInfo?: RunningTask["credentialInfo"];
|
|
@@ -4645,6 +4968,7 @@ export async function checkCompletedProcesses(
|
|
|
4645
4968
|
model?: string;
|
|
4646
4969
|
durationMs: number;
|
|
4647
4970
|
assistantText?: RunningTask["assistantText"];
|
|
4971
|
+
serverTerminalStatus?: string;
|
|
4648
4972
|
}> = [];
|
|
4649
4973
|
|
|
4650
4974
|
for (const [taskId, task] of state.activeTasks) {
|
|
@@ -4657,6 +4981,8 @@ export async function checkCompletedProcesses(
|
|
|
4657
4981
|
taskId,
|
|
4658
4982
|
result: task.result,
|
|
4659
4983
|
triggerType: task.triggerType,
|
|
4984
|
+
triggerSurface: task.triggerSurface,
|
|
4985
|
+
requestedByUserId: task.requestedByUserId,
|
|
4660
4986
|
cursorUpdates: task.cursorUpdates,
|
|
4661
4987
|
workingDir: task.workingDir,
|
|
4662
4988
|
credentialInfo: task.credentialInfo,
|
|
@@ -4667,6 +4993,7 @@ export async function checkCompletedProcesses(
|
|
|
4667
4993
|
model: task.model,
|
|
4668
4994
|
durationMs: Date.now() - task.startTime.getTime(),
|
|
4669
4995
|
assistantText: task.assistantText,
|
|
4996
|
+
serverTerminalStatus: task.serverTerminalStatus,
|
|
4670
4997
|
});
|
|
4671
4998
|
}
|
|
4672
4999
|
}
|
|
@@ -4675,6 +5002,8 @@ export async function checkCompletedProcesses(
|
|
|
4675
5002
|
for (const {
|
|
4676
5003
|
taskId,
|
|
4677
5004
|
result,
|
|
5005
|
+
triggerSurface,
|
|
5006
|
+
requestedByUserId,
|
|
4678
5007
|
cursorUpdates,
|
|
4679
5008
|
workingDir,
|
|
4680
5009
|
credentialInfo,
|
|
@@ -4684,6 +5013,7 @@ export async function checkCompletedProcesses(
|
|
|
4684
5013
|
model,
|
|
4685
5014
|
durationMs,
|
|
4686
5015
|
assistantText,
|
|
5016
|
+
serverTerminalStatus,
|
|
4687
5017
|
} of completedTasks) {
|
|
4688
5018
|
state.activeTasks.delete(taskId);
|
|
4689
5019
|
vcsDetectedTasks.delete(taskId);
|
|
@@ -4699,6 +5029,17 @@ export async function checkCompletedProcesses(
|
|
|
4699
5029
|
);
|
|
4700
5030
|
}
|
|
4701
5031
|
|
|
5032
|
+
// The server finished this task without the session (heartbeat sweep,
|
|
5033
|
+
// another writer). Its result stands: no finish call, and no credential
|
|
5034
|
+
// or model outcome built from the abort this runner forced.
|
|
5035
|
+
if (serverTerminalStatus) {
|
|
5036
|
+
console.log(
|
|
5037
|
+
`[${role}] Task ${taskId.slice(0, 8)} was already ${serverTerminalStatus} server-side — slot released, server result kept`,
|
|
5038
|
+
);
|
|
5039
|
+
state.tasksProcessed += 1;
|
|
5040
|
+
continue;
|
|
5041
|
+
}
|
|
5042
|
+
|
|
4702
5043
|
// Detect VCS before finishing — last chance to link a PR
|
|
4703
5044
|
if (apiConfig && workingDir && !vcsDetectedTasks.has(taskId)) {
|
|
4704
5045
|
await detectVcsForTask(apiConfig.apiUrl, apiConfig.apiKey, taskId, workingDir);
|
|
@@ -4778,31 +5119,44 @@ export async function checkCompletedProcesses(
|
|
|
4778
5119
|
),
|
|
4779
5120
|
);
|
|
4780
5121
|
|
|
4781
|
-
|
|
4782
|
-
|
|
4783
|
-
|
|
4784
|
-
|
|
4785
|
-
|
|
4786
|
-
|
|
4787
|
-
|
|
4788
|
-
typeof harnessVariantMeta?.version === "string" ||
|
|
4789
|
-
typeof harnessVariantMeta?.version === "number"
|
|
4790
|
-
? String(harnessVariantMeta.version)
|
|
4791
|
-
: undefined,
|
|
4792
|
-
exitCode: result.exitCode,
|
|
4793
|
-
isError: result.exitCode !== 0,
|
|
4794
|
-
durationMs,
|
|
4795
|
-
});
|
|
4796
|
-
const sessionTelemetryEvent = resolveSessionTelemetryEvent(result);
|
|
4797
|
-
if (sessionTelemetryEvent) {
|
|
4798
|
-
telemetry.session(sessionTelemetryEvent, {
|
|
5122
|
+
const sessionTriggerSurface = workerTriggerSurface(triggerSurface);
|
|
5123
|
+
const sessionActor = { userId: requestedByUserId ?? null };
|
|
5124
|
+
telemetry.taskEvent(
|
|
5125
|
+
"session_completed",
|
|
5126
|
+
{
|
|
5127
|
+
taskId,
|
|
5128
|
+
trigger_surface: sessionTriggerSurface,
|
|
4799
5129
|
agentId: apiConfig.agentId,
|
|
4800
|
-
errorCategory: normalizeSessionErrorCategory(result.errorCategory),
|
|
4801
5130
|
provider: result.cost?.provider ?? harnessProvider,
|
|
4802
|
-
model: result.cost?.model ?? model,
|
|
4803
|
-
|
|
4804
|
-
|
|
4805
|
-
|
|
5131
|
+
model: result.cost?.model ?? model ?? "unknown",
|
|
5132
|
+
harnessVariant,
|
|
5133
|
+
harnessVersion:
|
|
5134
|
+
typeof harnessVariantMeta?.version === "string" ||
|
|
5135
|
+
typeof harnessVariantMeta?.version === "number"
|
|
5136
|
+
? String(harnessVariantMeta.version)
|
|
5137
|
+
: undefined,
|
|
5138
|
+
exitCode: result.exitCode,
|
|
5139
|
+
isError: result.exitCode !== 0,
|
|
5140
|
+
durationMs,
|
|
5141
|
+
},
|
|
5142
|
+
sessionActor,
|
|
5143
|
+
);
|
|
5144
|
+
const sessionTelemetryEvent = resolveSessionTelemetryEvent(result);
|
|
5145
|
+
if (sessionTelemetryEvent) {
|
|
5146
|
+
telemetry.session(
|
|
5147
|
+
sessionTelemetryEvent,
|
|
5148
|
+
{
|
|
5149
|
+
agentId: apiConfig.agentId,
|
|
5150
|
+
taskId,
|
|
5151
|
+
trigger_surface: sessionTriggerSurface,
|
|
5152
|
+
errorCategory: normalizeSessionErrorCategory(result.errorCategory),
|
|
5153
|
+
provider: result.cost?.provider ?? harnessProvider,
|
|
5154
|
+
model: result.cost?.model ?? model ?? "unknown",
|
|
5155
|
+
durationMs: result.cost?.durationMs ?? durationMs,
|
|
5156
|
+
wasRateLimited: result.rateLimitResetAt != null,
|
|
5157
|
+
},
|
|
5158
|
+
sessionActor,
|
|
5159
|
+
);
|
|
4806
5160
|
}
|
|
4807
5161
|
state.tasksProcessed += 1;
|
|
4808
5162
|
|
|
@@ -5072,6 +5426,9 @@ export async function runAgent(config: RunnerConfig, opts: RunnerOptions) {
|
|
|
5072
5426
|
}
|
|
5073
5427
|
telemetry.session("started", {
|
|
5074
5428
|
agentId,
|
|
5429
|
+
// The boot session is not tied to a task.
|
|
5430
|
+
taskId: null,
|
|
5431
|
+
trigger_surface: null,
|
|
5075
5432
|
harnessProvider: bootProvider,
|
|
5076
5433
|
model: bootModel || undefined,
|
|
5077
5434
|
role,
|
|
@@ -6131,10 +6488,16 @@ export async function runAgent(config: RunnerConfig, opts: RunnerOptions) {
|
|
|
6131
6488
|
// Throttle orphan recovery so it runs periodically while the worker is idle or under capacity.
|
|
6132
6489
|
let lastOrphanRecoveryAt = 0;
|
|
6133
6490
|
const ORPHAN_RECOVERY_INTERVAL_MS = 60_000;
|
|
6491
|
+
const taskReconcileIntervalMs = resolveTaskReconcileIntervalMs();
|
|
6134
6492
|
|
|
6135
6493
|
while (true) {
|
|
6136
|
-
// Ping server on each iteration to keep status updated
|
|
6137
|
-
|
|
6494
|
+
// Ping server on each iteration to keep status updated. The answer also
|
|
6495
|
+
// carries the API's drain signal, which reaches workers at capacity that
|
|
6496
|
+
// do not poll.
|
|
6497
|
+
applyApiDrainSignal(state, role, await pingServer(apiConfig, role));
|
|
6498
|
+
if (state.apiDraining) {
|
|
6499
|
+
await handOffTasksForApiDrain(state, role, apiConfig);
|
|
6500
|
+
}
|
|
6138
6501
|
|
|
6139
6502
|
// Check for completed processes first and ensure tasks are marked as finished
|
|
6140
6503
|
await checkCompletedProcesses(state, role, apiConfig, cancelledSignaled);
|
|
@@ -6210,38 +6573,18 @@ export async function runAgent(config: RunnerConfig, opts: RunnerOptions) {
|
|
|
6210
6573
|
);
|
|
6211
6574
|
}
|
|
6212
6575
|
|
|
6213
|
-
// Check for cancelled tasks and signal their subprocesses
|
|
6214
|
-
//
|
|
6215
|
-
//
|
|
6576
|
+
// Check for cancelled tasks and signal their subprocesses, and reconcile
|
|
6577
|
+
// active tasks with server-side status so a session that never settles
|
|
6578
|
+
// cannot hold its slot. Deliberately NOT gated on steeringDispatchState —
|
|
6579
|
+
// cancellation abort must keep working when steering dispatch is off
|
|
6580
|
+
// (STEERING_ENABLED=false).
|
|
6216
6581
|
if (state.activeTasks.size > 0) {
|
|
6217
|
-
|
|
6218
|
-
|
|
6219
|
-
|
|
6220
|
-
|
|
6221
|
-
|
|
6222
|
-
|
|
6223
|
-
headers: {
|
|
6224
|
-
Authorization: `Bearer ${apiKey}`,
|
|
6225
|
-
"X-Agent-ID": agentId,
|
|
6226
|
-
},
|
|
6227
|
-
},
|
|
6228
|
-
);
|
|
6229
|
-
if (cancelResp.ok) {
|
|
6230
|
-
const cancelData = (await cancelResp.json()) as {
|
|
6231
|
-
cancelled: Array<{ id: string }>;
|
|
6232
|
-
};
|
|
6233
|
-
if (cancelData.cancelled?.some((t) => t.id === taskId)) {
|
|
6234
|
-
console.log(
|
|
6235
|
-
`[${role}] Task ${taskId.slice(0, 8)} was cancelled — sending SIGTERM to subprocess`,
|
|
6236
|
-
);
|
|
6237
|
-
task.session.abort("cancelled").catch(() => {});
|
|
6238
|
-
cancelledSignaled.add(taskId);
|
|
6239
|
-
}
|
|
6240
|
-
}
|
|
6241
|
-
} catch {
|
|
6242
|
-
// Non-blocking — cancellation check is best-effort
|
|
6243
|
-
}
|
|
6244
|
-
}
|
|
6582
|
+
await reconcileActiveTasks(state, role, {
|
|
6583
|
+
cancelledSignaled,
|
|
6584
|
+
isCancelled: (taskId) => fetchTaskCancelled(apiUrl, apiKey, agentId, taskId),
|
|
6585
|
+
fetchStatus: (taskId) => fetchTaskStatus(apiUrl, apiKey, taskId),
|
|
6586
|
+
intervalMs: taskReconcileIntervalMs,
|
|
6587
|
+
});
|
|
6245
6588
|
}
|
|
6246
6589
|
|
|
6247
6590
|
// Deliver pending steering to live provider sessions and report the actual outcome.
|
|
@@ -6258,8 +6601,10 @@ export async function runAgent(config: RunnerConfig, opts: RunnerOptions) {
|
|
|
6258
6601
|
}
|
|
6259
6602
|
}
|
|
6260
6603
|
|
|
6261
|
-
// Only poll if we have capacity
|
|
6262
|
-
if (state.
|
|
6604
|
+
// Only poll if we have capacity and the API is not draining
|
|
6605
|
+
if (state.apiDraining) {
|
|
6606
|
+
await Bun.sleep(1000);
|
|
6607
|
+
} else if (state.activeTasks.size < state.maxConcurrent) {
|
|
6263
6608
|
if (Date.now() - lastOrphanRecoveryAt > ORPHAN_RECOVERY_INTERVAL_MS) {
|
|
6264
6609
|
lastOrphanRecoveryAt = Date.now();
|
|
6265
6610
|
const recoveredOrphans = await recoverOrphanedInProgressTasks(apiConfig);
|
|
@@ -6285,6 +6630,7 @@ export async function runAgent(config: RunnerConfig, opts: RunnerOptions) {
|
|
|
6285
6630
|
runtimeInstanceId,
|
|
6286
6631
|
pollTimeout: effectiveTimeout,
|
|
6287
6632
|
harnessProvider: state.harnessProvider,
|
|
6633
|
+
onApiDrainSignal: (draining) => applyApiDrainSignal(state, role, draining),
|
|
6288
6634
|
});
|
|
6289
6635
|
|
|
6290
6636
|
if (trigger) {
|
|
@@ -6638,6 +6984,8 @@ export async function runAgent(config: RunnerConfig, opts: RunnerOptions) {
|
|
|
6638
6984
|
runnerSessionId: taskRunnerSessionId,
|
|
6639
6985
|
iteration,
|
|
6640
6986
|
taskId: trigger.taskId,
|
|
6987
|
+
triggerSurface: trigger.triggerSurface,
|
|
6988
|
+
requestedByUserId: trigger.requestedBy?.id,
|
|
6641
6989
|
model: taskModel,
|
|
6642
6990
|
modelTier: taskModelTier,
|
|
6643
6991
|
resolvedModel: (trigger.task as { resolvedModel?: string } | undefined)
|