@desplega.ai/agent-swarm 2.7.7 → 2.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{acp-adapter-7b4vk3h5.js → acp-adapter-vg5hqkvj.js} +6 -6
- package/dist/{actions-3tt153af.js → actions-4m1ct4nh.js} +18 -18
- package/dist/{amp-adapter-njpts0yr.js → amp-adapter-txqh7eqj.js} +2 -2
- package/dist/{app-nky4378f.js → app-e00m45gn.js} +3 -3
- package/dist/{assistant-jnb669pa.js → assistant-gd08kr9e.js} +20 -20
- package/dist/boot-args-schema-tjrkpbvm.js +89 -0
- package/dist/{boot-reembed-9mgvaztt.js → boot-reembed-21hbck22.js} +1 -1
- package/dist/{boot-reembed-qs2djdej.js → boot-reembed-mdxd3wgp.js} +1 -1
- package/dist/{boot-scrub-sweep-yjpdj7s1.js → boot-scrub-sweep-qy0zr9t2.js} +3 -3
- package/dist/{boot-seeds-5cm6ambd.js → boot-seeds-n46eaxdv.js} +4 -4
- package/dist/{claude-adapter-fn287zmm.js → claude-adapter-j37w2eds.js} +6 -6
- package/dist/{claude-managed-adapter-dvs2xw5n.js → claude-managed-adapter-8jvcma9a.js} +3 -3
- package/dist/{claude-managed-setup-wtdz2mj2.js → claude-managed-setup-rzkjmgc1.js} +3 -3
- package/dist/{claude-sdk-session-x91kqyhm.js → claude-sdk-session-4k7w73t0.js} +7 -7
- package/dist/{cli-rtt8g4v9.js → cli-0ykgn1h5.js} +1 -1
- package/dist/{cli-5b456bpf.js → cli-1cxrbkk6.js} +2 -2
- package/dist/{cli-5jnhv72d.js → cli-269q28a1.js} +4 -2
- package/dist/{cli-k1nje3v3.js → cli-32m9eda8.js} +49 -37
- package/dist/{cli-35rsp8ye.js → cli-3e4snnzf.js} +1 -1
- package/dist/{cli-5zx699j9.js → cli-4t50yq3j.js} +2 -2
- package/dist/{cli-n6bv12jn.js → cli-5j0m12ns.js} +10 -3
- package/dist/{cli-dhar9qay.js → cli-5ja3b75e.js} +2 -2
- package/dist/{cli-g08zdaec.js → cli-66ww7fer.js} +1 -1
- package/dist/{cli-nmzhp1b5.js → cli-7axf41jq.js} +25 -14
- package/dist/{cli-gz6q4eve.js → cli-84rj785g.js} +5 -5
- package/dist/{cli-fyt2g4wd.js → cli-85gzce7b.js} +5 -5
- package/dist/{cli-3fg0bdcv.js → cli-8h0ayw8c.js} +1 -1
- package/dist/{cli-qghe0h66.js → cli-8rpcng8j.js} +2 -2
- package/dist/{cli-ws19768n.js → cli-8sdejs1f.js} +115 -51
- package/dist/{cli-8305gbq0.js → cli-9m8hdawy.js} +3 -3
- package/dist/{cli-excnnjg2.js → cli-ae0dnfee.js} +1 -1
- package/dist/{cli-e0kmphd6.js → cli-bb0mmdk8.js} +2 -2
- package/dist/{cli-1c6tzt8g.js → cli-bbw9wj9m.js} +8 -8
- package/dist/{cli-pjctyea3.js → cli-bshb7jas.js} +2 -2
- package/dist/{cli-08bmz9z9.js → cli-btfsp3mv.js} +3 -3
- package/dist/{cli-4zsenjhy.js → cli-c0kqky8y.js} +16 -3
- package/dist/{cli-tgrv9cjx.js → cli-dq8x79v8.js} +1 -1
- package/dist/{cli-ftyxyspd.js → cli-eqtfgfr6.js} +1 -1
- package/dist/{cli-ddaanqkd.js → cli-eyg1pa00.js} +3 -3
- package/dist/{cli-8sckt74b.js → cli-fyhr5h4s.js} +34 -12
- package/dist/{cli-q3tkegby.js → cli-fzachfnf.js} +1 -1
- package/dist/{cli-ayayvfg4.js → cli-ga786dzg.js} +13 -10
- package/dist/{cli-yyj3j5m4.js → cli-gazw7kpa.js} +2 -2
- package/dist/{cli-e46hg0xw.js → cli-gvx71kqv.js} +2 -2
- package/dist/{cli-pc6n7fre.js → cli-jdv6ypxs.js} +1 -1
- package/dist/{cli-cm5yqn35.js → cli-kf3pxxdg.js} +1 -0
- package/dist/{cli-6g0hb4cp.js → cli-kyr67fgx.js} +7 -7
- package/dist/{cli-95jzxcp3.js → cli-m0hmeqma.js} +2 -2
- package/dist/{cli-6pfd54vx.js → cli-msg9m2ny.js} +3 -1
- package/dist/{cli-afkqkrtw.js → cli-nbsf8yvn.js} +15 -3
- package/dist/{cli-tfyyvzx6.js → cli-njwac61j.js} +5 -0
- package/dist/{cli-vz22fyqv.js → cli-nn3ysbqk.js} +1 -1
- package/dist/{cli-m0da8j35.js → cli-p3vsj0d3.js} +5 -5
- package/dist/{cli-72v799xn.js → cli-ppjxh6ah.js} +3 -3
- package/dist/{cli-k899ehvh.js → cli-q4ebh7h7.js} +4 -4
- package/dist/{cli-75gkpjvw.js → cli-qd57hhhh.js} +2 -2
- package/dist/{cli-qh4d4tvk.js → cli-rjknb2ae.js} +4 -4
- package/dist/{cli-caj33vcq.js → cli-s4ss5g59.js} +1 -1
- package/dist/{cli-cb2a8pna.js → cli-sq4n7af4.js} +1 -1
- package/dist/{cli-vfym7wmz.js → cli-ssnjfg5p.js} +5 -5
- package/dist/{cli-je518txm.js → cli-t60ajbbp.js} +8 -8
- package/dist/{cli-adeegh7d.js → cli-tpksw2nr.js} +21 -17
- package/dist/{cli-wk5yrfwd.js → cli-w4xnbm46.js} +150 -58
- package/dist/{cli-k8196sh2.js → cli-wemma3jd.js} +8 -7
- package/dist/{cli-cppkf404.js → cli-xq9r2wtt.js} +45 -21
- package/dist/{cli-bfv7vdg6.js → cli-xr8908my.js} +11 -11
- package/dist/{cli-73jzwksr.js → cli-ycscb2ar.js} +4 -1
- package/dist/{cli-p82cnnjq.js → cli-yqefz277.js} +1 -1
- package/dist/{cli-jtjtabxe.js → cli-z1srzaf6.js} +11 -3
- package/dist/{cli-pq73h5mz.js → cli-z75yxkjh.js} +3 -3
- package/dist/{cli-e5bzrn01.js → cli-zkky4t5g.js} +1 -1
- package/dist/cli.js +17 -15
- package/dist/{codex-adapter-cf2yxe9m.js → codex-adapter-88z6psm4.js} +5 -5
- package/dist/{codex-hook-a0c6g6t6.js → codex-hook-fac6175r.js} +1 -1
- package/dist/{codex-login-y0pmff1c.js → codex-login-74wa4hmq.js} +1 -1
- package/dist/{codex-session-runner-6vfzdgbd.js → codex-session-runner-zwbcwzvx.js} +5 -5
- package/dist/{commands-t3mfy7vn.js → commands-7amxs716.js} +3 -3
- package/dist/{controller-q7xrbaz0.js → controller-5rkkc37m.js} +2 -2
- package/dist/{controllers-connect-c6nm70kg.js → controllers-connect-m7d4vxxb.js} +19 -19
- package/dist/{cursor-adapter-ftd81ga8.js → cursor-adapter-x1q18693.js} +1 -1
- package/dist/{db-vemtpmcc.js → db-athc68zt.js} +4 -2
- package/dist/{db-dk572x25.js → db-h2fsfve3.js} +3 -3
- package/dist/{dispatcher-kh7ecxh9.js → dispatcher-b1yz2bnn.js} +17 -17
- package/dist/{dsh-adapter-v8628r89.js → dsh-adapter-e33bkxq9.js} +1 -1
- package/dist/{easter-egg-3d-nenw4x63.js → easter-egg-3d-pv5qnzc8.js} +1 -1
- package/dist/{embedding-space-0jepb239.js → embedding-space-b4txbwrk.js} +6 -6
- package/dist/{embeddings-xxt49yxg.js → embeddings-m6zn6tad.js} +1 -1
- package/dist/{execute-1mhw6e4x.js → execute-68nwny8m.js} +1 -1
- package/dist/{external-channel-55v12e60.js → external-channel-gkckmhzh.js} +2 -2
- package/dist/{fx-adapter-bs8wqrk5.js → fx-adapter-m5jbgd5q.js} +7 -7
- package/dist/{grok-adapter-gpjqmkcq.js → grok-adapter-csvv7sac.js} +7 -7
- package/dist/handlers-8x5gfbzx.js +32 -0
- package/dist/{heartbeat-k42svnr0.js → heartbeat-6c2y3267.js} +20 -20
- package/dist/{hook-6nphweh0.js → hook-q5fv0jy2.js} +6 -6
- package/dist/{hook-114m7hap.js → hook-w0q2wcrv.js} +5 -5
- package/dist/{http-r8cc4wz7.js → http-bxat8dg3.js} +260 -120
- package/dist/{index-nh3wyqdt.js → index-bxrexmfy.js} +13 -13
- package/dist/{index-e3s8wmxy.js → index-cqhqpgrv.js} +1 -1
- package/dist/{index-fpk4bcd9.js → index-fm0czesf.js} +1 -1
- package/dist/index-hpfte8jd.js +33 -0
- package/dist/index-ncf7yb5s.js +30 -0
- package/dist/index-vte6dyeh.js +37 -0
- package/dist/{keepalive-x060nt9p.js → keepalive-qnt21cv0.js} +3 -3
- package/dist/lead-4bvftzm6.js +71 -0
- package/dist/{maintenance-2xxfexhf.js → maintenance-btdr68y4.js} +1 -1
- package/dist/{oauth-refresh-sweep-fckc4ar5.js → oauth-refresh-sweep-vczabeh4.js} +2 -2
- package/dist/{onboard-zc48j237.js → onboard-k33ezyq8.js} +2 -2
- package/dist/{opencode-adapter-r690h1cr.js → opencode-adapter-3dst2ka7.js} +5 -5
- package/dist/{otel-impl-r5xbh81q.js → otel-impl-13am7a65.js} +1 -1
- package/dist/{pi-mono-adapter-c7v8sdec.js → pi-mono-adapter-c53de1gd.js} +15 -9
- package/dist/{pricing-refresh-3pmre11v.js → pricing-refresh-9fcbnq3f.js} +3 -3
- package/dist/{rbac-roles-910mmkgz.js → rbac-roles-66j5h4y5.js} +5 -3
- package/dist/{rbac-roles-3vbshwsb.js → rbac-roles-gw0p9h3j.js} +2 -2
- package/dist/{render-v2-pxykkbab.js → render-v2-fg8bmdn4.js} +3 -3
- package/dist/{resume-adda0bwy.js → resume-1c8kr3nh.js} +6 -6
- package/dist/{runtime-fnbm7stk.js → runtime-tzf9j7tc.js} +1 -1
- package/dist/{session-access-2fvamrdc.js → session-access-d0atq10j.js} +7 -5
- package/dist/{session-source-backfill-08xvv0sm.js → session-source-backfill-0vscqmsa.js} +2 -2
- package/dist/{setup-1aqmvmh1.js → setup-tvfa7rwe.js} +1 -1
- package/dist/{virtual-modules-d2pjk9j1.js → virtual-modules-efxcp740.js} +2 -2
- package/dist/{work-objects-9s0yrm5j.js → work-objects-ks71xqeb.js} +20 -20
- package/dist/worker-e7v2bvm9.js +71 -0
- package/dist/{worker-follow-up-3q78fqmr.js → worker-follow-up-bfx0h9hg.js} +17 -17
- package/openapi.json +104 -24
- package/package.json +3 -1
- package/src/be/db/model-profiles.ts +1 -1
- package/src/be/db/session-tree.ts +9 -5
- package/src/be/db/session-visibility.ts +25 -9
- package/src/be/db/tasks/read.ts +11 -6
- package/src/be/db/tasks/write.ts +77 -7
- package/src/be/db-queries/tracker.ts +4 -2
- package/src/be/db.ts +49 -17
- package/src/be/migrations/271_subscription_usage_model.sql +30 -0
- package/src/be/model-validation.ts +19 -1
- package/src/be/rbac-roles.ts +21 -0
- package/src/be/runtime-pools/routing.ts +1 -1
- package/src/be/scripts/boot-args-schema.ts +95 -0
- package/src/be/scripts/extract-schema.ts +15 -10
- package/src/be/seed-scripts/catalog/boot-triage.inline.ts +1 -1
- package/src/be/seed-scripts/catalog/boot-triage.ts +1 -1
- package/src/be/seed-scripts/catalog/get-child-outputs.ts +1 -1
- package/src/be/seed-scripts/catalog/wait-for-task.ts +1 -1
- package/src/be/swarm-config-guard.ts +7 -0
- package/src/be/users.ts +6 -4
- package/src/commands/claude-managed-setup.ts +1 -1
- package/src/commands/runner.ts +26 -9
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/http/agents.ts +7 -1
- package/src/http/approval-requests.ts +30 -6
- package/src/http/codex-oauth-device.ts +2 -2
- package/src/http/index.ts +8 -0
- package/src/http/mcp-oauth.ts +6 -0
- package/src/http/mcp-servers.ts +8 -0
- package/src/http/models-catalog.ts +1 -1
- package/src/http/pages-public.ts +38 -1
- package/src/http/poll.ts +3 -4
- package/src/http/prompt-templates.ts +1 -1
- package/src/http/schedules.ts +4 -0
- package/src/http/script-runs.ts +6 -1
- package/src/http/session-access.ts +61 -6
- package/src/http/sessions.ts +23 -7
- package/src/http/tasks.ts +53 -9
- package/src/http/users.ts +30 -1
- package/src/http/utils.ts +2 -1
- package/src/http/workflows.ts +11 -7
- package/src/prompts/session-templates.ts +1 -0
- package/src/providers/acp-targets.ts +1 -1
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/codex-adapter.ts +9 -2
- package/src/providers/codex-oauth/device.ts +49 -15
- package/src/providers/codex-oauth/flow.ts +2 -1
- package/src/providers/pi-mono-adapter.ts +8 -0
- package/src/providers/pricing-sources.md +16 -1
- package/src/providers/swarm-events-shared.ts +15 -2
- package/src/rbac/legacy-policy.ts +1 -0
- package/src/rbac/permissions.ts +5 -0
- package/src/scheduler/deferred-task-waits.ts +9 -4
- package/src/scripts-runtime/extract-args-schema.ts +3 -1
- package/src/scripts-runtime/swarm-sdk.ts +1 -1
- package/src/scripts-runtime/types/swarm-extension.d.ts +29 -28
- package/src/server-user.ts +1 -1
- package/src/slack/ack.ts +48 -12
- package/src/slack/blocks.ts +1 -0
- package/src/slack/reaction-shortcode.ts +8 -2
- package/src/slack/render-v2.ts +30 -3
- package/src/slack/task-output.ts +4 -1
- package/src/slack/thread-buffer.ts +2 -2
- package/src/tasks/task-skip.ts +28 -0
- package/src/tasks/terminal-result-guard.ts +3 -2
- package/src/telemetry.ts +28 -1
- package/src/tests/agentmail-inbox-mapping.test.ts +73 -0
- package/src/tests/approval-requests.test.ts +58 -0
- package/src/tests/claude-managed-setup.test.ts +36 -0
- package/src/tests/codex-adapter.test.ts +2 -2
- package/src/tests/codex-oauth-device.test.ts +60 -0
- package/src/tests/codex-swarm-events.test.ts +43 -1
- package/src/tests/context-window.test.ts +14 -0
- package/src/tests/db-queries-tracker.test.ts +2 -1
- package/src/tests/db-task-read-contract.test.ts +1 -0
- package/src/tests/db-task-write-contract.test.ts +2 -0
- package/src/tests/deferred-task-wake.test.ts +7 -2
- package/src/tests/e2e-coverage-contract.test.ts +235 -0
- package/src/tests/empty-output-schema.test.ts +160 -0
- package/src/tests/env-flag.test.ts +1 -0
- package/src/tests/explicit-model-validation.test.ts +14 -0
- package/src/tests/http-api-integration.test.ts +2 -2
- package/src/tests/http-users.test.ts +63 -0
- package/src/tests/mcp-input-caps.test.ts +4 -3
- package/src/tests/merge-gate-detect-changes.test.ts +22 -0
- package/src/tests/pages-authed-mode.test.ts +13 -2
- package/src/tests/pi-mono-adapter.test.ts +39 -4
- package/src/tests/rbac-engine.test.ts +1 -0
- package/src/tests/runner-context-usage.test.ts +119 -0
- package/src/tests/script-connections.test.ts +2 -0
- package/src/tests/script-executor-quickjs.test.ts +2 -0
- package/src/tests/script-runs-http.test.ts +57 -0
- package/src/tests/scripts-boot-args-schema.test.ts +181 -0
- package/src/tests/scripts-runtime.test.ts +24 -0
- package/src/tests/sdk-store-progress-skipped.test.ts +155 -0
- package/src/tests/session-costs-model-key-normalize.test.ts +59 -0
- package/src/tests/session-sharing.test.ts +212 -2
- package/src/tests/slack-reaction-config.test.ts +1 -0
- package/src/tests/slack-render-v2.test.ts +73 -0
- package/src/tests/slack-skip-reaction.test.ts +203 -0
- package/src/tests/store-progress-skipped.test.ts +159 -0
- package/src/tests/subscription-usage-migration.test.ts +57 -0
- package/src/tests/swarm-config-reserved-keys.test.ts +3 -0
- package/src/tests/telemetry-endpoint-override.test.ts +27 -0
- package/src/tests/trigger-claiming.test.ts +2 -0
- package/src/tests/workflow-system-one-extraction.test.ts +29 -0
- package/src/tools/create-channel.ts +1 -1
- package/src/tools/defer-task.ts +1 -1
- package/src/tools/register-agentmail-inbox.ts +5 -0
- package/src/tools/repos/update-repo.ts +1 -1
- package/src/tools/request-human-input.ts +1 -1
- package/src/tools/send-task.ts +1 -1
- package/src/tools/store-progress.ts +39 -8
- package/src/tools/tracker/tracker-unlink.ts +2 -1
- package/src/tools/workflows/retry-workflow-run.ts +3 -0
- package/src/types.ts +11 -2
- package/src/utils/context-window.ts +6 -1
- package/src/utils/output-schema.ts +23 -0
- package/src/workflows/executors/system-one-providers.ts +25 -6
- package/src/workflows/recovery.ts +8 -4
- package/src/workflows/resume.ts +19 -0
- package/dist/handlers-zxmp1ta4.js +0 -32
- package/dist/index-a8phxqnk.js +0 -37
- package/dist/index-k6h00t4c.js +0 -30
- package/dist/index-xrz7te8h.js +0 -33
- package/dist/lead-956sd2yc.js +0 -71
- package/dist/worker-y15hy08h.js +0 -71
package/src/be/db/tasks/read.ts
CHANGED
|
@@ -20,6 +20,7 @@ import {
|
|
|
20
20
|
RoutingAffinitySchema,
|
|
21
21
|
TERMINAL_TASK_STATUSES,
|
|
22
22
|
} from "../../../types";
|
|
23
|
+
import { normalizeOutputSchema } from "../../../utils/output-schema";
|
|
23
24
|
import { parseProviderMeta } from "../../../utils/provider-metadata";
|
|
24
25
|
import { scrubSecrets } from "../../../utils/secret-scrubber";
|
|
25
26
|
import { getAgentById } from "../agents";
|
|
@@ -359,7 +360,11 @@ export function rowToAgentTask(row: AgentTaskRow): AgentTask {
|
|
|
359
360
|
scheduleId: row.scheduleId ?? undefined,
|
|
360
361
|
workflowRunId: row.workflowRunId ?? undefined,
|
|
361
362
|
workflowRunStepId: row.workflowRunStepId ?? undefined,
|
|
362
|
-
|
|
363
|
+
// A stored '{}' (legacy rows, defer-task resumes that copied it) means no
|
|
364
|
+
// schema: expose it as absent so no harness or validator treats it as one.
|
|
365
|
+
outputSchema: row.outputSchema
|
|
366
|
+
? normalizeOutputSchema(JSON.parse(row.outputSchema))
|
|
367
|
+
: undefined,
|
|
363
368
|
followUpConfig,
|
|
364
369
|
contextKey: row.contextKey ?? undefined,
|
|
365
370
|
compactionCount: row.compactionCount ?? undefined,
|
|
@@ -595,7 +600,7 @@ export async function hasNonTerminalResumeChild(parentId: string): Promise<boole
|
|
|
595
600
|
`SELECT 1 FROM agent_tasks
|
|
596
601
|
WHERE parentTaskId = ?
|
|
597
602
|
AND taskType = 'resume'
|
|
598
|
-
AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded')
|
|
603
|
+
AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped')
|
|
599
604
|
LIMIT 1`,
|
|
600
605
|
[parentId],
|
|
601
606
|
);
|
|
@@ -691,7 +696,7 @@ export async function hasNonTerminalRerouteDecisionChild(parentId: string): Prom
|
|
|
691
696
|
`SELECT 1 FROM agent_tasks
|
|
692
697
|
WHERE parentTaskId = ?
|
|
693
698
|
AND taskType = 'reroute-decision'
|
|
694
|
-
AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded')
|
|
699
|
+
AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped')
|
|
695
700
|
LIMIT 1`,
|
|
696
701
|
[parentId],
|
|
697
702
|
);
|
|
@@ -759,7 +764,7 @@ export async function findTaskByVcs(
|
|
|
759
764
|
const row = await getDbClient().get<AgentTaskRow>(
|
|
760
765
|
`SELECT * FROM agent_tasks
|
|
761
766
|
WHERE vcsRepo = ? AND vcsNumber = ? AND ${providerClause}
|
|
762
|
-
AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded')
|
|
767
|
+
AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped')
|
|
763
768
|
ORDER BY createdAt DESC
|
|
764
769
|
LIMIT 1`,
|
|
765
770
|
[vcsRepo, vcsNumber, vcsProvider],
|
|
@@ -782,7 +787,7 @@ export async function findActiveTasksByVcs(
|
|
|
782
787
|
const rows = await getDbClient().query<AgentTaskRow>(
|
|
783
788
|
`SELECT * FROM agent_tasks
|
|
784
789
|
WHERE vcsRepo = ? AND vcsNumber = ? AND ${providerClause}
|
|
785
|
-
AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded')
|
|
790
|
+
AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped')
|
|
786
791
|
ORDER BY createdAt DESC`,
|
|
787
792
|
[vcsRepo, vcsNumber, vcsProvider],
|
|
788
793
|
);
|
|
@@ -1683,7 +1688,7 @@ export async function findExistingLinearTrackerContextWork(
|
|
|
1683
1688
|
SELECT * FROM agent_tasks
|
|
1684
1689
|
WHERE contextKey = ?
|
|
1685
1690
|
AND id NOT IN (SELECT id FROM lineage)
|
|
1686
|
-
AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded')
|
|
1691
|
+
AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped')
|
|
1687
1692
|
ORDER BY lastUpdatedAt DESC
|
|
1688
1693
|
LIMIT 1`,
|
|
1689
1694
|
[...lineageParams, contextKey],
|
package/src/be/db/tasks/write.ts
CHANGED
|
@@ -290,7 +290,7 @@ export async function startTask(taskId: string): Promise<AgentTask | null> {
|
|
|
290
290
|
|
|
291
291
|
const row = await getDbClient().get<AgentTaskRow>(
|
|
292
292
|
`UPDATE agent_tasks SET status = 'in_progress', lastUpdatedAt = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
|
|
293
|
-
WHERE id = ? AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded') RETURNING *`,
|
|
293
|
+
WHERE id = ? AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped') RETURNING *`,
|
|
294
294
|
[taskId],
|
|
295
295
|
);
|
|
296
296
|
if (row && oldTask) {
|
|
@@ -437,7 +437,7 @@ export async function completeTask(
|
|
|
437
437
|
// terminal transition (e.g. heartbeat failTask) land first.
|
|
438
438
|
let completed = await getDbClient().get<AgentTaskRow>(
|
|
439
439
|
`UPDATE agent_tasks SET status = ?, finishedAt = ?, lastUpdatedAt = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
|
|
440
|
-
WHERE id = ? AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded') RETURNING *`,
|
|
440
|
+
WHERE id = ? AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped') RETURNING *`,
|
|
441
441
|
["completed", finishedAt, id],
|
|
442
442
|
);
|
|
443
443
|
if (!completed) return null;
|
|
@@ -569,7 +569,7 @@ export async function failTask(
|
|
|
569
569
|
// terminal transition can land during the await above).
|
|
570
570
|
const row = await getDbClient().get<AgentTaskRow>(
|
|
571
571
|
`UPDATE agent_tasks SET status = 'failed', failureReason = ?, finishedAt = ?, lastUpdatedAt = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
|
|
572
|
-
WHERE id = ? AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded')
|
|
572
|
+
WHERE id = ? AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped')
|
|
573
573
|
AND (? IS NULL OR lastUpdatedAt = ?) RETURNING *`,
|
|
574
574
|
[
|
|
575
575
|
scrubbedReason,
|
|
@@ -666,7 +666,7 @@ export async function overwriteTerminalTaskResultText(
|
|
|
666
666
|
const updated =
|
|
667
667
|
(await getDbClient().get<AgentTaskRow>(
|
|
668
668
|
`UPDATE agent_tasks SET output = ?, failureReason = ?
|
|
669
|
-
WHERE id = ? AND status IN ('completed', 'failed', 'cancelled', 'superseded')
|
|
669
|
+
WHERE id = ? AND status IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped')
|
|
670
670
|
RETURNING *`,
|
|
671
671
|
[output, failureReason, id],
|
|
672
672
|
)) ?? null;
|
|
@@ -705,7 +705,7 @@ export async function cancelTask(
|
|
|
705
705
|
// terminal transition can land during the await above).
|
|
706
706
|
const row = await getDbClient().get<AgentTaskRow>(
|
|
707
707
|
`UPDATE agent_tasks SET status = 'cancelled', failureReason = ?, finishedAt = ?, lastUpdatedAt = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
|
|
708
|
-
WHERE id = ? AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded') RETURNING *`,
|
|
708
|
+
WHERE id = ? AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped') RETURNING *`,
|
|
709
709
|
[cancelReason, finishedAt, id],
|
|
710
710
|
);
|
|
711
711
|
|
|
@@ -800,6 +800,76 @@ export async function cancelTask(
|
|
|
800
800
|
return row ? rowToAgentTask(row) : null;
|
|
801
801
|
}
|
|
802
802
|
|
|
803
|
+
/**
|
|
804
|
+
* Skip a task: the agent decided the work is not its to handle (for example a
|
|
805
|
+
* Slack thread message addressed to someone else). `skipped` is terminal. The
|
|
806
|
+
* one-line reason lands in `failureReason`, like a cancel's, so `output` stays
|
|
807
|
+
* empty and nothing that publishes a task's output has text to post.
|
|
808
|
+
*
|
|
809
|
+
* Unlike `cancelTask` it does not cascade-fail dependents: a skipped
|
|
810
|
+
* dependency satisfies `dependsOn` (see `checkDependencies`). It emits
|
|
811
|
+
* `task.skipped`, which defer-task waits and workflow resume listen for; the
|
|
812
|
+
* Slack, chat, Jira and Linear outbound paths do not, so a skip notifies no one.
|
|
813
|
+
*/
|
|
814
|
+
export async function skipTask(id: string, reason: string): Promise<AgentTask | null> {
|
|
815
|
+
const oldTask = await getTaskById(id);
|
|
816
|
+
if (!oldTask) return null;
|
|
817
|
+
if (isTerminalTaskStatus(oldTask.status)) return null;
|
|
818
|
+
|
|
819
|
+
const finishedAt = new Date().toISOString();
|
|
820
|
+
const skipReason = scrubSecrets(reason);
|
|
821
|
+
// Status predicate re-checks the idempotency guard atomically (a racing
|
|
822
|
+
// terminal transition can land during the await above).
|
|
823
|
+
const row = await getDbClient().get<AgentTaskRow>(
|
|
824
|
+
`UPDATE agent_tasks SET status = 'skipped', failureReason = ?, finishedAt = ?, lastUpdatedAt = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
|
|
825
|
+
WHERE id = ? AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped') RETURNING *`,
|
|
826
|
+
[skipReason, finishedAt, id],
|
|
827
|
+
);
|
|
828
|
+
if (!row) return null;
|
|
829
|
+
|
|
830
|
+
try {
|
|
831
|
+
await dependencies.createLogEntry({
|
|
832
|
+
eventType: "task_status_change",
|
|
833
|
+
taskId: id,
|
|
834
|
+
agentId: row.agentId ?? undefined,
|
|
835
|
+
oldValue: oldTask.status,
|
|
836
|
+
newValue: "skipped",
|
|
837
|
+
metadata: { reason: skipReason },
|
|
838
|
+
});
|
|
839
|
+
} catch {}
|
|
840
|
+
getDbClient().afterCommit(() => {
|
|
841
|
+
import("../../../workflows/event-bus")
|
|
842
|
+
.then(({ workflowEventBus }) => {
|
|
843
|
+
workflowEventBus.emit("task.skipped", {
|
|
844
|
+
taskId: id,
|
|
845
|
+
failureReason: skipReason,
|
|
846
|
+
agentId: row.agentId,
|
|
847
|
+
workflowRunId: row.workflowRunId,
|
|
848
|
+
workflowRunStepId: row.workflowRunStepId,
|
|
849
|
+
});
|
|
850
|
+
})
|
|
851
|
+
.catch((err) =>
|
|
852
|
+
console.error(
|
|
853
|
+
"[db] task.skipped event not emitted:",
|
|
854
|
+
scrubSecrets(err instanceof Error ? err.message : String(err)),
|
|
855
|
+
),
|
|
856
|
+
);
|
|
857
|
+
});
|
|
858
|
+
try {
|
|
859
|
+
await dependencies.promotePendingSteeringForTask(
|
|
860
|
+
id,
|
|
861
|
+
"Task was skipped before steering was delivered",
|
|
862
|
+
);
|
|
863
|
+
} catch (error) {
|
|
864
|
+
console.error(
|
|
865
|
+
"[skipTask] pending steering promotion error:",
|
|
866
|
+
scrubSecrets(error instanceof Error ? error.message : String(error)),
|
|
867
|
+
);
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
return rowToAgentTask(row);
|
|
871
|
+
}
|
|
872
|
+
|
|
803
873
|
/**
|
|
804
874
|
* Supersede a task: mark it as `superseded` (terminal) so a fresh "resume"
|
|
805
875
|
* follow-up task can pick up where it left off. Used by the graceful-shutdown
|
|
@@ -834,7 +904,7 @@ export async function supersedeTask(
|
|
|
834
904
|
SET status = 'superseded',
|
|
835
905
|
finishedAt = ?,
|
|
836
906
|
lastUpdatedAt = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
|
|
837
|
-
WHERE id = ? AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded')
|
|
907
|
+
WHERE id = ? AND status NOT IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped')
|
|
838
908
|
AND (? IS NULL OR lastUpdatedAt = ?)
|
|
839
909
|
RETURNING *`,
|
|
840
910
|
[finishedAt, id, args.expectedLastUpdatedAt ?? null, args.expectedLastUpdatedAt ?? null],
|
|
@@ -1189,7 +1259,7 @@ export async function updateTaskProgress(id: string, progress: string): Promise<
|
|
|
1189
1259
|
const scrubbedProgress = scrubSecrets(progress);
|
|
1190
1260
|
const row = await getDbClient().get<AgentTaskRow>(
|
|
1191
1261
|
`UPDATE agent_tasks SET progress = ?,
|
|
1192
|
-
status = CASE WHEN status IN ('completed', 'failed', 'cancelled', 'superseded') THEN status ELSE 'in_progress' END,
|
|
1262
|
+
status = CASE WHEN status IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped') THEN status ELSE 'in_progress' END,
|
|
1193
1263
|
lastUpdatedAt = strftime('%Y-%m-%dT%H:%M:%fZ', 'now')
|
|
1194
1264
|
WHERE id = ? RETURNING *`,
|
|
1195
1265
|
[scrubbedProgress, id],
|
|
@@ -220,8 +220,10 @@ export async function updateTrackerSync(
|
|
|
220
220
|
await getDbClient().run(`UPDATE tracker_sync SET ${sets.join(", ")} WHERE id = ?`, values);
|
|
221
221
|
}
|
|
222
222
|
|
|
223
|
-
|
|
224
|
-
|
|
223
|
+
/** Whether a mapping with `id` existed and was removed. */
|
|
224
|
+
export async function deleteTrackerSync(id: string): Promise<boolean> {
|
|
225
|
+
const result = await getDbClient().run("DELETE FROM tracker_sync WHERE id = ?", [id]);
|
|
226
|
+
return result.changes > 0;
|
|
225
227
|
}
|
|
226
228
|
|
|
227
229
|
/**
|
package/src/be/db.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Database } from "bun:sqlite";
|
|
2
|
+
import { chatgptSubscriptionModelId } from "@desplega/model-catalog";
|
|
2
3
|
import pkg from "../../package.json";
|
|
3
4
|
import { defaultAssetKey, normalizeAssetKey } from "../assets/key";
|
|
4
5
|
import { sessionSourceKey, sessionThreadGroupKey } from "../assets/source-key";
|
|
@@ -156,6 +157,7 @@ import {
|
|
|
156
157
|
IdentityFieldBudgetError,
|
|
157
158
|
} from "../utils/identity-field-budget";
|
|
158
159
|
import { activeModelBlock, type ModelFamily } from "../utils/model-rate-limit-windows";
|
|
160
|
+
import { isEffectiveOutputSchema } from "../utils/output-schema";
|
|
159
161
|
import { getCurrentRequestUserId } from "../utils/request-auth-context";
|
|
160
162
|
import { isRuntimePoolsEnabled } from "../utils/runtime-pools-flag";
|
|
161
163
|
import {
|
|
@@ -416,6 +418,7 @@ export {
|
|
|
416
418
|
resumeTask,
|
|
417
419
|
setTaskTitleIfUnset,
|
|
418
420
|
settleSupersededTaskDependents,
|
|
421
|
+
skipTask,
|
|
419
422
|
startTask,
|
|
420
423
|
supersedeTask,
|
|
421
424
|
updateTaskClaudeSessionId,
|
|
@@ -897,7 +900,7 @@ export async function getResolvableDeferralOutcomes(
|
|
|
897
900
|
WHERE child.parentTaskId = wake.id AND child.taskType = 'deferred'
|
|
898
901
|
)
|
|
899
902
|
AND (wake.deferredAt IS NULL OR wake.finishedAt > card.updated_at)
|
|
900
|
-
AND wake.status IN ('completed', 'failed', 'cancelled')
|
|
903
|
+
AND wake.status IN ('completed', 'failed', 'cancelled', 'skipped')
|
|
901
904
|
ORDER BY wake.finishedAt ASC
|
|
902
905
|
LIMIT ?`,
|
|
903
906
|
[limit],
|
|
@@ -992,7 +995,7 @@ export async function getSlackTreeMessages(): Promise<SlackMessageRecord[]> {
|
|
|
992
995
|
WHERE task.slackChannelId = tree.channel_id
|
|
993
996
|
AND task.slackThreadTs = tree.thread_ts
|
|
994
997
|
AND task.createdAt >= state.activated_at
|
|
995
|
-
AND task.status NOT IN ('completed', 'failed', 'cancelled', 'superseded')
|
|
998
|
+
AND task.status NOT IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped')
|
|
996
999
|
)
|
|
997
1000
|
OR EXISTS (
|
|
998
1001
|
SELECT 1 FROM agent_tasks task
|
|
@@ -2381,7 +2384,7 @@ export async function findRecentSimilarTasks(opts: {
|
|
|
2381
2384
|
|
|
2382
2385
|
// Exclude all terminal statuses — only active or recently created.
|
|
2383
2386
|
// Keep in lock-step with `TERMINAL_TASK_STATUSES` in src/types.ts.
|
|
2384
|
-
conditions.push("status NOT IN ('completed', 'failed', 'cancelled', 'superseded')");
|
|
2387
|
+
conditions.push("status NOT IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped')");
|
|
2385
2388
|
|
|
2386
2389
|
if (opts.creatorAgentId) {
|
|
2387
2390
|
conditions.push("creatorAgentId = ?");
|
|
@@ -2522,6 +2525,12 @@ export async function createTaskExtended(
|
|
|
2522
2525
|
"Disabling parent routing-affinity inheritance requires an explicit Lead-only control-plane affinity.",
|
|
2523
2526
|
);
|
|
2524
2527
|
}
|
|
2528
|
+
// An explicit empty `outputSchema: {}` means "no output schema": it stores
|
|
2529
|
+
// NULL and blocks the parent-schema inheritance below. Callers pass `{}` on
|
|
2530
|
+
// purpose to keep a delegated child free of their own output contract.
|
|
2531
|
+
if (options.outputSchema !== undefined && !isEffectiveOutputSchema(options.outputSchema)) {
|
|
2532
|
+
options = { ...options, outputSchema: undefined, inheritParentOutputSchema: false };
|
|
2533
|
+
}
|
|
2525
2534
|
let requestedByUserIdInherited = false;
|
|
2526
2535
|
// The parent key is read again inside the INSERT transaction (see below).
|
|
2527
2536
|
let keyInherited = false;
|
|
@@ -2671,7 +2680,7 @@ export async function createTaskExtended(
|
|
|
2671
2680
|
// Lead reroute-decision) that must not be held to the original work's
|
|
2672
2681
|
// output contract.
|
|
2673
2682
|
if (
|
|
2674
|
-
parent.outputSchema &&
|
|
2683
|
+
isEffectiveOutputSchema(parent.outputSchema) &&
|
|
2675
2684
|
!options.outputSchema &&
|
|
2676
2685
|
options.inheritParentOutputSchema !== false
|
|
2677
2686
|
) {
|
|
@@ -3657,7 +3666,9 @@ export async function checkDependencies(taskId: string): Promise<{
|
|
|
3657
3666
|
const blockedBy: string[] = [];
|
|
3658
3667
|
for (const depId of task.dependsOn) {
|
|
3659
3668
|
const depTask = await getTaskById(depId);
|
|
3660
|
-
|
|
3669
|
+
// A skipped dependency settled without work to hand on; it does not
|
|
3670
|
+
// block, the same as a completed one.
|
|
3671
|
+
if (!depTask || (depTask.status !== "completed" && depTask.status !== "skipped")) {
|
|
3661
3672
|
blockedBy.push(depId);
|
|
3662
3673
|
}
|
|
3663
3674
|
}
|
|
@@ -4409,11 +4420,12 @@ export async function getInboxSummary(agentId: string): Promise<InboxSummary> {
|
|
|
4409
4420
|
*/
|
|
4410
4421
|
export async function claimMentions(
|
|
4411
4422
|
agentId: string,
|
|
4412
|
-
): Promise<{ channelId: string; lastReadAt: string | null }[]> {
|
|
4423
|
+
): Promise<{ channelId: string; lastReadAt: string | null; mentionsCount: number }[]> {
|
|
4413
4424
|
const now = new Date().toISOString();
|
|
4414
4425
|
const client = getDbClient();
|
|
4415
4426
|
const channels = await getAllChannels();
|
|
4416
|
-
const claimedChannels: { channelId: string; lastReadAt: string | null }[] =
|
|
4427
|
+
const claimedChannels: { channelId: string; lastReadAt: string | null; mentionsCount: number }[] =
|
|
4428
|
+
[];
|
|
4417
4429
|
|
|
4418
4430
|
for (const channel of channels) {
|
|
4419
4431
|
// Check if this channel is already being processed
|
|
@@ -4457,7 +4469,11 @@ export async function claimMentions(
|
|
|
4457
4469
|
|
|
4458
4470
|
// Only add to claimed list if we actually claimed it (not already processing)
|
|
4459
4471
|
if (result.changes > 0) {
|
|
4460
|
-
claimedChannels.push({
|
|
4472
|
+
claimedChannels.push({
|
|
4473
|
+
channelId: channel.id,
|
|
4474
|
+
lastReadAt,
|
|
4475
|
+
mentionsCount: mentionCountRow.count,
|
|
4476
|
+
});
|
|
4461
4477
|
}
|
|
4462
4478
|
}
|
|
4463
4479
|
}
|
|
@@ -5027,13 +5043,22 @@ export async function createSessionCost(input: CreateSessionCostInput): Promise<
|
|
|
5027
5043
|
thinkingTokens,
|
|
5028
5044
|
input.durationMs,
|
|
5029
5045
|
input.numTurns,
|
|
5030
|
-
|
|
5046
|
+
// Cost rows group by the underlying model, while task configuration and
|
|
5047
|
+
// session logs retain the pi route used to select credentials.
|
|
5048
|
+
chatgptSubscriptionModelId(input.model)?.toLowerCase() ?? input.model,
|
|
5031
5049
|
input.isError ? 1 : 0,
|
|
5032
5050
|
costSource,
|
|
5033
5051
|
input.harnessCostUsd ?? null,
|
|
5034
5052
|
input.cacheWrite5mTokens ?? null,
|
|
5035
5053
|
input.cacheWrite1hTokens ?? null,
|
|
5036
|
-
input.modelBreakdown
|
|
5054
|
+
input.modelBreakdown
|
|
5055
|
+
? JSON.stringify(
|
|
5056
|
+
input.modelBreakdown.map((entry) => ({
|
|
5057
|
+
...entry,
|
|
5058
|
+
model: chatgptSubscriptionModelId(entry.model)?.toLowerCase() ?? entry.model,
|
|
5059
|
+
})),
|
|
5060
|
+
)
|
|
5061
|
+
: null,
|
|
5037
5062
|
],
|
|
5038
5063
|
);
|
|
5039
5064
|
|
|
@@ -7197,24 +7222,29 @@ export async function getAllAgentMailInboxMappings(): Promise<AgentMailInboxMapp
|
|
|
7197
7222
|
);
|
|
7198
7223
|
}
|
|
7199
7224
|
|
|
7225
|
+
/**
|
|
7226
|
+
* Map an inbox to an agent. Re-registering an inbox the same agent already owns
|
|
7227
|
+
* refreshes its email. Returns null, and changes nothing, when the inbox is
|
|
7228
|
+
* already mapped to a different agent.
|
|
7229
|
+
*/
|
|
7200
7230
|
export async function createAgentMailInboxMapping(
|
|
7201
7231
|
inboxId: string,
|
|
7202
7232
|
agentId: string,
|
|
7203
7233
|
inboxEmail?: string,
|
|
7204
|
-
): Promise<AgentMailInboxMapping> {
|
|
7234
|
+
): Promise<AgentMailInboxMapping | null> {
|
|
7205
7235
|
const id = crypto.randomUUID();
|
|
7206
7236
|
const now = new Date().toISOString();
|
|
7207
7237
|
|
|
7208
7238
|
const row = await getDbClient().get<AgentMailInboxMapping>(
|
|
7209
7239
|
`INSERT INTO agentmail_inbox_mappings (id, inboxId, agentId, inboxEmail, createdAt)
|
|
7210
7240
|
VALUES (?, ?, ?, ?, ?)
|
|
7211
|
-
ON CONFLICT(inboxId) DO UPDATE SET
|
|
7241
|
+
ON CONFLICT(inboxId) DO UPDATE SET inboxEmail = excluded.inboxEmail
|
|
7242
|
+
WHERE agentmail_inbox_mappings.agentId = excluded.agentId
|
|
7212
7243
|
RETURNING *`,
|
|
7213
7244
|
[id, inboxId, agentId, inboxEmail ?? null, now],
|
|
7214
7245
|
);
|
|
7215
7246
|
|
|
7216
|
-
|
|
7217
|
-
return row;
|
|
7247
|
+
return row ?? null;
|
|
7218
7248
|
}
|
|
7219
7249
|
|
|
7220
7250
|
export async function deleteAgentMailInboxMapping(inboxId: string): Promise<boolean> {
|
|
@@ -8343,7 +8373,7 @@ export async function getStuckWorkflowRuns(): Promise<StuckWorkflowRun[]> {
|
|
|
8343
8373
|
CROSS JOIN agent_tasks at ON at.workflowRunStepId = wrs.id
|
|
8344
8374
|
WHERE wrs.status = 'waiting'
|
|
8345
8375
|
AND wr.status = 'waiting'
|
|
8346
|
-
AND at.status IN ('completed', 'failed', 'cancelled')
|
|
8376
|
+
AND at.status IN ('completed', 'failed', 'cancelled', 'skipped')
|
|
8347
8377
|
ORDER BY at.createdAt ASC, at.rowid ASC`,
|
|
8348
8378
|
);
|
|
8349
8379
|
}
|
|
@@ -14244,8 +14274,8 @@ export async function createScriptRun(data: {
|
|
|
14244
14274
|
const row = await client.get<ScriptRunRow>(
|
|
14245
14275
|
`INSERT INTO script_runs
|
|
14246
14276
|
(id, agentId, scriptName, source, args, idempotencyKey, requestedByUserId, sourceTaskId,
|
|
14247
|
-
created_by, updated_by)
|
|
14248
|
-
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
14277
|
+
created_by, updated_by, startedAt)
|
|
14278
|
+
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
|
14249
14279
|
RETURNING *`,
|
|
14250
14280
|
[
|
|
14251
14281
|
data.id,
|
|
@@ -14261,6 +14291,8 @@ export async function createScriptRun(data: {
|
|
|
14261
14291
|
data.sourceTaskId ?? null,
|
|
14262
14292
|
data.createdBy ?? null,
|
|
14263
14293
|
data.updatedBy ?? data.createdBy ?? null,
|
|
14294
|
+
// ISO like finishedAt and the inline path, not the column's datetime('now') default.
|
|
14295
|
+
new Date().toISOString(),
|
|
14264
14296
|
],
|
|
14265
14297
|
);
|
|
14266
14298
|
if (!row) throw new Error("Failed to create script run");
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
-- Reporting groups ChatGPT subscription usage with Codex's bare OpenAI id.
|
|
2
|
+
-- Runtime routing stays in agent_tasks.model, latestModel, and session logs.
|
|
3
|
+
-- Match chatgptSubscriptionModelId(): one nonempty id, no additional slash.
|
|
4
|
+
UPDATE session_costs
|
|
5
|
+
SET model = lower(substr(trim(model), 14))
|
|
6
|
+
WHERE lower(trim(model)) LIKE 'openai-codex/%'
|
|
7
|
+
AND length(trim(model)) > 13
|
|
8
|
+
AND instr(substr(trim(model), 14), '/') = 0;
|
|
9
|
+
|
|
10
|
+
UPDATE session_costs
|
|
11
|
+
SET modelBreakdown = (
|
|
12
|
+
SELECT json_group_array(json(
|
|
13
|
+
CASE
|
|
14
|
+
WHEN lower(trim(json_extract(value, '$.model'))) LIKE 'openai-codex/%'
|
|
15
|
+
AND length(trim(json_extract(value, '$.model'))) > 13
|
|
16
|
+
AND instr(substr(trim(json_extract(value, '$.model')), 14), '/') = 0
|
|
17
|
+
THEN json_set(value, '$.model', lower(substr(trim(json_extract(value, '$.model')), 14)))
|
|
18
|
+
ELSE value
|
|
19
|
+
END
|
|
20
|
+
))
|
|
21
|
+
FROM json_each(session_costs.modelBreakdown)
|
|
22
|
+
)
|
|
23
|
+
WHERE modelBreakdown IS NOT NULL
|
|
24
|
+
AND json_valid(modelBreakdown)
|
|
25
|
+
AND EXISTS (
|
|
26
|
+
SELECT 1 FROM json_each(session_costs.modelBreakdown)
|
|
27
|
+
WHERE lower(trim(json_extract(value, '$.model'))) LIKE 'openai-codex/%'
|
|
28
|
+
AND length(trim(json_extract(value, '$.model'))) > 13
|
|
29
|
+
AND instr(substr(trim(json_extract(value, '$.model')), 14), '/') = 0
|
|
30
|
+
);
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
buildClaudeShortnameMap,
|
|
27
27
|
chatgptSubscriptionModelId,
|
|
28
28
|
type HarnessCatalogSections,
|
|
29
|
+
harnessCatalogSection,
|
|
29
30
|
harnessModelMismatch,
|
|
30
31
|
isAlias,
|
|
31
32
|
type ModelsDevCatalog,
|
|
@@ -75,6 +76,18 @@ export function isKnownCatalogModel(model: string, catalog: CatalogSections): bo
|
|
|
75
76
|
return Object.hasOwn(buildClaudeShortnameMap(anthropic), id);
|
|
76
77
|
}
|
|
77
78
|
|
|
79
|
+
/**
|
|
80
|
+
* The catalog id a Claude CLI shortname stands for (`opus` -> `claude-opus-5-5`), else `model`
|
|
81
|
+
* unchanged. `harnessModelMismatch` lets a bare name no section lists pass, so on a harness that
|
|
82
|
+
* does not run the shortname it must be spelled as its id to be judged like the id.
|
|
83
|
+
*/
|
|
84
|
+
function claudeShortnameToCatalogId(model: string, catalog: CatalogSections): string {
|
|
85
|
+
const anthropic = catalog.anthropic?.models as ModelsDevCatalog[string]["models"] | undefined;
|
|
86
|
+
const shortnames = buildClaudeShortnameMap(anthropic);
|
|
87
|
+
const bare = model.replace(CONTEXT_SUFFIX_RE, "");
|
|
88
|
+
return Object.hasOwn(shortnames, bare) ? (shortnames[bare] as string) : model;
|
|
89
|
+
}
|
|
90
|
+
|
|
78
91
|
export interface ExplicitModelCheck {
|
|
79
92
|
/** The model the caller named. Empty or absent values pass: there is nothing to check. */
|
|
80
93
|
model: string | null | undefined;
|
|
@@ -142,8 +155,13 @@ export async function explicitModelError(check: ExplicitModelCheck): Promise<str
|
|
|
142
155
|
const { providers } = await loadModelsCatalog();
|
|
143
156
|
const catalog = providers as CatalogSections;
|
|
144
157
|
if (check.harnessProvider) {
|
|
158
|
+
// The Claude harnesses run a shortname themselves; every other harness judges the id behind it.
|
|
159
|
+
const harnessModel =
|
|
160
|
+
harnessCatalogSection(check.harnessProvider) === "anthropic"
|
|
161
|
+
? model
|
|
162
|
+
: claudeShortnameToCatalogId(model, catalog);
|
|
145
163
|
const mismatch = harnessModelMismatch(
|
|
146
|
-
|
|
164
|
+
harnessModel,
|
|
147
165
|
check.harnessProvider,
|
|
148
166
|
catalog as HarnessCatalogSections,
|
|
149
167
|
{ agentId: check.agentId, agentName: check.agentName },
|
package/src/be/rbac-roles.ts
CHANGED
|
@@ -185,6 +185,27 @@ function parseDatabaseGrantVerb(roleId: string, verb: string): PermissionVerb |
|
|
|
185
185
|
return null;
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
+
/**
|
|
189
|
+
* Whether one of the user's roles lists `verb` in `role_permissions`. Unlike
|
|
190
|
+
* `getUserGrant`, a grant-all role does not count: it holds no rows, and
|
|
191
|
+
* every new user gets one (`trg_users_default_role`). Use it for a verb that
|
|
192
|
+
* must be granted on purpose.
|
|
193
|
+
*/
|
|
194
|
+
export async function userHoldsExplicitVerb(
|
|
195
|
+
userId: string,
|
|
196
|
+
verb: PermissionVerb,
|
|
197
|
+
): Promise<boolean> {
|
|
198
|
+
const row = await getDbClient().get<{ found: number }>(
|
|
199
|
+
`SELECT 1 AS found
|
|
200
|
+
FROM principal_roles pr
|
|
201
|
+
JOIN role_permissions rp ON rp.roleId = pr.roleId
|
|
202
|
+
WHERE pr.principalType = 'user' AND pr.principalId = ? AND rp.verb = ?
|
|
203
|
+
LIMIT 1`,
|
|
204
|
+
[userId, verb],
|
|
205
|
+
);
|
|
206
|
+
return row != null;
|
|
207
|
+
}
|
|
208
|
+
|
|
188
209
|
export async function getUserGrant(userId: string): Promise<EffectiveGrant> {
|
|
189
210
|
const rows = await getDbClient().query<GrantRow>(
|
|
190
211
|
`SELECT r.id AS roleId, r.grantsAll, rp.verb
|
|
@@ -42,7 +42,7 @@ async function eligibleRuntimeSlots(agentId?: string): Promise<Map<string, numbe
|
|
|
42
42
|
AND r.last_seen_at >= ?
|
|
43
43
|
AND (a.runtime_pool_id IS NULL OR p.enabled = 1)
|
|
44
44
|
AND (COALESCE(p.lifecycle, 'idle') != 'per-task' OR t.id IS NULL
|
|
45
|
-
OR t.status NOT IN ('completed', 'failed', 'cancelled', 'superseded'))
|
|
45
|
+
OR t.status NOT IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped'))
|
|
46
46
|
${agentId ? "AND r.agent_id = ?" : ""}
|
|
47
47
|
GROUP BY r.agent_id`,
|
|
48
48
|
[
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post-listen backfill: normalize stored `argsJsonSchema` JSON, so rows
|
|
3
|
+
* saved before the extractor marked `.default()` fields optional get the
|
|
4
|
+
* corrected schema without a re-upsert. Runs once per boot, async/non-blocking,
|
|
5
|
+
* idempotent: a second run finds every schema equal and rewrites nothing.
|
|
6
|
+
*
|
|
7
|
+
* This removes defaulted properties from `required` without executing script source.
|
|
8
|
+
* The write creates no version and preserves `updatedAt`. Scratch scripts and
|
|
9
|
+
* scripts without a stored schema are skipped.
|
|
10
|
+
*
|
|
11
|
+
* Mirrors the script embedding backfill (src/be/scripts/boot-reembed.ts).
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import { getDbClient } from "../db";
|
|
15
|
+
import { listScripts } from "./db";
|
|
16
|
+
|
|
17
|
+
function isObject(value: unknown): value is Record<string, unknown> {
|
|
18
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Normalize schema nodes without changing literal values in default, const, or enum. */
|
|
22
|
+
function optionalDefaults(schema: unknown): boolean {
|
|
23
|
+
if (!isObject(schema)) return false;
|
|
24
|
+
let changed = false;
|
|
25
|
+
if (Array.isArray(schema.required) && isObject(schema.properties)) {
|
|
26
|
+
const properties = schema.properties;
|
|
27
|
+
const required = schema.required.filter((name) => {
|
|
28
|
+
const property = typeof name === "string" ? properties[name] : undefined;
|
|
29
|
+
return !isObject(property) || !Object.hasOwn(property, "default");
|
|
30
|
+
});
|
|
31
|
+
if (required.length !== schema.required.length) {
|
|
32
|
+
if (required.length) schema.required = required;
|
|
33
|
+
else delete schema.required;
|
|
34
|
+
changed = true;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
for (const key of [
|
|
38
|
+
"properties",
|
|
39
|
+
"$defs",
|
|
40
|
+
"definitions",
|
|
41
|
+
"patternProperties",
|
|
42
|
+
"dependentSchemas",
|
|
43
|
+
]) {
|
|
44
|
+
const children = schema[key];
|
|
45
|
+
if (isObject(children)) {
|
|
46
|
+
for (const child of Object.values(children)) changed = optionalDefaults(child) || changed;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
for (const key of [
|
|
50
|
+
"items",
|
|
51
|
+
"additionalProperties",
|
|
52
|
+
"contains",
|
|
53
|
+
"not",
|
|
54
|
+
"if",
|
|
55
|
+
"then",
|
|
56
|
+
"else",
|
|
57
|
+
"allOf",
|
|
58
|
+
"anyOf",
|
|
59
|
+
"oneOf",
|
|
60
|
+
"prefixItems",
|
|
61
|
+
]) {
|
|
62
|
+
const children = schema[key];
|
|
63
|
+
if (Array.isArray(children)) {
|
|
64
|
+
for (const child of children) changed = optionalDefaults(child) || changed;
|
|
65
|
+
} else {
|
|
66
|
+
changed = optionalDefaults(children) || changed;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return changed;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export async function runBootArgsSchemaBackfill(): Promise<void> {
|
|
73
|
+
const scripts = (await listScripts()).filter((script) => script.argsJsonSchema);
|
|
74
|
+
if (scripts.length === 0) return;
|
|
75
|
+
|
|
76
|
+
let rewrote = 0;
|
|
77
|
+
for (const script of scripts) {
|
|
78
|
+
let schema: unknown;
|
|
79
|
+
try {
|
|
80
|
+
schema = JSON.parse(script.argsJsonSchema as string);
|
|
81
|
+
} catch {
|
|
82
|
+
// Preserve malformed legacy values for explicit repair through script_upsert.
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (!optionalDefaults(schema)) continue;
|
|
86
|
+
// A concurrent upsert must retain its own source and schema.
|
|
87
|
+
const { changes } = await getDbClient().run(
|
|
88
|
+
"UPDATE scripts SET argsJsonSchema = ? WHERE id = ? AND contentHash = ? AND argsJsonSchema = ?",
|
|
89
|
+
[JSON.stringify(schema), script.id, script.contentHash, script.argsJsonSchema],
|
|
90
|
+
);
|
|
91
|
+
rewrote += changes;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
console.log(`[boot-args-schema] rewrote ${rewrote} of ${scripts.length} script schemas`);
|
|
95
|
+
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { fileURLToPath } from "node:url";
|
|
11
|
+
import { buildSandboxedCommand } from "../../utils/sandboxed-process";
|
|
11
12
|
|
|
12
13
|
const TIMEOUT_MS = 5_000;
|
|
13
14
|
|
|
@@ -28,16 +29,20 @@ export async function extractArgsJsonSchema(source: string): Promise<string | nu
|
|
|
28
29
|
const resultFile = `${tmpdir}/result.json`;
|
|
29
30
|
await Bun.write(sourceFile, source);
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
// The extractor imports user-supplied source. Run it under the same ulimit
|
|
33
|
+
// sandbox and --no-orphans wrapper as a script run, so a hostile argsSchema
|
|
34
|
+
// module gets the memory, CPU, process and file caps of the runtime.
|
|
35
|
+
const env: Record<string, string> = {
|
|
36
|
+
PATH: process.env.PATH ?? "/usr/bin:/bin",
|
|
37
|
+
HOME: process.env.HOME ?? "/tmp",
|
|
38
|
+
TMPDIR: tmpdir,
|
|
39
|
+
SWARM_SCHEMA_SOURCE_FILE: sourceFile,
|
|
40
|
+
SWARM_SCHEMA_RESULT_FILE: resultFile,
|
|
41
|
+
SWARM_SCHEMA_TMPDIR: tmpdir,
|
|
42
|
+
};
|
|
43
|
+
if (process.env.SCRIPT_RUNTIME_DIR) env.SCRIPT_RUNTIME_DIR = process.env.SCRIPT_RUNTIME_DIR;
|
|
44
|
+
const proc = Bun.spawn(buildSandboxedCommand(["bun", "run", extractorPath()], env), {
|
|
45
|
+
env,
|
|
41
46
|
cwd: tmpdir,
|
|
42
47
|
stdout: "ignore",
|
|
43
48
|
stderr: "ignore",
|
|
@@ -195,7 +195,7 @@ export default async function bootTriage(args: any, ctx: any) {
|
|
|
195
195
|
FROM agent_tasks c
|
|
196
196
|
WHERE c.parentTaskId = p.id
|
|
197
197
|
AND c.taskType = 'resume'
|
|
198
|
-
AND c.status NOT IN ('completed', 'failed', 'cancelled', 'superseded')
|
|
198
|
+
AND c.status NOT IN ('completed', 'failed', 'cancelled', 'superseded', 'skipped')
|
|
199
199
|
)
|
|
200
200
|
ORDER BY datetime(p.lastUpdatedAt) DESC
|
|
201
201
|
LIMIT 50`,
|