@loucompanion/forge-bridge 0.1.4-dev.bfa11ebe98c6 → 0.1.4-dev.c2f22d1dd395
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 +1 -1
- package/dist/bridge/bridge.service.d.ts +12 -1
- package/dist/bridge/bridge.service.js +53 -6
- package/dist/bridge/bridge.types.d.ts +6 -0
- package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
- package/dist/bridge/dispatch-result-outbox.js +31 -6
- package/dist/cli/cli.help.js +2 -2
- package/dist/runtime/attempt-database-broker.d.ts +89 -0
- package/dist/runtime/attempt-database-broker.js +390 -0
- package/dist/runtime/attempt-process-supervisor.d.ts +24 -0
- package/dist/runtime/attempt-process-supervisor.js +77 -3
- 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-diagnostics.js +4 -3
- package/dist/runtime/host-facts.d.ts +35 -0
- package/dist/runtime/host-facts.js +95 -0
- package/dist/runtime/host-load-sampler.d.ts +83 -0
- package/dist/runtime/host-load-sampler.js +164 -0
- package/dist/runtime/host-pressure-stall.d.ts +41 -0
- package/dist/runtime/host-pressure-stall.js +121 -0
- package/dist/runtime/host-runtime-contract.d.ts +1 -0
- package/dist/runtime/host-runtime-contract.js +71 -10
- package/dist/runtime/host-runtime-lease.d.ts +4 -2
- package/dist/runtime/host-runtime-lease.js +108 -24
- package/dist/runtime/managed-command-teardown.d.ts +62 -0
- package/dist/runtime/managed-command-teardown.js +607 -0
- package/dist/runtime/node-host-runtime-adapter.js +5 -4
- package/dist/runtime/playwright-browser-cache.d.ts +39 -0
- package/dist/runtime/playwright-browser-cache.js +227 -0
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +11 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +48 -54
- package/dist/sandbox/repository-lock.js +3 -2
- package/dist/sandbox/runtime.js +5 -4
- package/dist/session/managed-attempt-tools.d.ts +25 -0
- package/dist/session/managed-attempt-tools.js +222 -20
- package/dist/session/managed-build-coordinator.d.ts +1 -1
- package/dist/session/managed-build-coordinator.js +8 -4
- package/dist/session/phase-completion.artifacts.js +4 -0
- package/dist/session/phase-completion.runtime.js +30 -18
- package/dist/session/pre-publication-process.d.ts +20 -0
- package/dist/session/pre-publication-process.js +97 -0
- 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-validation.js +32 -58
- package/dist/session/provider-cli/provider-cli.artifacts.js +2 -9
- package/dist/session/provider-cli/provider-cli.process.d.ts +6 -1
- package/dist/session/provider-cli/provider-cli.process.js +198 -16
- package/dist/session/provider-cli/provider-cli.runtime.d.ts +6 -0
- package/dist/session/provider-cli/provider-cli.runtime.js +14 -0
- package/dist/session/provider-cli/provider-cli.service.js +64 -12
- package/dist/session/provider-cli/provider-usage.d.ts +2 -1
- package/dist/session/publishable-worktree-changes.d.ts +45 -0
- package/dist/session/publishable-worktree-changes.js +177 -0
- package/dist/session/session.types.js +3 -0
- package/dist/shared/process/host-process-recovery.js +3 -2
- package/dist/shared/process/host-process-supervisor.js +5 -4
- package/dist/shared/time/monotonic.d.ts +1 -0
- package/dist/shared/time/monotonic.js +8 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/dist/worktree/dependency-warmer.js +74 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -65,7 +65,7 @@ Show or change the saved server without editing `bridge.json`:
|
|
|
65
65
|
```bash
|
|
66
66
|
forge-bridge server show
|
|
67
67
|
forge-bridge server set http://localhost:5208
|
|
68
|
-
forge-bridge server set https://
|
|
68
|
+
forge-bridge server set https://forge.example.ts.net:8443
|
|
69
69
|
```
|
|
70
70
|
|
|
71
71
|
`FORGE_URL` overrides the saved server. Changing the saved URL retains runner credentials so aliases for the same deployment keep working; pair again with `--server` when switching to a different Forge deployment.
|
|
@@ -7,6 +7,7 @@ import type { SandboxPreflightResult } from "../sandbox/sandbox.types.js";
|
|
|
7
7
|
import { type SandboxRuntime } from "../sandbox/runtime.js";
|
|
8
8
|
import type { BridgeConnection, BridgeConnectionFactory, 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;
|
|
@@ -60,7 +62,7 @@ export declare class ForgeBridgeService implements BridgeService {
|
|
|
60
62
|
private hostCapabilities;
|
|
61
63
|
private readonly recoveredHostAttempts;
|
|
62
64
|
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);
|
|
65
|
+
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
66
|
connectOnce(): Promise<void>;
|
|
65
67
|
private rememberRecoveredHostAttempts;
|
|
66
68
|
private recoveredHostAttemptsForHello;
|
|
@@ -107,6 +109,15 @@ export declare class ForgeBridgeService implements BridgeService {
|
|
|
107
109
|
private sendResultPayloadDirect;
|
|
108
110
|
private flushDispatchResults;
|
|
109
111
|
private flushDispatchResultsCore;
|
|
112
|
+
/**
|
|
113
|
+
* Forge binds each result to the runner instance that ran the attempt. On an
|
|
114
|
+
* authoritative connection it rejects another instance's result with
|
|
115
|
+
* bridge.stale_result_instance; Forge's own recovery handles that attempt,
|
|
116
|
+
* so the record can never be delivered and must not block the replay queue.
|
|
117
|
+
* bridge.stale_runner_instance means this connection is not authoritative
|
|
118
|
+
* and says nothing about the record, so it never quarantines.
|
|
119
|
+
*/
|
|
120
|
+
private isReplacedRunnerInstanceResult;
|
|
110
121
|
private startHeartbeat;
|
|
111
122
|
private heartbeatTick;
|
|
112
123
|
private startLeaseWatchdog;
|
|
@@ -17,6 +17,7 @@ import { assertHostDatabaseCapabilityBoundary, establishHostDatabaseCapabilityBo
|
|
|
17
17
|
import { defaultHostExecutionRoot } from "../runtime/host-execution-root.js";
|
|
18
18
|
import { buildMemoryAdmissionDiagnostics } from "../runtime/memory-capacity.js";
|
|
19
19
|
import { DockerEngineProbe } from "../runtime/docker-engine-probe.js";
|
|
20
|
+
import { createNativeTestClusterDatabaseBroker } from "../runtime/attempt-database-broker.js";
|
|
20
21
|
import { readNativeTestPostgresFallback } from "../runtime/native-test-postgres-fallback.js";
|
|
21
22
|
import { estimateWorkspaceBytesFromRepo } from "../runtime/workspace-resource-estimator.js";
|
|
22
23
|
import { GitWorktreeService } from "../worktree/worktree.service.js";
|
|
@@ -32,8 +33,9 @@ import { codexSandboxProviderAuthAdapter, sandboxProviderAuthAdapterFor, sandbox
|
|
|
32
33
|
import { assertBridgeChatCallbackPayload, bridgeChatMaxProviderThreadIdChars, bridgeChatProtocolVersion, isTerminalChatTurnCallbackKind, parseChatTurnDispatchPacket, } from "./bridge-chat.types.js";
|
|
33
34
|
import { formatBytes } from "../shared/format/format-bytes.js";
|
|
34
35
|
import { emptyRunnerHostCapabilitySnapshot, ProcessRunnerHostCapabilityProbe, } from "./runner-host-capabilities.js";
|
|
36
|
+
import { HostLoadSampler } from "../runtime/host-load-sampler.js";
|
|
35
37
|
import { FileReadinessResultOutbox } from "./readiness-result-outbox.js";
|
|
36
|
-
import { FileDispatchResultOutbox } from "./dispatch-result-outbox.js";
|
|
38
|
+
import { dispatchResultQuarantineDirectory, FileDispatchResultOutbox } from "./dispatch-result-outbox.js";
|
|
37
39
|
/**
|
|
38
40
|
* Protocol-v2 events are acknowledged one at a time before runOnce returns.
|
|
39
41
|
* Sending the complete transcript again in DispatchResult made long QA and CI
|
|
@@ -52,6 +54,7 @@ export class ForgeBridgeService {
|
|
|
52
54
|
connections;
|
|
53
55
|
hostCapabilityProbe;
|
|
54
56
|
chatProcessRunner;
|
|
57
|
+
hostLoad;
|
|
55
58
|
connection = null;
|
|
56
59
|
heartbeatTimer = null;
|
|
57
60
|
heartbeatInFlight = false;
|
|
@@ -86,11 +89,12 @@ export class ForgeBridgeService {
|
|
|
86
89
|
// leaves those attempts on Forge's conservative unknown-outcome path.
|
|
87
90
|
recoveredHostAttempts = new Map();
|
|
88
91
|
hostCapabilitiesDetected = false;
|
|
89
|
-
constructor(config, sessions = undefined, connections = new SignalRBridgeConnectionFactory(), preflight, sandboxRuntime, sandboxResourceResolver, dockerEngineProbe, hostCapabilityProbe = new ProcessRunnerHostCapabilityProbe(), readinessResultOutbox, chatProcessRunner = new StreamingProviderProcessRunner(), dispatchResultOutbox) {
|
|
92
|
+
constructor(config, sessions = undefined, connections = new SignalRBridgeConnectionFactory(), preflight, sandboxRuntime, sandboxResourceResolver, dockerEngineProbe, hostCapabilityProbe = new ProcessRunnerHostCapabilityProbe(), readinessResultOutbox, chatProcessRunner = new StreamingProviderProcessRunner(), dispatchResultOutbox, hostLoad = new HostLoadSampler()) {
|
|
90
93
|
this.config = config;
|
|
91
94
|
this.connections = connections;
|
|
92
95
|
this.hostCapabilityProbe = hostCapabilityProbe;
|
|
93
96
|
this.chatProcessRunner = chatProcessRunner;
|
|
97
|
+
this.hostLoad = hostLoad;
|
|
94
98
|
this.enforceHostDatabaseCapabilityBoundary = sessions === undefined;
|
|
95
99
|
if (this.enforceHostDatabaseCapabilityBoundary) {
|
|
96
100
|
establishHostDatabaseCapabilityBoundary();
|
|
@@ -155,6 +159,9 @@ export class ForgeBridgeService {
|
|
|
155
159
|
this.hostCapabilities = await this.hostCapabilityProbe.detect(this.config);
|
|
156
160
|
this.hostCapabilitiesDetected = true;
|
|
157
161
|
}
|
|
162
|
+
// Static host facts and the first load sample ride on Hello; the sampler
|
|
163
|
+
// keeps refreshing its cached snapshot for later heartbeats.
|
|
164
|
+
await this.hostLoad.start().catch(() => undefined);
|
|
158
165
|
const connection = this.connections.create(this.config);
|
|
159
166
|
this.connection = connection;
|
|
160
167
|
this.transportRecovery = null;
|
|
@@ -305,6 +312,7 @@ export class ForgeBridgeService {
|
|
|
305
312
|
this.abortActiveSessions("bridge stopping");
|
|
306
313
|
this.abortActiveReadinessProbes("bridge stopping");
|
|
307
314
|
await this.stopConnection();
|
|
315
|
+
this.hostLoad.stop();
|
|
308
316
|
await this.preflight.release();
|
|
309
317
|
}
|
|
310
318
|
async handleChatTurn(rawDispatch) {
|
|
@@ -1467,6 +1475,19 @@ export class ForgeBridgeService {
|
|
|
1467
1475
|
await this.dispatchResultOutbox.acknowledge(pending.payload.leaseId);
|
|
1468
1476
|
continue;
|
|
1469
1477
|
}
|
|
1478
|
+
if (this.isReplacedRunnerInstanceResult(pending.payload, error)) {
|
|
1479
|
+
try {
|
|
1480
|
+
await this.dispatchResultOutbox.quarantine(pending);
|
|
1481
|
+
}
|
|
1482
|
+
catch (quarantineError) {
|
|
1483
|
+
// Keep the record and surface Forge's rejection: replay stays
|
|
1484
|
+
// deferred and a heartbeat tick does not count it as a failure.
|
|
1485
|
+
logBridgeStatus(`Dispatch result ${pending.payload.leaseId} from replaced runner instance ${pending.payload.runnerInstanceId} could not be quarantined: ${errorMessage(quarantineError)}`);
|
|
1486
|
+
throw error;
|
|
1487
|
+
}
|
|
1488
|
+
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.`);
|
|
1489
|
+
continue;
|
|
1490
|
+
}
|
|
1470
1491
|
throw error;
|
|
1471
1492
|
}
|
|
1472
1493
|
}
|
|
@@ -1477,6 +1498,20 @@ export class ForgeBridgeService {
|
|
|
1477
1498
|
this.dispatchResultFlushedGeneration = startedGeneration;
|
|
1478
1499
|
}
|
|
1479
1500
|
}
|
|
1501
|
+
/**
|
|
1502
|
+
* Forge binds each result to the runner instance that ran the attempt. On an
|
|
1503
|
+
* authoritative connection it rejects another instance's result with
|
|
1504
|
+
* bridge.stale_result_instance; Forge's own recovery handles that attempt,
|
|
1505
|
+
* so the record can never be delivered and must not block the replay queue.
|
|
1506
|
+
* bridge.stale_runner_instance means this connection is not authoritative
|
|
1507
|
+
* and says nothing about the record, so it never quarantines.
|
|
1508
|
+
*/
|
|
1509
|
+
isReplacedRunnerInstanceResult(payload, error) {
|
|
1510
|
+
return error instanceof BridgeCallbackRejectedError
|
|
1511
|
+
&& error.code === "bridge.stale_result_instance"
|
|
1512
|
+
&& typeof payload.runnerInstanceId === "string"
|
|
1513
|
+
&& payload.runnerInstanceId.toLowerCase() !== this.config.runnerInstanceId.toLowerCase();
|
|
1514
|
+
}
|
|
1480
1515
|
startHeartbeat() {
|
|
1481
1516
|
this.stopHeartbeat();
|
|
1482
1517
|
this.consecutiveHeartbeatFailures = 0;
|
|
@@ -1495,8 +1530,11 @@ export class ForgeBridgeService {
|
|
|
1495
1530
|
return;
|
|
1496
1531
|
this.heartbeatInFlight = true;
|
|
1497
1532
|
try {
|
|
1498
|
-
|
|
1499
|
-
|
|
1533
|
+
// A rejected replay is an answer from Forge, so the connection is alive:
|
|
1534
|
+
// an undeliverable record must not count as a heartbeat failure and
|
|
1535
|
+
// force reconnects. Transport failures still do.
|
|
1536
|
+
await this.flushDispatchResults().catch(deferRejectedReplay("Dispatch"));
|
|
1537
|
+
await this.flushReadinessResults().catch(deferRejectedReplay("Readiness"));
|
|
1500
1538
|
await this.sendHeartbeat();
|
|
1501
1539
|
this.consecutiveHeartbeatFailures = 0;
|
|
1502
1540
|
}
|
|
@@ -1655,7 +1693,7 @@ export class ForgeBridgeService {
|
|
|
1655
1693
|
pendingCommitmentMemoryBytes: Math.max(0, used.memoryBytes - activeResources.memoryBytes),
|
|
1656
1694
|
}) : null;
|
|
1657
1695
|
return {
|
|
1658
|
-
schemaVersion:
|
|
1696
|
+
schemaVersion: 7,
|
|
1659
1697
|
activeSessionCount: this.activeSessions.size,
|
|
1660
1698
|
cliProviders: this.config.cliProviders,
|
|
1661
1699
|
providerStatuses: this.config.providerStatuses,
|
|
@@ -1678,6 +1716,8 @@ export class ForgeBridgeService {
|
|
|
1678
1716
|
playwrightProjects: this.hostCapabilities.playwrightProjects,
|
|
1679
1717
|
browserLaunch: this.hostCapabilities.browserLaunch,
|
|
1680
1718
|
providerConnectivity: this.hostCapabilities.providerConnectivity,
|
|
1719
|
+
host: this.hostLoad.facts(),
|
|
1720
|
+
load: this.hostLoad.current(),
|
|
1681
1721
|
maxConcurrentSandboxes: capacity.sandboxSlots,
|
|
1682
1722
|
reservedSandboxCount: reserved,
|
|
1683
1723
|
activeSandboxCount: runtimeState.active,
|
|
@@ -1879,6 +1919,13 @@ class BridgeCallbackRejectedError extends Error {
|
|
|
1879
1919
|
this.name = "BridgeCallbackRejectedError";
|
|
1880
1920
|
}
|
|
1881
1921
|
}
|
|
1922
|
+
function deferRejectedReplay(kind) {
|
|
1923
|
+
return error => {
|
|
1924
|
+
if (!(error instanceof BridgeCallbackRejectedError))
|
|
1925
|
+
throw error;
|
|
1926
|
+
logBridgeStatus(`${kind} result replay deferred: ${errorMessage(error)}`);
|
|
1927
|
+
};
|
|
1928
|
+
}
|
|
1882
1929
|
function isDispatchNoLongerPending(error) {
|
|
1883
1930
|
if (error instanceof BridgeCallbackRejectedError) {
|
|
1884
1931
|
return error.code === "bridge.dispatch_not_pending" || error.code === "bridge.stale_dispatch";
|
|
@@ -1901,7 +1948,7 @@ function createDefaultSessionService(sandboxStateRoot, sandboxExecutionRoot, doc
|
|
|
1901
1948
|
const rawProcessRunner = new StreamingProviderProcessRunner();
|
|
1902
1949
|
const processSupervisors = new AttemptProcessSupervisorRegistry();
|
|
1903
1950
|
const coordinatedProcessRunner = new AttemptCoordinatedProviderProcessRunner(processSupervisors, rawProcessRunner);
|
|
1904
|
-
return new BridgeSessionService(new GitWorktreeService(undefined, new RepositoryCoordinatorLock(sandboxStateRoot)), new RoutingProviderCliService(new ProcessBackedProviderCliService(coordinatedProcessRunner, undefined, undefined, undefined, new PrePublicationValidator(undefined, dockerEngineProbe, readNativeTestPostgresFallback))), new HostRuntimeLeaseManager(sandboxStateRoot, undefined, undefined, processSupervisors, rawProcessRunner, undefined, undefined, undefined, undefined, undefined, sandboxExecutionRoot));
|
|
1951
|
+
return new BridgeSessionService(new GitWorktreeService(undefined, new RepositoryCoordinatorLock(sandboxStateRoot)), new RoutingProviderCliService(new ProcessBackedProviderCliService(coordinatedProcessRunner, undefined, undefined, undefined, new PrePublicationValidator(undefined, dockerEngineProbe, readNativeTestPostgresFallback))), new HostRuntimeLeaseManager(sandboxStateRoot, undefined, undefined, processSupervisors, rawProcessRunner, undefined, undefined, undefined, undefined, undefined, sandboxExecutionRoot, createNativeTestClusterDatabaseBroker(readNativeTestPostgresFallback, sandboxStateRoot)));
|
|
1905
1952
|
}
|
|
1906
1953
|
export class SignalRBridgeConnectionFactory {
|
|
1907
1954
|
create(config) {
|
|
@@ -3,6 +3,8 @@ import type { SandboxFeatureMatrix } from "../sandbox/sandbox.types.js";
|
|
|
3
3
|
import type { HostRuntimeCapacitySnapshot } from "../runtime/host-runtime-lease.js";
|
|
4
4
|
import type { MemoryAdmissionDiagnostics } from "../runtime/memory-capacity.js";
|
|
5
5
|
import type { DockerEngineCapabilitySnapshot } from "../runtime/docker-engine-probe.js";
|
|
6
|
+
import type { HostFacts } from "../runtime/host-facts.js";
|
|
7
|
+
import type { HostLoadSnapshot } from "../runtime/host-load-sampler.js";
|
|
6
8
|
import type { BridgeChatCapability, ChatTurnCancelPacket } from "./bridge-chat.types.js";
|
|
7
9
|
export interface BridgeServiceConfig {
|
|
8
10
|
readonly serverUrl: string;
|
|
@@ -142,6 +144,10 @@ export interface BridgeCapabilities {
|
|
|
142
144
|
readonly playwrightProjects?: readonly string[] | null;
|
|
143
145
|
readonly browserLaunch?: boolean | null;
|
|
144
146
|
readonly providerConnectivity?: Readonly<Record<string, boolean>> | null;
|
|
147
|
+
/** Static host hardware facts (schema 7). Material: changes are persisted immediately. */
|
|
148
|
+
readonly host?: HostFacts | null;
|
|
149
|
+
/** Live host load sample (schema 7). Never material: heartbeats with only load changes are not persisted. */
|
|
150
|
+
readonly load?: HostLoadSnapshot | null;
|
|
145
151
|
}
|
|
146
152
|
export interface SandboxMemoryCapacityDiagnostics {
|
|
147
153
|
readonly defaultWorkerMemoryLimitBytes: number;
|
|
@@ -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
|
}
|
package/dist/cli/cli.help.js
CHANGED
|
@@ -28,7 +28,7 @@ export function helpText() {
|
|
|
28
28
|
"",
|
|
29
29
|
"Examples:",
|
|
30
30
|
" npm install -g @loucompanion/forge-bridge@next",
|
|
31
|
-
" forge-bridge pair 1234-5678 --server https://
|
|
31
|
+
" forge-bridge pair 1234-5678 --server https://forge.example.ts.net:8443 --repo-root \"%USERPROFILE%\\ForgeRepos\"",
|
|
32
32
|
" forge-bridge connect",
|
|
33
33
|
" forge-bridge status --check-updates",
|
|
34
34
|
" forge-bridge server set http://localhost:5208",
|
|
@@ -116,7 +116,7 @@ export function commandHelpText(command) {
|
|
|
116
116
|
"",
|
|
117
117
|
"Examples:",
|
|
118
118
|
" forge-bridge server set http://localhost:5208",
|
|
119
|
-
" forge-bridge server set https://
|
|
119
|
+
" forge-bridge server set https://forge.example.ts.net:8443",
|
|
120
120
|
"",
|
|
121
121
|
].join("\n");
|
|
122
122
|
case "add-repo":
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import type { NativeTestPostgresFallback } from "./native-test-postgres-fallback.js";
|
|
2
|
+
/**
|
|
3
|
+
* The managed host attempt's database capability. The Bridge keeps the test cluster's
|
|
4
|
+
* administrator credential; an attempt (its agent, its application runtime and its tests)
|
|
5
|
+
* receives only a login for one database created for it. Forge.Api checks that login before it
|
|
6
|
+
* migrates (AttemptScopedDatabasePolicy.AssertBrokeredCapabilityAsync), but that check runs in
|
|
7
|
+
* attempt code: the boundary is what this broker issues and the cluster's pg_hba rules, which
|
|
8
|
+
* let an attempt role log in only to its own database.
|
|
9
|
+
*/
|
|
10
|
+
export declare const attemptDatabaseCapabilityEnvironment = "FORGE_ATTEMPT_DATABASE_CAPABILITY";
|
|
11
|
+
export interface AttemptDatabaseCapability {
|
|
12
|
+
readonly databaseName: string;
|
|
13
|
+
readonly connectionString: string;
|
|
14
|
+
}
|
|
15
|
+
export type AttemptDatabaseReleaseOutcome = "dropped" | "missing" | "retained";
|
|
16
|
+
export interface AttemptDatabaseBroker {
|
|
17
|
+
provision(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal): Promise<AttemptDatabaseCapability>;
|
|
18
|
+
release(dispatchAttemptId: string, fencingToken: string): Promise<AttemptDatabaseReleaseOutcome>;
|
|
19
|
+
/**
|
|
20
|
+
* Drops this broker's databases whose attempt is no longer live, asking `isLive` about each one
|
|
21
|
+
* just before acting on it. Returns the dropped names.
|
|
22
|
+
*/
|
|
23
|
+
reapOrphans(isLive: (dispatchAttemptId: string) => boolean): Promise<readonly string[]>;
|
|
24
|
+
}
|
|
25
|
+
export declare class AttemptDatabaseBrokerError extends Error {
|
|
26
|
+
readonly code: string;
|
|
27
|
+
constructor(code: string, detail: string);
|
|
28
|
+
}
|
|
29
|
+
export interface AttemptDatabaseLogin {
|
|
30
|
+
readonly database: string;
|
|
31
|
+
readonly username: string;
|
|
32
|
+
readonly password: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Runs one psql script and returns its unaligned output: as the cluster administrator against
|
|
36
|
+
* `postgres`, or, given a login, as that login against its database.
|
|
37
|
+
*/
|
|
38
|
+
export type AttemptDatabaseSqlRunner = (sql: string, signal?: AbortSignal, login?: AttemptDatabaseLogin) => Promise<string>;
|
|
39
|
+
/**
|
|
40
|
+
* The ownership marker on the attempt's role. Only a role with CREATEROLE can change a role's
|
|
41
|
+
* comment, so the attempt cannot forge or erase it (it can rewrite its database's comment, which
|
|
42
|
+
* is therefore informational). Must match AttemptScopedDatabasePolicy.BrokeredRoleMarkerPrefix.
|
|
43
|
+
*/
|
|
44
|
+
export declare function brokeredDatabaseMarker(dispatchAttemptId: string, fencingToken: string, owner: string): string;
|
|
45
|
+
export declare function attemptDatabaseName(dispatchAttemptId: string): string;
|
|
46
|
+
/** Identifies one Bridge's broker on a shared cluster, so it reaps only databases it issued. */
|
|
47
|
+
export declare function attemptDatabaseBrokerOwner(stateRoot: string): string;
|
|
48
|
+
/**
|
|
49
|
+
* Brokers attempt databases on the dedicated native test cluster that
|
|
50
|
+
* scripts/setup-native-test-postgres.ps1 provisions. That cluster holds only disposable test
|
|
51
|
+
* databases, so even a leaked attempt capability cannot reach developer data. Each attempt
|
|
52
|
+
* gets a login role and a database it owns, cloned from template1 (which carries pgvector,
|
|
53
|
+
* an extension an unprivileged owner cannot create).
|
|
54
|
+
*/
|
|
55
|
+
export declare class NativeTestClusterDatabaseBroker implements AttemptDatabaseBroker {
|
|
56
|
+
private readonly admin;
|
|
57
|
+
private readonly runSql;
|
|
58
|
+
private readonly owner;
|
|
59
|
+
private readonly delay;
|
|
60
|
+
/** Names being provisioned right now; the reaper leaves them alone. */
|
|
61
|
+
private readonly provisioning;
|
|
62
|
+
constructor(admin: NativeTestClusterAdmin, runSql: AttemptDatabaseSqlRunner, owner: string, delay?: (milliseconds: number) => Promise<void>);
|
|
63
|
+
provision(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal): Promise<AttemptDatabaseCapability>;
|
|
64
|
+
release(dispatchAttemptId: string, fencingToken: string): Promise<AttemptDatabaseReleaseOutcome>;
|
|
65
|
+
reapOrphans(isLive: (dispatchAttemptId: string) => boolean): Promise<readonly string[]>;
|
|
66
|
+
private state;
|
|
67
|
+
private createDatabase;
|
|
68
|
+
/** Fails closed unless the cluster lets this login reach its own database and nothing else. */
|
|
69
|
+
private assertConfinedToOwnDatabase;
|
|
70
|
+
private drop;
|
|
71
|
+
}
|
|
72
|
+
export interface NativeTestClusterAdmin {
|
|
73
|
+
readonly host: string;
|
|
74
|
+
readonly port: number;
|
|
75
|
+
readonly username: string;
|
|
76
|
+
readonly password: string;
|
|
77
|
+
}
|
|
78
|
+
export declare function nativeTestClusterAdmin(fallback: NativeTestPostgresFallback): NativeTestClusterAdmin;
|
|
79
|
+
/** Runs SQL through the psql that ships with the PostgreSQL install hosting the native test cluster. */
|
|
80
|
+
export declare function psqlSqlRunner(admin: NativeTestClusterAdmin, psqlPath: string, timeoutMs?: number): AttemptDatabaseSqlRunner;
|
|
81
|
+
/** psql beside the cluster's pg_ctl: FORGE_NATIVE_TEST_POSTGRES_PSQL, a Windows install, or PATH. */
|
|
82
|
+
export declare function resolvePsqlPath(): string | null;
|
|
83
|
+
/**
|
|
84
|
+
* The broker for this host, or null when no native test cluster is provisioned. Without a
|
|
85
|
+
* broker, Forge.Api still refuses to start in a managed host attempt; other applications run.
|
|
86
|
+
*/
|
|
87
|
+
export declare function createNativeTestClusterDatabaseBroker(readFallback: () => NativeTestPostgresFallback | null, stateRoot: string): AttemptDatabaseBroker | null;
|
|
88
|
+
/** The exact strings to redact wherever a capability may be printed: the whole value and its password. */
|
|
89
|
+
export declare function attemptDatabaseCapabilitySecrets(capability: string | undefined): readonly string[];
|