@loucompanion/forge-bridge 0.1.4-dev.bfa11ebe98c6 → 0.1.4-dev.c03d3c89ec4a

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.
Files changed (174) hide show
  1. package/README.md +45 -3
  2. package/dist/bridge/bridge.base.d.ts +9 -0
  3. package/dist/bridge/bridge.service.d.ts +84 -2
  4. package/dist/bridge/bridge.service.js +358 -12
  5. package/dist/bridge/bridge.types.d.ts +22 -0
  6. package/dist/bridge/dispatch-result-outbox.d.ts +11 -1
  7. package/dist/bridge/dispatch-result-outbox.js +31 -6
  8. package/dist/bridge/local-yield-flag.d.ts +6 -0
  9. package/dist/bridge/local-yield-flag.js +34 -0
  10. package/dist/bridge/runner-host-capabilities.d.ts +2 -0
  11. package/dist/bridge/runner-host-capabilities.js +4 -0
  12. package/dist/bridge/test-postgres-capability.d.ts +14 -0
  13. package/dist/bridge/test-postgres-capability.js +120 -0
  14. package/dist/cleanup/cleanup.service.d.ts +9 -0
  15. package/dist/cleanup/cleanup.service.js +72 -109
  16. package/dist/cleanup/cleanup.types.d.ts +4 -0
  17. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  18. package/dist/cleanup/forge-owned-paths.js +53 -0
  19. package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
  20. package/dist/cleanup/host-runtime-ledger.js +109 -0
  21. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  22. package/dist/cleanup/managed-branch-sweep.js +111 -0
  23. package/dist/cli/cli.help.js +20 -2
  24. package/dist/cli/cli.service.d.ts +16 -0
  25. package/dist/cli/cli.service.js +142 -16
  26. package/dist/cli/local-config.d.ts +4 -0
  27. package/dist/cli/local-config.js +26 -4
  28. package/dist/runtime/aspnet-runtime-prebuild.js +94 -6
  29. package/dist/runtime/attempt-database-broker.d.ts +89 -0
  30. package/dist/runtime/attempt-database-broker.js +390 -0
  31. package/dist/runtime/attempt-process-supervisor.d.ts +24 -0
  32. package/dist/runtime/attempt-process-supervisor.js +77 -3
  33. package/dist/runtime/host-database-capability-boundary.d.ts +1 -1
  34. package/dist/runtime/host-database-capability-boundary.js +1 -0
  35. package/dist/runtime/host-diagnostics.js +4 -3
  36. package/dist/runtime/host-facts.d.ts +35 -0
  37. package/dist/runtime/host-facts.js +95 -0
  38. package/dist/runtime/host-load-admission.d.ts +60 -0
  39. package/dist/runtime/host-load-admission.js +99 -0
  40. package/dist/runtime/host-load-child-environment.d.ts +22 -0
  41. package/dist/runtime/host-load-child-environment.js +67 -0
  42. package/dist/runtime/host-load-forge-cgroups.d.ts +49 -0
  43. package/dist/runtime/host-load-forge-cgroups.js +140 -0
  44. package/dist/runtime/host-load-governor-config.d.ts +43 -0
  45. package/dist/runtime/host-load-governor-config.js +76 -0
  46. package/dist/runtime/host-load-governor.d.ts +174 -0
  47. package/dist/runtime/host-load-governor.js +541 -0
  48. package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
  49. package/dist/runtime/host-load-ledger-lock.js +185 -0
  50. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  51. package/dist/runtime/host-load-runtime-settings.js +78 -0
  52. package/dist/runtime/host-load-sampler.d.ts +126 -0
  53. package/dist/runtime/host-load-sampler.js +232 -0
  54. package/dist/runtime/host-load-step-class.d.ts +68 -0
  55. package/dist/runtime/host-load-step-class.js +106 -0
  56. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  57. package/dist/runtime/host-load-step-reaper.js +95 -0
  58. package/dist/runtime/host-load-step-run.d.ts +73 -0
  59. package/dist/runtime/host-load-step-run.js +102 -0
  60. package/dist/runtime/host-load-token-ledger.d.ts +174 -0
  61. package/dist/runtime/host-load-token-ledger.js +421 -0
  62. package/dist/runtime/host-pressure-stall.d.ts +61 -0
  63. package/dist/runtime/host-pressure-stall.js +168 -0
  64. package/dist/runtime/host-runtime-contract.d.ts +4 -0
  65. package/dist/runtime/host-runtime-contract.js +75 -11
  66. package/dist/runtime/host-runtime-lease.d.ts +76 -4
  67. package/dist/runtime/host-runtime-lease.js +386 -32
  68. package/dist/runtime/host-runtime-promotion.d.ts +23 -0
  69. package/dist/runtime/host-runtime-promotion.js +48 -0
  70. package/dist/runtime/host-runtime-requirements-check.d.ts +17 -0
  71. package/dist/runtime/host-runtime-requirements-check.js +29 -0
  72. package/dist/runtime/host-runtime-requirements.d.ts +36 -0
  73. package/dist/runtime/host-runtime-requirements.js +117 -0
  74. package/dist/runtime/managed-command-teardown.d.ts +62 -0
  75. package/dist/runtime/managed-command-teardown.js +607 -0
  76. package/dist/runtime/node-host-runtime-adapter.js +5 -4
  77. package/dist/runtime/playwright-browser-cache.d.ts +39 -0
  78. package/dist/runtime/playwright-browser-cache.js +227 -0
  79. package/dist/runtime/playwright-host-runtime-adapter.d.ts +18 -0
  80. package/dist/runtime/playwright-host-runtime-adapter.js +61 -55
  81. package/dist/runtime/runner-settings.d.ts +100 -0
  82. package/dist/runtime/runner-settings.js +214 -0
  83. package/dist/sandbox/host-capacity-broker.d.ts +107 -0
  84. package/dist/sandbox/host-capacity-broker.js +315 -0
  85. package/dist/sandbox/repository-lock.js +3 -2
  86. package/dist/sandbox/runtime.d.ts +10 -1
  87. package/dist/sandbox/runtime.js +50 -6
  88. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  89. package/dist/sandbox/sandbox-cgroups.js +42 -0
  90. package/dist/session/managed-attempt-tools.d.ts +27 -0
  91. package/dist/session/managed-attempt-tools.js +366 -45
  92. package/dist/session/managed-build-coordinator.d.ts +1 -1
  93. package/dist/session/managed-build-coordinator.js +8 -4
  94. package/dist/session/managed-command-host-load.d.ts +45 -0
  95. package/dist/session/managed-command-host-load.js +82 -0
  96. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  97. package/dist/session/mcp-argument-coercion.js +121 -0
  98. package/dist/session/phase-completion.artifacts.d.ts +7 -0
  99. package/dist/session/phase-completion.artifacts.js +98 -25
  100. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  101. package/dist/session/phase-completion.command-validation.js +77 -0
  102. package/dist/session/phase-completion.d.ts +4 -0
  103. package/dist/session/phase-completion.helpers.js +13 -12
  104. package/dist/session/phase-completion.js +4 -0
  105. package/dist/session/phase-completion.prompts.js +6 -1
  106. package/dist/session/phase-completion.runtime.d.ts +5 -3
  107. package/dist/session/phase-completion.runtime.js +78 -36
  108. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  109. package/dist/session/phase-completion.schema-parts.js +188 -0
  110. package/dist/session/phase-completion.schemas.d.ts +3 -3
  111. package/dist/session/phase-completion.schemas.js +206 -221
  112. package/dist/session/phase-completion.validation.d.ts +2 -3
  113. package/dist/session/phase-completion.validation.js +46 -92
  114. package/dist/session/pre-publication-host-load.d.ts +27 -0
  115. package/dist/session/pre-publication-host-load.js +111 -0
  116. package/dist/session/pre-publication-pass.d.ts +60 -0
  117. package/dist/session/pre-publication-pass.js +145 -0
  118. package/dist/session/pre-publication-process.d.ts +23 -0
  119. package/dist/session/pre-publication-process.js +109 -0
  120. package/dist/session/pre-publication-skipped-tests.d.ts +21 -0
  121. package/dist/session/pre-publication-skipped-tests.js +109 -0
  122. package/dist/session/pre-publication-step-execution.d.ts +11 -0
  123. package/dist/session/pre-publication-step-execution.js +49 -0
  124. package/dist/session/pre-publication-validation.d.ts +30 -20
  125. package/dist/session/pre-publication-validation.js +178 -193
  126. package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
  127. package/dist/session/provider-cli/pre-publication-repair.js +243 -0
  128. package/dist/session/provider-cli/provider-cli.artifacts.d.ts +2 -1
  129. package/dist/session/provider-cli/provider-cli.artifacts.js +21 -15
  130. package/dist/session/provider-cli/provider-cli.merge-integrity.d.ts +89 -0
  131. package/dist/session/provider-cli/provider-cli.merge-integrity.js +310 -0
  132. package/dist/session/provider-cli/provider-cli.process.d.ts +37 -1
  133. package/dist/session/provider-cli/provider-cli.process.js +299 -25
  134. package/dist/session/provider-cli/provider-cli.prompts.d.ts +7 -0
  135. package/dist/session/provider-cli/provider-cli.prompts.js +62 -9
  136. package/dist/session/provider-cli/provider-cli.runtime.d.ts +6 -0
  137. package/dist/session/provider-cli/provider-cli.runtime.js +14 -0
  138. package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
  139. package/dist/session/provider-cli/provider-cli.service.js +200 -162
  140. package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
  141. package/dist/session/provider-cli/provider-in-flight-work.d.ts +6 -0
  142. package/dist/session/provider-cli/provider-in-flight-work.js +47 -0
  143. package/dist/session/provider-cli/provider-output-state.d.ts +6 -0
  144. package/dist/session/provider-cli/provider-output-state.js +9 -0
  145. package/dist/session/provider-cli/provider-usage.d.ts +2 -1
  146. package/dist/session/publishable-worktree-changes.d.ts +54 -0
  147. package/dist/session/publishable-worktree-changes.js +193 -0
  148. package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
  149. package/dist/session/sandbox-host-capacity-gate.js +229 -0
  150. package/dist/session/session.base.d.ts +9 -1
  151. package/dist/session/session.service.d.ts +9 -2
  152. package/dist/session/session.service.js +120 -5
  153. package/dist/session/session.types.d.ts +3 -0
  154. package/dist/session/session.types.js +15 -3
  155. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  156. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  157. package/dist/shared/process/host-process-recovery.js +3 -2
  158. package/dist/shared/process/host-process-supervisor.d.ts +1 -0
  159. package/dist/shared/process/host-process-supervisor.js +6 -5
  160. package/dist/shared/process/process-tree.d.ts +52 -0
  161. package/dist/shared/process/process-tree.js +144 -0
  162. package/dist/shared/process/process.d.ts +67 -0
  163. package/dist/shared/process/process.js +213 -11
  164. package/dist/shared/provider-capabilities.js +5 -6
  165. package/dist/shared/time/monotonic.d.ts +1 -0
  166. package/dist/shared/time/monotonic.js +8 -0
  167. package/dist/version.d.ts +1 -1
  168. package/dist/version.js +1 -1
  169. package/dist/worktree/dependency-warmer.d.ts +25 -0
  170. package/dist/worktree/dependency-warmer.js +120 -10
  171. package/dist/worktree/worktree.service.d.ts +10 -1
  172. package/dist/worktree/worktree.service.js +42 -2
  173. package/dist/worktree/worktree.types.d.ts +7 -0
  174. package/package.json +2 -2
