@parcha/agentrun-serve 0.1.0-beta.58 → 0.1.0-beta.59
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 +325 -1
- package/README.md +332 -88
- package/dist/acp-package.d.ts +5 -1
- package/dist/acp-package.js +19 -2
- package/dist/adapters.d.ts +23 -2
- package/dist/adapters.js +106 -33
- package/dist/agents-store.js +1 -1
- package/dist/answer-text.d.ts +3 -0
- package/dist/answer-text.js +22 -0
- package/dist/attach-conformance.js +5 -4
- package/dist/box-paths.d.ts +3 -2
- package/dist/box-paths.js +5 -4
- package/dist/browser-computer.d.ts +3 -8
- package/dist/browser-computer.js +12 -35
- package/dist/browser-cost.js +94 -20
- package/dist/capacity.d.ts +1 -1
- package/dist/capacity.js +3 -3
- package/dist/chatgpt-plan.d.ts +5 -0
- package/dist/chatgpt-plan.js +25 -11
- package/dist/claude-login-token.d.ts +15 -11
- package/dist/claude-login-token.js +167 -107
- package/dist/claude-login.d.ts +76 -31
- package/dist/claude-login.js +426 -79
- package/dist/claude-sign-in.d.ts +3 -0
- package/dist/claude-sign-in.js +10 -1
- package/dist/cli.js +323 -292
- package/dist/composio-made.d.ts +1 -6
- package/dist/composio-made.js +1 -6
- package/dist/composio-owners.d.ts +26 -0
- package/dist/composio-owners.js +36 -0
- package/dist/composio-preset.d.ts +56 -23
- package/dist/composio-preset.js +173 -77
- package/dist/composio-triggers.d.ts +4 -4
- package/dist/composio-triggers.js +6 -7
- package/dist/compute-cost.js +11 -2
- package/dist/computer-attach.d.ts +6 -3
- package/dist/computer-attach.js +41 -29
- package/dist/computer-held-routes.d.ts +1 -1
- package/dist/computer-held-routes.js +9 -4
- package/dist/computer-keys.d.ts +11 -1
- package/dist/computer-keys.js +26 -1
- package/dist/computer-record.js +3 -1
- package/dist/computer-view.d.ts +5 -3
- package/dist/computer-view.js +10 -6
- package/dist/computer-viewer.js +36 -7
- package/dist/computers.d.ts +2 -1
- package/dist/computers.js +6 -3
- package/dist/console/THIRD-PARTY-NOTICES.txt +50 -0
- package/dist/console/assets/backend-BztxEAvb.js +166 -0
- package/dist/console/assets/index-LwNL4L9q.js +619 -0
- package/dist/console/assets/share-L84tlUDW.js +6 -0
- package/dist/console/assets/styles-CaRKlHke.js +291 -0
- package/dist/console/assets/styles-DQo8rzY-.css +1 -0
- package/dist/console/index.html +4 -3
- package/dist/console/share.html +17 -0
- package/dist/decisions.d.ts +17 -7
- package/dist/decisions.js +41 -15
- package/dist/dial-relay.js +10 -4
- package/dist/docker-daemon.js +4 -5
- package/dist/docker-host-addresses.js +29 -11
- package/dist/email/account.d.ts +6 -0
- package/dist/email/account.js +6 -0
- package/dist/email/authentication.d.ts +21 -0
- package/dist/email/authentication.js +106 -0
- package/dist/email/email-faux.d.ts +11 -2
- package/dist/email/email-faux.js +21 -5
- package/dist/email/mail.d.ts +25 -0
- package/dist/email/mail.js +58 -2
- package/dist/email/names.js +2 -2
- package/dist/email/tools.d.ts +9 -4
- package/dist/email/tools.js +95 -13
- package/dist/env-switch.d.ts +12 -2
- package/dist/env-switch.js +23 -3
- package/dist/errors.d.ts +1 -0
- package/dist/errors.js +2 -0
- package/dist/fal-price.d.ts +11 -1
- package/dist/fal-price.js +33 -0
- package/dist/faux-computers.js +1 -1
- package/dist/filed-answer.d.ts +2 -2
- package/dist/filed-answer.js +2 -2
- package/dist/graph-served.d.ts +10 -5
- package/dist/graph-served.js +40 -10
- package/dist/handed-values.js +1 -2
- package/dist/harness-check.d.ts +2 -1
- package/dist/harness-check.js +45 -12
- package/dist/harness-keys.js +9 -6
- package/dist/harness-opencode/facts.js +2 -0
- package/dist/harness-recipe-entry.d.ts +9 -3
- package/dist/harness-recipe-entry.js +18 -9
- package/dist/harness-recipe.d.ts +21 -0
- package/dist/harness-recipe.js +25 -3
- package/dist/harness-table.d.ts +8 -0
- package/dist/harness-table.js +17 -6
- package/dist/helper-env.d.ts +4 -1
- package/dist/helper-env.js +4 -1
- package/dist/host-check.d.ts +2 -3
- package/dist/host-check.js +13 -7
- package/dist/hosted-search.js +1 -1
- package/dist/import.d.ts +11 -8
- package/dist/import.js +437 -186
- package/dist/key-refusal.d.ts +9 -2
- package/dist/key-refusal.js +86 -32
- package/dist/learn/audit.d.ts +8 -5
- package/dist/learn/audit.js +15 -7
- package/dist/learn/compile.d.ts +5 -2
- package/dist/learn/compile.js +45 -21
- package/dist/learn/field-check.d.ts +111 -0
- package/dist/learn/field-check.js +174 -0
- package/dist/learn/ledger.d.ts +32 -29
- package/dist/learn/ledger.js +26 -19
- package/dist/learn/promote.d.ts +79 -36
- package/dist/learn/promote.js +60 -65
- package/dist/learn/secrets.d.ts +4 -0
- package/dist/learn/secrets.js +12 -0
- package/dist/learned-nodes.d.ts +8 -5
- package/dist/learned-nodes.js +8 -5
- package/dist/learned-workflow.d.ts +2 -1
- package/dist/learned-workflow.js +13 -10
- package/dist/learning-cost.d.ts +25 -8
- package/dist/learning-cost.js +23 -8
- package/dist/learning-setting.d.ts +6 -0
- package/dist/learning-setting.js +11 -1
- package/dist/listen-first.d.ts +5 -4
- package/dist/listen-first.js +4 -5
- package/dist/live-reach.d.ts +7 -0
- package/dist/live-reach.js +7 -0
- package/dist/mcp-api-only-origins.d.ts +15 -0
- package/dist/mcp-api-only-origins.js +40 -0
- package/dist/mcp-gateway.d.ts +16 -2
- package/dist/mcp-gateway.js +41 -3
- package/dist/mcp-oauth.d.ts +1 -1
- package/dist/mcp-oauth.js +3 -2
- package/dist/mcp-probe.d.ts +3 -0
- package/dist/mcp-probe.js +3 -0
- package/dist/mcp-secret-writes.d.ts +24 -2
- package/dist/mcp-secret-writes.js +30 -2
- package/dist/mcp-servers-store.d.ts +52 -14
- package/dist/mcp-servers-store.js +165 -61
- package/dist/mcp-sources.d.ts +1 -2
- package/dist/mcp-sources.js +1 -2
- package/dist/mcp-store.d.ts +5 -5
- package/dist/mcp-store.js +3 -3
- package/dist/mcp.js +1 -1
- package/dist/model-gateway.d.ts +1 -1
- package/dist/model-gateway.js +20 -36
- package/dist/ollama-provider.d.ts +23 -9
- package/dist/ollama-provider.js +49 -20
- package/dist/openapi.js +202 -51
- package/dist/otel/genai.d.ts +83 -7
- package/dist/otel/genai.js +69 -9
- package/dist/otel/tracer.d.ts +42 -13
- package/dist/otel/tracer.js +241 -56
- package/dist/page.d.ts +7 -1
- package/dist/page.js +76 -22
- package/dist/paid-calls.d.ts +6 -4
- package/dist/paid-calls.js +15 -7
- package/dist/place-offers.d.ts +55 -34
- package/dist/place-offers.js +93 -54
- package/dist/place.d.ts +13 -14
- package/dist/place.js +56 -41
- package/dist/print.js +1 -1
- package/dist/provider.d.ts +3 -2
- package/dist/provider.js +17 -8
- package/dist/redact/match.d.ts +27 -9
- package/dist/redact/match.js +266 -57
- package/dist/run-census.d.ts +1 -1
- package/dist/run-census.js +4 -5
- package/dist/run-cut.js +4 -5
- package/dist/run-export-store.d.ts +15 -0
- package/dist/run-export-store.js +30 -0
- package/dist/run-export.d.ts +139 -0
- package/dist/run-export.js +379 -0
- package/dist/run-file-cut.d.ts +5 -0
- package/dist/run-file-cut.js +13 -0
- package/dist/run-launch.js +16 -3
- package/dist/run-model-key.d.ts +15 -6
- package/dist/run-model-key.js +30 -31
- package/dist/run-reads-over-store.js +4 -4
- package/dist/run-secrets.js +3 -5
- package/dist/run-timeline-served.js +3 -1
- package/dist/runnable.js +2 -2
- package/dist/runner/adapter-loop.d.ts +35 -18
- package/dist/runner/adapter-loop.js +94 -47
- package/dist/runner/adapter-run-spec.d.ts +14 -1
- package/dist/runner/adapter-run-spec.js +64 -28
- package/dist/runner/adapters/pi.js +4 -2
- package/dist/runner/audit.d.ts +8 -5
- package/dist/runner/audit.js +37 -17
- package/dist/runner/beside.js +5 -6
- package/dist/runner/claim-secrets.d.ts +10 -3
- package/dist/runner/claim-secrets.js +29 -13
- package/dist/runner/cli-run-spec.d.ts +18 -0
- package/dist/runner/cli-run-spec.js +81 -46
- package/dist/runner/compare-end.d.ts +2 -1
- package/dist/runner/compare-end.js +25 -10
- package/dist/runner/conformance/harness.js +2 -3
- package/dist/runner/conformance/subject.d.ts +4 -1
- package/dist/runner/harness-loops.js +3 -3
- package/dist/runner/held.d.ts +5 -2
- package/dist/runner/journal-kinds.d.ts +4 -1
- package/dist/runner/journal-kinds.js +22 -4
- package/dist/runner/learned-first.js +20 -4
- package/dist/runner/learning-end.d.ts +2 -8
- package/dist/runner/learning-end.js +11 -19
- package/dist/runner/live-ticker.js +7 -5
- package/dist/runner/loop-contract.d.ts +0 -2
- package/dist/runner/loop.d.ts +7 -0
- package/dist/runner/loop.js +1 -0
- package/dist/runner/main.js +12 -11
- package/dist/runner/mcp-claim.js +21 -5
- package/dist/runner/meta-tools.js +3 -2
- package/dist/runner/metrics.d.ts +7 -0
- package/dist/runner/metrics.js +19 -0
- package/dist/runner/model-route.d.ts +10 -7
- package/dist/runner/model-route.js +79 -15
- package/dist/runner/native-loop.js +10 -8
- package/dist/runner/presence.d.ts +1 -4
- package/dist/runner/presence.js +6 -8
- package/dist/runner/promotion.d.ts +25 -13
- package/dist/runner/promotion.js +125 -50
- package/dist/runner/redact.d.ts +3 -1
- package/dist/runner/redact.js +5 -3
- package/dist/runner/responses-fetch.d.ts +36 -0
- package/dist/runner/responses-fetch.js +511 -0
- package/dist/runner/run-child-host.d.ts +20 -5
- package/dist/runner/run-child-host.js +179 -77
- package/dist/runner/run-child.js +11 -4
- package/dist/runner/runner-check.js +5 -1
- package/dist/runner/runner.d.ts +2 -3
- package/dist/runner/runner.js +13 -9
- package/dist/runner/sdk-loop.js +8 -8
- package/dist/runner/spec-holds.d.ts +8 -1
- package/dist/runner/spec-holds.js +9 -4
- package/dist/runner/workflow-calls.d.ts +9 -0
- package/dist/runner/workflow-calls.js +150 -0
- package/dist/runner/workflow-first.d.ts +120 -32
- package/dist/runner/workflow-first.js +218 -94
- package/dist/runner/workflow-spec.js +1 -1
- package/dist/runs-over-store.js +8 -7
- package/dist/save-once.d.ts +14 -0
- package/dist/save-once.js +31 -0
- package/dist/scrub-command.d.ts +34 -31
- package/dist/scrub-command.js +116 -147
- package/dist/sdk/runs.d.ts +6 -0
- package/dist/sdk/runs.js +89 -10
- package/dist/seal-key.js +4 -4
- package/dist/secret-cut.d.ts +3 -0
- package/dist/secret-cut.js +7 -1
- package/dist/secret-rules.d.ts +8 -1
- package/dist/secret-rules.js +482 -53
- package/dist/secrets.d.ts +51 -9
- package/dist/secrets.js +311 -21
- package/dist/server-keys.d.ts +4 -3
- package/dist/server-keys.js +4 -3
- package/dist/server-secrets-store.js +2 -4
- package/dist/server.d.ts +15 -3
- package/dist/server.js +312 -80
- package/dist/share-context.d.ts +22 -0
- package/dist/share-context.js +76 -0
- package/dist/shell-lex.d.ts +105 -0
- package/dist/shell-lex.js +646 -0
- package/dist/sign-ins-store.d.ts +5 -7
- package/dist/sign-ins-store.js +12 -16
- package/dist/sign-ins.d.ts +7 -11
- package/dist/sign-ins.js +40 -41
- package/dist/skills/agentrun-serve/SKILL.md +5 -2
- package/dist/start-switches.d.ts +6 -5
- package/dist/start-switches.js +8 -4
- package/dist/stats.d.ts +5 -1
- package/dist/stats.js +1 -1
- package/dist/store/agent-body.js +2 -2
- package/dist/store/dialect.d.ts +4 -0
- package/dist/store/dialect.js +1 -0
- package/dist/store/index.d.ts +2 -2
- package/dist/store/index.js +1 -1
- package/dist/store/mcp-record-keys.d.ts +10 -0
- package/dist/store/mcp-record-keys.js +13 -0
- package/dist/store/postgres/dialect.js +2 -0
- package/dist/store/postgres/migrations/0029_run_launch_census_settle.sql +28 -0
- package/dist/store/postgres/migrations/0030_learning_ledger_epoch.sql +40 -0
- package/dist/store/postgres/migrations/0031_learning_ledger_calls.sql +12 -0
- package/dist/store/postgres/store.js +4 -0
- package/dist/store/schema.d.ts +33 -10
- package/dist/store/schema.js +70 -16
- package/dist/store/seal.d.ts +4 -1
- package/dist/store/sqlite/run-launch.d.ts +3 -10
- package/dist/store/sqlite/run-launch.js +12 -23
- package/dist/store/sqlite/run-patch.d.ts +17 -10
- package/dist/store/sqlite/run-patch.js +50 -13
- package/dist/store/sqlite/store.d.ts +3 -0
- package/dist/store/sqlite/store.js +116 -34
- package/dist/store/store-schema.js +3 -4
- package/dist/store/store.d.ts +67 -32
- package/dist/store/store.js +14 -11
- package/dist/store-reads/analytics.d.ts +2 -1
- package/dist/store-reads/analytics.js +7 -5
- package/dist/store-reads/learning.d.ts +35 -26
- package/dist/store-reads/learning.js +120 -92
- package/dist/store-reads/stats.d.ts +2 -2
- package/dist/store-reads/stats.js +13 -7
- package/dist/store-view.js +10 -7
- package/dist/suggestions.d.ts +1 -1
- package/dist/suggestions.js +29 -13
- package/dist/template-eval.d.ts +72 -9
- package/dist/template-eval.js +358 -64
- package/dist/timeline/labels.d.ts +1 -1
- package/dist/timeline/labels.js +4 -3
- package/dist/timeline/timeline.d.ts +23 -11
- package/dist/timeline/timeline.js +115 -31
- package/dist/timeline/web-calls.d.ts +8 -6
- package/dist/timeline/web-calls.js +10 -6
- package/dist/tool-gate.d.ts +13 -1
- package/dist/tool-gate.js +43 -3
- package/dist/tool-keys-store.js +2 -4
- package/dist/tool-keys.d.ts +11 -0
- package/dist/tool-keys.js +16 -0
- package/dist/tool-plane.d.ts +50 -11
- package/dist/tool-plane.js +94 -30
- package/dist/tools.d.ts +5 -1
- package/dist/tools.js +7 -7
- package/dist/trigger-email.js +12 -6
- package/dist/triggers.d.ts +15 -34
- package/dist/triggers.js +119 -126
- package/dist/validate.d.ts +8 -1
- package/dist/validate.js +163 -23
- package/dist/web-fake.d.ts +2 -1
- package/dist/web-fake.js +8 -6
- package/dist/web-fetch.d.ts +8 -6
- package/dist/web-fetch.js +13 -11
- package/dist/web-holds.d.ts +32 -0
- package/dist/web-holds.js +86 -0
- package/dist/web-run.d.ts +32 -5
- package/dist/web-run.js +75 -28
- package/dist/web-save.js +23 -12
- package/dist/web-search.js +14 -25
- package/dist/wires.d.ts +4 -3
- package/dist/wires.js +5 -4
- package/dist/workspace/archil-claim.d.ts +12 -5
- package/dist/workspace/archil-claim.js +45 -5
- package/dist/workspace/attach.js +52 -19
- package/dist/workspace/attached-computers.d.ts +6 -2
- package/dist/workspace/attached-computers.js +5 -4
- package/dist/workspace/computer-deps.d.ts +23 -6
- package/dist/workspace/computer-deps.js +35 -17
- package/dist/workspace/computer-for-claim.d.ts +21 -4
- package/dist/workspace/computer-for-claim.js +160 -54
- package/dist/workspace/computer-intervals.d.ts +2 -0
- package/dist/workspace/computer-intervals.js +1 -1
- package/dist/workspace/computer-janitor.d.ts +48 -14
- package/dist/workspace/computer-janitor.js +153 -44
- package/dist/workspace/computer-kept.d.ts +158 -32
- package/dist/workspace/computer-kept.js +288 -63
- package/dist/workspace/computer-providers.d.ts +8 -3
- package/dist/workspace/computer-providers.js +12 -5
- package/dist/workspace/index.d.ts +1 -1
- package/dist/workspace/index.js +1 -1
- package/dist/workspace/local.js +41 -1
- package/dist/workspace/mount-revoke-left.d.ts +31 -0
- package/dist/workspace/mount-revoke-left.js +72 -0
- package/dist/workspace/paired-route.js +4 -5
- package/dist/workspace/resolve-computer.d.ts +5 -2
- package/dist/workspace/resolve-computer.js +9 -3
- package/dist/workspace/run-end-computers.d.ts +11 -5
- package/dist/workspace/run-end-computers.js +153 -28
- package/dist/workspace/run-tools.d.ts +22 -3
- package/dist/workspace/run-tools.js +17 -5
- package/dist/workspace/run-workspace.d.ts +14 -1
- package/dist/workspace/run-workspace.js +34 -1
- package/dist/workspace/workspace.d.ts +6 -0
- package/package.json +12 -13
- package/skills/agentrun-serve/SKILL.md +5 -2
- package/templates/README.md +22 -6
- package/dist/console/assets/backend-CSAWUqtZ.js +0 -166
- package/dist/console/assets/index-Bwn1oTem.css +0 -1
- package/dist/console/assets/index-DPh29cyz.js +0 -747
|
@@ -6,13 +6,15 @@
|
|
|
6
6
|
// the kept computer is ended, and a later resume makes a new one, said as any replaced computer is, and why.
|
|
7
7
|
//
|
|
8
8
|
// One server setting per run holds it (`computer_kept:<run id>`): its provider, its kind, its ref, the claim epoch its
|
|
9
|
-
// labels carry,
|
|
10
|
-
// off and attaches the computer. At its time it is ended by the parking runner's own timer and, whatever became of
|
|
9
|
+
// labels carry, the Archil disk its mount credential is on (where it holds the run's folder there), and the time it is
|
|
10
|
+
// kept until. The claim that parks writes it; the claim that resumes in time takes it off and attaches the computer. At its time it is ended by the parking runner's own timer and, whatever became of
|
|
11
11
|
// that process (a server's restart), by the janitor (computer-janitor.ts), which reads every row at each sweep and wakes
|
|
12
|
-
// at the earliest time still ahead. Ending one marks its row ending (no claim takes it after), deletes the computer
|
|
13
|
-
//
|
|
14
|
-
//
|
|
15
|
-
//
|
|
12
|
+
// at the earliest time still ahead. Ending one marks its row ending (no claim takes it after), deletes the computer and
|
|
13
|
+
// removes the mount credential of a run folder it held on Archil, then marks the row ended, so the resume says why its
|
|
14
|
+
// computer is new; a row left ending (its process died, or its delete or remove failed or hung mid-way) is ended again at
|
|
15
|
+
// the janitor's next pass, with no remove once the credential's ttl is past its time. A row whose run is final is
|
|
16
|
+
// removed, its computer deleted first: by the run's end, once the row reads ended (forgetEnded), so a follow-up never
|
|
17
|
+
// says that lapse again, and otherwise by the janitor's pass (none runs under --faux).
|
|
16
18
|
//
|
|
17
19
|
// A sandbox's run folder is the run's either way (bound from this machine, or on Archil, as before); what the keep adds is
|
|
18
20
|
// the rest of the machine (its other files, its processes). A synced folder's delta lands on the disk at the park; what
|
|
@@ -32,15 +34,24 @@
|
|
|
32
34
|
// names the runner and its process (`runner`, `incarnation`: the presence incarnation, runner/presence.ts), and while
|
|
33
35
|
// that runner is there under that incarnation and the keep lasts, the claim rule gives the run to that runner alone
|
|
34
36
|
// (store KEPT_PREFIX: no other runner's poll picks it, nothing is claimed and given back). A stop or cancel is exempt:
|
|
35
|
-
// any runner claims the run at once and ends it with no loop, never taking the row (runner.ts claimMore)
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
//
|
|
40
|
-
//
|
|
37
|
+
// any runner claims the run at once and ends it with no loop, never taking the row (runner.ts claimMore). The run is
|
|
38
|
+
// final then, so its machine has no user: the run's end (run-end-computers.ts) or any janitor's provider sweep deletes it
|
|
39
|
+
// wherever its provider lists it, and the row's runner ends the row at its time or its janitor's pass, reading the
|
|
40
|
+
// machine gone where it is, as when it deletes it itself. Once it is gone (its row stale
|
|
41
|
+
// for RUNNER_STALE_MS, a new incarnation) or refusing claims, any runner claims the run; a claim that then can't reach
|
|
42
|
+
// the machine says why: its runner is gone (computerLostWords), or it is there and ends it (computerHeldWords). A
|
|
43
|
+
// refusing runner is still there (store KEPT_PREFIX). A claim takes a row back by marking it taking (takeKept), never
|
|
44
|
+
// by removing it: the mark comes off once the claim holds the machine (keptTaken), and turns ending when it goes on
|
|
45
|
+
// without it (restoreKept: the claim goes on on a new machine, so that one is the run's no more and no claim takes it
|
|
46
|
+
// back), whatever it then reads of that runner. No janitor but that runner's ends a row pinned to a runner still there
|
|
47
|
+
// (sweepKept): that runner's own timer (endKept finishes a row so marked, or one still marked taking) or janitor does;
|
|
48
|
+
// once it is gone, any janitor does. No park writes over a row pinned to another runner still there, or marked taking
|
|
49
|
+
// (keepKept): it keeps nothing then, and its machine goes as at the run's end. So a machine a claim took and could not
|
|
50
|
+
// reach, or a park did not keep, is never left with no row to end it: a give-back the store fails, or a claim's process
|
|
51
|
+
// that died mid-way, leaves the row marked taking, and it is ended at its time as any row. A machine any runner reaches
|
|
52
|
+
// by its id (an exec vendor's sandbox, a phone) is not pinned, and moves.
|
|
41
53
|
import { connectOf } from "@parcha/agentrun-computer";
|
|
42
|
-
import {
|
|
43
|
-
import { FINAL_STATES, KEPT_PREFIX as KEPT_ROWS } from "../store/index.js";
|
|
54
|
+
import { FINAL_STATES, KEPT_PREFIX, RUNNER_STALE_MS } from "../store/index.js";
|
|
44
55
|
/** How long a park keeps the run's computer for its resume: 10 minutes. */
|
|
45
56
|
export const KEEP_MS = 10 * 60_000;
|
|
46
57
|
/** KEEP_MS in words. */
|
|
@@ -62,11 +73,18 @@ export const computerLapsedWords = (kind) => `The ${kind} wasn't kept: ${KEEP_WO
|
|
|
62
73
|
* (pinnedOf), that runner was gone by the resume, and the claiming runner could not reach it. Never names the runner:
|
|
63
74
|
* a runner's name carries its host's. */
|
|
64
75
|
export const computerLostWords = (kind) => `The ${kind} wasn't kept: the runner that kept it is gone.`;
|
|
76
|
+
/** Why the run's computer at its resume is a new one: the one kept at its park was pinned to the runner that kept it,
|
|
77
|
+
* that runner was still there but could not take the run back (refusing claims, or its word late), and the claiming
|
|
78
|
+
* runner could not reach the machine, so it went on on a new one and that runner ends the kept one (restoreKept). Never
|
|
79
|
+
* names the runner. */
|
|
80
|
+
export const computerHeldWords = (kind) => `The ${kind} wasn't kept: another runner kept it and couldn't take the run, so that runner ends it.`;
|
|
65
81
|
/** The live view's words once the kept computer's time passed, the run still parked. */
|
|
66
82
|
export const lapsedWords = (kind) => `${computerLapsedWords(kind)} A new one starts when the run goes on.`;
|
|
67
|
-
/** The
|
|
68
|
-
|
|
69
|
-
|
|
83
|
+
/** The live view's words, the run still parked, for a kept computer whose end began before its time: a claim that could
|
|
84
|
+
* not reach it went on without it (restoreKept), or a later park kept nothing beside another runner's row (keepKept).
|
|
85
|
+
* Its time did not pass, and nothing happens at it for this run, so no reason is given. */
|
|
86
|
+
export const unkeptWords = (kind) => `The ${kind} wasn't kept. A new one starts when the run goes on.`;
|
|
87
|
+
/** The settings key of `runId`'s kept computer (the store's KEPT_PREFIX, which its claim rule reads). */
|
|
70
88
|
export const keptKeyOf = (runId) => `${KEPT_PREFIX}${runId}`;
|
|
71
89
|
/** Whether a computer of `entry`, made with `options` (its settings' options under the configuration's, as the claim makes
|
|
72
90
|
* its provider), can be reached again only by the runner that kept it: a local provider's (a container on that
|
|
@@ -85,37 +103,26 @@ export function pinnedOf(entry, options = {}) {
|
|
|
85
103
|
}
|
|
86
104
|
/** Whether `kept` names `holder` as the runner that keeps it (the same name and the same process). */
|
|
87
105
|
export const keptBy = (kept, holder) => holder !== undefined && kept.runner === holder.runner && kept.incarnation === holder.incarnation;
|
|
88
|
-
/** The one rule
|
|
89
|
-
* row is pinned to a runner other than `self` that is
|
|
90
|
-
*
|
|
91
|
-
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
106
|
+
/** The one rule the janitor's kept pass leaves a kept row by (sweepKept), a park leaves another's row by (keepKept), and a
|
|
107
|
+
* claim gives a row back by (computer-for-claim.ts reattach): its row is pinned to a runner other than `self` that is
|
|
108
|
+
* still there under the row's incarnation (seen within RUNNER_STALE_MS, refusing claims or not: store KEPT_PREFIX
|
|
109
|
+
* states the one meaning, and why the claim rule alone also asks that it claims). Only that runner's engine or hub has
|
|
110
|
+
* the machine, so a delete from here either finds nothing (and marks the row ended, leaking it) or, where both runners
|
|
111
|
+
* list it (a dial vendor's account, a shared Docker engine), ends a machine its runner still keeps. The provider sweep
|
|
112
|
+
* asks nothing of this: it ends only a machine past its deadline or whose run is final, which has no user. The runners
|
|
113
|
+
* are read once per maker's call. A read that fails counts every pinned row as held elsewhere: ending another runner's
|
|
114
|
+
* machine blind would leak it or take it. */
|
|
94
115
|
export function heldElsewhere(holders) {
|
|
95
116
|
let there;
|
|
96
117
|
return async (kept) => {
|
|
97
118
|
const { runners } = holders;
|
|
98
119
|
if (kept.runner === undefined || keptBy(kept, holders.self) || !runners)
|
|
99
120
|
return false;
|
|
100
|
-
there ??= runners.live(
|
|
121
|
+
there ??= runners.live(RUNNER_STALE_MS).then((live) => new Set(live.map((one) => `${one.runner}\n${one.incarnation}`)), () => "unknown");
|
|
101
122
|
const live = await there;
|
|
102
123
|
return live === "unknown" || live.has(`${kept.runner}\n${kept.incarnation}`);
|
|
103
124
|
};
|
|
104
125
|
}
|
|
105
|
-
/** The kept machines a provider sweep leaves this pass, by provider id and computer id: each row not yet ended whose
|
|
106
|
-
* machine is held elsewhere (heldElsewhere, the kept pass's own rule). Throws when the rows can't be read: the sweep
|
|
107
|
-
* then can't tell which machines are kept, and must not guess. */
|
|
108
|
-
export async function sparedKept(deps) {
|
|
109
|
-
const rows = await deps.settings.all({ prefix: KEPT_PREFIX });
|
|
110
|
-
const elsewhere = heldElsewhere(deps);
|
|
111
|
-
const spared = new Set();
|
|
112
|
-
for (const row of rows) {
|
|
113
|
-
const kept = keptOf(row.value);
|
|
114
|
-
if (kept && !kept.ended && (await elsewhere(kept)))
|
|
115
|
-
spared.add(`${kept.provider}\n${kept.id}`);
|
|
116
|
-
}
|
|
117
|
-
return (provider, id) => spared.has(`${provider}\n${id}`);
|
|
118
|
-
}
|
|
119
126
|
/** How long one delete of a kept computer may take at the janitor's pass: past it the pass goes on, the row is left
|
|
120
127
|
* ending, and the next pass deletes it again (a Docker command has no timeout of its own). */
|
|
121
128
|
export const KEPT_DELETE_MS = 60_000;
|
|
@@ -123,64 +130,280 @@ export const KEPT_DELETE_MS = 60_000;
|
|
|
123
130
|
export function keptOf(value) {
|
|
124
131
|
if (!value || typeof value !== "object")
|
|
125
132
|
return undefined;
|
|
126
|
-
const { provider, kind, id, name, epoch, until, folder, runner, incarnation, ending, ended } = value;
|
|
133
|
+
const { provider, kind, id, name, epoch, until, folder, disk, runner, incarnation, taking, ending, ended } = value;
|
|
127
134
|
if (typeof provider !== "string" || (kind !== "desktop" && kind !== "phone" && kind !== "sandbox") || typeof id !== "string" || typeof name !== "string")
|
|
128
135
|
return undefined;
|
|
129
136
|
if (typeof epoch !== "number" || !Number.isSafeInteger(epoch) || typeof until !== "number" || !Number.isFinite(until))
|
|
130
137
|
return undefined;
|
|
131
138
|
if (folder !== undefined && folder !== "bind" && folder !== "archil" && folder !== "sync")
|
|
132
139
|
return undefined;
|
|
140
|
+
if (disk !== undefined && typeof disk !== "string")
|
|
141
|
+
return undefined;
|
|
133
142
|
// Its runner and incarnation together, or neither.
|
|
134
143
|
if ((runner === undefined) !== (incarnation === undefined))
|
|
135
144
|
return undefined;
|
|
136
145
|
if (runner !== undefined && (typeof runner !== "string" || typeof incarnation !== "string"))
|
|
137
146
|
return undefined;
|
|
138
|
-
|
|
147
|
+
if (taking !== undefined && (typeof taking !== "number" || !Number.isSafeInteger(taking)))
|
|
148
|
+
return undefined;
|
|
149
|
+
const held = { ...(folder === undefined ? {} : { folder: folder }), ...(typeof disk === "string" ? { disk } : {}), ...(typeof runner === "string" && typeof incarnation === "string" ? { runner, incarnation } : {}) };
|
|
139
150
|
if (ended === true)
|
|
140
151
|
return { provider, kind, id, name, epoch, until, ...held, ended: true };
|
|
141
|
-
|
|
152
|
+
if (ending === true)
|
|
153
|
+
return { provider, kind, id, name, epoch, until, ...held, ending: true };
|
|
154
|
+
return { provider, kind, id, name, epoch, until, ...held, ...(typeof taking === "number" ? { taking } : {}) };
|
|
142
155
|
}
|
|
143
|
-
/** The row as written: its fields in one order, so a compare-and-set reads the same text.
|
|
156
|
+
/** The row as written: its fields in one order, so a compare-and-set reads the same text. Marked ending or ended, it
|
|
157
|
+
* is no claim's take any more. */
|
|
144
158
|
const rowOf = (kept, state) => ({
|
|
145
159
|
provider: kept.provider, kind: kept.kind, id: kept.id, name: kept.name, epoch: kept.epoch, until: kept.until,
|
|
146
160
|
...(kept.folder === undefined ? {} : { folder: kept.folder }),
|
|
161
|
+
...(kept.disk === undefined ? {} : { disk: kept.disk }),
|
|
147
162
|
...(kept.runner === undefined || kept.incarnation === undefined ? {} : { runner: kept.runner, incarnation: kept.incarnation }),
|
|
163
|
+
...(state === undefined && kept.taking !== undefined ? { taking: kept.taking } : {}),
|
|
148
164
|
...(state === "ending" ? { ending: true } : state === "ended" ? { ended: true } : {}),
|
|
149
165
|
});
|
|
166
|
+
/** Whether `row` is `kept`'s keep, whoever is taking it back (a row a park wrote, the same once marked taking). */
|
|
167
|
+
const sameKeep = (row, kept) => row !== undefined && JSON.stringify(rowOf({ ...row, taking: undefined })) === JSON.stringify(rowOf({ ...kept, taking: undefined }));
|
|
150
168
|
/** `runId`'s kept computer, as its row reads now; undefined when there is none. */
|
|
151
169
|
export async function readKept(settings, runId) {
|
|
152
170
|
return keptOf(await settings.get(keptKeyOf(runId)));
|
|
153
171
|
}
|
|
154
|
-
/** Writes `kept` as `runId`'s kept computer
|
|
155
|
-
* reads the same text. */
|
|
172
|
+
/** Writes `kept` as `runId`'s kept computer, whatever the row held. Its fields in one order, so a later compare-and-set
|
|
173
|
+
* reads the same text. A park writes through keepKept. */
|
|
156
174
|
export async function writeKept(settings, runId, kept) {
|
|
157
175
|
const row = rowOf(kept);
|
|
158
176
|
await settings.put(keptKeyOf(runId), row);
|
|
159
177
|
return row;
|
|
160
178
|
}
|
|
161
|
-
/**
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
179
|
+
/** How many times a park reads the row again after a write that lost to another between its read and its write. */
|
|
180
|
+
const KEEP_TRIES = 3;
|
|
181
|
+
/**
|
|
182
|
+
* Writes `kept` as `runId`'s kept computer at the claim's park, by compare-and-set: from no row (putIfAbsent), or from the
|
|
183
|
+
* row as read (replaceIf). Its row as written, or undefined when the park keeps nothing.
|
|
184
|
+
*
|
|
185
|
+
* A row not yet ended that is pinned to another runner still there (`holders`, heldElsewhere: store KEPT_PREFIX's one
|
|
186
|
+
* meaning of there), that a claim is taking back (Kept.taking: it may be reaching the machine, or could not write what
|
|
187
|
+
* came of that), or that reads ending (its end begun, a claim that gave it back, a stop: whoever kept it, there or not)
|
|
188
|
+
* is never written over. Its end at its time (endKept) compares the row with the one its park wrote, and a janitor ends
|
|
189
|
+
* an ending row of a runner gone, so a row written over would leave its machine running with nothing to end it. The park
|
|
190
|
+
* keeps nothing then. Its row is marked ending where it is not yet: this claim went on without that machine, so no claim
|
|
191
|
+
* may take it back as the run's (a claim still reaching it then never uses it), and its end still finishes a row so
|
|
192
|
+
* marked. Any other row is replaced, as before: no runner, this claim's own runner, a runner gone (its row as its park
|
|
193
|
+
* wrote it), or one ended. A write that lost reads again, up to KEEP_TRIES times; past them the park keeps nothing.
|
|
194
|
+
* Throws where the store throws.
|
|
195
|
+
*
|
|
196
|
+
* Every write is under `claim`, the parking claim (Settings.putIfAbsent's and replaceIf's claim: the fence checked in the
|
|
197
|
+
* write's own transaction). A park runs before its claim's park commit, so a claim that lost the run by then (its lease
|
|
198
|
+
* ran out, and another claim may have parked and kept since) is refused (Fenced, thrown) and writes and marks nothing:
|
|
199
|
+
* the row the run's current claim wrote stays as it wrote it.
|
|
200
|
+
*/
|
|
201
|
+
export async function keepKept(settings, runId, kept, holders, claim) {
|
|
202
|
+
const key = keptKeyOf(runId);
|
|
203
|
+
const row = rowOf(kept);
|
|
204
|
+
const elsewhere = heldElsewhere(holders);
|
|
205
|
+
for (let tries = 0; tries < KEEP_TRIES; tries += 1) {
|
|
206
|
+
const was = await settings.get(key);
|
|
207
|
+
if (was === undefined) {
|
|
208
|
+
if (JSON.stringify(await settings.putIfAbsent(key, row, undefined, claim)) === JSON.stringify(row))
|
|
209
|
+
return row;
|
|
210
|
+
continue;
|
|
211
|
+
}
|
|
212
|
+
const other = keptOf(was);
|
|
213
|
+
if (other && !other.ended && (other.ending === true || other.taking !== undefined || (await elsewhere(other)))) {
|
|
214
|
+
if (!other.ending)
|
|
215
|
+
await settings.replaceIf(key, was, rowOf(other, "ending"), claim);
|
|
216
|
+
return undefined;
|
|
217
|
+
}
|
|
218
|
+
if (await settings.replaceIf(key, was, row, claim))
|
|
219
|
+
return row;
|
|
220
|
+
}
|
|
221
|
+
return undefined;
|
|
222
|
+
}
|
|
223
|
+
/** The compare-and-set every ending mark goes by: the row read, judged ("go": the delete may go on as it reads;
|
|
224
|
+
* "leave": its machine is not this delete's; "mark": marked ending, only while it still reads so), read again after a
|
|
225
|
+
* write that lost, up to KEEP_TRIES times. A read or write the store fails is tried again, up to GIVE_BACK_TRIES times
|
|
226
|
+
* in all; past them it is `unmarked` in the store's words. Never throws. */
|
|
227
|
+
async function markEnding(settings, runId, judge) {
|
|
228
|
+
const key = keptKeyOf(runId);
|
|
229
|
+
let id;
|
|
230
|
+
try {
|
|
231
|
+
return await tried(async () => {
|
|
232
|
+
for (let tries = 0; tries < KEEP_TRIES; tries += 1) {
|
|
233
|
+
const was = await settings.get(key);
|
|
234
|
+
const kept = keptOf(was);
|
|
235
|
+
id = kept?.id ?? id;
|
|
236
|
+
const verdict = judge(kept);
|
|
237
|
+
if (verdict === "go")
|
|
238
|
+
return { kind: "marked", ...(kept?.ending ? { kept: rowOf(kept, "ending") } : {}) };
|
|
239
|
+
if (verdict === "leave")
|
|
240
|
+
return { kind: "left", ...(kept ? { id: kept.id } : {}) };
|
|
241
|
+
const ending = rowOf(kept, "ending");
|
|
242
|
+
if (await settings.replaceIf(key, was, ending))
|
|
243
|
+
return { kind: "marked", kept: ending };
|
|
244
|
+
}
|
|
245
|
+
return { kind: "unmarked", ...(id === undefined ? {} : { id }), why: "the row kept changing" };
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
catch (error) {
|
|
249
|
+
return { kind: "unmarked", ...(id === undefined ? {} : { id }), why: words(error) };
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
/** Marks `runId`'s kept row ending at the run's end (run-end-computers.ts), for the claim at `epoch` that ended the run:
|
|
253
|
+
* the run is final, so a machine kept at or before that claim has no user, whichever runner kept it or older claim is
|
|
254
|
+
* taking it back. No claim takes it back after, so the run's end deleting it and its keeper's end agree; the keeper's
|
|
255
|
+
* end at its time, or any janitor's pass, finishes the row. A row of a later claim (its machine made at a later epoch,
|
|
256
|
+
* or a later claim taking it back: a follow-up that queued the run again while this end waited on the store) is left
|
|
257
|
+
* as that claim wrote it, and so is its machine (`left`). A store that fails the mark is asked again (markEnding);
|
|
258
|
+
* `unmarked` past every try, and the run's end then deletes no machine the row names. */
|
|
259
|
+
export async function endingKept(settings, runId, epoch) {
|
|
260
|
+
return markEnding(settings, runId, (kept) => {
|
|
261
|
+
if (!kept || kept.ending || kept.ended)
|
|
262
|
+
return "go";
|
|
263
|
+
return kept.epoch > epoch || (kept.taking ?? 0) > epoch ? "leave" : "mark";
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
/** Marks `runId`'s kept row ending before a janitor's provider sweep deletes `machine`, the one the row kept when the
|
|
267
|
+
* sweep listed it (computer-janitor.ts thisServers). The sweep ends only a machine past its deadline or whose run is final, but the row's
|
|
268
|
+
* runner may still be there and its row unmarked (that runner died before its run's end ran, or the end could not mark
|
|
269
|
+
* it): marked first, no claim takes the machine back mid-delete. A row a claim is taking back, or one gone since the
|
|
270
|
+
* read (a claim took it), is a claim's: `left`, and the sweep leaves the machine. A row that keeps another machine
|
|
271
|
+
* now, or already reads ending or ended, needs no mark. */
|
|
272
|
+
export async function endingKeptMachine(settings, runId, machine) {
|
|
273
|
+
return markEnding(settings, runId, (kept) => {
|
|
274
|
+
if (!kept)
|
|
275
|
+
return "leave";
|
|
276
|
+
if (kept.provider !== machine.provider || kept.id !== machine.id || kept.ending || kept.ended)
|
|
277
|
+
return "go";
|
|
278
|
+
return kept.taking === undefined ? "mark" : "leave";
|
|
279
|
+
});
|
|
280
|
+
}
|
|
281
|
+
/** Takes `row` off `runId`'s row, only while it still reads so: a keep written for a park that never followed. */
|
|
282
|
+
export async function dropKept(settings, runId, row) {
|
|
283
|
+
return settings.removeIf(keptKeyOf(runId), row);
|
|
284
|
+
}
|
|
285
|
+
/** How many times a claim's take-back writes what came of it (keptTaken, restoreKept) when the store fails the write. */
|
|
286
|
+
const GIVE_BACK_TRIES = 3;
|
|
287
|
+
/** `work` again while it throws, up to GIVE_BACK_TRIES times in all; the last throw is thrown. */
|
|
288
|
+
async function tried(work) {
|
|
289
|
+
for (let tries = 1;; tries += 1) {
|
|
290
|
+
try {
|
|
291
|
+
return await work();
|
|
292
|
+
}
|
|
293
|
+
catch (error) {
|
|
294
|
+
if (tries >= GIVE_BACK_TRIES)
|
|
295
|
+
throw error;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
/** Marks `kept` taking on its row for the claim at `epoch` that resumes in time (Kept.taking), under `claim` (the store's
|
|
300
|
+
* fence: a claim that lost the run takes nothing): the row as marked when this call took it, undefined when its end (or
|
|
301
|
+
* another claim) had it first. The row stays while the claim reaches the machine: it holds it once keptTaken takes the
|
|
302
|
+
* mark off, and goes on without it through restoreKept. */
|
|
303
|
+
export async function takeKept(settings, runId, kept, epoch, claim) {
|
|
304
|
+
const taking = rowOf({ ...kept, taking: epoch });
|
|
305
|
+
return (await settings.replaceIf(keptKeyOf(runId), rowOf(kept), taking, claim)) ? taking : undefined;
|
|
306
|
+
}
|
|
307
|
+
/** The claim that marked `taking` (takeKept) reached its machine: the row taken off, only while it still reads so. True
|
|
308
|
+
* when the machine is the claim's; false when the row changed since (its end began at its time, a park or a stop marked
|
|
309
|
+
* it ending), and the claim must not use it. A write the store fails is tried again; past GIVE_BACK_TRIES it throws. */
|
|
310
|
+
export async function keptTaken(settings, runId, taking) {
|
|
311
|
+
return tried(() => settings.removeIf(keptKeyOf(runId), taking));
|
|
312
|
+
}
|
|
313
|
+
/** The claim that marked `taking` (takeKept) goes on without its machine (it could not reach it, or could not say it
|
|
314
|
+
* holds it): the row turned ending, whoever kept it and whether that runner is there or not, so no claim takes that
|
|
315
|
+
* machine back as the run's (nor does the claim rule pin the run to it). Its runner's end at its time (endKept, which
|
|
316
|
+
* finishes a row its park wrote that reads ending) or its janitor's next pass deletes it; once it is gone, or where any
|
|
317
|
+
* runner reaches it, any janitor's pass does. A row this claim took the mark off (it reached the machine, then failed
|
|
318
|
+
* before it could use it) is put back so, only while the key has none. A write the store fails is tried again. True when
|
|
319
|
+
* the row reads ending (or ended) after; false when it does not (the store failed every try, and the row is left marked
|
|
320
|
+
* taking, which is ended at its time all the same). */
|
|
321
|
+
export async function restoreKept(settings, runId, taking) {
|
|
322
|
+
const key = keptKeyOf(runId);
|
|
323
|
+
const ending = rowOf(taking, "ending");
|
|
324
|
+
try {
|
|
325
|
+
return await tried(async () => {
|
|
326
|
+
if (await settings.replaceIf(key, taking, ending))
|
|
327
|
+
return true;
|
|
328
|
+
// No row: this claim took the mark off (keptTaken) and then could not go on with the machine. Put back so.
|
|
329
|
+
const was = await settings.get(key);
|
|
330
|
+
const now = keptOf(was === undefined ? await settings.putIfAbsent(key, ending) : was);
|
|
331
|
+
return sameKeep(now, taking) && (now.ending === true || now.ended === true);
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
catch {
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
165
337
|
}
|
|
166
|
-
/** Ends a kept computer at its time: its row marked ending, only while it still reads `kept
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
*
|
|
338
|
+
/** Ends a kept computer at its time: its row marked ending, only while it still reads `kept`, or `kept` marked taking by
|
|
339
|
+
* a claim (one that is reaching it, or could not write what came of that: its time is over all the same, and the claim
|
|
340
|
+
* never uses it once the mark is gone, keptTaken), then `end` (its delete), then the row marked ended. A claim that took
|
|
341
|
+
* it since (the row gone) or a park that wrote another has it. A row already ending (a process that died mid-way, a
|
|
342
|
+
* delete that failed, a claim that gave it back, a park that kept nothing else or a stop: restoreKept, keepKept,
|
|
343
|
+
* endingKept) is deleted again. A delete that fails leaves the row ending, for the janitor's next pass, and throws its
|
|
344
|
+
* words. True when this call ended it. */
|
|
170
345
|
export async function endKept(settings, runId, kept, end) {
|
|
346
|
+
const key = keptKeyOf(runId);
|
|
171
347
|
const ending = rowOf(kept, "ending");
|
|
172
|
-
if (!kept.ending && !(await settings.replaceIf(
|
|
173
|
-
|
|
348
|
+
if (!kept.ending && !(await settings.replaceIf(key, rowOf(kept), ending))) {
|
|
349
|
+
const was = await settings.get(key);
|
|
350
|
+
const now = keptOf(was);
|
|
351
|
+
if (JSON.stringify(was) !== JSON.stringify(ending) && !(now?.taking !== undefined && sameKeep(now, kept) && (await settings.replaceIf(key, was, ending))))
|
|
352
|
+
return false;
|
|
353
|
+
}
|
|
174
354
|
await end();
|
|
175
|
-
return settings.replaceIf(
|
|
355
|
+
return settings.replaceIf(key, ending, rowOf(kept, "ended"));
|
|
356
|
+
}
|
|
357
|
+
/** Marks `runId`'s kept row ended once a delete that marked it ending (a run's end, a janitor's provider sweep: the
|
|
358
|
+
* `kept` of KeptEnding's `marked`) took its machine: only while the row still reads that ending row, so a row changed
|
|
359
|
+
* since is left. A row left ending refuses every later park of the run (keepKept) until a janitor's pass ends it, so a
|
|
360
|
+
* follow-up to a stopped run would keep nothing; ended, the next park writes over it. The delete's caller says only
|
|
361
|
+
* where its provider answered ok for that very machine, so a machine its list never showed (another runner's engine)
|
|
362
|
+
* keeps its row ending for its keeper to end. A row whose machine held the run's folder on Archil, its credential's
|
|
363
|
+
* disk named (Kept.disk), is marked ended only once `revokeMount` removed that credential: an ended row is one no
|
|
364
|
+
* janitor pass removes a credential for, so one marked ended first would leave it valid for its ttl with no machine.
|
|
365
|
+
* Without `revokeMount`, or with one that throws, the row is left ending, and the janitor's kept pass (sweepKept)
|
|
366
|
+
* removes the credential and ends it. Never throws: a row left ending is still ended at its time. */
|
|
367
|
+
export async function finishedKept(settings, runId, kept, revokeMount) {
|
|
368
|
+
if (kept.folder === "archil" && kept.disk !== undefined) {
|
|
369
|
+
if (!revokeMount)
|
|
370
|
+
return false;
|
|
371
|
+
try {
|
|
372
|
+
await revokeMount(runId, kept);
|
|
373
|
+
}
|
|
374
|
+
catch {
|
|
375
|
+
return false;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
return settings.replaceIf(keptKeyOf(runId), rowOf(kept, "ending"), rowOf(kept, "ended")).catch(() => false);
|
|
379
|
+
}
|
|
380
|
+
/** Removes `runId`'s kept row at the run's end (run-end-computers.ts: the claim at `epoch` ended the run), after its
|
|
381
|
+
* deletes answered or its bound passed: one read of the row, then a remove only while it still reads as read. Removed
|
|
382
|
+
* only where it reads ended (its machine gone: this end's delete marked it so, finishedKept, or its keeper's end at its
|
|
383
|
+
* time or a janitor's pass did before) and was kept at or before `epoch`. Whoever ended it, the run is final, so no
|
|
384
|
+
* resume of this run is left to read it and say why its computer is new; removed, a follow-up that queues the run again
|
|
385
|
+
* reads no keep and never says that lapse. A row that reads ending (a delete not done or not proven), none, and a later
|
|
386
|
+
* claim's keep are left. True when removed; false when left, or when the read or the remove failed. Never throws. */
|
|
387
|
+
export async function forgetEnded(settings, runId, epoch) {
|
|
388
|
+
try {
|
|
389
|
+
const was = await settings.get(keptKeyOf(runId));
|
|
390
|
+
const kept = keptOf(was);
|
|
391
|
+
if (kept?.ended !== true || kept.epoch > epoch)
|
|
392
|
+
return false;
|
|
393
|
+
return await settings.removeIf(keptKeyOf(runId), was);
|
|
394
|
+
}
|
|
395
|
+
catch {
|
|
396
|
+
return false;
|
|
397
|
+
}
|
|
176
398
|
}
|
|
177
399
|
/**
|
|
178
400
|
* The janitor's pass over every kept row: one whose run is final in the store, or no longer there, has its computer
|
|
179
401
|
* deleted (unless its time already ended it) and the row removed; one past its time, or left ending, is ended (endKept),
|
|
180
|
-
* each delete bounded by `deleteMs` (KEPT_DELETE_MS)
|
|
402
|
+
* each delete bounded by `deleteMs` (KEPT_DELETE_MS), and one on Archil has its mount credentials removed (`revokeMount`).
|
|
403
|
+
* The rest are left, the earliest of their times answered as `next`.
|
|
181
404
|
* `providerOf`: the provider a row names, made with this server's keys, or undefined when this server can't make it (its
|
|
182
405
|
* keys gone): that row is left and said. A row pinned to a runner other than this one (`self`) that is still there under
|
|
183
|
-
* the row's incarnation (`runners`, seen within
|
|
406
|
+
* the row's incarnation (`runners`, seen within RUNNER_STALE_MS) is left whatever its time or its run: only that
|
|
184
407
|
* runner's engine or hub has its machine, so a delete from here would find nothing, mark it ended and leak the machine.
|
|
185
408
|
* That runner's own timer, or its janitor, ends it; once it is gone the row is ended here as any other. Never throws.
|
|
186
409
|
*/
|
|
@@ -195,8 +418,7 @@ export async function sweepKept(deps) {
|
|
|
195
418
|
catch (error) {
|
|
196
419
|
return { ended, failed: [`the kept computers could not be read: ${words(error)}`] };
|
|
197
420
|
}
|
|
198
|
-
// The runners there now, read once for the pass, only where a row is pinned to another runner (heldElsewhere
|
|
199
|
-
// provider sweep leaves the same machines by the same rule, computer-janitor.ts).
|
|
421
|
+
// The runners there now, read once for the pass, only where a row is pinned to another runner (heldElsewhere).
|
|
200
422
|
const othersThere = heldElsewhere(deps);
|
|
201
423
|
for (const row of rows) {
|
|
202
424
|
const runId = row.key.slice(KEPT_PREFIX.length);
|
|
@@ -228,11 +450,14 @@ export async function sweepKept(deps) {
|
|
|
228
450
|
failed.push(`${kept.name} of run ${runId}: this server can't reach ${kept.provider} to end it`);
|
|
229
451
|
continue;
|
|
230
452
|
}
|
|
231
|
-
const
|
|
232
|
-
|
|
453
|
+
const cut = new AbortController();
|
|
454
|
+
const proven = async () => {
|
|
455
|
+
if (await deleteKept(provider, kept))
|
|
233
456
|
await deps.deleted?.(kept.provider, kept.id);
|
|
234
|
-
|
|
235
|
-
|
|
457
|
+
if (kept.folder === "archil")
|
|
458
|
+
await deps.revokeMount?.(runId, kept, cut.signal);
|
|
459
|
+
};
|
|
460
|
+
const deleted = await endKept(deps.settings, runId, kept, () => bounded(deps.deleteMs ?? KEPT_DELETE_MS, proven()).finally(() => cut.abort(new Error("the janitor's bound on the delete passed"))));
|
|
236
461
|
if (deleted)
|
|
237
462
|
ended.push(kept.name);
|
|
238
463
|
if (deleted && over)
|
|
@@ -10,9 +10,14 @@ export type ProviderLoad = (id: string, options: Record<string, unknown>, claim?
|
|
|
10
10
|
/** Settings → Computers' factories (createComputerRoutes' `factories`, its account test) from the same makers, so serve
|
|
11
11
|
* builds a provider in one place: each made with its options and `ledgerOf` its id's ledger. */
|
|
12
12
|
export declare function computerProviderFactories(makers: ProviderMakers, ledgerOf: (id: string) => unknown): ProviderFactories;
|
|
13
|
+
/** `env`'s values of `names` (a descriptor's hostEnv), and no other variable of it. */
|
|
14
|
+
export declare function hostEnvOf(env: NodeJS.ProcessEnv, names: readonly string[]): Record<string, string>;
|
|
13
15
|
/** Every provider in `entries` (the computer package's PROVIDERS, each from its descriptor), made through `load`
|
|
14
|
-
* (providerFor) from its options, plus the server's ledger as the option its descriptor names, when it declares one
|
|
15
|
-
|
|
16
|
+
* (providerFor) from its options, plus the server's ledger as the option its descriptor names, when it declares one, and
|
|
17
|
+
* `env`'s values of the host variables it declares (hostEnv) as its `env`. Without `env`, no `env` option is added, and
|
|
18
|
+
* the package gives such a provider none. */
|
|
19
|
+
export declare function computerProviderMakers({ load, entries, env }?: {
|
|
16
20
|
readonly load?: ProviderLoad;
|
|
17
|
-
readonly entries?: readonly Pick<ProviderEntry, "id" | "ledger">[];
|
|
21
|
+
readonly entries?: readonly Pick<ProviderEntry, "id" | "ledger" | "hostEnv">[];
|
|
22
|
+
readonly env?: NodeJS.ProcessEnv;
|
|
18
23
|
}): ProviderMakers;
|
|
@@ -2,18 +2,25 @@
|
|
|
2
2
|
// declares, built by its providerFor from the options its saved keys fill (computer-keys.ts providerOptions, by its
|
|
3
3
|
// descriptor's key names), and nothing else. A provider whose descriptor declares a ledger (its sessions carry no labels
|
|
4
4
|
// of their own) is given the store's computer ledger, as the option its descriptor names. No key reaches a provider any
|
|
5
|
-
// other way, and nothing here reads the environment or names a vendor
|
|
5
|
+
// other way, and nothing here reads the environment or names a vendor: a provider whose descriptor names the host
|
|
6
|
+
// variables it reads (hostEnv) is given the caller's values of those names alone.
|
|
6
7
|
import { PROVIDERS, providerFor } from "@parcha/agentrun-computer";
|
|
7
8
|
/** Settings → Computers' factories (createComputerRoutes' `factories`, its account test) from the same makers, so serve
|
|
8
9
|
* builds a provider in one place: each made with its options and `ledgerOf` its id's ledger. */
|
|
9
10
|
export function computerProviderFactories(makers, ledgerOf) {
|
|
10
11
|
return Object.fromEntries(Object.entries(makers).map(([id, make]) => [id, (options) => make(options, { ledger: ledgerOf(id) })]));
|
|
11
12
|
}
|
|
13
|
+
/** `env`'s values of `names` (a descriptor's hostEnv), and no other variable of it. */
|
|
14
|
+
export function hostEnvOf(env, names) {
|
|
15
|
+
return Object.fromEntries(names.flatMap((name) => (env[name] === undefined ? [] : [[name, String(env[name])]])));
|
|
16
|
+
}
|
|
12
17
|
/** Every provider in `entries` (the computer package's PROVIDERS, each from its descriptor), made through `load`
|
|
13
|
-
* (providerFor) from its options, plus the server's ledger as the option its descriptor names, when it declares one
|
|
14
|
-
|
|
15
|
-
|
|
18
|
+
* (providerFor) from its options, plus the server's ledger as the option its descriptor names, when it declares one, and
|
|
19
|
+
* `env`'s values of the host variables it declares (hostEnv) as its `env`. Without `env`, no `env` option is added, and
|
|
20
|
+
* the package gives such a provider none. */
|
|
21
|
+
export function computerProviderMakers({ load = providerFor, entries = PROVIDERS, env } = {}) {
|
|
22
|
+
return Object.fromEntries(entries.map(({ id, ledger, hostEnv }) => [
|
|
16
23
|
id,
|
|
17
|
-
(options, extras) => load(id, { ...options, ...(ledger === undefined ? {} : { [ledger.option]: extras.ledger }) }, extras.boxAllow === undefined ? {} : { boxAllow: extras.boxAllow }),
|
|
24
|
+
(options, extras) => load(id, { ...options, ...(ledger === undefined ? {} : { [ledger.option]: extras.ledger }), ...(hostEnv && env ? { env: hostEnvOf(env, hostEnv) } : {}) }, extras.boxAllow === undefined ? {} : { boxAllow: extras.boxAllow }),
|
|
18
25
|
]));
|
|
19
26
|
}
|
|
@@ -18,7 +18,7 @@ export { NO_PROGRAMS_WORDS, portOf } from "./computer-ports.js";
|
|
|
18
18
|
export { registryHere } from "./resolve-computer.js";
|
|
19
19
|
export { COMPUTER_MCP_NAME, computerMcp, type ComputerMcpAnswer, mcpAnswerOf } from "./computer-mcp.js";
|
|
20
20
|
export { type ClaimSide, computerReadiness, type ComputerSetting, type KindRegistry, type LaunchedComputer, type Port, resolveComputer, type ResolvedComputer, runShellOf, type ShellPlace, shellPlaceOf, type StartedComputer, } from "./resolve-computer.js";
|
|
21
|
-
export { computerProviderFactories, computerProviderMakers, type ProviderLoad } from "./computer-providers.js";
|
|
21
|
+
export { computerProviderFactories, computerProviderMakers, hostEnvOf, type ProviderLoad } from "./computer-providers.js";
|
|
22
22
|
export { claimComputer, claimKinds, type ComputerDeps, computerDepsFrom, type ComputerDepsOptions, computerSpecOf, DAEMON_CACHE_IN_VOLUME, DOCKER_HOST_ADDRESSES_ENV, type DockerComputerOptions, dockerHostAddressesOf, dockerVolumeOf, } from "./computer-deps.js";
|
|
23
23
|
export { type ClaimComputer, type ClaimLaunch, computerForClaim, type ComputerForClaimDeps, type ComputerRun, type ComputerSaid, type ImageWait, type OpenComputerView, type ProviderMakers, type ViewEnd } from "./computer-for-claim.js";
|
|
24
24
|
export { JANITOR_EVERY_MS, type JanitorDeps, type ProviderSweep, startJanitor, sweepServerComputers } from "./computer-janitor.js";
|
package/dist/workspace/index.js
CHANGED
|
@@ -20,7 +20,7 @@ export { NO_PROGRAMS_WORDS, portOf } from "./computer-ports.js";
|
|
|
20
20
|
export { registryHere } from "./resolve-computer.js";
|
|
21
21
|
export { COMPUTER_MCP_NAME, computerMcp, mcpAnswerOf } from "./computer-mcp.js";
|
|
22
22
|
export { computerReadiness, resolveComputer, runShellOf, shellPlaceOf, } from "./resolve-computer.js";
|
|
23
|
-
export { computerProviderFactories, computerProviderMakers } from "./computer-providers.js";
|
|
23
|
+
export { computerProviderFactories, computerProviderMakers, hostEnvOf } from "./computer-providers.js";
|
|
24
24
|
export { claimComputer, claimKinds, computerDepsFrom, computerSpecOf, DAEMON_CACHE_IN_VOLUME, DOCKER_HOST_ADDRESSES_ENV, dockerHostAddressesOf, dockerVolumeOf, } from "./computer-deps.js";
|
|
25
25
|
export { computerForClaim } from "./computer-for-claim.js";
|
|
26
26
|
export { JANITOR_EVERY_MS, startJanitor, sweepServerComputers } from "./computer-janitor.js";
|
package/dist/workspace/local.js
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
import { spawn } from "node:child_process";
|
|
35
35
|
import { randomBytes } from "node:crypto";
|
|
36
36
|
import { constants } from "node:fs";
|
|
37
|
-
import { access, lstat, mkdir as makeDir, open, readdir, realpath, rename, rmdir, unlink } from "node:fs/promises";
|
|
37
|
+
import { access, link, lstat, mkdir as makeDir, open, readdir, realpath, rename, rmdir, unlink } from "node:fs/promises";
|
|
38
38
|
import { join } from "node:path";
|
|
39
39
|
import { Worker } from "node:worker_threads";
|
|
40
40
|
import { attachedWorkspace, checkReadBack, noProcesses } from "./attach.js";
|
|
@@ -379,6 +379,46 @@ class LocalWorkspace {
|
|
|
379
379
|
}
|
|
380
380
|
}, { make: true });
|
|
381
381
|
}
|
|
382
|
+
async writeNew(path, data) {
|
|
383
|
+
const bytes = bytesOf(data);
|
|
384
|
+
const segments = LocalWorkspace.#below(path, "a file");
|
|
385
|
+
const name = segments.at(-1);
|
|
386
|
+
return this.#in(path, segments, segments.length - 1, async (dir) => {
|
|
387
|
+
try {
|
|
388
|
+
// The bytes in a temporary file of their own first, made durable; then a hard link gives them the name, which the
|
|
389
|
+
// kernel refuses (EEXIST) when anything is at it, a file, a folder or a link, in the same step that would make it.
|
|
390
|
+
const temp = `.workspace-${randomBytes(8).toString("hex")}.tmp`;
|
|
391
|
+
const handle = await dir.open(temp, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0o666);
|
|
392
|
+
let made = false;
|
|
393
|
+
try {
|
|
394
|
+
await handle.writeFile(bytes);
|
|
395
|
+
await handle.sync();
|
|
396
|
+
await handle.close();
|
|
397
|
+
await dir.confirm(path);
|
|
398
|
+
try {
|
|
399
|
+
await link(dir.at(temp), dir.at(name));
|
|
400
|
+
made = true;
|
|
401
|
+
}
|
|
402
|
+
catch (error) {
|
|
403
|
+
if (errno(error) !== "EEXIST")
|
|
404
|
+
throw error;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
catch (error) {
|
|
408
|
+
await handle.close().catch(() => undefined);
|
|
409
|
+
throw error;
|
|
410
|
+
}
|
|
411
|
+
finally {
|
|
412
|
+
await unlink(dir.at(temp)).catch(() => undefined);
|
|
413
|
+
}
|
|
414
|
+
await dir.handle.sync();
|
|
415
|
+
return made;
|
|
416
|
+
}
|
|
417
|
+
catch (error) {
|
|
418
|
+
throw failed(error, path);
|
|
419
|
+
}
|
|
420
|
+
}, { make: true });
|
|
421
|
+
}
|
|
382
422
|
async append(path, data) {
|
|
383
423
|
const bytes = bytesOf(data);
|
|
384
424
|
const segments = LocalWorkspace.#below(path, "a file");
|