@parcha/agentrun-serve 0.1.0-beta.50 → 0.1.0-beta.52
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/CHANGELOG.md +185 -0
- package/README.md +236 -30
- package/dist/adapters.js +1 -1
- package/dist/agent-delete.d.ts +13 -2
- package/dist/agent-delete.js +14 -5
- package/dist/agents-store.d.ts +5 -1
- package/dist/agents-store.js +17 -7
- package/dist/api-only.d.ts +6 -3
- package/dist/api-only.js +8 -5
- package/dist/archil-routes.d.ts +1 -0
- package/dist/archil-routes.js +28 -2
- package/dist/capacity.d.ts +50 -0
- package/dist/capacity.js +49 -0
- package/dist/cli-learning/claude-wire.d.ts +41 -0
- package/dist/cli-learning/claude-wire.js +258 -0
- package/dist/cli-learning/cli.d.ts +11 -0
- package/dist/cli-learning/cli.js +241 -0
- package/dist/cli-learning/codex-worktree.d.ts +10 -0
- package/dist/cli-learning/codex-worktree.js +119 -0
- package/dist/cli-learning/connections.d.ts +62 -0
- package/dist/cli-learning/connections.js +87 -0
- package/dist/cli-learning/entry.d.ts +1 -0
- package/dist/cli-learning/entry.js +4 -0
- package/dist/cli-learning/evidence.d.ts +78 -0
- package/dist/cli-learning/evidence.js +492 -0
- package/dist/cli-learning/hook.d.ts +33 -0
- package/dist/cli-learning/hook.js +544 -0
- package/dist/cli-learning/install.d.ts +33 -0
- package/dist/cli-learning/install.js +335 -0
- package/dist/cli-learning/observation-proof.d.ts +14 -0
- package/dist/cli-learning/observation-proof.js +10 -0
- package/dist/cli-learning/policy.d.ts +48 -0
- package/dist/cli-learning/policy.js +363 -0
- package/dist/cli-learning/schema.d.ts +16 -0
- package/dist/cli-learning/schema.js +27 -0
- package/dist/cli-learning/state.d.ts +23 -0
- package/dist/cli-learning/state.js +61 -0
- package/dist/cli.js +24 -2
- package/dist/computer-setting.d.ts +8 -0
- package/dist/computer-setting.js +11 -0
- package/dist/computers.d.ts +6 -2
- package/dist/computers.js +2 -2
- package/dist/console/assets/index-B-D0EM3j.js +733 -0
- package/dist/console/assets/{index-D0mr9wfZ.css → index-DlQepP2J.css} +1 -1
- package/dist/console/index.html +2 -2
- package/dist/email/email-faux.d.ts +3 -1
- package/dist/email/email-faux.js +3 -2
- package/dist/email/routes.js +22 -12
- package/dist/fal-price.d.ts +76 -0
- package/dist/fal-price.js +368 -0
- package/dist/harness-install.d.ts +6 -2
- package/dist/harness-install.js +40 -8
- package/dist/harness.d.ts +1 -1
- package/dist/harness.js +2 -2
- package/dist/learn/commit.d.ts +5 -0
- package/dist/learn/commit.js +4 -1
- package/dist/learn/compile.d.ts +13 -5
- package/dist/learn/compile.js +24 -7
- package/dist/learn/delete.d.ts +12 -6
- package/dist/learn/delete.js +17 -11
- package/dist/learn/folder.d.ts +11 -0
- package/dist/learn/folder.js +20 -3
- package/dist/learn/learning-of.d.ts +8 -0
- package/dist/learn/learning-of.js +8 -0
- package/dist/learn/learning.sh +14 -1
- package/dist/learn/promote.d.ts +51 -7
- package/dist/learn/promote.js +51 -8
- package/dist/learn/secrets.js +14 -3
- package/dist/learning-reset.d.ts +18 -0
- package/dist/learning-reset.js +115 -0
- package/dist/learning-routes.d.ts +1 -1
- package/dist/learning-words.d.ts +6 -1
- package/dist/learning-words.js +6 -1
- package/dist/learning.d.ts +8 -6
- package/dist/learning.js +5 -4
- package/dist/llms.txt +1 -0
- package/dist/mcp-gateway.d.ts +39 -2
- package/dist/mcp-gateway.js +41 -10
- package/dist/mcp-pin-first.js +3 -2
- package/dist/mcp-private-hosts.d.ts +24 -3
- package/dist/mcp-private-hosts.js +53 -3
- package/dist/mcp-servers-store.d.ts +1 -0
- package/dist/mcp-servers-store.js +2 -1
- package/dist/media-duration.d.ts +2 -0
- package/dist/media-duration.js +136 -0
- package/dist/model-gateway.d.ts +2 -0
- package/dist/model-gateway.js +3 -1
- package/dist/native/runtimes.d.ts +2 -0
- package/dist/native/runtimes.js +2 -0
- package/dist/observation/learning.d.ts +32 -0
- package/dist/observation/learning.js +66 -0
- package/dist/observation/observer.d.ts +8 -1
- package/dist/observation/observer.js +89 -9
- package/dist/observation/schema.js +12 -4
- package/dist/observation/usage-identity.d.ts +9 -0
- package/dist/observation/usage-identity.js +11 -0
- package/dist/openapi.js +133 -24
- package/dist/provider.d.ts +8 -0
- package/dist/provider.js +14 -2
- package/dist/refusal-words.d.ts +0 -3
- package/dist/refusal-words.js +0 -3
- package/dist/request-metadata.d.ts +20 -0
- package/dist/request-metadata.js +24 -0
- package/dist/run-launch.d.ts +27 -4
- package/dist/run-launch.js +18 -3
- package/dist/run-learning-served.d.ts +2 -2
- package/dist/run-usage.d.ts +48 -4
- package/dist/run-usage.js +156 -39
- package/dist/run-view.d.ts +2 -0
- package/dist/run-view.js +8 -7
- package/dist/runner/adapter-loop.d.ts +3 -1
- package/dist/runner/adapter-loop.js +41 -35
- package/dist/runner/adapter-run-spec.d.ts +1 -1
- package/dist/runner/adapter-run-spec.js +15 -15
- package/dist/runner/audit.d.ts +8 -3
- package/dist/runner/audit.js +21 -6
- package/dist/runner/beside.d.ts +13 -0
- package/dist/runner/beside.js +27 -8
- package/dist/runner/claim-secrets.d.ts +2 -1
- package/dist/runner/claim-secrets.js +5 -3
- package/dist/runner/cli-run-spec.d.ts +1 -1
- package/dist/runner/cli-run-spec.js +14 -13
- package/dist/runner/conformance/harness.js +4 -2
- package/dist/runner/disk-free.d.ts +44 -0
- package/dist/runner/disk-free.js +96 -0
- package/dist/runner/dispatch.js +4 -2
- package/dist/runner/feedback-round.d.ts +12 -8
- package/dist/runner/feedback-round.js +16 -30
- package/dist/runner/harness-loops.js +8 -3
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/learning-end.d.ts +2 -1
- package/dist/runner/learning-end.js +51 -22
- package/dist/runner/main.d.ts +17 -6
- package/dist/runner/main.js +187 -45
- package/dist/runner/mcp-claim.js +1 -1
- package/dist/runner/mcp-run.d.ts +9 -0
- package/dist/runner/mcp-run.js +16 -1
- package/dist/runner/model-route.js +7 -4
- package/dist/runner/presence.d.ts +11 -2
- package/dist/runner/presence.js +31 -3
- package/dist/runner/promotion.d.ts +40 -21
- package/dist/runner/promotion.js +130 -59
- package/dist/runner/run-child-host.d.ts +12 -15
- package/dist/runner/run-child-host.js +52 -112
- package/dist/runner/run-errors.js +2 -0
- package/dist/runner/runner-check.d.ts +51 -0
- package/dist/runner/runner-check.js +206 -0
- package/dist/runner/runner-metrics.d.ts +19 -0
- package/dist/runner/runner-metrics.js +49 -0
- package/dist/runner/runner.d.ts +37 -0
- package/dist/runner/runner.js +58 -6
- package/dist/runner/sdk-loop.d.ts +2 -2
- package/dist/runner/sdk-loop.js +37 -25
- package/dist/runner/store-port.d.ts +3 -0
- package/dist/runner/workflow-spec.js +3 -3
- package/dist/runs-over-store.d.ts +13 -3
- package/dist/runs-over-store.js +71 -16
- package/dist/sdk/check.d.ts +6 -5
- package/dist/sdk/check.js +17 -16
- package/dist/sdk/runs.d.ts +22 -2
- package/dist/sdk/runs.js +167 -82
- package/dist/server.d.ts +3 -0
- package/dist/server.js +230 -43
- package/dist/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/start-switches.js +2 -0
- package/dist/stats.d.ts +4 -0
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.d.ts +16 -0
- package/dist/store/agent-body.js +20 -3
- package/dist/store/dialect.d.ts +2 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.d.ts +2 -0
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/connection.d.ts +5 -2
- package/dist/store/postgres/connection.js +19 -7
- package/dist/store/postgres/dialect.js +1 -0
- package/dist/store/postgres/migrate.d.ts +30 -0
- package/dist/store/postgres/migrate.js +72 -5
- package/dist/store/postgres/migration-lint.d.ts +8 -0
- package/dist/store/postgres/migration-lint.js +119 -0
- package/dist/store/postgres/migrations/0024_runner_capacity.sql +28 -0
- package/dist/store/postgres/migrations/0025_run_attempts.sql +27 -0
- package/dist/store/postgres/migrations/0026_run_disk.sql +23 -0
- package/dist/store/postgres/store.d.ts +8 -3
- package/dist/store/postgres/store.js +31 -11
- package/dist/store/schema.d.ts +32 -2
- package/dist/store/schema.js +74 -5
- package/dist/store/sqlite/run-launch.d.ts +31 -1
- package/dist/store/sqlite/run-launch.js +111 -2
- package/dist/store/sqlite/run-patch.d.ts +2 -1
- package/dist/store/sqlite/run-patch.js +4 -3
- package/dist/store/sqlite/store.d.ts +17 -0
- package/dist/store/sqlite/store.js +226 -37
- package/dist/store/store-schema.d.ts +34 -0
- package/dist/store/store-schema.js +125 -0
- package/dist/store/store.d.ts +120 -5
- package/dist/store/store.js +13 -0
- package/dist/store-reads/analytics.d.ts +3 -2
- package/dist/store-reads/analytics.js +20 -8
- package/dist/store-reads/learning.d.ts +12 -8
- package/dist/store-reads/learning.js +33 -24
- package/dist/store-reads/loop.d.ts +4 -3
- package/dist/store-reads/loop.js +7 -5
- package/dist/store-view.d.ts +4 -3
- package/dist/store-view.js +11 -7
- package/dist/template-eval.js +4 -4
- package/dist/templates.d.ts +6 -2
- package/dist/templates.js +7 -5
- package/dist/timeline/labels.js +1 -1
- package/dist/tool-gate.d.ts +4 -2
- package/dist/tools.js +1 -1
- package/dist/unified-usage.d.ts +24 -0
- package/dist/unified-usage.js +400 -0
- package/dist/uploads-archil.d.ts +100 -0
- package/dist/uploads-archil.js +431 -0
- package/dist/uploads.d.ts +52 -1
- package/dist/uploads.js +186 -108
- package/dist/validate.js +5 -1
- package/dist/web-save.d.ts +3 -0
- package/dist/web-save.js +17 -2
- package/dist/workspace/archil-disk.d.ts +6 -5
- package/dist/workspace/archil-disk.js +27 -12
- package/dist/workspace/archil-exec.js +1 -1
- package/dist/workspace/archil.js +4 -3
- package/dist/workspace/revision-skills.js +24 -11
- package/dist/workspace/synced-folder.d.ts +3 -3
- package/dist/workspace/synced-folder.js +7 -6
- package/package.json +10 -10
- package/skills/agentrun-serve/SKILL.md +52 -7
- package/dist/console/assets/index-D7G6o-1E.js +0 -720
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
// Which statements of a Postgres migration a runner of an earlier build cannot run beside (migrate.ts RUNNERS_BREAKING):
|
|
2
|
+
// a migration past LAST_UNMARKED with any of them carries the header, or the migration lint (its test) fails. The rule
|
|
3
|
+
// is the deploy order's: the server migrates first, under runners of the earlier release that keep running; a schema
|
|
4
|
+
// change those runners' statements no longer fit (a table or column they read gone or renamed, a type they write changed,
|
|
5
|
+
// a column they never write made NOT NULL) fails their runs. Such a change lands in two releases: the additive half first,
|
|
6
|
+
// and the destructive cleanup one release later, marked, which raises the runner floor.
|
|
7
|
+
//
|
|
8
|
+
// It reads statements, never meaning: a tightened constraint an earlier runner's writes break (a new UNIQUE, CHECK or
|
|
9
|
+
// FOREIGN KEY on what it writes) is not found here, and its author marks it as well. A new PRIMARY KEY is found: it makes
|
|
10
|
+
// its columns NOT NULL. A function's or DO block's body is not read: a destructive statement in one (an EXECUTE of a DROP)
|
|
11
|
+
// is its author's to mark.
|
|
12
|
+
/** `sql` with its comments gone and every string literal's text and dollar-quoted body emptied: what is left is the
|
|
13
|
+
* statements' own words, so a refusal's text or a function's body is never read as a statement. */
|
|
14
|
+
function bare(sql) {
|
|
15
|
+
let out = "";
|
|
16
|
+
for (let i = 0; i < sql.length;) {
|
|
17
|
+
const rest = sql.slice(i);
|
|
18
|
+
if (rest.startsWith("--")) {
|
|
19
|
+
const end = sql.indexOf("\n", i);
|
|
20
|
+
i = end === -1 ? sql.length : end;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (rest.startsWith("/*")) {
|
|
24
|
+
const end = sql.indexOf("*/", i + 2);
|
|
25
|
+
i = end === -1 ? sql.length : end + 2;
|
|
26
|
+
out += " ";
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
const dollar = /^\$(?:[A-Za-z_][A-Za-z_0-9]*)?\$/.exec(rest);
|
|
30
|
+
if (dollar) {
|
|
31
|
+
const end = sql.indexOf(dollar[0], i + dollar[0].length);
|
|
32
|
+
i = end === -1 ? sql.length : end + dollar[0].length;
|
|
33
|
+
out += "''";
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (sql[i] === "'") {
|
|
37
|
+
let j = i + 1;
|
|
38
|
+
while (j < sql.length) {
|
|
39
|
+
if (sql[j] === "'" && sql[j + 1] === "'")
|
|
40
|
+
j += 2;
|
|
41
|
+
else if (sql[j] === "'")
|
|
42
|
+
break;
|
|
43
|
+
else
|
|
44
|
+
j += 1;
|
|
45
|
+
}
|
|
46
|
+
i = j + 1;
|
|
47
|
+
out += "''";
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
out += sql[i];
|
|
51
|
+
i += 1;
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
/** Each kind of statement an earlier build's runner cannot run beside: tested on one statement, upper-cased, with its
|
|
56
|
+
* whitespace on one line. */
|
|
57
|
+
const BREAKING = [
|
|
58
|
+
// DROP TABLE, DROP COLUMN, DROP INDEX (an ON CONFLICT of an earlier runner may name it), DROP CONSTRAINT (a unique one
|
|
59
|
+
// too), DROP DEFAULT (an earlier runner's insert may leave the column out). DROP NOT NULL only loosens, and a trigger
|
|
60
|
+
// is the database's own work, which no runner's statement names.
|
|
61
|
+
{ why: "drops what an earlier runner may read or write", test: (s) => /\bDROP\b/.test(s.replace(/\bDROP\s+NOT\s+NULL\b|^DROP\s+TRIGGER\b/g, "")) },
|
|
62
|
+
{ why: "renames what an earlier runner names", test: (s) => /\bRENAME\b/.test(s) },
|
|
63
|
+
{ why: "changes a column's type", test: (s) => /\bALTER\s+(?:COLUMN\s+)?(?:"[^"]+"|\w+)\s+(?:SET\s+DATA\s+)?TYPE\b/.test(s) },
|
|
64
|
+
{ why: "makes a column NOT NULL that an earlier runner may leave empty", test: (s) => /\bSET\s+NOT\s+NULL\b/.test(s) },
|
|
65
|
+
// A primary key makes each of its columns NOT NULL, and is unique besides.
|
|
66
|
+
{ why: "adds a primary key, which makes its columns NOT NULL", test: (s) => /^ALTER\s+TABLE\b/.test(s) && /\bADD\s+(?:CONSTRAINT\s+(?:"[^"]+"|\w+)\s+)?PRIMARY\s+KEY\b/.test(s) },
|
|
67
|
+
{
|
|
68
|
+
why: "adds a NOT NULL column with no default, which an earlier runner's inserts leave out",
|
|
69
|
+
// A column's own PRIMARY KEY makes it NOT NULL as well.
|
|
70
|
+
test: (s) => /^ALTER\s+TABLE\b/.test(s) && addedColumns(s).map(outerWords).map((column) => column.replace(/\bSET\s+DEFAULT\b/g, "")).some((column) => (/\bNOT\s+NULL\b/.test(column) || /\bPRIMARY\s+KEY\b/.test(column)) && !/\bDEFAULT\b/.test(column) && !/\bGENERATED\b/.test(column)),
|
|
71
|
+
},
|
|
72
|
+
];
|
|
73
|
+
/** `clause` with everything inside its parentheses removed, at any depth: a CHECK's `x IS NOT NULL`, however nested, is
|
|
74
|
+
* no NOT NULL of the column's own. */
|
|
75
|
+
function outerWords(clause) {
|
|
76
|
+
let out = "";
|
|
77
|
+
let depth = 0;
|
|
78
|
+
for (const c of clause) {
|
|
79
|
+
if (c === "(")
|
|
80
|
+
depth += 1;
|
|
81
|
+
else if (c === ")")
|
|
82
|
+
depth = Math.max(0, depth - 1);
|
|
83
|
+
else if (depth === 0)
|
|
84
|
+
out += c;
|
|
85
|
+
}
|
|
86
|
+
return out;
|
|
87
|
+
}
|
|
88
|
+
/** Each ADD COLUMN clause of an ALTER TABLE statement, up to the next top-level comma. */
|
|
89
|
+
function addedColumns(statement) {
|
|
90
|
+
const clauses = [];
|
|
91
|
+
let depth = 0;
|
|
92
|
+
let start = 0;
|
|
93
|
+
for (let i = 0; i <= statement.length; i++) {
|
|
94
|
+
const c = statement[i];
|
|
95
|
+
if (c === "(")
|
|
96
|
+
depth += 1;
|
|
97
|
+
else if (c === ")")
|
|
98
|
+
depth -= 1;
|
|
99
|
+
else if ((c === "," && depth === 0) || i === statement.length) {
|
|
100
|
+
clauses.push(statement.slice(start, i));
|
|
101
|
+
start = i + 1;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return clauses.filter((clause) => /\bADD\s+COLUMN\b/.test(clause) || /^\s*ADD\s+(?!CONSTRAINT\b|PRIMARY\b|UNIQUE\b|CHECK\b|FOREIGN\b|EXCLUDE\b)/.test(clause.replace(/^ALTER\s+TABLE\s+(?:IF\s+EXISTS\s+)?(?:ONLY\s+)?\S+\s*/, "")));
|
|
105
|
+
}
|
|
106
|
+
/** The statements of `sql` an earlier build's runner cannot run beside (BREAKING), in their order. */
|
|
107
|
+
export function breakingStatements(sql) {
|
|
108
|
+
const found = [];
|
|
109
|
+
for (const raw of bare(sql).split(";")) {
|
|
110
|
+
const statement = raw.replace(/\s+/g, " ").trim();
|
|
111
|
+
if (statement === "")
|
|
112
|
+
continue;
|
|
113
|
+
const upper = statement.toUpperCase();
|
|
114
|
+
for (const kind of BREAKING)
|
|
115
|
+
if (kind.test(upper))
|
|
116
|
+
found.push({ why: kind.why, statement });
|
|
117
|
+
}
|
|
118
|
+
return found;
|
|
119
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
-- The store's schema on Postgres, version 24: what each runner says of itself and each hand-back, for the server's
|
|
2
|
+
-- capacity read (GET /v2/capacity, capacity.ts), as store/schema.ts keeps them on SQLite (RUNNERS_ADDED, HAND_BACKS).
|
|
3
|
+
-- Applied once, after 0023, inside the transaction migrate.ts opens. Never edit this file once applied: a change is a new
|
|
4
|
+
-- file. Additive: a runner of an earlier build that is already running writes its row as before, its version and slots
|
|
5
|
+
-- read as unknown (null). A runner of an earlier build that starts after this file is applied refuses the store
|
|
6
|
+
-- (openPostgresStore: the schema is newer than it knows), so Postgres runners are upgraded with the server.
|
|
7
|
+
--
|
|
8
|
+
-- runners.version: the runner's build (the serve package's version); null on a row an earlier build wrote.
|
|
9
|
+
-- runners.slots: the most runs the runner holds at once (its loops); null on a row an earlier build wrote.
|
|
10
|
+
-- hand_backs: one row per release that left its run running (a runner's drain, a loop that closed itself, a claim given
|
|
11
|
+
-- back): the run, the runner that let it go, the epoch it let go of and when, on the database's clock. Counts and ids only,
|
|
12
|
+
-- kept 24 hours (the release that writes one removes the older rows), indexed by time (the window, the prune) and by
|
|
13
|
+
-- run (a run's purge and delete). Each piece is made only where missing, so a store
|
|
14
|
+
-- whose record of this file was lost applies it again unharmed.
|
|
15
|
+
|
|
16
|
+
ALTER TABLE runners ADD COLUMN IF NOT EXISTS version TEXT COLLATE "C";
|
|
17
|
+
ALTER TABLE runners ADD COLUMN IF NOT EXISTS slots INTEGER;
|
|
18
|
+
|
|
19
|
+
CREATE TABLE IF NOT EXISTS hand_backs (
|
|
20
|
+
run_id TEXT COLLATE "C" NOT NULL,
|
|
21
|
+
runner TEXT COLLATE "C" NOT NULL,
|
|
22
|
+
epoch BIGINT NOT NULL,
|
|
23
|
+
at BIGINT NOT NULL
|
|
24
|
+
);
|
|
25
|
+
CREATE INDEX IF NOT EXISTS hand_backs_at ON hand_backs (at);
|
|
26
|
+
CREATE INDEX IF NOT EXISTS hand_backs_run ON hand_backs (run_id);
|
|
27
|
+
|
|
28
|
+
UPDATE store_meta SET schema_version = 24 WHERE singleton = 1;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-- The store's schema on Postgres, version 25: each claim of a run, with the turn it works and its attempt at it, as
|
|
2
|
+
-- store/schema.ts keeps it on SQLite (RUN_ATTEMPTS). Applied once, after 0024, inside the transaction migrate.ts opens.
|
|
3
|
+
-- Never edit this file once applied: a change is a new file. Additive: a runner of version 24 never reads it, and a claim
|
|
4
|
+
-- it makes has no row.
|
|
5
|
+
--
|
|
6
|
+
-- run_attempts: one row per claim (run_id, epoch), written in the claim's own transaction: the turn it works and its
|
|
7
|
+
-- attempt at it, why the attempt before was cut (cause: drain, crash, lease_lapse, retry; null on a turn's first), why
|
|
8
|
+
-- this claim let the run go unfinished (cut, written by its release or its runner's lost lease), its runner, the run's
|
|
9
|
+
-- state it took the run from, the first journal entry id it could write and when it claimed. Data only: the usage read
|
|
10
|
+
-- splits a run's cost by it. Made only where missing, so a store whose record of this file was lost applies it again
|
|
11
|
+
-- unharmed.
|
|
12
|
+
|
|
13
|
+
CREATE TABLE IF NOT EXISTS run_attempts (
|
|
14
|
+
run_id TEXT COLLATE "C" NOT NULL,
|
|
15
|
+
epoch BIGINT NOT NULL,
|
|
16
|
+
turn BIGINT NOT NULL CHECK (turn >= 1),
|
|
17
|
+
attempt BIGINT NOT NULL CHECK (attempt >= 1),
|
|
18
|
+
cause TEXT COLLATE "C" CHECK (cause IS NULL OR cause IN ('drain', 'crash', 'lease_lapse', 'retry')),
|
|
19
|
+
cut TEXT COLLATE "C" CHECK (cut IS NULL OR cut IN ('drain', 'lease_lapse', 'retry')),
|
|
20
|
+
runner TEXT COLLATE "C" NOT NULL,
|
|
21
|
+
from_state TEXT COLLATE "C" NOT NULL,
|
|
22
|
+
journal_from BIGINT NOT NULL,
|
|
23
|
+
claimed_at BIGINT NOT NULL,
|
|
24
|
+
PRIMARY KEY (run_id, epoch)
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
UPDATE store_meta SET schema_version = 25 WHERE singleton = 1;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
-- Version 26: a run's disk (runs.disk, as store/schema.ts keeps it on SQLite): the disk the run's launch named as its own
|
|
2
|
+
-- (a customer's Archil disk, by its id), set once with the queued run; null for the default disk's. Learning reads an
|
|
3
|
+
-- agent's runs on one disk alone. Every run already here takes its disk from its launch body, as a new run's is taken at
|
|
4
|
+
-- its create; a run purged before this (0021) has no launch body left, so it reads as the default disk's, with nothing
|
|
5
|
+
-- of it left to learn from. Applied once, after 0025, inside the transaction migrate.ts opens. Never edit this file once
|
|
6
|
+
-- applied: a change is a new file.
|
|
7
|
+
--
|
|
8
|
+
-- The disk is read from a copy of each body that names one, its escaped NULs and surrogates (\u0000, \ud800-\udfff) read
|
|
9
|
+
-- as escaped spaces: Postgres's json functions refuse a whole document over one, and a run's input may hold one. A
|
|
10
|
+
-- replaced escape stays an escape (an escaped backslash before u0000 keeps its own), so the copy is still JSON, and only
|
|
11
|
+
-- the disk's id and kind are read from it (an Archil disk id holds neither).
|
|
12
|
+
ALTER TABLE runs ADD COLUMN IF NOT EXISTS disk TEXT COLLATE "C";
|
|
13
|
+
UPDATE runs SET disk = launch.disk_id
|
|
14
|
+
FROM (
|
|
15
|
+
SELECT run_id, readable #>> '{archil_disk,disk_id}' AS disk_id, readable #>> '{archil_disk,kind}' AS kind
|
|
16
|
+
FROM (
|
|
17
|
+
SELECT run_id, regexp_replace(body, '\\u(0000|[dD][89a-fA-F][0-9a-fA-F]{2})', '\\u0020', 'g')::json AS readable
|
|
18
|
+
FROM run_launch
|
|
19
|
+
WHERE strpos(body, '"archil_disk"') > 0
|
|
20
|
+
) AS bodies
|
|
21
|
+
) AS launch
|
|
22
|
+
WHERE launch.run_id = runs.id AND launch.kind = 'launch';
|
|
23
|
+
UPDATE store_meta SET schema_version = 26 WHERE singleton = 1;
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { type Store, type StoreOwned, type StoreRole } from "../store.js";
|
|
2
|
+
/** How long Store.schemaState waits for the database before it is Unanswered and its connection is dropped (ms): under
|
|
3
|
+
* the runner's 10 s floor read, so a read that hangs never outlasts the next one. */
|
|
4
|
+
export declare const SCHEMA_STATE_MS = 5000;
|
|
2
5
|
/** The schema a store is in when none is named. */
|
|
3
6
|
export declare const DEFAULT_SCHEMA = "agentrun";
|
|
4
7
|
/** How far a runner's clock may be from the database's before it says so at its start (ms). Leases are 30 s, so a gap this
|
|
@@ -42,7 +45,9 @@ export interface PostgresStoreOptions {
|
|
|
42
45
|
readonly onOwnerLost?: (error: StoreOwned) => void;
|
|
43
46
|
}
|
|
44
47
|
/** Opens the store in `schema` on the Postgres at `url`. As the server (the default): takes the owner lock (StoreOwned when
|
|
45
|
-
* another server holds the schema) and applies the pending migrations
|
|
46
|
-
* clock is far from the database's.
|
|
47
|
-
*
|
|
48
|
+
* another server holds the schema) and applies the pending migrations; it refuses a schema a later build migrated
|
|
49
|
+
* (SchemaVersionUnknown). As a runner: sets nothing up, and warns when its clock is far from the database's. It refuses a
|
|
50
|
+
* schema not set up yet (SchemaVersionUnknown) and one this build's server has yet to migrate (StoreAwaitsServer), and
|
|
51
|
+
* opens one a later build migrated while that schema's runner floor is at most this build's version (RunnerBelowFloor
|
|
52
|
+
* past it). The store it answers reads the version and the floor again (Store.schemaState). */
|
|
48
53
|
export declare function openPostgresStore(options: PostgresStoreOptions): Promise<Store>;
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
// The Store on Postgres: the same domain code as SQLite's (sqlite/store.ts storeOver) over a Postgres connection
|
|
2
2
|
// (connection.ts) in the store's own schema (default "agentrun"). The server sets the schema up (migrate.ts) and holds the
|
|
3
|
-
// owner lock, one server per schema; runners are many, set nothing up,
|
|
3
|
+
// owner lock, one server per schema; runners are many, set nothing up, wait for the server on a schema behind them, and
|
|
4
|
+
// run on one ahead of them while its runner floor is at most what they know (migrate.ts runnerFloorOf).
|
|
4
5
|
import { SchemaVersionUnknown, StoreAwaitsServer } from "../store.js";
|
|
5
6
|
import { backfillNativeCommandOwners } from '../native-command-owner.js';
|
|
6
7
|
import { storeOver } from "../sqlite/store.js";
|
|
7
8
|
import { PgConnection, SCHEMA_NAME } from "./connection.js";
|
|
8
|
-
import { migrate, migrationsIn, placeOf, versionOf } from "./migrate.js";
|
|
9
|
+
import { migrate, migrationsIn, placeOf, refuseBelowFloor, runnerFloorOf, versionOf } from "./migrate.js";
|
|
10
|
+
/** How long Store.schemaState waits for the database before it is Unanswered and its connection is dropped (ms): under
|
|
11
|
+
* the runner's 10 s floor read, so a read that hangs never outlasts the next one. */
|
|
12
|
+
export const SCHEMA_STATE_MS = 5_000;
|
|
9
13
|
/** The schema a store is in when none is named. */
|
|
10
14
|
export const DEFAULT_SCHEMA = "agentrun";
|
|
11
15
|
/** How far a runner's clock may be from the database's before it says so at its start (ms). Leases are 30 s, so a gap this
|
|
@@ -13,9 +17,11 @@ export const DEFAULT_SCHEMA = "agentrun";
|
|
|
13
17
|
export const CLOCK_WARN_MS = 2_000;
|
|
14
18
|
export { postgresWhere } from "./connection.js";
|
|
15
19
|
/** Opens the store in `schema` on the Postgres at `url`. As the server (the default): takes the owner lock (StoreOwned when
|
|
16
|
-
* another server holds the schema) and applies the pending migrations
|
|
17
|
-
* clock is far from the database's.
|
|
18
|
-
*
|
|
20
|
+
* another server holds the schema) and applies the pending migrations; it refuses a schema a later build migrated
|
|
21
|
+
* (SchemaVersionUnknown). As a runner: sets nothing up, and warns when its clock is far from the database's. It refuses a
|
|
22
|
+
* schema not set up yet (SchemaVersionUnknown) and one this build's server has yet to migrate (StoreAwaitsServer), and
|
|
23
|
+
* opens one a later build migrated while that schema's runner floor is at most this build's version (RunnerBelowFloor
|
|
24
|
+
* past it). The store it answers reads the version and the floor again (Store.schemaState). */
|
|
19
25
|
export async function openPostgresStore(options) {
|
|
20
26
|
const schema = options.schema ?? DEFAULT_SCHEMA;
|
|
21
27
|
if (!SCHEMA_NAME.test(schema))
|
|
@@ -41,11 +47,21 @@ export async function openPostgresStore(options) {
|
|
|
41
47
|
},
|
|
42
48
|
});
|
|
43
49
|
try {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
50
|
+
if (role === "server") {
|
|
51
|
+
const found = await connection.withClient((client) => migrate(client, schema, now(), migrations));
|
|
52
|
+
if (found !== known)
|
|
53
|
+
throw new SchemaVersionUnknown(placeOf(schema), found, known);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const state = await connection.withClient((client) => runnerFloorOf(client, schema));
|
|
57
|
+
const found = state.version;
|
|
58
|
+
if (found !== null && found < known)
|
|
59
|
+
throw new StoreAwaitsServer(`bring this store from version ${found} to ${known}`);
|
|
60
|
+
if (found === null)
|
|
61
|
+
throw new SchemaVersionUnknown(placeOf(schema), found, known);
|
|
62
|
+
// Ahead of this build: additive migrations leave the floor where it was, and this runner runs on them.
|
|
63
|
+
refuseBelowFloor(schema, state, known);
|
|
64
|
+
}
|
|
49
65
|
if (role === "server")
|
|
50
66
|
await backfillNativeCommandOwners(connection);
|
|
51
67
|
if (role === "runner" && options.warn) {
|
|
@@ -59,5 +75,9 @@ export async function openPostgresStore(options) {
|
|
|
59
75
|
await connection.close().catch(() => undefined);
|
|
60
76
|
throw error;
|
|
61
77
|
}
|
|
62
|
-
|
|
78
|
+
const store = storeOver(connection, now);
|
|
79
|
+
// Bounded: a runner reads it on a timer, and a database that stops answering must neither hold that timer's read for good
|
|
80
|
+
// nor the store's close, which waits for every call in flight.
|
|
81
|
+
const schemaState = async () => ({ ...(await connection.withClient((client) => runnerFloorOf(client, schema), SCHEMA_STATE_MS)), known });
|
|
82
|
+
return Object.assign(store, { schemaState });
|
|
63
83
|
}
|
package/dist/store/schema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const SCHEMA_VERSION =
|
|
1
|
+
export declare const SCHEMA_VERSION = 15;
|
|
2
2
|
/** One answer per approval of a run: a second approve or deny command naming the same approval is refused
|
|
3
3
|
* (StoreConstraint), so the first answer a person gives wins from the moment it is written, before the runner takes it
|
|
4
4
|
* (runs-over-store.ts approve). In STORE_DDL, and added at a server open to a store an earlier build of this version made. */
|
|
@@ -19,6 +19,11 @@ export declare const RUNS_COST_UPPER_BOUND = "ALTER TABLE runs ADD COLUMN cost_u
|
|
|
19
19
|
/** A run's labels (JSON, null for none): in STORE_DDL, and added at a server open to a store an earlier build of this version
|
|
20
20
|
* made, as RUNS_COST_UPPER_BOUND is (a run started before reads as given none). */
|
|
21
21
|
export declare const RUNS_LABELS: string;
|
|
22
|
+
/** Version 14 → 15 on SQLite (the server's open, sqlite/store.ts), given the runs' columns now: each run's disk
|
|
23
|
+
* (RunRow.disk), written for every run already there from its launch body, as a new run's is at its create, and the
|
|
24
|
+
* version, in one durable write. A run whose launch named no disk of its own reads as the default disk's, and so does a
|
|
25
|
+
* run purged before (its launch body gone): nothing of it is left to learn from. */
|
|
26
|
+
export declare function diskUpgrade(runColumns: ReadonlySet<string>): readonly string[];
|
|
22
27
|
/** A trigger's package mark (TriggerRow.templateId): the id of the template package whose apply made or last kept it, null
|
|
23
28
|
* for one a person made. In STORE_DDL, and added at a server open to a store an earlier build of this version made, as
|
|
24
29
|
* RUNS_LABELS is (a trigger made before reads as no package's). */
|
|
@@ -65,7 +70,32 @@ export declare const COMPUTER_INTERVALS_RUN = "CREATE INDEX IF NOT EXISTS comput
|
|
|
65
70
|
* STORE_DDL. A store an earlier build of version 13 made kept the relays in a table of their own (runner_relays): the
|
|
66
71
|
* server's open drops it and makes this one (sqlite/store.ts), as it drops browser_viewers, with no version: the rows
|
|
67
72
|
* are heartbeats renewed every 10 s, so none is copied, and a runner waits for that server (StoreAwaitsServer). */
|
|
68
|
-
export declare const RUNNERS = "CREATE TABLE IF NOT EXISTS runners (\n runner TEXT PRIMARY KEY,\n incarnation TEXT NOT NULL,\n refused TEXT,\n host TEXT,\n port INTEGER,\n seen_at INTEGER NOT NULL\n ) STRICT";
|
|
73
|
+
export declare const RUNNERS = "CREATE TABLE IF NOT EXISTS runners (\n runner TEXT PRIMARY KEY,\n incarnation TEXT NOT NULL,\n refused TEXT,\n host TEXT,\n port INTEGER,\n seen_at INTEGER NOT NULL,\n version TEXT,\n slots INTEGER\n ) STRICT";
|
|
74
|
+
/** What a runner says of itself for the server's capacity read (GET /v2/capacity, capacity.ts): its build's version
|
|
75
|
+
* (`version`) and the most runs it holds at once (`slots`), each null on a row an earlier build wrote. In RUNNERS, and
|
|
76
|
+
* added where missing at a server open to a runners table an earlier build of this version made, as
|
|
77
|
+
* COMPUTER_INTERVALS_ADDED is: nullable, so nothing is copied and no row is refused. */
|
|
78
|
+
export declare const RUNNERS_ADDED: Readonly<Record<string, string>>;
|
|
79
|
+
/** Each hand-back (store.release that leaves its run running: a runner's drain, a loop that closed itself, a claim given
|
|
80
|
+
* back): the run, the runner that let it go, the epoch it let go of and when, on the deadlines' clock. Counts and ids
|
|
81
|
+
* only; the capacity read (capacity.ts) counts the rows within its window. A release's own write keeps it, in the same
|
|
82
|
+
* transaction, and removes the rows older than HAND_BACKS_KEPT_MS. In STORE_DDL, and made at a server open on a store an
|
|
83
|
+
* earlier build of this version made. */
|
|
84
|
+
export declare const HAND_BACKS = "CREATE TABLE IF NOT EXISTS hand_backs (\n run_id TEXT NOT NULL,\n runner TEXT NOT NULL,\n epoch INTEGER NOT NULL,\n at INTEGER NOT NULL\n ) STRICT";
|
|
85
|
+
/** The hand-backs by time, for the capacity read's window and the release's prune. */
|
|
86
|
+
export declare const HAND_BACKS_AT = "CREATE INDEX IF NOT EXISTS hand_backs_at ON hand_backs (at)";
|
|
87
|
+
/** A run's hand-backs, for its purge and its delete (dropRunContent), so neither scans every hand-back kept. */
|
|
88
|
+
export declare const HAND_BACKS_RUN = "CREATE INDEX IF NOT EXISTS hand_backs_run ON hand_backs (run_id)";
|
|
89
|
+
/** How long a hand-back's row is kept: the longest window the capacity read takes. */
|
|
90
|
+
export declare const HAND_BACKS_KEPT_MS: number;
|
|
91
|
+
/** Each claim of a run (store.runAttempts, RunAttemptRow): the turn it works and its attempt at it, why the attempt before
|
|
92
|
+
* was cut (`cause`: drain, crash, lease_lapse, retry; null on a turn's first), why this one let the run go unfinished
|
|
93
|
+
* (`cut`), its runner, the run's state it took the run from, the first journal entry id it could write
|
|
94
|
+
* (`journal_from`) and when it claimed. Written in the claim's own transaction, its cut in its release's. Data only:
|
|
95
|
+
* the usage read (run-usage.ts) splits a run's cost by it, and nothing decides what a run does on it. In STORE_DDL, and
|
|
96
|
+
* added at a server open to a store an earlier build of this version made, as COMPUTER_INTERVALS is: a claim made before
|
|
97
|
+
* it has no row. */
|
|
98
|
+
export declare const RUN_ATTEMPTS = "CREATE TABLE IF NOT EXISTS run_attempts (\n run_id TEXT NOT NULL,\n epoch INTEGER NOT NULL,\n turn INTEGER NOT NULL CHECK (turn >= 1),\n attempt INTEGER NOT NULL CHECK (attempt >= 1),\n cause TEXT CHECK (cause IS NULL OR cause IN ('drain', 'crash', 'lease_lapse', 'retry')),\n cut TEXT CHECK (cut IS NULL OR cut IN ('drain', 'lease_lapse', 'retry')),\n runner TEXT NOT NULL,\n from_state TEXT NOT NULL,\n journal_from INTEGER NOT NULL,\n claimed_at INTEGER NOT NULL,\n PRIMARY KEY (run_id, epoch)\n ) STRICT";
|
|
69
99
|
/** Version 13 → 14 on SQLite (the server's open, sqlite/store.ts), given the runs' and the agents' columns now: when each
|
|
70
100
|
* run and each agent was purged (null: none was), and the version, in one durable write. */
|
|
71
101
|
export declare function purgeUpgrade(runColumns: ReadonlySet<string>, agentColumns: ReadonlySet<string>): readonly string[];
|
package/dist/store/schema.js
CHANGED
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
// else reads, so it needs no version: the server adds it at its open to a store an earlier build of this version made
|
|
20
20
|
// (IMPORTED_TEMPLATES), as it does the one-answer index. A hosted machine's minted token (minted_tokens, MINTED_TOKENS) is
|
|
21
21
|
// added the same way, and so is each runner's word that it is there and whether it refused to claim (runners, RUNNERS),
|
|
22
|
-
// and each computer a run made, from its create to its proven delete (computer_intervals, COMPUTER_INTERVALS).
|
|
22
|
+
// and each computer a run made, from its create to its proven delete (computer_intervals, COMPUTER_INTERVALS). Each runner's
|
|
23
|
+
// version and slots (runners.version, .slots: RUNNERS_ADDED), each hand-back (hand_backs, HAND_BACKS) and each claim of a
|
|
24
|
+
// run with the turn it works and its attempt at it (run_attempts, RUN_ATTEMPTS) are added the same way.
|
|
23
25
|
// Conventions: every time is INTEGER epoch milliseconds; JSON is TEXT checked by json_valid; money is REAL US dollars;
|
|
24
26
|
// sealed columns hold ciphertext only (sealed with the server's key outside the store), so the store never sees a secret
|
|
25
27
|
// in the clear. Foreign keys are on (the connection's pragma).
|
|
@@ -35,9 +37,10 @@
|
|
|
35
37
|
// .incarnation), the run the machine works for (.run), why the server refused to relay its dial (.refused), and where each
|
|
36
38
|
// such runner takes the dials the server relays to it (runners.host and .port, dial-relay.ts). Version 14 keeps when a run or
|
|
37
39
|
// an agent was purged (runs.purged_at, agents.purged_at; DELETE /runs/{id} and /agents/{id}, agent-delete.ts): its row is
|
|
38
|
-
// then a tombstone, its content gone and its cost kept.
|
|
39
|
-
//
|
|
40
|
-
|
|
40
|
+
// then a tombstone, its content gone and its cost kept. Version 15 keeps the disk a run's launch named as its own
|
|
41
|
+
// (runs.disk; a run on one learns nothing, learn/learning-of.ts). The server upgrades these in place at its open
|
|
42
|
+
// (listingUpgrade from 11, relayUpgrade from 12, purgeUpgrade from 13, then diskUpgrade from 14); a runner waits for it.
|
|
43
|
+
export const SCHEMA_VERSION = 15;
|
|
41
44
|
/** One answer per approval of a run: a second approve or deny command naming the same approval is refused
|
|
42
45
|
* (StoreConstraint), so the first answer a person gives wins from the moment it is written, before the runner takes it
|
|
43
46
|
* (runs-over-store.ts approve). In STORE_DDL, and added at a server open to a store an earlier build of this version made. */
|
|
@@ -63,6 +66,17 @@ export const RUNS_COST_UPPER_BOUND = `ALTER TABLE runs ADD COLUMN ${COST_UPPER_B
|
|
|
63
66
|
/** A run's labels (JSON, null for none): in STORE_DDL, and added at a server open to a store an earlier build of this version
|
|
64
67
|
* made, as RUNS_COST_UPPER_BOUND is (a run started before reads as given none). */
|
|
65
68
|
export const RUNS_LABELS = `ALTER TABLE runs ADD COLUMN ${json("labels", true)}`;
|
|
69
|
+
/** Version 14 → 15 on SQLite (the server's open, sqlite/store.ts), given the runs' columns now: each run's disk
|
|
70
|
+
* (RunRow.disk), written for every run already there from its launch body, as a new run's is at its create, and the
|
|
71
|
+
* version, in one durable write. A run whose launch named no disk of its own reads as the default disk's, and so does a
|
|
72
|
+
* run purged before (its launch body gone): nothing of it is left to learn from. */
|
|
73
|
+
export function diskUpgrade(runColumns) {
|
|
74
|
+
return [
|
|
75
|
+
...(runColumns.has("disk") ? [] : ["ALTER TABLE runs ADD COLUMN disk TEXT"]),
|
|
76
|
+
"UPDATE runs SET disk = (SELECT json_extract(body, '$.archil_disk.disk_id') FROM run_launch WHERE run_launch.run_id = runs.id AND json_extract(body, '$.archil_disk.kind') = 'launch')",
|
|
77
|
+
"UPDATE store_meta SET schema_version = 15 WHERE singleton = 1",
|
|
78
|
+
];
|
|
79
|
+
}
|
|
66
80
|
/** A trigger's package mark (TriggerRow.templateId): the id of the template package whose apply made or last kept it, null
|
|
67
81
|
* for one a person made. In STORE_DDL, and added at a server open to a store an earlier build of this version made, as
|
|
68
82
|
* RUNS_LABELS is (a trigger made before reads as no package's). */
|
|
@@ -153,7 +167,54 @@ export const RUNNERS = `CREATE TABLE IF NOT EXISTS runners (
|
|
|
153
167
|
refused TEXT,
|
|
154
168
|
host TEXT,
|
|
155
169
|
port INTEGER,
|
|
156
|
-
seen_at INTEGER NOT NULL
|
|
170
|
+
seen_at INTEGER NOT NULL,
|
|
171
|
+
version TEXT,
|
|
172
|
+
slots INTEGER
|
|
173
|
+
) STRICT`;
|
|
174
|
+
/** What a runner says of itself for the server's capacity read (GET /v2/capacity, capacity.ts): its build's version
|
|
175
|
+
* (`version`) and the most runs it holds at once (`slots`), each null on a row an earlier build wrote. In RUNNERS, and
|
|
176
|
+
* added where missing at a server open to a runners table an earlier build of this version made, as
|
|
177
|
+
* COMPUTER_INTERVALS_ADDED is: nullable, so nothing is copied and no row is refused. */
|
|
178
|
+
export const RUNNERS_ADDED = {
|
|
179
|
+
version: "ALTER TABLE runners ADD COLUMN version TEXT",
|
|
180
|
+
slots: "ALTER TABLE runners ADD COLUMN slots INTEGER",
|
|
181
|
+
};
|
|
182
|
+
/** Each hand-back (store.release that leaves its run running: a runner's drain, a loop that closed itself, a claim given
|
|
183
|
+
* back): the run, the runner that let it go, the epoch it let go of and when, on the deadlines' clock. Counts and ids
|
|
184
|
+
* only; the capacity read (capacity.ts) counts the rows within its window. A release's own write keeps it, in the same
|
|
185
|
+
* transaction, and removes the rows older than HAND_BACKS_KEPT_MS. In STORE_DDL, and made at a server open on a store an
|
|
186
|
+
* earlier build of this version made. */
|
|
187
|
+
export const HAND_BACKS = `CREATE TABLE IF NOT EXISTS hand_backs (
|
|
188
|
+
run_id TEXT NOT NULL,
|
|
189
|
+
runner TEXT NOT NULL,
|
|
190
|
+
epoch INTEGER NOT NULL,
|
|
191
|
+
at INTEGER NOT NULL
|
|
192
|
+
) STRICT`;
|
|
193
|
+
/** The hand-backs by time, for the capacity read's window and the release's prune. */
|
|
194
|
+
export const HAND_BACKS_AT = "CREATE INDEX IF NOT EXISTS hand_backs_at ON hand_backs (at)";
|
|
195
|
+
/** A run's hand-backs, for its purge and its delete (dropRunContent), so neither scans every hand-back kept. */
|
|
196
|
+
export const HAND_BACKS_RUN = "CREATE INDEX IF NOT EXISTS hand_backs_run ON hand_backs (run_id)";
|
|
197
|
+
/** How long a hand-back's row is kept: the longest window the capacity read takes. */
|
|
198
|
+
export const HAND_BACKS_KEPT_MS = 24 * 60 * 60_000;
|
|
199
|
+
/** Each claim of a run (store.runAttempts, RunAttemptRow): the turn it works and its attempt at it, why the attempt before
|
|
200
|
+
* was cut (`cause`: drain, crash, lease_lapse, retry; null on a turn's first), why this one let the run go unfinished
|
|
201
|
+
* (`cut`), its runner, the run's state it took the run from, the first journal entry id it could write
|
|
202
|
+
* (`journal_from`) and when it claimed. Written in the claim's own transaction, its cut in its release's. Data only:
|
|
203
|
+
* the usage read (run-usage.ts) splits a run's cost by it, and nothing decides what a run does on it. In STORE_DDL, and
|
|
204
|
+
* added at a server open to a store an earlier build of this version made, as COMPUTER_INTERVALS is: a claim made before
|
|
205
|
+
* it has no row. */
|
|
206
|
+
export const RUN_ATTEMPTS = `CREATE TABLE IF NOT EXISTS run_attempts (
|
|
207
|
+
run_id TEXT NOT NULL,
|
|
208
|
+
epoch INTEGER NOT NULL,
|
|
209
|
+
turn INTEGER NOT NULL CHECK (turn >= 1),
|
|
210
|
+
attempt INTEGER NOT NULL CHECK (attempt >= 1),
|
|
211
|
+
cause TEXT CHECK (cause IS NULL OR cause IN ('drain', 'crash', 'lease_lapse', 'retry')),
|
|
212
|
+
cut TEXT CHECK (cut IS NULL OR cut IN ('drain', 'lease_lapse', 'retry')),
|
|
213
|
+
runner TEXT NOT NULL,
|
|
214
|
+
from_state TEXT NOT NULL,
|
|
215
|
+
journal_from INTEGER NOT NULL,
|
|
216
|
+
claimed_at INTEGER NOT NULL,
|
|
217
|
+
PRIMARY KEY (run_id, epoch)
|
|
157
218
|
) STRICT`;
|
|
158
219
|
/** Version 13 → 14 on SQLite (the server's open, sqlite/store.ts), given the runs' and the agents' columns now: when each
|
|
159
220
|
* run and each agent was purged (null: none was), and the version, in one durable write. */
|
|
@@ -352,6 +413,10 @@ export const STORE_DDL = [
|
|
|
352
413
|
-- server and only filtered on (runs.list). Null when it was given none. Added at a server open to a store an earlier
|
|
353
414
|
-- build of this version made (RUNS_LABELS), its runs reading as given none.
|
|
354
415
|
${json("labels", true)},
|
|
416
|
+
-- The disk the run's launch named as its own (RunRow.disk: a customer's Archil disk, by its id), set once with the queued
|
|
417
|
+
-- run from its launch body; null for the default disk's. Learning reads an agent's runs on one disk alone. Version 15
|
|
418
|
+
-- (diskUpgrade): added then and written from each run's launch. A purge keeps it on the run's tombstone.
|
|
419
|
+
disk TEXT,
|
|
355
420
|
started_at INTEGER NOT NULL,
|
|
356
421
|
ended_at INTEGER,
|
|
357
422
|
-- The run's listing (RUN_LISTING_COLUMNS): what a runs list shows of it, kept on its row so a list reads rows alone.
|
|
@@ -601,8 +666,12 @@ export const STORE_DDL = [
|
|
|
601
666
|
IMPORTED_TEMPLATES,
|
|
602
667
|
MINTED_TOKENS,
|
|
603
668
|
RUNNERS,
|
|
669
|
+
HAND_BACKS,
|
|
670
|
+
HAND_BACKS_AT,
|
|
671
|
+
HAND_BACKS_RUN,
|
|
604
672
|
COMPUTER_INTERVALS,
|
|
605
673
|
COMPUTER_INTERVALS_RUN,
|
|
674
|
+
RUN_ATTEMPTS,
|
|
606
675
|
// An agent's saved browser sign-ins (design 2.1, the browser sign-in rules): one live row per agent and browser provider, its
|
|
607
676
|
// pointer (the vendor's context or profile id) sealed with the store's one rule (store/seal.ts, AAD
|
|
608
677
|
// sign_ins|<agent>:<provider>|pointer), which the store never opens. The owner sees its name ("default") and saved_at,
|
|
@@ -1,15 +1,40 @@
|
|
|
1
|
-
import { type LaunchSealed, type RunLaunchInput, type RunLaunchRow } from "../store.js";
|
|
1
|
+
import { type LaunchSealed, type RunLaunchInput, type RunLaunchRow, type Runs } from "../store.js";
|
|
2
2
|
import type { Dialect } from "../dialect.js";
|
|
3
3
|
import type { SqliteExecutor } from "./connection.js";
|
|
4
|
+
export { postgresReadableJson, postgresUnicodeRefusal };
|
|
5
|
+
/** JSON text `column` as a read of one id or flag out of it inside a transaction takes it, where a refused statement
|
|
6
|
+
* aborts the transaction and can't be read again: on Postgres its copy with those escapes blanked (postgresReadableJson),
|
|
7
|
+
* on SQLite (whose json functions read them) the column itself. */
|
|
8
|
+
export declare const readableJson: (dialect: Dialect, column: string) => string;
|
|
4
9
|
/** Writes a run's launch row inside `tx` (the same transaction as the queued run it belongs to): the run path and the
|
|
5
10
|
* trigger path both call it, so the row lands with its run or not at all. */
|
|
6
11
|
export declare function writeLaunch(tx: Pick<SqliteExecutor, "run">, runId: string, launch: RunLaunchInput, at: number): Promise<void>;
|
|
12
|
+
/** The disk a launch body names as the run's own (runs.disk, RunRow.disk): its `archil_disk` of kind "launch", by its id
|
|
13
|
+
* (run-launch.ts launchBody writes it so); null for none, or its agent's own disk (the default disk). The one read of the
|
|
14
|
+
* body's disk the store makes, at every create of a run, so no path that queues a run can leave it out. */
|
|
15
|
+
export declare function launchDiskOf(launch: RunLaunchInput | undefined): string | null;
|
|
7
16
|
/** A message's launch secrets written over the run's (runs.command, runs.reopen), inside `tx`: the bytes as given, or a
|
|
8
17
|
* function's answer to the bytes the launch holds now, read in the same transaction. */
|
|
9
18
|
export declare function writeLaunchSealed(tx: Pick<SqliteExecutor, "run" | "get">, runId: string, launchSealed: LaunchSealed): Promise<void>;
|
|
10
19
|
/** The run's launch row, read by the runner at its claim (and the server for views). StoreLaunchMissing when the run has
|
|
11
20
|
* none, never a default. */
|
|
12
21
|
export declare function readLaunch(executor: Pick<SqliteExecutor, "get">, runId: string): Promise<RunLaunchRow>;
|
|
22
|
+
/** Whether `error` (or a cause of it, six deep) is Postgres refusing a JSON document for an escaped NUL or a lone
|
|
23
|
+
* surrogate in it: the text type keeps them, but every json function decodes the whole document's strings. */
|
|
24
|
+
declare function postgresUnicodeRefusal(error: unknown): boolean;
|
|
25
|
+
/** Postgres SQL for JSON text `column` with its escaped NULs and surrogates (\u0000, \ud800-\udfff) read as escaped
|
|
26
|
+
* spaces, for a read of one number or id out of a document whose other strings may hold one (0026_run_disk.sql blanks
|
|
27
|
+
* them for its backfill). A replaced escape stays an escape, so it is still JSON. Only an escape is replaced: u0000 after
|
|
28
|
+
* an escaped backslash (the text \u0000 in an id, written \\u0000) is text and is kept, so an id reads as it is. */
|
|
29
|
+
declare const postgresReadableJson: (column: string) => string;
|
|
30
|
+
/** Project accounting facts before crossing the database boundary. An SDK inbox can contain megabytes of replay;
|
|
31
|
+
* the raw-JSON projection preserves strings, nulls and invalid scalar shapes equally on SQLite and Postgres.
|
|
32
|
+
* Uses an ordinary store connection: a PostgreSQL Unicode refusal is retried outside a failed transaction. */
|
|
33
|
+
export declare function readUsageMetadata(executor: Pick<SqliteExecutor, "get"> & {
|
|
34
|
+
readonly dialect: Dialect;
|
|
35
|
+
}, runId: string, { completion }: {
|
|
36
|
+
completion: boolean;
|
|
37
|
+
}): ReturnType<Runs["usageMetadata"]>;
|
|
13
38
|
/** The learning start of every run of agent `agentId` that `where` (a condition on runs' columns) keeps, in one read: only
|
|
14
39
|
* the body's `learning` member (the notes a run was given, its seed, its # Learned section), never the rest of the body
|
|
15
40
|
* and never the sealed bytes, so an agent with thousands of runs reads kilobytes a run, not each run's input. `learning`
|
|
@@ -20,3 +45,8 @@ export declare function readLearningStarts(executor: Pick<SqliteExecutor, "all">
|
|
|
20
45
|
runId: string;
|
|
21
46
|
learning: unknown;
|
|
22
47
|
}[]>;
|
|
48
|
+
/** The ids of agent `agentId`'s runs started after `at` whose learning seed was read at or before it (the launch body's
|
|
49
|
+
* `learning.seededAt`), in one read of that one number a run started after `at`: never a run's section or input. */
|
|
50
|
+
export declare function readSeededBefore(executor: Pick<SqliteExecutor, "all"> & {
|
|
51
|
+
readonly dialect: Dialect;
|
|
52
|
+
}, agentId: string, at: number): Promise<string[]>;
|