@desplega.ai/agent-swarm 2.7.10 → 2.8.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.
Files changed (281) hide show
  1. package/dist/acp-adapter-t949vbbp.js +15 -0
  2. package/dist/{actions-b8aqhrsg.js → actions-7e9czc7s.js} +18 -19
  3. package/dist/{amp-adapter-4c165vgn.js → amp-adapter-gv6cbb7d.js} +2 -3
  4. package/dist/{app-m9khefrh.js → app-b9fbkp9v.js} +3 -3
  5. package/dist/{assistant-rh4v3ntz.js → assistant-wjb7v4c7.js} +20 -21
  6. package/dist/{boot-args-schema-hwkc8bzv.js → boot-args-schema-2t37e0fe.js} +1 -1
  7. package/dist/{boot-reembed-5y6yw9sj.js → boot-reembed-a35nkyr1.js} +1 -1
  8. package/dist/{boot-reembed-fdyk55h4.js → boot-reembed-gka3zas7.js} +1 -1
  9. package/dist/{boot-scrub-sweep-r5r8kqsn.js → boot-scrub-sweep-65sdnp6c.js} +3 -3
  10. package/dist/{boot-seeds-8f9zt5cm.js → boot-seeds-x42tzytw.js} +4 -5
  11. package/dist/{claude-adapter-s5df247c.js → claude-adapter-v221b2fd.js} +7 -8
  12. package/dist/{claude-managed-adapter-h74d06yz.js → claude-managed-adapter-29eq09wd.js} +2 -2
  13. package/dist/{claude-managed-setup-9gsmwzyx.js → claude-managed-setup-9m6450zk.js} +2 -2
  14. package/dist/{claude-sdk-session-dq1j4nz9.js → claude-sdk-session-0q0ptaba.js} +9066 -8818
  15. package/dist/{cli-n5yexkdg.js → cli-0b4zam62.js} +1 -0
  16. package/dist/{cli-5wfz00be.js → cli-0jzra9ad.js} +2 -2
  17. package/dist/{cli-eqtfgfr6.js → cli-2gxeg5gr.js} +1 -1
  18. package/dist/{cli-eqk5p56g.js → cli-2wnq8jkz.js} +9 -9
  19. package/dist/{cli-hfkwwy1h.js → cli-2zp0et3v.js} +21 -2
  20. package/dist/{cli-rt0ag4x1.js → cli-334z18y3.js} +4 -4
  21. package/dist/{cli-6m6b4bep.js → cli-3rkdne1h.js} +2 -2
  22. package/dist/{cli-3xddv0rk.js → cli-4txa0ter.js} +5 -7
  23. package/dist/{cli-jc1g9ndz.js → cli-5j88qqa8.js} +10 -5
  24. package/dist/{cli-xfjrc279.js → cli-5mrq3ake.js} +48 -14
  25. package/dist/{cli-n07eecjs.js → cli-6t09sdhy.js} +3 -3
  26. package/dist/{cli-38yww4e9.js → cli-6wxjceza.js} +8 -8
  27. package/dist/{cli-5xcb8gxq.js → cli-7b8sbmag.js} +8 -8
  28. package/dist/{cli-3xj33nrx.js → cli-7cp6aa1q.js} +10 -3
  29. package/dist/{cli-mp9aa8g5.js → cli-7p1kvkck.js} +6 -6
  30. package/dist/{cli-w3bk0dgv.js → cli-8aes17e4.js} +2 -2
  31. package/dist/{cli-n9abj89w.js → cli-8fknbnhw.js} +8 -8
  32. package/dist/{cli-xd5ebp64.js → cli-8kzasymh.js} +3 -3
  33. package/dist/{cli-2tsfpc70.js → cli-a7wvp2km.js} +1 -1
  34. package/dist/{cli-kx4c8j05.js → cli-abejgen1.js} +63 -19
  35. package/dist/{cli-36wdfzgn.js → cli-bsywb58a.js} +8 -8
  36. package/dist/{cli-yz7v0sh4.js → cli-c55z5chy.js} +4 -6
  37. package/dist/{cli-18qt3few.js → cli-deefvewm.js} +1 -1
  38. package/dist/{cli-jg24scat.js → cli-ee0b971j.js} +3 -3
  39. package/dist/cli-f3vq58d2.js +242 -0
  40. package/dist/{cli-3xcwp3z8.js → cli-ffhtssbp.js} +2 -2
  41. package/dist/{cli-rjyghzg4.js → cli-g70vxtjh.js} +2 -2
  42. package/dist/{cli-g1px1g2e.js → cli-gxkx0zzp.js} +1 -1
  43. package/dist/{cli-j7d73g1y.js → cli-h38x262p.js} +3035 -354
  44. package/dist/{cli-zjphdj1a.js → cli-j790gp2w.js} +40 -18
  45. package/dist/{cli-f2zenhja.js → cli-kc7v1nfv.js} +1 -1
  46. package/dist/{cli-td33w98c.js → cli-m23zjcy2.js} +10 -10
  47. package/dist/{cli-8ewkreqd.js → cli-m28atx8q.js} +7 -9
  48. package/dist/{cli-x9exydey.js → cli-m4dqmnbp.js} +1 -1
  49. package/dist/{cli-ybjdc978.js → cli-mrt48bx7.js} +7 -4
  50. package/dist/{cli-mr97t7cc.js → cli-p1bq50aa.js} +263 -14
  51. package/dist/{cli-ttbqe3q4.js → cli-p1w18yhx.js} +1 -1
  52. package/dist/{cli-nj3x45rw.js → cli-p2gfst4m.js} +52 -43
  53. package/dist/{cli-z9cs5m0w.js → cli-pasjcnmj.js} +12 -12
  54. package/dist/{cli-an1knn2k.js → cli-qa4wdgsy.js} +5 -5
  55. package/dist/{cli-xncjscpm.js → cli-qfedvmcr.js} +50 -24
  56. package/dist/{cli-tmft5dz2.js → cli-qmqk2yc2.js} +1 -1
  57. package/dist/{cli-bxz823sz.js → cli-qsnnd04k.js} +1 -1
  58. package/dist/{cli-cr14kftt.js → cli-qwca7s44.js} +3 -3
  59. package/dist/{cli-7wz05bx3.js → cli-rfywm85n.js} +460 -737
  60. package/dist/{cli-v2fwbnsk.js → cli-rmmpt0wm.js} +6 -6
  61. package/dist/{cli-xbtq4d6s.js → cli-rzsy6nc6.js} +12 -8
  62. package/dist/{cli-0m7rtm11.js → cli-s7t6p9my.js} +1 -1
  63. package/dist/{cli-16phend6.js → cli-sdtt3men.js} +1 -1
  64. package/dist/{cli-pyrxt9gw.js → cli-tk7cjj8h.js} +1 -1
  65. package/dist/{cli-xvymtmv4.js → cli-tqegb8eq.js} +3 -3
  66. package/dist/{cli-kf3pxxdg.js → cli-v1dv1r37.js} +1 -1
  67. package/dist/{cli-h49ejvmc.js → cli-wcg8x116.js} +1 -1
  68. package/dist/{cli-q581b386.js → cli-wk18cm92.js} +5 -5
  69. package/dist/{cli-4vwxp550.js → cli-x1wa213s.js} +1 -1
  70. package/dist/{cli-jrp1dt73.js → cli-xzm9vcfg.js} +1 -1
  71. package/dist/{cli-eb2azq8n.js → cli-y97qxcfx.js} +9 -9
  72. package/dist/{cli-55bkx8hh.js → cli-yq3zak69.js} +1 -1
  73. package/dist/cli.js +17 -17
  74. package/dist/{codex-adapter-yr60sme6.js → codex-adapter-30j9bpzd.js} +5 -6
  75. package/dist/{codex-hook-fac6175r.js → codex-hook-h3vk6xzr.js} +1 -1
  76. package/dist/{codex-session-runner-pch8x584.js → codex-session-runner-8vp57v8w.js} +5 -6
  77. package/dist/{commands-phjfbkv0.js → commands-bngnz9g7.js} +3 -3
  78. package/dist/{controller-jkx994pz.js → controller-hxx8wwy1.js} +2 -2
  79. package/dist/{controllers-connect-c4448kwa.js → controllers-connect-e2b4gyxc.js} +19 -20
  80. package/dist/{cursor-adapter-ndebqnm8.js → cursor-adapter-n5nc3mfe.js} +1 -2
  81. package/dist/{db-ez6egt6v.js → db-bgm7vkc0.js} +3 -3
  82. package/dist/{db-ef32tbfc.js → db-c6np41ca.js} +10 -2
  83. package/dist/{devin-adapter-z46ep5ph.js → devin-adapter-xedz98zv.js} +1 -1
  84. package/dist/{dispatcher-g3tt9hs9.js → dispatcher-jnybck15.js} +17 -18
  85. package/dist/{dsh-adapter-tcyn3099.js → dsh-adapter-nrhbrjz8.js} +1 -2
  86. package/dist/{easter-egg-3d-e36hk5td.js → easter-egg-3d-533knw22.js} +1 -1
  87. package/dist/{embedding-space-4kyh5qqj.js → embedding-space-crsm2zp0.js} +6 -6
  88. package/dist/{embeddings-6a8v4a6t.js → embeddings-e7z3f27f.js} +1 -1
  89. package/dist/{execute-3cbg0twf.js → execute-b3mrb1mv.js} +1 -1
  90. package/dist/{external-channel-se646snz.js → external-channel-m77wf5z3.js} +2 -2
  91. package/dist/{fx-adapter-yw795hqq.js → fx-adapter-b6w0kf56.js} +7 -8
  92. package/dist/{grok-adapter-ttmcss2j.js → grok-adapter-4sqtebdk.js} +7 -8
  93. package/dist/handlers-kdjcyzdj.js +32 -0
  94. package/dist/heartbeat-xgb036sx.js +43 -0
  95. package/dist/{hook-g3nhexsy.js → hook-5h02c9ga.js} +6 -6
  96. package/dist/{hook-hq93y5ej.js → hook-xsk1jbha.js} +5 -5
  97. package/dist/{http-5a9p4h6y.js → http-txe7qhvn.js} +282 -140
  98. package/dist/{index-6haqt3v5.js → index-4a0670yh.js} +8917 -8476
  99. package/dist/index-835xdgnm.js +33 -0
  100. package/dist/index-d469300x.js +37 -0
  101. package/dist/index-rzqwp11g.js +32 -0
  102. package/dist/{index-s72rqgsx.js → index-tvfafeyy.js} +1 -1
  103. package/dist/{index-hgn3c961.js → index-vk63emp7.js} +978 -35
  104. package/dist/{index-3c5pxbge.js → index-ysvbhg5m.js} +1 -1
  105. package/dist/{keepalive-1j4n4dmk.js → keepalive-4zsrce78.js} +3 -3
  106. package/dist/lead-yqt47dkr.js +70 -0
  107. package/dist/{maintenance-dmghacy5.js → maintenance-86jvartk.js} +1 -1
  108. package/dist/{oauth-refresh-sweep-yy06c03c.js → oauth-refresh-sweep-j52kg9pr.js} +2 -2
  109. package/dist/{onboard-52f9t5dm.js → onboard-c2aj5p8q.js} +3 -3
  110. package/dist/{opencode-adapter-krnh9jkn.js → opencode-adapter-dsagkhtw.js} +5 -6
  111. package/dist/{otel-impl-xjqz6wjj.js → otel-impl-yyy203z8.js} +1 -1
  112. package/dist/{pi-mono-adapter-dbxyp0qv.js → pi-mono-adapter-546cd1cc.js} +9 -9
  113. package/dist/{pricing-refresh-ctdr74pd.js → pricing-refresh-1rgzqyzz.js} +2 -3
  114. package/dist/{rbac-roles-q0gr8eyj.js → rbac-roles-e70xfeyj.js} +4 -6
  115. package/dist/{rbac-roles-ehv8s10n.js → rbac-roles-q89qe8er.js} +3 -3
  116. package/dist/{registry-hpjfmcfz.js → registry-32b1mft6.js} +1 -1
  117. package/dist/{render-v2-5b6chvcq.js → render-v2-k6tt107q.js} +3 -3
  118. package/dist/{resume-5a5d2845.js → resume-cnnrjfxa.js} +6 -6
  119. package/dist/{runtime-khxszyfp.js → runtime-1hv06jsn.js} +1 -1
  120. package/dist/{session-access-gj0bjhqg.js → session-access-xkxkjw3n.js} +4 -4
  121. package/dist/{session-source-backfill-2sy0krfk.js → session-source-backfill-1d5pdwww.js} +2 -2
  122. package/dist/{setup-7ssfakk1.js → setup-se8q7gkc.js} +1 -1
  123. package/dist/{virtual-modules-pjj0knwf.js → virtual-modules-gazyapte.js} +3 -3
  124. package/dist/{work-objects-bf3syvhq.js → work-objects-1kxnbzy5.js} +20 -21
  125. package/dist/{worker-follow-up-38xevga6.js → worker-follow-up-zqm8apt4.js} +17 -18
  126. package/dist/worker-j6xxtq7p.js +70 -0
  127. package/openapi.json +334 -7
  128. package/package.json +4 -4
  129. package/src/apps/definition.ts +11 -0
  130. package/src/apps/store.ts +28 -8
  131. package/src/be/db/model-profiles.ts +147 -38
  132. package/src/be/db/tasks/read.ts +5 -1
  133. package/src/be/db/workflow-run-definitions.ts +117 -0
  134. package/src/be/db.ts +24 -3
  135. package/src/be/memory/constants.ts +14 -1
  136. package/src/be/memory/key-paths.ts +8 -0
  137. package/src/be/memory/providers/sqlite-store.ts +160 -10
  138. package/src/be/memory/task-learning.ts +79 -14
  139. package/src/be/memory/types.ts +24 -1
  140. package/src/be/migrations/279_backfill_learning_expiry.sql +15 -0
  141. package/src/be/migrations/281_model_profiles_pr2.sql +28 -0
  142. package/src/be/migrations/283_workflow_run_definitions.sql +14 -0
  143. package/src/be/model-profile-check.ts +284 -0
  144. package/src/be/model-tier-resolution.ts +112 -12
  145. package/src/be/multi-runtime.ts +27 -0
  146. package/src/be/runtime-pools/routing.ts +52 -4
  147. package/src/be/scripts/typecheck.ts +1 -0
  148. package/src/be/seed-scripts/catalog/dreaming-learnings.ts +552 -0
  149. package/src/be/seed-scripts/catalog/dreaming-memtax-create.ts +389 -14
  150. package/src/be/seed-scripts/catalog/dreaming-memtax.ts +6 -3
  151. package/src/be/seed-scripts/index.ts +9 -0
  152. package/src/be/steering.ts +8 -2
  153. package/src/commands/onboard/agent-fs-version.ts +1 -1
  154. package/src/commands/runner.ts +32 -1
  155. package/src/fs/provider.ts +17 -3
  156. package/src/heartbeat/heartbeat.ts +12 -1
  157. package/src/heartbeat/index.ts +1 -0
  158. package/src/http/agents.ts +56 -4
  159. package/src/http/apps.ts +3 -1
  160. package/src/http/config.ts +2 -6
  161. package/src/http/index.ts +2 -3
  162. package/src/http/model-profiles.ts +58 -10
  163. package/src/http/poll.ts +36 -3
  164. package/src/http/schedules.ts +42 -3
  165. package/src/http/tasks.ts +37 -12
  166. package/src/http/workflows.ts +15 -2
  167. package/src/prompts/session-templates.ts +1 -1
  168. package/src/providers/acp-targets.ts +11 -6
  169. package/src/providers/amp-adapter.ts +1 -1
  170. package/src/providers/claude-sdk-session.ts +132 -23
  171. package/src/providers/codex-skill-resolver.ts +10 -4
  172. package/src/providers/cursor-adapter.ts +1 -1
  173. package/src/providers/devin-skill-resolver.ts +5 -5
  174. package/src/providers/dsh-adapter.ts +1 -1
  175. package/src/scheduler/schedule-task.ts +1 -0
  176. package/src/scripts-runtime/sdk-allowlist.ts +1 -0
  177. package/src/scripts-runtime/swarm-sdk.ts +18 -1
  178. package/src/scripts-runtime/types/stdlib.d.ts +1 -0
  179. package/src/scripts-runtime/types/swarm-sdk.d.ts +1 -0
  180. package/src/server.ts +2 -0
  181. package/src/slack/app.ts +93 -0
  182. package/src/slack/inbound-dispatch.ts +18 -1
  183. package/src/slack/workspace-guard.ts +345 -0
  184. package/src/tasks/task-terminal-effects.ts +4 -0
  185. package/src/tasks/worker-follow-up.ts +102 -2
  186. package/src/tests/acp-adapter.test.ts +82 -0
  187. package/src/tests/apps-icon.test.ts +120 -0
  188. package/src/tests/chained-task-follow-up.test.ts +248 -0
  189. package/src/tests/check-pr-body.test.ts +40 -0
  190. package/src/tests/claude-sdk-lifecycle.test.ts +216 -1
  191. package/src/tests/claude-sdk-process.fixture.ts +57 -0
  192. package/src/tests/codex-skill-resolver.test.ts +31 -0
  193. package/src/tests/credentials-allowlist.test.ts +470 -0
  194. package/src/tests/db-task-read-contract.test.ts +5 -0
  195. package/src/tests/db-task-write-contract.test.ts +5 -0
  196. package/src/tests/deferred-wake-follow-up.test.ts +47 -0
  197. package/src/tests/docs-index-footprint.test.js +3 -3
  198. package/src/tests/dreaming-learnings.test.ts +1395 -0
  199. package/src/tests/dsh-adapter.test.ts +1 -1
  200. package/src/tests/explicit-model-validation.test.ts +2 -0
  201. package/src/tests/fs-provider.test.ts +42 -0
  202. package/src/tests/heartbeat.test.ts +28 -1
  203. package/src/tests/human-free-reclassify.test.ts +5 -1
  204. package/src/tests/list-endpoint-slimming.test.ts +17 -0
  205. package/src/tests/migration-283-workflow-run-definitions.test.ts +69 -0
  206. package/src/tests/model-profile-check.test.ts +387 -0
  207. package/src/tests/model-profiles-api.test.ts +528 -1
  208. package/src/tests/profile-claim.test.ts +415 -3
  209. package/src/tests/profile-tier-alias.test.ts +382 -0
  210. package/src/tests/schedule-profile.test.ts +359 -0
  211. package/src/tests/script-connections.test.ts +6 -0
  212. package/src/tests/script-per-script-executor.test.ts +1 -0
  213. package/src/tests/scripts-sdk-bridge-tool-failure.test.ts +141 -0
  214. package/src/tests/seed-scripts.test.ts +2 -2
  215. package/src/tests/slack-inbound-receipts.test.ts +22 -2
  216. package/src/tests/slack-socket-ack.test.ts +16 -1
  217. package/src/tests/slack-workspace-guard.test.ts +905 -0
  218. package/src/tests/steering-core.test.ts +40 -0
  219. package/src/tests/store-progress-learning.test.ts +605 -20
  220. package/src/tests/tool-annotations.test.ts +1 -1
  221. package/src/tests/workflow-convergence.test.ts +46 -40
  222. package/src/tests/workflow-definition-pinning-recovery.test.ts +552 -0
  223. package/src/tests/workflow-definition-pinning.test.ts +645 -0
  224. package/src/tests/workflow-executors.test.ts +16 -7
  225. package/src/tests/workflow-foreach.test.ts +43 -20
  226. package/src/tests/workflow-notify-slack-ready.test.ts +161 -0
  227. package/src/tests/workflow-profile.test.ts +328 -0
  228. package/src/tools/app-upsert.ts +1 -1
  229. package/src/tools/memory-edit.ts +2 -1
  230. package/src/tools/model-profiles/check-model-profile.ts +63 -0
  231. package/src/tools/schedules/create-schedule.ts +45 -4
  232. package/src/tools/schedules/patch-schedule.ts +50 -4
  233. package/src/tools/schedules/update-schedule.ts +50 -4
  234. package/src/tools/send-task.ts +17 -2
  235. package/src/tools/store-progress.ts +15 -3
  236. package/src/tools/task-action.ts +9 -1
  237. package/src/tools/templates.ts +13 -0
  238. package/src/tools/tool-config.ts +2 -1
  239. package/src/tools/utils.ts +61 -4
  240. package/src/tools/workflows/create-workflow.ts +1 -1
  241. package/src/tools/workflows/retry-workflow-run.ts +1 -1
  242. package/src/tools/workflows/update-workflow.ts +10 -1
  243. package/src/types.ts +56 -1
  244. package/src/utils/credentials.ts +89 -12
  245. package/src/workflows/engine.ts +10 -1
  246. package/src/workflows/executors/agent-task.ts +21 -2
  247. package/src/workflows/executors/foreach.ts +4 -1
  248. package/src/workflows/executors/notify.ts +62 -6
  249. package/src/workflows/executors/sub-workflow.ts +1 -1
  250. package/src/workflows/executors/swarm-script.ts +4 -1
  251. package/src/workflows/foreach-driver.ts +8 -5
  252. package/src/workflows/limits.ts +2 -1
  253. package/src/workflows/model-validation.ts +27 -2
  254. package/src/workflows/patch-definition.ts +3 -1
  255. package/src/workflows/recovery.ts +6 -6
  256. package/src/workflows/resume.ts +9 -9
  257. package/src/workflows/retry-poller.ts +2 -2
  258. package/templates/skills/apps/SKILL.md +2 -0
  259. package/templates/skills/apps/content.md +2 -0
  260. package/templates/skills/code-quality/content.md +12 -0
  261. package/templates/skills/memory/content.md +8 -0
  262. package/templates/skills/scheduling/config.json +1 -1
  263. package/templates/skills/scheduling/content.md +2 -2
  264. package/templates/skills/swarm-docs/content.md +4 -0
  265. package/templates/skills/swarm-extensions/content.md +1 -1
  266. package/templates/skills/swarm-scripts/SKILL.md +1 -1
  267. package/templates/skills/swarm-scripts/content.md +1 -1
  268. package/templates/skills/work-on-task/SKILL.md +2 -0
  269. package/templates/skills/work-on-task/content.md +2 -0
  270. package/templates/workflows/dreaming/content.md +174 -7
  271. package/dist/acp-adapter-srfhs1s9.js +0 -16
  272. package/dist/cli-bzvs88tv.js +0 -339
  273. package/dist/cli-cyn9v8zr.js +0 -748
  274. package/dist/cli-ed6yqpf1.js +0 -779
  275. package/dist/handlers-17wha3ze.js +0 -33
  276. package/dist/heartbeat-gwewgdms.js +0 -42
  277. package/dist/index-8arwq8mw.js +0 -34
  278. package/dist/index-tpw054az.js +0 -38
  279. package/dist/index-waq75j2j.js +0 -31
  280. package/dist/lead-re73kdgc.js +0 -72
  281. package/dist/worker-r8mz7a65.js +0 -72
