@loucompanion/forge-bridge 0.1.4-dev.8f4846c6e7a9 → 0.1.4-dev.93045aceba29

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 (109) hide show
  1. package/README.md +33 -0
  2. package/dist/bridge/bridge.base.d.ts +9 -0
  3. package/dist/bridge/bridge.service.d.ts +70 -1
  4. package/dist/bridge/bridge.service.js +288 -8
  5. package/dist/bridge/bridge.types.d.ts +11 -0
  6. package/dist/bridge/local-yield-flag.d.ts +6 -0
  7. package/dist/bridge/local-yield-flag.js +34 -0
  8. package/dist/cleanup/cleanup.service.d.ts +9 -0
  9. package/dist/cleanup/cleanup.service.js +72 -109
  10. package/dist/cleanup/cleanup.types.d.ts +4 -0
  11. package/dist/cleanup/forge-owned-paths.d.ts +9 -0
  12. package/dist/cleanup/forge-owned-paths.js +53 -0
  13. package/dist/cleanup/host-runtime-ledger.d.ts +5 -0
  14. package/dist/cleanup/host-runtime-ledger.js +109 -0
  15. package/dist/cleanup/managed-branch-sweep.d.ts +27 -0
  16. package/dist/cleanup/managed-branch-sweep.js +111 -0
  17. package/dist/cli/cli.help.js +18 -0
  18. package/dist/cli/cli.service.d.ts +16 -0
  19. package/dist/cli/cli.service.js +140 -16
  20. package/dist/cli/local-config.d.ts +4 -0
  21. package/dist/cli/local-config.js +26 -4
  22. package/dist/runtime/aspnet-runtime-prebuild.js +94 -6
  23. package/dist/runtime/host-load-admission.d.ts +9 -1
  24. package/dist/runtime/host-load-admission.js +19 -4
  25. package/dist/runtime/host-load-child-environment.d.ts +22 -0
  26. package/dist/runtime/host-load-child-environment.js +67 -0
  27. package/dist/runtime/host-load-forge-cgroups.d.ts +41 -0
  28. package/dist/runtime/host-load-forge-cgroups.js +93 -4
  29. package/dist/runtime/host-load-governor-config.d.ts +9 -0
  30. package/dist/runtime/host-load-governor-config.js +30 -0
  31. package/dist/runtime/host-load-governor.d.ts +62 -11
  32. package/dist/runtime/host-load-governor.js +168 -42
  33. package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
  34. package/dist/runtime/host-load-runtime-settings.js +78 -0
  35. package/dist/runtime/host-load-sampler.d.ts +5 -0
  36. package/dist/runtime/host-load-sampler.js +12 -4
  37. package/dist/runtime/host-load-step-class.d.ts +35 -0
  38. package/dist/runtime/host-load-step-class.js +60 -0
  39. package/dist/runtime/host-load-step-reaper.d.ts +27 -0
  40. package/dist/runtime/host-load-step-reaper.js +95 -0
  41. package/dist/runtime/host-load-step-run.d.ts +73 -0
  42. package/dist/runtime/host-load-step-run.js +102 -0
  43. package/dist/runtime/host-load-token-ledger.d.ts +58 -19
  44. package/dist/runtime/host-load-token-ledger.js +111 -35
  45. package/dist/runtime/host-runtime-lease.d.ts +61 -2
  46. package/dist/runtime/host-runtime-lease.js +255 -11
  47. package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
  48. package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
  49. package/dist/runtime/runner-settings.d.ts +100 -0
  50. package/dist/runtime/runner-settings.js +214 -0
  51. package/dist/sandbox/host-capacity-broker.d.ts +107 -0
  52. package/dist/sandbox/host-capacity-broker.js +315 -0
  53. package/dist/sandbox/runtime.d.ts +10 -1
  54. package/dist/sandbox/runtime.js +45 -2
  55. package/dist/sandbox/sandbox-cgroups.d.ts +14 -0
  56. package/dist/sandbox/sandbox-cgroups.js +42 -0
  57. package/dist/session/managed-attempt-tools.d.ts +2 -0
  58. package/dist/session/managed-attempt-tools.js +156 -37
  59. package/dist/session/managed-command-host-load.d.ts +45 -0
  60. package/dist/session/managed-command-host-load.js +82 -0
  61. package/dist/session/mcp-argument-coercion.d.ts +23 -0
  62. package/dist/session/mcp-argument-coercion.js +121 -0
  63. package/dist/session/phase-completion.artifacts.d.ts +7 -0
  64. package/dist/session/phase-completion.artifacts.js +94 -25
  65. package/dist/session/phase-completion.command-validation.d.ts +7 -0
  66. package/dist/session/phase-completion.command-validation.js +77 -0
  67. package/dist/session/phase-completion.d.ts +4 -0
  68. package/dist/session/phase-completion.helpers.js +13 -12
  69. package/dist/session/phase-completion.js +4 -0
  70. package/dist/session/phase-completion.prompts.js +6 -1
  71. package/dist/session/phase-completion.runtime.d.ts +5 -3
  72. package/dist/session/phase-completion.runtime.js +49 -19
  73. package/dist/session/phase-completion.schema-parts.d.ts +19 -0
  74. package/dist/session/phase-completion.schema-parts.js +188 -0
  75. package/dist/session/phase-completion.schemas.d.ts +3 -3
  76. package/dist/session/phase-completion.schemas.js +184 -209
  77. package/dist/session/phase-completion.validation.d.ts +2 -3
  78. package/dist/session/phase-completion.validation.js +46 -92
  79. package/dist/session/pre-publication-host-load.js +31 -16
  80. package/dist/session/pre-publication-process.d.ts +3 -0
  81. package/dist/session/pre-publication-process.js +23 -11
  82. package/dist/session/pre-publication-validation.js +4 -0
  83. package/dist/session/provider-cli/provider-cli.process.js +2 -2
  84. package/dist/session/provider-cli/provider-cli.prompts.js +5 -2
  85. package/dist/session/provider-cli/provider-cli.service.d.ts +6 -0
  86. package/dist/session/provider-cli/provider-cli.service.js +123 -15
  87. package/dist/session/provider-cli/provider-cli.types.d.ts +30 -0
  88. package/dist/session/sandbox-host-capacity-gate.d.ts +30 -0
  89. package/dist/session/sandbox-host-capacity-gate.js +229 -0
  90. package/dist/session/session.base.d.ts +6 -1
  91. package/dist/session/session.service.d.ts +7 -2
  92. package/dist/session/session.service.js +115 -5
  93. package/dist/session/session.types.js +2 -2
  94. package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
  95. package/dist/session/workspace-runtime-fingerprint.js +138 -0
  96. package/dist/shared/process/host-process-supervisor.d.ts +1 -0
  97. package/dist/shared/process/host-process-supervisor.js +1 -1
  98. package/dist/shared/process/process-tree.d.ts +52 -0
  99. package/dist/shared/process/process-tree.js +144 -0
  100. package/dist/shared/process/process.d.ts +67 -0
  101. package/dist/shared/process/process.js +213 -11
  102. package/dist/version.d.ts +1 -1
  103. package/dist/version.js +1 -1
  104. package/dist/worktree/dependency-warmer.d.ts +25 -0
  105. package/dist/worktree/dependency-warmer.js +46 -10
  106. package/dist/worktree/worktree.service.d.ts +10 -1
  107. package/dist/worktree/worktree.service.js +42 -2
  108. package/dist/worktree/worktree.types.d.ts +7 -0
  109. package/package.json +2 -2
