@north-light/cli 0.3.709 → 0.3.711
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/contract.d.ts +1 -1
- package/dist/api/contract.js +1 -1
- package/dist/clients/attach/input/capabilities.js +1 -1
- package/dist/clients/attach/input/controller.d.ts +1 -1
- package/dist/clients/attach/input/controller.js +2 -2
- package/dist/clients/attach/render/chat-view.d.ts +13 -2
- package/dist/clients/attach/render/chat-view.js +2 -2
- package/dist/clients/attach/session/input-wiring.d.ts +2 -2
- package/dist/clients/attach/session/layout-record.d.ts +15 -0
- package/dist/clients/attach/session/layout-record.js +1 -0
- package/dist/clients/attach/session/reconnect.d.ts +8 -1
- package/dist/clients/attach/session/reconnect.js +1 -1
- package/dist/clients/attach/session/teardown.d.ts +2 -0
- package/dist/clients/attach/session/teardown.js +3 -3
- package/dist/clients/attach/slash/dispatch.js +2 -2
- package/dist/clients/attach/slash/recover.d.ts +10 -0
- package/dist/clients/attach/slash/recover.js +3 -0
- package/dist/clients/attach/viewer.js +520 -516
- package/dist/commands/human/prompts.js +1 -1
- package/dist/commands/human/request.js +1 -1
- package/dist/commands/sys/doctor.js +1 -1
- package/dist/commands/sys/tutorial/scenario.js +2 -2
- package/dist/core/broker-client/client.d.ts +2 -0
- package/dist/core/broker-client/client.js +1 -1
- package/dist/core/broker-client/transport-relay.d.ts +6 -0
- package/dist/core/broker-client/transport-relay.js +1 -1
- package/dist/core/broker-client/transport.d.ts +4 -0
- package/dist/core/canvas/daemon-actions.d.ts +1 -1
- package/dist/core/canvas/daemon-actions.js +7 -7
- package/dist/core/canvas/deliveries.d.ts +1 -1
- package/dist/core/canvas/deliveries.js +21 -21
- package/dist/core/canvas/executions.d.ts +1 -1
- package/dist/core/canvas/executions.js +1 -1
- package/dist/core/canvas/managed-worktree-sweep-candidates.d.ts +2 -2
- package/dist/core/canvas/managed-worktree-sweep-candidates.js +5 -3
- package/dist/core/canvas/reconciler-leases.d.ts +4 -0
- package/dist/core/canvas/reconciler-leases.js +5 -5
- package/dist/core/canvas/schema-pg/028-machine-calls-worktree-sweep.sql +6 -0
- package/dist/core/canvas/schema-version.d.ts +1 -1
- package/dist/core/canvas/schema-version.js +1 -1
- package/dist/core/conversation-store/client.js +2 -2
- package/dist/core/conversation-store/index.d.ts +5 -2
- package/dist/core/conversation-store/row-store.js +14 -12
- package/dist/core/graph/package-docs.js +5 -5
- package/dist/core/graph/package-publish.js +4 -3
- package/dist/core/human/requests.js +19 -19
- package/dist/core/import/load/run.js +2 -2
- package/dist/core/runtime/broker/client-registry.d.ts +1 -1
- package/dist/core/runtime/broker/client-registry.js +1 -1
- package/dist/core/runtime/broker/turn-replies.js +3 -1
- package/dist/core/runtime/broker-protocol.d.ts +4 -4
- package/dist/core/runtime/broker-protocol.js +3 -3
- package/dist/core/runtime/broker-request.d.ts +2 -0
- package/dist/core/runtime/broker-request.js +1 -1
- package/dist/core/runtime/broker.js +1 -1
- package/dist/core/runtime/model-swap.d.ts +2 -1
- package/dist/core/runtime/model-swap.js +1 -1
- package/dist/core/runtime/placement-tmux.d.ts +2 -1
- package/dist/core/runtime/placement-tmux.js +1 -1
- package/dist/core/runtime/runner/machine/call.js +2 -2
- package/dist/core/runtime/runner/machine/ops.d.ts +11 -1
- package/dist/core/runtime/runner/machine/ops.js +1 -1
- package/dist/core/runtime/session-cycles.d.ts +21 -0
- package/dist/core/runtime/session-cycles.js +1 -1
- package/dist/core/runtime/tmux-driver.d.ts +7 -0
- package/dist/core/runtime/tmux-driver.js +6 -6
- package/dist/core/worktree-machine.d.ts +4 -1
- package/dist/core/worktree-machine.js +1 -1
- package/dist/core/worktree-sweep.d.ts +14 -3
- package/dist/core/worktree-sweep.js +4 -4
- package/dist/daemon/api/app-listener.js +1 -1
- package/dist/daemon/api/handlers/charges.d.ts +1 -1
- package/dist/daemon/api/handlers/charges.js +1 -1
- package/dist/daemon/api/handlers/conversations.js +4 -3
- package/dist/daemon/api/handlers/environments.d.ts +1 -1
- package/dist/daemon/api/handlers/environments.js +1 -1
- package/dist/daemon/api/handlers/limits.js +1 -1
- package/dist/daemon/api/handlers/nodes.js +1 -1
- package/dist/daemon/api/operations.js +1 -1
- package/dist/daemon/api/router.js +1 -1
- package/dist/daemon/cron/live-runs.d.ts +3 -0
- package/dist/daemon/cron/live-runs.js +1 -1
- package/dist/daemon/cron/machine-fire.js +1 -1
- package/dist/daemon/crtrd.js +12 -12
- package/dist/daemon/due-sources.d.ts +1 -1
- package/dist/daemon/due-sources.js +1 -1
- package/dist/daemon/due.js +7 -7
- package/dist/daemon/fleet.d.ts +1 -1
- package/dist/daemon/fleet.js +4 -4
- package/dist/daemon/human/finish.js +3 -3
- package/dist/daemon/human/settle.js +1 -1
- package/dist/daemon/reconcilers/action-lane.js +1 -1
- package/dist/daemon/reconcilers/delivery-lane.js +2 -2
- package/dist/daemon/reconcilers/grant-effects.js +1 -1
- package/dist/daemon/reconcilers/managed-worktree-sweep.js +1 -1
- package/dist/daemon/reconcilers/node-lifecycle/requested-stops.js +2 -2
- package/dist/daemon/runs/observer.d.ts +4 -0
- package/dist/daemon/runs/observer.js +1 -1
- package/dist/pi-extensions/canvas-inbox-watcher.js +1 -1
- package/package.json +4 -3
- package/packages/crouter-api/dist/api/contract.js +1 -1
- package/packages/crouter-api/dist/clients/attach/input/capabilities.js +1 -0
- package/packages/crouter-api/dist/clients/attach/input/controller.js +2 -2
- package/packages/crouter-api/dist/clients/attach/render/chat-view.js +40 -3
- package/packages/crouter-api/dist/clients/attach/session/layout-record.js +52 -0
- package/packages/crouter-api/dist/clients/attach/session/reconnect.js +41 -2
- package/packages/crouter-api/dist/clients/attach/session/teardown.js +2 -0
- package/packages/crouter-api/dist/clients/attach/slash/dispatch.js +12 -0
- package/packages/crouter-api/dist/clients/attach/slash/recover.js +133 -0
- package/packages/crouter-api/dist/clients/attach/viewer.js +24 -5
- package/packages/crouter-api/dist/commands/human/prompts.js +11 -18
- package/packages/crouter-api/dist/commands/human/request.js +3 -0
- package/packages/crouter-api/dist/commands/sys/doctor.js +17 -0
- package/packages/crouter-api/dist/commands/sys/tutorial/scenario.js +1 -0
- package/packages/crouter-api/dist/core/broker-client/client.js +4 -0
- package/packages/crouter-api/dist/core/broker-client/transport-relay.js +45 -0
- package/packages/crouter-api/dist/core/canvas/daemon-actions.js +3 -2
- package/packages/crouter-api/dist/core/canvas/deliveries.js +7 -3
- package/packages/crouter-api/dist/core/canvas/executions.js +8 -7
- package/packages/crouter-api/dist/core/canvas/reconciler-leases.js +4 -0
- package/packages/crouter-api/dist/core/canvas/schema-version.js +1 -1
- package/packages/crouter-api/dist/core/conversation-store/client.js +1 -1
- package/packages/crouter-api/dist/core/conversation-store/row-store.js +14 -1
- package/packages/crouter-api/dist/core/graph/package-docs.js +8 -3
- package/packages/crouter-api/dist/core/graph/package-publish.js +8 -1
- package/packages/crouter-api/dist/core/human/requests.js +2 -2
- package/packages/crouter-api/dist/core/runtime/broker-ownership.js +6 -0
- package/packages/crouter-api/dist/core/runtime/broker-protocol.js +4 -4
- package/packages/crouter-api/dist/core/runtime/broker-request.js +1 -1
- package/packages/crouter-api/dist/core/runtime/model-swap.js +2 -1
- package/packages/crouter-api/dist/core/runtime/placement-tmux.js +3 -3
- package/packages/crouter-api/dist/core/runtime/runner/machine/call.js +1 -1
- package/packages/crouter-api/dist/core/runtime/runner/machine/executor.js +235 -0
- package/packages/crouter-api/dist/core/runtime/runner/machine/ops.js +1 -1
- package/packages/crouter-api/dist/core/runtime/session-cycles.js +90 -8
- package/packages/crouter-api/dist/core/runtime/tmux-driver.js +11 -0
- package/packages/crouter-api/dist/core/worktree-machine.js +20 -0
- package/packages/crouter-api/dist/core/worktree-sweep.js +439 -0
- package/packages/crouter-api/dist/daemon/api/operations.js +3 -3
- package/packages/crouter-api/dist/daemon/api/router.js +1 -4
- package/packages/crouter-api/dist/daemon/cron/live-runs.js +4 -5
- package/packages/crouter-api/dist/daemon/cron/machine-fire.js +3 -3
- package/packages/crouter-api/dist/daemon/human/finish.js +2 -1
- package/packages/crouter-api/dist/daemon/human/settle.js +1 -6
- package/packages/crouter-api/dist/daemon/runs/observer.js +1 -1
- package/packages/crouter-api/package.json +1 -1
- package/packages/crouter-identity/package.json +1 -1
- package/packages/crouter-plugin/package.json +3 -3
- package/runtime.lock.json +14 -14
- package/scripts/install-runtime.mjs +18 -1
- package/scripts/lib/install-source.mjs +49 -0
- package/dist/daemon/reconcilers/idle-sandbox.d.ts +0 -18
- package/dist/daemon/reconcilers/idle-sandbox.js +0 -7
package/runtime.lock.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@north-light/cli",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.711",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@north-light/cli",
|
|
9
|
-
"version": "0.3.
|
|
9
|
+
"version": "0.3.711",
|
|
10
10
|
"hasInstallScript": true,
|
|
11
11
|
"license": "UNLICENSED",
|
|
12
12
|
"workspaces": [
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
"@milkdown/preset-gfm": "^7.22.3",
|
|
29
29
|
"@milkdown/prose": "^7.22.3",
|
|
30
30
|
"@milkdown/utils": "^7.22.3",
|
|
31
|
-
"@north-light/identity": "0.3.
|
|
32
|
-
"@north-light/plugin": "0.3.
|
|
31
|
+
"@north-light/identity": "0.3.711",
|
|
32
|
+
"@north-light/plugin": "0.3.711",
|
|
33
33
|
"cron-parser": "^5.6.0",
|
|
34
34
|
"esbuild": "0.28.2",
|
|
35
35
|
"jose": "^6.2.12",
|
|
@@ -11902,17 +11902,17 @@
|
|
|
11902
11902
|
},
|
|
11903
11903
|
"packages/crouter-api": {
|
|
11904
11904
|
"name": "@north-light/api",
|
|
11905
|
-
"version": "0.3.
|
|
11905
|
+
"version": "0.3.711",
|
|
11906
11906
|
"license": "UNLICENSED"
|
|
11907
11907
|
},
|
|
11908
11908
|
"packages/crouter-env-docker": {
|
|
11909
11909
|
"name": "@north-light/env-docker",
|
|
11910
|
-
"version": "0.3.
|
|
11910
|
+
"version": "0.3.711",
|
|
11911
11911
|
"license": "UNLICENSED"
|
|
11912
11912
|
},
|
|
11913
11913
|
"packages/crouter-identity": {
|
|
11914
11914
|
"name": "@north-light/identity",
|
|
11915
|
-
"version": "0.3.
|
|
11915
|
+
"version": "0.3.711",
|
|
11916
11916
|
"license": "UNLICENSED",
|
|
11917
11917
|
"dependencies": {
|
|
11918
11918
|
"jose": "^6.2.1"
|
|
@@ -11920,21 +11920,21 @@
|
|
|
11920
11920
|
},
|
|
11921
11921
|
"packages/crouter-plugin": {
|
|
11922
11922
|
"name": "@north-light/plugin",
|
|
11923
|
-
"version": "0.3.
|
|
11923
|
+
"version": "0.3.711",
|
|
11924
11924
|
"license": "UNLICENSED",
|
|
11925
11925
|
"dependencies": {
|
|
11926
|
-
"@north-light/api": "0.3.
|
|
11927
|
-
"@north-light/identity": "0.3.
|
|
11926
|
+
"@north-light/api": "0.3.711",
|
|
11927
|
+
"@north-light/identity": "0.3.711"
|
|
11928
11928
|
}
|
|
11929
11929
|
},
|
|
11930
11930
|
"packages/crouter-sdk": {
|
|
11931
11931
|
"name": "@north-light/sdk",
|
|
11932
|
-
"version": "0.3.
|
|
11932
|
+
"version": "0.3.711",
|
|
11933
11933
|
"license": "UNLICENSED",
|
|
11934
11934
|
"dependencies": {
|
|
11935
|
-
"@north-light/api": "0.3.
|
|
11936
|
-
"@north-light/identity": "0.3.
|
|
11937
|
-
"@north-light/plugin": "0.3.
|
|
11935
|
+
"@north-light/api": "0.3.711",
|
|
11936
|
+
"@north-light/identity": "0.3.711",
|
|
11937
|
+
"@north-light/plugin": "0.3.711",
|
|
11938
11938
|
"jose": "^6.2.1"
|
|
11939
11939
|
},
|
|
11940
11940
|
"bin": {
|
|
@@ -14,6 +14,7 @@ import { scrubInheritedBrokerEnv, unsafeIsolationReason } from './lib/isolation-
|
|
|
14
14
|
import { packArgs } from './lib/pack-args.mjs';
|
|
15
15
|
import { runtimeDepsKeyFromFiles } from './lib/runtime-deps-key.mjs';
|
|
16
16
|
import { assertCandidateMayOpenLiveDatabase, candidateSchemaVersion } from './lib/canvas-schema-gate.mjs';
|
|
17
|
+
import { ALLOW_UNLANDED_FLAG, readInstallSource, refusalMessage, unlandedReasons } from './lib/install-source.mjs';
|
|
17
18
|
|
|
18
19
|
scrubInheritedBrokerEnv();
|
|
19
20
|
// CI has no account store to protect, and its checkout sits inside the runner's
|
|
@@ -22,7 +23,8 @@ const unsafeReason = process.env.CI ? null : unsafeIsolationReason();
|
|
|
22
23
|
if (unsafeReason) throw new Error(`Unsafe crouter runtime install: ${unsafeReason}`);
|
|
23
24
|
|
|
24
25
|
const SHARED_FLAG = '--shared-node-modules=';
|
|
25
|
-
const
|
|
26
|
+
const ALLOW_UNLANDED = process.argv.slice(2).includes(ALLOW_UNLANDED_FLAG);
|
|
27
|
+
const positional = process.argv.slice(2).filter((arg) => !arg.startsWith(SHARED_FLAG) && arg !== ALLOW_UNLANDED_FLAG);
|
|
26
28
|
const sharedArg = process.argv.slice(2).find((arg) => arg.startsWith(SHARED_FLAG));
|
|
27
29
|
const PACKAGE_ROOT = positional[0] ? resolve(positional[0]) : resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
28
30
|
const RUNTIME_HOME = runtimeHome();
|
|
@@ -334,6 +336,7 @@ async function pruneGenerations() {
|
|
|
334
336
|
if (!retained.has(id)) {
|
|
335
337
|
await removeStage(join(GENERATIONS, id));
|
|
336
338
|
await rm(publishedMarkerPath(GENERATIONS, id), { force: true });
|
|
339
|
+
await rm(sourcePath(id), { force: true });
|
|
337
340
|
}
|
|
338
341
|
}
|
|
339
342
|
}
|
|
@@ -548,7 +551,17 @@ function loads(path) {
|
|
|
548
551
|
});
|
|
549
552
|
}
|
|
550
553
|
|
|
554
|
+
/** Where each generation's install came from, beside the sealed generation (`<id>.source.json`). */
|
|
555
|
+
const sourcePath = (id) => join(GENERATIONS, `${id}.source.json`);
|
|
556
|
+
|
|
551
557
|
async function install() {
|
|
558
|
+
// CI installs the commit under test, which is not origin/main by design.
|
|
559
|
+
const source = process.env.CI ? undefined : readInstallSource(PACKAGE_ROOT);
|
|
560
|
+
const reasons = source === undefined ? undefined : unlandedReasons(source);
|
|
561
|
+
if (reasons !== undefined && !ALLOW_UNLANDED) {
|
|
562
|
+
process.stderr.write(`${refusalMessage(source, reasons)}\n`);
|
|
563
|
+
process.exit(1);
|
|
564
|
+
}
|
|
552
565
|
await mkdir(GENERATIONS, { recursive: true });
|
|
553
566
|
await acquireLock();
|
|
554
567
|
cleanupState.lockTaken = true;
|
|
@@ -620,6 +633,9 @@ async function install() {
|
|
|
620
633
|
// Only after the full-hash check above has succeeded for this exact id —
|
|
621
634
|
// see `publishedMarkerPath`'s doc comment for the ordering invariant.
|
|
622
635
|
await markPublished(GENERATIONS, id);
|
|
636
|
+
if (source !== undefined) {
|
|
637
|
+
await writeFile(sourcePath(id), `${JSON.stringify({ ...source, unlanded: reasons ?? [], installedAt: new Date().toISOString(), node: process.env.CRTR_NODE_ID ?? null, checkout: PACKAGE_ROOT })}\n`);
|
|
638
|
+
}
|
|
623
639
|
const selected = join(RUNTIME_HOME, 'selected');
|
|
624
640
|
temporary = join(RUNTIME_HOME, `.selected-${process.pid}-${Date.now()}`);
|
|
625
641
|
cleanupState.temporary = temporary;
|
|
@@ -634,6 +650,7 @@ async function install() {
|
|
|
634
650
|
}
|
|
635
651
|
// stderr, not stdout: on a fresh install this runs inside the user's first `crtr` command, which may be `--json`.
|
|
636
652
|
process.stderr.write(`Installed immutable crouter runtime generation ${id}\n`);
|
|
653
|
+
if (reasons !== undefined) process.stderr.write(`WARNING: this machine now runs unlanded code (${reasons.join('; ')}). Land it or reinstall from origin/main before you finish, and say so in your report.\n`);
|
|
637
654
|
return { generation: id, version: pkg.version, selected };
|
|
638
655
|
} finally {
|
|
639
656
|
if (temporary) await rm(temporary, { force: true });
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// The git state an install comes from. The selected generation is one pointer for the whole
|
|
2
|
+
// machine and the last install wins, so an install from code that is not on origin/main silently
|
|
3
|
+
// replaces landed work (or someone else's) for every crtr process here. An install from a git
|
|
4
|
+
// checkout is refused unless its HEAD is exactly origin/main with a clean tree; `--allow-unlanded`
|
|
5
|
+
// is the explicit bypass. A package root that is not a git checkout (the npm package, image builds)
|
|
6
|
+
// is not checked.
|
|
7
|
+
import { spawnSync } from 'node:child_process';
|
|
8
|
+
|
|
9
|
+
export const ALLOW_UNLANDED_FLAG = '--allow-unlanded';
|
|
10
|
+
|
|
11
|
+
function git(root, args) {
|
|
12
|
+
const result = spawnSync('git', args, { cwd: root, encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'], timeout: 30_000 });
|
|
13
|
+
return result.status === 0 ? result.stdout.trim() : undefined;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** The checkout's commit, branch, and how it differs from origin/main; undefined when `root` is not a git checkout. */
|
|
17
|
+
export function readInstallSource(root) {
|
|
18
|
+
if (git(root, ['rev-parse', '--is-inside-work-tree']) !== 'true') return undefined;
|
|
19
|
+
const fetched = spawnSync('git', ['fetch', '--quiet', 'origin', 'main'], { cwd: root, stdio: 'ignore', timeout: 30_000 }).status === 0;
|
|
20
|
+
const commit = git(root, ['rev-parse', 'HEAD']);
|
|
21
|
+
const branch = git(root, ['branch', '--show-current']) || '(detached)';
|
|
22
|
+
const dirty = (git(root, ['status', '--porcelain', '--untracked-files=no']) ?? '') !== '';
|
|
23
|
+
const counts = git(root, ['rev-list', '--left-right', '--count', 'origin/main...HEAD']);
|
|
24
|
+
const [behind, ahead] = counts === undefined ? [undefined, undefined] : counts.split(/\s+/).map(Number);
|
|
25
|
+
return { commit, branch, dirty, behind, ahead, fetched };
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Why `source` may not be installed without the bypass, or undefined when it is exactly origin/main and clean. */
|
|
29
|
+
export function unlandedReasons(source) {
|
|
30
|
+
const reasons = [];
|
|
31
|
+
if (source.behind === undefined) reasons.push('origin/main could not be read, so this checkout cannot be compared with it');
|
|
32
|
+
if (source.behind > 0) reasons.push(`it is ${source.behind} commit(s) behind origin/main, so installing it removes work already landed there`);
|
|
33
|
+
if (source.ahead > 0) reasons.push(`it has ${source.ahead} commit(s) not on origin/main`);
|
|
34
|
+
if (source.dirty) reasons.push('it has uncommitted changes to tracked files');
|
|
35
|
+
return reasons.length > 0 ? reasons : undefined;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export function refusalMessage(source, reasons) {
|
|
39
|
+
return [
|
|
40
|
+
`Refused: this install is not origin/main (${source.branch} @ ${source.commit?.slice(0, 9) ?? 'unknown'}${source.fetched ? '' : '; fetching origin failed, so the comparison may be stale'}):`,
|
|
41
|
+
...reasons.map((reason) => ` - ${reason}`),
|
|
42
|
+
'',
|
|
43
|
+
'Every crtr process on this machine runs the installed runtime: the daemon, every node, every other agent. An install from code that is not on main replaces their runtime with yours, and the next install from main silently removes yours.',
|
|
44
|
+
'',
|
|
45
|
+
'Land the work instead: commit it, rebase onto origin/main, push to main, then install from that checkout.',
|
|
46
|
+
'',
|
|
47
|
+
`To test unlanded code you may pass ${ALLOW_UNLANDED_FLAG}, but only when Silas approved installing unlanded code for this task. Even then, do not leave the machine in that state: land the work or reinstall from origin/main before you finish, and say in your report that you did.`,
|
|
48
|
+
].join('\n');
|
|
49
|
+
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { RunnerExecution } from '../../core/runtime/runner/types.js';
|
|
2
|
-
import type { DetachedWorkLifecycle } from './broker-supervision.js';
|
|
3
|
-
import { type LanePass } from './throttled-lane.js';
|
|
4
|
-
export declare const IDLE_SANDBOX_INTERVAL_MS: number;
|
|
5
|
-
export declare const IDLE_SANDBOX_MAX_AGE_MS: number;
|
|
6
|
-
/** Sandboxes deleted per pass; the rest wait for the next pass. */
|
|
7
|
-
export declare const IDLE_SANDBOX_BUDGET = 50;
|
|
8
|
-
export interface IdleSandboxResult {
|
|
9
|
-
deleted: number;
|
|
10
|
-
failed: number;
|
|
11
|
-
}
|
|
12
|
-
export declare class IdleSandboxReconciler {
|
|
13
|
-
run(now: number, ctx: {
|
|
14
|
-
lifecycle: DetachedWorkLifecycle;
|
|
15
|
-
}): void;
|
|
16
|
-
/** One pass. `deleteExecution` is the runner's delete of the node's sandbox by default; tests pass their own. */
|
|
17
|
-
pass(now: number, lane?: LanePass, deleteExecution?: (execution: RunnerExecution) => Promise<void>): Promise<IdleSandboxResult>;
|
|
18
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
var p=Object.defineProperty;var c=(a,n)=>p(a,"name",{value:n,configurable:!0});import{openDb as m}from"../../core/canvas/db.js";import{endExecution as u}from"../../core/canvas/executions.js";import{emitEvent as d}from"../../core/events/emit.js";import{operationIdContext as _}from"../../core/events/operation-id.js";import{runnerForExecution as f}from"../../core/runtime/runner/index.js";import{runThrottledLane as E}from"./throttled-lane.js";const N=60*6e4,D=10080*6e4,S=10*6e4,I=50;class R{static{c(this,"IdleSandboxReconciler")}run(n,i){if(!i.lifecycle.acceptsDetachedWork())return;const o=_.fresh(()=>E("idle-sandbox","",n,N,S,async t=>{await this.pass(n,t)})).then(()=>{}).catch(t=>{_.fresh(()=>d({level:"error",event:"idle_sandbox.failed",error:t}))});i.lifecycle.registerDetached(o)}async pass(n,i,o=async t=>{await f("blaxel").delete(t.nodeId)}){const t={deleted:0,failed:0},r=new Date(n-D).toISOString(),s=await m(),x=await s.prepare(`SELECT x.execution_id, x.node_id, x.attempt, x.sandbox_name FROM executions x
|
|
2
|
-
JOIN nodes n ON n.node_id = x.node_id
|
|
3
|
-
JOIN profiles p ON p.id = n.profile_id
|
|
4
|
-
JOIN environments e ON e.object = p.environment_id
|
|
5
|
-
WHERE x.runner = 'blaxel' AND x.state = 'running' AND x.idle_at IS NOT NULL AND x.idle_at::timestamptz < ?::timestamptz
|
|
6
|
-
AND e.kind = 'blaxel' AND EXISTS (SELECT 1 FROM environment_repos r WHERE r.environment = e.object)
|
|
7
|
-
ORDER BY x.idle_at LIMIT ?`).all(r,I);for(const e of x){if(i&&!await i.holds())break;try{if(await s.prepare("SELECT 1 AS idle FROM executions WHERE execution_id = ? AND state = 'running' AND idle_at IS NOT NULL AND idle_at::timestamptz < ?::timestamptz").get(e.execution_id,r)===void 0)continue;await o({executionId:e.execution_id,nodeId:e.node_id,attempt:Number(e.attempt),sandboxName:e.sandbox_name}),await u(e.execution_id,{reason:"lost"}),t.deleted+=1,d({level:"info",event:"idle_sandbox.deleted",node_id:e.node_id,fields:{execution_id:e.execution_id}})}catch(l){t.failed+=1,d({level:"warn",event:"idle_sandbox.delete_failed",node_id:e.node_id,error:l,fields:{execution_id:e.execution_id}})}}return t}}export{I as IDLE_SANDBOX_BUDGET,N as IDLE_SANDBOX_INTERVAL_MS,D as IDLE_SANDBOX_MAX_AGE_MS,R as IdleSandboxReconciler};
|