@@ -26,6 +26,7 @@ import { withSpan } from "../otel";
26
26
  import { COLOR_LITERAL_THRESHOLD } from "../pages/color-literals";
27
27
  import type { PermissionVerb } from "../rbac/permissions";
28
28
  import { SCRIPT_LONG_TIMEOUT_HINT_MS } from "../scripts-runtime/executors/types";
29
+ import { DEFAULT_MODEL_TIER_MAP, type ModelTier, type ProviderName } from "../types";
29
30
  import { scrubObject, scrubSecrets } from "../utils/secret-scrubber";
30
31
 
31
32
  type Meta = RequestHandlerExtra<ServerRequest, ServerNotification>;
@@ -299,14 +300,30 @@ const storeProgressBlockedWaitingNudge = (r: SwarmToolResult): string | undefine
299
300
  return `That reads as blocked-waiting, ${formatIdleDuration(ms)} since your last update — keep working if you can, and if the wait is genuinely long, defer-task is one way to resume later instead of polling.`;
300
301
  };
301
302
 
303
+ /** One steer per noise-floor rule (src/be/memory/task-learning.ts), each naming the fix. */
304
+ const LEARNING_NOISE_FLOOR_NUDGES: Record<string, string> = {
305
+ "too-short":
306
+ 'That learning was too short to hold a lesson; resend it as a title line, then the rule as "When X, do Y", or drop it if it is only status.',
307
+ "repeats-progress":
308
+ 'That learning restates this call\'s progress or output; resend only the rule the next agent should follow ("When X, do Y"), or drop it.',
309
+ };
310
+
302
311
  const storeProgressNudge = (r: SwarmToolResult): string | undefined => {
303
- const learning = (r.data as { learning?: { status?: unknown; memoryId?: unknown } } | undefined)
304
- ?.learning;
305
- // nudgeMiddleware permits exactly one steer: the duplicate-learning steer
306
- // names a concrete next call, so it wins over the blocked-waiting reminder.
312
+ const learning = (
313
+ r.data as
314
+ | { learning?: { status?: unknown; memoryId?: unknown; noiseFloor?: unknown } }
315
+ | undefined
316
+ )?.learning;
317
+ // nudgeMiddleware permits exactly one steer: the learning steers name a
318
+ // concrete fix, so they win over the blocked-waiting reminder, duplicate first.
307
319
  if (r.ok && learning?.status === "duplicate" && typeof learning.memoryId === "string") {
308
320
  return `That learning repeats memory ${learning.memoryId}; if your text adds something, memory-edit that memory instead of storing a new one.`;
309
321
  }
322
+ const noiseSteer =
323
+ r.ok && learning?.status === "failed" && typeof learning.noiseFloor === "string"
324
+ ? LEARNING_NOISE_FLOOR_NUDGES[learning.noiseFloor]
325
+ : undefined;
326
+ if (noiseSteer) return noiseSteer;
310
327
  return storeProgressBlockedWaitingNudge(r);
311
328
  };
