@loucompanion/forge-bridge 0.1.4-dev.e1b4f55fb18d → 0.1.4-dev.e3697e9f5c98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -0
- package/dist/bridge/bridge.base.d.ts +9 -0
- package/dist/bridge/bridge.service.d.ts +70 -1
- package/dist/bridge/bridge.service.js +278 -4
- package/dist/bridge/bridge.types.d.ts +11 -0
- package/dist/bridge/local-yield-flag.d.ts +6 -0
- package/dist/bridge/local-yield-flag.js +34 -0
- package/dist/cleanup/cleanup.service.js +15 -9
- package/dist/cleanup/forge-owned-paths.d.ts +9 -0
- package/dist/cleanup/forge-owned-paths.js +53 -0
- package/dist/cli/cli.help.js +18 -0
- package/dist/cli/cli.service.d.ts +16 -0
- package/dist/cli/cli.service.js +132 -14
- package/dist/cli/local-config.d.ts +4 -0
- package/dist/cli/local-config.js +26 -4
- package/dist/runtime/aspnet-runtime-prebuild.js +94 -6
- package/dist/runtime/host-load-admission.d.ts +9 -1
- package/dist/runtime/host-load-admission.js +19 -4
- package/dist/runtime/host-load-child-environment.js +3 -1
- package/dist/runtime/host-load-governor-config.d.ts +9 -0
- package/dist/runtime/host-load-governor-config.js +30 -0
- package/dist/runtime/host-load-governor.d.ts +2 -0
- package/dist/runtime/host-load-governor.js +23 -1
- package/dist/runtime/host-load-runtime-settings.d.ts +25 -0
- package/dist/runtime/host-load-runtime-settings.js +78 -0
- package/dist/runtime/host-runtime-lease.d.ts +58 -2
- package/dist/runtime/host-runtime-lease.js +198 -7
- package/dist/runtime/host-runtime-promotion.d.ts +23 -0
- package/dist/runtime/host-runtime-promotion.js +36 -0
- package/dist/runtime/playwright-host-runtime-adapter.d.ts +7 -0
- package/dist/runtime/playwright-host-runtime-adapter.js +13 -1
- package/dist/runtime/runner-settings.d.ts +100 -0
- package/dist/runtime/runner-settings.js +214 -0
- package/dist/session/pre-publication-pass.d.ts +60 -0
- package/dist/session/pre-publication-pass.js +145 -0
- package/dist/session/pre-publication-validation.d.ts +21 -11
- package/dist/session/pre-publication-validation.js +149 -104
- package/dist/session/provider-cli/pre-publication-repair.d.ts +40 -0
- package/dist/session/provider-cli/pre-publication-repair.js +243 -0
- package/dist/session/provider-cli/provider-cli.prompts.js +4 -1
- package/dist/session/provider-cli/provider-cli.service.d.ts +4 -1
- package/dist/session/provider-cli/provider-cli.service.js +72 -143
- package/dist/session/provider-cli/provider-cli.types.d.ts +26 -0
- package/dist/session/session.base.d.ts +6 -1
- package/dist/session/session.service.d.ts +7 -2
- package/dist/session/session.service.js +100 -2
- package/dist/session/session.types.js +2 -2
- package/dist/session/workspace-runtime-fingerprint.d.ts +32 -0
- package/dist/session/workspace-runtime-fingerprint.js +138 -0
- package/dist/shared/provider-capabilities.js +5 -6
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
|
@@ -2,7 +2,6 @@ import fs from "node:fs/promises";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { RepositoryCoordinatorLock } from "../../sandbox/repository-lock.js";
|
|
4
4
|
import { GitClient } from "../../shared/git/git.js";
|
|
5
|
-
import { runtimeAdmissionPriority } from "../../runtime/host-runtime-lease.js";
|
|
6
5
|
import { sandboxHostLoadGateFromEnvironment } from "../sandbox-host-capacity-gate.js";
|
|
7
6
|
import { buildSpecBody, selectLaneCommand } from "../../worktree/artifact-injector.js";
|
|
8
7
|
import { defaultWorktreeCoordinatorStateRoot } from "../../worktree/worktree-paths.js";
|
|
@@ -13,12 +12,12 @@ import { diffClaimedChangedFiles, findUnpublishedWorktreePaths, normalizeChanged
|
|
|
13
12
|
import { DeterministicProviderCliService } from "./provider-cli.deterministic.js";
|
|
14
13
|
import { buildArchitectPrompt, buildConflictResolvePrompt, buildDebugCyclePrompt, buildDevelopCyclePrompt, buildDraftPrompt, buildDraftSpec, buildImplementationPrompt, buildProviderCliPrompt, buildProviderCliCommand, durableDraftInput, buildPullRequestCheckRepairPrompt, buildPullRequestCommentsPrompt, buildQaPrompt, formatProviderCliCommandForCheckpoint, isDecomposeDraftDispatch, isPullRequestCheckRepairDispatch, isPullRequestCommentsDispatch } from "./provider-cli.prompts.js";
|
|
15
14
|
import { isTransientCodexProviderNotFoundFailure, providerCompletionToolMissingFailure, recoveringProviderProcessRunner, StreamingProviderProcessRunner } from "./provider-cli.process.js";
|
|
16
|
-
import { emitProviderUsageEvent,
|
|
15
|
+
import { emitProviderUsageEvent, providerProcessEnv } from "./provider-cli.runtime.js";
|
|
17
16
|
import { clip, createProviderOutputState, parseJsonLine } from "./provider-output-state.js";
|
|
18
17
|
import { writeCiRepairReadinessManifest } from "./ci-repair-readiness.js";
|
|
19
18
|
import { assertRepairHeadEpoch } from "./provider-cli.repair-epoch.js";
|
|
20
|
-
import {
|
|
21
|
-
|
|
19
|
+
import { PrePublicationValidator } from "../pre-publication-validation.js";
|
|
20
|
+
import { prePublicationRepairTurnsFromEnvironment, validatePrePublicationWithRepair, } from "./pre-publication-repair.js";
|
|
22
21
|
const maxQaCompletionRecoveryTurns = 2;
|
|
23
22
|
function assertCommentRepairArtifactMatchesDispatch(dispatch, artifact) {
|
|
24
23
|
const pullRequest = dispatch.pullRequest;
|
|
@@ -214,22 +213,6 @@ async function pushWorktreeBranch(git, worktreePath, branchName, repoPath, coord
|
|
|
214
213
|
function providerOwnsBranchPublication(context) {
|
|
215
214
|
return context.dispatch.sandbox?.executionMode !== "docker";
|
|
216
215
|
}
|
|
217
|
-
function prePublicationExecution(context, environment, defaultRunner, baselineRevision) {
|
|
218
|
-
const hostLoadOwner = {
|
|
219
|
-
dispatchAttemptId: context.dispatch.sandbox?.dispatchAttemptId ?? null,
|
|
220
|
-
priority: runtimeAdmissionPriority(context.dispatch),
|
|
221
|
-
};
|
|
222
|
-
if (context.processRunner)
|
|
223
|
-
return { baselineRevision, environment, processRunner: context.processRunner, hostLoadOwner };
|
|
224
|
-
if (context.dispatch.sandbox?.executionMode !== "docker")
|
|
225
|
-
return { baselineRevision, environment, hostLoadOwner };
|
|
226
|
-
const expectedSandboxId = context.dispatch.sandbox.dispatchAttemptId;
|
|
227
|
-
const observedSandboxId = context.runtimeEnvironment?.FORGE_SANDBOX_ID ?? process.env.FORGE_SANDBOX_ID;
|
|
228
|
-
if (observedSandboxId !== expectedSandboxId) {
|
|
229
|
-
throw new ForgeFailureError("prepublication_execution_scope_invalid", `prepublication_execution_scope_invalid: Docker attempt ${expectedSandboxId} has no runner proven to execute inside that sandbox.`, "bridge");
|
|
230
|
-
}
|
|
231
|
-
return { baselineRevision, environment, processRunner: defaultRunner, hostLoadOwner };
|
|
232
|
-
}
|
|
233
216
|
function remoteTrackingRefspec(branchName) {
|
|
234
217
|
return `refs/heads/${branchName}:refs/remotes/origin/${branchName}`;
|
|
235
218
|
}
|
|
@@ -571,17 +554,19 @@ export class ProcessBackedProviderCliService {
|
|
|
571
554
|
providerToolHeartbeatIntervalMs;
|
|
572
555
|
publicationCoordinator;
|
|
573
556
|
prePublicationValidator;
|
|
557
|
+
prePublicationRepairTurns;
|
|
574
558
|
constructor(processRunner = new StreamingProviderProcessRunner(), git = new GitClient(), providerToolHeartbeatIntervalMs = defaultProviderToolHeartbeatIntervalMs, publicationCoordinator = new RepositoryCoordinatorLock(defaultWorktreeCoordinatorStateRoot()),
|
|
575
559
|
// The Docker sandbox worker (`forge` run-once via ForgeBridgeCliService) builds
|
|
576
560
|
// this default. A container cannot reach the host ledger, so when the host
|
|
577
561
|
// bridge enabled it, its steps ask the bridge for tokens over the sandbox
|
|
578
562
|
// channel (decision 0013); elsewhere the gate is absent and validation is ungated.
|
|
579
|
-
prePublicationValidator = new PrePublicationValidator(undefined, undefined, undefined, sandboxHostLoadGateFromEnvironment())) {
|
|
563
|
+
prePublicationValidator = new PrePublicationValidator(undefined, undefined, undefined, sandboxHostLoadGateFromEnvironment()), prePublicationRepairTurns = prePublicationRepairTurnsFromEnvironment()) {
|
|
580
564
|
this.processRunner = processRunner;
|
|
581
565
|
this.git = git;
|
|
582
566
|
this.providerToolHeartbeatIntervalMs = providerToolHeartbeatIntervalMs;
|
|
583
567
|
this.publicationCoordinator = publicationCoordinator;
|
|
584
568
|
this.prePublicationValidator = prePublicationValidator;
|
|
569
|
+
this.prePublicationRepairTurns = prePublicationRepairTurns;
|
|
585
570
|
}
|
|
586
571
|
async runDraft(context) {
|
|
587
572
|
const { dispatch } = context;
|
|
@@ -1151,6 +1136,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1151
1136
|
const addressComments = !repairChecks && isPullRequestCommentsDispatch(dispatch);
|
|
1152
1137
|
let repairSpec = null;
|
|
1153
1138
|
let repairEnvironment = context.runtimeEnvironment;
|
|
1139
|
+
let ciRepairSpecPath = null;
|
|
1154
1140
|
let completionTools = null;
|
|
1155
1141
|
if (repairChecks) {
|
|
1156
1142
|
const metadataRoot = path.join(worktree.worktreePath, ".forge", "work-items", dispatch.workItem.id);
|
|
@@ -1161,6 +1147,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1161
1147
|
}
|
|
1162
1148
|
const specBody = buildSpecBody(laneCommand, dispatch.workItem, "ci_repair");
|
|
1163
1149
|
const specPath = path.join(metadataRoot, "spec.md");
|
|
1150
|
+
ciRepairSpecPath = specPath;
|
|
1164
1151
|
await fs.writeFile(specPath, specBody, "utf8");
|
|
1165
1152
|
await fs.writeFile(path.join(metadataRoot, "spec.meta.json"), `${JSON.stringify({ schema_version: 1, status: "approved", produced_by: "forge-lane-command" })}\n`, "utf8");
|
|
1166
1153
|
repairSpec = {
|
|
@@ -1315,6 +1302,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1315
1302
|
: addressComments
|
|
1316
1303
|
? "comment_repair"
|
|
1317
1304
|
: "conflict_repair";
|
|
1305
|
+
const readinessSpecPath = ciRepairSpecPath;
|
|
1318
1306
|
await this.validatePrePublicationWithRecovery({
|
|
1319
1307
|
context,
|
|
1320
1308
|
validationProfile,
|
|
@@ -1322,6 +1310,10 @@ export class ProcessBackedProviderCliService {
|
|
|
1322
1310
|
outputState,
|
|
1323
1311
|
preparedHeadSha,
|
|
1324
1312
|
repairScope: "pull_request",
|
|
1313
|
+
...(readinessSpecPath ? {
|
|
1314
|
+
// The readiness manifest records the attempt URLs; a restart must not leave it pointing at the old stack.
|
|
1315
|
+
onRuntimeEnvironmentRefreshed: async (runtimeEnvironment) => (await writeCiRepairReadinessManifest(dispatch, worktree.worktreePath, readinessSpecPath, runtimeEnvironment)).environment,
|
|
1316
|
+
} : {}),
|
|
1325
1317
|
});
|
|
1326
1318
|
const stagedChangeSet = await stagePublishableWorktreeChangeSet(this.git, worktree.worktreePath);
|
|
1327
1319
|
const stagedChangedFiles = stagedChangeSet.publishable;
|
|
@@ -1590,141 +1582,78 @@ export class ProcessBackedProviderCliService {
|
|
|
1590
1582
|
return artifact;
|
|
1591
1583
|
}
|
|
1592
1584
|
async validatePrePublicationWithRecovery(options) {
|
|
1593
|
-
const
|
|
1585
|
+
const processRunner = recoveringProviderProcessRunner(options.context.processRunner ?? this.processRunner);
|
|
1586
|
+
await validatePrePublicationWithRepair(options, {
|
|
1587
|
+
validator: this.prePublicationValidator,
|
|
1588
|
+
defaultProcessRunner: this.processRunner,
|
|
1589
|
+
maxRepairTurns: this.prePublicationRepairTurns,
|
|
1590
|
+
runRepairTurn: async (turn) => await this.runPrePublicationRepairTurn(options, processRunner, turn),
|
|
1591
|
+
});
|
|
1592
|
+
}
|
|
1593
|
+
/** Resumes the provider thread for one in-place repair turn; the turn must leave HEAD where it was. */
|
|
1594
|
+
async runPrePublicationRepairTurn(options, processRunner, turn) {
|
|
1595
|
+
const { context, outputState, preparedHeadSha } = options;
|
|
1594
1596
|
const { dispatch, worktree } = context;
|
|
1595
|
-
const
|
|
1596
|
-
const
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1600
|
-
|
|
1601
|
-
|
|
1597
|
+
const { prompt: focusedPrompt, repairTurn: nextRepairTurn, maxRepairTurns, repairEnvironment, environment } = turn;
|
|
1598
|
+
const repairDispatch = {
|
|
1599
|
+
...dispatch,
|
|
1600
|
+
session: { ...dispatch.session, resumeProviderThreadId: turn.providerThreadId },
|
|
1601
|
+
};
|
|
1602
|
+
const providerPrompt = buildProviderCliPrompt(repairDispatch, focusedPrompt, repairEnvironment);
|
|
1603
|
+
const pipePromptToStdin = shouldPipePromptToStdin(repairDispatch.execution.provider, providerPrompt, usesManagedWindowsHost(repairDispatch));
|
|
1604
|
+
const command = buildProviderCliCommand(repairDispatch, {
|
|
1605
|
+
worktreePath: worktree.worktreePath,
|
|
1606
|
+
prompt: focusedPrompt,
|
|
1607
|
+
promptFromStdin: pipePromptToStdin,
|
|
1608
|
+
runtimeEnvironment: repairEnvironment,
|
|
1609
|
+
});
|
|
1610
|
+
const toolHeartbeat = new ProviderToolActivityHeartbeat(outputState, context.emit, this.providerToolHeartbeatIntervalMs);
|
|
1611
|
+
let result;
|
|
1612
|
+
let providerStarted = false;
|
|
1613
|
+
try {
|
|
1614
|
+
result = await processRunner.run({
|
|
1615
|
+
command: command.command,
|
|
1616
|
+
args: command.args,
|
|
1617
|
+
cwd: worktree.worktreePath,
|
|
1618
|
+
env: environment,
|
|
1619
|
+
resumesProviderThread: Boolean(repairDispatch.session.resumeProviderThreadId),
|
|
1620
|
+
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1621
|
+
}, {
|
|
1622
|
+
onStarted: async () => {
|
|
1602
1623
|
await context.emit({
|
|
1603
1624
|
role: "runner",
|
|
1604
1625
|
kind: "checkpoint",
|
|
1605
|
-
content: `
|
|
1606
|
-
eventType: "
|
|
1607
|
-
data: JSON.stringify({ repairTurn, maxRepairTurns: maxPrePublicationRepairTurns }),
|
|
1608
|
-
});
|
|
1609
|
-
}
|
|
1610
|
-
return;
|
|
1611
|
-
}
|
|
1612
|
-
catch (error) {
|
|
1613
|
-
if (!(error instanceof PrePublicationValidationError))
|
|
1614
|
-
throw error;
|
|
1615
|
-
if (repairTurn >= maxPrePublicationRepairTurns) {
|
|
1616
|
-
await context.emit({
|
|
1617
|
-
role: "runner",
|
|
1618
|
-
kind: "error",
|
|
1619
|
-
content: `Pre-publication validation still fails after ${maxPrePublicationRepairTurns} in-place repair turns: ${clip(error.message, 4000)}`,
|
|
1620
|
-
eventType: "prepublication_repair_exhausted",
|
|
1621
|
-
data: JSON.stringify({ checkId: error.checkId, repairTurns: repairTurn, maxRepairTurns: maxPrePublicationRepairTurns }),
|
|
1626
|
+
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxRepairTurns} is supervised and ready.`,
|
|
1627
|
+
eventType: "provider_cli_started",
|
|
1622
1628
|
});
|
|
1623
|
-
|
|
1624
|
-
}
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1632
|
-
|
|
1633
|
-
|
|
1634
|
-
|
|
1635
|
-
const providerPrompt = buildProviderCliPrompt(repairDispatch, focusedPrompt, repairEnvironment);
|
|
1636
|
-
const pipePromptToStdin = shouldPipePromptToStdin(repairDispatch.execution.provider, providerPrompt, usesManagedWindowsHost(repairDispatch));
|
|
1637
|
-
const command = buildProviderCliCommand(repairDispatch, {
|
|
1638
|
-
worktreePath: worktree.worktreePath,
|
|
1639
|
-
prompt: focusedPrompt,
|
|
1640
|
-
promptFromStdin: pipePromptToStdin,
|
|
1641
|
-
runtimeEnvironment: repairEnvironment,
|
|
1642
|
-
});
|
|
1629
|
+
providerStarted = true;
|
|
1630
|
+
},
|
|
1631
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1632
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1633
|
+
onStdoutLine: async (line) => {
|
|
1634
|
+
await toolHeartbeat.consume(line);
|
|
1635
|
+
},
|
|
1636
|
+
}, context.signal);
|
|
1637
|
+
}
|
|
1638
|
+
finally {
|
|
1639
|
+
toolHeartbeat.stop();
|
|
1640
|
+
if (providerStarted) {
|
|
1643
1641
|
await context.emit({
|
|
1644
1642
|
role: "runner",
|
|
1645
1643
|
kind: "checkpoint",
|
|
1646
|
-
content: `
|
|
1647
|
-
eventType: "
|
|
1648
|
-
data: JSON.stringify({ checkId: error.checkId, repairTurn: nextRepairTurn, maxRepairTurns: maxPrePublicationRepairTurns }),
|
|
1644
|
+
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxRepairTurns} exited.`,
|
|
1645
|
+
eventType: "provider_cli_completed",
|
|
1649
1646
|
});
|
|
1650
|
-
const toolHeartbeat = new ProviderToolActivityHeartbeat(outputState, context.emit, this.providerToolHeartbeatIntervalMs);
|
|
1651
|
-
let result;
|
|
1652
|
-
let providerStarted = false;
|
|
1653
|
-
try {
|
|
1654
|
-
result = await processRunner.run({
|
|
1655
|
-
command: command.command,
|
|
1656
|
-
args: command.args,
|
|
1657
|
-
cwd: worktree.worktreePath,
|
|
1658
|
-
env: environment,
|
|
1659
|
-
resumesProviderThread: Boolean(repairDispatch.session.resumeProviderThreadId),
|
|
1660
|
-
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1661
|
-
}, {
|
|
1662
|
-
onStarted: async () => {
|
|
1663
|
-
await context.emit({
|
|
1664
|
-
role: "runner",
|
|
1665
|
-
kind: "checkpoint",
|
|
1666
|
-
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxPrePublicationRepairTurns} is supervised and ready.`,
|
|
1667
|
-
eventType: "provider_cli_started",
|
|
1668
|
-
});
|
|
1669
|
-
providerStarted = true;
|
|
1670
|
-
},
|
|
1671
|
-
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1672
|
-
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1673
|
-
onStdoutLine: async (line) => {
|
|
1674
|
-
await toolHeartbeat.consume(line);
|
|
1675
|
-
},
|
|
1676
|
-
}, context.signal);
|
|
1677
|
-
}
|
|
1678
|
-
finally {
|
|
1679
|
-
toolHeartbeat.stop();
|
|
1680
|
-
if (providerStarted) {
|
|
1681
|
-
await context.emit({
|
|
1682
|
-
role: "runner",
|
|
1683
|
-
kind: "checkpoint",
|
|
1684
|
-
content: `Provider pre-publication repair turn ${nextRepairTurn}/${maxPrePublicationRepairTurns} exited.`,
|
|
1685
|
-
eventType: "provider_cli_completed",
|
|
1686
|
-
});
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
if (result.exitCode !== 0)
|
|
1690
|
-
throw providerCliExitFailure(command.command, result);
|
|
1691
|
-
const postRepairHeadSha = (await this.git.run(worktree.worktreePath, ["rev-parse", "HEAD"])).trim();
|
|
1692
|
-
if (postRepairHeadSha.toLowerCase() !== preparedHeadSha.toLowerCase()) {
|
|
1693
|
-
throw new Error(`provider_publication_boundary_violation: pre-publication repair changed HEAD from ${preparedHeadSha} to ${postRepairHeadSha}; Forge requires provider changes to remain uncommitted and unpushed until validation passes.`, { cause: error });
|
|
1694
|
-
}
|
|
1695
1647
|
}
|
|
1696
1648
|
}
|
|
1649
|
+
if (result.exitCode !== 0)
|
|
1650
|
+
throw providerCliExitFailure(command.command, result);
|
|
1651
|
+
const postRepairHeadSha = (await this.git.run(worktree.worktreePath, ["rev-parse", "HEAD"])).trim();
|
|
1652
|
+
if (postRepairHeadSha.toLowerCase() !== preparedHeadSha.toLowerCase()) {
|
|
1653
|
+
throw new Error(`provider_publication_boundary_violation: pre-publication repair changed HEAD from ${preparedHeadSha} to ${postRepairHeadSha}; Forge requires provider changes to remain uncommitted and unpushed until validation passes.`, { cause: turn.failure });
|
|
1654
|
+
}
|
|
1697
1655
|
}
|
|
1698
1656
|
}
|
|
1699
|
-
function buildPrePublicationRepairPrompt(error, repairTurn, repairScope) {
|
|
1700
|
-
const invocation = [error.command, ...error.args].join(" ");
|
|
1701
|
-
const priorWork = repairScope === "implementation"
|
|
1702
|
-
? "Keep the completed implementation and its Forge-owned completion artifacts intact."
|
|
1703
|
-
: "Keep the existing PR-comment or CI repairs intact.";
|
|
1704
|
-
return [
|
|
1705
|
-
`Forge pre-publication validation failed after your ${repairScope === "implementation" ? "implementation" : "PR repair"} turn.`,
|
|
1706
|
-
`This is bounded in-place repair turn ${repairTurn}/${maxPrePublicationRepairTurns}.`,
|
|
1707
|
-
`Failed check: ${error.checkId}`,
|
|
1708
|
-
`Command: ${invocation}`,
|
|
1709
|
-
`Exit code: ${error.exitCode}`,
|
|
1710
|
-
"Diagnostics:",
|
|
1711
|
-
error.detail || "The validation command returned no diagnostic output.",
|
|
1712
|
-
"Fix the root cause in the current worktree and run the focused failing check.",
|
|
1713
|
-
`${priorWork} Do not commit, push, rebase, or modify Forge-owned protocol artifacts.`,
|
|
1714
|
-
"When the focused check passes, stop; Bridge will rerun the complete required pre-publication profile and owns commit/push.",
|
|
1715
|
-
].join("\n\n");
|
|
1716
|
-
}
|
|
1717
|
-
function publicationCapabilities(context, runtimeEnvironment) {
|
|
1718
|
-
const capabilities = new Set();
|
|
1719
|
-
const launchTarget = context.dispatch.qaBrowser?.launchTarget;
|
|
1720
|
-
if (runtimeEnvironment?.FORGE_PLAYWRIGHT_CONFIG
|
|
1721
|
-
|| launchTarget?.url
|
|
1722
|
-
|| launchTarget?.command
|
|
1723
|
-
|| launchTarget?.managed_runtime_port) {
|
|
1724
|
-
capabilities.add("browser_launch");
|
|
1725
|
-
}
|
|
1726
|
-
return capabilities;
|
|
1727
|
-
}
|
|
1728
1657
|
async function stageDraftAttachments(dispatch, metadataRoot) {
|
|
1729
1658
|
const attachments = dispatch.draft?.attachments ?? [];
|
|
1730
1659
|
const stageable = attachments.filter((attachment) => (attachment.kind === "text" && typeof attachment.textContent === "string")
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import type { RunOnceDispatchPacket, RunnerDispatchArtifact, RunnerDispatchEvent, RunnerDispatchSpec } from "../session.types.js";
|
|
2
2
|
import type { WorktreeHandle } from "../../worktree/worktree.types.js";
|
|
3
3
|
import type { ProviderProcessRunner } from "./provider-cli.process.js";
|
|
4
|
+
/**
|
|
5
|
+
* Why the attempt's runtime stack restarted before a validation pass. The first cause that applies:
|
|
6
|
+
* a previous restart did not complete; the workspace state could not be compared with the stack's
|
|
7
|
+
* (either reading was unavailable); or the workspace changed since the stack was launched.
|
|
8
|
+
*/
|
|
9
|
+
export type RuntimeRestartReason = "previous_restart_incomplete" | "fingerprint_unavailable" | "workspace_changed";
|
|
10
|
+
export interface RuntimeEnvironmentRefresh {
|
|
11
|
+
/** The restarted stack's runtime environment. */
|
|
12
|
+
readonly environment: Readonly<Record<string, string>>;
|
|
13
|
+
readonly reason: RuntimeRestartReason;
|
|
14
|
+
/** What changed in the workspace since the stack was launched, when both states could be read. */
|
|
15
|
+
readonly changes: readonly string[];
|
|
16
|
+
}
|
|
4
17
|
export interface ProviderCliRunContext {
|
|
5
18
|
readonly dispatch: RunOnceDispatchPacket;
|
|
6
19
|
readonly worktree: WorktreeHandle;
|
|
@@ -9,6 +22,19 @@ export interface ProviderCliRunContext {
|
|
|
9
22
|
readonly hostLoadEnvironment?: Readonly<Record<string, string>>;
|
|
10
23
|
readonly processRunner?: ProviderProcessRunner;
|
|
11
24
|
readonly signal?: AbortSignal;
|
|
25
|
+
/**
|
|
26
|
+
* Restarts the attempt's host runtime stack when the workspace changed since it was
|
|
27
|
+
* launched (an uncommitted edit, an in-progress merge), so validation and repair
|
|
28
|
+
* turns run against the current source. Resolves to the refreshed runtime
|
|
29
|
+
* environment and why the stack restarted, or null when the stack is current or
|
|
30
|
+
* there is no configured project.
|
|
31
|
+
*/
|
|
32
|
+
refreshRuntimeEnvironment?(signal?: AbortSignal): Promise<RuntimeEnvironmentRefresh | null>;
|
|
33
|
+
/**
|
|
34
|
+
* The runtime environment keys that name the configured project's live stack (its URLs and
|
|
35
|
+
* ports). A failed restart withholds them from the repair turn, since the stack is down.
|
|
36
|
+
*/
|
|
37
|
+
readonly runtimeStackEnvironmentKeys?: readonly string[];
|
|
12
38
|
emit(event: RunnerDispatchEvent): Promise<void>;
|
|
13
39
|
}
|
|
14
40
|
export interface ProviderCliDraftContext {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { HostRequirementsCheck } from "../runtime/host-runtime-requirements-check.js";
|
|
2
2
|
import type { HostRuntimeReadinessProbeRequest, HostRuntimeReadinessProbeResult, RunOnceDispatchPacket, RunOnceResultPacket, RunnerDispatchEvent } from "./session.types.js";
|
|
3
|
-
import type {
|
|
3
|
+
import type { RunnerHostDefaults } from "../runtime/runner-settings.js";
|
|
4
|
+
import type { HostCapacityLimits, HostRuntimeCapacitySnapshot, HostRuntimeReapOptions, HostRuntimeReapReport } from "../runtime/host-runtime-lease.js";
|
|
4
5
|
export interface SessionEventSink {
|
|
5
6
|
emit(event: RunnerDispatchEvent): Promise<void>;
|
|
6
7
|
}
|
|
@@ -12,4 +13,8 @@ export interface SessionService {
|
|
|
12
13
|
probeHostRuntime?(request: HostRuntimeReadinessProbeRequest, signal?: AbortSignal): Promise<HostRuntimeReadinessProbeResult>;
|
|
13
14
|
/** Decision 0013: host attempts recheck the project's requirements before starting. */
|
|
14
15
|
setHostRequirementsCheck?(check: HostRequirementsCheck | null): void;
|
|
16
|
+
/** Decision 0014: the host's max attempts and memory reserve defaults; null without host attempts. */
|
|
17
|
+
runnerLimitDefaults?(): RunnerHostDefaults | null;
|
|
18
|
+
/** Decision 0014: applies the effective max attempts and memory reserve to host attempt admission. */
|
|
19
|
+
applyRunnerLimits?(limits: HostCapacityLimits): void | Promise<void>;
|
|
15
20
|
}
|
|
@@ -3,13 +3,18 @@ import type { ProviderCliService } from "./provider-cli/provider-cli.base.js";
|
|
|
3
3
|
import type { SessionEventSink, SessionService } from "./session.base.js";
|
|
4
4
|
import type { HostRuntimeReadinessProbeRequest, HostRuntimeReadinessProbeResult, RunOnceDispatchPacket, RunOnceResultPacket } from "./session.types.js";
|
|
5
5
|
import type { WorktreeService } from "../worktree/worktree.base.js";
|
|
6
|
-
import { type HostRuntimeCapacitySnapshot, type HostRuntimeLeaseRuntime, type HostRuntimeReapOptions, type HostRuntimeReapReport } from "../runtime/host-runtime-lease.js";
|
|
6
|
+
import { type HostCapacityLimits, type HostRuntimeCapacitySnapshot, type HostRuntimeLeaseRuntime, type HostRuntimeReapOptions, type HostRuntimeReapReport } from "../runtime/host-runtime-lease.js";
|
|
7
|
+
import type { RunnerHostDefaults } from "../runtime/runner-settings.js";
|
|
8
|
+
import { type WorkspaceRuntimeFingerprintReader } from "./workspace-runtime-fingerprint.js";
|
|
7
9
|
export declare class BridgeSessionService implements SessionService {
|
|
8
10
|
private readonly worktrees;
|
|
9
11
|
private readonly providerCli;
|
|
10
12
|
private readonly hostRuntime?;
|
|
11
|
-
|
|
13
|
+
private readonly workspaceFingerprint;
|
|
14
|
+
constructor(worktrees?: WorktreeService, providerCli?: ProviderCliService, hostRuntime?: HostRuntimeLeaseRuntime | undefined, workspaceFingerprint?: WorkspaceRuntimeFingerprintReader);
|
|
12
15
|
setHostRequirementsCheck(check: HostRequirementsCheck | null): void;
|
|
16
|
+
runnerLimitDefaults(): RunnerHostDefaults | null;
|
|
17
|
+
applyRunnerLimits(limits: HostCapacityLimits): void;
|
|
13
18
|
updateLease(dispatchAttemptId: string, fencingToken: string, expiresAt: string): Promise<void>;
|
|
14
19
|
reapHostRuntime(options: HostRuntimeReapOptions): Promise<HostRuntimeReapReport | null>;
|
|
15
20
|
runtimeCapacity(): HostRuntimeCapacitySnapshot | null;
|
|
@@ -4,23 +4,32 @@ import { RoutingProviderCliService } from "./provider-cli/provider-cli.service.j
|
|
|
4
4
|
import { ForgeFailureError, waitKindForEvent, waitWakeCondition } from "./session.types.js";
|
|
5
5
|
import { GitWorktreeService } from "../worktree/worktree.service.js";
|
|
6
6
|
import { SandboxWorkspaceService } from "../sandbox/workspace.service.js";
|
|
7
|
-
import { HostRuntimeAdmissionExpiredError, hostRuntimeEventResources, runtimeAdmissionPriority, } from "../runtime/host-runtime-lease.js";
|
|
7
|
+
import { HostRuntimeAdmissionExpiredError, hostRuntimeEventResources, hostRuntimeStackEnvironmentKeys, runtimeAdmissionPriority, } from "../runtime/host-runtime-lease.js";
|
|
8
8
|
import { configuredLaunchPortNames, hostRuntimeContractFingerprint, hostRuntimeParallelEligible, } from "../runtime/host-runtime-promotion.js";
|
|
9
|
+
import { readWorkspaceRuntimeFingerprint, sameWorkspaceRuntimeFingerprint, workspaceRuntimeFingerprintChanges, } from "./workspace-runtime-fingerprint.js";
|
|
9
10
|
const minimumReadinessProbeStartupBudgetMs = 150_000;
|
|
10
11
|
export class BridgeSessionService {
|
|
11
12
|
worktrees;
|
|
12
13
|
providerCli;
|
|
13
14
|
hostRuntime;
|
|
15
|
+
workspaceFingerprint;
|
|
14
16
|
constructor(worktrees = process.env.FORGE_SANDBOX_ID
|
|
15
17
|
? new SandboxWorkspaceService()
|
|
16
|
-
: new GitWorktreeService(), providerCli = new RoutingProviderCliService(), hostRuntime) {
|
|
18
|
+
: new GitWorktreeService(), providerCli = new RoutingProviderCliService(), hostRuntime, workspaceFingerprint = readWorkspaceRuntimeFingerprint) {
|
|
17
19
|
this.worktrees = worktrees;
|
|
18
20
|
this.providerCli = providerCli;
|
|
19
21
|
this.hostRuntime = hostRuntime;
|
|
22
|
+
this.workspaceFingerprint = workspaceFingerprint;
|
|
20
23
|
}
|
|
21
24
|
setHostRequirementsCheck(check) {
|
|
22
25
|
this.hostRuntime?.setRequirementsCheck?.(check);
|
|
23
26
|
}
|
|
27
|
+
runnerLimitDefaults() {
|
|
28
|
+
return this.hostRuntime?.capacityLimitDefaults?.() ?? null;
|
|
29
|
+
}
|
|
30
|
+
applyRunnerLimits(limits) {
|
|
31
|
+
this.hostRuntime?.applyCapacityLimits?.(limits);
|
|
32
|
+
}
|
|
24
33
|
async updateLease(dispatchAttemptId, fencingToken, expiresAt) {
|
|
25
34
|
await this.hostRuntime?.updateLease(dispatchAttemptId, fencingToken, expiresAt);
|
|
26
35
|
}
|
|
@@ -338,6 +347,92 @@ export class BridgeSessionService {
|
|
|
338
347
|
});
|
|
339
348
|
}
|
|
340
349
|
}
|
|
350
|
+
// The stack was built and launched from this workspace state. Pre-publication
|
|
351
|
+
// validation restarts it when the provider has changed the source since.
|
|
352
|
+
let refreshRuntimeEnvironment;
|
|
353
|
+
const hostRuntime = this.hostRuntime;
|
|
354
|
+
if (hostLease && dispatch.sandbox && hostRuntime?.restartConfiguredProject
|
|
355
|
+
&& hostLease.executionClass === "managed_runtime"
|
|
356
|
+
&& configuredLaunchPortNames(hostLease.runtimeContract).length > 0) {
|
|
357
|
+
const worktreePath = worktree.worktreePath;
|
|
358
|
+
const dispatchAttemptId = dispatch.sandbox.dispatchAttemptId;
|
|
359
|
+
const fencingToken = dispatch.lease.fencingToken;
|
|
360
|
+
const restartConfiguredProject = hostRuntime.restartConfiguredProject.bind(hostRuntime);
|
|
361
|
+
let launchFingerprint = await this.workspaceFingerprint(worktreePath)
|
|
362
|
+
.catch(() => null);
|
|
363
|
+
// Set while the stack may not match the workspace: a failed restart is retried on the next pass.
|
|
364
|
+
let restartPending = false;
|
|
365
|
+
refreshRuntimeEnvironment = async (refreshSignal) => {
|
|
366
|
+
const current = await this.workspaceFingerprint(worktreePath).catch(() => null);
|
|
367
|
+
if (!restartPending && sameWorkspaceRuntimeFingerprint(launchFingerprint, current))
|
|
368
|
+
return null;
|
|
369
|
+
// Every cause that applies is reported; `reason` is the first of them. Changes are named
|
|
370
|
+
// only when both states were read: an unreadable baseline is not a workspace change.
|
|
371
|
+
const comparable = launchFingerprint !== null && current !== null;
|
|
372
|
+
const changes = comparable ? workspaceRuntimeFingerprintChanges(launchFingerprint, current) : [];
|
|
373
|
+
const causes = [
|
|
374
|
+
...(restartPending ? ["previous_restart_incomplete"] : []),
|
|
375
|
+
...(comparable ? [] : ["fingerprint_unavailable"]),
|
|
376
|
+
...(changes.length > 0 ? ["workspace_changed"] : []),
|
|
377
|
+
];
|
|
378
|
+
const reason = causes[0] ?? "workspace_changed";
|
|
379
|
+
const changeText = changes.length > 0 ? ` The workspace also changed since launch (${changes.join(", ")}).` : "";
|
|
380
|
+
await emitLifecycle({
|
|
381
|
+
role: "runner",
|
|
382
|
+
kind: "checkpoint",
|
|
383
|
+
content: reason === "workspace_changed"
|
|
384
|
+
? `The workspace changed since the attempt runtime stack was launched (${changes.join(", ")}); restarting it so validation runs against the current source.`
|
|
385
|
+
: reason === "previous_restart_incomplete"
|
|
386
|
+
? `The previous attempt runtime restart did not complete; restarting it again so validation runs against the current source.${changeText}`
|
|
387
|
+
: `The workspace state could not be compared with the attempt runtime stack; restarting it so validation runs against the current source.`,
|
|
388
|
+
eventType: "host_runtime_restart_started",
|
|
389
|
+
data: JSON.stringify({
|
|
390
|
+
reason,
|
|
391
|
+
causes,
|
|
392
|
+
changes,
|
|
393
|
+
head_sha: current?.headSha ?? null,
|
|
394
|
+
merge_in_progress: Boolean(current?.mergeHead),
|
|
395
|
+
}),
|
|
396
|
+
});
|
|
397
|
+
restartPending = true;
|
|
398
|
+
let restarted;
|
|
399
|
+
try {
|
|
400
|
+
restarted = await restartConfiguredProject(dispatchAttemptId, fencingToken, refreshSignal ?? signal, async (checkpoint) => {
|
|
401
|
+
await emitLifecycle({
|
|
402
|
+
role: "runner",
|
|
403
|
+
kind: "checkpoint",
|
|
404
|
+
content: checkpoint.message,
|
|
405
|
+
eventType: checkpoint.code,
|
|
406
|
+
data: checkpoint.data ? JSON.stringify(checkpoint.data) : undefined,
|
|
407
|
+
});
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
catch (error) {
|
|
411
|
+
await emitLifecycle({
|
|
412
|
+
role: "runner",
|
|
413
|
+
kind: "error",
|
|
414
|
+
content: `Restarting the attempt runtime stack failed: ${failureMessage(error)}`,
|
|
415
|
+
eventType: "host_runtime_restart_failed",
|
|
416
|
+
data: JSON.stringify({ reason, causes, changes }),
|
|
417
|
+
}).catch(() => undefined);
|
|
418
|
+
throw error;
|
|
419
|
+
}
|
|
420
|
+
hostLease = restarted;
|
|
421
|
+
// The restarted stack serves the workspace as it is now. Read that state again rather than
|
|
422
|
+
// keep the pre-restart reading, which is null when it could not be collected; a null
|
|
423
|
+
// baseline never matches, so every later pass would restart and rotate ports again.
|
|
424
|
+
launchFingerprint = await this.workspaceFingerprint(worktreePath).catch(() => current);
|
|
425
|
+
restartPending = false;
|
|
426
|
+
await emitLifecycle({
|
|
427
|
+
role: "runner",
|
|
428
|
+
kind: "checkpoint",
|
|
429
|
+
content: `Restarted the supervised project runtime on ${restarted.lease.resources.ports.map(port => `${port.name} ${port.hostIp}:${port.hostPort}`).join(", ") || "no ports"}.`,
|
|
430
|
+
eventType: "host_runtime_restarted",
|
|
431
|
+
data: JSON.stringify(hostRuntimeEventResources(restarted.lease, restarted.runtimeContract, restarted.executionClass)),
|
|
432
|
+
});
|
|
433
|
+
return { environment: restarted.environment, reason, changes };
|
|
434
|
+
};
|
|
435
|
+
}
|
|
341
436
|
providerDispatch = withMaterializedManagedQaTarget(providerDispatch, hostLease);
|
|
342
437
|
const providerEnvironment = {
|
|
343
438
|
runtimeEnvironment: hostLease?.environment,
|
|
@@ -384,6 +479,9 @@ export class BridgeSessionService {
|
|
|
384
479
|
processRunner: hostLease && dispatch.sandbox
|
|
385
480
|
? this.hostRuntime?.providerProcessRunner?.(dispatch.sandbox.dispatchAttemptId, dispatch.lease.fencingToken) ?? undefined
|
|
386
481
|
: undefined,
|
|
482
|
+
...(refreshRuntimeEnvironment && hostLease
|
|
483
|
+
? { refreshRuntimeEnvironment, runtimeStackEnvironmentKeys: hostRuntimeStackEnvironmentKeys(hostLease.runtimeContract) }
|
|
484
|
+
: {}),
|
|
387
485
|
emit,
|
|
388
486
|
signal
|
|
389
487
|
};
|
|
@@ -469,7 +469,7 @@ function unvalidatedFailureFactsForCode(code, source) {
|
|
|
469
469
|
if (code === "bridge.unavailable") {
|
|
470
470
|
return facts(code, "transport", "offer", source, "retryable", "retry_dispatch");
|
|
471
471
|
}
|
|
472
|
-
if (["capacity_unavailable", "bridge.runner_draining", "docker_engine_unavailable", "docker_memory_low", "docker_memory_sample_unavailable", "docker_cpu_low", "docker_disk_low", "server_local.resource_pressure", "server_local.capacity_unavailable", "dispatch.preparation_resource_pressure", "sandbox_capacity_profile_unavailable", "host_runtime_admission_expired", "placement_requirements_unmet"].includes(code)) {
|
|
472
|
+
if (["capacity_unavailable", "bridge.runner_draining", "docker_engine_unavailable", "docker_memory_low", "docker_memory_sample_unavailable", "docker_cpu_low", "docker_disk_low", "server_local.resource_pressure", "server_local.capacity_unavailable", "dispatch.preparation_resource_pressure", "sandbox_capacity_profile_unavailable", "host_runtime_admission_expired", "placement_requirements_unmet", "runner_yielding", "runner_settings_pending", "runner_settings_apply_failed", "runner_tier_light", "runner_project_not_allowed"].includes(code)) {
|
|
473
473
|
return facts(code, "resource", "offer", source, "retryable", "retry_dispatch");
|
|
474
474
|
}
|
|
475
475
|
if (["bridge.lease_retry_exhausted", "bridge.capacity_wait_exhausted"].includes(code)) {
|
|
@@ -496,7 +496,7 @@ function unvalidatedFailureFactsForCode(code, source) {
|
|
|
496
496
|
if (code === "provider_configuration_invalid") {
|
|
497
497
|
return facts(code, "provider", "prepare", source, "non_retryable", "fix_environment");
|
|
498
498
|
}
|
|
499
|
-
if (["host_port_collision", "host_runtime_process_exited", "host_runtime_listener_timeout", "host_runtime_http_readiness_timeout", "host_runtime_prepared_source_changed", "host_runtime_prepared_probe_incomplete", "host_runtime_prepared_probe_cleanup_unconfirmed"].includes(code)) {
|
|
499
|
+
if (["host_port_collision", "host_runtime_process_exited", "host_runtime_listener_timeout", "host_runtime_http_readiness_timeout", "host_runtime_prepared_source_changed", "host_runtime_contract_changed", "host_runtime_prepared_probe_incomplete", "host_runtime_prepared_probe_cleanup_unconfirmed"].includes(code)) {
|
|
500
500
|
return facts(code, "resource", "prepare", source, "retryable", "retry_dispatch");
|
|
501
501
|
}
|
|
502
502
|
if (code === "host_runtime_project_start_failed") {
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { GitClient } from "../shared/git/git.js";
|
|
2
|
+
/**
|
|
3
|
+
* What the attempt's host runtime stack was built and launched from. When the
|
|
4
|
+
* workspace no longer matches, the running API binary and dev server are stale:
|
|
5
|
+
* an uncommitted edit or an in-progress `merge --no-commit` changes the source
|
|
6
|
+
* without moving HEAD.
|
|
7
|
+
*/
|
|
8
|
+
export interface WorkspaceRuntimeFingerprint {
|
|
9
|
+
readonly headSha: string;
|
|
10
|
+
/** Contents of MERGE_HEAD while a merge is in progress, else null. */
|
|
11
|
+
readonly mergeHead: string | null;
|
|
12
|
+
/** sha256 of `git diff HEAD --binary` (staged and unstaged changes to tracked files, mode changes included). */
|
|
13
|
+
readonly diffDigest: string;
|
|
14
|
+
/**
|
|
15
|
+
* sha256 over untracked, non-ignored file names, their executable bit, and their contents (or
|
|
16
|
+
* size and mtime for large files).
|
|
17
|
+
*/
|
|
18
|
+
readonly untrackedDigest: string;
|
|
19
|
+
/**
|
|
20
|
+
* sha256 over the runtime contract as loaded now and the files its launch commands name. Git's
|
|
21
|
+
* views above skip ignored files, and a project may ignore its contract or a launch script; a
|
|
22
|
+
* change there alters what the stack runs without changing anything git reports.
|
|
23
|
+
*/
|
|
24
|
+
readonly runtimeInputsDigest: string;
|
|
25
|
+
/** One digest over every field above. */
|
|
26
|
+
readonly digest: string;
|
|
27
|
+
}
|
|
28
|
+
export type WorkspaceRuntimeFingerprintReader = (worktreePath: string) => Promise<WorkspaceRuntimeFingerprint>;
|
|
29
|
+
export declare function readWorkspaceRuntimeFingerprint(worktreePath: string, git?: Pick<GitClient, "run">): Promise<WorkspaceRuntimeFingerprint>;
|
|
30
|
+
export declare function sameWorkspaceRuntimeFingerprint(left: WorkspaceRuntimeFingerprint | null, right: WorkspaceRuntimeFingerprint | null): boolean;
|
|
31
|
+
/** Names what changed between two fingerprints, for the restart checkpoint. */
|
|
32
|
+
export declare function workspaceRuntimeFingerprintChanges(previous: WorkspaceRuntimeFingerprint | null, current: WorkspaceRuntimeFingerprint): readonly string[];
|