@loucompanion/forge-bridge 0.1.4-dev.fb770705136a → 0.2.1-dev.15efe2d7309f
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 +146 -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 +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 +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 +72 -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 +61 -0
- package/dist/runtime/host-load-governor-config.js +86 -0
- package/dist/runtime/host-load-governor.d.ts +193 -0
- package/dist/runtime/host-load-governor.js +662 -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 +88 -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 +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 +277 -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 +29 -10
- 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 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +109 -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 +106 -181
- 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 +257 -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.service.d.ts +15 -2
- package/dist/session/session.service.js +246 -138
- 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 +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 +36 -5
- package/dist/worktree/worktree.service.js +127 -155
- package/dist/worktree/worktree.types.d.ts +47 -0
- package/package.json +2 -2
- package/runtime/windows-listener-owner.ps1 +12 -1
|
@@ -2,21 +2,34 @@ import { redactRunnerDispatchEvent, redactRunOnceResultPacket } from "./session-
|
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { RoutingProviderCliService } from "./provider-cli/provider-cli.service.js";
|
|
4
4
|
import { ForgeFailureError, waitKindForEvent, waitWakeCondition } from "./session.types.js";
|
|
5
|
-
import { GitWorktreeService } from "../worktree/worktree.service.js";
|
|
5
|
+
import { emitWorktreePreparedEvents, GitWorktreeService, sessionWipOutcome, settleWorktree, } from "../worktree/worktree.service.js";
|
|
6
6
|
import { SandboxWorkspaceService } from "../sandbox/workspace.service.js";
|
|
7
|
-
import { HostRuntimeAdmissionExpiredError, hostRuntimeEventResources, } from "../runtime/host-runtime-lease.js";
|
|
7
|
+
import { HostRuntimeAdmissionExpiredError, hostRuntimeEventResources, hostRuntimeStackEnvironmentKeys, runtimeAdmissionPriority, } from "../runtime/host-runtime-lease.js";
|
|
8
8
|
import { configuredLaunchPortNames, hostRuntimeContractFingerprint, hostRuntimeParallelEligible, } from "../runtime/host-runtime-promotion.js";
|
|
9
|
+
import { managedQaLaunchTarget, runtimeRestartStartedMessage, startOrDeferConfiguredProject, withMaterializedManagedQaTarget, } from "./session-host-project.js";
|
|
10
|
+
import { readWorkspaceRuntimeFingerprint, sameWorkspaceRuntimeFingerprint, workspaceRuntimeFingerprintChanges, } from "./workspace-runtime-fingerprint.js";
|
|
9
11
|
const minimumReadinessProbeStartupBudgetMs = 150_000;
|
|
10
12
|
export class BridgeSessionService {
|
|
11
13
|
worktrees;
|
|
12
14
|
providerCli;
|
|
13
15
|
hostRuntime;
|
|
16
|
+
workspaceFingerprint;
|
|
14
17
|
constructor(worktrees = process.env.FORGE_SANDBOX_ID
|
|
15
18
|
? new SandboxWorkspaceService()
|
|
16
|
-
: new GitWorktreeService(), providerCli = new RoutingProviderCliService(), hostRuntime) {
|
|
19
|
+
: new GitWorktreeService(), providerCli = new RoutingProviderCliService(), hostRuntime, workspaceFingerprint = readWorkspaceRuntimeFingerprint) {
|
|
17
20
|
this.worktrees = worktrees;
|
|
18
21
|
this.providerCli = providerCli;
|
|
19
22
|
this.hostRuntime = hostRuntime;
|
|
23
|
+
this.workspaceFingerprint = workspaceFingerprint;
|
|
24
|
+
}
|
|
25
|
+
setHostRequirementsCheck(check) {
|
|
26
|
+
this.hostRuntime?.setRequirementsCheck?.(check);
|
|
27
|
+
}
|
|
28
|
+
runnerLimitDefaults() {
|
|
29
|
+
return this.hostRuntime?.capacityLimitDefaults?.() ?? null;
|
|
30
|
+
}
|
|
31
|
+
applyRunnerLimits(limits) {
|
|
32
|
+
this.hostRuntime?.applyCapacityLimits?.(limits);
|
|
20
33
|
}
|
|
21
34
|
async updateLease(dispatchAttemptId, fencingToken, expiresAt) {
|
|
22
35
|
await this.hostRuntime?.updateLease(dispatchAttemptId, fencingToken, expiresAt);
|
|
@@ -61,9 +74,11 @@ export class BridgeSessionService {
|
|
|
61
74
|
// failed agent worktrees for inspection.
|
|
62
75
|
cleanupWorktrees: dispatch.serverLocal.cleanupWorktrees,
|
|
63
76
|
artifacts: [],
|
|
77
|
+
hostLoadOwner: { dispatchAttemptId: dispatch.sandbox?.dispatchAttemptId ?? null, priority: "background" },
|
|
78
|
+
signal,
|
|
64
79
|
});
|
|
65
80
|
assertReadinessProbeStartupBudget(request.expiresAt);
|
|
66
|
-
|
|
81
|
+
const started = await this.hostRuntime.start(dispatch, worktree.worktreePath, signal);
|
|
67
82
|
runtimeStarted = true;
|
|
68
83
|
const discovery = started.runtimeContract.discovery;
|
|
69
84
|
if (!hostRuntimeParallelEligible(started.runtimeContract)) {
|
|
@@ -71,28 +86,14 @@ export class BridgeSessionService {
|
|
|
71
86
|
status: "serialized",
|
|
72
87
|
runtimeContractFingerprint: hostRuntimeContractFingerprint(started.runtimeContract),
|
|
73
88
|
runtimeContractSource: started.runtimeContract.source,
|
|
89
|
+
runtimeRequirements: started.runtimeContract.contract.requires ?? null,
|
|
74
90
|
reasonCode: discovery?.reasonCode ?? "host_runtime_contract_serialized",
|
|
75
91
|
reasonMessage: discovery?.summary ?? "The detected runtime requires serialized host execution.",
|
|
76
92
|
checkedAt: new Date().toISOString(),
|
|
77
93
|
};
|
|
78
94
|
}
|
|
79
95
|
else {
|
|
80
|
-
|
|
81
|
-
started = await this.hostRuntime.startConfiguredProject(request.requestId, request.fencingToken, signal);
|
|
82
|
-
const requiredPorts = configuredLaunchPortNames(started.runtimeContract);
|
|
83
|
-
const verifiedPorts = started.lease.resources.ports.map(port => port.name);
|
|
84
|
-
const verified = requiredPorts.length > 0 && requiredPorts.every(name => verifiedPorts.includes(name));
|
|
85
|
-
result = verified
|
|
86
|
-
? {
|
|
87
|
-
status: "parallel_ready",
|
|
88
|
-
runtimeContractFingerprint: hostRuntimeContractFingerprint(started.runtimeContract),
|
|
89
|
-
runtimeContractSource: started.runtimeContract.source,
|
|
90
|
-
reasonCode: null,
|
|
91
|
-
reasonMessage: null,
|
|
92
|
-
qaAppLaunchTarget: managedQaLaunchTarget(started.runtimeContract),
|
|
93
|
-
checkedAt: new Date().toISOString(),
|
|
94
|
-
}
|
|
95
|
-
: failedProbe("host_runtime_probe_unverified", "The application did not prove ownership and readiness on every Forge-assigned port.");
|
|
96
|
+
result = await this.probeConfiguredProject(this.hostRuntime, request, started, signal);
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
catch (error) {
|
|
@@ -174,6 +175,7 @@ export class BridgeSessionService {
|
|
|
174
175
|
let worktree = null;
|
|
175
176
|
let hostSingletonKeys = null;
|
|
176
177
|
let hostLease = null;
|
|
178
|
+
let succeeded = false;
|
|
177
179
|
try {
|
|
178
180
|
if (dispatch.sandbox?.executionMode === "host" && this.hostRuntime) {
|
|
179
181
|
const capacity = this.hostRuntime.snapshot?.() ?? null;
|
|
@@ -248,7 +250,10 @@ export class BridgeSessionService {
|
|
|
248
250
|
qaRework: dispatch.qaRework,
|
|
249
251
|
warmPathOverrides: dispatch.warmPathOverrides,
|
|
250
252
|
applicationRuntimeRequired: dispatch.runtimeIntent.applicationRuntimeRequired,
|
|
251
|
-
preserveExistingState: Boolean(dispatch.session.resumedFromSessionId)
|
|
253
|
+
preserveExistingState: Boolean(dispatch.session.resumedFromSessionId),
|
|
254
|
+
sessionId: dispatch.session.id,
|
|
255
|
+
...preparedAttemptOwner(dispatch),
|
|
256
|
+
signal,
|
|
252
257
|
});
|
|
253
258
|
}
|
|
254
259
|
catch (error) {
|
|
@@ -264,6 +269,7 @@ export class BridgeSessionService {
|
|
|
264
269
|
: `Prepared worktree ${worktree.branchName}.`,
|
|
265
270
|
eventType: dispatch.session.resumedFromSessionId ? "worktree_reattached" : "worktree_prepared"
|
|
266
271
|
});
|
|
272
|
+
await emitWorktreePreparedEvents(worktree, emit);
|
|
267
273
|
if ((worktree.hydratedPriorPhaseArtifactCount ?? 0) > 0) {
|
|
268
274
|
await emit({
|
|
269
275
|
role: "runner",
|
|
@@ -275,6 +281,10 @@ export class BridgeSessionService {
|
|
|
275
281
|
if (worktree.dependencyWarm) {
|
|
276
282
|
await emitDependencyWarmEvents(worktree.dependencyWarm, emit);
|
|
277
283
|
}
|
|
284
|
+
// Conflicts a WIP re-apply left for the agent (deferredProjectStartEvent): the project stack
|
|
285
|
+
// is not started on them, and the prompt names them.
|
|
286
|
+
const reapplyConflicts = worktree.reapplyConflicts;
|
|
287
|
+
let projectStartDeferred = false;
|
|
278
288
|
if (dispatch.sandbox?.executionMode === "host" && this.hostRuntime) {
|
|
279
289
|
hostLease = await this.hostRuntime.start(dispatch, worktree.worktreePath, signal, async (checkpoint) => {
|
|
280
290
|
const observation = waitObservation(checkpoint.code);
|
|
@@ -305,28 +315,101 @@ export class BridgeSessionService {
|
|
|
305
315
|
remediation: "Enable Run in Docker in Project Settings.",
|
|
306
316
|
}),
|
|
307
317
|
});
|
|
308
|
-
|
|
309
|
-
|
|
318
|
+
({ hostLease, deferred: projectStartDeferred } = await startOrDeferConfiguredProject(this.hostRuntime, hostLease, dispatch, reapplyConflicts, signal, emitLifecycle));
|
|
319
|
+
}
|
|
320
|
+
// The stack was built and launched from this workspace state. Pre-publication
|
|
321
|
+
// validation restarts it when the provider has changed the source since.
|
|
322
|
+
let refreshRuntimeEnvironment;
|
|
323
|
+
const hostRuntime = this.hostRuntime;
|
|
324
|
+
if (hostLease && dispatch.sandbox && hostRuntime?.restartConfiguredProject
|
|
325
|
+
&& hostLease.executionClass === "managed_runtime"
|
|
326
|
+
&& configuredLaunchPortNames(hostLease.runtimeContract).length > 0) {
|
|
327
|
+
const worktreePath = worktree.worktreePath;
|
|
328
|
+
const dispatchAttemptId = dispatch.sandbox.dispatchAttemptId;
|
|
329
|
+
const fencingToken = dispatch.lease.fencingToken;
|
|
330
|
+
const restartConfiguredProject = hostRuntime.restartConfiguredProject.bind(hostRuntime);
|
|
331
|
+
let launchFingerprint = await this.workspaceFingerprint(worktreePath)
|
|
332
|
+
.catch(() => null);
|
|
333
|
+
// Set while the stack may not match the workspace: a failed restart is retried on the next pass.
|
|
334
|
+
let restartPending = false;
|
|
335
|
+
// Set until the deferred first start (re-apply conflicts) succeeds: the stack has never run.
|
|
336
|
+
let startDeferred = projectStartDeferred;
|
|
337
|
+
refreshRuntimeEnvironment = async (refreshSignal) => {
|
|
338
|
+
// A late violation stopped the stack: fail this validation pass rather than run it against closed ports.
|
|
339
|
+
this.throwIfAbortedOrIsolationViolated(undefined, dispatch, hostLease);
|
|
340
|
+
const current = await this.workspaceFingerprint(worktreePath).catch(() => null);
|
|
341
|
+
if (!restartPending && !startDeferred && sameWorkspaceRuntimeFingerprint(launchFingerprint, current))
|
|
342
|
+
return null;
|
|
343
|
+
// Every cause that applies is reported; `reason` is the first of them. Changes are named
|
|
344
|
+
// only when both states were read: an unreadable baseline is not a workspace change.
|
|
345
|
+
const comparable = launchFingerprint !== null && current !== null;
|
|
346
|
+
const changes = comparable ? workspaceRuntimeFingerprintChanges(launchFingerprint, current) : [];
|
|
347
|
+
const causes = [
|
|
348
|
+
...(startDeferred ? ["deferred_start"] : []),
|
|
349
|
+
...(restartPending ? ["previous_restart_incomplete"] : []),
|
|
350
|
+
...(comparable ? [] : ["fingerprint_unavailable"]),
|
|
351
|
+
...(changes.length > 0 ? ["workspace_changed"] : []),
|
|
352
|
+
];
|
|
353
|
+
const reason = causes[0] ?? "workspace_changed";
|
|
310
354
|
await emitLifecycle({
|
|
311
355
|
role: "runner",
|
|
312
356
|
kind: "checkpoint",
|
|
313
|
-
content:
|
|
314
|
-
eventType:
|
|
315
|
-
data:
|
|
357
|
+
content: runtimeRestartStartedMessage(reason, changes),
|
|
358
|
+
eventType: "host_runtime_restart_started",
|
|
359
|
+
data: JSON.stringify({
|
|
360
|
+
reason,
|
|
361
|
+
causes,
|
|
362
|
+
changes,
|
|
363
|
+
head_sha: current?.headSha ?? null,
|
|
364
|
+
merge_in_progress: Boolean(current?.mergeHead),
|
|
365
|
+
}),
|
|
316
366
|
});
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
367
|
+
restartPending = true;
|
|
368
|
+
let restarted;
|
|
369
|
+
try {
|
|
370
|
+
restarted = await restartConfiguredProject(dispatchAttemptId, fencingToken, refreshSignal ?? signal, async (checkpoint) => {
|
|
371
|
+
await emitLifecycle({
|
|
372
|
+
role: "runner",
|
|
373
|
+
kind: "checkpoint",
|
|
374
|
+
content: checkpoint.message,
|
|
375
|
+
eventType: checkpoint.code,
|
|
376
|
+
data: checkpoint.data ? JSON.stringify(checkpoint.data) : undefined,
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
}
|
|
380
|
+
catch (error) {
|
|
381
|
+
await emitLifecycle({
|
|
382
|
+
role: "runner",
|
|
383
|
+
kind: "error",
|
|
384
|
+
content: `Restarting the attempt runtime stack failed: ${failureMessage(error)}`,
|
|
385
|
+
eventType: "host_runtime_restart_failed",
|
|
386
|
+
data: JSON.stringify({ reason, causes, changes }),
|
|
387
|
+
}).catch(() => undefined);
|
|
388
|
+
throw error;
|
|
389
|
+
}
|
|
390
|
+
hostLease = restarted;
|
|
391
|
+
// The restarted stack serves the workspace as it is now. Read that state again rather than
|
|
392
|
+
// keep the pre-restart reading, which is null when it could not be collected; a null
|
|
393
|
+
// baseline never matches, so every later pass would restart and rotate ports again.
|
|
394
|
+
launchFingerprint = await this.workspaceFingerprint(worktreePath).catch(() => current);
|
|
395
|
+
restartPending = false;
|
|
396
|
+
startDeferred = false;
|
|
320
397
|
await emitLifecycle({
|
|
321
398
|
role: "runner",
|
|
322
399
|
kind: "checkpoint",
|
|
323
|
-
content: `
|
|
324
|
-
eventType: "
|
|
325
|
-
data: JSON.stringify(hostRuntimeEventResources(
|
|
400
|
+
content: `Restarted the supervised project runtime on ${restarted.lease.resources.ports.map(port => `${port.name} ${port.hostIp}:${port.hostPort}`).join(", ") || "no ports"}.`,
|
|
401
|
+
eventType: "host_runtime_restarted",
|
|
402
|
+
data: JSON.stringify(hostRuntimeEventResources(restarted.lease, restarted.runtimeContract, restarted.executionClass)),
|
|
326
403
|
});
|
|
327
|
-
|
|
404
|
+
return { environment: restarted.environment, reason, changes };
|
|
405
|
+
};
|
|
328
406
|
}
|
|
329
|
-
providerDispatch = withMaterializedManagedQaTarget(providerDispatch, hostLease);
|
|
407
|
+
providerDispatch = withMaterializedManagedQaTarget(providerDispatch, hostLease, projectStartDeferred);
|
|
408
|
+
const providerEnvironment = {
|
|
409
|
+
runtimeEnvironment: hostLease?.environment,
|
|
410
|
+
// Only the completion MCP server gets these: its managed commands share the host ledger.
|
|
411
|
+
hostLoadEnvironment: hostLease ? this.hostRuntime?.hostLoadChildEnvironment?.() : undefined,
|
|
412
|
+
};
|
|
330
413
|
if (dispatch.draft) {
|
|
331
414
|
throwIfAborted(signal);
|
|
332
415
|
const processRunner = hostLease && dispatch.sandbox
|
|
@@ -335,22 +418,23 @@ export class BridgeSessionService {
|
|
|
335
418
|
const run = await this.providerCli.runDraft({
|
|
336
419
|
dispatch: providerDispatch,
|
|
337
420
|
worktree,
|
|
338
|
-
|
|
421
|
+
...providerEnvironment,
|
|
339
422
|
processRunner,
|
|
340
423
|
emit,
|
|
341
424
|
signal
|
|
342
425
|
});
|
|
343
|
-
|
|
426
|
+
this.throwIfAbortedOrIsolationViolated(signal, dispatch, hostLease);
|
|
344
427
|
const draftArtifacts = run.artifacts?.length ? run.artifacts : run.artifact ? [run.artifact] : [];
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
exitCode: 0,
|
|
348
|
-
summary: run.summary,
|
|
428
|
+
// Redaction can throw (a secret in a structural field); only a returned result is a success.
|
|
429
|
+
const draftResult = redactRunOnceResultPacket({
|
|
430
|
+
schemaVersion: 2, exitCode: 0, summary: run.summary,
|
|
349
431
|
events,
|
|
350
432
|
spec: run.spec ?? null,
|
|
351
433
|
artifact: run.artifact ?? null,
|
|
352
434
|
artifacts: draftArtifacts
|
|
353
435
|
}, redactionSecrets);
|
|
436
|
+
succeeded = true;
|
|
437
|
+
return draftResult;
|
|
354
438
|
}
|
|
355
439
|
throwIfAborted(signal);
|
|
356
440
|
const lane = dispatch.execution.lane.trim().toLowerCase();
|
|
@@ -363,10 +447,15 @@ export class BridgeSessionService {
|
|
|
363
447
|
const context = {
|
|
364
448
|
dispatch: providerDispatch,
|
|
365
449
|
worktree,
|
|
366
|
-
|
|
450
|
+
...providerEnvironment,
|
|
367
451
|
processRunner: hostLease && dispatch.sandbox
|
|
368
452
|
? this.hostRuntime?.providerProcessRunner?.(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken) ?? undefined
|
|
369
453
|
: undefined,
|
|
454
|
+
...(refreshRuntimeEnvironment && hostLease
|
|
455
|
+
? { refreshRuntimeEnvironment, runtimeStackEnvironmentKeys: hostRuntimeStackEnvironmentKeys(hostLease.runtimeContract) }
|
|
456
|
+
: {}),
|
|
457
|
+
reapplyConflicts,
|
|
458
|
+
projectStartDeferred,
|
|
370
459
|
emit,
|
|
371
460
|
signal
|
|
372
461
|
};
|
|
@@ -391,12 +480,10 @@ export class BridgeSessionService {
|
|
|
391
480
|
}
|
|
392
481
|
throw error;
|
|
393
482
|
}
|
|
394
|
-
|
|
483
|
+
this.throwIfAbortedOrIsolationViolated(signal, dispatch, hostLease);
|
|
395
484
|
const phaseArtifacts = run.artifacts?.length ? run.artifacts : run.artifact ? [run.artifact] : [];
|
|
396
|
-
|
|
397
|
-
schemaVersion: 2,
|
|
398
|
-
exitCode: 0,
|
|
399
|
-
summary: run.summary,
|
|
485
|
+
const result = redactRunOnceResultPacket({
|
|
486
|
+
schemaVersion: 2, exitCode: 0, summary: run.summary,
|
|
400
487
|
resultCommitSha: run.resultCommitSha ?? null,
|
|
401
488
|
publishedCommitSha: run.publishedCommitSha ?? null,
|
|
402
489
|
events,
|
|
@@ -404,72 +491,102 @@ export class BridgeSessionService {
|
|
|
404
491
|
artifact: run.artifact ?? null,
|
|
405
492
|
artifacts: phaseArtifacts
|
|
406
493
|
}, redactionSecrets);
|
|
494
|
+
succeeded = true;
|
|
495
|
+
return result;
|
|
407
496
|
}
|
|
408
497
|
finally {
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
498
|
+
await this.releaseHostRuntime(dispatch, hostLease, hostSingletonKeys, emitLifecycle);
|
|
499
|
+
if (worktree) {
|
|
500
|
+
await settleWorktree(this.worktrees, worktree, sessionWipOutcome(signal, events, succeeded), signal, emitLifecycle);
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
/** Launches a parallel-eligible probe's project, unless its contract is quarantined and so could never earn proof. */
|
|
505
|
+
async probeConfiguredProject(hostRuntime, request, started, signal) {
|
|
506
|
+
if (await hostRuntime.promotionQuarantined?.(request.repoId, hostRuntimeContractFingerprint(started.runtimeContract))) {
|
|
507
|
+
// Not launched; the server retries on its backoff, and the check passes once the quarantine expires.
|
|
508
|
+
return failedProbe("host_runtime_isolation_quarantined", "The runtime contract is quarantined after a recent isolation violation, so it was not probed; its runs stay serialized.");
|
|
509
|
+
}
|
|
510
|
+
assertReadinessProbeStartupBudget(request.expiresAt);
|
|
511
|
+
let isolationDetail = null;
|
|
512
|
+
const launched = await hostRuntime.startConfiguredProject(request.requestId, request.fencingToken, signal, async (checkpoint) => {
|
|
513
|
+
if (checkpoint.code === "host_runtime_isolation_serialized")
|
|
514
|
+
isolationDetail = checkpoint.message;
|
|
515
|
+
});
|
|
516
|
+
return configuredProbeResult(launched, isolationDetail);
|
|
517
|
+
}
|
|
518
|
+
/** A late isolation violation stopped the attempt's project in the background: fail rather than report success. */
|
|
519
|
+
throwIfAbortedOrIsolationViolated(signal, dispatch, hostLease) {
|
|
520
|
+
throwIfAborted(signal);
|
|
521
|
+
const violation = hostLease && dispatch.sandbox
|
|
522
|
+
? this.hostRuntime?.isolationViolation?.(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken)
|
|
523
|
+
: null;
|
|
524
|
+
if (violation)
|
|
525
|
+
throw violation;
|
|
526
|
+
}
|
|
527
|
+
/** Reports the provider's peak memory and releases the attempt's host runtime lease. */
|
|
528
|
+
async releaseHostRuntime(dispatch, hostLease, hostSingletonKeys, emitLifecycle) {
|
|
529
|
+
if (hostLease && dispatch.sandbox) {
|
|
530
|
+
const providerMemory = this.hostRuntime?.providerMemoryTelemetry?.(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken);
|
|
531
|
+
if (providerMemory) {
|
|
430
532
|
await emitLifecycle({
|
|
431
533
|
role: "runner",
|
|
432
534
|
kind: "checkpoint",
|
|
433
|
-
content: `
|
|
434
|
-
eventType: "
|
|
435
|
-
occurredAt:
|
|
535
|
+
content: `Observed managed-host provider process-tree peak memory ${formatMemoryBytes(providerMemory.peakMemoryBytes)} from ${providerMemory.sampleCount} sample${providerMemory.sampleCount === 1 ? "" : "s"}.`,
|
|
536
|
+
eventType: "sandbox_peak_memory_observed",
|
|
537
|
+
occurredAt: providerMemory.observedAt,
|
|
538
|
+
data: JSON.stringify({
|
|
539
|
+
peakMemoryBytes: providerMemory.peakMemoryBytes,
|
|
540
|
+
sampleCount: providerMemory.sampleCount,
|
|
541
|
+
source: providerMemory.source,
|
|
542
|
+
containers: [{
|
|
543
|
+
role: "agent",
|
|
544
|
+
peakMemoryBytes: providerMemory.peakMemoryBytes,
|
|
545
|
+
}],
|
|
546
|
+
}),
|
|
436
547
|
}).catch(() => undefined);
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
await emitLifecycle({
|
|
450
|
-
role: "runner",
|
|
451
|
-
kind: "checkpoint",
|
|
452
|
-
content: `Released host runtime lease ${released.leaseId}. Diagnostics remain runner-local.`,
|
|
453
|
-
eventType: "sandbox_teardown_completed",
|
|
454
|
-
occurredAt: released.releasedAt,
|
|
455
|
-
}).catch(() => undefined);
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
catch (error) {
|
|
548
|
+
}
|
|
549
|
+
const teardownAt = new Date().toISOString();
|
|
550
|
+
await emitLifecycle({
|
|
551
|
+
role: "runner",
|
|
552
|
+
kind: "checkpoint",
|
|
553
|
+
content: `Releasing host runtime lease ${hostLease.lease.leaseId}.`,
|
|
554
|
+
eventType: "sandbox_teardown_started",
|
|
555
|
+
occurredAt: teardownAt,
|
|
556
|
+
}).catch(() => undefined);
|
|
557
|
+
try {
|
|
558
|
+
const released = await this.hostRuntime?.release(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken);
|
|
559
|
+
if (!released) {
|
|
459
560
|
await emitLifecycle({
|
|
460
561
|
role: "runner",
|
|
461
562
|
kind: "error",
|
|
462
|
-
content:
|
|
563
|
+
content: "Host runtime cleanup requires reconciliation: the runtime lease was not current during release.",
|
|
463
564
|
eventType: "teardown_failed",
|
|
464
565
|
occurredAt: new Date().toISOString(),
|
|
465
566
|
}).catch(() => undefined);
|
|
466
567
|
}
|
|
568
|
+
else {
|
|
569
|
+
await emitLifecycle({
|
|
570
|
+
role: "runner",
|
|
571
|
+
kind: "checkpoint",
|
|
572
|
+
content: `Released host runtime lease ${released.leaseId}. Diagnostics remain runner-local.`,
|
|
573
|
+
eventType: "sandbox_teardown_completed",
|
|
574
|
+
occurredAt: released.releasedAt,
|
|
575
|
+
}).catch(() => undefined);
|
|
576
|
+
}
|
|
467
577
|
}
|
|
468
|
-
|
|
469
|
-
await
|
|
578
|
+
catch (error) {
|
|
579
|
+
await emitLifecycle({
|
|
580
|
+
role: "runner",
|
|
581
|
+
kind: "error",
|
|
582
|
+
content: `Host runtime cleanup requires reconciliation: ${error instanceof Error ? error.message : String(error)}`,
|
|
583
|
+
eventType: "teardown_failed",
|
|
584
|
+
occurredAt: new Date().toISOString(),
|
|
585
|
+
}).catch(() => undefined);
|
|
470
586
|
}
|
|
471
|
-
|
|
472
|
-
|
|
587
|
+
}
|
|
588
|
+
if (!hostLease && hostSingletonKeys && dispatch.sandbox) {
|
|
589
|
+
await this.hostRuntime?.release(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken).catch(() => undefined);
|
|
473
590
|
}
|
|
474
591
|
}
|
|
475
592
|
}
|
|
@@ -479,10 +596,6 @@ function failureMessage(error) {
|
|
|
479
596
|
function formatMemoryBytes(bytes) {
|
|
480
597
|
return `${(bytes / (1024 ** 2)).toFixed(bytes >= 1024 ** 3 ? 0 : 1)} MiB`;
|
|
481
598
|
}
|
|
482
|
-
function isPauseCancellation(signal) {
|
|
483
|
-
return signal?.aborted === true
|
|
484
|
-
&& String(signal.reason ?? "").trim().toLowerCase() === "session pause requested";
|
|
485
|
-
}
|
|
486
599
|
function readinessProbeDispatch(request) {
|
|
487
600
|
return {
|
|
488
601
|
schemaVersion: 2,
|
|
@@ -562,6 +675,31 @@ function readinessProbeDispatch(request) {
|
|
|
562
675
|
artifacts: [],
|
|
563
676
|
};
|
|
564
677
|
}
|
|
678
|
+
/**
|
|
679
|
+
* A probe is parallel_ready only when every configured port proved readiness and the launch earned the
|
|
680
|
+
* parallel promotion, which an isolation violation or a quarantined contract withholds while it runs.
|
|
681
|
+
*/
|
|
682
|
+
function configuredProbeResult(started, isolationDetail) {
|
|
683
|
+
const requiredPorts = configuredLaunchPortNames(started.runtimeContract);
|
|
684
|
+
const verifiedPorts = started.lease.resources.ports.map(port => port.name);
|
|
685
|
+
if (requiredPorts.length === 0 || !requiredPorts.every(name => verifiedPorts.includes(name))) {
|
|
686
|
+
return failedProbe("host_runtime_probe_unverified", "The application did not prove ownership and readiness on every Forge-assigned port.");
|
|
687
|
+
}
|
|
688
|
+
if (started.environment.FORGE_HOST_CONCURRENCY !== "host_parallel_safe") {
|
|
689
|
+
return failedProbe("host_runtime_isolation_violation", isolationDetail
|
|
690
|
+
?? "The application served every Forge-assigned port, but did not earn parallel-safety proof for this runtime contract.");
|
|
691
|
+
}
|
|
692
|
+
return {
|
|
693
|
+
status: "parallel_ready",
|
|
694
|
+
runtimeContractFingerprint: hostRuntimeContractFingerprint(started.runtimeContract),
|
|
695
|
+
runtimeContractSource: started.runtimeContract.source,
|
|
696
|
+
runtimeRequirements: started.runtimeContract.contract.requires ?? null,
|
|
697
|
+
reasonCode: null,
|
|
698
|
+
reasonMessage: null,
|
|
699
|
+
qaAppLaunchTarget: managedQaLaunchTarget(started.runtimeContract),
|
|
700
|
+
checkedAt: new Date().toISOString(),
|
|
701
|
+
};
|
|
702
|
+
}
|
|
565
703
|
function failedProbe(reasonCode, reasonMessage) {
|
|
566
704
|
return { status: "failed", reasonCode, reasonMessage, checkedAt: new Date().toISOString() };
|
|
567
705
|
}
|
|
@@ -571,43 +709,6 @@ function assertReadinessProbeStartupBudget(expiresAt) {
|
|
|
571
709
|
throw new Error("host_runtime_probe_deadline_insufficient: readiness admission completed too close to the probe deadline; Forge released the reservation before launching the application.");
|
|
572
710
|
}
|
|
573
711
|
}
|
|
574
|
-
function managedQaLaunchTarget(runtimeContract) {
|
|
575
|
-
const playwright = runtimeContract.contract.runtime.playwright;
|
|
576
|
-
if (!playwright)
|
|
577
|
-
return null;
|
|
578
|
-
const port = runtimeContract.contract.runtime.ports.find(candidate => candidate.name === playwright.baseUrlPort);
|
|
579
|
-
return port?.launch && port.baseUrlEnv && port.format
|
|
580
|
-
? { managedRuntimePort: port.name, routes: ["/"] }
|
|
581
|
-
: null;
|
|
582
|
-
}
|
|
583
|
-
function withMaterializedManagedQaTarget(dispatch, hostLease) {
|
|
584
|
-
const target = dispatch.qaBrowser?.launchTarget;
|
|
585
|
-
const portName = target?.managed_runtime_port?.trim().toLowerCase();
|
|
586
|
-
if (!target || !portName)
|
|
587
|
-
return dispatch;
|
|
588
|
-
if (!hostLease) {
|
|
589
|
-
throw new Error("qa_managed_runtime_unavailable: Browser QA requires the verified managed host runtime selected during readiness.");
|
|
590
|
-
}
|
|
591
|
-
const normalizedName = portName.toUpperCase().replaceAll(/[^A-Z0-9]/gu, "_");
|
|
592
|
-
const url = hostLease.environment[`FORGE_${normalizedName}_URL`];
|
|
593
|
-
if (!url) {
|
|
594
|
-
throw new Error(`qa_managed_runtime_unavailable: verified runtime port '${portName}' was not launched for this attempt.`);
|
|
595
|
-
}
|
|
596
|
-
return {
|
|
597
|
-
...dispatch,
|
|
598
|
-
qaBrowser: dispatch.qaBrowser ? {
|
|
599
|
-
...dispatch.qaBrowser,
|
|
600
|
-
launchTarget: {
|
|
601
|
-
...target,
|
|
602
|
-
url: target.url ?? url,
|
|
603
|
-
ready_url: target.ready_url ?? url,
|
|
604
|
-
notes: [target.notes, "Forge launched and verified this URL inside the current fenced attempt."]
|
|
605
|
-
.filter(Boolean)
|
|
606
|
-
.join(" "),
|
|
607
|
-
},
|
|
608
|
-
} : dispatch.qaBrowser,
|
|
609
|
-
};
|
|
610
|
-
}
|
|
611
712
|
function probeFailureCode(error) {
|
|
612
713
|
const message = error instanceof Error ? error.message : String(error);
|
|
613
714
|
const candidate = message.split(":", 1)[0]?.trim().toLowerCase() ?? "";
|
|
@@ -622,6 +723,13 @@ function throwIfAborted(signal) {
|
|
|
622
723
|
throw new Error(String(signal.reason ?? "Dispatch cancelled."));
|
|
623
724
|
}
|
|
624
725
|
}
|
|
726
|
+
/** The dispatch attempt a worktree is prepared for: Forge's attempt for its WIP refs, and whose host load it reserves. */
|
|
727
|
+
function preparedAttemptOwner(dispatch) {
|
|
728
|
+
return {
|
|
729
|
+
wipAttempt: dispatch.wipAttempt ?? null,
|
|
730
|
+
hostLoadOwner: { dispatchAttemptId: dispatch.sandbox?.dispatchAttemptId ?? null, priority: runtimeAdmissionPriority(dispatch) },
|
|
731
|
+
};
|
|
732
|
+
}
|
|
625
733
|
function validateApiKeySecretGrant(dispatch) {
|
|
626
734
|
if (!dispatch.execution.requiresApiKeySecretGrant) {
|
|
627
735
|
return;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { HostRuntimeRequirements } from "../runtime/host-runtime-requirements.js";
|
|
1
2
|
export interface RunOnceDispatchPacket {
|
|
2
3
|
readonly schemaVersion: 1 | 2;
|
|
3
4
|
readonly userId: string;
|
|
@@ -10,6 +11,7 @@ export interface RunOnceDispatchPacket {
|
|
|
10
11
|
readonly runtimeIntent: DispatchRuntimeIntent;
|
|
11
12
|
readonly serverLocal: DispatchServerLocalConfig;
|
|
12
13
|
readonly sandbox?: DispatchSandboxContext | null;
|
|
14
|
+
readonly wipAttempt?: number | null;
|
|
13
15
|
readonly pullRequest?: DispatchPullRequestContext | null;
|
|
14
16
|
readonly apiKeySecretGrant?: ApiKeySecretGrant | null;
|
|
15
17
|
readonly apiKeySecretGrantHandle?: ApiKeySecretGrantHandle | null;
|
|
@@ -546,6 +548,8 @@ export interface HostRuntimeReadinessProbeResult {
|
|
|
546
548
|
readonly status: "parallel_ready" | "serialized" | "failed";
|
|
547
549
|
readonly runtimeContractFingerprint?: string | null;
|
|
548
550
|
readonly runtimeContractSource?: string | null;
|
|
551
|
+
/** Requirements declared by the probed contract (decision 0013); null when none. */
|
|
552
|
+
readonly runtimeRequirements?: HostRuntimeRequirements | null;
|
|
549
553
|
readonly reasonCode?: string | null;
|
|
550
554
|
readonly reasonMessage?: string | null;
|
|
551
555
|
readonly qaAppLaunchTarget?: HostRuntimeReadinessQaLaunchTarget | null;
|
|
@@ -28,6 +28,7 @@ export function parseRunOnceDispatchPacket(value) {
|
|
|
28
28
|
runtimeIntent: parseRuntimeIntent(packet.runtimeIntent),
|
|
29
29
|
serverLocal: parseServerLocal(packet.serverLocal),
|
|
30
30
|
sandbox: parseSandbox(packet.sandbox, schemaVersion),
|
|
31
|
+
wipAttempt: optionalNonNegativeInteger(packet, "wipAttempt"),
|
|
31
32
|
pullRequest: parsePullRequest(packet.pullRequest),
|
|
32
33
|
apiKeySecretGrant: parseApiKeySecretGrant(packet.apiKeySecretGrant),
|
|
33
34
|
apiKeySecretGrantHandle: parseApiKeySecretGrantHandle(packet.apiKeySecretGrantHandle),
|
|
@@ -469,19 +470,19 @@ function unvalidatedFailureFactsForCode(code, source) {
|
|
|
469
470
|
if (code === "bridge.unavailable") {
|
|
470
471
|
return facts(code, "transport", "offer", source, "retryable", "retry_dispatch");
|
|
471
472
|
}
|
|
472
|
-
if (["capacity_unavailable", "bridge.runner_draining", "docker_engine_unavailable", "docker_memory_low", "docker_memory_sample_unavailable", "docker_cpu_low", "docker_disk_low", "server_local.resource_pressure", "server_local.capacity_unavailable", "dispatch.preparation_resource_pressure", "sandbox_capacity_profile_unavailable", "host_runtime_admission_expired"].includes(code)) {
|
|
473
|
+
if (["capacity_unavailable", "bridge.runner_draining", "docker_engine_unavailable", "docker_memory_low", "docker_memory_sample_unavailable", "docker_cpu_low", "docker_disk_low", "server_local.resource_pressure", "server_local.capacity_unavailable", "dispatch.preparation_resource_pressure", "sandbox_capacity_profile_unavailable", "host_runtime_admission_expired", "placement_requirements_unmet", "runner_yielding", "runner_settings_pending", "runner_settings_apply_failed", "runner_tier_light", "runner_project_not_allowed"].includes(code)) {
|
|
473
474
|
return facts(code, "resource", "offer", source, "retryable", "retry_dispatch");
|
|
474
475
|
}
|
|
475
476
|
if (["bridge.lease_retry_exhausted", "bridge.capacity_wait_exhausted"].includes(code)) {
|
|
476
477
|
return facts(code, "resource", "offer", source, "non_retryable", "inspect_failure");
|
|
477
478
|
}
|
|
478
|
-
if (["prepublication_infrastructure_failed", "prepublication_capability_unavailable"].includes(code)) {
|
|
479
|
+
if (["prepublication_infrastructure_failed", "prepublication_capability_unavailable", "host_capacity_timeout", "host_capacity_token_fenced", "host_capacity_ledger_unavailable"].includes(code)) {
|
|
479
480
|
return facts(code, "resource", "validation", source, "retryable", "retry_with_policy");
|
|
480
481
|
}
|
|
481
482
|
if (["prepublication_validation_failed", "prepublication_contract_invalid", "prepublication_execution_scope_invalid"].includes(code)) {
|
|
482
483
|
return facts(code, "domain", "validation", source, "non_retryable", "fix_input");
|
|
483
484
|
}
|
|
484
|
-
if (
|
|
485
|
+
if (["comment_repair_changed_files_mismatch", "runner_result_sidecar_malformed"].includes(code)) {
|
|
485
486
|
return facts(code, "domain", "validation", source, "non_retryable", "inspect_failure");
|
|
486
487
|
}
|
|
487
488
|
if (["generated_output_reset_failed", "generated_output_reset_unverified", "worktree_prepare_failed", "host_runtime_ledger_write_failed", "host_diagnostics_temporary_unavailable", "attempt_process_supervisor_start_failed", "attempt_process_supervisor_start_timeout"].includes(code)) {
|
|
@@ -496,7 +497,7 @@ function unvalidatedFailureFactsForCode(code, source) {
|
|
|
496
497
|
if (code === "provider_configuration_invalid") {
|
|
497
498
|
return facts(code, "provider", "prepare", source, "non_retryable", "fix_environment");
|
|
498
499
|
}
|
|
499
|
-
if (["host_port_collision", "host_runtime_process_exited", "host_runtime_listener_timeout", "host_runtime_http_readiness_timeout", "host_runtime_prepared_source_changed", "host_runtime_prepared_probe_incomplete", "host_runtime_prepared_probe_cleanup_unconfirmed"].includes(code)) {
|
|
500
|
+
if (["host_port_collision", "host_runtime_process_exited", "host_runtime_listener_timeout", "host_runtime_http_readiness_timeout", "host_runtime_prepared_source_changed", "host_runtime_contract_changed", "host_runtime_prepared_probe_incomplete", "host_runtime_prepared_probe_cleanup_unconfirmed"].includes(code)) {
|
|
500
501
|
return facts(code, "resource", "prepare", source, "retryable", "retry_dispatch");
|
|
501
502
|
}
|
|
502
503
|
if (code === "host_runtime_project_start_failed") {
|
|
@@ -525,7 +526,7 @@ function unvalidatedFailureFactsForCode(code, source) {
|
|
|
525
526
|
if (code === "provider_completion_tool_missing") {
|
|
526
527
|
return facts(code, "provider", "agent", source, "non_retryable", "inspect_failure");
|
|
527
528
|
}
|
|
528
|
-
if (
|
|
529
|
+
if (["provider_terminated_at_turn_ceiling", "provider_turn_ended_with_background_work"].includes(code)) {
|
|
529
530
|
return facts(code, "provider", "agent", source, "retryable", "retry_with_policy");
|
|
530
531
|
}
|
|
531
532
|
if (code === "provider_context_window_exhausted") {
|
|
@@ -1373,9 +1374,8 @@ function optionalPositiveInteger(source, key) {
|
|
|
1373
1374
|
}
|
|
1374
1375
|
function optionalNonNegativeInteger(source, key) {
|
|
1375
1376
|
const value = source[key];
|
|
1376
|
-
if (value === undefined || value === null)
|
|
1377
|
+
if (value === undefined || value === null)
|
|
1377
1378
|
return null;
|
|
1378
|
-
}
|
|
1379
1379
|
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
1380
1380
|
throw new Error(`${key} must be a non-negative integer when provided.`);
|
|
1381
1381
|
}
|