312
329
 
@@ -316,6 +333,41 @@ const workflowLongScriptTimeoutNudge = (r: SwarmToolResult): string | undefined
316
333
  return hint ? WORKFLOW_LONG_SCRIPT_TIMEOUT_NUDGE : undefined;
317
334
  };
318
335
 
336
+ /** Result extra for a tool that received `modelTier` (runbooks/model-tiers.md § Model profiles). */
337
+ export type ModelTierDeprecated = { tier: ModelTier; suggestedProfile: string | null };
338
+
339
+ export const modelTierDeprecatedOutputSchema = z.looseObject({
340
+ tier: z.string().optional(),
341
+ suggestedProfile: z.string().nullable().optional(),
342
+ });
343
+
344
+ /**
345
+ * `modelTier` is an alias for the seeded `<harness>-<tier>` profile. The
346
+ * suggestion is null when the harness is unknown (a pool task) or has no seed
347
+ * for the tier (acp).
348
+ */
349
+ export function modelTierDeprecation(
350
+ tier: ModelTier | null | undefined,
351
+ harness: ProviderName | null | undefined,
352
+ ): ModelTierDeprecated | undefined {
353
+ if (!tier) return undefined;
354
+ const seeded = harness ? Boolean(DEFAULT_MODEL_TIER_MAP[harness]?.[tier]) : false;
355
+ return { tier, suggestedProfile: seeded ? `${harness}-${tier}` : null };
356
+ }
357
+
358
+ const modelTierDeprecatedNudge = (r: SwarmToolResult): string | undefined => {
359
+ if (!r.ok) return undefined;
360
+ const note = (
361
+ r.data as { modelTierDeprecated?: { tier?: unknown; suggestedProfile?: unknown } } | undefined
362
+ )?.modelTierDeprecated;
363
+ if (!note) return undefined;
364
+ const profile =
365
+ typeof note.suggestedProfile === "string"
366
+ ? note.suggestedProfile
367
+ : `<harness>-${String(note.tier)}`;
368
+ return `modelTier is deprecated: pass profile "${profile}" (same model).`;
369
+ };
370
+
319
371
  /**
320
372
  * One call can fall into more than one create_page trap, and a result carries
321
373
  * one nudge, so this entry joins one sentence per trap that applies: a
@@ -365,6 +417,11 @@ export const NUDGES: Record<string, (result: SwarmToolResult) => string | undefi
365
417
  "patch-workflow": workflowLongScriptTimeoutNudge,
366
418
  "patch-workflow-node": workflowLongScriptTimeoutNudge,
367
419
  "slack-download-file": slackDownloadFileNudge,
420
+ "send-task": modelTierDeprecatedNudge,
421
+ "task-action": modelTierDeprecatedNudge,
422
+ "create-schedule": modelTierDeprecatedNudge,
423
+ "update-schedule": modelTierDeprecatedNudge,
424
+ "patch-schedule": modelTierDeprecatedNudge,
368
425
  "slack-read": slackReadNudge,
369
426
  create_page: createPageNudge,
370
427
  "script-search": (r) => {
@@ -135,7 +135,7 @@ export const registerCreateWorkflowTool = (server: McpServer) => {
135
135
  if (!validation.valid) {
136
136
  return toolErr(`Invalid definition: ${validation.errors.join("; ")}`);
137
137
  }
138
- const modelErrors = await workflowModelErrors(definition);
138
+ const modelErrors = await workflowModelErrors(definition, { vcsRepo });
139
139
  if (modelErrors.length > 0) {
140
140
  return toolErr(`Invalid definition: ${modelErrors.join("; ")}`);
141
141
  }
@@ -11,7 +11,7 @@ export const registerRetryWorkflowRunTool = (server: McpServer) => {
11
11
  title: "Retry Workflow Run",
12
12
  annotations: { destructiveHint: false },
13
13
  description:
14
- "Resume the same failed workflow run from its failed step(s); completed steps are not re-run. Retrying re-creates the failed node's side effects (e.g. an agent task), so check the target state first if that work was already done manually.",
14
+ "Resume the same failed workflow run from its failed step(s); completed steps are not re-run. Retrying re-creates the failed node's side effects (e.g. an agent task), so check the target state first if that work was already done manually. Retries on the definition the run started with; to use an edited workflow, trigger a new run.",
15
15
  inputSchema: z.object({
16
16
  runId: z.string().uuid().describe("Workflow run ID to retry"),
17
17
  }),
@@ -122,7 +122,16 @@ export const registerUpdateWorkflowTool = (server: McpServer) => {
122
122
  if (!validation.valid) {
123
123
  return toolErr(`Invalid definition: ${validation.errors.join("; ")}`);
124
124
  }
125
- const modelErrors = await workflowModelErrors(definition);
125
+ }
126
+ // A stored definition moving to another repo is judged again: its
127
+ // static profiles now check against that repo's credential pool.
128
+ const repoChanged =
129
+ vcsRepo !== undefined && (vcsRepo ?? null) !== (existing.vcsRepo ?? null);
130
+ const judged = definition ?? (repoChanged ? existing.definition : undefined);
131
+ if (judged) {
132
+ const modelErrors = await workflowModelErrors(judged, {
133
+ vcsRepo: vcsRepo === undefined ? existing.vcsRepo : vcsRepo,
134
+ });
126
135
  if (modelErrors.length > 0) {
127
136
  return toolErr(`Invalid definition: ${modelErrors.join("; ")}`);
128
137
  }
package/src/types.ts CHANGED
@@ -466,6 +466,16 @@ export const ModelProfileNameSchema = z
466
466
  .trim()
467
467
  .regex(/^[a-z0-9][a-z0-9._-]{0,99}$/, "lowercase letters, digits, '.', '_' or '-', max 100");
468
468
 
469
+ /**
470
+ * The pooled keys a profile may use, per credential var: the last 5
471
+ * characters of each allowed key. A var with no entry keeps its whole pool.
472
+ */
473
+ export const ModelProfileCredentialsSchema = z.record(
474
+ z.string(),
475
+ z.array(z.string().length(5)).min(1),
476
+ );
477
+ export type ModelProfileCredentials = z.infer<typeof ModelProfileCredentialsSchema>;
478
+
469
479
  export const ModelProfileSchema = z.object({
470
480
  id: z.string(),
471
481
  name: z.string(),
@@ -476,11 +486,44 @@ export const ModelProfileSchema = z.object({
476
486
  description: z.string().nullable(),
477
487
  /** `tier:<tier>` (boot seed), `agent-config` (made from an agent's MODEL_OVERRIDE), or null. */
478
488
  seededFrom: z.string().nullable(),
489
+ /** Pooled-key allowlist (column `credentialAllowlist`); null uses the whole pool. */
490
+ credentials: ModelProfileCredentialsSchema.nullable(),
479
491
  createdAt: z.string(),
480
492
  lastUpdatedAt: z.string(),
481
493
  });
482
494
  export type ModelProfile = z.infer<typeof ModelProfileSchema>;
483
495
 
496
+ /** One check's verdict: only `fail` blocks; `unverified` means nothing to judge yet. */
497
+ export const ProfileCheckStateSchema = z.enum(["pass", "warn", "fail", "unverified"]);
498
+ export type ProfileCheckState = z.infer<typeof ProfileCheckStateSchema>;
499
+
500
+ export const ProfileCheckRowSchema = z.object({
501
+ check: z.enum(["harness", "model", "harness-credentials", "credential-allowlist"]),
502
+ state: ProfileCheckStateSchema,
503
+ /** Why, in words. Names vars and key suffixes, never a secret value. */
504
+ detail: z.string().optional(),
505
+ });
506
+ export type ProfileCheckRow = z.infer<typeof ProfileCheckRowSchema>;
507
+
508
+ /**
509
+ * Whether an agent can run a profile. `profiles[0]` is the primary; `ok` is
510
+ * true when it has no `fail` row.
511
+ */
512
+ export const ProfileCheckResultSchema = z
513
+ .object({
514
+ agentId: z.string(),
515
+ ok: z.boolean(),
516
+ profiles: z.array(
517
+ z.object({
518
+ name: z.string(),
519
+ ok: z.boolean(),
520
+ checks: z.array(ProfileCheckRowSchema),
521
+ }),
522
+ ),
523
+ })
524
+ .openapi("ProfileCheckResult");
525
+ export type ProfileCheckResult = z.infer<typeof ProfileCheckResultSchema>;
526
+
484
527
  // ============================================================================
485
528
  // Session sharing
486
529
  // ============================================================================
@@ -767,7 +810,7 @@ export const AgentTaskSchema = z
767
810
 
768
811
  // Model selection (optional — provider-specific; can be "opus", "gpt-4o",
769
812
  // "openrouter/openai/gpt-5-nano", etc. depending on HARNESS_PROVIDER).
770
- // Prefer modelTier for portable task intent; model is a concrete override
813
+ // Prefer `profile` (below) for named intent; model is a concrete override
771
814
  // interpreted by the claiming worker's harness and never switches provider.
772
815
  model: z.string().optional(),
773
816
  modelTier: ModelTierSchema.optional(),
@@ -1285,6 +1328,14 @@ export const AgentAvatarSchema = z.discriminatedUnion("type", [
1285
1328
  ]);
1286
1329
  export type AgentAvatar = z.infer<typeof AgentAvatarSchema>;
1287
1330
 
1331
+ /**
1332
+ * Apps reuse the same avatar shape as agents (lucide icon + optional hex
1333
+ * color) for their dashboard tile icon. A distinct export name keeps app call
1334
+ * sites self-documenting.
1335
+ */
1336
+ export const AppIconSchema = AgentAvatarSchema;
1337
+ export type AppIcon = AgentAvatar;
1338
+
1288
1339
  // Separate from `avatar` so an agent can keep its lucide disc and still post
1289
1340
  // to Slack with its own emoji or image.
1290
1341
  export const AgentSlackIconSchema = z
@@ -1965,6 +2016,8 @@ export const ScheduledTaskSchema = z
1965
2016
  lastErrorMessage: z.string().optional(),
1966
2017
  model: z.string().optional(),
1967
2018
  modelTier: ModelTierSchema.optional(),
2019
+ /** Model profile copied onto every fired task; exclusive with model/modelTier. */
2020
+ profile: z.string().optional(),
1968
2021
  scheduleType: z.enum(["recurring", "one_time"]).default("recurring"),
1969
2022
  targetType: ScheduledTaskTargetTypeSchema.default("agent-task"),
1970
2023
  workflowId: z.uuid().optional(),
@@ -2926,6 +2979,8 @@ export type AgentTaskSummary = Pick<
2926
2979
  | "modelAlias"
2927
2980
  | "effort"
2928
2981
  | "resolvedEffort"
2982
+ | "profile"
2983
+ | "resolvedProfile"
2929
2984
  | "provider"
2930
2985
  | "requestedByUserId"
2931
2986
  | "progress"
@@ -231,6 +231,32 @@ export class ModelWindowExhaustedError extends Error {
231
231
  }
232
232
  }
233
233
 
234
+ /**
235
+ * Thrown by `resolveCredentialPools` when a model profile's credential
236
+ * allowlist names no key of a pool the worker holds. The caller must not
237
+ * spawn the CLI on this error, the same as `ModelWindowExhaustedError`.
238
+ */
239
+ export class CredentialAllowlistError extends Error {
240
+ readonly profile: string | null;
241
+ readonly keyType: string;
242
+ readonly wanted: string[];
243
+
244
+ constructor(opts: { profile?: string | null; keyType: string; wanted: string[] }) {
245
+ super(
246
+ `credential allowlist for ${opts.profile ?? "this task"} matches no ${opts.keyType} key (wanted ${opts.wanted.join(", ")})`,
247
+ );
248
+ this.name = "CredentialAllowlistError";
249
+ this.profile = opts.profile ?? null;
250
+ this.keyType = opts.keyType;
251
+ this.wanted = opts.wanted;
252
+ }
253
+ }
254
+
255
+ /** The last 5 characters of a credential: the suffix stamped on task records and named by allowlists. */
256
+ export function keySuffix(value: string): string {
257
+ return value.slice(-5);
258
+ }
259
+
234
260
  function isJsonObject(value: string): boolean {
235
261
  const trimmed = value.trim();
236
262
  if (!trimmed.startsWith("{") || !trimmed.endsWith("}")) return false;
@@ -257,10 +283,16 @@ export function splitCredentialPool(value: string): string[] {
257
283
  .filter(Boolean);
258
284
  }
259
285
 
286
+ /**
287
+ * `allowedIndices` (a profile's credential allowlist, as pool positions)
288
+ * bounds every pick, including the "all rate-limited, pick anyway" fallbacks.
289
+ * Indices stay positions in the full pool.
290
+ */
260
291
  export function selectCredential(
261
292
  value: string,
262
293
  availableIndices?: number[],
263
294
  keyType = "ANTHROPIC_API_KEY",
295
+ allowedIndices?: number[],
264
296
  ): CredentialSelection {
265
297
  // A CODEX_OAUTH value is one JSON blob ({access, refresh, expires, accountId}),
266
298
  // never a comma-separated pool: its commas are field separators. Splitting it
@@ -275,31 +307,43 @@ export function selectCredential(
275
307
  selected,
276
308
  index: 0,
277
309
  total: 1,
278
- keySuffix: selected.slice(-5),
310
+ keySuffix: keySuffix(selected),
279
311
  keyType,
280
312
  isRateLimitFallback,
281
313
  };
282
314
  }
283
315
 
316
+ // Every random draw comes from the allowlist when one is given, never the
317
+ // full pool. An empty list is ignored here: `resolveCredentialPools` throws
318
+ // `CredentialAllowlistError` before it gets this far.
319
+ const allowed = allowedIndices?.filter((i) => i >= 0 && i < credentials.length);
320
+ const drawFrom = allowed && allowed.length > 0 ? allowed : undefined;
321
+ const pickAny = () =>
322
+ drawFrom
323
+ ? drawFrom[Math.floor(Math.random() * drawFrom.length)]!
324
+ : Math.floor(Math.random() * credentials.length);
325
+
284
326
  let index: number;
285
327
  let isRateLimitFallback = false;
286
328
  if (availableIndices && availableIndices.length > 0) {
287
329
  // Pick randomly from available (non-rate-limited) indices
288
- const validIndices = availableIndices.filter((i) => i >= 0 && i < credentials.length);
330
+ const validIndices = availableIndices.filter(
331
+ (i) => i >= 0 && i < credentials.length && (!drawFrom || drawFrom.includes(i)),
332
+ );
289
333
  if (validIndices.length > 0) {
290
334
  index = validIndices[Math.floor(Math.random() * validIndices.length)]!;
291
335
  } else {
292
336
  // All available indices out of range — fall back to random from all
293
- index = Math.floor(Math.random() * credentials.length);
337
+ index = pickAny();
294
338
  isRateLimitFallback = true;
295
339
  }
296
340
  } else if (availableIndices && availableIndices.length === 0) {
297
341
  // All keys are rate-limited — pick randomly anyway (best effort)
298
- index = Math.floor(Math.random() * credentials.length);
342
+ index = pickAny();
299
343
  isRateLimitFallback = true;
300
344
  } else {
301
345
  // No availability info — pure random (backward compatible)
302
- index = Math.floor(Math.random() * credentials.length);
346
+ index = pickAny();
303
347
  }
304
348
 
305
349
  const selected = credentials[index]!;
@@ -307,7 +351,7 @@ export function selectCredential(
307
351
  selected,
308
352
  index,
309
353
  total: credentials.length,
310
- keySuffix: selected.slice(-5),
354
+ keySuffix: keySuffix(selected),
311
355
  keyType,
312
356
  isRateLimitFallback,
313
357
  };
@@ -499,6 +543,15 @@ export async function resolveCredentialPools(
499
543
  * worker can still accept tasks for another model.
500
544
  */
501
545
  enforceModelCapacity?: boolean;
546
+ /**
547
+ * The claimed model profile's credential allowlist (`{ VAR: [suffix] }`).
548
+ * A pool var with an entry picks only keys whose last 5 characters are
549
+ * listed, and throws `CredentialAllowlistError` when none match. A var
550
+ * with no entry, or no allowlist at all, keeps the whole pool.
551
+ */
552
+ allowedKeySuffixes?: Record<string, string[]>;
553
+ /** Profile name for the `CredentialAllowlistError` message. */
554
+ allowlistProfile?: string;
502
555
  },
503
556
  ): Promise<CredentialSelection[]> {
504
557
  const providerVars = opts?.provider
@@ -519,9 +572,30 @@ export async function resolveCredentialPools(
519
572
  for (const envVar of providerVars) {
520
573
  const val = env[envVar];
521
574
  if (val) {
575
+ // Allowlist positions in the full pool, so reported key indices are unchanged.
576
+ const wanted = opts?.allowedKeySuffixes?.[envVar];
577
+ let allowedIdx: number[] | undefined;
578
+ if (wanted) {
579
+ allowedIdx = splitCredentialPool(val).flatMap((key, i) =>
580
+ wanted.includes(keySuffix(key)) ? [i] : [],
581
+ );
582
+ if (allowedIdx.length === 0) {
583
+ throw new CredentialAllowlistError({
584
+ profile: opts?.allowlistProfile,
585
+ keyType: envVar,
586
+ wanted,
587
+ });
588
+ }
589
+ }
590
+ const inAllowlist = (i: number) => !allowedIdx || allowedIdx.includes(i);
591
+
522
592
  const info = availableIndicesMap?.[envVar];
523
- let available = info?.availableIndices;
524
- let modelBlockedCount = info?.modelBlockedIndices?.length ?? 0;
593
+ let available = allowedIdx
594
+ ? info?.availableIndices?.filter(inAllowlist)
595
+ : info?.availableIndices;
596
+ let modelBlockedCount = allowedIdx
597
+ ? (info?.modelBlockedIndices?.filter(inAllowlist).length ?? 0)
598
+ : (info?.modelBlockedIndices?.length ?? 0);
525
599
  if (available && window && opts?.localBlocks) {
526
600
  const beforeCount = available.length;
527
601
  available = available.filter((i) => {
@@ -532,7 +606,7 @@ export async function resolveCredentialPools(
532
606
  }
533
607
 
534
608
  const seatBlockedIndices = info?.seatBlockedIndices ?? [];
535
- const seatBlockedCount = seatBlockedIndices.length;
609
+ const seatBlockedCount = seatBlockedIndices.filter(inAllowlist).length;
536
610
  let seatFallbackIndices: number[] | undefined;
537
611
 
538
612
  // Every key is key-wide rate-limited, blocked by this model's weekly
@@ -551,7 +625,7 @@ export async function resolveCredentialPools(
551
625
  if (seatBlockedCount > 0) {
552
626
  seatFallbackIndices = splitCredentialPool(val)
553
627
  .map((_, i) => i)
554
- .filter((i) => !seatBlockedIndices.includes(i));
628
+ .filter((i) => !seatBlockedIndices.includes(i) && inAllowlist(i));
555
629
  }
556
630
  if (windowExhausted || seatFallbackIndices?.length === 0) {
557
631
  throw new ModelWindowExhaustedError({
@@ -566,8 +640,11 @@ export async function resolveCredentialPools(
566
640
  }
567
641
 
568
642
  const result = seatFallbackIndices
569
- ? { ...selectCredential(val, seatFallbackIndices, envVar), isRateLimitFallback: true }
570
- : selectCredential(val, available, envVar);
643
+ ? {
644
+ ...selectCredential(val, seatFallbackIndices, envVar, allowedIdx),
645
+ isRateLimitFallback: true,
646
+ }
647
+ : selectCredential(val, available, envVar, allowedIdx);
571
648
  env[envVar] = result.selected;
572
649
  const availInfo = available ? ` (${available.length} available of ${result.total})` : "";
573
650
  console.log(
@@ -18,6 +18,7 @@ import {
18
18
  getStepCountForNode,
19
19
  getWorkflowRun,
20
20
  getWorkflowRunStepsByRunId,
21
+ pinWorkflowDefinition,
21
22
  updateWorkflowRun,
22
23
  updateWorkflowRunStep,
23
24
  } from "../be/db";
@@ -61,7 +62,8 @@ import { runStepValidation, type ValidationRunResult } from "./validation";
61
62
  // `process.env`, so a module-level const would permanently ignore DB-saved
62
63
  // limits. Functions let a config reload take effect without a restart.
63
64
  function maxIterations(): number {
64
- return Number(process.env.WORKFLOW_MAX_ITERATIONS) || 100;
65
+ const value = Number(process.env.WORKFLOW_MAX_ITERATIONS);
66
+ return Number.isInteger(value) && value > 0 ? value : 100;
65
67
  }
66
68
 
67
69
  export interface WorkflowExecutionOptions {
@@ -131,6 +133,9 @@ export async function startWorkflowExecution(
131
133
  registry: ExecutorRegistry,
132
134
  options: WorkflowExecutionOptions = {},
133
135
  ): Promise<string> {
136
+ // The run pins the definition exactly as the caller read it, before token
137
+ // rendering: resume paths read the pin back raw, as they read the live row.
138
+ const pinSource = workflow;
134
139
  const preflight = preflightAutomation(
135
140
  workflowPreflightInput(workflow),
136
141
  await getAutomationSetupStates(),
@@ -198,6 +203,7 @@ export async function startWorkflowExecution(
198
203
  options,
199
204
  initial,
200
205
  newRunId,
206
+ pinSource,
201
207
  );
202
208
  if (!created) return runId;
203
209
  if (initial.status === "failed" && initial.preflight) {
@@ -317,6 +323,7 @@ async function createRunWithInitialState(
317
323
  options: WorkflowExecutionOptions,
318
324
  initial: InitialRunState,
319
325
  runId: string,
326
+ pinSource: Workflow,
320
327
  ): Promise<{
321
328
  runId: string;
322
329
  created: boolean;
@@ -343,6 +350,7 @@ async function createRunWithInitialState(
343
350
  (await shouldSkipCooldown(workflow.id, workflow.cooldown))
344
351
  ? { status: "skipped", error: "cooldown", finishedAt: new Date().toISOString() }
345
352
  : initial;
353
+ const definitionHash = await pinWorkflowDefinition(pinSource);
346
354
  await createWorkflowRun({
347
355
  id: runId,
348
356
  workflowId: workflow.id,
@@ -352,6 +360,7 @@ async function createRunWithInitialState(
352
360
  parentStepId,
353
361
  parentStepAttempt: parentStepId ? attempt : undefined,
354
362
  triggeredByAgentId: options.triggeredByAgentId,
363
+ definitionHash,
355
364
  });
356
365
  await updateWorkflowRun(
357
366
  runId,
@@ -1,4 +1,5 @@
1
1
  import { z } from "zod";
2
+ import { modelProfileRefError, taskProfileError } from "../../be/db/model-profiles";
2
3
  import { explicitModelErrorForAgent } from "../../be/model-validation";
3
4
  import { applyPreTaskCreate } from "../../extensions/apply-task-create";
4
5
  import { workflowContextKey } from "../../tasks/context-key";
@@ -33,6 +34,8 @@ export const AgentTaskConfigSchema = z.object({
33
34
  /** Accept a `model` the catalog does not list (a custom id). Without it an unknown id fails the node. */
34
35
  allowCustomModel: z.boolean().optional(),
35
36
  effort: ReasoningEffortSchema.optional(),
37
+ /** Model profile name (see list-model-profiles). Exclusive with model/modelTier; checked against `agentId` at run. */
38
+ profile: z.string().min(1).optional(),
36
39
  parentTaskId: z.string().uuid().optional(),
37
40
  requestedByUserId: z.string().optional(),
38
41
  outputSchema: z.record(z.string(), z.unknown()).optional(),
@@ -91,7 +94,7 @@ export class AgentTaskExecutor extends BaseExecutor<
91
94
  let effectiveVcsRepo = config.vcsRepo;
92
95
  let effectiveKey: string | undefined;
93
96
  if (meta.workflowId) {
94
- const workflow = await db.getWorkflow(meta.workflowId);
97
+ const workflow = await db.getRunWorkflow({ id: meta.runId, workflowId: meta.workflowId });
95
98
  if (workflow) {
96
99
  if (!effectiveDir && workflow.dir) effectiveDir = workflow.dir;
97
100
  if (!effectiveVcsRepo && workflow.vcsRepo) effectiveVcsRepo = workflow.vcsRepo;
@@ -106,6 +109,14 @@ export class AgentTaskExecutor extends BaseExecutor<
106
109
  agentId: config.agentId,
107
110
  });
108
111
  if (modelError) return { status: "failed", error: modelError };
112
+ const profileError = await taskProfileError({
113
+ profile: config.profile,
114
+ model: config.model,
115
+ modelTier: config.modelTier,
116
+ agentId: config.agentId,
117
+ vcsRepo: effectiveVcsRepo,
118
+ });
119
+ if (profileError) return { status: "failed", error: profileError };
109
120
  const preCreate = await applyPreTaskCreate({
110
121
  description: config.template,
111
122
  options: {
@@ -129,6 +140,7 @@ export class AgentTaskExecutor extends BaseExecutor<
129
140
  vcsRepo: effectiveVcsRepo,
130
141
  ...splitLegacyModelAlias({ model: config.model, modelTier: config.modelTier }),
131
142
  effort: config.effort,
143
+ profile: config.profile?.trim() || undefined,
132
144
  parentTaskId: config.parentTaskId,
133
145
  requestedByUserId: config.requestedByUserId ?? meta.requestedByUserId,
134
146
  outputSchema: config.outputSchema,
@@ -146,7 +158,14 @@ export class AgentTaskExecutor extends BaseExecutor<
146
158
  // block handed each child its siblings' task ids, and one child completed
147
159
  // a sibling's task with its own report. It would also wire parentTaskId to
148
160
  // a concurrent same-agent sibling's session.
149
- const task = await db.createTaskExtended(preCreate.description, preCreate.options);
161
+ let task: Awaited<ReturnType<typeof db.createTaskExtended>>;
162
+ try {
163
+ task = await db.createTaskExtended(preCreate.description, preCreate.options);
164
+ } catch (error) {
165
+ // The profile was deleted between taskProfileError and the insert.
166
+ if (modelProfileRefError(error) !== "missing") throw error;
167
+ return { status: "failed", error: `Unknown model profile "${config.profile}".` };
168
+ }
150
169
 
151
170
  // 4. Return async result — engine will pause the workflow
152
171
  return {
@@ -107,7 +107,10 @@ export class ForeachExecutor extends BaseExecutor<
107
107
  // before any child is dispatched — but only when there IS a post-join walk: a
108
108
  // terminal foreach (no successors) just closes the join and finalizes, so an
109
109
  // exact-cap fan-out is allowed there.
110
- const workflow = await this.deps.db.getWorkflow(meta.workflowId);
110
+ const workflow = await this.deps.db.getRunWorkflow({
111
+ id: meta.runId,
112
+ workflowId: meta.workflowId,
113
+ });
111
114
  const hasSuccessors = workflow
112
115
  ? getSuccessors(workflow.definition, meta.nodeId).length > 0
113
116
  : true;
@@ -1,8 +1,45 @@
1
+ import type { App } from "@slack/bolt";
1
2
  import { z } from "zod";
3
+ import { isSlackConfigured } from "../../slack/config";
2
4
  import type { ExecutorMeta } from "../../types";
3
5
  import { scrubSecrets } from "../../utils/secret-scrubber";
4
6
  import { BaseExecutor, type ExecutorResult } from "./base";
5
7
 
8
+ // ─── Slack readiness wait ───────────────────────────────────
9
+
10
+ /**
11
+ * How long a Slack notify waits for a configured but not yet initialized
12
+ * client. Kept under the default 30s node watchdog (`DEFAULT_NODE_TIMEOUT_MS`)
13
+ * so the step fails with this executor's error rather than a bare timeout.
14
+ */
15
+ const slackReadyWait = { timeoutMs: 25_000, pollMs: 250 };
16
+
17
+ /** Test seam: shrink the readiness wait. */
18
+ export function _setNotifySlackReadyWaitForTests(opts: {
19
+ timeoutMs?: number;
20
+ pollMs?: number;
21
+ }): void {
22
+ if (opts.timeoutMs !== undefined) slackReadyWait.timeoutMs = opts.timeoutMs;
23
+ if (opts.pollMs !== undefined) slackReadyWait.pollMs = opts.pollMs;
24
+ }
25
+
26
+ /** Poll for the Slack client until it exists, the wait runs out, or `signal` aborts. */
27
+ async function waitForSlackApp(
28
+ getApp: () => App | null,
29
+ signal: AbortSignal | undefined,
30
+ ): Promise<App | null> {
31
+ const deadline = Date.now() + slackReadyWait.timeoutMs;
32
+ while (Date.now() < deadline && !signal?.aborted) {
33
+ await Bun.sleep(Math.min(slackReadyWait.pollMs, Math.max(0, deadline - Date.now())));
34
+ // The deadline may have fired during the sleep. Posting now would land
35
+ // after the engine marked the step failed, and a retry would post again.
36
+ if (signal?.aborted) return null;
37
+ const app = getApp();
38
+ if (app) return app;
39
+ }
40
+ return null;
41
+ }
42
+
6
43
  // ─── Schemas ────────────────────────────────────────────────
7
44
 
8
45
  export const NotifyConfigSchema = z.object({
@@ -31,7 +68,7 @@ export class NotifyExecutor extends BaseExecutor<
31
68
  protected async execute(
32
69
  config: z.infer<typeof NotifyConfigSchema>,
33
70
  context: Readonly<Record<string, unknown>>,
34
- _meta: ExecutorMeta,
71
+ meta: ExecutorMeta,
35
72
  ): Promise<ExecutorResult<z.infer<typeof NotifyOutputSchema>>> {
36
73
  // Scrub once: the message reaches Slack, the swarm channel, a log line and
37
74
  // the step output.
@@ -62,12 +99,31 @@ export class NotifyExecutor extends BaseExecutor<
62
99
  }
63
100
  case "slack": {
64
101
  const { getSlackApp } = await import("../../slack/app");
65
- const app = getSlackApp();
102
+ let app = getSlackApp();
66
103
  if (!app) {
67
- return {
68
- status: "success",
69
- output: { sent: false, message },
70
- };
104
+ // No Slack on this install: nothing to post to, so not a failure.
105
+ if (!isSlackConfigured()) {
106
+ return {
107
+ status: "success",
108
+ output: { sent: false, message },
109
+ };
110
+ }
111
+ // Slack is configured but its client is not up: the server is still
112
+ // booting, shutting down, or reloading integrations. Reporting
113
+ // success here would drop the message and hide it.
114
+ app = await waitForSlackApp(getSlackApp, meta.signal);
115
+ if (meta.signal?.aborted) {
116
+ return {
117
+ status: "failed",
118
+ error: "Step deadline reached while waiting for the Slack client; message not sent",
119
+ };
120
+ }
121
+ if (!app) {
122
+ return {
123
+ status: "failed",
124
+ error: `Slack is configured but its client was not ready within ${slackReadyWait.timeoutMs}ms; message not sent`,
125
+ };
126
+ }
71
127
  }
72
128
  try {
73
129
  const result = await app.client.chat.postMessage({
@@ -125,7 +125,7 @@ export class SubWorkflowExecutor extends BaseExecutor<
125
125
  // The child acts as the parent's principal, never as an `agentId` in
126
126
  // `config.inputs`: the parent's author writes those, so a creator-less
127
127
  // child would otherwise run as any agent the author names.
128
- const parent = await db.getWorkflow(meta.workflowId);
128
+ const parent = await db.getRunWorkflow({ id: meta.runId, workflowId: meta.workflowId });
129
129
  const triggeredByAgentId =
130
130
  parent?.createdByAgentId ?? (await getWorkflowRunTriggeredByAgentId(meta.runId)) ?? undefined;
131
131