@@ -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,11 +13,16 @@ 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";
15
- import { HostRuntimeLeaseManager, } from "../runtime/host-runtime-lease.js";
16
+ import { FileForgeCgroupRegistry } from "../runtime/host-load-forge-cgroups.js";
17
+ import { hostCapacityLimitDefaults, HostRuntimeLeaseManager, } from "../runtime/host-runtime-lease.js";
18
+ import { computeEffectiveRunnerSettings, parseRunnerSettingsDocument, runnerSettingsInForce, sameRunnerSettingsReport, } from "../runtime/runner-settings.js";
19
+ import { resetHostLoadRuntimeSettings, writeHostLoadRuntimeSettings } from "../runtime/host-load-runtime-settings.js";
20
+ import { readLocalYieldFlag } from "./local-yield-flag.js";
16
21
  import { assertHostDatabaseCapabilityBoundary, establishHostDatabaseCapabilityBoundary, } from "../runtime/host-database-capability-boundary.js";
17
22
  import { defaultHostExecutionRoot } from "../runtime/host-execution-root.js";
18
23
  import { buildMemoryAdmissionDiagnostics } from "../runtime/memory-capacity.js";
19
24
  import { DockerEngineProbe } from "../runtime/docker-engine-probe.js";
25
+ import { createNativeTestClusterDatabaseBroker } from "../runtime/attempt-database-broker.js";
20
26
  import { readNativeTestPostgresFallback } from "../runtime/native-test-postgres-fallback.js";
