@loucompanion/forge-bridge 0.1.4-dev.fb770705136a → 0.2.1-dev.1a5cf93b48a1
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/README.md +144 -3
- package/dist/bridge/bridge-chat-giphy-look.d.ts +48 -0
- package/dist/bridge/bridge-chat-giphy-look.js +55 -0
- package/dist/bridge/bridge-chat-provider-command.d.ts +40 -0
- package/dist/bridge/bridge-chat-provider-command.js +230 -0
- package/dist/bridge/bridge-chat.types.d.ts +20 -0
- package/dist/bridge/bridge-chat.types.js +28 -1
- package/dist/bridge/bridge-state-file.d.ts +161 -0
- package/dist/bridge/bridge-state-file.js +376 -0
- package/dist/bridge/bridge-state-io.d.ts +11 -0
- package/dist/bridge/bridge-state-io.js +50 -0
- package/dist/bridge/bridge-state-lock.d.ts +11 -0
- package/dist/bridge/bridge-state-lock.js +102 -0
- package/dist/bridge/bridge-state-unpublished.d.ts +17 -0
- package/dist/bridge/bridge-state-unpublished.js +111 -0
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +92 -14
- package/dist/bridge/bridge.service.js +446 -380
- package/dist/bridge/bridge.types.d.ts +21 -0
- package/dist/bridge/in-flight-registry.d.ts +62 -0
- package/dist/bridge/in-flight-registry.js +207 -0
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/bridge/readiness-result-outbox.d.ts +5 -1
- package/dist/bridge/readiness-result-outbox.js +20 -0
- package/dist/bridge/runner-host-capabilities.d.ts +5 -0
- package/dist/bridge/runner-host-capabilities.js +17 -0
- package/dist/bridge/sandbox-resource-accounting.d.ts +16 -0
- package/dist/bridge/sandbox-resource-accounting.js +150 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/cleanup/cleanup-wip.d.ts +12 -0
- package/dist/cleanup/cleanup-wip.js +66 -0
- package/dist/cleanup/cleanup.service.d.ts +20 -1
- package/dist/cleanup/cleanup.service.js +150 -169
- package/dist/cleanup/cleanup.types.d.ts +6 -0
- package/dist/cleanup/forge-owned-paths.d.ts +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -0
- package/dist/cleanup/host-runtime-ledger.d.ts +7 -0
- package/dist/cleanup/host-runtime-ledger.js +130 -0
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.help.js +74 -12
- package/dist/cli/cli.service.d.ts +19 -10
- package/dist/cli/cli.service.js +152 -187
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +6 -0
- package/dist/cli/local-config.js +32 -4
- package/dist/cli/provider-cli-detection.d.ts +10 -0
- package/dist/cli/provider-cli-detection.js +160 -0
- package/dist/runtime/aspnet-runtime-prebuild.d.ts +20 -0
- package/dist/runtime/aspnet-runtime-prebuild.js +184 -18
- package/dist/runtime/attempt-database-broker.d.ts +1 -1
- package/dist/runtime/attempt-node-runtime-launcher.d.ts +36 -0
- package/dist/runtime/attempt-node-runtime-launcher.js +169 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +2 -0
- package/dist/runtime/attempt-process-supervisor.js +12 -6
- package/dist/runtime/docker-engine-probe.d.ts +5 -0
- package/dist/runtime/docker-engine-probe.js +7 -0
- package/dist/runtime/dotnet-build-outputs.d.ts +107 -0
- package/dist/runtime/dotnet-build-outputs.js +402 -0
- package/dist/runtime/ephemeral-test-postgres-grant.d.ts +37 -0
- package/dist/runtime/ephemeral-test-postgres-grant.js +85 -0
- package/dist/runtime/ephemeral-test-postgres.d.ts +57 -0
- package/dist/runtime/ephemeral-test-postgres.js +303 -0
- package/dist/runtime/host-facts.d.ts +2 -1
- package/dist/runtime/host-listener-inspector.d.ts +26 -0
- package/dist/runtime/host-listener-inspector.js +84 -3
- package/dist/runtime/host-load-admission.d.ts +67 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-child-environment.d.ts +27 -0
- package/dist/runtime/host-load-child-environment.js +76 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
- package/dist/runtime/host-load-forge-cgroups.js +140 -0
- package/dist/runtime/host-load-governor-config.d.ts +52 -0
- package/dist/runtime/host-load-governor-config.js +83 -0
- package/dist/runtime/host-load-governor.d.ts +186 -0
- package/dist/runtime/host-load-governor.js +632 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +187 -0
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +80 -0
- package/dist/runtime/host-load-sampler.d.ts +75 -2
- package/dist/runtime/host-load-sampler.js +142 -8
- package/dist/runtime/host-load-step-class.d.ts +70 -0
- package/dist/runtime/host-load-step-class.js +161 -0
- package/dist/runtime/host-load-step-reaper.d.ts +27 -0
- package/dist/runtime/host-load-step-reaper.js +95 -0
- package/dist/runtime/host-load-step-run.d.ts +73 -0
- package/dist/runtime/host-load-step-run.js +102 -0
- package/dist/runtime/host-load-test-slot.d.ts +43 -0
- package/dist/runtime/host-load-test-slot.js +81 -0
- package/dist/runtime/host-load-token-ledger.d.ts +200 -0
- package/dist/runtime/host-load-token-ledger.js +453 -0
- package/dist/runtime/host-load-windows-cpu.d.ts +34 -0
- package/dist/runtime/host-load-windows-cpu.js +85 -0
- package/dist/runtime/host-pressure-stall.d.ts +21 -1
- package/dist/runtime/host-pressure-stall.js +48 -1
- package/dist/runtime/host-runtime-contract.d.ts +15 -0
- package/dist/runtime/host-runtime-contract.js +33 -2
- package/dist/runtime/host-runtime-lease.d.ts +101 -6
- package/dist/runtime/host-runtime-lease.js +408 -294
- package/dist/runtime/host-runtime-ledger-recovery.d.ts +20 -0
- package/dist/runtime/host-runtime-ledger-recovery.js +134 -0
- package/dist/runtime/host-runtime-promotion.d.ts +101 -2
- package/dist/runtime/host-runtime-promotion.js +355 -14
- package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
- package/dist/runtime/host-runtime-requirements-check.js +29 -0
- package/dist/runtime/host-runtime-requirements.d.ts +36 -0
- package/dist/runtime/host-runtime-requirements.js +117 -0
- package/dist/runtime/managed-command-teardown.js +5 -16
- package/dist/runtime/native-test-postgres-fallback.d.ts +51 -7
- package/dist/runtime/native-test-postgres-fallback.js +60 -8
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
- package/dist/runtime/prepared-runtime-identity.d.ts +4 -0
- package/dist/runtime/prepared-runtime-identity.js +130 -9
- package/dist/runtime/prepared-runtime-readiness.d.ts +13 -1
- package/dist/runtime/prepared-runtime-readiness.js +63 -16
- package/dist/runtime/runner-settings.d.ts +104 -0
- package/dist/runtime/runner-settings.js +236 -0
- package/dist/runtime/supervised-runtime-build-guard.d.ts +45 -0
- package/dist/runtime/supervised-runtime-build-guard.js +112 -0
- package/dist/sandbox/host-capacity-broker.d.ts +115 -0
- package/dist/sandbox/host-capacity-broker.js +336 -0
- package/dist/sandbox/managed-branch.d.ts +13 -0
- package/dist/sandbox/managed-branch.js +90 -0
- package/dist/sandbox/provider-auth/codex.js +11 -11
- package/dist/sandbox/runtime.d.ts +10 -1
- package/dist/sandbox/runtime.js +47 -8
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/session/architect-waits.d.ts +2 -0
- package/dist/session/architect-waits.js +138 -0
- package/dist/session/managed-attempt-tools.d.ts +2 -7
- package/dist/session/managed-attempt-tools.js +207 -121
- package/dist/session/managed-build-coordinator.d.ts +16 -0
- package/dist/session/managed-build-coordinator.js +10 -0
- package/dist/session/managed-build-receipt.d.ts +5 -0
- package/dist/session/managed-build-receipt.js +8 -3
- package/dist/session/managed-command-host-load.d.ts +47 -0
- package/dist/session/managed-command-host-load.js +83 -0
- package/dist/session/mcp-argument-coercion.d.ts +23 -0
- package/dist/session/mcp-argument-coercion.js +121 -0
- package/dist/session/phase-completion.artifacts.d.ts +7 -0
- package/dist/session/phase-completion.artifacts.js +96 -26
- package/dist/session/phase-completion.command-validation.d.ts +7 -0
- package/dist/session/phase-completion.command-validation.js +77 -0
- package/dist/session/phase-completion.d.ts +12 -0
- package/dist/session/phase-completion.helpers.js +13 -12
- package/dist/session/phase-completion.js +5 -0
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +156 -0
- package/dist/session/phase-completion.prompts.js +6 -1
- package/dist/session/phase-completion.runtime.d.ts +5 -11
- package/dist/session/phase-completion.runtime.js +91 -215
- package/dist/session/phase-completion.schema-parts.d.ts +19 -0
- package/dist/session/phase-completion.schema-parts.js +188 -0
- package/dist/session/phase-completion.schemas.d.ts +3 -3
- package/dist/session/phase-completion.schemas.js +208 -231
- package/dist/session/phase-completion.validation.d.ts +2 -3
- package/dist/session/phase-completion.validation.js +49 -93
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +111 -0
- package/dist/session/pre-publication-native-postgres.d.ts +30 -0
- package/dist/session/pre-publication-native-postgres.js +111 -0
- package/dist/session/pre-publication-pass.d.ts +61 -0
- package/dist/session/pre-publication-pass.js +148 -0
- package/dist/session/pre-publication-process.d.ts +3 -0
- package/dist/session/pre-publication-process.js +31 -19
- package/dist/session/pre-publication-step-execution.d.ts +12 -0
- package/dist/session/pre-publication-step-execution.js +50 -0
- package/dist/session/pre-publication-validation.d.ts +37 -21
- package/dist/session/pre-publication-validation.js +221 -182
- package/dist/session/provider-cli/claude-background-work.d.ts +67 -0
- package/dist/session/provider-cli/claude-background-work.js +181 -0
- package/dist/session/provider-cli/host-build-lock.d.ts +18 -0
- package/dist/session/provider-cli/host-build-lock.js +30 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +276 -0
- package/dist/session/provider-cli/provider-cli.child-environment.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.child-environment.js +75 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.d.ts +3 -0
- package/dist/session/provider-cli/provider-cli.codex-models-cache.js +37 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +28 -8
- package/dist/session/provider-cli/provider-cli.process.d.ts +15 -36
- package/dist/session/provider-cli/provider-cli.process.js +41 -432
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +72 -32
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +8 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +29 -1
- package/dist/session/provider-cli/provider-cli.service.d.ts +7 -1
- package/dist/session/provider-cli/provider-cli.service.js +98 -173
- package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.windows-environment.js +151 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.windows-launch.js +131 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +4 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +45 -0
- package/dist/session/provider-cli/provider-output-pipes.d.ts +30 -0
- package/dist/session/provider-cli/provider-output-pipes.js +67 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +2 -0
- package/dist/session/provider-cli/provider-output-state.js +6 -0
- package/dist/session/provider-cli/provider-user-config-isolation.d.ts +69 -0
- package/dist/session/provider-cli/provider-user-config-isolation.js +164 -0
- package/dist/session/qa-sidecar-validation.d.ts +6 -0
- package/dist/session/qa-sidecar-validation.js +28 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +51 -0
- package/dist/session/sandbox-host-capacity-gate.js +257 -0
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.service.d.ts +15 -2
- package/dist/session/session.service.js +246 -88
- package/dist/session/session.types.d.ts +4 -0
- package/dist/session/session.types.js +7 -7
- package/dist/session/sidecar-json-shape.d.ts +31 -0
- package/dist/session/sidecar-json-shape.js +217 -0
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/fs/file-identity.d.ts +10 -0
- package/dist/shared/fs/file-identity.js +15 -0
- package/dist/shared/fs/replace-file.d.ts +7 -0
- package/dist/shared/fs/replace-file.js +33 -0
- package/dist/shared/process/host-process-recovery.d.ts +14 -3
- package/dist/shared/process/host-process-recovery.js +23 -3
- package/dist/shared/process/host-process-supervisor.d.ts +14 -1
- package/dist/shared/process/host-process-supervisor.js +67 -15
- package/dist/shared/process/process-tree.d.ts +52 -0
- package/dist/shared/process/process-tree.js +144 -0
- package/dist/shared/process/process.d.ts +67 -0
- package/dist/shared/process/process.js +213 -11
- package/dist/shared/process/windows-app-execution-alias.d.ts +19 -0
- package/dist/shared/process/windows-app-execution-alias.js +45 -0
- package/dist/shared/process/windows-launch.d.ts +18 -0
- package/dist/shared/process/windows-launch.js +68 -0
- package/dist/shared/provider-capabilities.js +14 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.d.ts +25 -0
- package/dist/worktree/dependency-warmer.js +46 -10
- package/dist/worktree/orphan-relink.d.ts +19 -0
- package/dist/worktree/orphan-relink.js +106 -0
- package/dist/worktree/wip-git.d.ts +42 -0
- package/dist/worktree/wip-git.js +139 -0
- package/dist/worktree/wip-refs.d.ts +77 -0
- package/dist/worktree/wip-refs.js +146 -0
- package/dist/worktree/wip-restore.d.ts +46 -0
- package/dist/worktree/wip-restore.js +280 -0
- package/dist/worktree/wip-snapshot.d.ts +53 -0
- package/dist/worktree/wip-snapshot.js +270 -0
- package/dist/worktree/worktree-inputs.d.ts +8 -0
- package/dist/worktree/worktree-inputs.js +134 -0
- package/dist/worktree/worktree-origin-sync.d.ts +35 -0
- package/dist/worktree/worktree-origin-sync.js +128 -0
- package/dist/worktree/worktree-wip-events.d.ts +18 -0
- package/dist/worktree/worktree-wip-events.js +115 -0
- package/dist/worktree/worktree-wip.d.ts +51 -0
- package/dist/worktree/worktree-wip.js +190 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +36 -5
- package/dist/worktree/worktree.service.js +126 -155
- package/dist/worktree/worktree.types.d.ts +42 -0
- package/package.json +2 -2
- package/runtime/windows-listener-owner.ps1 +12 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import { isProcessTreeTerminationUnproven, ProcessTreeTerminationError } from "../shared/process/process.js";
|
|
3
|
+
/**
|
|
4
|
+
* The retention a step's failure calls for: a tree that could not be proven gone,
|
|
5
|
+
* whether the runner said so with its own check (ProcessTreeTerminationError) or a
|
|
6
|
+
* supervisor did (host_process_supervisor_termination_failed, possibly wrapped).
|
|
7
|
+
*/
|
|
8
|
+
export function retentionFor(error) {
|
|
9
|
+
if (error instanceof ProcessTreeTerminationError)
|
|
10
|
+
return { stillGone: error.stillGone, reason: error };
|
|
11
|
+
if (!isProcessTreeTerminationUnproven(error))
|
|
12
|
+
return null;
|
|
13
|
+
return { stillGone: null, reason: error instanceof Error ? error : new Error(String(error)) };
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* With the governor off (or no gate), `run` is called directly with a null
|
|
17
|
+
* wait, so behavior is unchanged. With it on, `run` starts only after
|
|
18
|
+
* admission, so the step's own timers never include queue time, and the token
|
|
19
|
+
* is returned when `run` settles, whether it succeeded, failed or was stopped.
|
|
20
|
+
*/
|
|
21
|
+
export async function runHostGovernedStep(gate, step, run) {
|
|
22
|
+
if (!gate?.enabled)
|
|
23
|
+
return await run(null, {});
|
|
24
|
+
const admission = await gate.acquire({
|
|
25
|
+
stepClass: step.classification.stepClass,
|
|
26
|
+
label: step.label,
|
|
27
|
+
cost: step.classification.cost,
|
|
28
|
+
dispatchAttemptId: step.dispatchAttemptId,
|
|
29
|
+
priority: step.priority,
|
|
30
|
+
}, { signal: step.signal, onWaiting: step.onWaiting });
|
|
31
|
+
let retention = null;
|
|
32
|
+
try {
|
|
33
|
+
let outcome;
|
|
34
|
+
try {
|
|
35
|
+
outcome = await run(Math.round(admission.waitMs), {
|
|
36
|
+
fenced: admission.fenced,
|
|
37
|
+
attachProcess: async (stepProcess) => await admission.attachProcess(stepProcess),
|
|
38
|
+
holdUntilStopped: (stillGone, reason) => { retention = { stillGone, reason }; },
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
// Part of the step may still run: that, not a fence, is what the step failed with.
|
|
43
|
+
const unproven = retentionFor(error);
|
|
44
|
+
if (unproven) {
|
|
45
|
+
retention = unproven;
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
if (step.reportsOwnFence !== true)
|
|
49
|
+
throwIfFenced(admission.fenced, undefined);
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
52
|
+
return step.reportsOwnFence === true ? outcome : throwIfFenced(admission.fenced, outcome);
|
|
53
|
+
}
|
|
54
|
+
finally {
|
|
55
|
+
await returnHostLoadToken(admission, retention, step.onReleaseFailed);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Returns a step's token, unless part of its process tree could not be proven
|
|
60
|
+
* gone: the token (and its cost) is then kept until the tree is.
|
|
61
|
+
*/
|
|
62
|
+
export async function returnHostLoadToken(admission, retention, onReleaseFailed) {
|
|
63
|
+
if (retention) {
|
|
64
|
+
admission.retainUntilStopped(retention.stillGone, retention.reason);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
await admission.release();
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
await Promise.resolve(onReleaseFailed?.(error)).catch(() => undefined);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* A step stopped because its token was reclaimed reports host_capacity_token_fenced
|
|
76
|
+
* (retryable), not the exit status or error it died with.
|
|
77
|
+
*/
|
|
78
|
+
export function throwIfFenced(fenced, outcome) {
|
|
79
|
+
if (fenced.aborted)
|
|
80
|
+
throw fenced.reason;
|
|
81
|
+
return outcome;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Records a supervised step's process tree on its host load token, from the
|
|
85
|
+
* metadata its process supervisor wrote (`FORGE_PROCESS_SUPERVISOR_METADATA_PATH`):
|
|
86
|
+
* a reclaim then stops exactly this tree before reusing its capacity. Rejects when
|
|
87
|
+
* the tree cannot be read or recorded; the caller must then stop the step, since
|
|
88
|
+
* it would otherwise run on without a reservation the host can account for.
|
|
89
|
+
*/
|
|
90
|
+
export async function attachSupervisedStepProcess(control, metadataPath) {
|
|
91
|
+
if (!control.attachProcess)
|
|
92
|
+
return;
|
|
93
|
+
const metadata = JSON.parse(await fs.readFile(metadataPath, "utf8"));
|
|
94
|
+
if (typeof metadata.rootPid !== "number" || !Number.isSafeInteger(metadata.rootPid) || metadata.rootPid <= 1) {
|
|
95
|
+
throw new Error(`the step's process supervisor recorded no usable root process in ${metadataPath}.`);
|
|
96
|
+
}
|
|
97
|
+
await control.attachProcess({
|
|
98
|
+
rootPid: metadata.rootPid,
|
|
99
|
+
rootIdentity: typeof metadata.rootIdentity === "string" ? metadata.rootIdentity : null,
|
|
100
|
+
processGroup: metadata.strategy === "unix_process_group",
|
|
101
|
+
});
|
|
102
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { HostLoadAdmissionDecision } from "./host-load-admission.js";
|
|
2
|
+
import type { HostLoadToken, HostLoadTokenOwner, HostLoadTokenPriority } from "./host-load-token-ledger.js";
|
|
3
|
+
/** Every governed step class takes the slot unless it is known to be light. */
|
|
4
|
+
export declare function takesHostTestSlot(stepClass: string): boolean;
|
|
5
|
+
/** A step waiting for the slot, as its owner records it in the ledger. */
|
|
6
|
+
export interface HostTestSlotTicketRequest {
|
|
7
|
+
readonly ticketId: string;
|
|
8
|
+
readonly stepClass: string;
|
|
9
|
+
readonly label: string;
|
|
10
|
+
readonly dispatchAttemptId: string | null;
|
|
11
|
+
readonly priority: HostLoadTokenPriority;
|
|
12
|
+
/** Wall clock (ISO): every process on the host orders by the same clock. */
|
|
13
|
+
readonly enqueuedAt: string;
|
|
14
|
+
}
|
|
15
|
+
/** A ticket in the ledger: its owner renews `expiresAt` on every transaction while it waits. */
|
|
16
|
+
export interface HostTestSlotTicket extends HostTestSlotTicketRequest {
|
|
17
|
+
readonly owner: HostLoadTokenOwner;
|
|
18
|
+
readonly expiresAt: string;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* The host queue in admission order: foreground first, except background that has
|
|
22
|
+
* waited past the anti-starvation window, then oldest first.
|
|
23
|
+
*/
|
|
24
|
+
export declare function orderHostTestSlotQueue(tickets: readonly HostTestSlotTicketRequest[], nowMs: number, antiStarvationMs: number): HostTestSlotTicketRequest[];
|
|
25
|
+
export interface HostTestSlotInput {
|
|
26
|
+
readonly ticket: HostTestSlotTicketRequest;
|
|
27
|
+
/** Every live ticket on the host, this one included or not. */
|
|
28
|
+
readonly queue: readonly HostTestSlotTicketRequest[];
|
|
29
|
+
/** Every live token on the host; fenced and degraded ones still hold their slot. */
|
|
30
|
+
readonly tokens: readonly HostLoadToken[];
|
|
31
|
+
readonly testSlots: number;
|
|
32
|
+
readonly nowMs: number;
|
|
33
|
+
readonly antiStarvationMs: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Admitted once the slots the holders leave free reach this ticket's place in the
|
|
37
|
+
* host queue. A token kept until its attempt's teardown (`retainedAt`) holds the slot
|
|
38
|
+
* against every other attempt, but not against its own: that attempt's next step
|
|
39
|
+
* would otherwise wait for its own teardown.
|
|
40
|
+
*/
|
|
41
|
+
export declare function decideHostTestSlot(input: HostTestSlotInput): HostLoadAdmissionDecision;
|
|
42
|
+
/** A ticket read back from the ledger; a malformed one is dropped, never trusted. */
|
|
43
|
+
export declare function validHostTestSlotTicket(value: unknown): value is HostTestSlotTicket;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// The host test slot (decision 0018): two Forge sessions on one host share it, so
|
|
2
|
+
// their builds, test runs, Playwright runs and runtime builds take turns instead of
|
|
3
|
+
// competing for the CPU and memory. Waiters queue host-wide in the shared ledger,
|
|
4
|
+
// foreground before background and first come, first served within a class, so a
|
|
5
|
+
// step in another process (the completion MCP server) is never overtaken by the
|
|
6
|
+
// bridge's own steps. A slot holder that crashed keeps its slot only until the
|
|
7
|
+
// ledger reclaims its token (dead owner, process tree stopped, or lease fenced).
|
|
8
|
+
/** Steps that never take the slot: plain managed commands (git, ls, cat) and dependency installs. */
|
|
9
|
+
const slotFreeStepClasses = new Set(["managed.command", "deps.install"]);
|
|
10
|
+
/** Every governed step class takes the slot unless it is known to be light. */
|
|
11
|
+
export function takesHostTestSlot(stepClass) {
|
|
12
|
+
return !slotFreeStepClasses.has(stepClass);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The host queue in admission order: foreground first, except background that has
|
|
16
|
+
* waited past the anti-starvation window, then oldest first.
|
|
17
|
+
*/
|
|
18
|
+
export function orderHostTestSlotQueue(tickets, nowMs, antiStarvationMs) {
|
|
19
|
+
const rank = (ticket) => ticket.priority === "foreground" || nowMs - Date.parse(ticket.enqueuedAt) >= antiStarvationMs ? 0 : 1;
|
|
20
|
+
return [...tickets].sort((a, b) => rank(a) - rank(b)
|
|
21
|
+
|| Date.parse(a.enqueuedAt) - Date.parse(b.enqueuedAt)
|
|
22
|
+
|| a.ticketId.localeCompare(b.ticketId));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Admitted once the slots the holders leave free reach this ticket's place in the
|
|
26
|
+
* host queue. A token kept until its attempt's teardown (`retainedAt`) holds the slot
|
|
27
|
+
* against every other attempt, but not against its own: that attempt's next step
|
|
28
|
+
* would otherwise wait for its own teardown.
|
|
29
|
+
*/
|
|
30
|
+
export function decideHostTestSlot(input) {
|
|
31
|
+
const ownRetained = (token) => Boolean(token.retainedAt)
|
|
32
|
+
&& token.dispatchAttemptId !== null && token.dispatchAttemptId === input.ticket.dispatchAttemptId;
|
|
33
|
+
const holders = input.tokens.filter(token => takesHostTestSlot(token.stepClass) && !ownRetained(token));
|
|
34
|
+
const queue = input.queue.some(entry => entry.ticketId === input.ticket.ticketId)
|
|
35
|
+
? input.queue
|
|
36
|
+
: [...input.queue, input.ticket];
|
|
37
|
+
const ahead = orderHostTestSlotQueue(queue, input.nowMs, input.antiStarvationMs)
|
|
38
|
+
.findIndex(entry => entry.ticketId === input.ticket.ticketId);
|
|
39
|
+
const free = Math.max(0, input.testSlots - holders.length);
|
|
40
|
+
const admitted = ahead < free;
|
|
41
|
+
const reserved = {
|
|
42
|
+
reservedCpuCores: input.tokens.reduce((sum, token) => sum + token.cost.cpuCores, 0),
|
|
43
|
+
reservedMemoryBytes: input.tokens.reduce((sum, token) => sum + token.cost.memoryBytes, 0),
|
|
44
|
+
cpuBudgetCores: null,
|
|
45
|
+
memoryBudgetBytes: null,
|
|
46
|
+
};
|
|
47
|
+
if (admitted) {
|
|
48
|
+
return { ...reserved, admitted, reason: "admitted_test_slot", detail: "The host test slot is free." };
|
|
49
|
+
}
|
|
50
|
+
const heldBy = holders.length > 0
|
|
51
|
+
? `held by ${holders.map(describeHolder).join("; ")}`
|
|
52
|
+
: "the steps ahead of this one take it first";
|
|
53
|
+
return {
|
|
54
|
+
...reserved,
|
|
55
|
+
admitted,
|
|
56
|
+
reason: "host_test_slot",
|
|
57
|
+
detail: `Waiting for the host test slot (${input.testSlots} at once): ${heldBy}; ${ahead} step(s) ahead in the host queue.`,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function describeHolder(token) {
|
|
61
|
+
const attempt = token.dispatchAttemptId ? `, attempt ${token.dispatchAttemptId}` : "";
|
|
62
|
+
const state = token.degradedAt
|
|
63
|
+
? ", whose owner is gone; it is returned once its processes are stopped"
|
|
64
|
+
: token.fencedAt ? ", which is past its lease"
|
|
65
|
+
: token.retainedAt ? ", whose processes could not be proven stopped; it is returned at attempt teardown" : "";
|
|
66
|
+
return `${token.label} (${token.stepClass}${attempt}${state})`;
|
|
67
|
+
}
|
|
68
|
+
/** A ticket read back from the ledger; a malformed one is dropped, never trusted. */
|
|
69
|
+
export function validHostTestSlotTicket(value) {
|
|
70
|
+
const ticket = value;
|
|
71
|
+
return Boolean(ticket)
|
|
72
|
+
&& typeof ticket.ticketId === "string"
|
|
73
|
+
&& typeof ticket.stepClass === "string"
|
|
74
|
+
&& typeof ticket.label === "string"
|
|
75
|
+
&& (ticket.dispatchAttemptId === null || typeof ticket.dispatchAttemptId === "string")
|
|
76
|
+
&& (ticket.priority === "foreground" || ticket.priority === "background")
|
|
77
|
+
&& Number.isFinite(Date.parse(String(ticket.enqueuedAt)))
|
|
78
|
+
&& Number.isFinite(Date.parse(String(ticket.expiresAt)))
|
|
79
|
+
&& Number.isSafeInteger(ticket.owner?.pid)
|
|
80
|
+
&& typeof ticket.owner?.processInstanceId === "string";
|
|
81
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
import { ForgeFailureError } from "../session/session.types.js";
|
|
2
|
+
import type { HostLoadStepCost } from "./host-load-step-class.js";
|
|
3
|
+
import { type HostTestSlotTicket, type HostTestSlotTicketRequest } from "./host-load-test-slot.js";
|
|
4
|
+
import { type HostLoadStepProcess, type HostLoadStepTerminator } from "./host-load-step-reaper.js";
|
|
5
|
+
/**
|
|
6
|
+
* File-backed token ledger for the host load governor (decision 0013). Every
|
|
7
|
+
* process on the host that runs heavy steps shares it through the coordinator
|
|
8
|
+
* state root. Each token names its owner (pid, OS process birth marker and a
|
|
9
|
+
* per-process instance id), carries a fencing token, and holds an `expiresAt`
|
|
10
|
+
* lease the owner renews. A lapsed lease with a live owner fences the token:
|
|
11
|
+
* it keeps its reserved cost (the owner's step may still be running), renewals
|
|
12
|
+
* are refused so the owner stops that step, and the capacity returns when the
|
|
13
|
+
* owner releases it or is gone. A dead owner's token is reclaimed only once its
|
|
14
|
+
* step's recorded process tree is stopped and confirmed gone; until then it
|
|
15
|
+
* stays `degraded` and keeps its reserved cost.
|
|
16
|
+
*/
|
|
17
|
+
export type HostLoadTokenPriority = "foreground" | "background";
|
|
18
|
+
export interface HostLoadTokenOwner {
|
|
19
|
+
readonly pid: number;
|
|
20
|
+
/** OS-issued birth marker (Linux boot id + start ticks); null where unsupported. */
|
|
21
|
+
readonly processIdentity: string | null;
|
|
22
|
+
/** Random per process: a reused pid in a new process never matches it. */
|
|
23
|
+
readonly processInstanceId: string;
|
|
24
|
+
}
|
|
25
|
+
export interface HostLoadToken {
|
|
26
|
+
readonly tokenId: string;
|
|
27
|
+
readonly fencingToken: number;
|
|
28
|
+
readonly stepClass: string;
|
|
29
|
+
readonly label: string;
|
|
30
|
+
readonly cost: HostLoadStepCost;
|
|
31
|
+
readonly dispatchAttemptId: string | null;
|
|
32
|
+
readonly priority: HostLoadTokenPriority;
|
|
33
|
+
readonly owner: HostLoadTokenOwner;
|
|
34
|
+
readonly admittedAt: string;
|
|
35
|
+
readonly expiresAt: string;
|
|
36
|
+
/** The step's process tree, recorded once it launches; the reaper stops it before reuse. */
|
|
37
|
+
readonly stepProcess?: HostLoadStepProcess | null;
|
|
38
|
+
/** The host's suspend counter (hostSuspendedMs) when the lease was last renewed. */
|
|
39
|
+
readonly suspendedMsAtRenewal?: number;
|
|
40
|
+
/** When an expired token's step could not be proven stopped; it keeps its cost meanwhile. */
|
|
41
|
+
readonly degradedAt?: string | null;
|
|
42
|
+
/** Set when the lease lapsed while the owner was still live: cost kept, renewal refused. */
|
|
43
|
+
readonly fencedAt?: string | null;
|
|
44
|
+
/**
|
|
45
|
+
* Set when the step ended but part of its process tree could not be proven
|
|
46
|
+
* stopped: the token is kept until it is (or until attempt teardown), and the
|
|
47
|
+
* attempt's own later steps do not wait for it (decision 0018).
|
|
48
|
+
*/
|
|
49
|
+
readonly retainedAt?: string | null;
|
|
50
|
+
}
|
|
51
|
+
export interface HostLoadTokenRequest {
|
|
52
|
+
readonly stepClass: string;
|
|
53
|
+
readonly label: string;
|
|
54
|
+
readonly cost: HostLoadStepCost;
|
|
55
|
+
readonly dispatchAttemptId: string | null;
|
|
56
|
+
readonly priority: HostLoadTokenPriority;
|
|
57
|
+
}
|
|
58
|
+
/** The live (post-reclaim) token set inside one locked ledger transaction. */
|
|
59
|
+
export interface HostLoadLedgerTransaction {
|
|
60
|
+
readonly tokens: readonly HostLoadToken[];
|
|
61
|
+
/**
|
|
62
|
+
* Set for one lease after a corrupt ledger was quarantined: owners are still
|
|
63
|
+
* restoring the reservations it lost, so no new step may be admitted yet.
|
|
64
|
+
*/
|
|
65
|
+
readonly recoveringUntil: string | null;
|
|
66
|
+
/** Live host test slot tickets of every owner (decision 0018). */
|
|
67
|
+
readonly queue: readonly HostTestSlotTicket[];
|
|
68
|
+
issue(request: HostLoadTokenRequest): HostLoadToken;
|
|
69
|
+
/** Takes an admitted step's ticket out of the queue in the same commit as its token. */
|
|
70
|
+
removeTicket(ticketId: string): void;
|
|
71
|
+
renew(tokenId: string, fencingToken: number): HostLoadToken | null;
|
|
72
|
+
remove(tokenId: string, fencingToken: number): boolean;
|
|
73
|
+
/** Records the step's process tree on its token; null when the token is fenced. */
|
|
74
|
+
attach(tokenId: string, fencingToken: number, stepProcess: HostLoadStepProcess): HostLoadToken | null;
|
|
75
|
+
/** Marks the token kept after its step ended (`retainedAt`), fenced or not; null when it is gone. */
|
|
76
|
+
retain(tokenId: string, fencingToken: number): HostLoadToken | null;
|
|
77
|
+
}
|
|
78
|
+
export interface HostLoadTransactionOutcome<T> {
|
|
79
|
+
readonly result: T;
|
|
80
|
+
readonly reclaimed: readonly HostLoadToken[];
|
|
81
|
+
/**
|
|
82
|
+
* Tokens this owner holds that are fenced (lease lapsed, or lost from the
|
|
83
|
+
* ledger and put back fenced): their steps must stop. They keep their cost
|
|
84
|
+
* until released.
|
|
85
|
+
*/
|
|
86
|
+
readonly fenced: readonly HostLoadToken[];
|
|
87
|
+
/** Tokens this owner holds whose lease this transaction renewed. */
|
|
88
|
+
readonly renewed: readonly HostLoadToken[];
|
|
89
|
+
}
|
|
90
|
+
export interface HostLoadOwnerLiveness {
|
|
91
|
+
isLive(owner: HostLoadTokenOwner): boolean;
|
|
92
|
+
}
|
|
93
|
+
export interface HostLoadTokenLedgerOptions {
|
|
94
|
+
readonly stateRoot: string;
|
|
95
|
+
readonly leaseMs: number;
|
|
96
|
+
readonly now?: () => number;
|
|
97
|
+
readonly liveness?: HostLoadOwnerLiveness;
|
|
98
|
+
/** Owner recorded on tokens this ledger issues; defaults to the current process (resolved lazily). */
|
|
99
|
+
readonly owner?: HostLoadTokenOwner;
|
|
100
|
+
readonly lockTimeoutMs?: number;
|
|
101
|
+
/**
|
|
102
|
+
* Tokens this owner still holds for running steps. Each transaction renews
|
|
103
|
+
* them before it reclaims anything. One missing from the ledger keeps its
|
|
104
|
+
* cost: it is put back (fenced, unless a quarantine is still recovering).
|
|
105
|
+
*/
|
|
106
|
+
readonly heldTokens?: () => readonly HostLoadToken[];
|
|
107
|
+
/**
|
|
108
|
+
* The steps this owner still waits on for the host test slot (decision 0018). Each
|
|
109
|
+
* transaction renews their tickets and drops the owner's other tickets.
|
|
110
|
+
*/
|
|
111
|
+
readonly waitingTickets?: () => readonly HostTestSlotTicketRequest[];
|
|
112
|
+
/** Stops a reclaimed token's step; defaults to the exact process-tree reaper. */
|
|
113
|
+
readonly terminateStep?: HostLoadStepTerminator;
|
|
114
|
+
/** Host suspend counter (test seam); defaults to hostSuspendedMs. */
|
|
115
|
+
readonly suspendedMs?: () => number;
|
|
116
|
+
/** Test seam passed to the ledger lock. */
|
|
117
|
+
readonly beforeStaleLockBreak?: () => Promise<void>;
|
|
118
|
+
}
|
|
119
|
+
export declare class HostCapacityTokenFencedError extends ForgeFailureError {
|
|
120
|
+
readonly tokenId: string;
|
|
121
|
+
readonly code = "host_capacity_token_fenced";
|
|
122
|
+
constructor(tokenId: string, action: "renew" | "release" | "released_fenced");
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* This process as a token owner, computed once. The birth marker is read only
|
|
126
|
+
* on Linux (a cheap /proc read); elsewhere it would mean a synchronous process
|
|
127
|
+
* spawn, so pid reuse there is covered by the lease and the instance id.
|
|
128
|
+
*/
|
|
129
|
+
export declare function currentHostLoadTokenOwner(): HostLoadTokenOwner;
|
|
130
|
+
/** Owner liveness from the OS: dead pid, or a pid reused by a different process, is gone. */
|
|
131
|
+
export declare const processHostLoadOwnerLiveness: HostLoadOwnerLiveness;
|
|
132
|
+
/**
|
|
133
|
+
* Total time the host has been suspended (Linux: boot-time uptime minus the
|
|
134
|
+
* monotonic clock, which stops while suspended). Zero where it is unknown.
|
|
135
|
+
*/
|
|
136
|
+
export declare function hostSuspendedMs(): number;
|
|
137
|
+
export declare class HostLoadTokenLedger {
|
|
138
|
+
private readonly options;
|
|
139
|
+
private readonly root;
|
|
140
|
+
private readonly ledgerPath;
|
|
141
|
+
private readonly now;
|
|
142
|
+
private readonly liveness;
|
|
143
|
+
private resolvedOwner;
|
|
144
|
+
private readonly lock;
|
|
145
|
+
private tail;
|
|
146
|
+
constructor(options: HostLoadTokenLedgerOptions);
|
|
147
|
+
private suspendedMs;
|
|
148
|
+
private get owner();
|
|
149
|
+
/**
|
|
150
|
+
* Runs `action` under the cross-process ledger lock against the live token
|
|
151
|
+
* set. Dead or expired tokens are reclaimed first, so every admission
|
|
152
|
+
* decision sees only real reservations.
|
|
153
|
+
*/
|
|
154
|
+
transaction<T>(action: (transaction: HostLoadLedgerTransaction) => T | Promise<T>): Promise<HostLoadTransactionOutcome<T>>;
|
|
155
|
+
reclaim(): Promise<readonly HostLoadToken[]>;
|
|
156
|
+
list(): Promise<readonly HostLoadToken[]>;
|
|
157
|
+
/** Extends a token's lease. A fenced, reclaimed or superseded token is rejected. */
|
|
158
|
+
renew(tokenId: string, fencingToken: number): Promise<HostLoadToken>;
|
|
159
|
+
/**
|
|
160
|
+
* Returns a token. A reclaimed or superseded token is rejected, never released
|
|
161
|
+
* twice. A fenced token is removed (its owner's step is over) but still
|
|
162
|
+
* reported as fenced.
|
|
163
|
+
*/
|
|
164
|
+
release(tokenId: string, fencingToken: number): Promise<void>;
|
|
165
|
+
private lockedTransaction;
|
|
166
|
+
/** The live token set and host test slot queue one locked transaction reads and changes. */
|
|
167
|
+
private transactionView;
|
|
168
|
+
/**
|
|
169
|
+
* The host test slot queue (decision 0018): other owners' tickets while their owner
|
|
170
|
+
* lives and renews them, and this owner's current waiters, renewed. A ticket this
|
|
171
|
+
* owner no longer waits on (admitted, cancelled, timed out) leaves the queue here.
|
|
172
|
+
*/
|
|
173
|
+
private liveQueue;
|
|
174
|
+
/**
|
|
175
|
+
* Decides every token another owner can no longer vouch for (decision 0013):
|
|
176
|
+
* - owner alive but its lease lapsed (it stalled): the token is fenced, never
|
|
177
|
+
* killed, and keeps its cost; the owner stops its own step when it next
|
|
178
|
+
* touches the ledger and returns the capacity when it releases the token;
|
|
179
|
+
* - owner gone with a recorded process tree: the tree is stopped and confirmed
|
|
180
|
+
* gone first, otherwise the token stays degraded and keeps its cost;
|
|
181
|
+
* - owner gone with no recorded tree: degraded, keeping its cost, until the
|
|
182
|
+
* attempt's teardown or the bridge's restart reap proves the step stopped
|
|
183
|
+
* (releaseOrphaned).
|
|
184
|
+
*/
|
|
185
|
+
private reapExpired;
|
|
186
|
+
/**
|
|
187
|
+
* Returns dead owners' tokens that have no recorded process tree once the
|
|
188
|
+
* caller has proven their steps stopped (attempt teardown after its process
|
|
189
|
+
* trees are stopped, or the restart reap after attempt recovery).
|
|
190
|
+
*/
|
|
191
|
+
releaseOrphaned(belongs: (token: HostLoadToken) => boolean): Promise<readonly HostLoadToken[]>;
|
|
192
|
+
private read;
|
|
193
|
+
/**
|
|
194
|
+
* A corrupt ledger is kept aside for inspection and none of its tokens are
|
|
195
|
+
* trusted. Admissions pause for one lease while live owners, which renew
|
|
196
|
+
* several times per lease, put their running steps' reservations back.
|
|
197
|
+
*/
|
|
198
|
+
private quarantine;
|
|
199
|
+
private write;
|
|
200
|
+
}
|