@desplega.ai/agent-swarm 2.8.0 → 2.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{acp-adapter-t949vbbp.js → acp-adapter-fqzkxyra.js} +3 -3
- package/dist/{actions-7e9czc7s.js → actions-kxek041g.js} +18 -18
- package/dist/{amp-adapter-gv6cbb7d.js → amp-adapter-ce7jjke4.js} +1 -1
- package/dist/{app-b9fbkp9v.js → app-v6zz8yh0.js} +3 -3
- package/dist/{assistant-wjb7v4c7.js → assistant-m0sw9xx2.js} +19 -19
- package/dist/{boot-args-schema-2t37e0fe.js → boot-args-schema-66bk37wv.js} +1 -1
- package/dist/{boot-reembed-gka3zas7.js → boot-reembed-edjpwsc1.js} +1 -1
- package/dist/{boot-reembed-a35nkyr1.js → boot-reembed-y27n09tz.js} +1 -1
- package/dist/{boot-scrub-sweep-65sdnp6c.js → boot-scrub-sweep-1xc35965.js} +3 -3
- package/dist/{boot-seeds-x42tzytw.js → boot-seeds-7hjj91qj.js} +4 -4
- package/dist/{boxd-qbkxy6ap.js → boxd-ent8ch04.js} +1 -1
- package/dist/{claude-adapter-v221b2fd.js → claude-adapter-stw7jdcf.js} +3 -3
- package/dist/{claude-managed-adapter-29eq09wd.js → claude-managed-adapter-jh6c523j.js} +2 -2
- package/dist/{claude-managed-setup-9m6450zk.js → claude-managed-setup-y6z2perp.js} +5 -5
- package/dist/{claude-sdk-session-0q0ptaba.js → claude-sdk-session-vvya8wqk.js} +3 -3
- package/dist/{cli-wk18cm92.js → cli-0cq8y6m7.js} +1 -1
- package/dist/{cli-p1w18yhx.js → cli-1pz0330a.js} +1 -1
- package/dist/{cli-y97qxcfx.js → cli-1qkz151v.js} +3 -3
- package/dist/{cli-qwca7s44.js → cli-26ctbcdp.js} +18 -6
- package/dist/{cli-8fknbnhw.js → cli-2kvhc7x8.js} +7 -7
- package/dist/{cli-rfywm85n.js → cli-3e875j5p.js} +136 -49
- package/dist/{cli-6wxjceza.js → cli-3sy2xags.js} +10 -10
- package/dist/{cli-a7wvp2km.js → cli-3vmb0n58.js} +1 -1
- package/dist/{cli-p1bq50aa.js → cli-4vzgeta4.js} +13 -13
- package/dist/{cli-m28atx8q.js → cli-5y340nzn.js} +4 -4
- package/dist/{cli-7p1kvkck.js → cli-6rc5frdm.js} +1 -1
- package/dist/{cli-tph5wt3y.js → cli-6wj7p986.js} +1 -1
- package/dist/{cli-t73cas91.js → cli-7349va39.js} +8100 -7620
- package/dist/{cli-ee0b971j.js → cli-837vfs2x.js} +2 -2
- package/dist/{cli-abejgen1.js → cli-959kp5h2.js} +12 -11
- package/dist/{cli-8kzasymh.js → cli-97ae65rz.js} +4 -4
- package/dist/{cli-m4dqmnbp.js → cli-9mb2q6pb.js} +1 -1
- package/dist/{cli-p2gfst4m.js → cli-a0z912j7.js} +123 -35
- package/dist/{cli-4txa0ter.js → cli-b98a65ed.js} +3 -3
- package/dist/{cli-k0wwfqbg.js → cli-dns0y538.js} +4 -0
- package/dist/{cli-tk7cjj8h.js → cli-dzpc6en0.js} +1 -1
- package/dist/{cli-qa4wdgsy.js → cli-e1p3n5gq.js} +4 -4
- package/dist/{cli-gxkx0zzp.js → cli-f4e8r23x.js} +1 -1
- package/dist/{cli-qmqk2yc2.js → cli-f4r3g076.js} +1 -1
- package/dist/{cli-wcg8x116.js → cli-f6bahpn5.js} +1 -1
- package/dist/{cli-qsnnd04k.js → cli-fpjmegdb.js} +1 -1
- package/dist/{cli-j790gp2w.js → cli-fwy8kfd6.js} +271 -37
- package/dist/{cli-rmmpt0wm.js → cli-g5mtmf6t.js} +6 -6
- package/dist/{cli-rzsy6nc6.js → cli-gyt3zydq.js} +3 -3
- package/dist/{cli-pasjcnmj.js → cli-j24zbska.js} +3 -3
- package/dist/{cli-qfedvmcr.js → cli-jdknh18m.js} +10 -10
- package/dist/{cli-7b8sbmag.js → cli-kjtwrhea.js} +1 -1
- package/dist/{cli-gpwhbgx0.js → cli-m9s2qff2.js} +57 -25
- package/dist/{cli-2wnq8jkz.js → cli-mxn1qvbn.js} +3 -2
- package/dist/{cli-s7t6p9my.js → cli-n6vtrcht.js} +1 -1
- package/dist/{cli-2zp0et3v.js → cli-pchypa1s.js} +55 -19
- package/dist/{cli-yq3zak69.js → cli-pfs8adn4.js} +1 -1
- package/dist/{cli-c55z5chy.js → cli-q24n86d2.js} +2 -2
- package/dist/{cli-h38x262p.js → cli-rcecc3yq.js} +167 -43
- package/dist/{cli-xae4g51r.js → cli-rh15cakt.js} +1 -1
- package/dist/{cli-sdtt3men.js → cli-rmzsadkf.js} +1 -1
- package/dist/{cli-f3vq58d2.js → cli-t2tma8gb.js} +1 -1
- package/dist/{cli-m23zjcy2.js → cli-tekytdq9.js} +2 -2
- package/dist/{cli-tqegb8eq.js → cli-vdektqgf.js} +1 -1
- package/dist/{cli-ffhtssbp.js → cli-vj75tyaw.js} +1 -1
- package/dist/{cli-deefvewm.js → cli-w401b9tq.js} +1 -1
- package/dist/{cli-n9ftpys4.js → cli-x6t50dmw.js} +7 -7
- package/dist/{cli-6t09sdhy.js → cli-xf3qw745.js} +3 -3
- package/dist/{cli-hxpyc9sn.js → cli-z1w943va.js} +2 -2
- package/dist/{cli-334z18y3.js → cli-zh9rsbqf.js} +3 -3
- package/dist/cli.js +17 -17
- package/dist/{codex-adapter-30j9bpzd.js → codex-adapter-zerf5qsp.js} +1 -1
- package/dist/{codex-hook-h3vk6xzr.js → codex-hook-30gyhzxe.js} +1 -1
- package/dist/{codex-session-runner-8vp57v8w.js → codex-session-runner-89s304py.js} +1 -1
- package/dist/{commands-bngnz9g7.js → commands-jeh1b51j.js} +3 -3
- package/dist/{controller-hxx8wwy1.js → controller-mctfbrse.js} +3 -3
- package/dist/{controllers-connect-e2b4gyxc.js → controllers-connect-nxa1ddwn.js} +19 -19
- package/dist/{cursor-adapter-n5nc3mfe.js → cursor-adapter-qj8vehv6.js} +1 -1
- package/dist/{db-bgm7vkc0.js → db-2dvay0es.js} +3 -3
- package/dist/{db-c6np41ca.js → db-b36qn6k3.js} +2 -2
- package/dist/{dispatcher-jnybck15.js → dispatcher-gndbta01.js} +17 -17
- package/dist/{dsh-adapter-nrhbrjz8.js → dsh-adapter-f75sz821.js} +1 -1
- package/dist/{e2b-jkwfhbcv.js → e2b-3gpc2n3w.js} +1 -1
- package/dist/{e2b-s16txnpx.js → e2b-jbm7mj93.js} +1 -1
- package/dist/{embedding-space-crsm2zp0.js → embedding-space-4p05vb2x.js} +6 -6
- package/dist/{embeddings-e7z3f27f.js → embeddings-m6768mgh.js} +1 -1
- package/dist/{external-channel-m77wf5z3.js → external-channel-gjv3jne3.js} +2 -2
- package/dist/{fx-adapter-b6w0kf56.js → fx-adapter-rpsgb1tw.js} +4 -4
- package/dist/{grok-adapter-4sqtebdk.js → grok-adapter-n2m3zjg1.js} +4 -4
- package/dist/handlers-nv8edn19.js +32 -0
- package/dist/{heartbeat-xgb036sx.js → heartbeat-a1tv60gt.js} +20 -20
- package/dist/{hook-xsk1jbha.js → hook-8h5dzcgq.js} +2 -2
- package/dist/{hook-5h02c9ga.js → hook-cyaps9ba.js} +4 -4
- package/dist/{http-txe7qhvn.js → http-t15mhbd9.js} +1733 -79
- package/dist/{index-0eny15vj.js → index-2skqtd76.js} +2 -2
- package/dist/{index-w7em4ktq.js → index-d6wkh8ar.js} +2 -2
- package/dist/{index-rvccek1w.js → index-gjwaqaq8.js} +5 -5
- package/dist/{index-e5pfbsys.js → index-hjhfk3ra.js} +3 -3
- package/dist/{index-1qw6f2dc.js → index-khe3gp0k.js} +4 -4
- package/dist/index-ksmyd6kc.js +37 -0
- package/dist/{index-vk63emp7.js → index-qav6455f.js} +14 -12
- package/dist/index-rjnrje98.js +32 -0
- package/dist/index-tv3413wy.js +33 -0
- package/dist/{index-ysvbhg5m.js → index-w1zqf680.js} +1 -1
- package/dist/{keepalive-4zsrce78.js → keepalive-91s7hzrb.js} +3 -3
- package/dist/lead-3hmddvrm.js +70 -0
- package/dist/{maintenance-86jvartk.js → maintenance-7pjmy5xy.js} +1 -1
- package/dist/{node-je82wjet.js → node-4c5jqxr3.js} +1 -1
- package/dist/{oauth-refresh-sweep-j52kg9pr.js → oauth-refresh-sweep-rzqfm94j.js} +2 -2
- package/dist/{onboard-c2aj5p8q.js → onboard-74st7pag.js} +3 -3
- package/dist/{opencode-adapter-dsagkhtw.js → opencode-adapter-arn7gm8q.js} +2 -2
- package/dist/{otel-impl-yyy203z8.js → otel-impl-rnzey8cb.js} +1 -1
- package/dist/{pi-mono-adapter-546cd1cc.js → pi-mono-adapter-6mkwq64n.js} +3 -2
- package/dist/{pricing-refresh-1rgzqyzz.js → pricing-refresh-ha21jhk7.js} +2 -2
- package/dist/{rbac-roles-e70xfeyj.js → rbac-roles-59dxachk.js} +2 -2
- package/dist/{rbac-roles-q89qe8er.js → rbac-roles-wqhma4dr.js} +3 -3
- package/dist/{render-v2-k6tt107q.js → render-v2-14kpzx12.js} +3 -3
- package/dist/{resume-cnnrjfxa.js → resume-gsa5fb5f.js} +6 -6
- package/dist/{session-access-xkxkjw3n.js → session-access-skm7bnp6.js} +4 -4
- package/dist/{session-source-backfill-1d5pdwww.js → session-source-backfill-pbqzbncv.js} +2 -2
- package/dist/{setup-se8q7gkc.js → setup-5yermsem.js} +1 -1
- package/dist/{work-objects-1kxnbzy5.js → work-objects-xj0ck0w4.js} +20 -20
- package/dist/{worker-follow-up-zqm8apt4.js → worker-follow-up-911xc0b8.js} +19 -17
- package/dist/worker-qgg0m2gw.js +70 -0
- package/openapi.json +1741 -290
- package/package.json +3 -3
- package/src/apps/catalog.generated.json +120 -1
- package/src/apps/definition.ts +38 -11
- package/src/apps/page-validator.ts +88 -0
- package/src/be/db/model-profiles.ts +110 -11
- package/src/be/db/tasks/read.ts +20 -0
- package/src/be/db/workflow-run-definitions.ts +19 -8
- package/src/be/db-client.ts +43 -5
- package/src/be/db.ts +9 -3
- package/src/be/migrations/284_model_profile_fallbacks.sql +9 -0
- package/src/be/model-profile-check.ts +43 -18
- package/src/be/runtime-pools/routing.ts +1 -0
- package/src/be/savings/calibrate.ts +468 -0
- package/src/be/savings/compute.ts +182 -0
- package/src/be/savings/model.ts +406 -0
- package/src/be/scripts/typecheck.ts +5 -0
- package/src/be/seed/agent-fs-provision.ts +48 -11
- package/src/be/seed/workflows-seeder.ts +67 -23
- package/src/be/skill-parser.ts +19 -7
- package/src/commands/onboard/agent-fs-version.ts +1 -1
- package/src/commands/provider-error-class.ts +97 -0
- package/src/commands/runner.ts +99 -17
- package/src/extensions/contract-types.generated.ts +1 -1
- package/src/http/all-routes.ts +2 -0
- package/src/http/fs.ts +8 -2
- package/src/http/index.ts +4 -0
- package/src/http/model-profiles.ts +43 -10
- package/src/http/poll.ts +1 -0
- package/src/http/savings-calibration.ts +277 -0
- package/src/http/savings.ts +363 -0
- package/src/http/tasks.ts +46 -4
- package/src/http/trackers/authorize-gate.ts +41 -0
- package/src/http/trackers/jira.ts +26 -4
- package/src/http/trackers/linear.ts +26 -4
- package/src/integrations/chat-sdk/limits.ts +6 -1
- package/src/jira/oauth.ts +7 -1
- package/src/linear/README.md +2 -1
- package/src/linear/oauth.ts +7 -1
- package/src/providers/amp-adapter.ts +1 -1
- package/src/providers/codex-adapter.ts +3 -0
- package/src/providers/pi-mono-adapter.ts +6 -5
- package/src/providers/types.ts +7 -0
- package/src/scripts-runtime/eval-harness.ts +14 -1
- package/src/scripts-runtime/executors/types.ts +3 -0
- package/src/scripts-runtime/sdk-allowlist.ts +11 -1
- package/src/scripts-runtime/swarm-sdk.ts +6 -0
- package/src/scripts-runtime/types/stdlib.d.ts +9 -0
- package/src/scripts-runtime/types/swarm-extension.d.ts +34 -0
- package/src/scripts-runtime/types/swarm-sdk.d.ts +9 -0
- package/src/tasks/worker-follow-up.ts +142 -3
- package/src/tests/agent-fs-provision-seeder.test.ts +81 -0
- package/src/tests/apps-chart-shell.test.ts +170 -0
- package/src/tests/apps-icon.test.ts +156 -2
- package/src/tests/chat-sdk-relay.test.ts +12 -0
- package/src/tests/codex-adapter.test.ts +11 -0
- package/src/tests/comb-default.test.ts +6 -0
- package/src/tests/core-auth.test.ts +7 -6
- package/src/tests/db-client-busy-retry.test.ts +58 -6
- package/src/tests/deploy-guard.test.ts +154 -0
- package/src/tests/docs-index-footprint.test.js +3 -3
- package/src/tests/fixtures/app-shell-charts-definition.json.txt +180 -0
- package/src/tests/mcp-tools.test.ts +1 -1
- package/src/tests/model-profile-fallbacks.test.ts +482 -0
- package/src/tests/model-profiles-api.test.ts +1 -0
- package/src/tests/pi-mono-session-cost-on-abort.test.ts +115 -0
- package/src/tests/provider-error-class.test.ts +174 -0
- package/src/tests/runner-provider-fallback.test.ts +197 -0
- package/src/tests/savings-calibration-api.test.ts +264 -0
- package/src/tests/savings-calibration.test.ts +201 -0
- package/src/tests/savings-compute.test.ts +406 -0
- package/src/tests/savings-model.test.ts +287 -0
- package/src/tests/script-connections.test.ts +2 -0
- package/src/tests/script-native-unawaited-drain.test.ts +167 -0
- package/src/tests/sdk-allowlist.test.ts +40 -0
- package/src/tests/seed-workflows.test.ts +167 -11
- package/src/tests/skill-parser.test.ts +45 -0
- package/src/tests/tracker-oauth-authorize-auth.test.ts +262 -0
- package/src/tests/workflow-definition-pinning.test.ts +128 -3
- package/src/tests/workflow-script-principal.test.ts +94 -4
- package/src/tools/app-upsert.ts +1 -1
- package/src/tools/model-profiles/list-model-profiles.ts +4 -2
- package/src/tools/script-run.ts +1 -1
- package/src/tools/update-profile.ts +1 -1
- package/src/types.ts +115 -33
- package/src/utils/constants.ts +2 -0
- package/templates/skills/apps/SKILL.md +62 -3
- package/templates/skills/apps/content.md +62 -3
- package/templates/skills/swarm-docs/content.md +2 -0
- package/templates/skills/swarm-scripts/SKILL.md +1 -1
- package/templates/skills/swarm-scripts/content.md +1 -1
- package/dist/handlers-kdjcyzdj.js +0 -32
- package/dist/index-835xdgnm.js +0 -33
- package/dist/index-d469300x.js +0 -37
- package/dist/index-rzqwp11g.js +0 -32
- package/dist/lead-yqt47dkr.js +0 -70
- package/dist/worker-j6xxtq7p.js +0 -70
|
@@ -106,12 +106,23 @@ export async function getRunWorkflow(run: {
|
|
|
106
106
|
return pinned ? mergePinnedDefinition(live, pinned) : live;
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
/**
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
109
|
+
/**
|
|
110
|
+
* Remove only the supplied snapshots that no run references. Collect the
|
|
111
|
+
* hashes before deleting runs, then call this within the same transaction.
|
|
112
|
+
*/
|
|
113
|
+
export async function deleteOrphanedRunDefinitions(hashes: readonly string[]): Promise<void> {
|
|
114
|
+
// Snapshots can be large. Bound each statement's rows and bind parameters,
|
|
115
|
+
// and seek by hash instead of scanning unrelated definitions.
|
|
116
|
+
const batchSize = 100;
|
|
117
|
+
for (let offset = 0; offset < hashes.length; offset += batchSize) {
|
|
118
|
+
const batch = hashes.slice(offset, offset + batchSize);
|
|
119
|
+
await getDbClient().run(
|
|
120
|
+
`DELETE FROM workflow_run_definitions
|
|
121
|
+
WHERE hash IN (${batch.map(() => "?").join(", ")})
|
|
122
|
+
AND NOT EXISTS (
|
|
123
|
+
SELECT 1 FROM workflow_runs r WHERE r.definitionHash = workflow_run_definitions.hash
|
|
124
|
+
)`,
|
|
125
|
+
batch,
|
|
126
|
+
);
|
|
127
|
+
}
|
|
117
128
|
}
|
package/src/be/db-client.ts
CHANGED
|
@@ -40,8 +40,35 @@ export type TransactionOptions = {
|
|
|
40
40
|
* SELECT-only callbacks.
|
|
41
41
|
*/
|
|
42
42
|
readOnly?: boolean;
|
|
43
|
+
/**
|
|
44
|
+
* Wall-clock deadline (epoch ms) for the whole transaction, BEGIN retries and
|
|
45
|
+
* COMMIT retries included. Past it the transaction is rolled back and the call
|
|
46
|
+
* throws `DbTransactionDeadlineError`: BEGIN stops retrying, and COMMIT is never
|
|
47
|
+
* issued (or retried) once the deadline has passed, so a caller that already
|
|
48
|
+
* answered 504 cannot be followed by a late write. A COMMIT that starts before
|
|
49
|
+
* the deadline can still finish up to one `attemptSpinMs` after it. Ignored for
|
|
50
|
+
* a nested call (a SAVEPOINT): the outermost transaction owns the deadline.
|
|
51
|
+
*/
|
|
52
|
+
deadlineAt?: number;
|
|
43
53
|
};
|
|
44
54
|
|
|
55
|
+
/** The transaction's `deadlineAt` passed before it could commit; nothing was written. */
|
|
56
|
+
export class DbTransactionDeadlineError extends Error {
|
|
57
|
+
constructor() {
|
|
58
|
+
super("db-client: transaction passed its deadline and was rolled back");
|
|
59
|
+
this.name = "DbTransactionDeadlineError";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function assertBeforeDeadline(deadlineAt: number | undefined): void {
|
|
64
|
+
if (deadlineAt !== undefined && Date.now() >= deadlineAt) throw new DbTransactionDeadlineError();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** A backoff sleep never runs past the deadline: the next loop turn then fails on time. */
|
|
68
|
+
function sleepMs(ms: number, deadlineAt: number | undefined): number {
|
|
69
|
+
return deadlineAt === undefined ? ms : Math.max(0, Math.min(ms, deadlineAt - Date.now()));
|
|
70
|
+
}
|
|
71
|
+
|
|
45
72
|
export interface DbClient extends DbExecutor {
|
|
46
73
|
/**
|
|
47
74
|
* Run `fn` atomically. The callback receives an executor bound to the
|
|
@@ -393,15 +420,17 @@ class BunSqliteClient implements DbClient {
|
|
|
393
420
|
}
|
|
394
421
|
|
|
395
422
|
const readOnly = opts?.readOnly === true;
|
|
423
|
+
const deadlineAt = opts?.deadlineAt;
|
|
396
424
|
let sleptMs = 0;
|
|
397
425
|
for (let attemptIndex = 0; ; attemptIndex++) {
|
|
426
|
+
assertBeforeDeadline(deadlineAt);
|
|
398
427
|
const backoff = this.busyRetry.backoffMs[attemptIndex];
|
|
399
428
|
const canRetryAfter = backoff !== undefined && sleptMs + backoff <= this.busyRetry.maxWaitMs;
|
|
400
429
|
// The FINAL attempt spins `finalAttemptSpinMs`, never the ambient
|
|
401
430
|
// busy_timeout: a 5s synchronous camp froze every in-flight request.
|
|
402
431
|
// The dense 500ms backoff tail catches a periodic holder's release gap
|
|
403
432
|
// instead (see DEFAULT_BUSY_RETRY).
|
|
404
|
-
const attempt = await this.runTransactionAttempt(fn, readOnly, !canRetryAfter);
|
|
433
|
+
const attempt = await this.runTransactionAttempt(fn, readOnly, !canRetryAfter, deadlineAt);
|
|
405
434
|
if (attempt.ok) return attempt.value;
|
|
406
435
|
if (!canRetryAfter || backoff === undefined) throw attempt.busyBegin;
|
|
407
436
|
sleptMs += backoff;
|
|
@@ -409,7 +438,7 @@ class BunSqliteClient implements DbClient {
|
|
|
409
438
|
// (reads especially) proceeds while this writer waits out the external
|
|
410
439
|
// lock holder. Jitter desynchronizes concurrent retriers from each
|
|
411
440
|
// other and from periodic holders.
|
|
412
|
-
await sleep(jittered(backoff));
|
|
441
|
+
await sleep(sleepMs(jittered(backoff), deadlineAt));
|
|
413
442
|
}
|
|
414
443
|
}
|
|
415
444
|
|
|
@@ -422,6 +451,7 @@ class BunSqliteClient implements DbClient {
|
|
|
422
451
|
fn: (tx: DbExecutor) => Promise<T>,
|
|
423
452
|
readOnly: boolean,
|
|
424
453
|
finalAttempt = false,
|
|
454
|
+
deadlineAt?: number,
|
|
425
455
|
): Promise<{ ok: true; value: T } | { ok: false; busyBegin: unknown }> {
|
|
426
456
|
const release = await this.lock.acquire();
|
|
427
457
|
const ctx: TxContext = { closed: false, afterCommit: [] };
|
|
@@ -449,6 +479,8 @@ class BunSqliteClient implements DbClient {
|
|
|
449
479
|
}
|
|
450
480
|
began = true;
|
|
451
481
|
const result = await txContext.run(ctx, () => fn(tx));
|
|
482
|
+
// Last point a deadline can stop the write: the throw rolls back in the catch below.
|
|
483
|
+
assertBeforeDeadline(deadlineAt);
|
|
452
484
|
if (readOnly) {
|
|
453
485
|
db.run("COMMIT");
|
|
454
486
|
} else {
|
|
@@ -456,7 +488,10 @@ class BunSqliteClient implements DbClient {
|
|
|
456
488
|
// is exact. The open transaction pins the connection, so these
|
|
457
489
|
// retries hold the FIFO lock and their sleeps block queued work;
|
|
458
490
|
// WAL-mode COMMIT BUSY is rare enough for that to be acceptable.
|
|
459
|
-
await this.retryHoldingLock(
|
|
491
|
+
await this.retryHoldingLock(
|
|
492
|
+
() => this.shortSpin(db, () => db.run("COMMIT"), false, false),
|
|
493
|
+
deadlineAt,
|
|
494
|
+
);
|
|
460
495
|
}
|
|
461
496
|
for (const hook of ctx.afterCommit) this.scheduleHook(hook);
|
|
462
497
|
return { ok: true, value: result };
|
|
@@ -635,17 +670,20 @@ class BunSqliteClient implements DbClient {
|
|
|
635
670
|
* COMMIT-only retry: the open transaction pins the shared connection, so
|
|
636
671
|
* the FIFO lock stays held and these sleeps block queued in-process work.
|
|
637
672
|
*/
|
|
638
|
-
private async retryHoldingLock<T>(attempt: () => T): Promise<T> {
|
|
673
|
+
private async retryHoldingLock<T>(attempt: () => T, deadlineAt?: number): Promise<T> {
|
|
639
674
|
let sleptMs = 0;
|
|
640
675
|
for (let attemptIndex = 0; ; attemptIndex++) {
|
|
641
676
|
try {
|
|
642
677
|
return attempt();
|
|
643
678
|
} catch (err) {
|
|
644
679
|
if (!isSqliteBusy(err)) throw err;
|
|
680
|
+
// The transaction is still open and intact after a BUSY COMMIT: the caller rolls it back.
|
|
681
|
+
assertBeforeDeadline(deadlineAt);
|
|
645
682
|
const backoff = this.busyRetry.backoffMs[attemptIndex];
|
|
646
683
|
if (backoff === undefined || sleptMs + backoff > this.busyRetry.maxWaitMs) throw err;
|
|
647
684
|
sleptMs += backoff;
|
|
648
|
-
await sleep(backoff);
|
|
685
|
+
await sleep(sleepMs(backoff, deadlineAt));
|
|
686
|
+
assertBeforeDeadline(deadlineAt);
|
|
649
687
|
}
|
|
650
688
|
}
|
|
651
689
|
}
|
package/src/be/db.ts
CHANGED
|
@@ -2963,9 +2963,9 @@ export async function createTaskExtended(
|
|
|
2963
2963
|
vcsProvider, vcsRepo, vcsEventType, vcsNumber, vcsCommentId, vcsAuthor, vcsUrl,
|
|
2964
2964
|
vcsInstallationId, vcsNodeId,
|
|
2965
2965
|
agentmailInboxId, agentmailMessageId, agentmailThreadId,
|
|
2966
|
-
mentionMessageId, mentionChannelId, dir, parentTaskId, dispatchedByTaskId, model, modelTier, effort, profile, scheduleId,
|
|
2966
|
+
mentionMessageId, mentionChannelId, dir, parentTaskId, dispatchedByTaskId, model, modelTier, effort, profile, fallbackHops, scheduleId,
|
|
2967
2967
|
workflowRunId, workflowRunStepId, outputSchema, followUpConfig, requestedByUserId, requestedByUserIdInherited, contextKey, routingAffinity, swarmVersion, createdAt, lastUpdatedAt, created_by, updated_by, isHumanFree
|
|
2968
|
-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING *`,
|
|
2968
|
+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING *`,
|
|
2969
2969
|
[
|
|
2970
2970
|
id,
|
|
2971
2971
|
insertKey,
|
|
@@ -3009,6 +3009,7 @@ export async function createTaskExtended(
|
|
|
3009
3009
|
options?.modelTier ?? null,
|
|
3010
3010
|
options?.effort ?? null,
|
|
3011
3011
|
options?.profile?.trim() || null,
|
|
3012
|
+
options?.fallbackHops?.length ? JSON.stringify(options.fallbackHops) : null,
|
|
3012
3013
|
options?.scheduleId ?? null,
|
|
3013
3014
|
options?.workflowRunId ?? null,
|
|
3014
3015
|
options?.workflowRunStepId ?? null,
|
|
@@ -7963,8 +7964,13 @@ async function deleteWorkflowRows(id: string, source?: "api" | "mcp"): Promise<b
|
|
|
7963
7964
|
[id],
|
|
7964
7965
|
);
|
|
7965
7966
|
// 3. Delete runs (they reference workflow)
|
|
7967
|
+
const definitionHashes = await client.query<{ definitionHash: string }>(
|
|
7968
|
+
`SELECT DISTINCT definitionHash FROM workflow_runs
|
|
7969
|
+
WHERE workflowId = ? AND definitionHash IS NOT NULL`,
|
|
7970
|
+
[id],
|
|
7971
|
+
);
|
|
7966
7972
|
await client.run("DELETE FROM workflow_runs WHERE workflowId = ?", [id]);
|
|
7967
|
-
await deleteOrphanedRunDefinitions();
|
|
7973
|
+
await deleteOrphanedRunDefinitions(definitionHashes.map((row) => row.definitionHash));
|
|
7968
7974
|
await reclassifyTaskHumanFree(linkedTaskIds);
|
|
7969
7975
|
// 4. Delete every user's favorite of it (no FK to the workflow)
|
|
7970
7976
|
await client.run("DELETE FROM user_favorites WHERE itemType = 'workflow' AND itemId = ?", [id]);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
-- Model profiles, PR 3 (runbooks/model-tiers.md § Fallbacks on provider errors).
|
|
2
|
+
|
|
3
|
+
-- JSON array of profile names on the same harness, tried in order when a
|
|
4
|
+
-- provider error ends a task running on this profile. '[]' never hops.
|
|
5
|
+
ALTER TABLE model_profiles ADD COLUMN fallbacks TEXT NOT NULL DEFAULT '[]';
|
|
6
|
+
|
|
7
|
+
-- JSON array of the hops the work took so far ({from, profile, errorClass,
|
|
8
|
+
-- at, skipped?}); every resume of the same work carries it. NULL: no hop.
|
|
9
|
+
ALTER TABLE agent_tasks ADD COLUMN fallbackHops TEXT;
|
|
@@ -49,6 +49,11 @@ export interface ProfileCheckOptions {
|
|
|
49
49
|
vcsRepo?: string | null;
|
|
50
50
|
/** Whether the worker's config read includes secret repo rows (`readsRepoSecrets`). */
|
|
51
51
|
includeRepoSecrets?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* Judge the profile's fallbacks too (default). Gates that read only `ok`
|
|
54
|
+
* pass false and skip the extra reads.
|
|
55
|
+
*/
|
|
56
|
+
fallbacks?: boolean;
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
/**
|
|
@@ -232,10 +237,37 @@ async function credentialAllowlistRow(
|
|
|
232
237
|
};
|
|
233
238
|
}
|
|
234
239
|
|
|
240
|
+
/** Every check row for one profile on the agent. */
|
|
241
|
+
async function profileRows(
|
|
242
|
+
agent: Agent,
|
|
243
|
+
profile: ModelProfile,
|
|
244
|
+
harness: string | null,
|
|
245
|
+
agentHarness: string | null,
|
|
246
|
+
pools: Map<string, string>,
|
|
247
|
+
): Promise<ProfileCheckRow[]> {
|
|
248
|
+
const checks: ProfileCheckRow[] = [
|
|
249
|
+
harnessRow(profile, harness),
|
|
250
|
+
modelRow(profile, harness),
|
|
251
|
+
harnessCredentialsRow(agent, profile, harness, agentHarness, pools),
|
|
252
|
+
];
|
|
253
|
+
if (hasUnreadableCredentialAllowlist(profile)) {
|
|
254
|
+
// Null credentials here would read as the whole pool; fail closed instead.
|
|
255
|
+
checks.push({
|
|
256
|
+
check: "credential-allowlist",
|
|
257
|
+
state: "fail",
|
|
258
|
+
detail: "the stored credential allowlist is unreadable; set the profile's credentials again",
|
|
259
|
+
});
|
|
260
|
+
} else if (profile.credentials) {
|
|
261
|
+
checks.push(await credentialAllowlistRow(agent.id, profile.credentials, pools));
|
|
262
|
+
}
|
|
263
|
+
return checks;
|
|
264
|
+
}
|
|
265
|
+
|
|
235
266
|
/**
|
|
236
267
|
* Judge whether `agentId` can run `profileName`. Null when the agent or the
|
|
237
|
-
* profile does not exist.
|
|
238
|
-
* primary only.
|
|
268
|
+
* profile does not exist. `profiles` holds the primary, then each of its
|
|
269
|
+
* fallbacks with its own rows; `ok` judges the primary only. A fallback that
|
|
270
|
+
* no longer exists is left out.
|
|
239
271
|
*/
|
|
240
272
|
export async function checkProfileForAgent(
|
|
241
273
|
agentId: string,
|
|
@@ -251,23 +283,16 @@ export async function checkProfileForAgent(
|
|
|
251
283
|
const harness = options.harness === undefined ? agentHarness : options.harness;
|
|
252
284
|
const pools = await configPools(agentId, options);
|
|
253
285
|
|
|
254
|
-
const checks
|
|
255
|
-
harnessRow(profile, harness),
|
|
256
|
-
modelRow(profile, harness),
|
|
257
|
-
harnessCredentialsRow(agent, profile, harness, agentHarness, pools),
|
|
258
|
-
];
|
|
259
|
-
if (hasUnreadableCredentialAllowlist(profile)) {
|
|
260
|
-
// Null credentials here would read as the whole pool; fail closed instead.
|
|
261
|
-
checks.push({
|
|
262
|
-
check: "credential-allowlist",
|
|
263
|
-
state: "fail",
|
|
264
|
-
detail: "the stored credential allowlist is unreadable; set the profile's credentials again",
|
|
265
|
-
});
|
|
266
|
-
} else if (profile.credentials) {
|
|
267
|
-
checks.push(await credentialAllowlistRow(agentId, profile.credentials, pools));
|
|
268
|
-
}
|
|
286
|
+
const checks = await profileRows(agent, profile, harness, agentHarness, pools);
|
|
269
287
|
const ok = !checks.some((row) => row.state === "fail");
|
|
270
|
-
|
|
288
|
+
const profiles: ProfileCheckResult["profiles"] = [{ name: profile.name, ok, checks }];
|
|
289
|
+
for (const name of options.fallbacks === false ? [] : profile.fallbacks) {
|
|
290
|
+
const fallback = await getModelProfileByName(name);
|
|
291
|
+
if (!fallback) continue;
|
|
292
|
+
const rows = await profileRows(agent, fallback, harness, agentHarness, pools);
|
|
293
|
+
profiles.push({ name, ok: !rows.some((row) => row.state === "fail"), checks: rows });
|
|
294
|
+
}
|
|
295
|
+
return { agentId, ok, profiles };
|
|
271
296
|
}
|
|
272
297
|
|
|
273
298
|
/** One line per failing row of the primary profile, for a gate's error message. */
|