@@ -15,6 +15,7 @@ import { HostParallelPromotionStore } from "./host-runtime-promotion.js";
15
15
  import { type HostProcessRecovery } from "../shared/process/host-process-recovery.js";
16
16
  import { HostLoadGovernor } from "./host-load-governor.js";
17
17
  import { type HostLoadGovernorSource } from "./host-load-sampler.js";
18
+ import type { RunnerHostDefaults } from "./runner-settings.js";
18
19
  export interface HostRuntimeLeaseStart {
19
20
  readonly lease: RuntimeIsolationLease;
20
21
  readonly environment: Readonly<Record<string, string>>;
@@ -28,7 +29,7 @@ export interface HostRuntimeAdmissionCheckpoint {
28
29
  }
29
30
  export type HostRuntimeAdmissionCheckpointHandler = (checkpoint: HostRuntimeAdmissionCheckpoint) => void | Promise<void>;
30
31
  export interface HostRuntimeProjectCheckpoint {
31
- readonly code: "host_runtime_build_started" | "host_runtime_build_cached" | "host_runtime_build_completed" | "host_runtime_database_provisioned";
32
+ readonly code: "host_runtime_build_started" | "host_runtime_build_waiting_for_host_capacity" | "host_runtime_build_cached" | "host_runtime_build_completed" | "host_runtime_database_provisioned";
32
33
  readonly message: string;
33
34
  readonly data?: Readonly<Record<string, unknown>>;
34
35
  }
@@ -96,10 +97,20 @@ export interface HostNodeRuntimeLaunch<T> extends NodeRuntimeAdapterLaunch<T> {
96
97
  }
97
98
  export interface HostRuntimeLeaseRuntime {
98
99
  setRequirementsCheck?(check: HostRequirementsCheck | null): void;
100
+ /** Decision 0014: today's max attempts and memory reserve defaults, before env bounds. */
101
+ capacityLimitDefaults?(): RunnerHostDefaults;
102
+ /** Decision 0014: the effective max attempts and memory reserve, from the next attempt admission. */
103
+ applyCapacityLimits?(limits: HostCapacityLimits): void;
99
104
  acquirePreparation?(dispatch: RunOnceDispatchPacket, signal?: AbortSignal): Promise<readonly string[]>;
100
105
  acquire(dispatch: RunOnceDispatchPacket, signal?: AbortSignal): Promise<readonly string[]>;
101
106
  start(dispatch: RunOnceDispatchPacket, worktreePath: string, signal?: AbortSignal, onAdmissionCheckpoint?: HostRuntimeAdmissionCheckpointHandler): Promise<HostRuntimeLeaseStart>;
102
107
  startConfiguredProject(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal, onProjectCheckpoint?: HostRuntimeProjectCheckpointHandler): Promise<HostRuntimeLeaseStart>;
108
+ /**
109
+ * Stops the attempt's configured project processes, releases their ports, and
110
+ * starts them again (rebuilding when sources changed) so the stack serves the
111
+ * current workspace. Returns the environment with the newly assigned URLs.
112
+ */
113
+ restartConfiguredProject?(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal, onProjectCheckpoint?: HostRuntimeProjectCheckpointHandler): Promise<HostRuntimeLeaseStart>;
103
114
  updateLease(dispatchAttemptId: string, fencingToken: string, expiresAt: string): Promise<void>;
104
115
  providerProcessRunner?(dispatchAttemptId: string, fencingToken: string): ProviderProcessRunner | null;
105
116
  providerMemoryTelemetry?(dispatchAttemptId: string, fencingToken: string): AttemptProcessTreeMemoryTelemetry | null;
@@ -108,6 +119,8 @@ export interface HostRuntimeLeaseRuntime {
108
119
  hasForegroundDemand?(): boolean;
109
120
  reap?(options: HostRuntimeReapOptions): Promise<HostRuntimeReapReport>;
110
121
  snapshot?(): HostRuntimeCapacitySnapshot;
122
+ /** Variables that let the completion MCP server share this host's load governor. */
123
+ hostLoadChildEnvironment?(): Readonly<Record<string, string>>;
111
124
  }
112
125
  export type HostRuntimeAdmissionPriority = "foreground" | "background";
113
126
  export interface HostCapacityResourceSample {
@@ -145,7 +158,8 @@ export declare class HostRuntimeLeaseManager implements HostRuntimeLeaseRuntime
145
158
  private workspaceAvailableBytes;
146
159
  private readonly portBroker;
147
160
  private readonly nodeAdapter;
148
- private readonly capacityConfiguration;
161
+ /** Rebuilt by applyCapacityLimits (decision 0014); every admission reads the current one. */
162
+ private capacityConfiguration;
149
163
  private readonly memoryAvailability;
150
164
  private readonly executionRoot;
151
165
  /** Host-wide admission for heavy steps (decision 0013); inert unless FORGE_HOST_LOAD_GOVERNOR=on. */
@@ -154,6 +168,16 @@ export declare class HostRuntimeLeaseManager implements HostRuntimeLeaseRuntime
154
168
  /** Installs the decision 0013 accept-time requirements recheck for host attempts. */
155
169
  setRequirementsCheck(check: HostRequirementsCheck | null): void;
156
170
  constructor(stateRoot: string, portBroker?: HostPortBroker, nodeAdapter?: NodeHostRuntimeAdapter, processSupervisors?: AttemptProcessSupervisorRegistry, processRunner?: ProviderProcessRunner, listenerInspector?: HostListenerInspector, promotionStore?: HostParallelPromotionStore, playwrightAdapter?: PlaywrightHostRuntimeAdapter, processRecovery?: HostProcessRecovery, capacityResourceSample?: HostCapacityResourceSample | undefined, executionRoot?: string, databaseBroker?: AttemptDatabaseBroker | null, hostLoad?: HostLoadGovernorSource | null);
171
+ /** Today's defaults for the limits the server can push, before any env bound (decision 0014). */
172
+ capacityLimitDefaults(): RunnerHostDefaults;
173
+ /**
174
+ * Decision 0014: the bridge's effective max attempts and memory reserve. They
175
+ * apply from the next attempt admission; admitted attempts keep their
176
+ * reservations and are never preempted, even when the new limit is lower than
177
+ * what already runs. The idle reserve follows the reserve as at startup.
178
+ */
179
+ applyCapacityLimits(limits: HostCapacityLimits): void;
180
+ hostLoadChildEnvironment(): Readonly<Record<string, string>>;
157
181
  reap(options: HostRuntimeReapOptions): Promise<HostRuntimeReapReport>;
158
182
  snapshot(): HostRuntimeCapacitySnapshot;
159
183
  hasForegroundDemand(): boolean;
@@ -175,6 +199,24 @@ export declare class HostRuntimeLeaseManager implements HostRuntimeLeaseRuntime
175
199
  start(dispatch: RunOnceDispatchPacket, worktreePath: string, signal?: AbortSignal, onAdmissionCheckpoint?: HostRuntimeAdmissionCheckpointHandler): Promise<HostRuntimeLeaseStart>;
176
200
  updateLease(dispatchAttemptId: string, fencingToken: string, expiresAt: string): Promise<void>;
177
201
  startConfiguredProject(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal, onProjectCheckpoint?: HostRuntimeProjectCheckpointHandler): Promise<HostRuntimeLeaseStart>;
202
+ /**
203
+ * Launches the configured project. Only the first launch, from the admitted commit's clean
204
+ * source, may record parallel-safety proof: a restart serves the workspace after the provider
205
+ * edited it, and a proof observed there would be stored under the admitted commit and could
206
+ * move this or a later attempt at that commit into shared admission for source it never ran.
207
+ */
208
+ private launchConfiguredProject;
209
+ /**
210
+ * Relaunches the configured project so it serves the current workspace. Every
211
+ * configured process stops (the API port changes, so the dev server's proxy target
212
+ * must change with it), its port reservation is released and dropped from the
213
+ * persisted lease, and the regular start path runs again, including the ASP.NET
214
+ * prebuild, whose receipt rebuilds only when the sources changed.
215
+ */
216
+ restartConfiguredProject(dispatchAttemptId: string, fencingToken: string, signal?: AbortSignal, onProjectCheckpoint?: HostRuntimeProjectCheckpointHandler): Promise<HostRuntimeLeaseStart>;
217
+ private runConfiguredProjectRestart;
218
+ /** Stops configured project processes in reverse launch order and releases their ports. */
219
+ private stopConfiguredProject;
178
220
  providerProcessRunner(dispatchAttemptId: string, fencingToken: string): ProviderProcessRunner | null;
179
221
  private markCapacityReservationRunning;
180
222
  providerMemoryTelemetry(dispatchAttemptId: string, fencingToken: string): AttemptProcessTreeMemoryTelemetry | null;
@@ -225,4 +267,21 @@ export declare class HostRuntimeCapacityRequestImpossibleError extends Error {
225
267
  }
226
268
  export declare function hostRuntimeEventResources(lease: RuntimeIsolationLease, runtimeContract?: LoadedHostRuntimeContract, executionClass?: HostRuntimeExecutionClass): Record<string, unknown>;
227
269
  export declare function hostRuntimeSingletonKeys(dispatch: RunOnceDispatchPacket): readonly string[];
270
+ /**
271
+ * Every environment key `hostRuntimeEnvironment` and the Playwright overlay derive from the
272
+ * configured project's assigned ports. They name a live stack, so they are withheld while the
273
+ * stack is down: after its ports are released another attempt may be assigned them.
274
+ */
275
+ export declare function hostRuntimeStackEnvironmentKeys(runtimeContract: LoadedHostRuntimeContract): readonly string[];
228
276
  export declare function runtimeAdmissionPriority(dispatch: RunOnceDispatchPacket): HostRuntimeAdmissionPriority;
277
+ /** The pushed attempt limits (decision 0014), already resolved against host env bounds. */
278
+ export interface HostCapacityLimits {
279
+ readonly maxConcurrentAttempts: number;
280
+ readonly memoryReserveBytes: number;
281
+ }
282
+ /**
283
+ * Today's max attempts and adaptive memory reserve for this host, before
284
+ * FORGE_HOST_MAX_CONCURRENT_ATTEMPTS and FORGE_HOST_MEMORY_RESERVE_BYTES
285
+ * (decision 0014 treats those as bounds on the server's values).
286
+ */
287
+ export declare function hostCapacityLimitDefaults(capacityResourceSample?: HostCapacityResourceSample): RunnerHostDefaults;
@@ -32,6 +32,9 @@ import { readPinnedSourceDirectory } from "./pinned-source-directory.js";
32
32
  import { architectMinimumWorkspaceEstimateBytes } from "./workspace-resource-estimator.js";
33
33
  import { createAspNetRuntimePrebuildPlan, ensureAspNetRuntimePrebuilt, resolveWorktreeCommitSha, } from "./aspnet-runtime-prebuild.js";
34
34
  import { HostLoadGovernor } from "./host-load-governor.js";
35
+ import { hostLoadChildEnvironment } from "./host-load-child-environment.js";
36
+ import { aspNetPrebuildStepClass } from "./host-load-step-class.js";
37
+ import { attachSupervisedStepProcess, runHostGovernedStep } from "./host-load-step-run.js";
35
38
  import { HostLoadSampler } from "./host-load-sampler.js";
36
39
  const hostCapacityWaiterScanLimit = 64;
37
40
  const maximumProcessRecoveryMetadataBytes = 1024 * 1024;
@@ -64,6 +67,7 @@ export class HostRuntimeLeaseManager {
64
67
  workspaceAvailableBytes = Number.MAX_SAFE_INTEGER;
65
68
  portBroker;
66
69
  nodeAdapter;
70
+ /** Rebuilt by applyCapacityLimits (decision 0014); every admission reads the current one. */
67
71
  capacityConfiguration;
68
72
  memoryAvailability;
69
73
  executionRoot;
@@ -94,6 +98,37 @@ export class HostRuntimeLeaseManager {
94
98
  this.capacityConfiguration = loadHostCapacityConfiguration(capacityResourceSample);
95
99
  this.memoryAvailability = new RecoveryStabilizedMemory(this.capacityConfiguration.memoryRecoverySamples, this.capacityConfiguration.memoryRecoverySampleIntervalMs);
96
100
  }
101
+ /** Today's defaults for the limits the server can push, before any env bound (decision 0014). */
102
+ capacityLimitDefaults() {
103
+ return {
104
+ maxConcurrentAttempts: this.capacityConfiguration.defaultHardMaxAttempts,
105
+ memoryReserveBytes: this.capacityConfiguration.adaptiveHostReserveBytes,
106
+ };
107
+ }
108
+ /**
109
+ * Decision 0014: the bridge's effective max attempts and memory reserve. They
110
+ * apply from the next attempt admission; admitted attempts keep their
111
+ * reservations and are never preempted, even when the new limit is lower than
112
+ * what already runs. The idle reserve follows the reserve as at startup.
113
+ */
114
+ applyCapacityLimits(limits) {
115
+ const current = this.capacityConfiguration;
116
+ const hardMaxAttempts = Math.max(1, Math.min(32, Math.floor(limits.maxConcurrentAttempts)));
117
+ const hostReserveBytes = Math.max(512 * 1024 ** 2, Math.floor(limits.memoryReserveBytes));
118
+ if (hardMaxAttempts === current.hardMaxAttempts && hostReserveBytes === current.hostReserveBytes)
119
+ return;
120
+ this.capacityConfiguration = {
121
+ ...current,
122
+ hardMaxAttempts,
123
+ hostReserveBytes,
124
+ idleHostReserveBytes: idleHostReserveBytesFor(hostReserveBytes, current),
125
+ };
126
+ // A raised limit may admit queued attempts now rather than at their next recheck.
127
+ this.drainAdmissionWaiters();
128
+ }
129
+ hostLoadChildEnvironment() {
130
+ return this.hostLoadGovernor.enabled ? hostLoadChildEnvironment(this.stateRoot) : {};
131
+ }
97
132
  async reap(options) {
98
133
  // Heavy-step tokens whose owner died or whose lease lapsed are returned first.
99
134
  await this.hostLoadGovernor.reclaim().catch(() => undefined);
@@ -221,6 +256,11 @@ export class HostRuntimeLeaseManager {
221
256
  // drop that met a lingering session) are removed once no live lease holds them.
222
257
  // A degraded lease may still own running processes after a restart, so its database is kept.
223
258
  await this.databaseBroker?.reapOrphans(id => this.active.has(id) || this.degraded.has(id)).catch(() => undefined);
259
+ // Heavy-step tokens of a dead owner with no recorded process tree (an attempt that
260
+ // ended with a crashed bridge or MCP server) are returned once no live lease holds
261
+ // their attempt; a degraded lease may still own the running step, so its tokens stay.
262
+ await this.hostLoadGovernor.releaseOrphaned(token => !token.dispatchAttemptId
263
+ || (!this.active.has(token.dispatchAttemptId) && !this.degraded.has(token.dispatchAttemptId))).catch(() => undefined);
224
264
  return report;
225
265
  }
226
266
  snapshot() {
@@ -1111,6 +1151,8 @@ export class HostRuntimeLeaseManager {
1111
1151
  parallelPromotionEligible: hostRuntimeParallelEligible(runtimeContract) && dispatch.cycleRun.phase !== "prepared_readiness",
1112
1152
  processSupervisor,
1113
1153
  adapterCleanups: [],
1154
+ adapterCleanupsByPort: new Map(),
1155
+ restartingConfiguredProject: false,
1114
1156
  pendingAdapterLaunches: new Map(),
1115
1157
  runtimeResourcesReleased: false,
1116
1158
  releasing: false,
@@ -1173,6 +1215,15 @@ export class HostRuntimeLeaseManager {
1173
1215
  await this.writeLedger(renewed);
1174
1216
  }
1175
1217
  async startConfiguredProject(dispatchAttemptId, fencingToken, signal, onProjectCheckpoint) {
1218
+ return await this.launchConfiguredProject(dispatchAttemptId, fencingToken, signal, onProjectCheckpoint, true);
1219
+ }
1220
+ /**
1221
+ * Launches the configured project. Only the first launch, from the admitted commit's clean
1222
+ * source, may record parallel-safety proof: a restart serves the workspace after the provider
1223
+ * edited it, and a proof observed there would be stored under the admitted commit and could
1224
+ * move this or a later attempt at that commit into shared admission for source it never ran.
1225
+ */
1226
+ async launchConfiguredProject(dispatchAttemptId, fencingToken, signal, onProjectCheckpoint, promote) {
1176
1227
  const active = this.active.get(dispatchAttemptId);
1177
1228
  if (!active || active.lease.fencingToken !== fencingToken || active.lease.state !== "active" || active.releasing) {
1178
1229
  throw new Error("host_runtime_project_unavailable: an active matching host runtime lease is required.");
@@ -1248,7 +1299,29 @@ export class HostRuntimeLeaseManager {
1248
1299
  message: `Preparing the ASP.NET runtime for commit ${active.inputCommitSha.slice(0, 12)} before binding its assigned port.`,
1249
1300
  data: { input_commit_sha: active.inputCommitSha, project_path: prebuild.projectPath },
1250
1301
  });
1251
- const build = await ensureAspNetRuntimePrebuilt(prebuild, async (plan, buildSignal) => await executeAspNetRuntimeBuild(active.processSupervisor, logDirectory, plan, buildSignal, capabilitySecrets), signal);
1302
+ let hostLoadWaitMs = null;
1303
+ const build = await ensureAspNetRuntimePrebuilt(prebuild,
1304
+ // Only a real build (not a verified cache hit) takes a host load token.
1305
+ async (plan, buildSignal) => await runHostGovernedStep(this.hostLoadGovernor, {
1306
+ classification: aspNetPrebuildStepClass,
1307
+ label: prebuild.projectPath,
1308
+ dispatchAttemptId,
1309
+ priority: this.admissions.get(dispatchAttemptId)?.priority ?? "foreground",
1310
+ signal: buildSignal,
1311
+ onWaiting: async (decision) => await onProjectCheckpoint?.({
1312
+ code: "host_runtime_build_waiting_for_host_capacity",
1313
+ message: `The ASP.NET runtime build is waiting for host capacity: ${decision.detail}`,
1314
+ data: { status: "waiting_for_host_capacity", step_class: aspNetPrebuildStepClass.stepClass, reason: decision.reason },
1315
+ }),
1316
+ }, async (waitMs, control) => {
1317
+ hostLoadWaitMs = waitMs;
1318
+ // A reclaimed token stops the build: its capacity is no longer reserved. So does a
1319
+ // build whose process tree cannot be recorded on its token (a reclaim could not stop it).
1320
+ const unrecorded = new AbortController();
1321
+ const stepSignal = anySignal(buildSignal, control.fenced, unrecorded.signal);
1322
+ return await executeAspNetRuntimeBuild(active.processSupervisor, logDirectory, plan, stepSignal, capabilitySecrets, async (metadataPath) => await attachSupervisedStepProcess(control, metadataPath)
1323
+ .catch((error) => { unrecorded.abort(error); }));
1324
+ }), signal);
1252
1325
  await onProjectCheckpoint?.({
1253
1326
  code: build.cacheHit ? "host_runtime_build_cached" : "host_runtime_build_completed",
1254
1327
  message: build.cacheHit
@@ -1258,6 +1331,7 @@ export class HostRuntimeLeaseManager {
1258
1331
  input_commit_sha: active.inputCommitSha,
1259
1332
  build_fingerprint: build.fingerprint,
1260
1333
  receipt_path: build.receiptPath,
1334
+ ...(hostLoadWaitMs === null ? {} : { host_load_wait_ms: hostLoadWaitMs }),
1261
1335
  },
1262
1336
  });
1263
1337
  }
@@ -1270,7 +1344,7 @@ export class HostRuntimeLeaseManager {
1270
1344
  },
1271
1345
  }, launcher, signal);
1272
1346
  }
1273
- const promotedLease = await this.promoteVerifiedRuntime(active, active.lease);
1347
+ const promotedLease = promote ? await this.promoteVerifiedRuntime(active, active.lease) : active.lease;
1274
1348
  const runtimeEnvironment = hostRuntimeEnvironment(active.sessionId, promotedLease, active.runtimeContract, active.executionClass, active.databaseCapability);
1275
1349
  const playwright = active.runtimeContract.contract.runtime.playwright;
1276
1350
  if (!playwright) {
@@ -1309,6 +1383,93 @@ export class HostRuntimeLeaseManager {
1309
1383
  executionClass: active.executionClass,
1310
1384
  };
1311
1385
  }
1386
+ /**
1387
+ * Relaunches the configured project so it serves the current workspace. Every
1388
+ * configured process stops (the API port changes, so the dev server's proxy target
1389
+ * must change with it), its port reservation is released and dropped from the
1390
+ * persisted lease, and the regular start path runs again, including the ASP.NET
1391
+ * prebuild, whose receipt rebuilds only when the sources changed.
1392
+ */
1393
+ async restartConfiguredProject(dispatchAttemptId, fencingToken, signal, onProjectCheckpoint) {
1394
+ const active = this.active.get(dispatchAttemptId);
1395
+ if (!active || active.lease.fencingToken !== fencingToken || active.lease.state !== "active" || active.releasing) {
1396
+ throw new Error("host_runtime_project_unavailable: an active matching host runtime lease is required.");
1397
+ }
1398
+ if (signal?.aborted)
1399
+ throw new Error(String(signal.reason ?? "Host runtime restart was cancelled."));
1400
+ if (active.restartingConfiguredProject) {
1401
+ throw new Error("host_runtime_project_conflict: a configured project restart is already in progress.");
1402
+ }
1403
+ active.restartingConfiguredProject = true;
1404
+ // Release cancels the whole restart through this controller and waits for it to settle.
1405
+ const controller = linkedAbortController(signal);
1406
+ const promise = this.runConfiguredProjectRestart(active, dispatchAttemptId, fencingToken, controller.signal, onProjectCheckpoint);
1407
+ const restart = { controller, promise };
1408
+ active.configuredProjectRestart = restart;
1409
+ try {
1410
+ return await promise;
1411
+ }
1412
+ finally {
1413
+ // The controller is not aborted on settle: adapters this restart launched keep it as their
1414
+ // parent signal for as long as they run, exactly as they would keep the caller's signal.
1415
+ if (active.configuredProjectRestart === restart)
1416
+ active.configuredProjectRestart = null;
1417
+ active.restartingConfiguredProject = false;
1418
+ }
1419
+ }
1420
+ async runConfiguredProjectRestart(active, dispatchAttemptId, fencingToken, signal, onProjectCheckpoint) {
1421
+ // The relaunch reuses the contract (commands, ports, environment, concurrency) admitted at
1422
+ // start. If the workspace now declares a different one, a restart would run stale settings;
1423
+ // the attempt fails retryably instead, so a fresh attempt admits the new contract.
1424
+ const currentContract = await loadHostRuntimeContract(active.lease.worktreePath);
1425
+ if (hostRuntimeContractFingerprint(currentContract) !== active.runtimeContractFingerprint) {
1426
+ throw new ForgeFailureError("host_runtime_contract_changed", "host_runtime_contract_changed: the workspace's runtime contract changed after this attempt's runtime was admitted; a fresh attempt is needed to run it.");
1427
+ }
1428
+ const portNames = active.executionClass === "analysis_only" ? [] : configuredLaunchPortNames(active.runtimeContract);
1429
+ const pendingPort = portNames.find(name => active.pendingAdapterLaunches.has(name));
1430
+ if (pendingPort) {
1431
+ throw new Error(`host_runtime_project_conflict: configured port '${pendingPort}' is still launching.`);
1432
+ }
1433
+ const temporaryDirectory = active.lease.resources.paths.find(entry => entry.role === "temporary")?.path;
1434
+ if (active.runtimeContract.contract.runtime.playwright && temporaryDirectory) {
1435
+ // The generated Playwright config targets the stack being stopped. If the restart fails, no
1436
+ // config may be left pointing at ports another attempt can now be assigned.
1437
+ await this.playwrightAdapter.discardOverlay(temporaryDirectory);
1438
+ }
1439
+ await this.stopConfiguredProject(active, portNames);
1440
+ // Keeps whatever admission the attempt holds; see launchConfiguredProject.
1441
+ const restarted = await this.launchConfiguredProject(dispatchAttemptId, fencingToken, signal, onProjectCheckpoint, false);
1442
+ if (active.releasing) {
1443
+ throw new Error("host_runtime_project_unavailable: the host runtime lease was released during restart.");
1444
+ }
1445
+ return restarted;
1446
+ }
1447
+ /** Stops configured project processes in reverse launch order and releases their ports. */
1448
+ async stopConfiguredProject(active, portNames) {
1449
+ const launched = active.lease.resources.ports
1450
+ .map(port => port.name)
1451
+ .filter(name => portNames.includes(name))
1452
+ .reverse();
1453
+ for (const name of launched) {
1454
+ if (active.releasing) {
1455
+ throw new Error("host_runtime_project_unavailable: the host runtime lease was released during restart.");
1456
+ }
1457
+ const cleanup = active.adapterCleanupsByPort.get(name);
1458
+ if (!cleanup) {
1459
+ throw new Error(`host_runtime_project_restart_unavailable: configured port '${name}' has no supervised process to stop.`);
1460
+ }
1461
+ // A failed stop keeps the cleanup and the port record for the fenced release retry.
1462
+ await cleanup();
1463
+ removeCleanup(active.adapterCleanups, cleanup);
1464
+ active.adapterCleanupsByPort.delete(name);
1465
+ const runtimeLease = withRuntimeIsolationResources(active.lease, {
1466
+ ...active.lease.resources,
1467
+ ports: active.lease.resources.ports.filter(port => port.name !== name),
1468
+ });
1469
+ await this.writeLedger(runtimeLease);
1470
+ active.lease = runtimeLease;
1471
+ }
1472
+ }
1312
1473
  providerProcessRunner(dispatchAttemptId, fencingToken) {
1313
1474
  const active = this.active.get(dispatchAttemptId);
1314
1475
  if (!active || active.lease.fencingToken !== fencingToken || active.releasing)
@@ -1396,6 +1557,7 @@ export class HostRuntimeLeaseManager {
1396
1557
  unlinkAbortController(controller, signal);
1397
1558
  };
1398
1559
  active.adapterCleanups.push(cleanup);
1560
+ active.adapterCleanupsByPort.set(portName, cleanup);
1399
1561
  try {
1400
1562
  if (active.releasing)
1401
1563
  throw new Error("host_runtime_adapter_cancelled: host runtime release started during launch.");
@@ -1418,6 +1580,8 @@ export class HostRuntimeLeaseManager {
1418
1580
  try {
1419
1581
  await cleanup();
1420
1582
  removeCleanup(active.adapterCleanups, cleanup);
1583
+ if (active.adapterCleanupsByPort.get(portName) === cleanup)
1584
+ active.adapterCleanupsByPort.delete(portName);
1421
1585
  }
1422
1586
  catch {
1423
1587
  // Preserve the cleanup and broker claim for the fenced release retry.
@@ -1442,7 +1606,9 @@ export class HostRuntimeLeaseManager {
1442
1606
  if (!preservePreparation)
1443
1607
  this.pendingRenewals.delete(dispatchAttemptId);
1444
1608
  if (!active) {
1445
- await this.hostLoadGovernor.releaseAttempt(dispatchAttemptId).catch(() => undefined);
1609
+ // Queued steps are cancelled and running ones stopped; each returns its own
1610
+ // token once its processes are gone (never before, or capacity is reused early).
1611
+ this.hostLoadGovernor.stopAttempt(dispatchAttemptId);
1446
1612
  this.cancelAdmissionWaiters(dispatchAttemptId, fencingToken, "Managed host admission was released before acquisition.");
1447
1613
  this.releaseSingletonKeys(dispatchAttemptId, fencingToken);
1448
1614
  this.releaseParallelProjects(dispatchAttemptId, fencingToken);
@@ -1452,12 +1618,20 @@ export class HostRuntimeLeaseManager {
1452
1618
  if (active.lease.fencingToken !== fencingToken)
1453
1619
  return null;
1454
1620
  active.releasing = true;
1455
- // Attempt teardown returns the attempt's heavy-step tokens and cancels its queued steps.
1456
- await this.hostLoadGovernor.releaseAttempt(dispatchAttemptId).catch(() => undefined);
1621
+ // Attempt teardown cancels the attempt's queued heavy steps and stops its running
1622
+ // ones. Each running step (an ASP.NET prebuild, an install, a validation step)
1623
+ // returns its own token only after its processes have exited, so the capacity is
1624
+ // not reused while, say, a build is still being terminated.
1625
+ this.hostLoadGovernor.stopAttempt(dispatchAttemptId);
1457
1626
  for (const pending of active.pendingAdapterLaunches.values()) {
1458
1627
  pending.controller.abort("Host runtime release cancelled the pending adapter launch.");
1459
1628
  }
1460
1629
  await Promise.allSettled([...active.pendingAdapterLaunches.values()].map(pending => pending.promise));
1630
+ const restart = active.configuredProjectRestart;
1631
+ if (restart) {
1632
+ restart.controller.abort("Host runtime release cancelled the configured project restart.");
1633
+ await restart.promise.catch(() => undefined);
1634
+ }
1461
1635
  await active.databaseProvision?.catch(() => undefined);
1462
1636
  let releasing = transitionRuntimeIsolationLease(active.lease, "releasing");
1463
1637
  active.lease = releasing;
@@ -1465,7 +1639,17 @@ export class HostRuntimeLeaseManager {
1465
1639
  try {
1466
1640
  if (!active.runtimeResourcesReleased) {
1467
1641
  await active.processSupervisor.stopAll(fencingToken, "Host runtime lease released.");
1642
+ // The attempt's MCP servers and process trees are stopped now; tokens they held
1643
+ // belong to dead owners and go back to the host budget at once, including any
1644
+ // without a recorded process tree (their steps were inside the stopped trees).
1645
+ await this.hostLoadGovernor.reclaim().catch(() => undefined);
1646
+ await this.hostLoadGovernor.releaseOrphaned(token => token.dispatchAttemptId === dispatchAttemptId)
1647
+ .catch(() => undefined);
1648
+ // This bridge's own steps whose trees only stopAll could prove gone (a supervised
1649
+ // validation step whose termination failed earlier) return their tokens now.
1650
+ await this.hostLoadGovernor.releaseRetainedAfterTeardown(dispatchAttemptId).catch(() => undefined);
1468
1651
  await releaseAdapterResources(active.adapterCleanups);
1652
+ active.adapterCleanupsByPort.clear();
1469
1653
  if (active.databaseCapability && this.databaseBroker) {
1470
1654
  // A database the broker cannot drop now is reaped later; it must not hold host capacity.
1471
1655
  await this.databaseBroker.release(dispatchAttemptId, fencingToken).catch(() => "retained");
@@ -2165,7 +2349,36 @@ function hostRuntimeEnvironment(sessionId, lease, runtimeContract, executionClas
2165
2349
  environment.FORGE_BASE_URL = resolvedBaseUrls[0];
2166
2350
  return environment;
2167
2351
  }
2168
- async function executeAspNetRuntimeBuild(supervisor, logDirectory, plan, signal, exactSecrets = []) {
2352
+ /**
2353
+ * Every environment key `hostRuntimeEnvironment` and the Playwright overlay derive from the
2354
+ * configured project's assigned ports. They name a live stack, so they are withheld while the
2355
+ * stack is down: after its ports are released another attempt may be assigned them.
2356
+ */
2357
+ export function hostRuntimeStackEnvironmentKeys(runtimeContract) {
2358
+ const keys = new Set([
2359
+ "FORGE_E2E_API_URL",
2360
+ "FORGE_E2E_WEB_URL",
2361
+ "FORGE_BASE_URL",
2362
+ "FORGE_PLAYWRIGHT_BASE_URL",
2363
+ // The generated Playwright config embeds the base URL.
2364
+ "FORGE_PLAYWRIGHT_CONFIG",
2365
+ ]);
2366
+ for (const port of runtimeContract.contract.runtime.ports) {
2367
+ const normalizedName = port.name.toUpperCase().replaceAll(/[^A-Z0-9]/gu, "_");
2368
+ keys.add(port.env);
2369
+ if (port.baseUrlEnv)
2370
+ keys.add(port.baseUrlEnv);
2371
+ keys.add(`FORGE_${normalizedName}_PORT`);
2372
+ keys.add(`FORGE_${normalizedName}_URL`);
2373
+ }
2374
+ return [...keys];
2375
+ }
2376
+ function anySignal(...signals) {
2377
+ return AbortSignal.any(signals.filter((signal) => signal !== undefined));
2378
+ }
2379
+ async function executeAspNetRuntimeBuild(supervisor, logDirectory, plan, signal, exactSecrets = [],
2380
+ /** Once the build's supervised tree is up: records it on the build's host load token. */
2381
+ onStarted) {
2169
2382
  const childName = `runtime-build-${plan.fingerprint.slice(-12)}`;
2170
2383
  const stdoutLogPath = path.join(logDirectory, `${childName}.stdout.log`);
2171
2384
  const stderrLogPath = path.join(logDirectory, `${childName}.stderr.log`);
@@ -2190,6 +2403,7 @@ async function executeAspNetRuntimeBuild(supervisor, logDirectory, plan, signal,
2190
2403
  await append(stderrLogPath, line);
2191
2404
  },
2192
2405
  }, signal, { maxStartAttempts: 2, retryDelayMs: 250 });
2406
+ await onStarted?.(child.metadataPath);
2193
2407
  const result = await child.result;
2194
2408
  return {
2195
2409
  exitCode: result.exitCode,
@@ -2304,6 +2518,18 @@ function configuredInteger(name, fallback, minimum, maximum) {
2304
2518
  const parsed = Number.parseInt(process.env[name] ?? "", 10);
2305
2519
  return Number.isFinite(parsed) ? Math.max(minimum, Math.min(maximum, parsed)) : fallback;
2306
2520
  }
2521
+ /**
2522
+ * Today's max attempts and adaptive memory reserve for this host, before
2523
+ * FORGE_HOST_MAX_CONCURRENT_ATTEMPTS and FORGE_HOST_MEMORY_RESERVE_BYTES
2524
+ * (decision 0014 treats those as bounds on the server's values).
2525
+ */
2526
+ export function hostCapacityLimitDefaults(capacityResourceSample) {
2527
+ const configuration = loadHostCapacityConfiguration(capacityResourceSample);
2528
+ return {
2529
+ maxConcurrentAttempts: configuration.defaultHardMaxAttempts,
2530
+ memoryReserveBytes: configuration.adaptiveHostReserveBytes,
2531
+ };
2532
+ }
2307
2533
  function loadHostCapacityConfiguration(capacityResourceSample) {
2308
2534
  const sampledCpuCount = capacityResourceSample
2309
2535
  ? Math.max(1, Math.floor(capacityResourceSample.totalCpuMillis / 1_000))
@@ -2311,23 +2537,41 @@ function loadHostCapacityConfiguration(capacityResourceSample) {
2311
2537
  const totalMemoryBytes = capacityResourceSample?.totalMemoryBytes ?? os.totalmem();
2312
2538
  const reserveFloorBytes = configuredInteger("FORGE_HOST_MEMORY_RESERVE_FLOOR_BYTES", 1024 ** 3, 512 * 1024 ** 2, 128 * 1024 ** 3);
2313
2539
  const reserveCeilingBytes = configuredInteger("FORGE_HOST_MEMORY_RESERVE_CEILING_BYTES", 4 * 1024 ** 3, reserveFloorBytes, 128 * 1024 ** 3);
2314
- const hostReserveBytes = resolveAdaptiveMemoryReserveBytes(totalMemoryBytes, {
2315
- explicitBytes: configuredOptionalInteger("FORGE_HOST_MEMORY_RESERVE_BYTES", 512 * 1024 ** 2, 128 * 1024 ** 3),
2540
+ const adaptiveOptions = {
2316
2541
  floorBytes: reserveFloorBytes,
2317
2542
  ceilingBytes: reserveCeilingBytes,
2318
2543
  percent: configuredNumber("FORGE_HOST_MEMORY_RESERVE_PERCENT", 12.5, 1, 50),
2544
+ };
2545
+ const hostReserveBytes = resolveAdaptiveMemoryReserveBytes(totalMemoryBytes, {
2546
+ ...adaptiveOptions,
2547
+ explicitBytes: configuredOptionalInteger("FORGE_HOST_MEMORY_RESERVE_BYTES", 512 * 1024 ** 2, 128 * 1024 ** 3),
2319
2548
  });
2320
- const minimumIdleReserveBytes = Math.min(hostReserveBytes, reserveFloorBytes);
2549
+ const defaultHardMaxAttempts = Math.max(1, Math.min(8, Math.floor(sampledCpuCount / 2)));
2550
+ const idleReserveOverride = Number.parseInt(process.env.FORGE_HOST_IDLE_MEMORY_RESERVE_BYTES ?? "", 10);
2551
+ const idleReserveOverrideBytes = Number.isFinite(idleReserveOverride) ? idleReserveOverride : null;
2321
2552
  return {
2322
- hardMaxAttempts: configuredInteger("FORGE_HOST_MAX_CONCURRENT_ATTEMPTS", Math.max(1, Math.min(8, Math.floor(sampledCpuCount / 2))), 1, 32),
2553
+ hardMaxAttempts: configuredInteger("FORGE_HOST_MAX_CONCURRENT_ATTEMPTS", defaultHardMaxAttempts, 1, 32),
2323
2554
  hostReserveBytes,
2324
- idleHostReserveBytes: configuredInteger("FORGE_HOST_IDLE_MEMORY_RESERVE_BYTES", minimumIdleReserveBytes, 512 * 1024 ** 2, hostReserveBytes),
2555
+ idleHostReserveBytes: idleHostReserveBytesFor(hostReserveBytes, { reserveFloorBytes, idleReserveOverrideBytes }),
2556
+ defaultHardMaxAttempts,
2557
+ adaptiveHostReserveBytes: resolveAdaptiveMemoryReserveBytes(totalMemoryBytes, adaptiveOptions),
2558
+ reserveFloorBytes,
2559
+ idleReserveOverrideBytes,
2325
2560
  cpuReserveMillis: configuredInteger("FORGE_HOST_CPU_RESERVE_MILLIS", 1000, 0, 32_000),
2326
2561
  workspaceReserveBytes: configuredInteger("FORGE_HOST_WORKSPACE_RESERVE_BYTES", 10 * 1024 ** 3, 1024 ** 3, Number.MAX_SAFE_INTEGER),
2327
2562
  memoryRecoverySamples: configuredInteger("FORGE_HOST_MEMORY_RECOVERY_SAMPLES", 2, 1, 10),
2328
2563
  memoryRecoverySampleIntervalMs: configuredInteger("FORGE_HOST_MEMORY_RECOVERY_SAMPLE_INTERVAL_MS", 1_000, 100, 30_000),
2329
2564
  };
2330
2565
  }
2566
+ /**
2567
+ * The reserve kept while no attempt holds capacity: FORGE_HOST_IDLE_MEMORY_RESERVE_BYTES
2568
+ * clamped to [512 MiB, reserve], else min(reserve, reserve floor). Never above the reserve.
2569
+ */
2570
+ function idleHostReserveBytesFor(hostReserveBytes, configuration) {
2571
+ const fallback = Math.min(hostReserveBytes, configuration.reserveFloorBytes);
2572
+ const override = configuration.idleReserveOverrideBytes;
2573
+ return override === null ? fallback : Math.max(512 * 1024 ** 2, Math.min(hostReserveBytes, override));
2574
+ }
2331
2575
  function configuredOptionalInteger(name, minimum, maximum) {
2332
2576
  const raw = process.env[name];
2333
2577
  if (raw === undefined || raw.trim().length === 0)
@@ -28,5 +28,12 @@ export declare class PlaywrightHostRuntimeAdapter {
28
28
  */
29
29
  assertBrowserCacheReady(config: HostRuntimePlaywrightConfig, worktreePath: string): Promise<void>;
30
30
  private readyBrowserCache;
31
+ /**
32
+ * Removes the generated config, which names the base URL of the stack it was prepared for. A
33
+ * stopped stack's config must not survive: its port may be reassigned to another attempt, and a
34
+ * provider that remembers the config's path would otherwise run Playwright against that port.
35
+ * The next `prepare` writes a fresh one.
36
+ */
37
+ discardOverlay(temporaryDirectory: string): Promise<void>;
31
38
  prepare(config: HostRuntimePlaywrightConfig, context: PlaywrightHostRuntimeContext): Promise<PreparedPlaywrightHostRuntime>;
32
39
  }
@@ -35,6 +35,17 @@ export class PlaywrightHostRuntimeAdapter {
35
35
  }
36
36
  return { cache: resolution.cache, installCommand };
37
37
  }
38
+ /**
39
+ * Removes the generated config, which names the base URL of the stack it was prepared for. A
40
+ * stopped stack's config must not survive: its port may be reassigned to another attempt, and a
41
+ * provider that remembers the config's path would otherwise run Playwright against that port.
42
+ * The next `prepare` writes a fresh one.
43
+ */
44
+ async discardOverlay(temporaryDirectory) {
45
+ if (!await assertCanonicalDirectory(temporaryDirectory, true))
46
+ return;
47
+ await fs.rm(path.join(path.resolve(temporaryDirectory), playwrightOverlayFileName), { force: true });
48
+ }
38
49
  async prepare(config, context) {
39
50
  const { realWorktree, realSource } = await projectConfigLocation(config, context.worktreePath);
40
51
  const sourceConfig = path.resolve(path.resolve(context.worktreePath), config.config);
@@ -62,7 +73,7 @@ export class PlaywrightHostRuntimeAdapter {
62
73
  if (!/^[0-9a-f]{32}$/u.test(context.ownershipToken)) {
63
74
  throw new Error("playwright_runtime_adapter_invalid: ownership token must be a normalized dispatch attempt UUID.");
64
75
  }
65
- const overlayPath = path.join(temporaryDirectory, "forge.playwright.config.mjs");
76
+ const overlayPath = path.join(temporaryDirectory, playwrightOverlayFileName);
66
77
  const { cache: readyCache, installCommand: browserInstallCommand } = await this.readyBrowserCache(context.worktreePath, realWorktree, path.dirname(realSource));
67
78
  const browserCache = readyCache
68
79
  ? { path: readyCache, ready: true }
@@ -135,6 +146,7 @@ async function ensureAttemptWritableDirectories(targets, realWorktree) {
135
146
  for (const target of resolvedTargets)
136
147
  await createPrivateCanonicalDirectory(target);
137
148
  }
149
+ const playwrightOverlayFileName = "forge.playwright.config.mjs";
138
150
  async function writeAttemptOverlay(target, content) {
139
151
  const parent = path.dirname(target);
140
152
  const identity = await assertCanonicalDirectory(parent);