@loucompanion/forge-bridge 0.1.4-dev.fb770705136a → 0.2.1-dev.0f07274d438b
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 +183 -4
- 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 +15 -0
- package/dist/bridge/bridge-state-io.js +68 -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 +102 -14
- package/dist/bridge/bridge.service.js +499 -471
- package/dist/bridge/bridge.types.d.ts +37 -0
- package/dist/bridge/bridge.types.js +2 -1
- package/dist/bridge/default-session-service.d.ts +13 -0
- package/dist/bridge/default-session-service.js +22 -0
- package/dist/bridge/dispatch-offer-policy.d.ts +22 -0
- package/dist/bridge/dispatch-offer-policy.js +58 -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 +31 -1
- 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/bridge/windows-bash-resolution.d.ts +31 -0
- package/dist/bridge/windows-bash-resolution.js +153 -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 +11 -0
- package/dist/cleanup/forge-owned-paths.js +62 -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 +75 -13
- package/dist/cli/cli.service.d.ts +19 -10
- package/dist/cli/cli.service.js +161 -228
- package/dist/cli/idle-status.d.ts +84 -0
- package/dist/cli/idle-status.js +181 -0
- package/dist/cli/local-config.d.ts +18 -1
- package/dist/cli/local-config.js +67 -5
- package/dist/cli/provider-cli-advertising.d.ts +24 -0
- package/dist/cli/provider-cli-advertising.js +88 -0
- 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 +72 -0
- package/dist/runtime/host-load-admission.js +99 -0
- package/dist/runtime/host-load-capacity.d.ts +198 -0
- package/dist/runtime/host-load-capacity.js +353 -0
- package/dist/runtime/host-load-child-environment.d.ts +40 -0
- package/dist/runtime/host-load-child-environment.js +110 -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 +82 -0
- package/dist/runtime/host-load-governor-config.js +104 -0
- package/dist/runtime/host-load-governor.d.ts +273 -0
- package/dist/runtime/host-load-governor.js +831 -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-live-test-slots.d.ts +61 -0
- package/dist/runtime/host-load-live-test-slots.js +193 -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 +92 -2
- package/dist/runtime/host-load-sampler.js +166 -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 +107 -0
- package/dist/runtime/host-load-step-run.js +158 -0
- package/dist/runtime/host-load-test-slot.d.ts +46 -0
- package/dist/runtime/host-load-test-slot.js +100 -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 +39 -6
- 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 +23 -1
- package/dist/runtime/prepared-runtime-readiness.js +89 -18
- 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 +11 -3
- package/dist/sandbox/runtime.js +53 -20
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/sandbox/sandbox-input.d.ts +22 -0
- package/dist/sandbox/sandbox-input.js +49 -0
- package/dist/sandbox/workspace.service.js +15 -2
- 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 +204 -141
- 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 +7 -0
- package/dist/session/managed-build-receipt.js +11 -3
- package/dist/session/managed-command-environment.d.ts +8 -0
- package/dist/session/managed-command-environment.js +28 -0
- package/dist/session/managed-command-host-load.d.ts +52 -0
- package/dist/session/managed-command-host-load.js +87 -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.artifact-bundle.d.ts +20 -0
- package/dist/session/phase-completion.artifact-bundle.js +167 -0
- package/dist/session/phase-completion.artifacts.d.ts +9 -17
- package/dist/session/phase-completion.artifacts.js +158 -190
- 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 +31 -2
- package/dist/session/phase-completion.helpers.js +18 -65
- package/dist/session/phase-completion.js +19 -32
- package/dist/session/phase-completion.mcp-args.d.ts +9 -0
- package/dist/session/phase-completion.mcp-args.js +195 -0
- package/dist/session/phase-completion.phase-aliases.d.ts +5 -0
- package/dist/session/phase-completion.phase-aliases.js +43 -0
- package/dist/session/phase-completion.pr-review-schema.d.ts +1 -0
- package/dist/session/phase-completion.pr-review-schema.js +75 -0
- package/dist/session/phase-completion.pr-review-validation.d.ts +11 -0
- package/dist/session/phase-completion.pr-review-validation.js +212 -0
- package/dist/session/phase-completion.pr-review.d.ts +36 -0
- package/dist/session/phase-completion.pr-review.js +294 -0
- package/dist/session/phase-completion.prompts.d.ts +1 -1
- package/dist/session/phase-completion.prompts.js +20 -1
- package/dist/session/phase-completion.runtime.d.ts +13 -12
- package/dist/session/phase-completion.runtime.js +113 -214
- 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 +219 -232
- package/dist/session/phase-completion.validation.d.ts +3 -3
- package/dist/session/phase-completion.validation.js +58 -94
- package/dist/session/pr-review-diff-base.d.ts +18 -0
- package/dist/session/pr-review-diff-base.js +44 -0
- package/dist/session/pr-review-placement.d.ts +50 -0
- package/dist/session/pr-review-placement.js +91 -0
- package/dist/session/pre-publication-change-set.d.ts +62 -0
- package/dist/session/pre-publication-change-set.js +166 -0
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +112 -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 +32 -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 +39 -22
- package/dist/session/pre-publication-validation.js +241 -207
- 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/dispatch-target-branch.d.ts +7 -0
- package/dist/session/provider-cli/dispatch-target-branch.js +8 -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/pr-review-credential-isolation.d.ts +83 -0
- package/dist/session/provider-cli/pr-review-credential-isolation.js +144 -0
- package/dist/session/provider-cli/pr-review-guardrails.d.ts +70 -0
- package/dist/session/provider-cli/pr-review-guardrails.js +360 -0
- package/dist/session/provider-cli/pr-review-prompt.d.ts +2 -0
- package/dist/session/provider-cli/pr-review-prompt.js +119 -0
- package/dist/session/provider-cli/pre-publication-repair.d.ts +56 -0
- package/dist/session/provider-cli/pre-publication-repair.js +281 -0
- package/dist/session/provider-cli/provider-cli.base.d.ts +1 -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.deterministic.d.ts +1 -0
- package/dist/session/provider-cli/provider-cli.deterministic.js +5 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +6 -3
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +29 -10
- package/dist/session/provider-cli/provider-cli.pr-review.d.ts +23 -0
- package/dist/session/provider-cli/provider-cli.pr-review.js +213 -0
- 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 +15 -3
- package/dist/session/provider-cli/provider-cli.prompts.js +183 -90
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.d.ts +10 -0
- package/dist/session/provider-cli/provider-cli.reapply-conflicts.js +37 -0
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +15 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +43 -1
- package/dist/session/provider-cli/provider-cli.service-support.d.ts +37 -0
- package/dist/session/provider-cli/provider-cli.service-support.js +146 -0
- package/dist/session/provider-cli/provider-cli.service.d.ts +18 -18
- package/dist/session/provider-cli/provider-cli.service.js +127 -317
- package/dist/session/provider-cli/provider-cli.types.d.ts +35 -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 +279 -0
- package/dist/session/session-host-project.d.ts +22 -0
- package/dist/session/session-host-project.js +98 -0
- package/dist/session/session-redaction.js +31 -181
- package/dist/session/session.base.d.ts +9 -1
- package/dist/session/session.parse-helpers.d.ts +10 -0
- package/dist/session/session.parse-helpers.js +84 -0
- package/dist/session/session.runtime-refresh.d.ts +46 -0
- package/dist/session/session.runtime-refresh.js +116 -0
- package/dist/session/session.service.d.ts +16 -2
- package/dist/session/session.service.js +208 -155
- package/dist/session/session.types.d.ts +8 -0
- package/dist/session/session.types.js +13 -83
- package/dist/session/session.types.pr-review.d.ts +48 -0
- package/dist/session/session.types.pr-review.js +51 -0
- 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.d.ts +2 -0
- package/dist/shared/provider-capabilities.js +23 -7
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/artifact-injector.js +24 -0
- 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 +58 -0
- package/dist/worktree/wip-git.js +182 -0
- package/dist/worktree/wip-refs.d.ts +85 -0
- package/dist/worktree/wip-refs.js +169 -0
- package/dist/worktree/wip-restore.d.ts +51 -0
- package/dist/worktree/wip-restore.js +324 -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 +20 -0
- package/dist/worktree/worktree-wip-events.js +148 -0
- package/dist/worktree/worktree-wip.d.ts +57 -0
- package/dist/worktree/worktree-wip.js +200 -0
- package/dist/worktree/worktree.base.d.ts +7 -1
- package/dist/worktree/worktree.service.d.ts +58 -5
- package/dist/worktree/worktree.service.js +237 -161
- package/dist/worktree/worktree.types.d.ts +54 -0
- package/package.json +2 -2
- package/runtime/windows-listener-owner.ps1 +12 -1
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
const epsilon = 1e-9;
|
|
2
|
+
/**
|
|
3
|
+
* Decision 0013 admission rule. A step is admitted when the reserved cost of
|
|
4
|
+
* running steps plus its own cost fits the budget and host pressure is under
|
|
5
|
+
* the backpressure threshold. Memory `full` pressure is a hard stop. A step
|
|
6
|
+
* too large for the budget on its own runs only when nothing else does. An
|
|
7
|
+
* optional count limit (decision 0014) caps how many heavy steps run at once.
|
|
8
|
+
* Without PSI, a simple per-host semaphore applies instead.
|
|
9
|
+
*/
|
|
10
|
+
export function decideHostLoadAdmission(input) {
|
|
11
|
+
const { request, running, signals, config } = input;
|
|
12
|
+
const reservedCpuCores = running.reduce((sum, cost) => sum + cost.cpuCores, 0);
|
|
13
|
+
const reservedMemoryBytes = running.reduce((sum, cost) => sum + cost.memoryBytes, 0);
|
|
14
|
+
const base = { reservedCpuCores, reservedMemoryBytes };
|
|
15
|
+
const maxHeavySteps = input.maxHeavySteps ?? null;
|
|
16
|
+
if (!signals) {
|
|
17
|
+
// The count limit narrows the semaphore: min(fallback slots, max heavy steps).
|
|
18
|
+
const limited = maxHeavySteps !== null && maxHeavySteps < config.fallbackSlots;
|
|
19
|
+
const slots = limited ? maxHeavySteps : config.fallbackSlots;
|
|
20
|
+
const admitted = running.length < slots;
|
|
21
|
+
return {
|
|
22
|
+
...base,
|
|
23
|
+
admitted,
|
|
24
|
+
reason: admitted ? "admitted_fallback" : limited ? "heavy_step_limit" : "fallback_slots",
|
|
25
|
+
cpuBudgetCores: null,
|
|
26
|
+
memoryBudgetBytes: null,
|
|
27
|
+
detail: admitted
|
|
28
|
+
? "Host pressure data is unavailable; admitted under the per-host step semaphore."
|
|
29
|
+
: limited
|
|
30
|
+
? `Host pressure data is unavailable; ${running.length} of ${slots} heavy step(s) allowed at once are running (max heavy steps).`
|
|
31
|
+
: `Host pressure data is unavailable; ${running.length} of ${config.fallbackSlots} heavy step slot(s) are in use.`,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const cpuBudgetCores = Math.max(0, input.logicalCpus * config.cpuBudgetFraction - (signals.externalCpuCores ?? 0));
|
|
35
|
+
const usedByRunning = Math.min(reservedMemoryBytes, Math.max(0, input.runningMemoryBytes ?? 0));
|
|
36
|
+
const memoryBudgetBytes = signals.memoryAvailableBytes === null
|
|
37
|
+
? null
|
|
38
|
+
: Math.max(0, signals.memoryAvailableBytes + usedByRunning - config.memoryReserveBytes);
|
|
39
|
+
const budget = { ...base, cpuBudgetCores, memoryBudgetBytes };
|
|
40
|
+
if (signals.memoryFullAvg10 !== null && signals.memoryFullAvg10 > config.memoryFullThreshold) {
|
|
41
|
+
return {
|
|
42
|
+
...budget,
|
|
43
|
+
admitted: false,
|
|
44
|
+
reason: "memory_pressure",
|
|
45
|
+
detail: `Host memory pressure (full avg10 ${signals.memoryFullAvg10}%) is above ${config.memoryFullThreshold}%; no heavy step may start.`,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
if (signals.cpuPressuredSamples >= config.backpressureSamples) {
|
|
49
|
+
return {
|
|
50
|
+
...budget,
|
|
51
|
+
admitted: false,
|
|
52
|
+
reason: "cpu_pressure",
|
|
53
|
+
detail: `Host CPU pressure (some avg10 ${signals.cpuSomeAvg10}%) has been at or above ${config.cpuPressureThreshold}% for ${signals.cpuPressuredSamples} sample(s).`,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
if (maxHeavySteps !== null && running.length >= maxHeavySteps) {
|
|
57
|
+
return {
|
|
58
|
+
...budget,
|
|
59
|
+
admitted: false,
|
|
60
|
+
reason: "heavy_step_limit",
|
|
61
|
+
detail: `${running.length} heavy step(s) are running and the host allows at most ${maxHeavySteps} at once.`,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
if (running.length === 0) {
|
|
65
|
+
const oversize = request.cpuCores > cpuBudgetCores + epsilon
|
|
66
|
+
|| (memoryBudgetBytes !== null && request.memoryBytes > memoryBudgetBytes + epsilon);
|
|
67
|
+
return {
|
|
68
|
+
...budget,
|
|
69
|
+
admitted: true,
|
|
70
|
+
reason: oversize ? "admitted_alone" : "admitted",
|
|
71
|
+
detail: oversize
|
|
72
|
+
? "The step exceeds the host budget on its own and runs alone because nothing else is running."
|
|
73
|
+
: "The step fits the host budget.",
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (reservedCpuCores + request.cpuCores > cpuBudgetCores + epsilon) {
|
|
77
|
+
return {
|
|
78
|
+
...budget,
|
|
79
|
+
admitted: false,
|
|
80
|
+
reason: "cpu_budget",
|
|
81
|
+
detail: `Reserved ${round(reservedCpuCores)} + requested ${round(request.cpuCores)} cores exceed the ${round(cpuBudgetCores)}-core budget${signals.externalCpuCores ? ` (${round(signals.externalCpuCores)} cores of external load)` : ""}.`,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
if (memoryBudgetBytes !== null && reservedMemoryBytes + request.memoryBytes > memoryBudgetBytes + epsilon) {
|
|
85
|
+
return {
|
|
86
|
+
...budget,
|
|
87
|
+
admitted: false,
|
|
88
|
+
reason: "memory_budget",
|
|
89
|
+
detail: `Reserved ${gib(reservedMemoryBytes)} + requested ${gib(request.memoryBytes)} GiB exceed the ${gib(memoryBudgetBytes)} GiB memory budget.`,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return { ...budget, admitted: true, reason: "admitted", detail: "The step fits the host budget." };
|
|
93
|
+
}
|
|
94
|
+
function round(value) {
|
|
95
|
+
return Math.round(value * 100) / 100;
|
|
96
|
+
}
|
|
97
|
+
function gib(bytes) {
|
|
98
|
+
return round(bytes / 1024 ** 3);
|
|
99
|
+
}
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
/** What the sizing reads from the host. */
|
|
2
|
+
export interface HostCapacitySpec {
|
|
3
|
+
/** Every CPU on the host: the denominator of the sampler's hostCpuPercent. */
|
|
4
|
+
readonly logicalCpus: number;
|
|
5
|
+
readonly totalMemoryBytes: number;
|
|
6
|
+
/**
|
|
7
|
+
* The CPUs the bridge may use, when a quota or CPU set (a systemd unit, a container, a pod)
|
|
8
|
+
* allows fewer than the host has (os.availableParallelism()). Absent when it does not.
|
|
9
|
+
*/
|
|
10
|
+
readonly allowedCpus?: number;
|
|
11
|
+
/** The memory the bridge may use under a cgroup limit (process.constrainedMemory()), when below the host's. */
|
|
12
|
+
readonly allowedMemoryBytes?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* What one heavy step is planned to need. Measured on a Forge .NET suite: about 1.6
|
|
16
|
+
* cores on average with peaks well above it (parallel test classes, the build before
|
|
17
|
+
* them), and about 2.2 GB for the test host plus its PostgreSQL. The plan covers the
|
|
18
|
+
* peaks, not the average: 6 cores and 4 GiB (the measured memory with ~80% headroom).
|
|
19
|
+
*/
|
|
20
|
+
export declare const hostSuiteCost: {
|
|
21
|
+
readonly cpuCores: 6;
|
|
22
|
+
readonly memoryBytes: number;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Kept for the operating system, the bridge and its agents, and the person using the
|
|
26
|
+
* machine: a quarter of the CPUs (at least 2) and a quarter of the memory (at least 4 GiB).
|
|
27
|
+
* Other work up to this reserve never lowers the live slot count.
|
|
28
|
+
*/
|
|
29
|
+
export declare const hostOwnerReserve: {
|
|
30
|
+
readonly cpuShare: 0.25;
|
|
31
|
+
readonly minimumCpuCores: 2;
|
|
32
|
+
readonly memoryShare: 0.25;
|
|
33
|
+
readonly minimumMemoryBytes: number;
|
|
34
|
+
};
|
|
35
|
+
/** The most slots the sizing picks on its own; an operator may set up to 8. */
|
|
36
|
+
export declare const maximumAutoTestSlots = 4;
|
|
37
|
+
/** Slots when the host cannot be read. */
|
|
38
|
+
export declare const fallbackAutoTestSlots = 1;
|
|
39
|
+
export type HostTestSlotsSource = "auto" | "operator";
|
|
40
|
+
export interface HostTestSlotSizing {
|
|
41
|
+
readonly slots: number;
|
|
42
|
+
readonly source: HostTestSlotsSource;
|
|
43
|
+
/** How the count was chosen, for logs and wait messages. */
|
|
44
|
+
readonly detail: string;
|
|
45
|
+
}
|
|
46
|
+
/** Where detectHostCapacitySpec reads the host (a test seam). */
|
|
47
|
+
export interface HostCapacitySource {
|
|
48
|
+
readonly cpus: () => readonly unknown[];
|
|
49
|
+
readonly totalMemoryBytes: () => number;
|
|
50
|
+
/** The CPUs this process may run on (its quota or CPU set). */
|
|
51
|
+
readonly availableParallelism?: () => number;
|
|
52
|
+
/** The memory limit on this process (its cgroup); 0 or undefined when there is none. */
|
|
53
|
+
readonly constrainedMemoryBytes?: () => number | undefined;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* The host's logical CPUs and total memory; null when either cannot be read. The CPU count is
|
|
57
|
+
* the whole host's (os.cpus(), as the host facts report it): the sampler's hostCpuPercent is a
|
|
58
|
+
* share of every CPU on the host, and live readings must use the same denominator. A tighter CPU
|
|
59
|
+
* quota or memory limit on the bridge itself (os.availableParallelism(),
|
|
60
|
+
* process.constrainedMemory()) is kept beside them, and the configured count is sized within it.
|
|
61
|
+
*/
|
|
62
|
+
export declare function detectHostCapacitySpec(source?: HostCapacitySource): HostCapacitySpec | null;
|
|
63
|
+
/** The CPUs and memory the bridge may use: the host's, within its own CPU quota and memory limit. */
|
|
64
|
+
export declare function allowedHostCapacity(spec: HostCapacitySpec): HostCapacitySpec;
|
|
65
|
+
export declare function hostReserve(spec: HostCapacitySpec): {
|
|
66
|
+
readonly cpuCores: number;
|
|
67
|
+
readonly memoryBytes: number;
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* slots = clamp(min(floor((CPUs - CPU reserve) / 6), floor((memory - memory reserve) / 4 GiB)), 1, 4).
|
|
71
|
+
* 24 CPUs and 64 GB give 3, 8 CPUs and 16 GB give 1 (the 8-thread desktop that could not run
|
|
72
|
+
* two suites), 4 CPUs and 8 GB give 1. A bridge under a CPU quota or a memory limit is sized
|
|
73
|
+
* within it, not for the whole host.
|
|
74
|
+
*/
|
|
75
|
+
export declare function deriveHostTestSlots(spec: HostCapacitySpec): HostTestSlotSizing;
|
|
76
|
+
/** FORGE_HOST_LOAD_TEST_SLOTS when set to a number (0-8), else the auto size. */
|
|
77
|
+
export declare function resolveHostTestSlots(raw: string | undefined, spec: HostCapacitySpec | null): HostTestSlotSizing;
|
|
78
|
+
/**
|
|
79
|
+
* FORGE_TEST_MAX_PARALLEL_CLASSES for one heavy step when several share the host: the
|
|
80
|
+
* test framework's own default (ForgeTestParallelism.DefaultMaxParallelClasses) computed
|
|
81
|
+
* for the step's share of the machine (CPUs / slots and memory / slots), so two suites do
|
|
82
|
+
* not each size themselves for the whole host. Null with one slot: the framework's default
|
|
83
|
+
* already fits.
|
|
84
|
+
*/
|
|
85
|
+
export declare function testParallelClassesPerSlot(spec: HostCapacitySpec, slots: number, nativePostgres: boolean): number | null;
|
|
86
|
+
/**
|
|
87
|
+
* Whether the platform's free-memory figure counts memory the system can reclaim: Linux reads
|
|
88
|
+
* MemAvailable, Windows its available physical memory. Elsewhere (macOS) the sampler falls back
|
|
89
|
+
* to os.freemem(), the free pages alone, which leaves out inactive and purgeable memory and reads
|
|
90
|
+
* most of a normal Mac's RAM as in use, so live readings treat memory there as unknown.
|
|
91
|
+
*/
|
|
92
|
+
export declare function reportsAvailableMemory(platform: string): boolean;
|
|
93
|
+
/** One host reading, from a load sample. */
|
|
94
|
+
export interface HostLiveReading {
|
|
95
|
+
/** When the sample was taken: the sampler's monotonic clock where it has one, so wall-clock steps cannot reorder readings. */
|
|
96
|
+
readonly sampledAtMs: number;
|
|
97
|
+
/** Busy cores on the whole host; null when the platform does not report it. */
|
|
98
|
+
readonly hostCoresInUse: number | null;
|
|
99
|
+
/** Busy cores outside Forge, when the bridge's own cgroup measures Forge's share. */
|
|
100
|
+
readonly externalCoresInUse: number | null;
|
|
101
|
+
readonly memoryAvailableBytes: number | null;
|
|
102
|
+
/**
|
|
103
|
+
* Memory Forge's own work uses, measured from the bridge's dedicated cgroup above its idle
|
|
104
|
+
* baseline; null without one. Each slot holder is taken to use at least its planned 4 GiB.
|
|
105
|
+
*/
|
|
106
|
+
readonly forgeMemoryBytes?: number | null;
|
|
107
|
+
}
|
|
108
|
+
export interface HostLiveSlotTarget {
|
|
109
|
+
readonly slots: number;
|
|
110
|
+
/** Other work on the host, as estimated for this reading. */
|
|
111
|
+
readonly externalCpuCores: number | null;
|
|
112
|
+
readonly externalMemoryBytes: number | null;
|
|
113
|
+
readonly limitedBy: "cpu" | "memory" | null;
|
|
114
|
+
}
|
|
115
|
+
export interface HostLiveSlotTargetInput {
|
|
116
|
+
readonly spec: HostCapacitySpec;
|
|
117
|
+
readonly staticSlots: number;
|
|
118
|
+
readonly reading: HostLiveReading;
|
|
119
|
+
/** Heavy steps holding a slot while the reading was taken, in every process on the host. */
|
|
120
|
+
readonly forgeHolders: number;
|
|
121
|
+
/** Growing back needs this margin of extra room (half a step), so shrink and grow do not flap. */
|
|
122
|
+
readonly withGrowMargin: boolean;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
* The slots the host has room for in one reading. Other work up to the reserve costs
|
|
126
|
+
* nothing; beyond it, each step's planned share (its suite cost, or the host's share per
|
|
127
|
+
* slot when the operator set more slots than the auto size) is taken off. Forge's own CPU
|
|
128
|
+
* is taken from the bridge's dedicated cgroup when it has one. Without it (Windows, or no
|
|
129
|
+
* dedicated cgroup) nothing measures Forge's share: one build can use every core, so while
|
|
130
|
+
* a step holds a slot CPU never lowers the count, and growing back takes each holder to use
|
|
131
|
+
* its share of the CPUs (CPUs / slots), the rest counting as other work. Forge's memory is the
|
|
132
|
+
* larger of what the cgroup measures and the holders' planned memory: Docker sandboxes are
|
|
133
|
+
* charged to Docker's cgroups, not the bridge's.
|
|
134
|
+
*/
|
|
135
|
+
export declare function liveTestSlotTarget(input: HostLiveSlotTargetInput): HostLiveSlotTarget;
|
|
136
|
+
export interface HostTestSlotControllerOptions {
|
|
137
|
+
/** Consecutive readings that must call for fewer slots before the count drops. */
|
|
138
|
+
readonly shrinkSamples?: number;
|
|
139
|
+
/** How long the host must stay clear (with the margin) before the count grows by one. */
|
|
140
|
+
readonly growSettleMs?: number;
|
|
141
|
+
/** A longer gap between readings restarts both streaks. */
|
|
142
|
+
readonly sampleGapMs?: number;
|
|
143
|
+
}
|
|
144
|
+
export declare const defaultTestSlotShrinkSamples = 2;
|
|
145
|
+
export declare const defaultTestSlotGrowSettleMs: number;
|
|
146
|
+
export interface HostLiveTestSlots {
|
|
147
|
+
readonly slots: number;
|
|
148
|
+
/** Why the count is below the configured one; empty when it is not. */
|
|
149
|
+
readonly detail: string;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The live slot count. It drops at once to what the host has room for after
|
|
153
|
+
* `shrinkSamples` consecutive readings call for fewer (the least drastic of them, so one
|
|
154
|
+
* deep spike does not over-shrink), and grows back one slot at a time, each after the
|
|
155
|
+
* host has had room for one more, with the grow margin, for `growSettleMs`. It never
|
|
156
|
+
* drops below 1 and never rises above the configured count. Running steps are never
|
|
157
|
+
* stopped: a lower count only holds back new admissions.
|
|
158
|
+
*
|
|
159
|
+
* A reading is not judged only with the holders at the pass that folds it in: steps that ran
|
|
160
|
+
* while it was taken may have finished since. Shrinking takes the most holders any pass around
|
|
161
|
+
* it saw; growing, which a settle period guards, takes the holders now. A reading no pass came
|
|
162
|
+
* near (folded after a gap, when nothing fed the controller) has unknown holders: it can
|
|
163
|
+
* neither lower the count by CPU nor count Forge's work as room to grow.
|
|
164
|
+
*/
|
|
165
|
+
export declare class HostTestSlotController {
|
|
166
|
+
private readonly spec;
|
|
167
|
+
private readonly staticSlots;
|
|
168
|
+
private limit;
|
|
169
|
+
private lastSampleMs;
|
|
170
|
+
private foldedReadings;
|
|
171
|
+
private readonly passes;
|
|
172
|
+
private shrinkStreak;
|
|
173
|
+
private streakTarget;
|
|
174
|
+
private clearSinceMs;
|
|
175
|
+
private lastShrink;
|
|
176
|
+
private readonly shrinkSamples;
|
|
177
|
+
private readonly growSettleMs;
|
|
178
|
+
private readonly sampleGapMs;
|
|
179
|
+
constructor(spec: HostCapacitySpec, staticSlots: number, options?: HostTestSlotControllerOptions);
|
|
180
|
+
/** Folds in the readings not seen yet, oldest first, with `forgeHolders` holding slots across the host now. */
|
|
181
|
+
observe(readings: readonly HostLiveReading[], forgeHolders: number): HostLiveTestSlots;
|
|
182
|
+
/** The holders a pass left after its admissions: they count for the readings that follow it. */
|
|
183
|
+
noteHolders(forgeHolders: number): void;
|
|
184
|
+
/** How many readings the controller has taken in so far: a pass that adds none had nothing fresh. */
|
|
185
|
+
get readingsTaken(): number;
|
|
186
|
+
/** Whether the count is below the configured one now. */
|
|
187
|
+
get lowered(): boolean;
|
|
188
|
+
/**
|
|
189
|
+
* The count in force and why. The detail changes only with the count: a waiting step is told
|
|
190
|
+
* again whenever its slot wait's detail changes (waitChanged), so it carries nothing that
|
|
191
|
+
* moves from one reading to the next, such as whether the latest reading would let it grow.
|
|
192
|
+
*/
|
|
193
|
+
current(): HostLiveTestSlots;
|
|
194
|
+
private notePass;
|
|
195
|
+
/** The holders to judge a reading with: for shrinking the most around it, for growing those now. */
|
|
196
|
+
private holdersAround;
|
|
197
|
+
private step;
|
|
198
|
+
}
|
|
@@ -0,0 +1,353 @@
|
|
|
1
|
+
import os from "node:os";
|
|
2
|
+
// Host capacity sizing (plan Phase 4, first slice; amends decision 0018). With
|
|
3
|
+
// FORGE_HOST_LOAD_TEST_SLOTS unset, the number of heavy steps (builds, test runs,
|
|
4
|
+
// Playwright) a host runs at once comes from its logical CPUs and total memory, and
|
|
5
|
+
// while the bridge runs it is lowered when other work on the machine needs it: fast to
|
|
6
|
+
// shrink, slow to grow back, with a margin between the two so it does not flap. An
|
|
7
|
+
// explicit FORGE_HOST_LOAD_TEST_SLOTS stays the operator's override (0 turns the slot
|
|
8
|
+
// off); live adjustment only ever lowers it.
|
|
9
|
+
const gib = 1024 ** 3;
|
|
10
|
+
const epsilon = 1e-9;
|
|
11
|
+
/**
|
|
12
|
+
* What one heavy step is planned to need. Measured on a Forge .NET suite: about 1.6
|
|
13
|
+
* cores on average with peaks well above it (parallel test classes, the build before
|
|
14
|
+
* them), and about 2.2 GB for the test host plus its PostgreSQL. The plan covers the
|
|
15
|
+
* peaks, not the average: 6 cores and 4 GiB (the measured memory with ~80% headroom).
|
|
16
|
+
*/
|
|
17
|
+
export const hostSuiteCost = { cpuCores: 6, memoryBytes: 4 * gib };
|
|
18
|
+
/**
|
|
19
|
+
* Kept for the operating system, the bridge and its agents, and the person using the
|
|
20
|
+
* machine: a quarter of the CPUs (at least 2) and a quarter of the memory (at least 4 GiB).
|
|
21
|
+
* Other work up to this reserve never lowers the live slot count.
|
|
22
|
+
*/
|
|
23
|
+
export const hostOwnerReserve = {
|
|
24
|
+
cpuShare: 0.25,
|
|
25
|
+
minimumCpuCores: 2,
|
|
26
|
+
memoryShare: 0.25,
|
|
27
|
+
minimumMemoryBytes: 4 * gib,
|
|
28
|
+
};
|
|
29
|
+
/** The most slots the sizing picks on its own; an operator may set up to 8. */
|
|
30
|
+
export const maximumAutoTestSlots = 4;
|
|
31
|
+
/** Slots when the host cannot be read. */
|
|
32
|
+
export const fallbackAutoTestSlots = 1;
|
|
33
|
+
const osCapacitySource = {
|
|
34
|
+
cpus: () => os.cpus(),
|
|
35
|
+
totalMemoryBytes: () => os.totalmem(),
|
|
36
|
+
availableParallelism: () => os.availableParallelism(),
|
|
37
|
+
constrainedMemoryBytes: () => process.constrainedMemory(),
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* The host's logical CPUs and total memory; null when either cannot be read. The CPU count is
|
|
41
|
+
* the whole host's (os.cpus(), as the host facts report it): the sampler's hostCpuPercent is a
|
|
42
|
+
* share of every CPU on the host, and live readings must use the same denominator. A tighter CPU
|
|
43
|
+
* quota or memory limit on the bridge itself (os.availableParallelism(),
|
|
44
|
+
* process.constrainedMemory()) is kept beside them, and the configured count is sized within it.
|
|
45
|
+
*/
|
|
46
|
+
export function detectHostCapacitySpec(source = osCapacitySource) {
|
|
47
|
+
try {
|
|
48
|
+
const logicalCpus = source.cpus().length;
|
|
49
|
+
const totalMemoryBytes = source.totalMemoryBytes();
|
|
50
|
+
if (!(logicalCpus > 0) || !(totalMemoryBytes > 0))
|
|
51
|
+
return null;
|
|
52
|
+
const allowedCpus = limitBelow(source.availableParallelism, logicalCpus);
|
|
53
|
+
const allowedMemoryBytes = limitBelow(source.constrainedMemoryBytes, totalMemoryBytes);
|
|
54
|
+
return {
|
|
55
|
+
logicalCpus,
|
|
56
|
+
totalMemoryBytes,
|
|
57
|
+
...allowedCpus === null ? {} : { allowedCpus },
|
|
58
|
+
...allowedMemoryBytes === null ? {} : { allowedMemoryBytes },
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
catch {
|
|
62
|
+
return null;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/** A positive limit below the host's own figure; null when there is none or it cannot be read. */
|
|
66
|
+
function limitBelow(read, whole) {
|
|
67
|
+
try {
|
|
68
|
+
const value = read?.();
|
|
69
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 && value < whole ? value : null;
|
|
70
|
+
}
|
|
71
|
+
catch {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** The CPUs and memory the bridge may use: the host's, within its own CPU quota and memory limit. */
|
|
76
|
+
export function allowedHostCapacity(spec) {
|
|
77
|
+
return {
|
|
78
|
+
logicalCpus: Math.min(spec.logicalCpus, spec.allowedCpus ?? spec.logicalCpus),
|
|
79
|
+
totalMemoryBytes: Math.min(spec.totalMemoryBytes, spec.allowedMemoryBytes ?? spec.totalMemoryBytes),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export function hostReserve(spec) {
|
|
83
|
+
return {
|
|
84
|
+
cpuCores: Math.max(hostOwnerReserve.minimumCpuCores, spec.logicalCpus * hostOwnerReserve.cpuShare),
|
|
85
|
+
memoryBytes: Math.max(hostOwnerReserve.minimumMemoryBytes, spec.totalMemoryBytes * hostOwnerReserve.memoryShare),
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* slots = clamp(min(floor((CPUs - CPU reserve) / 6), floor((memory - memory reserve) / 4 GiB)), 1, 4).
|
|
90
|
+
* 24 CPUs and 64 GB give 3, 8 CPUs and 16 GB give 1 (the 8-thread desktop that could not run
|
|
91
|
+
* two suites), 4 CPUs and 8 GB give 1. A bridge under a CPU quota or a memory limit is sized
|
|
92
|
+
* within it, not for the whole host.
|
|
93
|
+
*/
|
|
94
|
+
export function deriveHostTestSlots(spec) {
|
|
95
|
+
const allowed = allowedHostCapacity(spec);
|
|
96
|
+
const reserve = hostReserve(allowed);
|
|
97
|
+
const byCpu = Math.floor((allowed.logicalCpus - reserve.cpuCores) / hostSuiteCost.cpuCores + epsilon);
|
|
98
|
+
const byMemory = Math.floor((allowed.totalMemoryBytes - reserve.memoryBytes) / hostSuiteCost.memoryBytes + epsilon);
|
|
99
|
+
const slots = Math.min(maximumAutoTestSlots, Math.max(1, Math.min(byCpu, byMemory)));
|
|
100
|
+
const limit = slots === maximumAutoTestSlots && Math.min(byCpu, byMemory) > maximumAutoTestSlots
|
|
101
|
+
? `the ceiling of ${maximumAutoTestSlots}`
|
|
102
|
+
: byCpu <= byMemory ? "CPU" : "memory";
|
|
103
|
+
return {
|
|
104
|
+
slots,
|
|
105
|
+
source: "auto",
|
|
106
|
+
detail: `auto-sized from ${allowed.logicalCpus} logical CPUs`
|
|
107
|
+
+ `${allowed.logicalCpus < spec.logicalCpus ? ` (the bridge's CPU limit; the host has ${spec.logicalCpus})` : ""}`
|
|
108
|
+
+ ` and ${round(allowed.totalMemoryBytes / gib)} GiB`
|
|
109
|
+
+ `${allowed.totalMemoryBytes < spec.totalMemoryBytes ? ` (the bridge's memory limit; the host has ${round(spec.totalMemoryBytes / gib)} GiB)` : ""}: `
|
|
110
|
+
+ `${Math.max(0, byCpu)} by CPU (${round(reserve.cpuCores)} kept for the host, ${hostSuiteCost.cpuCores} per step), `
|
|
111
|
+
+ `${Math.max(0, byMemory)} by memory (${round(reserve.memoryBytes / gib)} GiB kept, ${hostSuiteCost.memoryBytes / gib} GiB per step); `
|
|
112
|
+
+ `limited by ${limit}${Math.min(byCpu, byMemory) < 1 ? ", never below 1" : ""}`,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
/** FORGE_HOST_LOAD_TEST_SLOTS when set to a number (0-8), else the auto size. */
|
|
116
|
+
export function resolveHostTestSlots(raw, spec) {
|
|
117
|
+
const trimmed = raw?.trim() ?? "";
|
|
118
|
+
const value = trimmed === "" ? Number.NaN : Number(trimmed);
|
|
119
|
+
if (Number.isFinite(value)) {
|
|
120
|
+
const slots = Math.round(Math.min(8, Math.max(0, value)));
|
|
121
|
+
return {
|
|
122
|
+
slots,
|
|
123
|
+
source: "operator",
|
|
124
|
+
detail: slots === 0
|
|
125
|
+
? "turned off by the operator (FORGE_HOST_LOAD_TEST_SLOTS=0)"
|
|
126
|
+
: `set by the operator (FORGE_HOST_LOAD_TEST_SLOTS=${trimmed})`,
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
const ignored = trimmed === "" ? "" : ` (FORGE_HOST_LOAD_TEST_SLOTS=${JSON.stringify(trimmed)} is not a number and was ignored)`;
|
|
130
|
+
if (!spec) {
|
|
131
|
+
return { slots: fallbackAutoTestSlots, source: "auto", detail: `the host's size could not be read, so ${fallbackAutoTestSlots}${ignored}` };
|
|
132
|
+
}
|
|
133
|
+
const sizing = deriveHostTestSlots(spec);
|
|
134
|
+
return { ...sizing, detail: `${sizing.detail}${ignored}` };
|
|
135
|
+
}
|
|
136
|
+
/** Matches tests/Forge.Api.Tests ForgeTestParallelism.ContainerMaxParallelClasses. */
|
|
137
|
+
const containerMaxParallelClasses = 12;
|
|
138
|
+
/**
|
|
139
|
+
* FORGE_TEST_MAX_PARALLEL_CLASSES for one heavy step when several share the host: the
|
|
140
|
+
* test framework's own default (ForgeTestParallelism.DefaultMaxParallelClasses) computed
|
|
141
|
+
* for the step's share of the machine (CPUs / slots and memory / slots), so two suites do
|
|
142
|
+
* not each size themselves for the whole host. Null with one slot: the framework's default
|
|
143
|
+
* already fits.
|
|
144
|
+
*/
|
|
145
|
+
export function testParallelClassesPerSlot(spec, slots, nativePostgres) {
|
|
146
|
+
if (slots <= 1)
|
|
147
|
+
return null;
|
|
148
|
+
// The bridge's own quota and limit: a step's test host inherits them.
|
|
149
|
+
const allowed = allowedHostCapacity(spec);
|
|
150
|
+
const processorCount = Math.max(1, Math.floor(allowed.logicalCpus / slots));
|
|
151
|
+
const memoryBytes = allowed.totalMemoryBytes / slots;
|
|
152
|
+
let byCores = Math.max(2, Math.floor(processorCount * 3 / 2));
|
|
153
|
+
if (!nativePostgres)
|
|
154
|
+
byCores = Math.min(byCores, containerMaxParallelClasses);
|
|
155
|
+
const [reserved, perClass] = nativePostgres ? [4 * gib, 2 * gib] : [2 * gib, (9 * gib) / 10];
|
|
156
|
+
const byMemory = Math.floor((memoryBytes - reserved) / perClass);
|
|
157
|
+
return Math.min(byCores, Math.max(2, byMemory));
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Whether the platform's free-memory figure counts memory the system can reclaim: Linux reads
|
|
161
|
+
* MemAvailable, Windows its available physical memory. Elsewhere (macOS) the sampler falls back
|
|
162
|
+
* to os.freemem(), the free pages alone, which leaves out inactive and purgeable memory and reads
|
|
163
|
+
* most of a normal Mac's RAM as in use, so live readings treat memory there as unknown.
|
|
164
|
+
*/
|
|
165
|
+
export function reportsAvailableMemory(platform) {
|
|
166
|
+
return platform === "linux" || platform === "win32";
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* The slots the host has room for in one reading. Other work up to the reserve costs
|
|
170
|
+
* nothing; beyond it, each step's planned share (its suite cost, or the host's share per
|
|
171
|
+
* slot when the operator set more slots than the auto size) is taken off. Forge's own CPU
|
|
172
|
+
* is taken from the bridge's dedicated cgroup when it has one. Without it (Windows, or no
|
|
173
|
+
* dedicated cgroup) nothing measures Forge's share: one build can use every core, so while
|
|
174
|
+
* a step holds a slot CPU never lowers the count, and growing back takes each holder to use
|
|
175
|
+
* its share of the CPUs (CPUs / slots), the rest counting as other work. Forge's memory is the
|
|
176
|
+
* larger of what the cgroup measures and the holders' planned memory: Docker sandboxes are
|
|
177
|
+
* charged to Docker's cgroups, not the bridge's.
|
|
178
|
+
*/
|
|
179
|
+
export function liveTestSlotTarget(input) {
|
|
180
|
+
const { spec, staticSlots, reading, forgeHolders } = input;
|
|
181
|
+
const reserve = hostReserve(spec);
|
|
182
|
+
const unmeasuredHolders = forgeHolders > 0 && !input.withGrowMargin;
|
|
183
|
+
const externalCpuCores = reading.externalCoresInUse ?? (reading.hostCoresInUse === null || unmeasuredHolders
|
|
184
|
+
? null
|
|
185
|
+
: Math.max(0, reading.hostCoresInUse - forgeHolders * (allowedHostCapacity(spec).logicalCpus / staticSlots)));
|
|
186
|
+
const usedMemory = reading.memoryAvailableBytes === null
|
|
187
|
+
? null
|
|
188
|
+
: Math.max(0, spec.totalMemoryBytes - reading.memoryAvailableBytes);
|
|
189
|
+
const forgeMemoryBytes = Math.max(reading.forgeMemoryBytes ?? 0, forgeHolders * hostSuiteCost.memoryBytes);
|
|
190
|
+
const externalMemoryBytes = usedMemory === null
|
|
191
|
+
? null
|
|
192
|
+
: Math.max(0, usedMemory - Math.min(usedMemory, forgeMemoryBytes));
|
|
193
|
+
const cpuSlots = slotsWithRoom(spec.logicalCpus, reserve.cpuCores, hostSuiteCost.cpuCores, staticSlots, externalCpuCores, input.withGrowMargin);
|
|
194
|
+
const memorySlots = slotsWithRoom(spec.totalMemoryBytes, reserve.memoryBytes, hostSuiteCost.memoryBytes, staticSlots, externalMemoryBytes, input.withGrowMargin);
|
|
195
|
+
const slots = Math.max(1, Math.min(staticSlots, cpuSlots, memorySlots));
|
|
196
|
+
const limitedBy = slots >= staticSlots ? null : cpuSlots <= memorySlots ? "cpu" : "memory";
|
|
197
|
+
return { slots, externalCpuCores, externalMemoryBytes, limitedBy };
|
|
198
|
+
}
|
|
199
|
+
function slotsWithRoom(capacity, reserve, stepCost, staticSlots, external, withGrowMargin) {
|
|
200
|
+
const perSlot = Math.min(stepCost, (capacity - reserve) / staticSlots);
|
|
201
|
+
if (external === null || !(perSlot > 0))
|
|
202
|
+
return staticSlots;
|
|
203
|
+
const otherWork = external + (withGrowMargin ? perSlot / 2 : 0);
|
|
204
|
+
return Math.floor((capacity - Math.max(reserve, otherWork)) / perSlot + epsilon);
|
|
205
|
+
}
|
|
206
|
+
export const defaultTestSlotShrinkSamples = 2;
|
|
207
|
+
export const defaultTestSlotGrowSettleMs = 2 * 60_000;
|
|
208
|
+
/**
|
|
209
|
+
* The live slot count. It drops at once to what the host has room for after
|
|
210
|
+
* `shrinkSamples` consecutive readings call for fewer (the least drastic of them, so one
|
|
211
|
+
* deep spike does not over-shrink), and grows back one slot at a time, each after the
|
|
212
|
+
* host has had room for one more, with the grow margin, for `growSettleMs`. It never
|
|
213
|
+
* drops below 1 and never rises above the configured count. Running steps are never
|
|
214
|
+
* stopped: a lower count only holds back new admissions.
|
|
215
|
+
*
|
|
216
|
+
* A reading is not judged only with the holders at the pass that folds it in: steps that ran
|
|
217
|
+
* while it was taken may have finished since. Shrinking takes the most holders any pass around
|
|
218
|
+
* it saw; growing, which a settle period guards, takes the holders now. A reading no pass came
|
|
219
|
+
* near (folded after a gap, when nothing fed the controller) has unknown holders: it can
|
|
220
|
+
* neither lower the count by CPU nor count Forge's work as room to grow.
|
|
221
|
+
*/
|
|
222
|
+
export class HostTestSlotController {
|
|
223
|
+
spec;
|
|
224
|
+
staticSlots;
|
|
225
|
+
limit;
|
|
226
|
+
lastSampleMs = null;
|
|
227
|
+
foldedReadings = 0;
|
|
228
|
+
passes = [];
|
|
229
|
+
shrinkStreak = 0;
|
|
230
|
+
streakTarget = null;
|
|
231
|
+
clearSinceMs = null;
|
|
232
|
+
lastShrink = null;
|
|
233
|
+
shrinkSamples;
|
|
234
|
+
growSettleMs;
|
|
235
|
+
sampleGapMs;
|
|
236
|
+
constructor(spec, staticSlots, options = {}) {
|
|
237
|
+
this.spec = spec;
|
|
238
|
+
this.staticSlots = staticSlots;
|
|
239
|
+
this.limit = staticSlots;
|
|
240
|
+
this.shrinkSamples = Math.max(1, Math.round(options.shrinkSamples ?? defaultTestSlotShrinkSamples));
|
|
241
|
+
this.growSettleMs = Math.max(0, options.growSettleMs ?? defaultTestSlotGrowSettleMs);
|
|
242
|
+
this.sampleGapMs = Math.max(1, options.sampleGapMs ?? 15_000);
|
|
243
|
+
}
|
|
244
|
+
/** Folds in the readings not seen yet, oldest first, with `forgeHolders` holding slots across the host now. */
|
|
245
|
+
observe(readings, forgeHolders) {
|
|
246
|
+
const fresh = readings
|
|
247
|
+
.filter(reading => Number.isFinite(reading.sampledAtMs) && (this.lastSampleMs === null || reading.sampledAtMs > this.lastSampleMs))
|
|
248
|
+
.sort((a, b) => a.sampledAtMs - b.sampledAtMs);
|
|
249
|
+
for (const reading of fresh)
|
|
250
|
+
this.step(reading, this.holdersAround(reading.sampledAtMs, forgeHolders));
|
|
251
|
+
this.foldedReadings += fresh.length;
|
|
252
|
+
if (this.lastSampleMs !== null)
|
|
253
|
+
this.notePass(this.lastSampleMs, forgeHolders);
|
|
254
|
+
return this.current();
|
|
255
|
+
}
|
|
256
|
+
/** The holders a pass left after its admissions: they count for the readings that follow it. */
|
|
257
|
+
noteHolders(forgeHolders) {
|
|
258
|
+
const last = this.passes.at(-1);
|
|
259
|
+
if (last)
|
|
260
|
+
last.most = Math.max(last.most, forgeHolders);
|
|
261
|
+
}
|
|
262
|
+
/** How many readings the controller has taken in so far: a pass that adds none had nothing fresh. */
|
|
263
|
+
get readingsTaken() {
|
|
264
|
+
return this.foldedReadings;
|
|
265
|
+
}
|
|
266
|
+
/** Whether the count is below the configured one now. */
|
|
267
|
+
get lowered() {
|
|
268
|
+
return this.limit < this.staticSlots;
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* The count in force and why. The detail changes only with the count: a waiting step is told
|
|
272
|
+
* again whenever its slot wait's detail changes (waitChanged), so it carries nothing that
|
|
273
|
+
* moves from one reading to the next, such as whether the latest reading would let it grow.
|
|
274
|
+
*/
|
|
275
|
+
current() {
|
|
276
|
+
if (this.limit >= this.staticSlots)
|
|
277
|
+
return { slots: this.limit, detail: "" };
|
|
278
|
+
return {
|
|
279
|
+
slots: this.limit,
|
|
280
|
+
detail: `reduced from ${this.staticSlots} for other work on the host${this.lastShrink ? ` (${describeOtherWork(this.lastShrink)})` : ""}; it returns one slot at a time once the host clears`,
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
notePass(atMs, forgeHolders) {
|
|
284
|
+
const last = this.passes.at(-1);
|
|
285
|
+
if (last?.atMs === atMs) {
|
|
286
|
+
this.noteHolders(forgeHolders);
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
this.passes.push({ atMs, most: forgeHolders });
|
|
290
|
+
}
|
|
291
|
+
// Only passes within reach of a later reading's window are kept.
|
|
292
|
+
while (this.passes.length > 0 && this.passes[0].atMs < atMs - 2 * this.sampleGapMs)
|
|
293
|
+
this.passes.shift();
|
|
294
|
+
}
|
|
295
|
+
/** The holders to judge a reading with: for shrinking the most around it, for growing those now. */
|
|
296
|
+
holdersAround(sampledAtMs, current) {
|
|
297
|
+
const near = this.passes.filter(pass => pass.atMs >= sampledAtMs - this.sampleGapMs);
|
|
298
|
+
if (near.length === 0)
|
|
299
|
+
return { shrink: Math.max(current, this.staticSlots), grow: 0 };
|
|
300
|
+
return { shrink: Math.max(current, ...near.map(pass => pass.most)), grow: current };
|
|
301
|
+
}
|
|
302
|
+
step(reading, holders) {
|
|
303
|
+
if (this.lastSampleMs !== null && reading.sampledAtMs <= this.lastSampleMs)
|
|
304
|
+
return;
|
|
305
|
+
if (this.lastSampleMs !== null && reading.sampledAtMs - this.lastSampleMs > this.sampleGapMs) {
|
|
306
|
+
this.shrinkStreak = 0;
|
|
307
|
+
this.streakTarget = null;
|
|
308
|
+
this.clearSinceMs = null;
|
|
309
|
+
}
|
|
310
|
+
this.lastSampleMs = reading.sampledAtMs;
|
|
311
|
+
const input = { spec: this.spec, staticSlots: this.staticSlots, reading };
|
|
312
|
+
const shrink = liveTestSlotTarget({ ...input, forgeHolders: holders.shrink, withGrowMargin: false });
|
|
313
|
+
if (shrink.slots < this.limit) {
|
|
314
|
+
this.shrinkStreak += 1;
|
|
315
|
+
// The least drastic reading of the streak; the latest one when they agree.
|
|
316
|
+
this.streakTarget = this.streakTarget && this.streakTarget.slots > shrink.slots ? this.streakTarget : shrink;
|
|
317
|
+
if (this.shrinkStreak >= this.shrinkSamples) {
|
|
318
|
+
this.limit = Math.max(1, this.streakTarget.slots);
|
|
319
|
+
this.lastShrink = this.streakTarget;
|
|
320
|
+
this.shrinkStreak = 0;
|
|
321
|
+
this.streakTarget = null;
|
|
322
|
+
this.clearSinceMs = null;
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
else {
|
|
327
|
+
this.shrinkStreak = 0;
|
|
328
|
+
this.streakTarget = null;
|
|
329
|
+
}
|
|
330
|
+
const grow = liveTestSlotTarget({ ...input, forgeHolders: holders.grow, withGrowMargin: true });
|
|
331
|
+
if (grow.slots > this.limit) {
|
|
332
|
+
this.clearSinceMs ??= reading.sampledAtMs;
|
|
333
|
+
if (reading.sampledAtMs - this.clearSinceMs >= this.growSettleMs) {
|
|
334
|
+
this.limit = Math.min(this.staticSlots, this.limit + 1);
|
|
335
|
+
this.clearSinceMs = this.limit < this.staticSlots ? reading.sampledAtMs : null;
|
|
336
|
+
if (this.limit >= this.staticSlots)
|
|
337
|
+
this.lastShrink = null;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
this.clearSinceMs = null;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
function describeOtherWork(target) {
|
|
346
|
+
const cpu = target.externalCpuCores === null ? null : `about ${round(target.externalCpuCores)} cores`;
|
|
347
|
+
const memory = target.externalMemoryBytes === null ? null : `${round(target.externalMemoryBytes / gib)} GiB`;
|
|
348
|
+
const parts = target.limitedBy === "memory" ? [memory, cpu] : [cpu, memory];
|
|
349
|
+
return `${parts.filter(Boolean).join(" and ")} in use outside Forge's heavy steps`;
|
|
350
|
+
}
|
|
351
|
+
function round(value) {
|
|
352
|
+
return Math.round(value * 10) / 10;
|
|
353
|
+
}
|