@loucompanion/forge-bridge 0.1.4-dev.24bdf60b0b53 → 0.1.4-dev.25308ca4a63d
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 +2 -2
- package/dist/bridge/bridge.base.d.ts +7 -0
- package/dist/bridge/bridge.service.d.ts +32 -2
- package/dist/bridge/bridge.service.js +128 -10
- package/dist/bridge/bridge.types.d.ts +11 -0
- package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
- package/dist/bridge/dispatch-result-outbox.js +31 -6
- package/dist/bridge/runner-host-capabilities.d.ts +2 -0
- package/dist/bridge/runner-host-capabilities.js +4 -0
- package/dist/bridge/test-postgres-capability.d.ts +14 -0
- package/dist/bridge/test-postgres-capability.js +120 -0
- package/dist/cleanup/cleanup.service.d.ts +9 -0
- package/dist/cleanup/cleanup.service.js +72 -109
- package/dist/cleanup/cleanup.types.d.ts +4 -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 +5 -0
- package/dist/cleanup/host-runtime-ledger.js +109 -0
- package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
- package/dist/cleanup/managed-branch-sweep.js +111 -0
- package/dist/cli/cli.service.js +20 -3
- package/dist/runtime/aspnet-runtime-prebuild.js +94 -6
- package/dist/runtime/host-database-capability-boundary.d.ts +1 -1
- package/dist/runtime/host-database-capability-boundary.js +1 -0
- package/dist/runtime/host-facts.d.ts +35 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-load-admission.d.ts +52 -0
- package/dist/runtime/host-load-admission.js +84 -0
- package/dist/runtime/host-load-child-environment.d.ts +22 -0
- package/dist/runtime/host-load-child-environment.js +65 -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 +34 -0
- package/dist/runtime/host-load-governor-config.js +46 -0
- package/dist/runtime/host-load-governor.d.ts +172 -0
- package/dist/runtime/host-load-governor.js +519 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +185 -0
- package/dist/runtime/host-load-sampler.d.ts +126 -0
- package/dist/runtime/host-load-sampler.js +232 -0
- package/dist/runtime/host-load-step-class.d.ts +68 -0
- package/dist/runtime/host-load-step-class.js +106 -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-token-ledger.d.ts +174 -0
- package/dist/runtime/host-load-token-ledger.js +421 -0
- package/dist/runtime/host-pressure-stall.d.ts +61 -0
- package/dist/runtime/host-pressure-stall.js +168 -0
- package/dist/runtime/host-runtime-contract.d.ts +4 -0
- package/dist/runtime/host-runtime-contract.js +6 -1
- package/dist/runtime/host-runtime-lease.d.ts +47 -3
- package/dist/runtime/host-runtime-lease.js +215 -5
- package/dist/runtime/host-runtime-promotion.js +12 -0
- 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/playwright-host-runtime-adapter.d.ts +7 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
- package/dist/sandbox/host-capacity-broker.d.ts +107 -0
- package/dist/sandbox/host-capacity-broker.js +315 -0
- package/dist/sandbox/runtime.d.ts +10 -1
- package/dist/sandbox/runtime.js +45 -2
- package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
- package/dist/sandbox/sandbox-cgroups.js +42 -0
- package/dist/session/managed-attempt-tools.d.ts +2 -0
- package/dist/session/managed-attempt-tools.js +156 -37
- package/dist/session/managed-command-host-load.d.ts +45 -0
- package/dist/session/managed-command-host-load.js +82 -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 +98 -25
- 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 +4 -0
- package/dist/session/phase-completion.helpers.js +13 -12
- package/dist/session/phase-completion.js +4 -0
- package/dist/session/phase-completion.prompts.js +6 -1
- package/dist/session/phase-completion.runtime.d.ts +5 -3
- package/dist/session/phase-completion.runtime.js +49 -19
- 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 +184 -209
- package/dist/session/phase-completion.validation.d.ts +2 -3
- package/dist/session/phase-completion.validation.js +46 -92
- 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-process.d.ts +3 -0
- package/dist/session/pre-publication-process.js +25 -12
- package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
- package/dist/session/pre-publication-skipped-tests.js +109 -0
- package/dist/session/pre-publication-step-execution.d.ts +11 -0
- package/dist/session/pre-publication-step-execution.js +49 -0
- package/dist/session/pre-publication-validation.d.ts +9 -9
- package/dist/session/pre-publication-validation.js +44 -59
- package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
- package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
- package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
- package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
- package/dist/session/provider-cli/provider-cli.process.d.ts +32 -1
- package/dist/session/provider-cli/provider-cli.process.js +122 -30
- package/dist/session/provider-cli/provider-cli.prompts.d.ts +5 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +20 -2
- package/dist/session/provider-cli/provider-cli.service.d.ts +6 -0
- package/dist/session/provider-cli/provider-cli.service.js +237 -33
- package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
- package/dist/session/provider-cli/provider-in-flight-work.d.ts +6 -0
- package/dist/session/provider-cli/provider-in-flight-work.js +47 -0
- package/dist/session/provider-cli/provider-output-state.d.ts +6 -0
- package/dist/session/provider-cli/provider-output-state.js +9 -0
- package/dist/session/publishable-worktree-changes.d.ts +54 -0
- package/dist/session/publishable-worktree-changes.js +193 -0
- package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
- package/dist/session/sandbox-host-capacity-gate.js +229 -0
- package/dist/session/session.base.d.ts +3 -0
- package/dist/session/session.service.d.ts +5 -1
- package/dist/session/session.service.js +114 -5
- package/dist/session/session.types.d.ts +3 -0
- package/dist/session/session.types.js +15 -3
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/process/host-process-supervisor.d.ts +1 -0
- package/dist/shared/process/host-process-supervisor.js +1 -1
- 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/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/worktree.service.d.ts +10 -1
- package/dist/worktree/worktree.service.js +42 -2
- package/dist/worktree/worktree.types.d.ts +7 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -190,9 +190,9 @@ Production shared runners require a Linux rootless Docker daemon. Docker Desktop
|
|
|
190
190
|
|
|
191
191
|
Before selecting `sandbox_required`, save the full approved 40- or 64-character Git commit SHA in the project's Sandbox policy dialog. The server persists that SHA on the immutable attempt and the bridge reads `.forge/forge.sandbox.yml`, `.forge/Dockerfile`, and the tracked build context only from that commit. API-key dispatches carry an opaque one-time grant handle; the authenticated current runner instance redeems it after reservation, and plaintext stays out of offers, database payloads, Docker metadata, and host-persisted control files.
|
|
192
192
|
|
|
193
|
-
Temporary host fallback for `sandbox_preferred` requires both sides to opt in: a project owner must save a reason and future expiry (maximum 30 days), and an operator must enable **Host fallback** for the runner in
|
|
193
|
+
Temporary host fallback for `sandbox_preferred` requires both sides to opt in: a project owner must save a reason and future expiry (maximum 30 days), and an operator must enable **Host fallback** for the runner in Settings › Runners. Either missing or expired authorization fails closed. `sandbox_required` never falls back.
|
|
194
194
|
|
|
195
|
-
The bridge reaps exact-labeled orphan resources before connecting and every minute afterward. Connected passes reconcile current-instance ledgers against an authoritative, instance-scoped server attempt snapshot; startup does not adopt old-instance resources and terminates them before advertising capacity. Per-resource removal outcomes are written mode-0600 under `FORGE_SANDBOX_STATE_ROOT/cleanup-reports` before transmission, replayed after reconnect, acknowledged by report ID, and persisted by the API only when attempt, fence, resource runner instance, and current reporting runner match. Fenced dispatch events also persist image/cache status, build/agent-start/import/teardown timestamps, and a validated inventory of created agent/sidecar containers, networks, volumes, and published ports. Selected-session diagnostics expose that lifecycle data and recent cleanup actions while retaining cleanup-pending state after the agent outcome is terminal. Install `forge-bridge sandbox reap` as an independently supervised OS timer with the same `FORGE_RUNNER_ID`, Docker context, and state root so resources are reconciled while the bridge is down; the Docker-context ownership lock makes an overlapping pass fail safely. A non-zero `degradedReservationCount` means teardown has not completed; the affected capacity remains unavailable until a successful reaper pass. Drain a runner from
|
|
195
|
+
The bridge reaps exact-labeled orphan resources before connecting and every minute afterward. Connected passes reconcile current-instance ledgers against an authoritative, instance-scoped server attempt snapshot; startup does not adopt old-instance resources and terminates them before advertising capacity. Per-resource removal outcomes are written mode-0600 under `FORGE_SANDBOX_STATE_ROOT/cleanup-reports` before transmission, replayed after reconnect, acknowledged by report ID, and persisted by the API only when attempt, fence, resource runner instance, and current reporting runner match. Fenced dispatch events also persist image/cache status, build/agent-start/import/teardown timestamps, and a validated inventory of created agent/sidecar containers, networks, volumes, and published ports. Selected-session diagnostics expose that lifecycle data and recent cleanup actions while retaining cleanup-pending state after the agent outcome is terminal. Install `forge-bridge sandbox reap` as an independently supervised OS timer with the same `FORGE_RUNNER_ID`, Docker context, and state root so resources are reconciled while the bridge is down; the Docker-context ownership lock makes an overlapping pass fail safely. A non-zero `degradedReservationCount` means teardown has not completed; the affected capacity remains unavailable until a successful reaper pass. Drain a runner from Settings › Runners before upgrades or Docker maintenance, wait for active/starting counts to reach zero, then restart the bridge. Settings › Runners also exposes a scoped **Reap** action; the API delivers it only to the currently established protocol-v2 runner instance. Image GC runs only while disk pressure is latched, shares the build lock, preserves active image digests, and prunes only expired images beyond the per-project retention count. Lease renewals are HMAC-bound to the attempt and fence and advance an in-container monotonic deadline; lease, hard-wall, and idle expiry produce distinct failure codes.
|
|
196
196
|
|
|
197
197
|
Every attempt-owned container (including short-lived initialization helpers), network, and volume carries `dev.forge.resource-lease-id` equal to the dispatch execution lease. Ledger schema v2 persists the same `resourceLeaseId`; teardown compares the complete expected label set, and orphan reaping fails closed unless the managed, resource-lease, execution-lease, attempt, runner, runner-instance, and fencing identities are all present and consistent.
|
|
198
198
|
|
|
@@ -18,8 +18,15 @@ export interface BridgeConnection {
|
|
|
18
18
|
onCancel(handler: BridgeCancelHandler): void;
|
|
19
19
|
onReap?(handler: BridgeReapHandler): void;
|
|
20
20
|
onReadinessProbe?(handler: BridgeReadinessProbeHandler): void;
|
|
21
|
+
/** Decision 0014: the owner removed this runner from Forge; the bridge must stop, not reconnect. */
|
|
22
|
+
onRevoked?(handler: (notice: BridgeRevokedNotice) => void): void;
|
|
21
23
|
invoke<TResponse>(methodName: string, payload: unknown): Promise<TResponse>;
|
|
22
24
|
}
|
|
25
|
+
/** The `Revoked` hub message: the runner was removed from Forge and must be paired again. */
|
|
26
|
+
export interface BridgeRevokedNotice {
|
|
27
|
+
runnerId?: string;
|
|
28
|
+
reason?: string;
|
|
29
|
+
}
|
|
23
30
|
export interface BridgeConnectionFactory {
|
|
24
31
|
create(config: BridgeServiceConfig): BridgeConnection;
|
|
25
32
|
}
|
|
@@ -5,8 +5,9 @@ import { type DispatchSandboxResourceRequest, type RunOnceDispatchPacket, type R
|
|
|
5
5
|
import { DockerPreflight } from "../sandbox/preflight.js";
|
|
6
6
|
import type { SandboxPreflightResult } from "../sandbox/sandbox.types.js";
|
|
7
7
|
import { type SandboxRuntime } from "../sandbox/runtime.js";
|
|
8
|
-
import type { BridgeConnection, BridgeConnectionFactory, BridgeService } from "./bridge.base.js";
|
|
8
|
+
import type { BridgeConnection, BridgeConnectionFactory, BridgeRevokedNotice, BridgeService } from "./bridge.base.js";
|
|
9
9
|
import { type RunnerHostCapabilityProbe } from "./runner-host-capabilities.js";
|
|
10
|
+
import { type HostLoadSource } from "../runtime/host-load-sampler.js";
|
|
10
11
|
import type { BridgeCancelHandler, BridgeChatTurnHandler, BridgeDispatchHandler, BridgeLeaseUpdateRequest, BridgeReapRequest, BridgeServiceConfig } from "./bridge.types.js";
|
|
11
12
|
import { type ReadinessResultOutbox } from "./readiness-result-outbox.js";
|
|
12
13
|
import { type DispatchResultOutbox } from "./dispatch-result-outbox.js";
|
|
@@ -29,6 +30,7 @@ export declare class ForgeBridgeService implements BridgeService {
|
|
|
29
30
|
private readonly connections;
|
|
30
31
|
private readonly hostCapabilityProbe;
|
|
31
32
|
private readonly chatProcessRunner;
|
|
33
|
+
private readonly hostLoad;
|
|
32
34
|
private connection;
|
|
33
35
|
private heartbeatTimer;
|
|
34
36
|
private heartbeatInFlight;
|
|
@@ -41,6 +43,7 @@ export declare class ForgeBridgeService implements BridgeService {
|
|
|
41
43
|
private transportRecovery;
|
|
42
44
|
private transportRecoveryGeneration;
|
|
43
45
|
private stopped;
|
|
46
|
+
private revokedReason;
|
|
44
47
|
private readonly activeSessions;
|
|
45
48
|
private readonly reservations;
|
|
46
49
|
private readonly activeReadinessProbes;
|
|
@@ -58,14 +61,24 @@ export declare class ForgeBridgeService implements BridgeService {
|
|
|
58
61
|
private readonly sessions;
|
|
59
62
|
private readonly enforceHostDatabaseCapabilityBoundary;
|
|
60
63
|
private hostCapabilities;
|
|
64
|
+
private dockerAvailable;
|
|
65
|
+
private hostRequirementFacts;
|
|
61
66
|
private readonly recoveredHostAttempts;
|
|
62
67
|
private hostCapabilitiesDetected;
|
|
63
|
-
constructor(config: BridgeServiceConfig, sessions?: SessionService | undefined, connections?: BridgeConnectionFactory, preflight?: DockerPreflight, sandboxRuntime?: SandboxRuntime, sandboxResourceResolver?: SandboxResourceResolver, dockerEngineProbe?: DockerEngineProbe, hostCapabilityProbe?: RunnerHostCapabilityProbe, readinessResultOutbox?: ReadinessResultOutbox, chatProcessRunner?: ProviderProcessRunner, dispatchResultOutbox?: DispatchResultOutbox);
|
|
68
|
+
constructor(config: BridgeServiceConfig, sessions?: SessionService | undefined, connections?: BridgeConnectionFactory, preflight?: DockerPreflight, sandboxRuntime?: SandboxRuntime, sandboxResourceResolver?: SandboxResourceResolver, dockerEngineProbe?: DockerEngineProbe, hostCapabilityProbe?: RunnerHostCapabilityProbe, readinessResultOutbox?: ReadinessResultOutbox, chatProcessRunner?: ProviderProcessRunner, dispatchResultOutbox?: DispatchResultOutbox, hostLoad?: HostLoadSource);
|
|
64
69
|
connectOnce(): Promise<void>;
|
|
65
70
|
private rememberRecoveredHostAttempts;
|
|
66
71
|
private recoveredHostAttemptsForHello;
|
|
67
72
|
private registerConnection;
|
|
68
73
|
run(signal?: AbortSignal): Promise<void>;
|
|
74
|
+
/** The reason Forge gave when it removed this runner, or null while it is paired. */
|
|
75
|
+
get revoked(): string | null;
|
|
76
|
+
/**
|
|
77
|
+
* Decision 0014 §3 "Remove": Forge removed this runner. Stop for good instead of
|
|
78
|
+
* reconnecting; its attempts were already settled on the server, so local work is
|
|
79
|
+
* aborted rather than reported.
|
|
80
|
+
*/
|
|
81
|
+
private handleRevoked;
|
|
69
82
|
stop(): Promise<void>;
|
|
70
83
|
private handleChatTurn;
|
|
71
84
|
private createChatTurnWorkspace;
|
|
@@ -107,6 +120,15 @@ export declare class ForgeBridgeService implements BridgeService {
|
|
|
107
120
|
private sendResultPayloadDirect;
|
|
108
121
|
private flushDispatchResults;
|
|
109
122
|
private flushDispatchResultsCore;
|
|
123
|
+
/**
|
|
124
|
+
* Forge binds each result to the runner instance that ran the attempt. On an
|
|
125
|
+
* authoritative connection it rejects another instance's result with
|
|
126
|
+
* bridge.stale_result_instance; Forge's own recovery handles that attempt,
|
|
127
|
+
* so the record can never be delivered and must not block the replay queue.
|
|
128
|
+
* bridge.stale_runner_instance means this connection is not authoritative
|
|
129
|
+
* and says nothing about the record, so it never quarantines.
|
|
130
|
+
*/
|
|
131
|
+
private isReplacedRunnerInstanceResult;
|
|
110
132
|
private startHeartbeat;
|
|
111
133
|
private heartbeatTick;
|
|
112
134
|
private startLeaseWatchdog;
|
|
@@ -133,6 +155,13 @@ export declare class ForgeBridgeService implements BridgeService {
|
|
|
133
155
|
private waitForClose;
|
|
134
156
|
private stopConnection;
|
|
135
157
|
}
|
|
158
|
+
/** The `run` command's exit code after Forge removed the runner. */
|
|
159
|
+
export declare const bridgeRevokedExitCode = 3;
|
|
160
|
+
export declare const bridgeRevokedMessage = "This bridge was removed from Forge. Pair it again with forge-bridge pair.";
|
|
161
|
+
/** Thrown by `run` after Forge removed the runner, so the CLI exits instead of reconnecting. */
|
|
162
|
+
export declare class BridgeRevokedError extends Error {
|
|
163
|
+
constructor(message?: string);
|
|
164
|
+
}
|
|
136
165
|
export declare class SignalRBridgeConnectionFactory implements BridgeConnectionFactory {
|
|
137
166
|
create(config: BridgeServiceConfig): BridgeConnection;
|
|
138
167
|
}
|
|
@@ -140,6 +169,7 @@ export declare class SignalRBridgeConnection implements BridgeConnection {
|
|
|
140
169
|
private readonly config;
|
|
141
170
|
private readonly connection;
|
|
142
171
|
constructor(config: BridgeServiceConfig);
|
|
172
|
+
onRevoked(handler: (notice: BridgeRevokedNotice) => void): void;
|
|
143
173
|
start(): Promise<void>;
|
|
144
174
|
stop(): Promise<void>;
|
|
145
175
|
onClose(handler: (error?: Error) => void): void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { unmetHostRuntimeRequirements } from "../runtime/host-runtime-requirements-check.js";
|
|
1
2
|
import { HubConnectionBuilder, HttpTransportType, LogLevel } from "@microsoft/signalr";
|
|
2
3
|
import fs from "node:fs";
|
|
3
4
|
import path from "node:path";
|
|
@@ -12,6 +13,7 @@ import { codexSandboxModeForPlatform, formatProviderCliCommandForCheckpoint } fr
|
|
|
12
13
|
import { clip, createProviderOutputState } from "../session/provider-cli/provider-output-state.js";
|
|
13
14
|
import { redactRunnerDispatchEvent, redactRunOnceResultPacket } from "../session/session-redaction.js";
|
|
14
15
|
import { PrePublicationValidator } from "../session/pre-publication-validation.js";
|
|
16
|
+
import { FileForgeCgroupRegistry } from "../runtime/host-load-forge-cgroups.js";
|
|
15
17
|
import { HostRuntimeLeaseManager, } from "../runtime/host-runtime-lease.js";
|
|
16
18
|
import { assertHostDatabaseCapabilityBoundary, establishHostDatabaseCapabilityBoundary, } from "../runtime/host-database-capability-boundary.js";
|
|
17
19
|
import { defaultHostExecutionRoot } from "../runtime/host-execution-root.js";
|
|
@@ -33,8 +35,9 @@ import { codexSandboxProviderAuthAdapter, sandboxProviderAuthAdapterFor, sandbox
|
|
|
33
35
|
import { assertBridgeChatCallbackPayload, bridgeChatMaxProviderThreadIdChars, bridgeChatProtocolVersion, isTerminalChatTurnCallbackKind, parseChatTurnDispatchPacket, } from "./bridge-chat.types.js";
|
|
34
36
|
import { formatBytes } from "../shared/format/format-bytes.js";
|
|
35
37
|
import { emptyRunnerHostCapabilitySnapshot, ProcessRunnerHostCapabilityProbe, } from "./runner-host-capabilities.js";
|
|
38
|
+
import { HostLoadSampler } from "../runtime/host-load-sampler.js";
|
|
36
39
|
import { FileReadinessResultOutbox } from "./readiness-result-outbox.js";
|
|
37
|
-
import { FileDispatchResultOutbox } from "./dispatch-result-outbox.js";
|
|
40
|
+
import { dispatchResultQuarantineDirectory, FileDispatchResultOutbox } from "./dispatch-result-outbox.js";
|
|
38
41
|
/**
|
|
39
42
|
* Protocol-v2 events are acknowledged one at a time before runOnce returns.
|
|
40
43
|
* Sending the complete transcript again in DispatchResult made long QA and CI
|
|
@@ -53,6 +56,7 @@ export class ForgeBridgeService {
|
|
|
53
56
|
connections;
|
|
54
57
|
hostCapabilityProbe;
|
|
55
58
|
chatProcessRunner;
|
|
59
|
+
hostLoad;
|
|
56
60
|
connection = null;
|
|
57
61
|
heartbeatTimer = null;
|
|
58
62
|
heartbeatInFlight = false;
|
|
@@ -65,6 +69,7 @@ export class ForgeBridgeService {
|
|
|
65
69
|
transportRecovery = null;
|
|
66
70
|
transportRecoveryGeneration = 0;
|
|
67
71
|
stopped = false;
|
|
72
|
+
revokedReason = null;
|
|
68
73
|
activeSessions = new Map();
|
|
69
74
|
reservations = new Map();
|
|
70
75
|
activeReadinessProbes = new Map();
|
|
@@ -82,16 +87,33 @@ export class ForgeBridgeService {
|
|
|
82
87
|
sessions;
|
|
83
88
|
enforceHostDatabaseCapabilityBoundary;
|
|
84
89
|
hostCapabilities = emptyRunnerHostCapabilitySnapshot();
|
|
90
|
+
dockerAvailable = false;
|
|
91
|
+
hostRequirementFacts() {
|
|
92
|
+
const facts = this.hostLoad.facts();
|
|
93
|
+
return {
|
|
94
|
+
logicalThreads: facts?.logicalThreads ?? os.cpus().length,
|
|
95
|
+
totalMemoryBytes: facts?.totalMemoryBytes ?? os.totalmem(),
|
|
96
|
+
availableToolchains: Object.entries(this.hostCapabilities.toolchains)
|
|
97
|
+
.filter(([, tool]) => tool?.available === true)
|
|
98
|
+
.map(([name]) => name),
|
|
99
|
+
dockerAvailable: this.dockerAvailable,
|
|
100
|
+
browserLaunch: this.hostCapabilities.browserLaunch,
|
|
101
|
+
testPostgresSuperuser: this.hostCapabilities.testPostgres.superuser,
|
|
102
|
+
};
|
|
103
|
+
}
|
|
85
104
|
// Reaping deletes the stale ledger, so its stopped-process proof is held here
|
|
86
105
|
// until a Hello carrying it is accepted. A bridge restart forgets it, which
|
|
87
106
|
// leaves those attempts on Forge's conservative unknown-outcome path.
|
|
88
107
|
recoveredHostAttempts = new Map();
|
|
89
108
|
hostCapabilitiesDetected = false;
|
|
90
|
-
constructor(config, sessions = undefined, connections = new SignalRBridgeConnectionFactory(), preflight, sandboxRuntime, sandboxResourceResolver, dockerEngineProbe, hostCapabilityProbe = new ProcessRunnerHostCapabilityProbe(), readinessResultOutbox, chatProcessRunner = new StreamingProviderProcessRunner(), dispatchResultOutbox
|
|
109
|
+
constructor(config, sessions = undefined, connections = new SignalRBridgeConnectionFactory(), preflight, sandboxRuntime, sandboxResourceResolver, dockerEngineProbe, hostCapabilityProbe = new ProcessRunnerHostCapabilityProbe(), readinessResultOutbox, chatProcessRunner = new StreamingProviderProcessRunner(), dispatchResultOutbox,
|
|
110
|
+
// Reads the Docker sandbox cgroups the sandbox runtime registers on the same state root.
|
|
111
|
+
hostLoad = new HostLoadSampler({ forgeCgroups: new FileForgeCgroupRegistry(config.sandboxStateRoot) })) {
|
|
91
112
|
this.config = config;
|
|
92
113
|
this.connections = connections;
|
|
93
114
|
this.hostCapabilityProbe = hostCapabilityProbe;
|
|
94
115
|
this.chatProcessRunner = chatProcessRunner;
|
|
116
|
+
this.hostLoad = hostLoad;
|
|
95
117
|
this.enforceHostDatabaseCapabilityBoundary = sessions === undefined;
|
|
96
118
|
if (this.enforceHostDatabaseCapabilityBoundary) {
|
|
97
119
|
establishHostDatabaseCapabilityBoundary();
|
|
@@ -123,14 +145,19 @@ export class ForgeBridgeService {
|
|
|
123
145
|
},
|
|
124
146
|
onStatus: logBridgeStatus,
|
|
125
147
|
});
|
|
126
|
-
|
|
127
|
-
this.
|
|
148
|
+
const defaultSessions = sessions ? null : createDefaultSessionService(config.sandboxStateRoot, config.sandboxExecutionRoot, this.dockerEngineProbe, hostLoad);
|
|
149
|
+
this.sessions = sessions ?? defaultSessions.sessions;
|
|
150
|
+
// Docker sandboxes ask the same host load governor for their validation tokens.
|
|
151
|
+
this.sandboxRuntime = sandboxRuntime ?? new DockerSandboxRuntime(config, (request, signal) => this.redeemPublishGrant(request, signal), defaultSessions?.hostLoadGovernor);
|
|
128
152
|
this.sandboxResourceResolver = sandboxResourceResolver
|
|
129
153
|
?? (dispatch => resolveSandboxResourcesFromRepo(dispatch, this.config.sandboxRuntimeOverheadBytes));
|
|
130
154
|
this.readinessResultOutbox = readinessResultOutbox ?? new FileReadinessResultOutbox(config.sandboxStateRoot);
|
|
131
155
|
this.dispatchResultOutbox = dispatchResultOutbox ?? new FileDispatchResultOutbox(config.sandboxStateRoot);
|
|
132
156
|
}
|
|
133
157
|
async connectOnce() {
|
|
158
|
+
if (this.revokedReason !== null) {
|
|
159
|
+
throw new BridgeRevokedError(this.revokedReason);
|
|
160
|
+
}
|
|
134
161
|
await this.stopConnection();
|
|
135
162
|
this.stopped = false;
|
|
136
163
|
if (this.enforceHostDatabaseCapabilityBoundary) {
|
|
@@ -156,6 +183,10 @@ export class ForgeBridgeService {
|
|
|
156
183
|
this.hostCapabilities = await this.hostCapabilityProbe.detect(this.config);
|
|
157
184
|
this.hostCapabilitiesDetected = true;
|
|
158
185
|
}
|
|
186
|
+
// Static host facts and the first load sample ride on Hello; the sampler
|
|
187
|
+
// keeps refreshing its cached snapshot for later heartbeats.
|
|
188
|
+
await this.hostLoad.start().catch(() => undefined);
|
|
189
|
+
this.sessions.setHostRequirementsCheck?.(requires => unmetHostRuntimeRequirements(requires, this.hostRequirementFacts()));
|
|
159
190
|
const connection = this.connections.create(this.config);
|
|
160
191
|
this.connection = connection;
|
|
161
192
|
this.transportRecovery = null;
|
|
@@ -205,6 +236,7 @@ export class ForgeBridgeService {
|
|
|
205
236
|
connection.onCancel((request) => this.handleCancel(request));
|
|
206
237
|
connection.onReap?.((request) => this.handleReap(request));
|
|
207
238
|
connection.onReadinessProbe?.((request) => this.handleReadinessProbe(request));
|
|
239
|
+
connection.onRevoked?.((notice) => this.handleRevoked(notice));
|
|
208
240
|
await connection.start();
|
|
209
241
|
await this.registerConnection(connection);
|
|
210
242
|
await this.flushDispatchResults(true).catch(error => {
|
|
@@ -283,7 +315,7 @@ export class ForgeBridgeService {
|
|
|
283
315
|
}
|
|
284
316
|
}
|
|
285
317
|
catch (error) {
|
|
286
|
-
if (this.stopped || signal?.aborted) {
|
|
318
|
+
if (this.stopped || signal?.aborted || this.revokedReason !== null) {
|
|
287
319
|
break;
|
|
288
320
|
}
|
|
289
321
|
const backoff = this.config.reconnectBackoffMs[Math.min(attempt, this.config.reconnectBackoffMs.length - 1)] ?? 5000;
|
|
@@ -300,12 +332,38 @@ export class ForgeBridgeService {
|
|
|
300
332
|
}
|
|
301
333
|
await this.stopConnection();
|
|
302
334
|
}
|
|
335
|
+
if (this.revokedReason !== null) {
|
|
336
|
+
throw new BridgeRevokedError(this.revokedReason);
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
/** The reason Forge gave when it removed this runner, or null while it is paired. */
|
|
340
|
+
get revoked() {
|
|
341
|
+
return this.revokedReason;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Decision 0014 §3 "Remove": Forge removed this runner. Stop for good instead of
|
|
345
|
+
* reconnecting; its attempts were already settled on the server, so local work is
|
|
346
|
+
* aborted rather than reported.
|
|
347
|
+
*/
|
|
348
|
+
handleRevoked(notice) {
|
|
349
|
+
if (this.revokedReason !== null)
|
|
350
|
+
return;
|
|
351
|
+
const reason = typeof notice?.reason === "string" && notice.reason.trim()
|
|
352
|
+
? notice.reason.trim()
|
|
353
|
+
: bridgeRevokedMessage;
|
|
354
|
+
this.revokedReason = reason;
|
|
355
|
+
this.stopped = true;
|
|
356
|
+
logBridgeStatus(reason);
|
|
357
|
+
this.abortActiveSessions("runner removed from Forge");
|
|
358
|
+
this.abortActiveReadinessProbes("runner removed from Forge");
|
|
359
|
+
void this.stopConnection().catch(() => undefined);
|
|
303
360
|
}
|
|
304
361
|
async stop() {
|
|
305
362
|
this.stopped = true;
|
|
306
363
|
this.abortActiveSessions("bridge stopping");
|
|
307
364
|
this.abortActiveReadinessProbes("bridge stopping");
|
|
308
365
|
await this.stopConnection();
|
|
366
|
+
this.hostLoad.stop();
|
|
309
367
|
await this.preflight.release();
|
|
310
368
|
}
|
|
311
369
|
async handleChatTurn(rawDispatch) {
|
|
@@ -1468,6 +1526,19 @@ export class ForgeBridgeService {
|
|
|
1468
1526
|
await this.dispatchResultOutbox.acknowledge(pending.payload.leaseId);
|
|
1469
1527
|
continue;
|
|
1470
1528
|
}
|
|
1529
|
+
if (this.isReplacedRunnerInstanceResult(pending.payload, error)) {
|
|
1530
|
+
try {
|
|
1531
|
+
await this.dispatchResultOutbox.quarantine(pending);
|
|
1532
|
+
}
|
|
1533
|
+
catch (quarantineError) {
|
|
1534
|
+
// Keep the record and surface Forge's rejection: replay stays
|
|
1535
|
+
// deferred and a heartbeat tick does not count it as a failure.
|
|
1536
|
+
logBridgeStatus(`Dispatch result ${pending.payload.leaseId} from replaced runner instance ${pending.payload.runnerInstanceId} could not be quarantined: ${errorMessage(quarantineError)}`);
|
|
1537
|
+
throw error;
|
|
1538
|
+
}
|
|
1539
|
+
logBridgeStatus(`Quarantined dispatch result ${pending.payload.leaseId}: Forge rejected it because it belongs to replaced runner instance ${pending.payload.runnerInstanceId}. Forge's own recovery handles that instance's attempt; the redacted result is kept in ${dispatchResultQuarantineDirectory} for reconciliation.`);
|
|
1540
|
+
continue;
|
|
1541
|
+
}
|
|
1471
1542
|
throw error;
|
|
1472
1543
|
}
|
|
1473
1544
|
}
|
|
@@ -1478,6 +1549,20 @@ export class ForgeBridgeService {
|
|
|
1478
1549
|
this.dispatchResultFlushedGeneration = startedGeneration;
|
|
1479
1550
|
}
|
|
1480
1551
|
}
|
|
1552
|
+
/**
|
|
1553
|
+
* Forge binds each result to the runner instance that ran the attempt. On an
|
|
1554
|
+
* authoritative connection it rejects another instance's result with
|
|
1555
|
+
* bridge.stale_result_instance; Forge's own recovery handles that attempt,
|
|
1556
|
+
* so the record can never be delivered and must not block the replay queue.
|
|
1557
|
+
* bridge.stale_runner_instance means this connection is not authoritative
|
|
1558
|
+
* and says nothing about the record, so it never quarantines.
|
|
1559
|
+
*/
|
|
1560
|
+
isReplacedRunnerInstanceResult(payload, error) {
|
|
1561
|
+
return error instanceof BridgeCallbackRejectedError
|
|
1562
|
+
&& error.code === "bridge.stale_result_instance"
|
|
1563
|
+
&& typeof payload.runnerInstanceId === "string"
|
|
1564
|
+
&& payload.runnerInstanceId.toLowerCase() !== this.config.runnerInstanceId.toLowerCase();
|
|
1565
|
+
}
|
|
1481
1566
|
startHeartbeat() {
|
|
1482
1567
|
this.stopHeartbeat();
|
|
1483
1568
|
this.consecutiveHeartbeatFailures = 0;
|
|
@@ -1496,8 +1581,11 @@ export class ForgeBridgeService {
|
|
|
1496
1581
|
return;
|
|
1497
1582
|
this.heartbeatInFlight = true;
|
|
1498
1583
|
try {
|
|
1499
|
-
|
|
1500
|
-
|
|
1584
|
+
// A rejected replay is an answer from Forge, so the connection is alive:
|
|
1585
|
+
// an undeliverable record must not count as a heartbeat failure and
|
|
1586
|
+
// force reconnects. Transport failures still do.
|
|
1587
|
+
await this.flushDispatchResults().catch(deferRejectedReplay("Dispatch"));
|
|
1588
|
+
await this.flushReadinessResults().catch(deferRejectedReplay("Readiness"));
|
|
1501
1589
|
await this.sendHeartbeat();
|
|
1502
1590
|
this.consecutiveHeartbeatFailures = 0;
|
|
1503
1591
|
}
|
|
@@ -1640,6 +1728,7 @@ export class ForgeBridgeService {
|
|
|
1640
1728
|
capabilities() {
|
|
1641
1729
|
const preflight = this.preflight.current();
|
|
1642
1730
|
const dockerEngine = this.dockerEngineProbe.current();
|
|
1731
|
+
this.dockerAvailable = dockerEngine?.available === true;
|
|
1643
1732
|
const runtimeState = this.sandboxRuntime.snapshot();
|
|
1644
1733
|
const reserved = [...this.reservations.values()].filter(reservation => reservation.sandboxed).length;
|
|
1645
1734
|
const used = this.usedSandboxResources(runtimeState.degraded);
|
|
@@ -1656,7 +1745,7 @@ export class ForgeBridgeService {
|
|
|
1656
1745
|
pendingCommitmentMemoryBytes: Math.max(0, used.memoryBytes - activeResources.memoryBytes),
|
|
1657
1746
|
}) : null;
|
|
1658
1747
|
return {
|
|
1659
|
-
schemaVersion:
|
|
1748
|
+
schemaVersion: 7,
|
|
1660
1749
|
activeSessionCount: this.activeSessions.size,
|
|
1661
1750
|
cliProviders: this.config.cliProviders,
|
|
1662
1751
|
providerStatuses: this.config.providerStatuses,
|
|
@@ -1679,6 +1768,9 @@ export class ForgeBridgeService {
|
|
|
1679
1768
|
playwrightProjects: this.hostCapabilities.playwrightProjects,
|
|
1680
1769
|
browserLaunch: this.hostCapabilities.browserLaunch,
|
|
1681
1770
|
providerConnectivity: this.hostCapabilities.providerConnectivity,
|
|
1771
|
+
testPostgres: this.hostCapabilities.testPostgres,
|
|
1772
|
+
host: this.hostLoad.facts(),
|
|
1773
|
+
load: this.hostLoad.current(),
|
|
1682
1774
|
maxConcurrentSandboxes: capacity.sandboxSlots,
|
|
1683
1775
|
reservedSandboxCount: reserved,
|
|
1684
1776
|
activeSandboxCount: runtimeState.active,
|
|
@@ -1872,6 +1964,16 @@ export class ForgeBridgeService {
|
|
|
1872
1964
|
}
|
|
1873
1965
|
}
|
|
1874
1966
|
}
|
|
1967
|
+
/** The `run` command's exit code after Forge removed the runner. */
|
|
1968
|
+
export const bridgeRevokedExitCode = 3;
|
|
1969
|
+
export const bridgeRevokedMessage = "This bridge was removed from Forge. Pair it again with forge-bridge pair.";
|
|
1970
|
+
/** Thrown by `run` after Forge removed the runner, so the CLI exits instead of reconnecting. */
|
|
1971
|
+
export class BridgeRevokedError extends Error {
|
|
1972
|
+
constructor(message = bridgeRevokedMessage) {
|
|
1973
|
+
super(message);
|
|
1974
|
+
this.name = "BridgeRevokedError";
|
|
1975
|
+
}
|
|
1976
|
+
}
|
|
1875
1977
|
class BridgeCallbackRejectedError extends Error {
|
|
1876
1978
|
code;
|
|
1877
1979
|
constructor(code, message) {
|
|
@@ -1880,6 +1982,13 @@ class BridgeCallbackRejectedError extends Error {
|
|
|
1880
1982
|
this.name = "BridgeCallbackRejectedError";
|
|
1881
1983
|
}
|
|
1882
1984
|
}
|
|
1985
|
+
function deferRejectedReplay(kind) {
|
|
1986
|
+
return error => {
|
|
1987
|
+
if (!(error instanceof BridgeCallbackRejectedError))
|
|
1988
|
+
throw error;
|
|
1989
|
+
logBridgeStatus(`${kind} result replay deferred: ${errorMessage(error)}`);
|
|
1990
|
+
};
|
|
1991
|
+
}
|
|
1883
1992
|
function isDispatchNoLongerPending(error) {
|
|
1884
1993
|
if (error instanceof BridgeCallbackRejectedError) {
|
|
1885
1994
|
return error.code === "bridge.dispatch_not_pending" || error.code === "bridge.stale_dispatch";
|
|
@@ -1898,11 +2007,13 @@ function isProviderStorageUnavailable(error) {
|
|
|
1898
2007
|
function isBridgeCallbackTimeout(error) {
|
|
1899
2008
|
return errorMessage(error).startsWith("bridge_callback_timeout:");
|
|
1900
2009
|
}
|
|
1901
|
-
function createDefaultSessionService(sandboxStateRoot, sandboxExecutionRoot, dockerEngineProbe) {
|
|
2010
|
+
function createDefaultSessionService(sandboxStateRoot, sandboxExecutionRoot, dockerEngineProbe, hostLoad) {
|
|
1902
2011
|
const rawProcessRunner = new StreamingProviderProcessRunner();
|
|
1903
2012
|
const processSupervisors = new AttemptProcessSupervisorRegistry();
|
|
1904
2013
|
const coordinatedProcessRunner = new AttemptCoordinatedProviderProcessRunner(processSupervisors, rawProcessRunner);
|
|
1905
|
-
|
|
2014
|
+
const hostRuntime = new HostRuntimeLeaseManager(sandboxStateRoot, undefined, undefined, processSupervisors, rawProcessRunner, undefined, undefined, undefined, undefined, undefined, sandboxExecutionRoot, createNativeTestClusterDatabaseBroker(readNativeTestPostgresFallback, sandboxStateRoot), hostLoad);
|
|
2015
|
+
const sessions = new BridgeSessionService(new GitWorktreeService(undefined, new RepositoryCoordinatorLock(sandboxStateRoot), hostRuntime.hostLoadGovernor, sandboxStateRoot), new RoutingProviderCliService(new ProcessBackedProviderCliService(coordinatedProcessRunner, undefined, undefined, undefined, new PrePublicationValidator(undefined, dockerEngineProbe, readNativeTestPostgresFallback, hostRuntime.hostLoadGovernor))), hostRuntime);
|
|
2016
|
+
return { sessions, hostLoadGovernor: hostRuntime.hostLoadGovernor };
|
|
1906
2017
|
}
|
|
1907
2018
|
export class SignalRBridgeConnectionFactory {
|
|
1908
2019
|
create(config) {
|
|
@@ -1933,6 +2044,13 @@ export class SignalRBridgeConnection {
|
|
|
1933
2044
|
void this.connection.stop().catch(() => undefined);
|
|
1934
2045
|
});
|
|
1935
2046
|
}
|
|
2047
|
+
onRevoked(handler) {
|
|
2048
|
+
this.connection.on("Revoked", (raw) => {
|
|
2049
|
+
const notice = raw && typeof raw === "object" ? raw : {};
|
|
2050
|
+
handler(notice);
|
|
2051
|
+
void this.connection.stop().catch(() => undefined);
|
|
2052
|
+
});
|
|
2053
|
+
}
|
|
1936
2054
|
start() {
|
|
1937
2055
|
return this.connection.start();
|
|
1938
2056
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import type { HostRuntimeRequirements } from "../runtime/host-runtime-requirements.js";
|
|
2
|
+
import type { BridgeTestPostgresCapability } from "./test-postgres-capability.js";
|
|
1
3
|
import type { ApiKeySecretGrant, DispatchSandboxResourceRequest, RunOnceResultPacket, RunnerDispatchEvent } from "../session/session.types.js";
|
|
2
4
|
import type { SandboxFeatureMatrix } from "../sandbox/sandbox.types.js";
|
|
3
5
|
import type { HostRuntimeCapacitySnapshot } from "../runtime/host-runtime-lease.js";
|
|
4
6
|
import type { MemoryAdmissionDiagnostics } from "../runtime/memory-capacity.js";
|
|
5
7
|
import type { DockerEngineCapabilitySnapshot } from "../runtime/docker-engine-probe.js";
|
|
8
|
+
import type { HostFacts } from "../runtime/host-facts.js";
|
|
9
|
+
import type { HostLoadSnapshot } from "../runtime/host-load-sampler.js";
|
|
6
10
|
import type { BridgeChatCapability, ChatTurnCancelPacket } from "./bridge-chat.types.js";
|
|
7
11
|
export interface BridgeServiceConfig {
|
|
8
12
|
readonly serverUrl: string;
|
|
@@ -142,6 +146,12 @@ export interface BridgeCapabilities {
|
|
|
142
146
|
readonly playwrightProjects?: readonly string[] | null;
|
|
143
147
|
readonly browserLaunch?: boolean | null;
|
|
144
148
|
readonly providerConnectivity?: Readonly<Record<string, boolean>> | null;
|
|
149
|
+
/** Native test PostgreSQL and whether its role is a superuser (decision 0013 placement). */
|
|
150
|
+
readonly testPostgres?: BridgeTestPostgresCapability | null;
|
|
151
|
+
/** Static host hardware facts (schema 7). Material: changes are persisted immediately. */
|
|
152
|
+
readonly host?: HostFacts | null;
|
|
153
|
+
/** Live host load sample (schema 7). Never material: heartbeats with only load changes are not persisted. */
|
|
154
|
+
readonly load?: HostLoadSnapshot | null;
|
|
145
155
|
}
|
|
146
156
|
export interface SandboxMemoryCapacityDiagnostics {
|
|
147
157
|
readonly defaultWorkerMemoryLimitBytes: number;
|
|
@@ -292,6 +302,7 @@ export interface BridgeRuntimeReadinessResult {
|
|
|
292
302
|
readonly status: "parallel_ready" | "serialized" | "failed";
|
|
293
303
|
readonly runtimeContractFingerprint?: string | null;
|
|
294
304
|
readonly runtimeContractSource?: string | null;
|
|
305
|
+
readonly runtimeRequirements?: HostRuntimeRequirements | null;
|
|
295
306
|
readonly reasonCode?: string | null;
|
|
296
307
|
readonly reasonMessage?: string | null;
|
|
297
308
|
readonly qaAppLaunchTarget?: BridgeRuntimeReadinessQaLaunchTarget | null;
|
|
@@ -8,7 +8,14 @@ export interface DispatchResultOutbox {
|
|
|
8
8
|
persist(payload: BridgeDispatchResultCallback): Promise<void>;
|
|
9
9
|
pending(): Promise<readonly DurableDispatchResult[]>;
|
|
10
10
|
acknowledge(leaseId: string): Promise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* Moves an undeliverable record out of the replay set. The redacted result
|
|
13
|
+
* is kept, with its original persistedAt, so preserved work can be reconciled.
|
|
14
|
+
*/
|
|
15
|
+
quarantine(record: DurableDispatchResult): Promise<void>;
|
|
11
16
|
}
|
|
17
|
+
export declare const dispatchResultOutboxDirectory = "dispatch-results";
|
|
18
|
+
export declare const dispatchResultQuarantineDirectory = "dispatch-results-quarantine";
|
|
12
19
|
/**
|
|
13
20
|
* Persists the already-redacted terminal result before the Bridge attempts its
|
|
14
21
|
* SignalR callback. A transport or API restart can therefore delay delivery,
|
|
@@ -16,10 +23,13 @@ export interface DispatchResultOutbox {
|
|
|
16
23
|
*/
|
|
17
24
|
export declare class FileDispatchResultOutbox implements DispatchResultOutbox {
|
|
18
25
|
private readonly stateRoot;
|
|
26
|
+
private readonly directory;
|
|
19
27
|
private readonly writes;
|
|
20
|
-
constructor(stateRoot: string);
|
|
28
|
+
constructor(stateRoot: string, directory?: string);
|
|
21
29
|
persist(payload: BridgeDispatchResultCallback): Promise<void>;
|
|
30
|
+
private persistRecord;
|
|
22
31
|
pending(): Promise<readonly DurableDispatchResult[]>;
|
|
23
32
|
acknowledge(leaseId: string): Promise<void>;
|
|
33
|
+
quarantine(record: DurableDispatchResult): Promise<void>;
|
|
24
34
|
private operate;
|
|
25
35
|
}
|
|
@@ -3,6 +3,8 @@ import { isDeepStrictEqual } from "node:util";
|
|
|
3
3
|
import { assertCanonicalDirectory, createCanonicalDirectory } from "../runtime/attempt-private-directory.js";
|
|
4
4
|
import { runPinnedDirectoryProcess } from "../runtime/pinned-directory-process.js";
|
|
5
5
|
import { dispatchResultReceiptWorker } from "./dispatch-result-worker.js";
|
|
6
|
+
export const dispatchResultOutboxDirectory = "dispatch-results";
|
|
7
|
+
export const dispatchResultQuarantineDirectory = "dispatch-results-quarantine";
|
|
6
8
|
/**
|
|
7
9
|
* Persists the already-redacted terminal result before the Bridge attempts its
|
|
8
10
|
* SignalR callback. A transport or API restart can therefore delay delivery,
|
|
@@ -10,11 +12,16 @@ import { dispatchResultReceiptWorker } from "./dispatch-result-worker.js";
|
|
|
10
12
|
*/
|
|
11
13
|
export class FileDispatchResultOutbox {
|
|
12
14
|
stateRoot;
|
|
15
|
+
directory;
|
|
13
16
|
writes = new Map();
|
|
14
|
-
constructor(stateRoot) {
|
|
17
|
+
constructor(stateRoot, directory = dispatchResultOutboxDirectory) {
|
|
15
18
|
this.stateRoot = stateRoot;
|
|
19
|
+
this.directory = directory;
|
|
16
20
|
}
|
|
17
21
|
async persist(payload) {
|
|
22
|
+
await this.persistRecord(payload, new Date().toISOString());
|
|
23
|
+
}
|
|
24
|
+
async persistRecord(payload, persistedAt) {
|
|
18
25
|
const name = recordName(payload.leaseId);
|
|
19
26
|
const value = JSON.parse(JSON.stringify({ payload }));
|
|
20
27
|
const pending = this.writes.get(name);
|
|
@@ -27,7 +34,7 @@ export class FileDispatchResultOutbox {
|
|
|
27
34
|
const write = this.operate({
|
|
28
35
|
kind: "persist",
|
|
29
36
|
name,
|
|
30
|
-
record: { schemaVersion: 1, persistedAt
|
|
37
|
+
record: { schemaVersion: 1, persistedAt, ...value },
|
|
31
38
|
}).then(() => undefined);
|
|
32
39
|
this.writes.set(name, { value, write });
|
|
33
40
|
try {
|
|
@@ -44,8 +51,23 @@ export class FileDispatchResultOutbox {
|
|
|
44
51
|
async acknowledge(leaseId) {
|
|
45
52
|
await this.operate({ kind: "acknowledge", name: recordName(leaseId) });
|
|
46
53
|
}
|
|
54
|
+
async quarantine(record) {
|
|
55
|
+
// One execution lease can carry several dispatch attempts, so quarantine
|
|
56
|
+
// files are grouped per attempt: <quarantine>/<attempt>/<lease>.json.
|
|
57
|
+
// Copy before removal: a crash in between leaves an identical record in
|
|
58
|
+
// both places, and the next replay quarantines it again idempotently.
|
|
59
|
+
// A record without an attempt id has no per-attempt bucket; the caller
|
|
60
|
+
// keeps it deferred rather than grouping unrelated attempts together.
|
|
61
|
+
const { payload } = record;
|
|
62
|
+
if (!payload.dispatchAttemptId) {
|
|
63
|
+
throw new Error("dispatch_result_invalid: only attempt-bound results can be quarantined.");
|
|
64
|
+
}
|
|
65
|
+
const bucket = path.join(dispatchResultQuarantineDirectory, compactUuid(payload.dispatchAttemptId));
|
|
66
|
+
await new FileDispatchResultOutbox(this.stateRoot, bucket).persistRecord(payload, record.persistedAt);
|
|
67
|
+
await this.acknowledge(payload.leaseId);
|
|
68
|
+
}
|
|
47
69
|
async operate(operation) {
|
|
48
|
-
const root = path.resolve(this.stateRoot,
|
|
70
|
+
const root = path.resolve(this.stateRoot, this.directory);
|
|
49
71
|
await createCanonicalDirectory(root);
|
|
50
72
|
const identity = await assertCanonicalDirectory(root);
|
|
51
73
|
if (!identity)
|
|
@@ -54,9 +76,12 @@ export class FileDispatchResultOutbox {
|
|
|
54
76
|
}
|
|
55
77
|
}
|
|
56
78
|
function recordName(leaseId) {
|
|
57
|
-
|
|
79
|
+
return `${compactUuid(leaseId)}.json`;
|
|
80
|
+
}
|
|
81
|
+
function compactUuid(id) {
|
|
82
|
+
const value = id.replaceAll("-", "").toLowerCase();
|
|
58
83
|
if (!/^[0-9a-f]{32}$/u.test(value)) {
|
|
59
|
-
throw new Error("dispatch_result_invalid:
|
|
84
|
+
throw new Error("dispatch_result_invalid: identifiers must be UUIDs.");
|
|
60
85
|
}
|
|
61
|
-
return
|
|
86
|
+
return value;
|
|
62
87
|
}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { BridgeServiceConfig, BridgeToolchainCapabilities } from "./bridge.types.js";
|
|
2
|
+
import { type BridgeTestPostgresCapability } from "./test-postgres-capability.js";
|
|
2
3
|
export interface RunnerHostCapabilitySnapshot {
|
|
3
4
|
readonly toolchains: BridgeToolchainCapabilities;
|
|
4
5
|
readonly playwrightProjects: readonly string[];
|
|
5
6
|
readonly browserLaunch: boolean;
|
|
6
7
|
readonly providerConnectivity: Readonly<Record<string, boolean>>;
|
|
8
|
+
readonly testPostgres: BridgeTestPostgresCapability;
|
|
7
9
|
}
|
|
8
10
|
export interface RunnerHostCapabilityProbe {
|
|
9
11
|
detect(config: BridgeServiceConfig): Promise<RunnerHostCapabilitySnapshot>;
|
|
@@ -2,6 +2,7 @@ import { execFile } from "node:child_process";
|
|
|
2
2
|
import fs from "node:fs/promises";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { promisify } from "node:util";
|
|
5
|
+
import { probeTestPostgresCapability } from "./test-postgres-capability.js";
|
|
5
6
|
const execFileAsync = promisify(execFile);
|
|
6
7
|
export class ProcessRunnerHostCapabilityProbe {
|
|
7
8
|
async detect(config) {
|
|
@@ -16,6 +17,7 @@ export class ProcessRunnerHostCapabilityProbe {
|
|
|
16
17
|
: Promise.resolve(unavailable("powershell.exe")),
|
|
17
18
|
]);
|
|
18
19
|
const playwrightProjects = await detectPlaywrightProjects(config.repoMappings);
|
|
20
|
+
const testPostgres = await probeTestPostgresCapability();
|
|
19
21
|
const browserLaunch = playwrightProjects.length > 0
|
|
20
22
|
|| config.repoMappings.some(mapping => Boolean(mapping.qaAppLaunchTarget?.url
|
|
21
23
|
|| mapping.qaAppLaunchTarget?.command
|
|
@@ -33,6 +35,7 @@ export class ProcessRunnerHostCapabilityProbe {
|
|
|
33
35
|
browserLaunch,
|
|
34
36
|
providerConnectivity: Object.fromEntries(Object.entries(config.providerStatuses)
|
|
35
37
|
.map(([provider, status]) => [provider, status.signedIn === true])),
|
|
38
|
+
testPostgres,
|
|
36
39
|
};
|
|
37
40
|
}
|
|
38
41
|
}
|
|
@@ -89,5 +92,6 @@ export function emptyRunnerHostCapabilitySnapshot() {
|
|
|
89
92
|
playwrightProjects: [],
|
|
90
93
|
browserLaunch: false,
|
|
91
94
|
providerConnectivity: {},
|
|
95
|
+
testPostgres: { available: false, superuser: null },
|
|
92
96
|
};
|
|
93
97
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether this host offers a native test PostgreSQL and whether its role is a superuser
|
|
3
|
+
* (decision 0013 placement). Suites that need `session_replication_role`, `CREATE ROLE` or
|
|
4
|
+
* similar can only run on a superuser test database or on Docker-backed Testcontainers.
|
|
5
|
+
*/
|
|
6
|
+
export interface BridgeTestPostgresCapability {
|
|
7
|
+
readonly available: boolean;
|
|
8
|
+
/** Null when the cluster is configured but the role could not be checked. */
|
|
9
|
+
readonly superuser: boolean | null;
|
|
10
|
+
}
|
|
11
|
+
export type PsqlRunner = (args: readonly string[], env: NodeJS.ProcessEnv) => Promise<string>;
|
|
12
|
+
export declare function probeTestPostgresCapability(environment?: NodeJS.ProcessEnv, runPsql?: PsqlRunner, readFallback?: () => string | null): Promise<BridgeTestPostgresCapability>;
|
|
13
|
+
/** Maps an Npgsql-style connection string or a postgres:// URI to libpq environment. */
|
|
14
|
+
export declare function psqlTarget(connection: string): Record<string, string> | null;
|