pi-better-server 0.7.1 → 0.7.2
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/package.json +1 -1
- package/src/runtime/background-tools.ts +2 -1
- package/src/runtime/domain/background/registry.mjs +3 -0
- package/src/runtime/domain/background/shared-operation-coordinator/src/task-lifetime.mjs +6 -0
- package/src/runtime/domain/background/terminal-publication.mjs +5 -2
- package/src/runtime/domain/background-service/managed-authority.domain.mjs +13 -0
- package/src/runtime/domain/background-service/managed-authority.ts +16 -0
- package/src/runtime/domain/background-service/managed-client.domain.mjs +2 -2
- package/src/runtime/domain/background-service/managed-client.ts +2 -2
- package/src/runtime/domain/background-service/observed-waits.domain.mjs +8 -4
- package/src/runtime/domain/background-service/observed-waits.ts +8 -4
- package/src/runtime/domain/background-service/registry.domain.mjs +3 -0
- package/src/runtime/domain/background-service/registry.ts +2 -0
- package/src/runtime/domain/background-service/runtime.domain.mjs +3 -2
- package/src/runtime/domain/background-service/runtime.ts +3 -2
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/expiry.domain.mjs +44 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/expiry.ts +44 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.domain.mjs +8 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/schema.ts +8 -1
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.domain.mjs +3 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/store.ts +5 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-lifetime.domain.mjs +7 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/task-lifetime.ts +7 -0
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.domain.mjs +22 -13
- package/src/runtime/domain/background-service/shared-operation-coordinator/src/waits.ts +40 -32
- package/src/runtime/domain/background-service/shared-sandbox-diagnostics.domain.mjs +12 -19
- package/src/runtime/domain/background-service/shared-sandbox-diagnostics.ts +12 -16
- package/src/runtime/domain/background-service/supervisor/emit-runner.mjs +1 -0
- package/src/runtime/domain/background-service/supervisor/generated/runner.mjs +12 -7
- package/src/runtime/domain/background-service/supervisor/generated/task-lifetime.mjs +9 -0
- package/src/runtime/domain/background-service/supervisor/runner.domain.mjs +12 -7
- package/src/runtime/domain/background-service/supervisor/runner.ts +12 -7
- package/src/runtime/domain/background-service/supervisor/types.ts +1 -1
- package/src/runtime/domain/background-service/tools.domain.mjs +3 -2
- package/src/runtime/domain/background-service/tools.ts +3 -2
- package/src/runtime/domain/coordinator/src/expiry.mjs +43 -0
- package/src/runtime/domain/coordinator/src/schema.mjs +8 -1
- package/src/runtime/domain/coordinator/src/store.mjs +3 -0
- package/src/runtime/domain/coordinator/src/task-lifetime.mjs +6 -0
- package/src/runtime/domain/coordinator/src/waits.mjs +22 -13
- package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.domain.mjs +12 -19
- package/src/runtime/domain/sandbox-policy/shared-sandbox-diagnostics.ts +12 -16
- package/src/runtime/domain/subagents/README.md +2 -2
- package/src/runtime/domain/subagents/cleanup.domain.mjs +5 -2
- package/src/runtime/domain/subagents/cleanup.ts +4 -1
- package/src/runtime/domain/subagents/index.domain.mjs +41 -27
- package/src/runtime/domain/subagents/index.ts +39 -25
- package/src/runtime/domain/subagents/managed-launch-host.domain.mjs +28 -2
- package/src/runtime/domain/subagents/managed-launch-host.ts +26 -2
- package/src/runtime/domain/subagents/managed-launch-port.ts +2 -0
- package/src/runtime/domain/subagents/package.json +1 -1
- package/src/runtime/domain/subagents/registry-cleanup-worker.mjs +24 -0
- package/src/runtime/domain/subagents/registry.domain.mjs +33 -7
- package/src/runtime/domain/subagents/registry.ts +18 -4
- package/src/runtime/domain/subagents/settings-page.domain.mjs +10 -10
- package/src/runtime/domain/subagents/settings-page.ts +10 -10
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/expiry.domain.mjs +44 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/expiry.ts +44 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.domain.mjs +8 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/schema.ts +8 -1
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.domain.mjs +3 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/store.ts +5 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-lifetime.domain.mjs +7 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/task-lifetime.ts +7 -0
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.domain.mjs +22 -13
- package/src/runtime/domain/subagents/shared-operation-coordinator/src/waits.ts +40 -32
- package/src/runtime/domain/subagents/shared-sandbox-diagnostics.domain.mjs +12 -19
- package/src/runtime/domain/subagents/shared-sandbox-diagnostics.ts +12 -16
- package/src/runtime/domain/subagents/stop.domain.mjs +7 -5
- package/src/runtime/domain/subagents/stop.ts +7 -5
- package/src/runtime/domain/subagents/timing.domain.mjs +7 -3
- package/src/runtime/domain/subagents/timing.ts +11 -4
- package/src/runtime/domain/subagents/workspace-files.domain.mjs +6 -6
- package/src/runtime/domain/subagents/workspace-files.ts +6 -6
- package/src/runtime/task-expiry.ts +52 -0
- package/src/server.ts +4 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import type { acquireMutationStore } from "./mutation-store.ts";
|
|
2
|
+
// @ts-expect-error Generated canonical supervisor.
|
|
3
|
+
import { createLocalSupervisor, defaultSupervisorDirectory } from "./domain/background/supervisor/supervisor.mjs";
|
|
4
|
+
// @ts-expect-error Generated durable stop request.
|
|
5
|
+
import { writeStopRequest } from "./domain/background/supervisor/store.mjs";
|
|
6
|
+
// @ts-expect-error Generated supervisor identity and format.
|
|
7
|
+
import { SUPERVISOR_RECORD_VERSION, SUPERVISOR_TASK_ID_PATTERN } from "./domain/background/supervisor/types.mjs";
|
|
8
|
+
// @ts-expect-error Generated canonical terminal evidence rules.
|
|
9
|
+
import { supervisorTerminalPublication } from "./domain/background/terminal-publication.mjs";
|
|
10
|
+
|
|
11
|
+
const reason = "24-hour task lifetime exceeded";
|
|
12
|
+
|
|
13
|
+
/** Repair records left behind by offline or older task owners. */
|
|
14
|
+
export function startTaskExpiry(control: ReturnType<typeof acquireMutationStore>, log: (message: string) => void) {
|
|
15
|
+
const { store, budget } = control;
|
|
16
|
+
let timer: NodeJS.Timeout;
|
|
17
|
+
const sweep = () => {
|
|
18
|
+
const release = budget.enter("repair");
|
|
19
|
+
let delay = 30_000;
|
|
20
|
+
try {
|
|
21
|
+
if (!release) { delay = 1000; return; }
|
|
22
|
+
const overdue = store.overdueOperations();
|
|
23
|
+
if (store.expireWaits() || overdue.length) delay = 1000;
|
|
24
|
+
for (const op of overdue) {
|
|
25
|
+
try {
|
|
26
|
+
let publication;
|
|
27
|
+
if (op.observer.kind === "local-supervisor" && SUPERVISOR_TASK_ID_PATTERN.test(op.taskId)) {
|
|
28
|
+
const grant = store.resultSupervision(op.operationId);
|
|
29
|
+
const directory = grant ? grant.directory : defaultSupervisorDirectory();
|
|
30
|
+
const inspection = createLocalSupervisor({ directory }).snapshot(op.taskId);
|
|
31
|
+
if (inspection?.token === op.launchToken && (!grant || grant.launchToken === op.launchToken)) {
|
|
32
|
+
if (inspection.terminal) publication = supervisorTerminalPublication(op, inspection);
|
|
33
|
+
else writeStopRequest(directory, { version: SUPERVISOR_RECORD_VERSION, taskId: op.taskId,
|
|
34
|
+
token: op.launchToken, requestedAt: Date.now(), reason });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
store.recordTerminalOutcome(publication ?? { operationId: op.operationId, owner: op.owner,
|
|
38
|
+
eventId: "task-lifetime-expired", outcome: "failed", reason });
|
|
39
|
+
} catch (error) {
|
|
40
|
+
if (store.getOperation(op.operationId)?.phase === "running") log(`Task expiry for ${op.operationId}: ${String(error)}`);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
} catch (error) { log(`Task expiry: ${String(error)}`); }
|
|
44
|
+
finally {
|
|
45
|
+
release?.();
|
|
46
|
+
timer = setTimeout(sweep, delay);
|
|
47
|
+
timer.unref();
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
sweep();
|
|
51
|
+
return () => clearTimeout(timer);
|
|
52
|
+
}
|
package/src/server.ts
CHANGED
|
@@ -20,6 +20,7 @@ import type { IdleSessionsLease, UpgradeRequest } from "./startup/managed-types.
|
|
|
20
20
|
import { HostedSession } from "./hosted-session.ts";
|
|
21
21
|
import { readLifecycleConfig, type LifecycleConfig } from "./lifecycle-config.ts";
|
|
22
22
|
import { runtimeRoot } from "./runtime/root.ts";
|
|
23
|
+
import { startTaskExpiry } from "./runtime/task-expiry.ts";
|
|
23
24
|
import { RuntimeCancellation } from "./runtime/cancellation.ts";
|
|
24
25
|
import { RuntimeResultSupervision } from "./runtime/result-supervision.ts";
|
|
25
26
|
import { SharedCatalog } from "./runtime/catalog.ts";
|
|
@@ -594,6 +595,7 @@ export async function startDaemon(options: DaemonOptions = {}): Promise<Daemon>
|
|
|
594
595
|
let timer: ReturnType<typeof setInterval> | undefined;
|
|
595
596
|
let finishClosed!: () => void;
|
|
596
597
|
const closed = new Promise<void>(resolve => { finishClosed = resolve; });
|
|
598
|
+
const stopTaskExpiry = startTaskExpiry(controlStore, log);
|
|
597
599
|
const daemon: Daemon = {
|
|
598
600
|
serverDir,
|
|
599
601
|
socketPath,
|
|
@@ -625,6 +627,7 @@ export async function startDaemon(options: DaemonOptions = {}): Promise<Daemon>
|
|
|
625
627
|
// Unknown observation fails closed for an irreversible activation.
|
|
626
628
|
upgradeBlockers = await work().upgradeObligations();
|
|
627
629
|
if (upgradeBlockers.length) throw new Error(`Waiting for runtime work: ${JSON.stringify(upgradeBlockers)}`);
|
|
630
|
+
if (launches?.cleaningRegistry) throw new Error("Waiting for subagent registry cleanup");
|
|
628
631
|
if (inFlight > 0 || cancellations?.busy) throw new Error("Waiting for in-flight runtime admission");
|
|
629
632
|
commitActivationStop(request, lease, () => { draining = true; upgradeCommitted = true; });
|
|
630
633
|
for (const hosted of live) {
|
|
@@ -701,6 +704,7 @@ export async function startDaemon(options: DaemonOptions = {}): Promise<Daemon>
|
|
|
701
704
|
writeFileSync(temporary, JSON.stringify({ token: instanceId, pid: process.pid }), { mode: 0o600 });
|
|
702
705
|
renameSync(temporary, join(serverDir, "idle-stop-intent.json"));
|
|
703
706
|
}
|
|
707
|
+
stopTaskExpiry();
|
|
704
708
|
if (timer) clearInterval(timer);
|
|
705
709
|
await pendingMaintenance?.catch(error => log(`maintenance interrupted during shutdown: ${String(error)}`));
|
|
706
710
|
if (upgradeCommitted) {
|
package/src/version.ts
CHANGED