21
27
  import { estimateWorkspaceBytesFromRepo } from "../runtime/workspace-resource-estimator.js";
22
28
  import { GitWorktreeService } from "../worktree/worktree.service.js";
@@ -32,8 +38,9 @@ import { codexSandboxProviderAuthAdapter, sandboxProviderAuthAdapterFor, sandbox
32
38
  import { assertBridgeChatCallbackPayload, bridgeChatMaxProviderThreadIdChars, bridgeChatProtocolVersion, isTerminalChatTurnCallbackKind, parseChatTurnDispatchPacket, } from "./bridge-chat.types.js";
33
39
  import { formatBytes } from "../shared/format/format-bytes.js";
34
40
  import { emptyRunnerHostCapabilitySnapshot, ProcessRunnerHostCapabilityProbe, } from "./runner-host-capabilities.js";
41
+ import { HostLoadSampler } from "../runtime/host-load-sampler.js";
35
42
  import { FileReadinessResultOutbox } from "./readiness-result-outbox.js";
36
- import { FileDispatchResultOutbox } from "./dispatch-result-outbox.js";
43
+ import { dispatchResultQuarantineDirectory, FileDispatchResultOutbox } from "./dispatch-result-outbox.js";
37
44
  /**
38
45
  * Protocol-v2 events are acknowledged one at a time before runOnce returns.
39
46
  * Sending the complete transcript again in DispatchResult made long QA and CI
@@ -52,6 +59,7 @@ export class ForgeBridgeService {
52
59
  connections;
53
60
  hostCapabilityProbe;
54
61
  chatProcessRunner;
62
+ hostLoad;
55
63
  connection = null;
56
64
  heartbeatTimer = null;
57
65
  heartbeatInFlight = false;
@@ -64,6 +72,7 @@ export class ForgeBridgeService {
64
72
  transportRecovery = null;
65
73
  transportRecoveryGeneration = 0;
66
74
  stopped = false;
75
+ revokedReason = null;
67
76
  activeSessions = new Map();
68
77
  reservations = new Map();
69
78
  activeReadinessProbes = new Map();
@@ -81,16 +90,46 @@ export class ForgeBridgeService {
81
90
  sessions;
82
91
  enforceHostDatabaseCapabilityBoundary;
83
92
  hostCapabilities = emptyRunnerHostCapabilitySnapshot();
93
+ dockerAvailable = false;
94
+ // Decision 0014 settings push. The last applied server document (null until one
95
+ // arrives: an old server never sends one), the local `forge-bridge yield` flag,
96
+ // and the effective settings computed from both and the host's env bounds.
97
+ appliedSettingsDocument = null;
98
+ localYield = false;
99
+ effectiveSettings;
100
+ settingsReport;
101
+ /** Applies run one at a time; offers wait for every apply queued before them. */
102
+ settingsTail = Promise.resolve();
103
+ // Server documents that turn yield on and are queued but not applied yet. The
104
+ // reservation commit is synchronous and can't wait for the apply, so it counts these.
105
+ pendingYieldOn = 0;
106
+ settingsStarted = null;
107
+ hostRequirementFacts() {
108
+ const facts = this.hostLoad.facts();
109
+ return {
110
+ logicalThreads: facts?.logicalThreads ?? os.cpus().length,
111
+ totalMemoryBytes: facts?.totalMemoryBytes ?? os.totalmem(),
112
+ availableToolchains: Object.entries(this.hostCapabilities.toolchains)
113
+ .filter(([, tool]) => tool?.available === true)
114
+ .map(([name]) => name),
115
+ dockerAvailable: this.dockerAvailable,
116
+ browserLaunch: this.hostCapabilities.browserLaunch,
117
+ testPostgresSuperuser: this.hostCapabilities.testPostgres.superuser,
118
+ };
119
+ }
84
120
  // Reaping deletes the stale ledger, so its stopped-process proof is held here
85
121
  // until a Hello carrying it is accepted. A bridge restart forgets it, which
86
122
  // leaves those attempts on Forge's conservative unknown-outcome path.
87
123
  recoveredHostAttempts = new Map();
88
124
  hostCapabilitiesDetected = false;
89
- constructor(config, sessions = undefined, connections = new SignalRBridgeConnectionFactory(), preflight, sandboxRuntime, sandboxResourceResolver, dockerEngineProbe, hostCapabilityProbe = new ProcessRunnerHostCapabilityProbe(), readinessResultOutbox, chatProcessRunner = new StreamingProviderProcessRunner(), dispatchResultOutbox) {
125
+ constructor(config, sessions = undefined, connections = new SignalRBridgeConnectionFactory(), preflight, sandboxRuntime, sandboxResourceResolver, dockerEngineProbe, hostCapabilityProbe = new ProcessRunnerHostCapabilityProbe(), readinessResultOutbox, chatProcessRunner = new StreamingProviderProcessRunner(), dispatchResultOutbox,
126
+ // Reads the Docker sandbox cgroups the sandbox runtime registers on the same state root.
127
+ hostLoad = new HostLoadSampler({ forgeCgroups: new FileForgeCgroupRegistry(config.sandboxStateRoot) })) {
90
128
  this.config = config;
91
129
  this.connections = connections;
92
130
  this.hostCapabilityProbe = hostCapabilityProbe;
93
131
  this.chatProcessRunner = chatProcessRunner;
132
+ this.hostLoad = hostLoad;
94
133
  this.enforceHostDatabaseCapabilityBoundary = sessions === undefined;
95
134
  if (this.enforceHostDatabaseCapabilityBoundary) {
96
135
  establishHostDatabaseCapabilityBoundary();
@@ -122,14 +161,22 @@ export class ForgeBridgeService {
122
161
  },
123
162
  onStatus: logBridgeStatus,
124
163
  });
125
- this.sessions = sessions ?? createDefaultSessionService(config.sandboxStateRoot, config.sandboxExecutionRoot, this.dockerEngineProbe);
126
- this.sandboxRuntime = sandboxRuntime ?? new DockerSandboxRuntime(config, (request, signal) => this.redeemPublishGrant(request, signal));
164
+ const defaultSessions = sessions ? null : createDefaultSessionService(config.sandboxStateRoot, config.sandboxExecutionRoot, this.dockerEngineProbe, hostLoad);
165
+ this.sessions = sessions ?? defaultSessions.sessions;
166
+ // Docker sandboxes ask the same host load governor for their validation tokens.
167
+ this.sandboxRuntime = sandboxRuntime ?? new DockerSandboxRuntime(config, (request, signal) => this.redeemPublishGrant(request, signal), defaultSessions?.hostLoadGovernor);
127
168
  this.sandboxResourceResolver = sandboxResourceResolver
128
169
  ?? (dispatch => resolveSandboxResourcesFromRepo(dispatch, this.config.sandboxRuntimeOverheadBytes));
129
170
  this.readinessResultOutbox = readinessResultOutbox ?? new FileReadinessResultOutbox(config.sandboxStateRoot);
130
171
  this.dispatchResultOutbox = dispatchResultOutbox ?? new FileDispatchResultOutbox(config.sandboxStateRoot);
172
+ // With no server document and no local flag these equal today's env/default behaviour.
173
+ this.effectiveSettings = computeEffectiveRunnerSettings(null, process.env, this.runnerHostDefaults(), false);
174
+ this.settingsReport = this.effectiveSettings.report;
131
175
  }
132
176
  async connectOnce() {
177
+ if (this.revokedReason !== null) {
178
+ throw new BridgeRevokedError(this.revokedReason);
179
+ }
133
180
  await this.stopConnection();
134
181
  this.stopped = false;
135
182
  if (this.enforceHostDatabaseCapabilityBoundary) {
@@ -155,6 +202,11 @@ export class ForgeBridgeService {
155
202
  this.hostCapabilities = await this.hostCapabilityProbe.detect(this.config);
156
203
  this.hostCapabilitiesDetected = true;
157
204
  }
205
+ // Static host facts and the first load sample ride on Hello; the sampler
206
+ // keeps refreshing its cached snapshot for later heartbeats.
207
+ await this.hostLoad.start().catch(() => undefined);
208
+ this.sessions.setHostRequirementsCheck?.(requires => unmetHostRuntimeRequirements(requires, this.hostRequirementFacts()));
209
+ await this.startSettings();
158
210
  const connection = this.connections.create(this.config);
159
211
  this.connection = connection;
160
212
  this.transportRecovery = null;
@@ -204,6 +256,8 @@ export class ForgeBridgeService {
204
256
  connection.onCancel((request) => this.handleCancel(request));
205
257
  connection.onReap?.((request) => this.handleReap(request));
206
258
  connection.onReadinessProbe?.((request) => this.handleReadinessProbe(request));
259
+ connection.onRevoked?.((notice) => this.handleRevoked(notice));
260
+ connection.onApplySettings?.((document) => this.handleApplySettings(document));
207
261
  await connection.start();
208
262
  await this.registerConnection(connection);
209
263
  await this.flushDispatchResults(true).catch(error => {
@@ -282,7 +336,7 @@ export class ForgeBridgeService {
282
336
  }
283
337
  }
284
338
  catch (error) {
285
- if (this.stopped || signal?.aborted) {
339
+ if (this.stopped || signal?.aborted || this.revokedReason !== null) {
286
340
  break;
287
341
  }
288
342
  const backoff = this.config.reconnectBackoffMs[Math.min(attempt, this.config.reconnectBackoffMs.length - 1)] ?? 5000;
@@ -299,12 +353,201 @@ export class ForgeBridgeService {
299
353
  }
300
354
  await this.stopConnection();
301
355
  }
356
+ if (this.revokedReason !== null) {
357
+ throw new BridgeRevokedError(this.revokedReason);
358
+ }
359
+ }
360
+ /** The reason Forge gave when it removed this runner, or null while it is paired. */
361
+ get revoked() {
362
+ return this.revokedReason;
363
+ }
364
+ /**
365
+ * Decision 0014 §3 "Remove": Forge removed this runner. Stop for good instead of
366
+ * reconnecting; its attempts were already settled on the server, so local work is
367
+ * aborted rather than reported.
368
+ */
369
+ handleRevoked(notice) {
370
+ if (this.revokedReason !== null)
371
+ return;
372
+ const reason = typeof notice?.reason === "string" && notice.reason.trim()
373
+ ? notice.reason.trim()
374
+ : bridgeRevokedMessage;
375
+ this.revokedReason = reason;
376
+ this.stopped = true;
377
+ logBridgeStatus(reason);
378
+ this.abortActiveSessions("runner removed from Forge");
379
+ this.abortActiveReadinessProbes("runner removed from Forge");
380
+ void this.stopConnection().catch(() => undefined);
381
+ }
382
+ /** The effective settings and how they were derived, as last reported (decision 0014). */
383
+ get runnerSettings() {
384
+ return this.settingsReport;
385
+ }
386
+ runnerHostDefaults() {
387
+ return this.sessions.runnerLimitDefaults?.() ?? hostCapacityLimitDefaults();
388
+ }
389
+ /**
390
+ * Once per bridge process: drop governor overrides an earlier process left on
391
+ * the state root, then put today's effective settings (env bounds and the local
392
+ * yield flag, no server document yet) in force.
393
+ */
394
+ async startSettings() {
395
+ this.settingsStarted ??= (async () => {
396
+ await resetHostLoadRuntimeSettings(this.config.sandboxStateRoot).catch(error => {
397
+ logBridgeStatus(`Could not reset the host load settings file: ${errorMessage(error)}.`);
398
+ });
399
+ this.localYield = await this.readLocalYield();
400
+ await this.enqueueSettings({ kind: "local" });
401
+ })();
402
+ await this.settingsStarted;
403
+ }
404
+ /**
405
+ * Decision 0014 `ApplySettings`. Applies only a document newer than the one
406
+ * applied, one at a time, then acknowledges it with `SettingsApplied`. A replay of
407
+ * the applied version is acknowledged again without applying it; an older one is
408
+ * ignored.
409
+ */
410
+ async handleApplySettings(raw) {
411
+ const document = parseRunnerSettingsDocument(raw);
412
+ if (!document) {
413
+ logBridgeStatus("Ignored an ApplySettings message without a valid settings version.");
414
+ return;
415
+ }
416
+ if (document.runnerId && document.runnerId !== this.config.runnerId) {
417
+ logBridgeStatus(`Ignored settings v${document.version} addressed to runner ${document.runnerId}.`);
418
+ return;
419
+ }
420
+ await this.enqueueSettings({ kind: "server", document });
421
+ }
422
+ /**
423
+ * Polls the local `forge-bridge yield` flag (every heartbeat and before each
424
+ * offer decision). A change is applied at once and reported again under the
425
+ * same settings version.
426
+ */
427
+ /** Yielding now, or about to: a received yield-on that is still being applied counts. */
428
+ yieldingOrQueued() {
429
+ return this.effectiveSettings.yielding || this.localYield || this.pendingYieldOn > 0;
430
+ }
431
+ async refreshLocalYield() {
432
+ if (!this.config.localYieldFlagPath)
433
+ return;
434
+ const localYield = await this.readLocalYield();
435
+ if (localYield === this.localYield)
436
+ return;
437
+ this.localYield = localYield;
438
+ logBridgeStatus(`Local yield to foreground turned ${localYield ? "on" : "off"} (forge-bridge yield).`);
439
+ await this.enqueueSettings({ kind: "local" });
440
+ }
441
+ /**
442
+ * A setting the host couldn't put in force holds placement on the server, so
443
+ * every heartbeat tries the applied document again until it takes.
444
+ */
445
+ async retryFailedSettings() {
446
+ if (!this.settingsReport.rejected.some(entry => entry.kind === "apply_failed"))
447
+ return;
448
+ await this.enqueueSettings({ kind: "local" });
449
+ }
450
+ async readLocalYield() {
451
+ const flagPath = this.config.localYieldFlagPath;
452
+ return flagPath ? await readLocalYieldFlag(flagPath) : false;
453
+ }
454
+ enqueueSettings(change) {
455
+ const turnsYieldOn = change.kind === "server" && change.document.yieldToForeground;
456
+ if (turnsYieldOn)
457
+ this.pendingYieldOn += 1;
458
+ const applied = this.settingsTail
459
+ .then(() => this.applySettings(change))
460
+ .finally(() => {
461
+ if (turnsYieldOn)
462
+ this.pendingYieldOn -= 1;
463
+ });
464
+ // A failed apply must not wedge later applies or the offers waiting on them.
465
+ this.settingsTail = applied.catch(error => {
466
+ logBridgeStatus(`Applying runner settings failed: ${errorMessage(error)}.`);
467
+ });
468
+ return this.settingsTail;
469
+ }
470
+ async applySettings(change) {
471
+ const applied = this.appliedSettingsDocument;
472
+ if (change.kind === "server" && applied !== null && change.document.version <= applied.version) {
473
+ if (change.document.version === applied.version) {
474
+ // The server sends the current version again at each Hello. After a reconnect it may never
475
+ // have seen this version's ack (the old connection dropped first), and its offer gate waits
476
+ // for one from this connection, so acknowledge what is in force again rather than nothing.
477
+ void this.sendSettingsApplied(this.settingsReport);
478
+ return;
479
+ }
480
+ logBridgeStatus(`Ignored runner settings v${change.document.version}; v${applied.version} is already applied.`);
481
+ return;
482
+ }
483
+ const document = change.kind === "server" ? change.document : applied;
484
+ const effective = computeEffectiveRunnerSettings(document, process.env, this.runnerHostDefaults(), this.localYield);
485
+ const failures = await this.putSettingsInForce(effective);
486
+ // Report what is in force: a key the host couldn't take keeps its previous value.
487
+ const report = {
488
+ ...runnerSettingsInForce(effective.report, this.settingsReport, failures),
489
+ version: document?.version ?? null,
490
+ };
491
+ const changed = !sameRunnerSettingsReport(report, this.settingsReport);
492
+ this.appliedSettingsDocument = document;
493
+ this.effectiveSettings = effective;
494
+ this.settingsReport = report;
495
+ if (change.kind === "server") {
496
+ logBridgeStatus(`Applied runner settings v${change.document.version}: ${describeRunnerSettings(report)}.`);
497
+ }
498
+ // Only a server that has sent ApplySettings knows SettingsApplied; an old one learns nothing new.
499
+ if (this.appliedSettingsDocument !== null && (change.kind === "server" || changed)) {
500
+ void this.sendSettingsApplied(report);
501
+ }
502
+ }
503
+ /**
504
+ * Max attempts and the memory reserve go to host attempt admission; the governor
505
+ * budget (the yield budget while yielding) and the heavy-step limit go to the
506
+ * shared settings file every governor on the state root reads at admission.
507
+ * Neither touches admitted work. Returns the keys the host could not put in
508
+ * force (`apply_failed`); their previous values stay in force.
509
+ */
510
+ async putSettingsInForce(effective) {
511
+ const { values } = effective.report;
512
+ const rejected = [];
513
+ try {
514
+ await this.sessions.applyRunnerLimits?.({
515
+ maxConcurrentAttempts: values.maxConcurrentAttempts,
516
+ memoryReserveBytes: values.memoryReserveBytes,
517
+ });
518
+ }
519
+ catch (error) {
520
+ const reason = `host attempt admission did not take the limit: ${errorMessage(error)}`;
521
+ rejected.push({ key: "maxConcurrentAttempts", reason, kind: "apply_failed" }, { key: "memoryReserveBytes", reason, kind: "apply_failed" });
522
+ }
523
+ try {
524
+ await writeHostLoadRuntimeSettings(this.config.sandboxStateRoot, {
525
+ cpuBudgetFraction: effective.governorCpuBudgetFraction,
526
+ maxHeavySteps: values.maxHeavySteps,
527
+ yielding: effective.yielding,
528
+ });
529
+ }
530
+ catch (error) {
531
+ const reason = `the host load governor settings could not be written: ${errorMessage(error)}`;
532
+ rejected.push({ key: "cpuBudgetPercent", reason, kind: "apply_failed" }, { key: "yieldCpuBudgetPercent", reason, kind: "apply_failed" }, { key: "maxHeavySteps", reason, kind: "apply_failed" });
533
+ }
534
+ return rejected;
535
+ }
536
+ /** A failed acknowledgement is not retried here: the next heartbeat carries the same report. */
537
+ async sendSettingsApplied(report) {
538
+ try {
539
+ await this.invokeAck("SettingsApplied", report);
540
+ }
541
+ catch (error) {
542
+ logBridgeStatus(`SettingsApplied for v${report.version ?? "none"} was not acknowledged: ${errorMessage(error)}. The next heartbeat reports it.`);
543
+ }
302
544
  }
303
545
  async stop() {
304
546
  this.stopped = true;
305
547
  this.abortActiveSessions("bridge stopping");
306
548
  this.abortActiveReadinessProbes("bridge stopping");
307
549
  await this.stopConnection();
550
+ this.hostLoad.stop();
308
551
  await this.preflight.release();
309
552
  }
310
553
  async handleChatTurn(rawDispatch) {
@@ -832,6 +1075,16 @@ export class ForgeBridgeService {
832
1075
  await this.sendOfferDecision(dispatch, false, "lease_expired", "Offer lease is already expired.");
833
1076
  return;
834
1077
  }
1078
+ // Decision 0014: decide under the settings Forge sent (an offer never races an
1079
+ // apply), and refuse new work while yielding to the foreground. The local flag
1080
+ // is read here too, before Forge has heard about it.
1081
+ await this.refreshLocalYield().catch(() => undefined);
1082
+ // Every apply queued so far, including one a concurrent offer or heartbeat started.
1083
+ await this.settingsTail;
1084
+ if (this.effectiveSettings.yielding) {
1085
+ await this.sendOfferDecision(dispatch, false, "runner_yielding", runnerYieldingMessage(this.settingsReport));
1086
+ return;
1087
+ }
835
1088
  const preflight = sandbox.executionMode === "docker" && this.config.dockerEnabled
836
1089
  ? await this.preflight.run()
837
1090
  : this.preflight.current();
@@ -916,6 +1169,11 @@ export class ForgeBridgeService {
916
1169
  if (Date.parse(dispatch.lease.expiresAt) <= now) {
917
1170
  return rejectedOfferReservation("lease_expired", "Offer lease is already expired.");
918
1171
  }
1172
+ // Yield may have turned on while the offer was being profiled, including a
1173
+ // yield Forge sent or the local flag set that hasn't finished applying yet.
1174
+ if (this.yieldingOrQueued()) {
1175
+ return rejectedOfferReservation("runner_yielding", runnerYieldingMessage(this.settingsReport));
1176
+ }
919
1177
  if (sandbox.executionMode === "docker") {
920
1178
  // A concurrent heartbeat/preflight refresh may have produced a newer
921
1179
  // conservative dual-domain sample while this offer was being profiled.
@@ -1467,6 +1725,19 @@ export class ForgeBridgeService {
1467
1725
  await this.dispatchResultOutbox.acknowledge(pending.payload.leaseId);
1468
1726
  continue;
1469
1727
  }
1728
+ if (this.isReplacedRunnerInstanceResult(pending.payload, error)) {
1729
+ try {
1730
+ await this.dispatchResultOutbox.quarantine(pending);
1731
+ }
1732
+ catch (quarantineError) {
1733
+ // Keep the record and surface Forge's rejection: replay stays
1734
+ // deferred and a heartbeat tick does not count it as a failure.
1735
+ logBridgeStatus(`Dispatch result ${pending.payload.leaseId} from replaced runner instance ${pending.payload.runnerInstanceId} could not be quarantined: ${errorMessage(quarantineError)}`);
1736
+ throw error;
1737
+ }
1738
+ 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.`);
1739
+ continue;
1740
+ }
1470
1741
  throw error;
1471
1742
  }
1472
1743
  }
@@ -1477,6 +1748,20 @@ export class ForgeBridgeService {
1477
1748
  this.dispatchResultFlushedGeneration = startedGeneration;
1478
1749
  }
1479
1750
  }
1751
+ /**
1752
+ * Forge binds each result to the runner instance that ran the attempt. On an
1753
+ * authoritative connection it rejects another instance's result with
1754
+ * bridge.stale_result_instance; Forge's own recovery handles that attempt,
1755
+ * so the record can never be delivered and must not block the replay queue.
1756
+ * bridge.stale_runner_instance means this connection is not authoritative
1757
+ * and says nothing about the record, so it never quarantines.
1758
+ */
1759
+ isReplacedRunnerInstanceResult(payload, error) {
1760
+ return error instanceof BridgeCallbackRejectedError
1761
+ && error.code === "bridge.stale_result_instance"
1762
+ && typeof payload.runnerInstanceId === "string"
1763
+ && payload.runnerInstanceId.toLowerCase() !== this.config.runnerInstanceId.toLowerCase();
1764
+ }
1480
1765
  startHeartbeat() {
1481
1766
  this.stopHeartbeat();
1482
1767
  this.consecutiveHeartbeatFailures = 0;
@@ -1495,8 +1780,14 @@ export class ForgeBridgeService {
1495
1780
  return;
1496
1781
  this.heartbeatInFlight = true;
1497
1782
  try {
1498
- await this.flushDispatchResults();
1499
- await this.flushReadinessResults();
1783
+ // A rejected replay is an answer from Forge, so the connection is alive:
1784
+ // an undeliverable record must not count as a heartbeat failure and
1785
+ // force reconnects. Transport failures still do.
1786
+ await this.flushDispatchResults().catch(deferRejectedReplay("Dispatch"));
1787
+ await this.flushReadinessResults().catch(deferRejectedReplay("Readiness"));
1788
+ // The heartbeat carries the effective settings, so pick up `forge-bridge yield` first.
1789
+ await this.refreshLocalYield().catch(() => undefined);
1790
+ await this.retryFailedSettings().catch(() => undefined);
1500
1791
  await this.sendHeartbeat();
1501
1792
  this.consecutiveHeartbeatFailures = 0;
1502
1793
  }
@@ -1639,6 +1930,7 @@ export class ForgeBridgeService {
1639
1930
  capabilities() {
1640
1931
  const preflight = this.preflight.current();
1641
1932
  const dockerEngine = this.dockerEngineProbe.current();
1933
+ this.dockerAvailable = dockerEngine?.available === true;
1642
1934
  const runtimeState = this.sandboxRuntime.snapshot();
1643
1935
  const reserved = [...this.reservations.values()].filter(reservation => reservation.sandboxed).length;
1644
1936
  const used = this.usedSandboxResources(runtimeState.degraded);
@@ -1655,7 +1947,7 @@ export class ForgeBridgeService {
1655
1947
  pendingCommitmentMemoryBytes: Math.max(0, used.memoryBytes - activeResources.memoryBytes),
1656
1948
  }) : null;
1657
1949
  return {
1658
- schemaVersion: 6,
1950
+ schemaVersion: 8,
1659
1951
  activeSessionCount: this.activeSessions.size,
1660
1952
  cliProviders: this.config.cliProviders,
1661
1953
  providerStatuses: this.config.providerStatuses,
@@ -1678,6 +1970,9 @@ export class ForgeBridgeService {
1678
1970
  playwrightProjects: this.hostCapabilities.playwrightProjects,
1679
1971
  browserLaunch: this.hostCapabilities.browserLaunch,
1680
1972
  providerConnectivity: this.hostCapabilities.providerConnectivity,
1973
+ testPostgres: this.hostCapabilities.testPostgres,
1974
+ host: this.hostLoad.facts(),
1975
+ load: this.hostLoad.current(),
1681
1976
  maxConcurrentSandboxes: capacity.sandboxSlots,
1682
1977
  reservedSandboxCount: reserved,
1683
1978
  activeSandboxCount: runtimeState.active,
@@ -1717,7 +2012,8 @@ export class ForgeBridgeService {
1717
2012
  supportsDraftRunOnce: this.config.supportsDraftRunOnce,
1718
2013
  supportsDraftAttachments: this.config.supportsDraftAttachments,
1719
2014
  supportsDraftImageAttachments: this.config.supportsDraftImageAttachments,
1720
- bridgeChat: bridgeChatCapabilityFor(this.config.cliProviders, this.config.providerStatuses, this.config.bridgeChat)
2015
+ bridgeChat: bridgeChatCapabilityFor(this.config.cliProviders, this.config.providerStatuses, this.config.bridgeChat),
2016
+ settings: { supportsServerSettings: true, ...this.settingsReport },
1721
2017
  };
1722
2018
  }
1723
2019
  async requiredCapabilityFailure(dispatch) {
@@ -1871,6 +2167,35 @@ export class ForgeBridgeService {
1871
2167
  }
1872
2168
  }
1873
2169
  }
2170
+ function runnerYieldingMessage(report) {
2171
+ const where = report.sources.yieldToForeground === "host_local" ? "on this host (forge-bridge yield on)" : "in Forge";
2172
+ return `runner_yielding: this runner is yielding to foreground work (turned on ${where}); it takes no new attempts until yield is off. Running attempts continue.`;
2173
+ }
2174
+ function describeRunnerSettings(report) {
2175
+ const { values } = report;
2176
+ const parts = [
2177
+ `max attempts ${values.maxConcurrentAttempts}`,
2178
+ `CPU budget ${values.cpuBudgetPercent}%`,
2179
+ `yield budget ${values.yieldCpuBudgetPercent}%`,
2180
+ `memory reserve ${formatBytes(values.memoryReserveBytes)}`,
2181
+ `heavy steps ${values.maxHeavySteps ?? "budget only"}`,
2182
+ `yield ${values.yieldToForeground ? "on" : "off"}`,
2183
+ ];
2184
+ const capped = report.bounds
2185
+ .filter(bound => report.sources[bound.key] === "host_env")
2186
+ .map(bound => `${bound.envVar}=${bound.value}`);
2187
+ return `${parts.join(", ")}${capped.length > 0 ? `; host bounds in force: ${[...new Set(capped)].join(", ")}` : ""}`;
2188
+ }
2189
+ /** The `run` command's exit code after Forge removed the runner. */
2190
+ export const bridgeRevokedExitCode = 3;
2191
+ export const bridgeRevokedMessage = "This bridge was removed from Forge. Pair it again with forge-bridge pair.";
2192
+ /** Thrown by `run` after Forge removed the runner, so the CLI exits instead of reconnecting. */
2193
+ export class BridgeRevokedError extends Error {
2194
+ constructor(message = bridgeRevokedMessage) {
2195
+ super(message);
2196
+ this.name = "BridgeRevokedError";
2197
+ }
2198
+ }
1874
2199
  class BridgeCallbackRejectedError extends Error {
1875
2200
  code;
1876
2201
  constructor(code, message) {
@@ -1879,6 +2204,13 @@ class BridgeCallbackRejectedError extends Error {
1879
2204
  this.name = "BridgeCallbackRejectedError";
1880
2205
  }
1881
2206
  }
2207
+ function deferRejectedReplay(kind) {
2208
+ return error => {
2209
+ if (!(error instanceof BridgeCallbackRejectedError))
2210
+ throw error;
2211
+ logBridgeStatus(`${kind} result replay deferred: ${errorMessage(error)}`);
2212
+ };
2213
+ }
1882
2214
  function isDispatchNoLongerPending(error) {
1883
2215
  if (error instanceof BridgeCallbackRejectedError) {
1884
2216
  return error.code === "bridge.dispatch_not_pending" || error.code === "bridge.stale_dispatch";
@@ -1897,11 +2229,13 @@ function isProviderStorageUnavailable(error) {
1897
2229
  function isBridgeCallbackTimeout(error) {
1898
2230
  return errorMessage(error).startsWith("bridge_callback_timeout:");
1899
2231
  }
1900
- function createDefaultSessionService(sandboxStateRoot, sandboxExecutionRoot, dockerEngineProbe) {
2232
+ function createDefaultSessionService(sandboxStateRoot, sandboxExecutionRoot, dockerEngineProbe, hostLoad) {
1901
2233
  const rawProcessRunner = new StreamingProviderProcessRunner();
1902
2234
  const processSupervisors = new AttemptProcessSupervisorRegistry();
1903
2235
  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));
2236
+ const hostRuntime = new HostRuntimeLeaseManager(sandboxStateRoot, undefined, undefined, processSupervisors, rawProcessRunner, undefined, undefined, undefined, undefined, undefined, sandboxExecutionRoot, createNativeTestClusterDatabaseBroker(readNativeTestPostgresFallback, sandboxStateRoot), hostLoad);
2237
+ 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);
2238
+ return { sessions, hostLoadGovernor: hostRuntime.hostLoadGovernor };
1905
2239
  }
1906
2240
  export class SignalRBridgeConnectionFactory {
1907
2241
  create(config) {
@@ -1932,6 +2266,18 @@ export class SignalRBridgeConnection {
1932
2266
  void this.connection.stop().catch(() => undefined);
1933
2267
  });
1934
2268
  }
2269
+ onApplySettings(handler) {
2270
+ this.connection.on("ApplySettings", (raw) => {
2271
+ void Promise.resolve(handler(raw)).catch(() => undefined);
2272
+ });
2273
+ }
2274
+ onRevoked(handler) {
2275
+ this.connection.on("Revoked", (raw) => {
2276
+ const notice = raw && typeof raw === "object" ? raw : {};
2277
+ handler(notice);
2278
+ void this.connection.stop().catch(() => undefined);
2279
+ });
2280
+ }
1935
2281
  start() {
1936
2282
  return this.connection.start();
1937
2283
  }
@@ -1,8 +1,13 @@
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";
10
+ import type { RunnerSettingsReport } from "../runtime/runner-settings.js";
6
11
  import type { BridgeChatCapability, ChatTurnCancelPacket } from "./bridge-chat.types.js";
7
12
  export interface BridgeServiceConfig {
8
13
  readonly serverUrl: string;
@@ -61,6 +66,11 @@ export interface BridgeServiceConfig {
61
66
  readonly callbackAckTimeoutMs?: number;
62
67
  readonly heartbeatDockerProbeWaitMs?: number;
63
68
  readonly reconnectBackoffMs: readonly number[];
69
+ /**
70
+ * Decision 0014: the `forge-bridge yield` flag file next to the bridge config,
71
+ * polled while running. Null or absent: no local yield flag.
72
+ */
73
+ readonly localYieldFlagPath?: string | null;
64
74
  }
65
75
  export interface BridgeRepoMapping {
66
76
  readonly repoId?: string | null;
@@ -142,6 +152,17 @@ export interface BridgeCapabilities {
142
152
  readonly playwrightProjects?: readonly string[] | null;
143
153
  readonly browserLaunch?: boolean | null;
144
154
  readonly providerConnectivity?: Readonly<Record<string, boolean>> | null;
155
+ /** Native test PostgreSQL and whether its role is a superuser (decision 0013 placement). */
156
+ readonly testPostgres?: BridgeTestPostgresCapability | null;
157
+ /** Static host hardware facts (schema 7). Material: changes are persisted immediately. */
158
+ readonly host?: HostFacts | null;
159
+ /** Live host load sample (schema 7). Never material: heartbeats with only load changes are not persisted. */
160
+ readonly load?: HostLoadSnapshot | null;
161
+ /** Decision 0014 (schema 8): server settings support and the last `SettingsApplied` report. Material. */
162
+ readonly settings?: BridgeSettingsCapability | null;
163
+ }
164
+ export interface BridgeSettingsCapability extends RunnerSettingsReport {
165
+ readonly supportsServerSettings: true;
145
166
  }
146
167
  export interface SandboxMemoryCapacityDiagnostics {
147
168
  readonly defaultWorkerMemoryLimitBytes: number;
@@ -292,6 +313,7 @@ export interface BridgeRuntimeReadinessResult {
292
313
  readonly status: "parallel_ready" | "serialized" | "failed";
293
314
  readonly runtimeContractFingerprint?: string | null;
294
315
  readonly runtimeContractSource?: string | null;
316
+ readonly runtimeRequirements?: HostRuntimeRequirements | null;
295
317
  readonly reasonCode?: string | null;
296
318
  readonly reasonMessage?: string | null;
297
319
  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
  }