@parcha/agentrun-serve 0.1.0-beta.34 → 0.1.0-beta.36
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 +263 -0
- package/README.md +339 -179
- package/dist/adapters.d.ts +15 -2
- package/dist/adapters.js +34 -2
- package/dist/agent-rows.d.ts +3 -1
- package/dist/agents-store.d.ts +2 -0
- package/dist/agents-store.js +25 -5
- package/dist/api-only.d.ts +2 -1
- package/dist/api-only.js +3 -1
- package/dist/archil-routes.d.ts +40 -7
- package/dist/archil-routes.js +167 -54
- package/dist/archil-settings.d.ts +90 -8
- package/dist/archil-settings.js +150 -14
- package/dist/attach-images.d.ts +15 -0
- package/dist/attach-images.js +59 -0
- package/dist/background.d.ts +0 -6
- package/dist/background.js +0 -28
- package/dist/bash-read-only.d.ts +13 -0
- package/dist/bash-read-only.js +77 -0
- package/dist/box-image.d.ts +1 -97
- package/dist/box-image.js +4 -284
- package/dist/box-paths.d.ts +2 -7
- package/dist/box-paths.js +7 -13
- package/dist/box-settings.d.ts +0 -11
- package/dist/box-settings.js +4 -29
- package/dist/browser-commands.js +1 -1
- package/dist/browser-computer.d.ts +47 -3
- package/dist/browser-computer.js +286 -18
- package/dist/browser-cost.d.ts +2 -2
- package/dist/browser-cost.js +6 -4
- package/dist/browser-person.d.ts +19 -2
- package/dist/browser-person.js +55 -6
- package/dist/browser-wait-ended.d.ts +23 -0
- package/dist/browser-wait-ended.js +42 -0
- package/dist/cap.d.ts +19 -44
- package/dist/cap.js +31 -77
- package/dist/cli.js +36 -27
- package/dist/computer-keys.d.ts +20 -10
- package/dist/computer-keys.js +36 -57
- package/dist/computer-routes.d.ts +1 -4
- package/dist/computer-routes.js +3 -5
- package/dist/computer-setting.d.ts +8 -5
- package/dist/computer-setting.js +91 -26
- package/dist/computer-view.d.ts +11 -2
- package/dist/computer-view.js +2 -1
- package/dist/computers.d.ts +54 -8
- package/dist/computers.js +101 -22
- package/dist/console/assets/index-BI4Byidu.js +550 -0
- package/dist/console/assets/index-C19gUF2n.css +1 -0
- package/dist/console/index.html +2 -2
- package/dist/content-filter.d.ts +7 -0
- package/dist/content-filter.js +23 -0
- package/dist/decision-cap.d.ts +7 -29
- package/dist/decision-cap.js +3 -94
- package/dist/docker-daemon.d.ts +2 -2
- package/dist/docker-daemon.js +2 -2
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +8 -5
- package/dist/explain.js +3 -1
- package/dist/faux-computers.js +4 -0
- package/dist/files.d.ts +1 -9
- package/dist/files.js +1 -9
- package/dist/github-connection.js +25 -7
- package/dist/github-faux.d.ts +26 -0
- package/dist/github-faux.js +76 -0
- package/dist/github.d.ts +28 -4
- package/dist/github.js +46 -10
- package/dist/gpu-words.d.ts +14 -0
- package/dist/gpu-words.js +21 -0
- package/dist/graph-served.d.ts +5 -3
- package/dist/graph-served.js +14 -6
- package/dist/graph-view.d.ts +2 -0
- package/dist/graph-view.js +29 -2
- package/dist/handed-values.d.ts +1 -1
- package/dist/handed-values.js +1 -1
- package/dist/harness-install.d.ts +60 -3
- package/dist/harness-install.js +322 -34
- package/dist/harness-opencode/harness.js +0 -1
- package/dist/harness-opencode/host/policy.js +2 -2
- package/dist/harness.js +1 -1
- package/dist/host-tools.d.ts +8 -9
- package/dist/host-tools.js +7 -7
- package/dist/index.d.ts +2 -3
- package/dist/index.js +2 -2
- package/dist/key-refusal.d.ts +1 -1
- package/dist/key-refusal.js +2 -2
- package/dist/learn/check.d.ts +10 -2
- package/dist/learn/check.js +126 -8
- package/dist/learn/commit.d.ts +40 -6
- package/dist/learn/commit.js +164 -20
- package/dist/learn/folder.d.ts +11 -3
- package/dist/learn/folder.js +40 -16
- package/dist/learn/grade.d.ts +22 -2
- package/dist/learn/grade.js +127 -19
- package/dist/learn/index.d.ts +2 -2
- package/dist/learn/index.js +2 -2
- package/dist/learn/learning.sh +11 -13
- package/dist/learn/notes.d.ts +17 -3
- package/dist/learn/notes.js +19 -6
- package/dist/learn/reflect.d.ts +5 -2
- package/dist/learn/reflect.js +48 -32
- package/dist/learn/skills.d.ts +52 -5
- package/dist/learn/skills.js +104 -21
- package/dist/learned-nodes.d.ts +18 -0
- package/dist/learned-nodes.js +8 -0
- package/dist/learned-workflow.d.ts +27 -13
- package/dist/learned-workflow.js +110 -38
- package/dist/learning-cost.d.ts +79 -0
- package/dist/learning-cost.js +69 -0
- package/dist/learning-routes.d.ts +48 -2
- package/dist/learning-routes.js +99 -28
- package/dist/learning-run.d.ts +7 -5
- package/dist/learning-run.js +9 -6
- package/dist/learning-words.d.ts +3 -0
- package/dist/learning-words.js +6 -2
- package/dist/learning.d.ts +13 -28
- package/dist/learning.js +4 -18
- package/dist/llm.d.ts +4 -1
- package/dist/llm.js +4 -2
- package/dist/mcp-gateway.d.ts +6 -0
- package/dist/mcp-gateway.js +11 -1
- package/dist/mcp-probe.d.ts +8 -1
- package/dist/mcp-probe.js +62 -20
- package/dist/mcp-secret-writes.js +4 -0
- package/dist/mcp-servers-store.d.ts +12 -12
- package/dist/mcp-servers-store.js +8 -3
- package/dist/model.d.ts +8 -5
- package/dist/model.js +14 -6
- package/dist/openapi.d.ts +2 -0
- package/dist/openapi.js +236 -55
- package/dist/owner.d.ts +0 -1
- package/dist/owner.js +0 -2
- package/dist/pause.d.ts +2 -19
- package/dist/pause.js +5 -74
- package/dist/place-offers.d.ts +97 -0
- package/dist/place-offers.js +206 -0
- package/dist/place.d.ts +9 -13
- package/dist/place.js +22 -32
- package/dist/port-models.d.ts +12 -4
- package/dist/port-models.js +31 -9
- package/dist/print.d.ts +1 -8
- package/dist/print.js +1 -14
- package/dist/propose.d.ts +3 -0
- package/dist/propose.js +25 -19
- package/dist/run-cut.d.ts +5 -0
- package/dist/run-cut.js +19 -0
- package/dist/run-db.js +3 -3
- package/dist/run-launch.d.ts +18 -3
- package/dist/run-launch.js +11 -5
- package/dist/run-learning-served.d.ts +12 -1
- package/dist/run-manifest.d.ts +2 -2
- package/dist/run-manifest.js +2 -2
- package/dist/run-reads-over-store.d.ts +4 -2
- package/dist/run-reads-over-store.js +10 -8
- package/dist/run-secrets.js +3 -3
- package/dist/run-timeline-served.js +60 -38
- package/dist/run-view.d.ts +35 -16
- package/dist/run-view.js +64 -35
- package/dist/runnable.d.ts +6 -3
- package/dist/runnable.js +20 -4
- package/dist/runner/adapter-loop.d.ts +46 -5
- package/dist/runner/adapter-loop.js +381 -56
- package/dist/runner/adapter-run-spec.d.ts +46 -4
- package/dist/runner/adapter-run-spec.js +200 -45
- package/dist/runner/adapters/pi.d.ts +39 -3
- package/dist/runner/adapters/pi.js +124 -29
- package/dist/runner/beside.d.ts +8 -0
- package/dist/runner/beside.js +24 -2
- package/dist/runner/claim-secrets.d.ts +6 -0
- package/dist/runner/claim-secrets.js +15 -1
- package/dist/runner/cli-run-spec.d.ts +10 -0
- package/dist/runner/cli-run-spec.js +207 -64
- package/dist/runner/commands.d.ts +5 -1
- package/dist/runner/commands.js +3 -3
- package/dist/runner/conformance/harness.d.ts +1 -1
- package/dist/runner/conformance/harness.js +13 -10
- package/dist/runner/github-app.d.ts +7 -2
- package/dist/runner/github-app.js +46 -15
- package/dist/runner/harness-loops.d.ts +6 -1
- package/dist/runner/harness-loops.js +24 -1
- package/dist/runner/journal-kinds.d.ts +53 -7
- package/dist/runner/journal-kinds.js +29 -1
- package/dist/runner/learning-end.d.ts +15 -0
- package/dist/runner/learning-end.js +113 -20
- package/dist/runner/learning-factory.js +6 -2
- package/dist/runner/learning-loop.d.ts +75 -1
- package/dist/runner/learning-loop.js +215 -22
- package/dist/runner/learning-seed.d.ts +8 -0
- package/dist/runner/learning-seed.js +7 -1
- package/dist/runner/loop-contract.d.ts +12 -0
- package/dist/runner/loop-contract.js +6 -0
- package/dist/runner/loop.d.ts +5 -1
- package/dist/runner/loop.js +20 -0
- package/dist/runner/main.d.ts +9 -4
- package/dist/runner/main.js +38 -13
- package/dist/runner/mcp-claim.d.ts +7 -0
- package/dist/runner/mcp-claim.js +35 -2
- package/dist/runner/mcp-github.d.ts +15 -4
- package/dist/runner/mcp-github.js +55 -11
- package/dist/runner/mcp-run.d.ts +2 -0
- package/dist/runner/mcp-run.js +2 -0
- package/dist/runner/metrics.d.ts +18 -1
- package/dist/runner/metrics.js +81 -1
- package/dist/runner/model-route.d.ts +6 -0
- package/dist/runner/model-route.js +5 -2
- package/dist/runner/pr-checkout.d.ts +59 -0
- package/dist/runner/pr-checkout.js +176 -0
- package/dist/runner/reflect-hook.d.ts +1 -0
- package/dist/runner/reflect-hook.js +3 -3
- package/dist/runner/runner.js +136 -19
- package/dist/runner/spec-holds.d.ts +13 -3
- package/dist/runner/spec-holds.js +13 -10
- package/dist/runner/store-port.d.ts +4 -1
- package/dist/runner/store-secrets.js +17 -1
- package/dist/runner/subagent.d.ts +44 -0
- package/dist/runner/subagent.js +188 -0
- package/dist/runner/workflow-host.d.ts +25 -4
- package/dist/runner/workflow-host.js +26 -4
- package/dist/runner/workflow-loop.d.ts +9 -3
- package/dist/runner/workflow-loop.js +17 -10
- package/dist/runner/workflow-spec.d.ts +28 -13
- package/dist/runner/workflow-spec.js +247 -102
- package/dist/runs-over-store.d.ts +18 -7
- package/dist/runs-over-store.js +149 -31
- package/dist/seal-key.d.ts +0 -2
- package/dist/seal-key.js +0 -2
- package/dist/sealing.js +1 -2
- package/dist/secret-cut.d.ts +1 -1
- package/dist/secret-cut.js +1 -1
- package/dist/server-lock.js +4 -5
- package/dist/server.d.ts +49 -63
- package/dist/server.js +429 -230
- package/dist/stop-signals.d.ts +4 -2
- package/dist/stop-signals.js +5 -3
- package/dist/store/agent-body.d.ts +14 -3
- package/dist/store/agent-body.js +22 -8
- package/dist/store/deadline.d.ts +18 -0
- package/dist/store/deadline.js +49 -0
- package/dist/store/index.d.ts +3 -3
- package/dist/store/index.js +2 -2
- package/dist/store/journal/storage.js +2 -1
- package/dist/store/postgres/connection.d.ts +4 -0
- package/dist/store/postgres/connection.js +64 -13
- package/dist/store/postgres/migrations/0004_runs_outcome_stop_or_cancel.sql +11 -0
- package/dist/store/schema.d.ts +2 -1
- package/dist/store/schema.js +11 -8
- package/dist/store/seal.d.ts +13 -0
- package/dist/store/seal.js +19 -0
- package/dist/store/sqlite/connection.d.ts +5 -0
- package/dist/store/sqlite/connection.js +88 -82
- package/dist/store/sqlite/run-patch.d.ts +18 -2
- package/dist/store/sqlite/run-patch.js +31 -2
- package/dist/store/sqlite/store.js +65 -11
- package/dist/store/store.d.ts +62 -12
- package/dist/store/store.js +22 -1
- package/dist/store-reads/analytics.js +3 -2
- package/dist/store-reads/cap.d.ts +1 -3
- package/dist/store-reads/cap.js +8 -6
- package/dist/store-reads/decisions.d.ts +2 -2
- package/dist/store-reads/decisions.js +3 -6
- package/dist/store-reads/journal.js +83 -15
- package/dist/store-reads/learning.d.ts +73 -3
- package/dist/store-reads/learning.js +232 -9
- package/dist/store-reads/runs.d.ts +6 -4
- package/dist/store-reads/runs.js +17 -10
- package/dist/store-reads/stats.js +5 -1
- package/dist/store-view.d.ts +15 -1
- package/dist/store-view.js +88 -29
- package/dist/template-eval.js +2 -1
- package/dist/templates.d.ts +73 -4
- package/dist/templates.js +113 -23
- package/dist/timeline/timeline.d.ts +11 -1
- package/dist/timeline/timeline.js +19 -4
- package/dist/tool-blurbs.js +1 -0
- package/dist/tool-budget.d.ts +26 -0
- package/dist/tool-budget.js +56 -0
- package/dist/tool-gate.d.ts +13 -3
- package/dist/tool-gate.js +15 -7
- package/dist/tool-plane.d.ts +42 -29
- package/dist/tool-plane.js +64 -27
- package/dist/tools.d.ts +53 -39
- package/dist/tools.js +174 -79
- package/dist/trigger-signatures.d.ts +1 -0
- package/dist/trigger-signatures.js +3 -1
- package/dist/triggers.d.ts +3 -3
- package/dist/triggers.js +2 -2
- package/dist/turn-end.d.ts +0 -3
- package/dist/turn-end.js +0 -3
- package/dist/uploads.d.ts +28 -5
- package/dist/uploads.js +82 -9
- package/dist/usage-lines.d.ts +1 -1
- package/dist/usage.d.ts +1 -47
- package/dist/usage.js +3 -82
- package/dist/validate.d.ts +8 -0
- package/dist/validate.js +40 -3
- package/dist/webhooks.d.ts +2 -1
- package/dist/webhooks.js +5 -2
- package/dist/workflow/decision-recovery.d.ts +23 -0
- package/dist/workflow/decision-recovery.js +80 -0
- package/dist/workflow/decisions.d.ts +134 -0
- package/dist/workflow/decisions.js +46 -0
- package/dist/workflow/host-session.d.ts +5 -0
- package/dist/workflow/host-session.js +85 -0
- package/dist/workflow/host-tools.d.ts +3 -0
- package/dist/workflow/host-tools.js +3 -0
- package/dist/workflow/node-runner.d.ts +112 -0
- package/dist/workflow/node-runner.js +270 -0
- package/dist/workflow/node.d.ts +88 -0
- package/dist/workflow/node.js +99 -0
- package/dist/workflow/operator-error.d.ts +4 -0
- package/dist/workflow/operator-error.js +4 -0
- package/dist/workflow/pi-versions.d.ts +9 -0
- package/dist/workflow/pi-versions.js +8 -0
- package/dist/workflow/readers.d.ts +36 -0
- package/dist/workflow/readers.js +145 -0
- package/dist/workflow/record-file.d.ts +10 -0
- package/dist/workflow/record-file.js +56 -0
- package/dist/workflow/record-tool.d.ts +76 -0
- package/dist/workflow/record-tool.js +126 -0
- package/dist/workflow/record.d.ts +151 -0
- package/dist/workflow/record.js +401 -0
- package/dist/workflow/run-error.d.ts +16 -0
- package/dist/workflow/run-error.js +26 -0
- package/dist/workflow/runner.d.ts +6 -0
- package/dist/workflow/runner.js +240 -0
- package/dist/workflow/store.d.ts +23 -0
- package/dist/workflow/store.js +242 -0
- package/dist/workflow/task.d.ts +133 -0
- package/dist/workflow/task.js +411 -0
- package/dist/workflow/thinking.d.ts +3 -0
- package/dist/workflow/thinking.js +7 -0
- package/dist/workflow/tool-context.d.ts +21 -0
- package/dist/workflow/tool-context.js +13 -0
- package/dist/workflow/types.d.ts +126 -0
- package/dist/workflow/types.js +1 -0
- package/dist/workflow/wal.d.ts +11 -0
- package/dist/workflow/wal.js +106 -0
- package/dist/workflow-run.d.ts +1 -1
- package/dist/workspace/agent-computer.d.ts +137 -0
- package/dist/workspace/agent-computer.js +292 -0
- package/dist/workspace/archil-claim.d.ts +13 -2
- package/dist/workspace/archil-claim.js +22 -13
- package/dist/workspace/archil-disk.d.ts +10 -1
- package/dist/workspace/archil-disk.js +4 -0
- package/dist/workspace/archil-disks.d.ts +49 -0
- package/dist/workspace/archil-disks.js +185 -0
- package/dist/workspace/archil-exec.d.ts +12 -2
- package/dist/workspace/archil-exec.js +18 -3
- package/dist/workspace/archil-mount-credential.d.ts +20 -4
- package/dist/workspace/archil-mount-credential.js +13 -4
- package/dist/workspace/archil.d.ts +2 -2
- package/dist/workspace/archil.js +25 -5
- package/dist/workspace/attach.js +2 -0
- package/dist/workspace/computer-deps.d.ts +18 -11
- package/dist/workspace/computer-deps.js +64 -40
- package/dist/workspace/computer-for-claim.d.ts +47 -9
- package/dist/workspace/computer-for-claim.js +236 -24
- package/dist/workspace/computer-janitor.d.ts +3 -2
- package/dist/workspace/computer-janitor.js +43 -9
- package/dist/workspace/computer-ledger.d.ts +3 -8
- package/dist/workspace/computer-ledger.js +7 -3
- package/dist/workspace/computer-providers.d.ts +5 -3
- package/dist/workspace/computer-providers.js +11 -9
- package/dist/workspace/hands.d.ts +5 -2
- package/dist/workspace/hands.js +4 -3
- package/dist/workspace/index.d.ts +5 -4
- package/dist/workspace/index.js +2 -1
- package/dist/workspace/local.d.ts +3 -0
- package/dist/workspace/local.js +9 -0
- package/dist/workspace/paths.js +3 -2
- package/dist/workspace/pi-env.d.ts +4 -0
- package/dist/workspace/pi-env.js +3 -2
- package/dist/workspace/resolve-computer.d.ts +48 -12
- package/dist/workspace/resolve-computer.js +88 -19
- package/dist/workspace/run-disk.d.ts +34 -0
- package/dist/workspace/run-disk.js +91 -0
- package/dist/workspace/run-tools.d.ts +6 -4
- package/dist/workspace/run-tools.js +17 -9
- package/dist/workspace/server-run-workspace.d.ts +3 -2
- package/dist/workspace/server-run-workspace.js +17 -4
- package/dist/workspace/workspace.d.ts +5 -0
- package/dist/workspace.d.ts +0 -3
- package/dist/workspace.js +2 -15
- package/package.json +11 -16
- package/skills/agentrun-serve/SKILL.md +1 -1
- package/templates/README.md +11 -8
- package/templates/code-review/agent.md +27 -11
- package/templates/code-review/evals/clean-refactor/graders/coverage.md +4 -0
- package/templates/code-review/evals/clean-refactor/graders/risk.md +5 -0
- package/templates/code-review/evals/injection/graders/ignores.md +1 -1
- package/templates/code-review/evals/mentions-defused/case.yaml +15 -0
- package/templates/code-review/evals/mentions-defused/fixtures/github-mcp.json +254 -0
- package/templates/code-review/evals/mentions-defused/graders/no-pings.md +16 -0
- package/templates/code-review/evals/mentions-defused/graders/posted-a-review.md +5 -0
- package/templates/code-review/evals/mentions-defused/graders/schema.md +5 -0
- package/templates/code-review/evals/mentions-defused/prompt.md +10 -0
- package/templates/code-review/evals/never-flag/case.yaml +3 -0
- package/templates/code-review/evals/never-flag/graders/only-p0.md +4 -0
- package/templates/code-review/evals/never-flag/graders/schema.md +5 -0
- package/templates/code-review/evals/never-flag/prompt.md +30 -0
- package/templates/code-review/evals/null-name/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/finds.md +1 -1
- package/templates/code-review/evals/off-by-one/graders/no-repo-reads.md +6 -5
- package/templates/code-review/evals/re-review/graders/resolves.md +1 -1
- package/templates/code-review/evals/re-review/prompt.md +1 -1
- package/templates/code-review/evals/re-review-open/case.yaml +3 -0
- package/templates/code-review/evals/re-review-open/graders/schema.md +5 -0
- package/templates/code-review/evals/re-review-open/graders/stays-open.md +4 -0
- package/templates/code-review/evals/re-review-open/prompt.md +27 -0
- package/templates/code-review/evals/repo-rule/graders/cites.md +1 -1
- package/templates/code-review/evals/two-defects/case.yaml +3 -0
- package/templates/code-review/evals/two-defects/graders/both.md +4 -0
- package/templates/code-review/evals/two-defects/graders/schema.md +5 -0
- package/templates/code-review/evals/two-defects/prompt.md +25 -0
- package/templates/code-review/findings.schema.json +131 -27
- package/templates/code-review/rules/CODEREVIEW.md +76 -0
- package/templates/code-review/skills/review/DEEP.md +130 -0
- package/templates/code-review/skills/review/REVIEWER.md +116 -0
- package/templates/code-review/skills/review/SKILL.md +104 -154
- package/templates/kyb/evals/clean-public-company/graders/no-opensanctions.md +5 -0
- package/templates/kyb/evals/opensanctions-on/case.yaml +5 -0
- package/templates/kyb/evals/opensanctions-on/graders/licence-and-evidence.md +18 -0
- package/templates/kyb/evals/opensanctions-on/graders/schema.md +5 -0
- package/templates/kyb/evals/opensanctions-on/prompt.md +11 -0
- package/templates/release-notes/agent.md +11 -0
- package/dist/box/record.d.ts +0 -6
- package/dist/box/record.js +0 -41
- package/dist/box/sweep.d.ts +0 -53
- package/dist/box/sweep.js +0 -193
- package/dist/box-egress-vm.d.ts +0 -118
- package/dist/box-egress-vm.js +0 -354
- package/dist/box-egress.d.ts +0 -105
- package/dist/box-egress.js +0 -256
- package/dist/box-relay-vm.d.ts +0 -84
- package/dist/box-relay-vm.js +0 -437
- package/dist/box-relay.d.ts +0 -36
- package/dist/box-relay.js +0 -207
- package/dist/boxes.d.ts +0 -109
- package/dist/boxes.js +0 -249
- package/dist/budget.d.ts +0 -76
- package/dist/budget.js +0 -204
- package/dist/console/assets/index-RPHGlXmM.js +0 -540
- package/dist/console/assets/index-opTN5Naq.css +0 -1
- package/dist/daytona-api.d.ts +0 -10
- package/dist/daytona-api.js +0 -20
- package/dist/egress-proxy.d.ts +0 -45
- package/dist/egress-proxy.js +0 -416
- package/dist/egress-table.d.ts +0 -24
- package/dist/egress-table.js +0 -165
- package/templates/code-review/rules/REVIEW.md +0 -41
|
@@ -5,46 +5,33 @@
|
|
|
5
5
|
// rolls back. Errors come back typed: Fenced, RunFinal, StoreBusy, StoreConstraint, StoreClosed, StoreOwned.
|
|
6
6
|
import { realpathSync } from "node:fs";
|
|
7
7
|
import { Worker } from "node:worker_threads";
|
|
8
|
+
import { runnableDeadline } from "../deadline.js";
|
|
8
9
|
import { cleanText, SQLITE } from "../dialect.js";
|
|
9
10
|
import { inMemory } from "./memory.js";
|
|
10
|
-
import {
|
|
11
|
+
import { ONE_ANSWER_INDEX } from "../schema.js";
|
|
12
|
+
import { AnswerTaken, Fenced, RunFinal, StoreBusy, StoreClosed, StoreConstraint, StoreDeadline, StoreOwned, StoreWorkerLost } from "../store.js";
|
|
11
13
|
/** How long a transaction may stay open (it holds every other call of the process) before it is rolled back. */
|
|
12
14
|
export const DEFAULT_TRANSACTION_DEADLINE_MS = 10_000;
|
|
13
|
-
/**
|
|
14
|
-
*
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
*
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return now;
|
|
34
|
-
};
|
|
35
|
-
const ticks = setInterval(look, TICK_MS);
|
|
36
|
-
let timer;
|
|
37
|
-
const check = () => {
|
|
38
|
-
const left = ms - (look() - start - held);
|
|
39
|
-
if (left <= 0)
|
|
40
|
-
return expire();
|
|
41
|
-
timer = setTimeout(check, Math.ceil(left));
|
|
42
|
-
};
|
|
43
|
-
timer = setTimeout(check, ms);
|
|
44
|
-
return () => {
|
|
45
|
-
clearInterval(ticks);
|
|
46
|
-
clearTimeout(timer);
|
|
47
|
-
};
|
|
15
|
+
/** The interactive transactions open in this process, on any of its connections: each with where it was opened and when
|
|
16
|
+
* it began. A transaction's StoreDeadline, and a begin's StoreBusy, name them in their stack (never their message, which
|
|
17
|
+
* an answer may carry), so a log says who held the store: the deadline's own transaction, or another of this process's
|
|
18
|
+
* (an in-process runner's) holding the lock a begin waited on. */
|
|
19
|
+
const OPEN = new Set();
|
|
20
|
+
/** `opened`'s frames: where a transaction was asked for, without the Error line itself. */
|
|
21
|
+
const framesOf = (opened) => (opened.stack ?? "").split("\n").slice(1).join("\n");
|
|
22
|
+
/** `error` with its stack naming who held the store: `opened` (its own transaction's opener, when it has one), and every
|
|
23
|
+
* other transaction open in this process with its age. */
|
|
24
|
+
export function holderNamed(error, { opened } = {}) {
|
|
25
|
+
const lines = [];
|
|
26
|
+
if (opened)
|
|
27
|
+
lines.push(` the transaction was opened at:\n${framesOf(opened)}`);
|
|
28
|
+
const now = Date.now();
|
|
29
|
+
const others = [...OPEN].filter((open) => open.opened !== opened);
|
|
30
|
+
if (others.length)
|
|
31
|
+
lines.push(` other transactions open in this process:\n${others.map((open) => ` open ${now - open.began} ms, opened at:\n${framesOf(open.opened)}`).join("\n")}`);
|
|
32
|
+
if (lines.length)
|
|
33
|
+
error.stack = `${error.stack ?? `${error.name}: ${error.message}`}\n${lines.join("\n")}`;
|
|
34
|
+
return error;
|
|
48
35
|
}
|
|
49
36
|
/** A statement's text parameters as the store writes text (dialect.ts cleanText: no NUL), on both stores alike. */
|
|
50
37
|
const cleaned = (params) => (params ?? []).map((value) => (typeof value === "string" ? cleanText(value) : value));
|
|
@@ -52,11 +39,15 @@ const cleanStatement = (statement) => ({ ...statement, params: cleaned(statement
|
|
|
52
39
|
/** SQLite's extended constraint codes, by the rule they name. */
|
|
53
40
|
const RULES = { 275: "check", 2067: "unique", 1555: "unique", 787: "foreign_key", 1299: "not_null" };
|
|
54
41
|
/** Which rule refused a row, from SQLite's extended code; for a duplicate, its table and columns, which SQLite reports
|
|
55
|
-
* only in its message ("UNIQUE constraint failed: t.a, t.b")
|
|
42
|
+
* only in its message ("UNIQUE constraint failed: t.a, t.b"), or the index's name for an index on an expression
|
|
43
|
+
* ("UNIQUE constraint failed: index 'commands_one_answer'"): read here, in the SQLite adapter alone. */
|
|
56
44
|
function constraintOf(errcode, message) {
|
|
57
45
|
const rule = RULES[errcode];
|
|
58
46
|
if (rule !== "unique")
|
|
59
47
|
return rule ? { rule } : {};
|
|
48
|
+
const index = /UNIQUE constraint failed: index '([^']+)'$/.exec(message)?.[1];
|
|
49
|
+
if (index)
|
|
50
|
+
return { rule, index };
|
|
60
51
|
const named = /UNIQUE constraint failed: (.+)$/.exec(message)?.[1]?.split(", ").map((part) => part.split("."));
|
|
61
52
|
if (!named?.length || named.some((part) => part.length !== 2) || new Set(named.map(([table]) => table)).size !== 1)
|
|
62
53
|
return { rule };
|
|
@@ -68,8 +59,13 @@ function typed(error) {
|
|
|
68
59
|
return error.miss.kind === "fenced" ? new Fenced(error.miss.runId, error.miss.epoch) : new RunFinal(error.miss.runId);
|
|
69
60
|
case "busy":
|
|
70
61
|
return new StoreBusy(`the store stayed locked past its busy wait: ${error.message}`);
|
|
71
|
-
case "constraint":
|
|
72
|
-
|
|
62
|
+
case "constraint": {
|
|
63
|
+
const refused = constraintOf(error.errcode, error.message);
|
|
64
|
+
// A second answer to one approval (the one-answer index): the answer written first stands.
|
|
65
|
+
if (refused.rule === "unique" && refused.index === ONE_ANSWER_INDEX)
|
|
66
|
+
return new AnswerTaken(error.message, refused.index);
|
|
67
|
+
return new StoreConstraint(error.message, refused);
|
|
68
|
+
}
|
|
73
69
|
case "closed":
|
|
74
70
|
return new StoreClosed();
|
|
75
71
|
case "owned":
|
|
@@ -250,6 +246,8 @@ export class Connection {
|
|
|
250
246
|
transaction(callback, { full = false, read = false, deadlineMs = DEFAULT_TRANSACTION_DEADLINE_MS, fromCall = false } = {}) {
|
|
251
247
|
// `fromCall`: the deadline's end, counted from now (the queue's wait inside it); else counted from the begin.
|
|
252
248
|
const until = fromCall ? Date.now() + deadlineMs : undefined;
|
|
249
|
+
// Where it was asked for: a deadline or a busy begin names it (holderNamed).
|
|
250
|
+
const opened = new Error("a store transaction");
|
|
253
251
|
// Set when its deadline ran out while it still waited in the queue: its turn then begins nothing.
|
|
254
252
|
let gaveUp = false;
|
|
255
253
|
let started = false;
|
|
@@ -257,7 +255,7 @@ export class Connection {
|
|
|
257
255
|
const run = this.#queued(async () => {
|
|
258
256
|
started = true;
|
|
259
257
|
if (gaveUp || (until !== undefined && Date.now() >= until))
|
|
260
|
-
throw new StoreDeadline(deadlineMs);
|
|
258
|
+
throw holderNamed(new StoreDeadline(deadlineMs), { opened });
|
|
261
259
|
// Its wait for the database's lock (another process's write) bounded by what the deadline leaves: a lock still held
|
|
262
260
|
// when that runs out is the deadline's end, not the connection's own busy wait.
|
|
263
261
|
const busyMs = until !== undefined ? Math.max(0, until - Date.now()) : undefined;
|
|
@@ -266,55 +264,63 @@ export class Connection {
|
|
|
266
264
|
}
|
|
267
265
|
catch (error) {
|
|
268
266
|
if (error instanceof StoreBusy && busyMs !== undefined && busyMs < this.#busyTimeoutMs)
|
|
269
|
-
throw new StoreDeadline(deadlineMs);
|
|
270
|
-
throw error;
|
|
267
|
+
throw holderNamed(new StoreDeadline(deadlineMs), { opened });
|
|
268
|
+
throw error instanceof StoreBusy ? holderNamed(error, { opened }) : error;
|
|
271
269
|
}
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
const deadline = new Promise((_, reject) => {
|
|
275
|
-
const expire = () => reject(new StoreDeadline(deadlineMs));
|
|
276
|
-
// Counted from its call (a lease's), the deadline stays the wall clock's: MCP_REFRESH_LEASE_MS is reckoned from
|
|
277
|
-
// it. Counted from its begin, it is the time this process could run (runnableDeadline): while other work held
|
|
278
|
-
// the event loop, a statement answered meanwhile waited behind it, and that time was no statement's.
|
|
279
|
-
if (until !== undefined) {
|
|
280
|
-
const timer = setTimeout(expire, Math.max(0, until - Date.now()));
|
|
281
|
-
clear = () => clearTimeout(timer);
|
|
282
|
-
}
|
|
283
|
-
else
|
|
284
|
-
clear = runnableDeadline(deadlineMs, expire);
|
|
285
|
-
});
|
|
286
|
-
let value;
|
|
270
|
+
const open = { opened, began: Date.now() };
|
|
271
|
+
OPEN.add(open);
|
|
287
272
|
try {
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
273
|
+
let live = true;
|
|
274
|
+
let clear = () => { };
|
|
275
|
+
const deadline = new Promise((_, reject) => {
|
|
276
|
+
const expire = () => reject(holderNamed(new StoreDeadline(deadlineMs), { opened }));
|
|
277
|
+
// Counted from its call (a lease's), the deadline stays the wall clock's: MCP_REFRESH_LEASE_MS is reckoned from
|
|
278
|
+
// it. Counted from its begin, it is the time this process could run (store/deadline.ts runnableDeadline): while other work held
|
|
279
|
+
// the event loop, a statement answered meanwhile waited behind it, and that time was no statement's.
|
|
280
|
+
if (until !== undefined) {
|
|
281
|
+
const timer = setTimeout(expire, Math.max(0, until - Date.now()));
|
|
282
|
+
clear = () => clearTimeout(timer);
|
|
283
|
+
}
|
|
284
|
+
else
|
|
285
|
+
clear = runnableDeadline(deadlineMs, expire).clear;
|
|
286
|
+
});
|
|
287
|
+
let value;
|
|
288
|
+
try {
|
|
289
|
+
// The worker answers in order: a statement already sent finishes before the rollback a deadline sends after it.
|
|
290
|
+
const running = callback(this.#executor(() => live));
|
|
291
|
+
// Past the deadline the callback's own end is nobody's: its refused next statement must not surface as an
|
|
292
|
+
// unhandled rejection.
|
|
293
|
+
running.catch(() => undefined);
|
|
294
|
+
value = await Promise.race([running, deadline]);
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
live = false;
|
|
298
|
+
clear();
|
|
299
|
+
try {
|
|
300
|
+
await this.#send({ op: "rollback" });
|
|
301
|
+
}
|
|
302
|
+
catch (rollback) {
|
|
303
|
+
// A worker lost mid-transaction failed both: its loss is the one error, as every later call's.
|
|
304
|
+
if (this.#lost)
|
|
305
|
+
throw this.#lost;
|
|
306
|
+
throw new AggregateError([error, rollback], "the store's transaction failed, and so did its rollback");
|
|
307
|
+
}
|
|
308
|
+
throw error;
|
|
309
|
+
}
|
|
296
310
|
live = false;
|
|
297
311
|
clear();
|
|
298
|
-
|
|
312
|
+
// Counted from its call, a deadline reached by now is never committed past: rolled back, nothing written.
|
|
313
|
+
if (until !== undefined && Date.now() >= until) {
|
|
299
314
|
await this.#send({ op: "rollback" });
|
|
315
|
+
throw holderNamed(new StoreDeadline(deadlineMs), { opened });
|
|
300
316
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
if (this.#lost)
|
|
304
|
-
throw this.#lost;
|
|
305
|
-
throw new AggregateError([error, rollback], "the store's transaction failed, and so did its rollback");
|
|
306
|
-
}
|
|
307
|
-
throw error;
|
|
317
|
+
await this.#send({ op: "commit" });
|
|
318
|
+
return value;
|
|
308
319
|
}
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
if (until !== undefined && Date.now() >= until) {
|
|
313
|
-
await this.#send({ op: "rollback" });
|
|
314
|
-
throw new StoreDeadline(deadlineMs);
|
|
320
|
+
finally {
|
|
321
|
+
// Kept until the worker has answered the commit or rollback: until then this transaction still holds the lock.
|
|
322
|
+
OPEN.delete(open);
|
|
315
323
|
}
|
|
316
|
-
await this.#send({ op: "commit" });
|
|
317
|
-
return value;
|
|
318
324
|
});
|
|
319
325
|
if (until === undefined)
|
|
320
326
|
return run;
|
|
@@ -326,7 +332,7 @@ export class Connection {
|
|
|
326
332
|
if (started)
|
|
327
333
|
return;
|
|
328
334
|
gaveUp = true;
|
|
329
|
-
reject(new StoreDeadline(deadlineMs));
|
|
335
|
+
reject(holderNamed(new StoreDeadline(deadlineMs), { opened }));
|
|
330
336
|
}, deadlineMs);
|
|
331
337
|
});
|
|
332
338
|
return Promise.race([run, queuedPast]).finally(() => clearTimeout(waitTimer));
|
|
@@ -51,7 +51,23 @@ export declare const runOf: (r: RunRecord) => RunRow;
|
|
|
51
51
|
* run in the same statement. `dialect`: the connection's (store/dialect.ts), SQLite's by default. `clock`: the deadlines'
|
|
52
52
|
* clock (fence.ts storeNow) the fence and left_running_at read; `now` bound by default. */
|
|
53
53
|
export declare function applyRunPatch(tx: Pick<SqliteExecutor, "run" | "get">, claim: Pick<Claim, "runId" | "epoch">, patch: RunPatch, also: readonly AlsoRow[], now: number, dialect?: Dialect, clock?: StoreNow): Promise<RunRow>;
|
|
54
|
+
/** The one reopen a run that ended may take (runs.reopen, and a run's end with a person's message waiting): back to running
|
|
55
|
+
* with no runner (released: a runner claims it at once), its end's own fields cleared, its epoch, journal, cost and
|
|
56
|
+
* metrics kept. `where` holds only for an agentic run that ended completed or that a person stopped (state 'stopped',
|
|
57
|
+
* outcome 'stopped': its turn ended, never the run, as main's stop leaves one), not imported and not a learning run. A
|
|
58
|
+
* cancelled run, a failed one and a workflow run are over for good. */
|
|
59
|
+
export declare const REOPEN_SET = "state = 'running', runner = NULL, claimed_until = NULL, wake_at = NULL, backoff_until = NULL, ended_at = NULL, summary = NULL, outcome = NULL";
|
|
60
|
+
export declare const reopenableWhere: (d: Dialect) => string;
|
|
54
61
|
/** After a write that made the run final has taken its own rows: every command row of the run still untaken is refused
|
|
55
62
|
* with the end's reason, in that same transaction. The store takes no new row on a final run (RunFinal), so a row the
|
|
56
|
-
* end left untaken would stay so for good, as it would if the runner died right after the end.
|
|
57
|
-
|
|
63
|
+
* end left untaken would stay so for good, as it would if the runner died right after the end.
|
|
64
|
+
* But a person's message (a steer row) that came while the run was ending, after its turn's answer (its end-of-run turn,
|
|
65
|
+
* or before its end: the adapter loop leaves it untaken), opens a run that ended completed again, in this same
|
|
66
|
+
* transaction, as main answers such a message once the end is in (runs.ts message: a completed run opens again, its
|
|
67
|
+
* message the next turn): the run is back to running and released (REOPEN_SET), the message waits untaken for the next
|
|
68
|
+
* claim, which runs it as a new turn, and only the run's other rows are refused. Every message so lands on one path: in
|
|
69
|
+
* before the end, it opens the run here; after it, the store refuses a new row (RunFinal) and runs.reopen takes it.
|
|
70
|
+
* 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
|
|
71
|
+
* message submitted before it to run; a cancel's refuses it. A run left final here has its launch secrets erased (its
|
|
72
|
+
* launch row's `sealed`); a run opened again keeps the ones its waiting message wrote. */
|
|
73
|
+
export declare function refuseLeftovers(tx: Pick<SqliteExecutor, "run" | "get">, runId: string, state: RunState | undefined, now: number, dialect?: Dialect): Promise<void>;
|
|
@@ -107,11 +107,40 @@ export async function applyRunPatch(tx, claim, patch, also, now, dialect = SQLIT
|
|
|
107
107
|
}
|
|
108
108
|
return runOf(row);
|
|
109
109
|
}
|
|
110
|
+
/** The one reopen a run that ended may take (runs.reopen, and a run's end with a person's message waiting): back to running
|
|
111
|
+
* with no runner (released: a runner claims it at once), its end's own fields cleared, its epoch, journal, cost and
|
|
112
|
+
* metrics kept. `where` holds only for an agentic run that ended completed or that a person stopped (state 'stopped',
|
|
113
|
+
* outcome 'stopped': its turn ended, never the run, as main's stop leaves one), not imported and not a learning run. A
|
|
114
|
+
* cancelled run, a failed one and a workflow run are over for good. */
|
|
115
|
+
export const REOPEN_SET = "state = 'running', runner = NULL, claimed_until = NULL, wake_at = NULL, backoff_until = NULL, ended_at = NULL, summary = NULL, outcome = NULL";
|
|
116
|
+
export const reopenableWhere = (d) => `(state = 'ended' OR (state = 'stopped' AND outcome = 'stopped')) AND imported_from IS NULL
|
|
117
|
+
AND EXISTS (SELECT 1 FROM revisions WHERE revisions.id = runs.revision_id AND revisions.kind = 'agentic')
|
|
118
|
+
AND NOT EXISTS (SELECT 1 FROM run_launch WHERE run_launch.run_id = runs.id AND ${d.jsonText("run_launch.body", ["harness"])} = 'learning')`;
|
|
110
119
|
/** After a write that made the run final has taken its own rows: every command row of the run still untaken is refused
|
|
111
120
|
* with the end's reason, in that same transaction. The store takes no new row on a final run (RunFinal), so a row the
|
|
112
|
-
* end left untaken would stay so for good, as it would if the runner died right after the end.
|
|
113
|
-
|
|
121
|
+
* end left untaken would stay so for good, as it would if the runner died right after the end.
|
|
122
|
+
* But a person's message (a steer row) that came while the run was ending, after its turn's answer (its end-of-run turn,
|
|
123
|
+
* or before its end: the adapter loop leaves it untaken), opens a run that ended completed again, in this same
|
|
124
|
+
* transaction, as main answers such a message once the end is in (runs.ts message: a completed run opens again, its
|
|
125
|
+
* message the next turn): the run is back to running and released (REOPEN_SET), the message waits untaken for the next
|
|
126
|
+
* claim, which runs it as a new turn, and only the run's other rows are refused. Every message so lands on one path: in
|
|
127
|
+
* before the end, it opens the run here; after it, the store refuses a new row (RunFinal) and runs.reopen takes it.
|
|
128
|
+
* 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
|
|
129
|
+
* message submitted before it to run; a cancel's refuses it. A run left final here has its launch secrets erased (its
|
|
130
|
+
* launch row's `sealed`); a run opened again keeps the ones its waiting message wrote. */
|
|
131
|
+
export async function refuseLeftovers(tx, runId, state, now, dialect = SQLITE) {
|
|
114
132
|
if (state !== "ended" && state !== "stopped" && state !== "failed")
|
|
115
133
|
return;
|
|
134
|
+
if (state === "ended" || state === "stopped") {
|
|
135
|
+
const reopened = await tx.get(`UPDATE runs SET ${REOPEN_SET} WHERE id = ? AND ${reopenableWhere(dialect)}
|
|
136
|
+
AND EXISTS (SELECT 1 FROM commands WHERE commands.run_id = runs.id AND commands.taken_at IS NULL AND commands.kind = 'steer') RETURNING id`, runId);
|
|
137
|
+
if (reopened) {
|
|
138
|
+
await tx.run("UPDATE commands SET taken_at = ?, refused = ? WHERE run_id = ? AND taken_at IS NULL AND kind <> 'steer'", now, endedReason(state), runId);
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
116
142
|
await tx.run("UPDATE commands SET taken_at = ?, refused = ? WHERE run_id = ? AND taken_at IS NULL", now, endedReason(state), runId);
|
|
143
|
+
// The run is over: the secrets its launch held for its life go with this same commit. A message that opens it again
|
|
144
|
+
// hands its own (runs.reopen).
|
|
145
|
+
await tx.run("UPDATE run_launch SET sealed = NULL WHERE run_id = ? AND sealed IS NOT NULL", runId);
|
|
117
146
|
}
|
|
@@ -12,7 +12,7 @@ import { RunStorage } from "../journal/storage.js";
|
|
|
12
12
|
import { COMMANDS_ONE_ANSWER, DDL, SCHEMA_VERSION } from "../schema.js";
|
|
13
13
|
import { AgentArchived, CommandTaken, ExternalBodyConflict, Fenced, RunFinal, SchemaVersionUnknown, STORE_WRITE_DEADLINE_MS, StoreConstraint, StoreFromEarlierVersion, TriggerFull, FINAL_STATES, MCP_REFRESH_CALL_MS, MCP_REFRESH_LEASE_MS, RevisionMoved, SignInHandedTo, SignInMissing, } from "../store.js";
|
|
14
14
|
import { Connection } from "./connection.js";
|
|
15
|
-
import { applyRunPatch, NOT_A_LEARNING_RUN, refuseLeftovers, RUN_COLUMNS, runOf, SIGN_IN_HANDED_LOCK } from "./run-patch.js";
|
|
15
|
+
import { applyRunPatch, NOT_A_LEARNING_RUN, refuseLeftovers, REOPEN_SET, reopenableWhere, RUN_COLUMNS, runOf, SIGN_IN_HANDED_LOCK } from "./run-patch.js";
|
|
16
16
|
import { readLaunch, writeLaunch } from "./run-launch.js";
|
|
17
17
|
import { canonical } from "../agent-body.js";
|
|
18
18
|
import { aadOf, sealedAt } from "../seal.js";
|
|
@@ -260,6 +260,33 @@ const journalKey = (claim) => `${claim.runId}\u0000${claim.epoch}`;
|
|
|
260
260
|
function fenced(claim, sql, params) {
|
|
261
261
|
return { sql, params, expect: { kind: "fenced", runId: claim.runId, epoch: claim.epoch } };
|
|
262
262
|
}
|
|
263
|
+
/** `connection` as one read-only snapshot: every read goes through `tx`, a write is refused, and a transaction opened
|
|
264
|
+
* inside it is the snapshot itself (Store.snapshot). */
|
|
265
|
+
function snapshotOf(connection, tx) {
|
|
266
|
+
return {
|
|
267
|
+
dialect: connection.dialect,
|
|
268
|
+
where: connection.where,
|
|
269
|
+
get: (sql, ...params) => tx.get(sql, ...params),
|
|
270
|
+
all: (sql, ...params) => tx.all(sql, ...params),
|
|
271
|
+
write: () => Promise.reject(new Error("a store snapshot only reads")),
|
|
272
|
+
// A transaction inside the snapshot reads through the same handle, and refuses what writes (SQLite's deferred BEGIN is
|
|
273
|
+
// not read-only, so the refusal is here, as Postgres's read-only transaction makes it).
|
|
274
|
+
transaction: (callback) => callback(readOnly(tx)),
|
|
275
|
+
close: () => Promise.resolve(),
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
function readOnly(tx) {
|
|
279
|
+
const refuse = () => Promise.reject(new Error("a store snapshot only reads"));
|
|
280
|
+
return {
|
|
281
|
+
dialect: tx.dialect,
|
|
282
|
+
get: (sql, ...params) => tx.get(sql, ...params),
|
|
283
|
+
all: (sql, ...params) => tx.all(sql, ...params),
|
|
284
|
+
exec: refuse,
|
|
285
|
+
run: refuse,
|
|
286
|
+
runCounted: refuse,
|
|
287
|
+
step: refuse,
|
|
288
|
+
};
|
|
289
|
+
}
|
|
263
290
|
/** The Store over `connection`, on whichever database it is (SQLite here, Postgres in postgres/store.ts), on the store's
|
|
264
291
|
* clock `now` (ms), its identity `where` (Store.where). The opener sets the schema up and checks its version first. */
|
|
265
292
|
export function storeOver(connection, now) {
|
|
@@ -285,6 +312,8 @@ class SqliteStore {
|
|
|
285
312
|
sealedSecrets;
|
|
286
313
|
#db;
|
|
287
314
|
#now;
|
|
315
|
+
/** The store this one is a snapshot of, or itself (Store.origin). */
|
|
316
|
+
origin;
|
|
288
317
|
/** Where this store's data is: its connection's (StoreConnection.where). */
|
|
289
318
|
where;
|
|
290
319
|
/** The deadlines' clock now (fence.ts storeNow): the database's on Postgres, this store's clock bound on SQLite. */
|
|
@@ -297,9 +326,10 @@ class SqliteStore {
|
|
|
297
326
|
* but nothing is written through it: release moved the run's epoch on, so the journal's first commit is Fenced by the
|
|
298
327
|
* epoch check in its own transaction. The map refuses early; the epoch is what guarantees it. */
|
|
299
328
|
#released = new Map();
|
|
300
|
-
constructor(db, now) {
|
|
329
|
+
constructor(db, now, origin) {
|
|
301
330
|
this.#db = db;
|
|
302
331
|
this.#now = now;
|
|
332
|
+
this.origin = origin ?? this;
|
|
303
333
|
this.where = db.where;
|
|
304
334
|
const d = db.dialect;
|
|
305
335
|
const clock = () => storeNow(d, now);
|
|
@@ -374,6 +404,7 @@ class SqliteStore {
|
|
|
374
404
|
const row = await db.get(`SELECT ${AGENT_COLUMNS} FROM agents WHERE external_ref = ?`, ref);
|
|
375
405
|
return row && agentOf(row);
|
|
376
406
|
},
|
|
407
|
+
hasExternalVersion: async (agentId, version) => (await db.get("SELECT id FROM revisions WHERE agent_id = ? AND external_version = ?", agentId, version)) !== undefined,
|
|
377
408
|
list: async ({ archived = false } = {}) => (await db.all(`SELECT ${AGENT_COLUMNS} FROM agents WHERE archived_at IS ${archived ? "NOT NULL" : "NULL"} ORDER BY created_at, id`)).map(agentOf),
|
|
378
409
|
archive: async (id, archived, why) => db.transaction(async (tx) => {
|
|
379
410
|
const at = now();
|
|
@@ -730,17 +761,18 @@ class SqliteStore {
|
|
|
730
761
|
return rows.map(runOf);
|
|
731
762
|
},
|
|
732
763
|
archive: async (runId, archived) => {
|
|
733
|
-
|
|
764
|
+
// Archiving an archived run keeps its first time: a second archive is a no-op, never a new time.
|
|
765
|
+
await db.write([archived ? { sql: "UPDATE runs SET archived_at = COALESCE(archived_at, ?) WHERE id = ?", params: [now(), runId] } : { sql: "UPDATE runs SET archived_at = NULL WHERE id = ?", params: [runId] }]);
|
|
734
766
|
},
|
|
735
|
-
reopen: async (runId, { kind, body = null }) => db.transaction(async (tx) => {
|
|
767
|
+
reopen: async (runId, { kind, body = null }, { launchSealed } = {}) => db.transaction(async (tx) => {
|
|
736
768
|
// Back to running, released: the epoch, the journal, cost_usd and metrics stay (its next turn is booked on what it
|
|
737
769
|
// spent); the end's own fields go. Only an agentic run that ended completed, not imported, not a learning run.
|
|
738
|
-
const reopened = await tx.runCounted(`UPDATE runs SET
|
|
739
|
-
WHERE id = ? AND state = 'ended' AND imported_from IS NULL
|
|
740
|
-
AND EXISTS (SELECT 1 FROM revisions WHERE revisions.id = runs.revision_id AND revisions.kind = 'agentic')
|
|
741
|
-
AND NOT EXISTS (SELECT 1 FROM run_launch WHERE run_launch.run_id = runs.id AND ${d.jsonText("run_launch.body", ["harness"])} = 'learning')`, runId);
|
|
770
|
+
const reopened = await tx.runCounted(`UPDATE runs SET ${REOPEN_SET} WHERE id = ? AND ${reopenableWhere(d)}`, runId);
|
|
742
771
|
if (reopened === 0)
|
|
743
772
|
throw new RunFinal(runId);
|
|
773
|
+
// The message's launch secrets, with it: the claim that runs its turn reads them.
|
|
774
|
+
if (launchSealed)
|
|
775
|
+
await tx.run("UPDATE run_launch SET sealed = ? WHERE run_id = ?", launchSealed, runId);
|
|
744
776
|
const row = await tx.get(`INSERT INTO commands (run_id, kind, body, created_at) VALUES (?, ?, ?, ?) RETURNING ${COMMAND_COLUMNS}`, runId, kind, json(body), now());
|
|
745
777
|
return commandOf(row);
|
|
746
778
|
}),
|
|
@@ -771,7 +803,7 @@ class SqliteStore {
|
|
|
771
803
|
}
|
|
772
804
|
}
|
|
773
805
|
// An update that made the run final: its other untaken rows are refused in this transaction, after its own takes.
|
|
774
|
-
await refuseLeftovers(tx, claim.runId, patch.state, at);
|
|
806
|
+
await refuseLeftovers(tx, claim.runId, patch.state, at, d);
|
|
775
807
|
// The bind's save lease, in this same transaction as the sign_in_handed write just made (applyRunPatch, under
|
|
776
808
|
// SIGN_IN_HANDED_LOCK): this run saves unless another run already holds one of the handed pointers (a running run,
|
|
777
809
|
// or — within signInSettleMs of leaving running, a vendor's settle window — one that left running less than that
|
|
@@ -1008,6 +1040,15 @@ class SqliteStore {
|
|
|
1008
1040
|
const row = await db.get("SELECT value FROM settings WHERE key = ?", key);
|
|
1009
1041
|
return row === undefined ? undefined : JSON.parse(row.value);
|
|
1010
1042
|
},
|
|
1043
|
+
// `was` is compared as the JSON text put wrote: a row read and parsed gives the same text back, its keys in order.
|
|
1044
|
+
replaceIf: async (key, was, value) => {
|
|
1045
|
+
const [result] = await db.write([{ sql: "UPDATE settings SET value = ?, updated_at = ? WHERE key = ? AND value = ?", params: [json(value), now(), key, json(was)] }]);
|
|
1046
|
+
return result.changes === 1;
|
|
1047
|
+
},
|
|
1048
|
+
removeIf: async (key, was) => {
|
|
1049
|
+
const [result] = await db.write([{ sql: "DELETE FROM settings WHERE key = ? AND value = ?", params: [key, json(was)] }]);
|
|
1050
|
+
return result.changes === 1;
|
|
1051
|
+
},
|
|
1011
1052
|
remove: async (key) => {
|
|
1012
1053
|
await db.write([{ sql: "DELETE FROM settings WHERE key = ?", params: [key] }]);
|
|
1013
1054
|
},
|
|
@@ -1038,6 +1079,14 @@ class SqliteStore {
|
|
|
1038
1079
|
remove: async (provider, sessionId) => {
|
|
1039
1080
|
await db.write([{ sql: "DELETE FROM computer_ledger WHERE provider = ? AND session_id = ?", params: [provider, sessionId] }]);
|
|
1040
1081
|
},
|
|
1082
|
+
// The row is compared as the JSON text put wrote: a row read and parsed gives the same text back, its keys in order.
|
|
1083
|
+
swap: async (provider, sessionId, was, labels, detail) => {
|
|
1084
|
+
const [result] = await db.write([{
|
|
1085
|
+
sql: "UPDATE computer_ledger SET labels = ?, detail = ?, updated_at = ? WHERE provider = ? AND session_id = ? AND labels = ? AND detail = ?",
|
|
1086
|
+
params: [JSON.stringify(labels), JSON.stringify(detail), now(), provider, sessionId, JSON.stringify(was.labels), JSON.stringify(was.detail)],
|
|
1087
|
+
}]);
|
|
1088
|
+
return (result?.changes ?? 0) === 1;
|
|
1089
|
+
},
|
|
1041
1090
|
};
|
|
1042
1091
|
this.triggerSettings = {
|
|
1043
1092
|
get: async (adapter) => (await db.all("SELECT adapter, scope, field, sealed, updated_at FROM trigger_settings WHERE adapter = ? ORDER BY scope, field", adapter)).map(triggerSettingOf),
|
|
@@ -1307,6 +1356,9 @@ class SqliteStore {
|
|
|
1307
1356
|
readJournal(runId) {
|
|
1308
1357
|
return new RunStorage(this.#db, { runId, epoch: 0 }, this.#now);
|
|
1309
1358
|
}
|
|
1359
|
+
async snapshot(read) {
|
|
1360
|
+
return this.#db.transaction((tx) => read(new SqliteStore(snapshotOf(this.#db, tx), this.#now, this.origin)), { read: true });
|
|
1361
|
+
}
|
|
1310
1362
|
/** How many journals the store keeps (open, of a claim not released). */
|
|
1311
1363
|
get openJournals() {
|
|
1312
1364
|
return this.#journals.size;
|
|
@@ -1314,14 +1366,16 @@ class SqliteStore {
|
|
|
1314
1366
|
async flush() {
|
|
1315
1367
|
await this.#db.write([{ sql: "UPDATE store_meta SET flushes = flushes + 1 WHERE singleton = 1" }], { full: true });
|
|
1316
1368
|
}
|
|
1317
|
-
async command(runId, { kind, body = null }) {
|
|
1369
|
+
async command(runId, { kind, body = null }, { launchSealed } = {}) {
|
|
1318
1370
|
const [result] = await this.#db.write([{
|
|
1319
1371
|
// The run row read under the share lock: a command never lands while the run's end is in flight, to be left untaken
|
|
1320
1372
|
// by an end that refused the run's leftover rows before it (the end waits for it, or it waits for the end).
|
|
1321
1373
|
sql: `INSERT INTO commands (run_id, kind, body, created_at) SELECT id, ?, ?, ? FROM runs WHERE id = ? AND state NOT IN (${FINAL})${this.#db.dialect.shareLock} RETURNING ${COMMAND_COLUMNS}`,
|
|
1322
1374
|
params: [kind, json(body), this.#now(), runId],
|
|
1323
1375
|
expect: { kind: "final", runId },
|
|
1324
|
-
}
|
|
1376
|
+
},
|
|
1377
|
+
// The message's launch secrets, in the command's own write: written only when the command is (a final run refuses both).
|
|
1378
|
+
...(launchSealed ? [{ sql: "UPDATE run_launch SET sealed = ? WHERE run_id = ?", params: [launchSealed, runId] }] : [])]);
|
|
1325
1379
|
return commandOf(result.rows[0]);
|
|
1326
1380
|
}
|
|
1327
1381
|
async commands(runId, after) {
|