@parcha/agentrun-serve 0.1.0-beta.48 → 0.1.0-beta.49
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 +20 -0
- package/README.md +144 -16
- package/dist/agent-delete.d.ts +33 -10
- package/dist/agent-delete.js +184 -26
- package/dist/agents-store.d.ts +6 -2
- package/dist/agents-store.js +18 -5
- package/dist/agents.d.ts +8 -1
- package/dist/agents.js +14 -4
- package/dist/answer-json.d.ts +2 -2
- package/dist/answer-json.js +3 -4
- package/dist/archil-routes.d.ts +1 -1
- package/dist/archil-routes.js +4 -3
- package/dist/browser-sessions.d.ts +56 -0
- package/dist/browser-sessions.js +117 -0
- package/dist/computer-routes.d.ts +4 -15
- package/dist/computer-routes.js +6 -10
- package/dist/console/assets/index-Bzn4eUYF.js +715 -0
- package/dist/console/assets/index-CR2ZGei1.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/errors.d.ts +4 -1
- package/dist/errors.js +15 -5
- package/dist/import.js +4 -3
- package/dist/learn/check.d.ts +11 -2
- package/dist/learn/check.js +12 -9
- package/dist/learn/promote.d.ts +7 -1
- package/dist/learn/promote.js +47 -0
- package/dist/learn/repick.d.ts +34 -0
- package/dist/learn/repick.js +201 -0
- package/dist/learned-workflow.d.ts +2 -0
- package/dist/learned-workflow.js +18 -1
- package/dist/learning-setting.d.ts +13 -0
- package/dist/learning-setting.js +23 -1
- package/dist/llms.txt +1 -1
- package/dist/openapi.js +170 -12
- package/dist/paid-calls.d.ts +4 -1
- package/dist/paid-calls.js +1 -1
- package/dist/run-learning-served.d.ts +1 -1
- package/dist/run-usage.d.ts +110 -0
- package/dist/run-usage.js +312 -0
- package/dist/runner/adapter-loop.js +51 -20
- package/dist/runner/conformance/harness.d.ts +2 -0
- package/dist/runner/conformance/harness.js +18 -4
- package/dist/runner/feedback-round.d.ts +29 -1
- package/dist/runner/feedback-round.js +54 -3
- package/dist/runner/journal-kinds.d.ts +3 -1
- package/dist/runner/learning-end.js +49 -18
- package/dist/runner/loop-contract.d.ts +3 -0
- package/dist/runner/monid-run.js +2 -2
- package/dist/runner/promotion.js +8 -2
- package/dist/runner/reflect-hook.js +3 -2
- package/dist/runs-over-store.d.ts +3 -2
- package/dist/runs-over-store.js +9 -7
- package/dist/server.d.ts +3 -3
- package/dist/server.js +221 -98
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/journal/storage.js +1 -1
- package/dist/store/open.d.ts +1 -1
- package/dist/store/open.js +1 -1
- package/dist/store/postgres/migrations/0021_purged.sql +13 -0
- package/dist/store/postgres/migrations/0022_computer_intervals.sql +27 -0
- package/dist/store/schema.d.ts +15 -1
- package/dist/store/schema.js +50 -5
- package/dist/store/sqlite/connection.d.ts +4 -1
- package/dist/store/sqlite/connection.js +5 -0
- package/dist/store/sqlite/run-patch.d.ts +8 -3
- package/dist/store/sqlite/run-patch.js +15 -7
- package/dist/store/sqlite/store.d.ts +5 -2
- package/dist/store/sqlite/store.js +249 -48
- package/dist/store/sqlite/worker.d.ts +9 -0
- package/dist/store/sqlite/worker.js +18 -1
- package/dist/store/store.d.ts +142 -9
- package/dist/store/store.js +63 -0
- package/dist/store-reads/analytics.js +2 -1
- package/dist/store-reads/cap.d.ts +8 -2
- package/dist/store-reads/cap.js +27 -3
- package/dist/store-reads/learning.d.ts +1 -1
- package/dist/store-reads/learning.js +5 -2
- package/dist/store-reads/runs.js +2 -0
- package/dist/store-reads/stats.js +4 -2
- package/dist/store-view.d.ts +7 -0
- package/dist/store-view.js +61 -20
- package/dist/tools.js +9 -0
- package/dist/trigger-targets.d.ts +7 -4
- package/dist/trigger-targets.js +6 -6
- package/dist/triggers.d.ts +2 -1
- package/dist/triggers.js +5 -2
- package/dist/validate.d.ts +4 -2
- package/dist/validate.js +13 -3
- package/dist/viewer-credential.d.ts +3 -4
- package/dist/viewer-credential.js +6 -4
- package/dist/workspace/computer-for-claim.d.ts +5 -1
- package/dist/workspace/computer-for-claim.js +47 -18
- package/dist/workspace/computer-intervals.d.ts +20 -0
- package/dist/workspace/computer-intervals.js +49 -0
- package/dist/workspace/computer-janitor.d.ts +7 -3
- package/dist/workspace/computer-janitor.js +14 -6
- package/dist/workspace/computer-kept.d.ts +7 -2
- package/dist/workspace/computer-kept.js +9 -2
- package/dist/workspace/resolve-computer.d.ts +7 -4
- package/dist/workspace/resolve-computer.js +21 -32
- package/dist/workspace/run-end-computers.d.ts +1 -0
- package/dist/workspace/run-end-computers.js +4 -1
- package/package.json +10 -10
- package/dist/console/assets/index-CTGegcKt.css +0 -1
- package/dist/console/assets/index-D1Se6mgG.js +0 -715
package/dist/store/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export { AgentArchived, AgentDeleting, AnswerTaken, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreAwaitsServer, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, stoppedByPerson, TriggerFull, TriggersLeft } from "./store.js";
|
|
2
|
-
export type { ConstraintRule, AgentRow, Agents, AlsoRow, ChannelPost, Claim, Command, ComputerLedger, ComputerLedgerRow, Firing, FiringChange, FiringRow, FiringStatus, FiringStreak, Journal, Live, LiveRow, Mcp, McpCredentialMark, McpRemoved, McpOauth, McpOauthPendingRow, McpPinRow, McpServerRow, McpServerStamp, McpServerWrite, MintedTokenRow, MintedTokens, NewFiring, NewPairedComputer, NewRevision, NewTrigger, PairedComputerRow, PairedComputers, ReleasedState, RevisionRow, RunnerRow, Runners, RunPatch, RunRow, Runs, RunState, SealedKeyRow, SealedKeys, SealedPlane, SealedSecretRow, SealedSecrets, SettingRow, Settings, Staged, StagedTake, Store, StoreRole, TemplatePackage, Templates, TriggerDef, TriggerPatch, TriggerRow, Triggers, TriggerScope, TriggerSettingRow, TriggerSettings, Channels, ChannelAttemptRow, ChannelPostRow, ChannelToldRow, ImportedFrom, ImportSource, ImportRunInput, JournalReads, RunLabels, RunOrigin, RunOutcome, RunLaunchInput, RunLaunchRow, LaunchSealed, LaunchSealedWrite, Learning, LearningProposal, LiveViewerRow, LiveViewers, SignIns, SignInRow, SignInTombstoneRow, UpdatedRun, ViewerKind, } from "./store.js";
|
|
1
|
+
export { AgentArchived, AgentDeleting, AgentPurged, AnswerTaken, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, RunPurged, RunsMadeFromLeft, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreAwaitsServer, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, stoppedByPerson, TriggerFull, TriggersLeft } from "./store.js";
|
|
2
|
+
export type { ConstraintRule, AgentRow, Agents, AlsoRow, ChannelPost, Claim, Command, ComputerIntervalRow, ComputerIntervals, ComputerLedger, ComputerLedgerRow, Firing, FiringChange, FiringRow, FiringStatus, FiringStreak, Journal, Live, LiveRow, Mcp, McpCredentialMark, McpRemoved, McpOauth, McpOauthPendingRow, McpPinRow, McpServerRow, McpServerStamp, McpServerWrite, MintedTokenRow, MintedTokens, NewFiring, NewPairedComputer, NewRevision, NewTrigger, PairedComputerRow, PairedComputers, ReleasedState, RevisionRow, RunnerRow, Runners, RunPatch, RunRow, Runs, RunState, SealedKeyRow, SealedKeys, SealedPlane, SealedSecretRow, SealedSecrets, SettingRow, Settings, Staged, StagedTake, Store, StoreRole, TemplatePackage, Templates, TriggerDef, TriggerPatch, TriggerRow, Triggers, TriggerScope, TriggerSettingRow, TriggerSettings, Channels, ChannelAttemptRow, ChannelPostRow, ChannelToldRow, ImportedFrom, ImportSource, ImportRunInput, JournalReads, RunLabels, RunOrigin, RunOutcome, RunLaunchInput, RunLaunchRow, LaunchSealed, LaunchSealedWrite, Learning, LearningProposal, LiveViewerRow, LiveViewers, PurgeKept, SignIns, SignInRow, SignInTombstoneRow, UpdatedRun, ViewerKind, } from "./store.js";
|
|
3
3
|
export { aadOf, type McpCredential, type OpenedMcpCredential, openMcpCredential, openRunLaunch, openRunMcpAuth, type RunLaunchSecrets, type ComposioBinding, type RunMcpAuth, type RunMcpEntry, type RunModelKey, sealColumn, type SealedAt, sealedAt, sealMcpCredential, sealRunLaunch, sealRunMcpAuth, unsealColumn } from "./seal.js";
|
|
4
4
|
export { AgentBodyInvalid, type AgenticBody, bodyOf, canonical, isObject, isSkillPath, type PromptVariant, type ModelTiers, type MonidPinBody, type RevisionBodyInput, type RevisionComputer, type RevisionPlace, sha256, type ToolSettings, type WorkflowBody, } from "./agent-body.js";
|
|
5
5
|
export { checkPrompts, OTHER_OPTION, PromptsInvalid } from "./prompts.js";
|
package/dist/store/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// The one store (design 2.1), for the cutover: nothing on main imports it until then.
|
|
2
|
-
export { AgentArchived, AgentDeleting, AnswerTaken, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreAwaitsServer, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, stoppedByPerson, TriggerFull, TriggersLeft } from "./store.js";
|
|
2
|
+
export { AgentArchived, AgentDeleting, AgentPurged, AnswerTaken, CommandTaken, endedReason, ExternalBodyConflict, FINAL_STATES, Fenced, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, RunFinal, RunPurged, RunsMadeFromLeft, SchemaVersionUnknown, SignInHandedTo, SignInMissing, StoreAwaitsServer, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreFromEarlierVersion, StoreLaunchMissing, StoreOwned, StoreWorkerLost, STORE_WRITE_DEADLINE_MS, stoppedByPerson, TriggerFull, TriggersLeft } from "./store.js";
|
|
3
3
|
export { aadOf, openMcpCredential, openRunLaunch, openRunMcpAuth, sealColumn, sealedAt, sealMcpCredential, sealRunLaunch, sealRunMcpAuth, unsealColumn } from "./seal.js";
|
|
4
4
|
export { AgentBodyInvalid, bodyOf, canonical, isObject, isSkillPath, sha256, } from "./agent-body.js";
|
|
5
5
|
export { checkPrompts, OTHER_OPTION, PromptsInvalid } from "./prompts.js";
|
|
@@ -324,7 +324,7 @@ export class RunStorage {
|
|
|
324
324
|
// A run patch that made the run final: its other untaken rows are refused in this commit, after its own takes.
|
|
325
325
|
// A person's message that came while it was ending opens a completed run again instead (refuseLeftovers).
|
|
326
326
|
if (patching)
|
|
327
|
-
await refuseLeftovers(tx, this.#runId, staged?.run?.state, now, this.#dialect);
|
|
327
|
+
await refuseLeftovers(tx, this.#runId, staged?.run?.state, now, this.#dialect, staged?.run?.keepsEnd === true);
|
|
328
328
|
}
|
|
329
329
|
});
|
|
330
330
|
this.#nextId = Math.max(this.#nextId, candidateNextId);
|
package/dist/store/open.d.ts
CHANGED
|
@@ -37,7 +37,7 @@ export interface OpenStoreOptions {
|
|
|
37
37
|
/** The environment AGENTRUN_STORE_SCHEMA and AGENTRUN_STORE_POOL_SIZE are read from (process.env). Neither is a secret. */
|
|
38
38
|
readonly env?: NodeJS.ProcessEnv;
|
|
39
39
|
/** Told what a person should know at the open (a runner's clock far from Postgres's; a server waiting for another to
|
|
40
|
-
* let the Postgres schema go). */
|
|
40
|
+
* let the Postgres schema go), or later (a SQLite purge's checkpoint that left the WAL as it was). */
|
|
41
41
|
readonly warn?: (message: string) => void;
|
|
42
42
|
/** A server's, on Postgres: told when its owner lock is lost for good (PostgresStoreOptions.onOwnerLost). */
|
|
43
43
|
readonly onOwnerLost?: (error: StoreOwned) => void;
|
package/dist/store/open.js
CHANGED
|
@@ -45,6 +45,6 @@ export async function openStore({ dataDir, role = "server", now, url, env = proc
|
|
|
45
45
|
const target = storeTarget(dataDir, env, url ?? storeUrl());
|
|
46
46
|
const poolSize = storePoolSize(env);
|
|
47
47
|
if (target.kind === "sqlite")
|
|
48
|
-
return openSqliteStore({ dataDir, role, ...(now ? { now } : {}) });
|
|
48
|
+
return openSqliteStore({ dataDir, role, ...(now ? { now } : {}), ...(warn ? { warn } : {}) });
|
|
49
49
|
return openPostgresStore({ url: target.url, schema: target.schema, role, poolSize, ...(now ? { now } : {}), ...(warn ? { warn } : {}), ...(onOwnerLost ? { onOwnerLost } : {}) });
|
|
50
50
|
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
-- The store's schema on Postgres, version 21: when a run or an agent was purged, as store/schema.ts keeps it on SQLite
|
|
2
|
+
-- (runs.purged_at, agents.purged_at). Applied once, after 0020, inside the transaction migrate.ts opens. Never edit this
|
|
3
|
+
-- file once applied: a change is a new file.
|
|
4
|
+
--
|
|
5
|
+
-- A purged run (DELETE /v2/runs/{id}) keeps its row as a tombstone: its id, agent, state, times and cost, every record of
|
|
6
|
+
-- what it was given or did gone, so every total that summed its cost sums it still. A purged agent (DELETE
|
|
7
|
+
-- /v2/agents/{id} of an archived agent made here) keeps its row the same way, its name, description and revisions'
|
|
8
|
+
-- content blanked. Null: not purged. In place: every row reads as not purged.
|
|
9
|
+
|
|
10
|
+
ALTER TABLE runs ADD COLUMN IF NOT EXISTS purged_at BIGINT;
|
|
11
|
+
ALTER TABLE agents ADD COLUMN IF NOT EXISTS purged_at BIGINT;
|
|
12
|
+
|
|
13
|
+
UPDATE store_meta SET schema_version = 21 WHERE singleton = 1;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
-- The store's schema on Postgres, version 22: each computer a run made, from its create to its proven delete, as
|
|
2
|
+
-- store/schema.ts keeps it on SQLite (COMPUTER_INTERVALS). Applied once, after 0021, inside the transaction migrate.ts
|
|
3
|
+
-- opens. Never edit this file once applied: a change is a new file.
|
|
4
|
+
--
|
|
5
|
+
-- computer_intervals: one row per computer a run's claim made through its provider (a sandbox, a desktop, a phone), by the
|
|
6
|
+
-- provider's own id for it; what its create asked for (kind, GPU, CPUs, memory; null where it asked none), when it was
|
|
7
|
+
-- made, whether the run's park kept it past its claim (kept, 0 or 1), and ended_at, written only when the provider's
|
|
8
|
+
-- delete of it answered ok (null while none did). A computer made before this file has no row. The table and its index are
|
|
9
|
+
-- made only where missing, so a store whose record of this file was lost applies it again unharmed.
|
|
10
|
+
|
|
11
|
+
CREATE TABLE IF NOT EXISTS computer_intervals (
|
|
12
|
+
provider TEXT COLLATE "C" NOT NULL,
|
|
13
|
+
provider_id TEXT COLLATE "C" NOT NULL,
|
|
14
|
+
run_id TEXT COLLATE "C" NOT NULL,
|
|
15
|
+
kind TEXT COLLATE "C",
|
|
16
|
+
gpu_type TEXT COLLATE "C",
|
|
17
|
+
gpu_count BIGINT,
|
|
18
|
+
cpus DOUBLE PRECISION,
|
|
19
|
+
memory_mb BIGINT,
|
|
20
|
+
started_at BIGINT NOT NULL,
|
|
21
|
+
kept BIGINT NOT NULL DEFAULT 0 CHECK (kept IN (0, 1)),
|
|
22
|
+
ended_at BIGINT,
|
|
23
|
+
PRIMARY KEY (provider, provider_id)
|
|
24
|
+
);
|
|
25
|
+
CREATE INDEX IF NOT EXISTS computer_intervals_run ON computer_intervals (run_id, started_at);
|
|
26
|
+
|
|
27
|
+
UPDATE store_meta SET schema_version = 22 WHERE singleton = 1;
|
package/dist/store/schema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const SCHEMA_VERSION =
|
|
1
|
+
export declare const SCHEMA_VERSION = 14;
|
|
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. */
|
|
@@ -40,6 +40,17 @@ export declare const IMPORTED_TEMPLATES: string;
|
|
|
40
40
|
* end its wait; null while none was, and again at a mint. In STORE_DDL, and added at a server open to a store an earlier
|
|
41
41
|
* build of this version made. */
|
|
42
42
|
export declare const MINTED_TOKENS = "CREATE TABLE IF NOT EXISTS minted_tokens (\n machine TEXT PRIMARY KEY,\n token_sha256 TEXT NOT NULL UNIQUE,\n kind TEXT NOT NULL,\n os TEXT NOT NULL,\n arch TEXT NOT NULL,\n expires_at INTEGER NOT NULL,\n revoked_at INTEGER,\n created_at INTEGER NOT NULL,\n runner TEXT,\n incarnation TEXT,\n run TEXT,\n refused TEXT\n ) STRICT";
|
|
43
|
+
/** Each computer a run's claim made through its provider (a sandbox, a desktop, a phone), by the provider's own id for it:
|
|
44
|
+
* so an operator can see how long each lived for its run, find one left running after its run, and match the provider's
|
|
45
|
+
* invoice by its id. `kind`, and what it was made with (`gpu_type` and `gpu_count`, `cpus`, `memory_mb`), as its create
|
|
46
|
+
* asked, null where the create asked none (a hosted vendor that sizes its own machines): never a guess. `kept`: 1 once
|
|
47
|
+
* the run's park kept it past the claim (computer-kept.ts). `ended_at`: written once, only when the provider's delete of
|
|
48
|
+
* it answered ok; null while none did (still running, or its delete failed or was never asked), never a guessed end. Not
|
|
49
|
+
* the agent's own computer (it outlives every run), a paired one or --faux's. In STORE_DDL, and added at a server open to
|
|
50
|
+
* a store an earlier build of this version made, as MINTED_TOKENS is. */
|
|
51
|
+
export declare const COMPUTER_INTERVALS = "CREATE TABLE IF NOT EXISTS computer_intervals (\n provider TEXT NOT NULL,\n provider_id TEXT NOT NULL,\n run_id TEXT NOT NULL,\n kind TEXT,\n gpu_type TEXT,\n gpu_count INTEGER,\n cpus REAL,\n memory_mb INTEGER,\n started_at INTEGER NOT NULL,\n kept INTEGER NOT NULL DEFAULT 0 CHECK (kept IN (0, 1)),\n ended_at INTEGER,\n PRIMARY KEY (provider, provider_id)\n ) STRICT";
|
|
52
|
+
/** A run's computers, read by its run (store.computerIntervals.forRun). */
|
|
53
|
+
export declare const COMPUTER_INTERVALS_RUN = "CREATE INDEX IF NOT EXISTS computer_intervals_run ON computer_intervals (run_id, started_at)";
|
|
43
54
|
/** Each runner's word that it is there (runner/presence.ts), every runner's, beside a server or in a process of its own:
|
|
44
55
|
* its name, its incarnation (its process since its start, the one its relay's minted tokens and proofs name), why it
|
|
45
56
|
* refused to claim any run (`refused`, its words; null for one that claims), where its relay's attach listener takes the
|
|
@@ -50,6 +61,9 @@ export declare const MINTED_TOKENS = "CREATE TABLE IF NOT EXISTS minted_tokens (
|
|
|
50
61
|
* server's open drops it and makes this one (sqlite/store.ts), as it drops browser_viewers, with no version: the rows
|
|
51
62
|
* are heartbeats renewed every 10 s, so none is copied, and a runner waits for that server (StoreAwaitsServer). */
|
|
52
63
|
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";
|
|
64
|
+
/** Version 13 → 14 on SQLite (the server's open, sqlite/store.ts), given the runs' and the agents' columns now: when each
|
|
65
|
+
* run and each agent was purged (null: none was), and the version, in one durable write. */
|
|
66
|
+
export declare function purgeUpgrade(runColumns: ReadonlySet<string>, agentColumns: ReadonlySet<string>): readonly string[];
|
|
53
67
|
/** Version 12 → 13 on SQLite (the server's open, sqlite/store.ts), given minted_tokens' columns now: the minting runner,
|
|
54
68
|
* its incarnation, the machine's run and a refused relay's words on each token's row (none of the rows there has one: the
|
|
55
69
|
* server's own process minted them, naming no run), the runners (where their relays answer), and the version, in one
|
package/dist/store/schema.js
CHANGED
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
// The template packages imported from GitHub (imported_templates) are a table of their own that nothing
|
|
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
|
-
// added the same way, and so is each runner's word that it is there and whether it refused to claim (runners, RUNNERS)
|
|
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
23
|
// Conventions: every time is INTEGER epoch milliseconds; JSON is TEXT checked by json_valid; money is REAL US dollars;
|
|
23
24
|
// sealed columns hold ciphertext only (sealed with the server's key outside the store), so the store never sees a secret
|
|
24
25
|
// in the clear. Foreign keys are on (the connection's pragma).
|
|
@@ -32,8 +33,11 @@
|
|
|
32
33
|
// Version 12 keeps each run's listing on its row (RUN_LISTING_COLUMNS): what a runs list shows of it, so a list reads rows
|
|
33
34
|
// alone. Version 13 names the runner in a process of its own that minted a hosted machine's token (minted_tokens.runner,
|
|
34
35
|
// .incarnation), the run the machine works for (.run), why the server refused to relay its dial (.refused), and where each
|
|
35
|
-
// such runner takes the dials the server relays to it (runners.host and .port, dial-relay.ts).
|
|
36
|
-
|
|
36
|
+
// 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
|
+
// 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. The server upgrades these in place at its open (listingUpgrade from
|
|
39
|
+
// 11, relayUpgrade from 12, then purgeUpgrade from 13); a runner waits for it.
|
|
40
|
+
export const SCHEMA_VERSION = 14;
|
|
37
41
|
/** One answer per approval of a run: a second approve or deny command naming the same approval is refused
|
|
38
42
|
* (StoreConstraint), so the first answer a person gives wins from the moment it is written, before the runner takes it
|
|
39
43
|
* (runs-over-store.ts approve). In STORE_DDL, and added at a server open to a store an earlier build of this version made. */
|
|
@@ -100,6 +104,30 @@ export const MINTED_TOKENS = `CREATE TABLE IF NOT EXISTS minted_tokens (
|
|
|
100
104
|
run TEXT,
|
|
101
105
|
refused TEXT
|
|
102
106
|
) STRICT`;
|
|
107
|
+
/** Each computer a run's claim made through its provider (a sandbox, a desktop, a phone), by the provider's own id for it:
|
|
108
|
+
* so an operator can see how long each lived for its run, find one left running after its run, and match the provider's
|
|
109
|
+
* invoice by its id. `kind`, and what it was made with (`gpu_type` and `gpu_count`, `cpus`, `memory_mb`), as its create
|
|
110
|
+
* asked, null where the create asked none (a hosted vendor that sizes its own machines): never a guess. `kept`: 1 once
|
|
111
|
+
* the run's park kept it past the claim (computer-kept.ts). `ended_at`: written once, only when the provider's delete of
|
|
112
|
+
* it answered ok; null while none did (still running, or its delete failed or was never asked), never a guessed end. Not
|
|
113
|
+
* the agent's own computer (it outlives every run), a paired one or --faux's. In STORE_DDL, and added at a server open to
|
|
114
|
+
* a store an earlier build of this version made, as MINTED_TOKENS is. */
|
|
115
|
+
export const COMPUTER_INTERVALS = `CREATE TABLE IF NOT EXISTS computer_intervals (
|
|
116
|
+
provider TEXT NOT NULL,
|
|
117
|
+
provider_id TEXT NOT NULL,
|
|
118
|
+
run_id TEXT NOT NULL,
|
|
119
|
+
kind TEXT,
|
|
120
|
+
gpu_type TEXT,
|
|
121
|
+
gpu_count INTEGER,
|
|
122
|
+
cpus REAL,
|
|
123
|
+
memory_mb INTEGER,
|
|
124
|
+
started_at INTEGER NOT NULL,
|
|
125
|
+
kept INTEGER NOT NULL DEFAULT 0 CHECK (kept IN (0, 1)),
|
|
126
|
+
ended_at INTEGER,
|
|
127
|
+
PRIMARY KEY (provider, provider_id)
|
|
128
|
+
) STRICT`;
|
|
129
|
+
/** A run's computers, read by its run (store.computerIntervals.forRun). */
|
|
130
|
+
export const COMPUTER_INTERVALS_RUN = "CREATE INDEX IF NOT EXISTS computer_intervals_run ON computer_intervals (run_id, started_at)";
|
|
103
131
|
/** Each runner's word that it is there (runner/presence.ts), every runner's, beside a server or in a process of its own:
|
|
104
132
|
* its name, its incarnation (its process since its start, the one its relay's minted tokens and proofs name), why it
|
|
105
133
|
* refused to claim any run (`refused`, its words; null for one that claims), where its relay's attach listener takes the
|
|
@@ -117,6 +145,15 @@ export const RUNNERS = `CREATE TABLE IF NOT EXISTS runners (
|
|
|
117
145
|
port INTEGER,
|
|
118
146
|
seen_at INTEGER NOT NULL
|
|
119
147
|
) STRICT`;
|
|
148
|
+
/** Version 13 → 14 on SQLite (the server's open, sqlite/store.ts), given the runs' and the agents' columns now: when each
|
|
149
|
+
* run and each agent was purged (null: none was), and the version, in one durable write. */
|
|
150
|
+
export function purgeUpgrade(runColumns, agentColumns) {
|
|
151
|
+
return [
|
|
152
|
+
...(runColumns.has("purged_at") ? [] : ["ALTER TABLE runs ADD COLUMN purged_at INTEGER"]),
|
|
153
|
+
...(agentColumns.has("purged_at") ? [] : ["ALTER TABLE agents ADD COLUMN purged_at INTEGER"]),
|
|
154
|
+
"UPDATE store_meta SET schema_version = 14 WHERE singleton = 1",
|
|
155
|
+
];
|
|
156
|
+
}
|
|
120
157
|
/** Version 12 → 13 on SQLite (the server's open, sqlite/store.ts), given minted_tokens' columns now: the minting runner,
|
|
121
158
|
* its incarnation, the machine's run and a refused relay's words on each token's row (none of the rows there has one: the
|
|
122
159
|
* server's own process minted them, naming no run), the runners (where their relays answer), and the version, in one
|
|
@@ -232,7 +269,10 @@ export const STORE_DDL = [
|
|
|
232
269
|
current_revision TEXT,
|
|
233
270
|
created_at INTEGER NOT NULL,
|
|
234
271
|
archived_at INTEGER,
|
|
235
|
-
external_ref TEXT
|
|
272
|
+
external_ref TEXT,
|
|
273
|
+
-- When the agent was purged (DELETE /agents/{id} of an archived agent made here): its row is then a tombstone, its
|
|
274
|
+
-- name, description and revisions' content blanked, kept for its runs' tombstones and their cost. Null: not purged.
|
|
275
|
+
purged_at INTEGER
|
|
236
276
|
) STRICT`,
|
|
237
277
|
`CREATE UNIQUE INDEX IF NOT EXISTS agents_external ON agents (external_ref) WHERE external_ref IS NOT NULL`,
|
|
238
278
|
// A revision's skills (the P4 fold of the old agent store's skill table): the revision's own skill files, a JSON object
|
|
@@ -305,7 +345,10 @@ export const STORE_DDL = [
|
|
|
305
345
|
started_at INTEGER NOT NULL,
|
|
306
346
|
ended_at INTEGER,
|
|
307
347
|
-- The run's listing (RUN_LISTING_COLUMNS): what a runs list shows of it, kept on its row so a list reads rows alone.
|
|
308
|
-
${RUN_LISTING_COLUMNS.join(",\n ")}
|
|
348
|
+
${RUN_LISTING_COLUMNS.join(",\n ")},
|
|
349
|
+
-- When the run was purged (DELETE /runs/{id}, Runs.purge): its row is then a tombstone, every record of what it was
|
|
350
|
+
-- given or did gone and its cost kept, which no list shows and every total still sums. Null: not purged.
|
|
351
|
+
purged_at INTEGER
|
|
309
352
|
) STRICT`,
|
|
310
353
|
`CREATE INDEX IF NOT EXISTS runs_by_agent ON runs (agent_id, started_at)`,
|
|
311
354
|
`CREATE INDEX IF NOT EXISTS runs_by_revision ON runs (revision_id, started_at)`,
|
|
@@ -548,6 +591,8 @@ export const STORE_DDL = [
|
|
|
548
591
|
IMPORTED_TEMPLATES,
|
|
549
592
|
MINTED_TOKENS,
|
|
550
593
|
RUNNERS,
|
|
594
|
+
COMPUTER_INTERVALS,
|
|
595
|
+
COMPUTER_INTERVALS_RUN,
|
|
551
596
|
// An agent's saved browser sign-ins (design 2.1, the browser sign-in rules): one live row per agent and browser provider, its
|
|
552
597
|
// pointer (the vendor's context or profile id) sealed with the store's one rule (store/seal.ts, AAD
|
|
553
598
|
// sign_ins|<agent>:<provider>|pointer), which the store never opens. The owner sees its name ("default") and saved_at,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Worker } from "node:worker_threads";
|
|
2
2
|
import { type Dialect } from "../dialect.js";
|
|
3
|
-
import type { Statement, StatementResult } from "./worker.js";
|
|
3
|
+
import type { CheckpointResult, Statement, StatementResult } from "./worker.js";
|
|
4
4
|
export type { Params, Statement, StatementResult } from "./worker.js";
|
|
5
5
|
/** How long a transaction may stay open (it holds every other call of the process) before it is rolled back. */
|
|
6
6
|
export declare const DEFAULT_TRANSACTION_DEADLINE_MS = 10000;
|
|
@@ -95,6 +95,9 @@ export declare class Connection implements SqliteDatabase, StoreConnection {
|
|
|
95
95
|
runCounted(sql: string, ...params: SqliteValue[]): Promise<number>;
|
|
96
96
|
get<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T | undefined>;
|
|
97
97
|
all<T extends object>(sql: string, ...params: SqliteValue[]): Promise<T[]>;
|
|
98
|
+
/** A WAL checkpoint (TRUNCATE) that waits `busyMs` at most for another connection's reader or writer, never the
|
|
99
|
+
* connection's own busy wait: every call queued behind it waits that long at most for it. Busy (1) when one held it. */
|
|
100
|
+
checkpoint(busyMs: number): Promise<CheckpointResult | undefined>;
|
|
98
101
|
/** One write transaction of fixed statements: in order; an expectation miss or an error rolls all of them back. `full`: a
|
|
99
102
|
* FULL commit, durable against a lost box together with every commit before it. */
|
|
100
103
|
write(statements: readonly Statement[], { full }?: {
|
|
@@ -291,6 +291,11 @@ export class Connection {
|
|
|
291
291
|
all(sql, ...params) {
|
|
292
292
|
return this.#queued(async () => (await this.#stmt(sql, params, "all")));
|
|
293
293
|
}
|
|
294
|
+
/** A WAL checkpoint (TRUNCATE) that waits `busyMs` at most for another connection's reader or writer, never the
|
|
295
|
+
* connection's own busy wait: every call queued behind it waits that long at most for it. Busy (1) when one held it. */
|
|
296
|
+
checkpoint(busyMs) {
|
|
297
|
+
return this.#queued(async () => ((await this.#send({ op: "checkpoint", busyMs })) ?? undefined));
|
|
298
|
+
}
|
|
294
299
|
/** One write transaction of fixed statements: in order; an expectation miss or an error rolls all of them back. `full`: a
|
|
295
300
|
* FULL commit, durable against a lost box together with every commit before it. */
|
|
296
301
|
write(statements, { full = false } = {}) {
|
|
@@ -29,8 +29,9 @@ export type RunRecord = {
|
|
|
29
29
|
labels: string | null;
|
|
30
30
|
started_at: number;
|
|
31
31
|
ended_at: number | null;
|
|
32
|
+
purged_at: number | null;
|
|
32
33
|
};
|
|
33
|
-
export declare const RUN_COLUMNS = "id, agent_id, revision_id, state, epoch, runner, claimed_until, wake_at, backoff_until, cost_usd, cost_upper_bound, metrics, summary, outcome, archived_at, imported_from, sign_in_handed, labels, started_at, ended_at";
|
|
34
|
+
export declare const RUN_COLUMNS = "id, agent_id, revision_id, state, epoch, runner, claimed_until, wake_at, backoff_until, cost_usd, cost_upper_bound, metrics, summary, outcome, archived_at, imported_from, sign_in_handed, labels, started_at, ended_at, purged_at";
|
|
34
35
|
/** A run's exact cost in SQL, for a query that reads runs.cost_usd itself (`alias`: its runs table's): NULL when the
|
|
35
36
|
* stored figure is only the most the run can have cost, as runOf reads it. Every raw read of the column goes through it. */
|
|
36
37
|
export declare const EXACT_COST_USD: (alias: string) => string;
|
|
@@ -62,5 +63,9 @@ export declare const reopenableWhere: (d: Dialect) => string;
|
|
|
62
63
|
* before the end, it opens the run here; after it, the store refuses a new row (RunFinal) and runs.reopen takes it.
|
|
63
64
|
* A person's stop is the same (reopenableWhere): a message waiting at it is the run's next turn, as main's stop leaves a
|
|
64
65
|
* message submitted before it to run; a cancel's refuses it. A run left final here has its launch secrets erased (its
|
|
65
|
-
* launch row's `sealed`); a run opened again keeps the ones its waiting message wrote.
|
|
66
|
-
|
|
66
|
+
* launch row's `sealed`); a run opened again keeps the ones its waiting message wrote.
|
|
67
|
+
* An end that keeps its job's end (`keepsEnd`: a look-back's, RunPatch.keepsEnd) is that end, which every reader served
|
|
68
|
+
* while the run looked back: a cancel at it cut the look-back alone and is refused with the rest. Only with a person's
|
|
69
|
+
* message waiting (the run read as going on from it, as a completed run a message opens again) is a cancel, waiting or
|
|
70
|
+
* taken in this commit, that message's run's: it ends cancelled, at this commit's time. */
|
|
71
|
+
export declare function refuseLeftovers(tx: Pick<SqliteExecutor, "run" | "get">, runId: string, state: RunState | undefined, now: number, dialect?: Dialect, keepsEnd?: boolean): Promise<void>;
|
|
@@ -12,7 +12,7 @@ export const NOT_A_LEARNING_RUN = "id NOT IN (SELECT learning_run_id FROM learni
|
|
|
12
12
|
/** The lock a write of a run's sign_in_handed and a sign-in's forget both take (Dialect.lockKey): the forget's check of
|
|
13
13
|
* the running runs' hashes and a launch's write of them are serialized, as SQLite's one writer serializes them. */
|
|
14
14
|
export const SIGN_IN_HANDED_LOCK = "sign_in_handed";
|
|
15
|
-
export const RUN_COLUMNS = "id, agent_id, revision_id, state, epoch, runner, claimed_until, wake_at, backoff_until, cost_usd, cost_upper_bound, metrics, summary, outcome, archived_at, imported_from, sign_in_handed, labels, started_at, ended_at";
|
|
15
|
+
export const RUN_COLUMNS = "id, agent_id, revision_id, state, epoch, runner, claimed_until, wake_at, backoff_until, cost_usd, cost_upper_bound, metrics, summary, outcome, archived_at, imported_from, sign_in_handed, labels, started_at, ended_at, purged_at";
|
|
16
16
|
/** A run's exact cost in SQL, for a query that reads runs.cost_usd itself (`alias`: its runs table's): NULL when the
|
|
17
17
|
* stored figure is only the most the run can have cost, as runOf reads it. Every raw read of the column goes through it. */
|
|
18
18
|
export const EXACT_COST_USD = (alias) => `CASE WHEN ${alias}.cost_upper_bound = 1 THEN NULL ELSE ${alias}.cost_usd END`;
|
|
@@ -25,7 +25,7 @@ export const runOf = (r) => ({
|
|
|
25
25
|
wakeAt: r.wake_at, backoffUntil: r.backoff_until, ...costOf(r.cost_usd, r.cost_upper_bound), metrics: r.metrics === null ? null : JSON.parse(r.metrics), summary: r.summary,
|
|
26
26
|
outcome: r.outcome ?? null, archivedAt: r.archived_at, importedFrom: r.imported_from === null ? null : JSON.parse(r.imported_from),
|
|
27
27
|
signInHanded: r.sign_in_handed === null ? null : JSON.parse(r.sign_in_handed), labels: r.labels === null ? {} : JSON.parse(r.labels),
|
|
28
|
-
startedAt: r.started_at, endedAt: r.ended_at,
|
|
28
|
+
startedAt: r.started_at, endedAt: r.ended_at, purgedAt: r.purged_at ?? null,
|
|
29
29
|
});
|
|
30
30
|
/** Applies `patch` to the claim's run, then writes `also`, through `tx` (an open transaction's handle). Fenced, with nothing
|
|
31
31
|
* of it written once the caller rolls back, when the run's epoch is not the claim's or the claim's lease ran out before
|
|
@@ -108,7 +108,7 @@ export async function applyRunPatch(tx, claim, patch, also, now, dialect = SQLIT
|
|
|
108
108
|
* outcome 'stopped': its turn ended, never the run, as main's stop leaves one), not imported and not a learning run. A
|
|
109
109
|
* cancelled run, a failed one and a workflow run are over for good. */
|
|
110
110
|
export const REOPEN_SET = "state = 'running', runner = NULL, claimed_until = NULL, wake_at = NULL, backoff_until = NULL, ended_at = NULL, summary = NULL, outcome = NULL";
|
|
111
|
-
export const reopenableWhere = (d) => `(state = 'ended' OR (state = 'stopped' AND outcome = 'stopped')) AND imported_from IS NULL
|
|
111
|
+
export const reopenableWhere = (d) => `(state = 'ended' OR (state = 'stopped' AND outcome = 'stopped')) AND imported_from IS NULL AND purged_at IS NULL
|
|
112
112
|
AND EXISTS (SELECT 1 FROM revisions WHERE revisions.id = runs.revision_id AND revisions.kind = 'agentic')
|
|
113
113
|
AND NOT EXISTS (SELECT 1 FROM run_launch WHERE run_launch.run_id = runs.id AND ${d.jsonText("run_launch.body", ["harness"])} = 'learning')`;
|
|
114
114
|
/** After a write that made the run final has taken its own rows: every command row of the run still untaken is refused
|
|
@@ -122,8 +122,12 @@ export const reopenableWhere = (d) => `(state = 'ended' OR (state = 'stopped' AN
|
|
|
122
122
|
* before the end, it opens the run here; after it, the store refuses a new row (RunFinal) and runs.reopen takes it.
|
|
123
123
|
* A person's stop is the same (reopenableWhere): a message waiting at it is the run's next turn, as main's stop leaves a
|
|
124
124
|
* message submitted before it to run; a cancel's refuses it. A run left final here has its launch secrets erased (its
|
|
125
|
-
* launch row's `sealed`); a run opened again keeps the ones its waiting message wrote.
|
|
126
|
-
|
|
125
|
+
* launch row's `sealed`); a run opened again keeps the ones its waiting message wrote.
|
|
126
|
+
* An end that keeps its job's end (`keepsEnd`: a look-back's, RunPatch.keepsEnd) is that end, which every reader served
|
|
127
|
+
* while the run looked back: a cancel at it cut the look-back alone and is refused with the rest. Only with a person's
|
|
128
|
+
* message waiting (the run read as going on from it, as a completed run a message opens again) is a cancel, waiting or
|
|
129
|
+
* taken in this commit, that message's run's: it ends cancelled, at this commit's time. */
|
|
130
|
+
export async function refuseLeftovers(tx, runId, state, now, dialect = SQLITE, keepsEnd = false) {
|
|
127
131
|
if (state !== "ended" && state !== "stopped" && state !== "failed")
|
|
128
132
|
return;
|
|
129
133
|
// A cancel the API accepted (202, not refused) promised a cancelled run, and the view reads cancelled from that 202 on.
|
|
@@ -132,8 +136,12 @@ export async function refuseLeftovers(tx, runId, state, now, dialect = SQLITE) {
|
|
|
132
136
|
// A stop's end is the same (state 'stopped', outcome 'stopped': a CLI turn its harness interrupted on its own, or a
|
|
133
137
|
// person's stop): it would leave the run open to a message, so the cancel wins it too, and the run takes no more.
|
|
134
138
|
if (state === "ended" || state === "stopped") {
|
|
135
|
-
const
|
|
136
|
-
|
|
139
|
+
const cancel = keepsEnd
|
|
140
|
+
? `EXISTS (SELECT 1 FROM commands WHERE commands.run_id = runs.id AND commands.refused IS NULL AND commands.kind = 'cancel' AND (commands.taken_at IS NULL OR commands.taken_at = ?))
|
|
141
|
+
AND EXISTS (SELECT 1 FROM commands WHERE commands.run_id = runs.id AND commands.taken_at IS NULL AND commands.kind = 'steer')`
|
|
142
|
+
: "EXISTS (SELECT 1 FROM commands WHERE commands.run_id = runs.id AND commands.taken_at IS NULL AND commands.refused IS NULL AND commands.kind = 'cancel')";
|
|
143
|
+
const won = await tx.get(`UPDATE runs SET state = 'stopped', outcome = 'cancelled', summary = 'cancelled'${keepsEnd ? ", ended_at = ?" : ""} WHERE id = ? AND (state = 'ended' OR (state = 'stopped' AND outcome = 'stopped'))
|
|
144
|
+
AND ${cancel} RETURNING id`, ...(keepsEnd ? [now, runId, now] : [runId]));
|
|
137
145
|
if (won) {
|
|
138
146
|
await tx.run("UPDATE commands SET taken_at = ? WHERE run_id = ? AND taken_at IS NULL AND refused IS NULL AND kind = 'cancel'", now, runId);
|
|
139
147
|
await tx.run("UPDATE commands SET taken_at = ?, refused = ? WHERE run_id = ? AND taken_at IS NULL", now, endedReason("stopped"), runId);
|
|
@@ -21,6 +21,8 @@ export type SqliteStoreOptions = (
|
|
|
21
21
|
now?: () => number;
|
|
22
22
|
/** How long a write waits for another process's lock before StoreBusy. */
|
|
23
23
|
busyTimeoutMs?: number;
|
|
24
|
+
/** Told what a person should know that no caller is answered (a purge's checkpoint that left the WAL): stderr by default. */
|
|
25
|
+
warn?: (message: string) => void;
|
|
24
26
|
};
|
|
25
27
|
/** Opens the store in `dataDir` (its file is STORE_FILE there), or at `file` (the store's own tests). As the server (the
|
|
26
28
|
* default): makes the data directory, takes the owner lock (StoreOwned when another server holds it) and, on a store with
|
|
@@ -30,5 +32,6 @@ export type SqliteStoreOptions = (
|
|
|
30
32
|
export declare function openSqliteStore(options: SqliteStoreOptions): Promise<Store>;
|
|
31
33
|
/** The Store over `connection`, on whichever database it is (SQLite here, Postgres in postgres/store.ts), on the store's
|
|
32
34
|
* clock `now` (ms), its identity `where` (Store.where). The opener sets the schema up and checks its version first.
|
|
33
|
-
* `file`: a SQLite store's database file, beside which secureRewrite keeps its marker (SCRUB_SUFFIX)
|
|
34
|
-
|
|
35
|
+
* `file`: a SQLite store's database file, beside which secureRewrite keeps its marker (SCRUB_SUFFIX), and whose WAL a
|
|
36
|
+
* purge checkpoints. `warn`: told when that checkpoint could not empty the WAL (stderr by default). */
|
|
37
|
+
export declare function storeOver(connection: StoreConnection, now: () => number, file?: string, warn?: (message: string) => void): Store;
|