@loucompanion/forge-bridge 0.1.4-dev.028808a841c8 → 0.1.4-dev.19e5db286f12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/bridge/bridge.service.js +4 -3
- package/dist/cli/cli.service.js +3 -1
- package/dist/runtime/host-load-admission.d.ts +52 -0
- package/dist/runtime/host-load-admission.js +84 -0
- package/dist/runtime/host-load-forge-cgroups.d.ts +8 -0
- package/dist/runtime/host-load-forge-cgroups.js +51 -0
- package/dist/runtime/host-load-governor-config.d.ts +34 -0
- package/dist/runtime/host-load-governor-config.js +46 -0
- package/dist/runtime/host-load-governor.d.ts +123 -0
- package/dist/runtime/host-load-governor.js +415 -0
- package/dist/runtime/host-load-ledger-lock.d.ts +69 -0
- package/dist/runtime/host-load-ledger-lock.js +185 -0
- package/dist/runtime/host-load-sampler.d.ts +38 -0
- package/dist/runtime/host-load-sampler.js +66 -6
- package/dist/runtime/host-load-step-class.d.ts +33 -0
- package/dist/runtime/host-load-step-class.js +46 -0
- package/dist/runtime/host-load-token-ledger.d.ts +135 -0
- package/dist/runtime/host-load-token-ledger.js +345 -0
- package/dist/runtime/host-pressure-stall.d.ts +21 -1
- package/dist/runtime/host-pressure-stall.js +48 -1
- package/dist/runtime/host-runtime-lease.d.ts +7 -1
- package/dist/runtime/host-runtime-lease.js +12 -2
- package/dist/session/pre-publication-host-load.d.ts +27 -0
- package/dist/session/pre-publication-host-load.js +96 -0
- package/dist/session/pre-publication-step-execution.d.ts +11 -0
- package/dist/session/pre-publication-step-execution.js +49 -0
- package/dist/session/pre-publication-validation.d.ts +9 -9
- package/dist/session/pre-publication-validation.js +17 -55
- package/dist/session/provider-cli/provider-cli.process.d.ts +7 -0
- package/dist/session/provider-cli/provider-cli.process.js +13 -5
- package/dist/session/provider-cli/provider-cli.service.js +28 -5
- package/dist/session/session.types.js +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { PrePublicationExecutionContext } from "./pre-publication-validation.js";
|
|
2
|
+
export interface ValidationStep {
|
|
3
|
+
readonly command: string;
|
|
4
|
+
readonly fallbackCommand?: string;
|
|
5
|
+
readonly args: readonly string[];
|
|
6
|
+
readonly fallbackArgs?: readonly string[];
|
|
7
|
+
readonly assertUnchangedPaths?: readonly string[];
|
|
8
|
+
}
|
|
9
|
+
export declare function managedAttemptInvocation(checkId: string, step: ValidationStep, environment?: Readonly<Record<string, string>>): Pick<ValidationStep, "command" | "args">;
|
|
10
|
+
export declare function supportsNativeTestPostgresFallback(checkId: string): boolean;
|
|
11
|
+
export declare function validationExecutionForStep(checkId: string, step: ValidationStep, execution?: PrePublicationExecutionContext, postgresAdminConnection?: string): PrePublicationExecutionContext | undefined;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { nativeTestPostgresFallbackEnvironment, parseNativeTestPostgresFallback, } from "../runtime/native-test-postgres-fallback.js";
|
|
2
|
+
import { ForgeFailureError } from "./session.types.js";
|
|
3
|
+
export function managedAttemptInvocation(checkId, step, environment) {
|
|
4
|
+
const playwrightConfig = environment?.FORGE_PLAYWRIGHT_CONFIG?.trim();
|
|
5
|
+
const attemptOwned = environment?.FORGE_E2E_OWNERSHIP_MODE === "attempt"
|
|
6
|
+
|| Boolean(environment?.FORGE_DISPATCH_ATTEMPT_ID?.trim());
|
|
7
|
+
if (checkId !== "playwright-e2e" || !attemptOwned) {
|
|
8
|
+
return step;
|
|
9
|
+
}
|
|
10
|
+
if (!playwrightConfig) {
|
|
11
|
+
throw new ForgeFailureError("prepublication_capability_unavailable", "prepublication_capability_unavailable: playwright-e2e requires the Bridge-generated FORGE_PLAYWRIGHT_CONFIG for a managed attempt.", "bridge");
|
|
12
|
+
}
|
|
13
|
+
return {
|
|
14
|
+
command: "pnpm",
|
|
15
|
+
args: ["--dir", "tests/e2e", "exec", "playwright", "test", "--config", playwrightConfig],
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
const nativeFallbackCheckIds = new Set([
|
|
19
|
+
"owned-suite-registration",
|
|
20
|
+
"dotnet-build-and-unit",
|
|
21
|
+
"comment-repair-dotnet-regression",
|
|
22
|
+
]);
|
|
23
|
+
const nativeFallbackDotnetTierScripts = [
|
|
24
|
+
"scripts/run-dotnet-test-tier.ps1",
|
|
25
|
+
"scripts/run-dotnet-test-tier-set.ps1",
|
|
26
|
+
"scripts/run-affected-dotnet-tests.mjs",
|
|
27
|
+
];
|
|
28
|
+
export function supportsNativeTestPostgresFallback(checkId) {
|
|
29
|
+
return nativeFallbackCheckIds.has(checkId);
|
|
30
|
+
}
|
|
31
|
+
export function validationExecutionForStep(checkId, step, execution, postgresAdminConnection) {
|
|
32
|
+
// The connection only exists when Docker is unavailable and the operator
|
|
33
|
+
// provisioned a dedicated native test cluster. Only the runner-authored
|
|
34
|
+
// .NET test tiers and the suite-identity check receive it; build, client,
|
|
35
|
+
// Bridge, and E2E steps never do.
|
|
36
|
+
if (!postgresAdminConnection || !nativeFallbackCheckIds.has(checkId))
|
|
37
|
+
return execution;
|
|
38
|
+
const runsDotnetTier = step.args.some(argument => nativeFallbackDotnetTierScripts
|
|
39
|
+
.some(script => argument.replaceAll("\\", "/").endsWith(script)));
|
|
40
|
+
if (checkId !== "owned-suite-registration" && !runsDotnetTier)
|
|
41
|
+
return execution;
|
|
42
|
+
return {
|
|
43
|
+
...execution,
|
|
44
|
+
environment: {
|
|
45
|
+
...execution?.environment,
|
|
46
|
+
...nativeTestPostgresFallbackEnvironment(parseNativeTestPostgresFallback(postgresAdminConnection)),
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
import type { DockerEngineProbe } from "../runtime/docker-engine-probe.js";
|
|
2
|
-
import {
|
|
2
|
+
import type { NativeTestPostgresFallback } from "../runtime/native-test-postgres-fallback.js";
|
|
3
|
+
import type { HostLoadStepGate } from "../runtime/host-load-governor.js";
|
|
4
|
+
import { type PrePublicationHostLoadOwner } from "./pre-publication-host-load.js";
|
|
5
|
+
import { type ValidationStep } from "./pre-publication-step-execution.js";
|
|
3
6
|
import type { ProviderProcessRunner } from "./provider-cli/provider-cli.process.js";
|
|
4
7
|
import { ForgeFailureError, type RunnerDispatchEvent } from "./session.types.js";
|
|
5
8
|
export type PrePublicationProfile = "implementation" | "comment_repair" | "ci_repair" | "conflict_repair";
|
|
6
|
-
interface ValidationStep {
|
|
7
|
-
readonly command: string;
|
|
8
|
-
readonly fallbackCommand?: string;
|
|
9
|
-
readonly args: readonly string[];
|
|
10
|
-
readonly fallbackArgs?: readonly string[];
|
|
11
|
-
readonly assertUnchangedPaths?: readonly string[];
|
|
12
|
-
}
|
|
13
9
|
interface ValidationCheck {
|
|
14
10
|
readonly id: string;
|
|
15
11
|
readonly profiles: readonly string[];
|
|
@@ -36,6 +32,8 @@ export interface PrePublicationExecutionContext {
|
|
|
36
32
|
readonly baselineRevision?: string;
|
|
37
33
|
readonly environment?: Readonly<Record<string, string>>;
|
|
38
34
|
readonly processRunner?: ProviderProcessRunner;
|
|
35
|
+
/** The attempt governed steps reserve host capacity for (decision 0013). */
|
|
36
|
+
readonly hostLoadOwner?: PrePublicationHostLoadOwner;
|
|
39
37
|
}
|
|
40
38
|
export declare class PrePublicationValidationError extends ForgeFailureError {
|
|
41
39
|
readonly checkId: string;
|
|
@@ -59,7 +57,8 @@ export declare class PrePublicationValidator {
|
|
|
59
57
|
private readonly commands;
|
|
60
58
|
private readonly dockerEngineProbe?;
|
|
61
59
|
private readonly nativeTestPostgresFallback;
|
|
62
|
-
|
|
60
|
+
private readonly hostLoad?;
|
|
61
|
+
constructor(commands?: PrePublicationCommandRunner, dockerEngineProbe?: DockerEngineProbe | undefined, nativeTestPostgresFallback?: () => NativeTestPostgresFallback | null, hostLoad?: HostLoadStepGate | undefined);
|
|
63
62
|
validate(worktreePath: string, profile: PrePublicationProfile, capabilities: ReadonlySet<string>, emit?: (event: RunnerDispatchEvent) => Promise<void>, signal?: AbortSignal, execution?: PrePublicationExecutionContext): Promise<readonly string[]>;
|
|
64
63
|
/** Returns the native fallback connection when this check must use it instead of Docker. */
|
|
65
64
|
private ensurePrerequisite;
|
|
@@ -68,6 +67,7 @@ export declare class PrePublicationValidator {
|
|
|
68
67
|
private changedPaths;
|
|
69
68
|
private assertContractMatchesDispatchBaseline;
|
|
70
69
|
private runStep;
|
|
70
|
+
private launchStep;
|
|
71
71
|
private runCommand;
|
|
72
72
|
}
|
|
73
73
|
export declare function applicableChecks(contract: ValidationContract, profile: PrePublicationProfile | "github_actions", changedPaths: readonly string[]): readonly ValidationCheck[];
|
|
@@ -3,7 +3,8 @@ import fs from "node:fs/promises";
|
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { attemptDatabaseCapabilityEnvironment, attemptDatabaseCapabilitySecrets, } from "../runtime/attempt-database-broker.js";
|
|
5
5
|
import { assertHostDatabaseCapabilityBoundary } from "../runtime/host-database-capability-boundary.js";
|
|
6
|
-
import {
|
|
6
|
+
import { runHostGovernedValidationStep } from "./pre-publication-host-load.js";
|
|
7
|
+
import { managedAttemptInvocation, supportsNativeTestPostgresFallback, validationExecutionForStep, } from "./pre-publication-step-execution.js";
|
|
7
8
|
import { hostRuntimeLegacyTestPostgresEnvironment, hostRuntimeTestPostgresAdminEnvironment, hostRuntimeTestPostgresProvisionerEnvironment, } from "../runtime/host-runtime-contract.js";
|
|
8
9
|
import { redactText } from "../shared/redaction/redaction.js";
|
|
9
10
|
import { describeSkippedTests, mergeSkippedTests, readSkippedTests, } from "./pre-publication-skipped-tests.js";
|
|
@@ -84,10 +85,12 @@ export class PrePublicationValidator {
|
|
|
84
85
|
commands;
|
|
85
86
|
dockerEngineProbe;
|
|
86
87
|
nativeTestPostgresFallback;
|
|
87
|
-
|
|
88
|
+
hostLoad;
|
|
89
|
+
constructor(commands = new ProcessPrePublicationCommandRunner(), dockerEngineProbe, nativeTestPostgresFallback = () => null, hostLoad) {
|
|
88
90
|
this.commands = commands;
|
|
89
91
|
this.dockerEngineProbe = dockerEngineProbe;
|
|
90
92
|
this.nativeTestPostgresFallback = nativeTestPostgresFallback;
|
|
93
|
+
this.hostLoad = hostLoad;
|
|
91
94
|
}
|
|
92
95
|
async validate(worktreePath, profile, capabilities, emit, signal, execution) {
|
|
93
96
|
const checksExports = profile === "implementation" || profile === "comment_repair";
|
|
@@ -130,11 +133,11 @@ export class PrePublicationValidator {
|
|
|
130
133
|
let skipped = { count: 0, reasons: [] };
|
|
131
134
|
for (const step of check.steps) {
|
|
132
135
|
const stepStartedMs = Date.now() - 1000;
|
|
133
|
-
let result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection);
|
|
136
|
+
let result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection, emit);
|
|
134
137
|
await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
|
|
135
138
|
if (isTimeoutOnlyClientTestFailure(check.id, step, result)) {
|
|
136
139
|
await emit?.(validationEvent("prepublication_validation_timeout_confirmation_started", check.id, "The full client test step reported only Vitest timeouts; confirming once with the same command and attempt environment."));
|
|
137
|
-
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection);
|
|
140
|
+
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection, emit);
|
|
138
141
|
await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
|
|
139
142
|
await emit?.(validationEvent(result.exitCode === 0
|
|
140
143
|
? "prepublication_validation_timeout_confirmation_passed"
|
|
@@ -144,7 +147,7 @@ export class PrePublicationValidator {
|
|
|
144
147
|
}
|
|
145
148
|
if (isTransientBridgeCleanupFailure(check.id, step, result)) {
|
|
146
149
|
await emit?.(validationEvent("prepublication_validation_cleanup_confirmation_started", check.id, "The Bridge suite hit the known Windows temporary-worktree cleanup race; confirming once with the same command and attempt environment."));
|
|
147
|
-
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection);
|
|
150
|
+
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection, emit);
|
|
148
151
|
await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
|
|
149
152
|
await emit?.(validationEvent(result.exitCode === 0
|
|
150
153
|
? "prepublication_validation_cleanup_confirmation_passed"
|
|
@@ -154,7 +157,7 @@ export class PrePublicationValidator {
|
|
|
154
157
|
}
|
|
155
158
|
if (isTransientShellInfrastructureFailure(result)) {
|
|
156
159
|
await emit?.(validationEvent("prepublication_infrastructure_confirmation_started", check.id, "The validation shell reported a known host-runtime failure; confirming once with the same command and attempt environment."));
|
|
157
|
-
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection);
|
|
160
|
+
result = await this.runStep(check.id, step, worktreePath, signal, scoped.execution, postgresAdminConnection, emit);
|
|
158
161
|
await this.throwIfPrerequisiteWasLost(check, result, scoped.execution?.environment, postgresAdminConnection, emit);
|
|
159
162
|
const infrastructureFailed = isTransientShellInfrastructureFailure(result);
|
|
160
163
|
await emit?.(validationEvent(infrastructureFailed
|
|
@@ -213,7 +216,7 @@ export class PrePublicationValidator {
|
|
|
213
216
|
const snapshot = await this.dockerEngineProbe.ensureAvailableForRequiredWork();
|
|
214
217
|
if (!snapshot.available) {
|
|
215
218
|
const detail = `Docker prerequisite unavailable (${snapshot.unavailableCode ?? "docker_engine_unavailable"}): ${snapshot.unavailableReason ?? "the daemon did not pass a fresh readiness probe"}`;
|
|
216
|
-
const fallback = check.requiredPrerequisite === "isolated_postgres" && supportsNativeTestPostgresFallback(check)
|
|
219
|
+
const fallback = check.requiredPrerequisite === "isolated_postgres" && supportsNativeTestPostgresFallback(check.id)
|
|
217
220
|
? this.nativeTestPostgresFallback()
|
|
218
221
|
: null;
|
|
219
222
|
if (fallback) {
|
|
@@ -299,8 +302,14 @@ export class PrePublicationValidator {
|
|
|
299
302
|
throw new ForgeFailureError("prepublication_contract_invalid", `prepublication_contract_invalid: the CI parity contract changed after dispatch (baseline ${baselineDigest}, worktree ${contractDigest}).`, "bridge");
|
|
300
303
|
}
|
|
301
304
|
}
|
|
302
|
-
async runStep(checkId, step, cwd, signal, execution, postgresAdminConnection) {
|
|
305
|
+
async runStep(checkId, step, cwd, signal, execution, postgresAdminConnection, emit) {
|
|
303
306
|
const invocation = managedAttemptInvocation(checkId, step, execution?.environment);
|
|
307
|
+
// Every launch, including confirmation reruns, is admitted by the host load governor first.
|
|
308
|
+
return await runHostGovernedValidationStep(this.hostLoad, {
|
|
309
|
+
checkId, command: invocation.command, args: invocation.args, owner: execution?.hostLoadOwner, signal, emit,
|
|
310
|
+
}, async (stepSignal) => await this.launchStep(checkId, step, invocation, cwd, stepSignal, execution, postgresAdminConnection));
|
|
311
|
+
}
|
|
312
|
+
async launchStep(checkId, step, invocation, cwd, signal, execution, postgresAdminConnection) {
|
|
304
313
|
const stepExecution = validationExecutionForStep(checkId, step, execution, postgresAdminConnection);
|
|
305
314
|
const before = await readValidationFiles(cwd, step.assertUnchangedPaths ?? []);
|
|
306
315
|
const result = await this.runCommand(invocation.command, invocation.args, cwd, signal, stepExecution);
|
|
@@ -349,53 +358,6 @@ export class PrePublicationValidator {
|
|
|
349
358
|
}
|
|
350
359
|
}
|
|
351
360
|
}
|
|
352
|
-
function managedAttemptInvocation(checkId, step, environment) {
|
|
353
|
-
const playwrightConfig = environment?.FORGE_PLAYWRIGHT_CONFIG?.trim();
|
|
354
|
-
const attemptOwned = environment?.FORGE_E2E_OWNERSHIP_MODE === "attempt"
|
|
355
|
-
|| Boolean(environment?.FORGE_DISPATCH_ATTEMPT_ID?.trim());
|
|
356
|
-
if (checkId !== "playwright-e2e" || !attemptOwned) {
|
|
357
|
-
return step;
|
|
358
|
-
}
|
|
359
|
-
if (!playwrightConfig) {
|
|
360
|
-
throw new ForgeFailureError("prepublication_capability_unavailable", "prepublication_capability_unavailable: playwright-e2e requires the Bridge-generated FORGE_PLAYWRIGHT_CONFIG for a managed attempt.", "bridge");
|
|
361
|
-
}
|
|
362
|
-
return {
|
|
363
|
-
command: "pnpm",
|
|
364
|
-
args: ["--dir", "tests/e2e", "exec", "playwright", "test", "--config", playwrightConfig],
|
|
365
|
-
};
|
|
366
|
-
}
|
|
367
|
-
const nativeFallbackCheckIds = new Set([
|
|
368
|
-
"owned-suite-registration",
|
|
369
|
-
"dotnet-build-and-unit",
|
|
370
|
-
"comment-repair-dotnet-regression",
|
|
371
|
-
]);
|
|
372
|
-
const nativeFallbackDotnetTierScripts = [
|
|
373
|
-
"scripts/run-dotnet-test-tier.ps1",
|
|
374
|
-
"scripts/run-dotnet-test-tier-set.ps1",
|
|
375
|
-
"scripts/run-affected-dotnet-tests.mjs",
|
|
376
|
-
];
|
|
377
|
-
function supportsNativeTestPostgresFallback(check) {
|
|
378
|
-
return nativeFallbackCheckIds.has(check.id);
|
|
379
|
-
}
|
|
380
|
-
function validationExecutionForStep(checkId, step, execution, postgresAdminConnection) {
|
|
381
|
-
// The connection only exists when Docker is unavailable and the operator
|
|
382
|
-
// provisioned a dedicated native test cluster. Only the runner-authored
|
|
383
|
-
// .NET test tiers and the suite-identity check receive it; build, client,
|
|
384
|
-
// Bridge, and E2E steps never do.
|
|
385
|
-
if (!postgresAdminConnection || !nativeFallbackCheckIds.has(checkId))
|
|
386
|
-
return execution;
|
|
387
|
-
const runsDotnetTier = step.args.some(argument => nativeFallbackDotnetTierScripts
|
|
388
|
-
.some(script => argument.replaceAll("\\", "/").endsWith(script)));
|
|
389
|
-
if (checkId !== "owned-suite-registration" && !runsDotnetTier)
|
|
390
|
-
return execution;
|
|
391
|
-
return {
|
|
392
|
-
...execution,
|
|
393
|
-
environment: {
|
|
394
|
-
...execution?.environment,
|
|
395
|
-
...nativeTestPostgresFallbackEnvironment(parseNativeTestPostgresFallback(postgresAdminConnection)),
|
|
396
|
-
},
|
|
397
|
-
};
|
|
398
|
-
}
|
|
399
361
|
function environmentValue(environment, name) {
|
|
400
362
|
return Object.prototype.hasOwnProperty.call(environment ?? {}, name)
|
|
401
363
|
? environment?.[name]?.trim() ?? ""
|
|
@@ -50,6 +50,13 @@ export interface ProviderProcessHandlers {
|
|
|
50
50
|
* end-of-turn exit grace and the success ceiling.
|
|
51
51
|
*/
|
|
52
52
|
isToolCallInFlight?(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Called before each provider generation (child process) starts, including every
|
|
55
|
+
* relaunch a recovery wrapper or supervisor makes with the same handlers. Per-generation
|
|
56
|
+
* state, such as tool calls in flight, must be reset here: a generation that exited mid
|
|
57
|
+
* call never reports that call's completion.
|
|
58
|
+
*/
|
|
59
|
+
onGenerationStart?(): void;
|
|
53
60
|
}
|
|
54
61
|
/** Recovery must wrap the attempt coordinator, never its raw OS runner. Each
|
|
55
62
|
* relaunch needs a new fenced child generation and exclusive launch files. */
|
|
@@ -51,6 +51,7 @@ export class CodexModelsCacheRecoveringProcessRunner {
|
|
|
51
51
|
const recovered = await quarantineIncompatibleCodexModelsCache(request.env).catch(() => false);
|
|
52
52
|
if (!recovered || signal?.aborted)
|
|
53
53
|
return first;
|
|
54
|
+
handlers?.onGenerationStart?.();
|
|
54
55
|
return await this.inner.run(request, handlers, signal);
|
|
55
56
|
}
|
|
56
57
|
}
|
|
@@ -73,7 +74,10 @@ export class CodexResumeRecoveringProcessRunner {
|
|
|
73
74
|
return first;
|
|
74
75
|
}
|
|
75
76
|
const fallback = codexFreshTurnRequest(request);
|
|
76
|
-
|
|
77
|
+
if (!fallback)
|
|
78
|
+
return first;
|
|
79
|
+
handlers?.onGenerationStart?.();
|
|
80
|
+
return await this.inner.run(fallback, handlers, signal);
|
|
77
81
|
}
|
|
78
82
|
}
|
|
79
83
|
function isRecoverableCodexResumeFailure(command, result) {
|
|
@@ -111,7 +115,8 @@ function codexFreshTurnRequest(request) {
|
|
|
111
115
|
const cd = args.splice(cdIndex, 2);
|
|
112
116
|
args.splice(args.length - 1, 0, ...cd);
|
|
113
117
|
}
|
|
114
|
-
|
|
118
|
+
// The fallback starts a fresh thread, so it has no replayed turn to discount.
|
|
119
|
+
return { ...request, args, resumesProviderThread: false };
|
|
115
120
|
}
|
|
116
121
|
function isCodexCommand(command) {
|
|
117
122
|
return path.parse(command).name.toLowerCase() === "codex";
|
|
@@ -329,6 +334,8 @@ export class StreamingProviderProcessRunner {
|
|
|
329
334
|
}
|
|
330
335
|
async run(request, handlers = {}, signal) {
|
|
331
336
|
assertHostDatabaseCapabilityBoundary();
|
|
337
|
+
// Every child this runner launches is a new generation, including supervisor retries.
|
|
338
|
+
handlers.onGenerationStart?.();
|
|
332
339
|
const providerLaunch = await resolveProviderProcessLaunch(request.command, request.args);
|
|
333
340
|
const supervisedLaunch = resolveHostProcessSupervisedLaunch(request, providerLaunch.command, providerLaunch.args);
|
|
334
341
|
// An unsupervised Unix provider still gets a dedicated process group so a
|
|
@@ -595,11 +602,12 @@ export class StreamingProviderProcessRunner {
|
|
|
595
602
|
// the grace period restarts at its next terminal event.
|
|
596
603
|
graceIdleMs = null;
|
|
597
604
|
// A resumed session can replay a queued notification turn before the
|
|
598
|
-
// prompt's own turn.
|
|
599
|
-
// resumed agent is stopped mid-work
|
|
605
|
+
// prompt's own turn. The replayed turn must not consume the ceiling, or the
|
|
606
|
+
// resumed agent is stopped mid-work, but the prompt's turn still needs a
|
|
607
|
+
// watchdog: restart the ceiling from here instead of dropping it.
|
|
600
608
|
if (request.resumesProviderThread && terminalSuccessCount === 1 && !replayedTurnCeilingSkipped) {
|
|
601
609
|
replayedTurnCeilingSkipped = true;
|
|
602
|
-
ceilingIdleMs =
|
|
610
|
+
ceilingIdleMs = 0;
|
|
603
611
|
}
|
|
604
612
|
}
|
|
605
613
|
}
|
|
@@ -2,6 +2,7 @@ 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";
|
|
5
6
|
import { buildSpecBody, selectLaneCommand } from "../../worktree/artifact-injector.js";
|
|
6
7
|
import { defaultWorktreeCoordinatorStateRoot } from "../../worktree/worktree-paths.js";
|
|
7
8
|
import { completionPhaseFromDispatch, prepareCompletionToolRuntime, readCompletionArtifact, usesDebugCycleCompletion, usesDevelopCycleCompletion } from "../phase-completion.js";
|
|
@@ -213,16 +214,20 @@ function providerOwnsBranchPublication(context) {
|
|
|
213
214
|
return context.dispatch.sandbox?.executionMode !== "docker";
|
|
214
215
|
}
|
|
215
216
|
function prePublicationExecution(context, environment, defaultRunner, baselineRevision) {
|
|
217
|
+
const hostLoadOwner = {
|
|
218
|
+
dispatchAttemptId: context.dispatch.sandbox?.dispatchAttemptId ?? null,
|
|
219
|
+
priority: runtimeAdmissionPriority(context.dispatch),
|
|
220
|
+
};
|
|
216
221
|
if (context.processRunner)
|
|
217
|
-
return { baselineRevision, environment, processRunner: context.processRunner };
|
|
222
|
+
return { baselineRevision, environment, processRunner: context.processRunner, hostLoadOwner };
|
|
218
223
|
if (context.dispatch.sandbox?.executionMode !== "docker")
|
|
219
|
-
return { baselineRevision, environment };
|
|
224
|
+
return { baselineRevision, environment, hostLoadOwner };
|
|
220
225
|
const expectedSandboxId = context.dispatch.sandbox.dispatchAttemptId;
|
|
221
226
|
const observedSandboxId = context.runtimeEnvironment?.FORGE_SANDBOX_ID ?? process.env.FORGE_SANDBOX_ID;
|
|
222
227
|
if (observedSandboxId !== expectedSandboxId) {
|
|
223
228
|
throw new ForgeFailureError("prepublication_execution_scope_invalid", `prepublication_execution_scope_invalid: Docker attempt ${expectedSandboxId} has no runner proven to execute inside that sandbox.`, "bridge");
|
|
224
229
|
}
|
|
225
|
-
return { baselineRevision, environment, processRunner: defaultRunner };
|
|
230
|
+
return { baselineRevision, environment, processRunner: defaultRunner, hostLoadOwner };
|
|
226
231
|
}
|
|
227
232
|
function remoteTrackingRefspec(branchName) {
|
|
228
233
|
return `refs/heads/${branchName}:refs/remotes/origin/${branchName}`;
|
|
@@ -474,6 +479,8 @@ class ProviderToolActivityHeartbeat {
|
|
|
474
479
|
timer = null;
|
|
475
480
|
/** Lets the provider runner hold its end-of-turn timers while a tool call is in flight. */
|
|
476
481
|
isToolCallInFlight = () => this.outputState.hasActiveToolCall;
|
|
482
|
+
/** Forgets tool calls a previous generation left open; called before every relaunch. */
|
|
483
|
+
startGeneration = () => this.outputState.resetActiveToolCalls();
|
|
477
484
|
constructor(outputState, emit, intervalMs) {
|
|
478
485
|
this.outputState = outputState;
|
|
479
486
|
this.emit = emit;
|
|
@@ -562,7 +569,12 @@ export class ProcessBackedProviderCliService {
|
|
|
562
569
|
providerToolHeartbeatIntervalMs;
|
|
563
570
|
publicationCoordinator;
|
|
564
571
|
prePublicationValidator;
|
|
565
|
-
constructor(processRunner = new StreamingProviderProcessRunner(), git = new GitClient(), providerToolHeartbeatIntervalMs = defaultProviderToolHeartbeatIntervalMs, publicationCoordinator = new RepositoryCoordinatorLock(defaultWorktreeCoordinatorStateRoot()),
|
|
572
|
+
constructor(processRunner = new StreamingProviderProcessRunner(), git = new GitClient(), providerToolHeartbeatIntervalMs = defaultProviderToolHeartbeatIntervalMs, publicationCoordinator = new RepositoryCoordinatorLock(defaultWorktreeCoordinatorStateRoot()),
|
|
573
|
+
// No host load gate here: the Docker sandbox worker (`forge` run-once via
|
|
574
|
+
// ForgeBridgeCliService) builds this default, and a container cannot reach the
|
|
575
|
+
// host's governor ledger, so Docker-mode validation is not yet governed
|
|
576
|
+
// (decision 0013). Only the host bridge wires HostRuntimeLeaseManager's gate.
|
|
577
|
+
prePublicationValidator = new PrePublicationValidator()) {
|
|
566
578
|
this.processRunner = processRunner;
|
|
567
579
|
this.git = git;
|
|
568
580
|
this.providerToolHeartbeatIntervalMs = providerToolHeartbeatIntervalMs;
|
|
@@ -646,6 +658,7 @@ export class ProcessBackedProviderCliService {
|
|
|
646
658
|
});
|
|
647
659
|
},
|
|
648
660
|
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
661
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
649
662
|
onStdoutLine: async (line) => {
|
|
650
663
|
await toolHeartbeat.consume(line);
|
|
651
664
|
}
|
|
@@ -817,6 +830,7 @@ export class ProcessBackedProviderCliService {
|
|
|
817
830
|
});
|
|
818
831
|
},
|
|
819
832
|
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
833
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
820
834
|
onStdoutLine: async (line) => {
|
|
821
835
|
await toolHeartbeat.consume(line);
|
|
822
836
|
}
|
|
@@ -957,6 +971,7 @@ export class ProcessBackedProviderCliService {
|
|
|
957
971
|
});
|
|
958
972
|
},
|
|
959
973
|
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
974
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
960
975
|
onStdoutLine: async (line) => await toolHeartbeat.consume(line)
|
|
961
976
|
}, context.signal);
|
|
962
977
|
}
|
|
@@ -1063,6 +1078,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1063
1078
|
});
|
|
1064
1079
|
},
|
|
1065
1080
|
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1081
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1066
1082
|
onStdoutLine: async (line) => await toolHeartbeat.consume(line)
|
|
1067
1083
|
}, context.signal);
|
|
1068
1084
|
}
|
|
@@ -1220,6 +1236,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1220
1236
|
providerStarted = true;
|
|
1221
1237
|
},
|
|
1222
1238
|
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1239
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1223
1240
|
onStdoutLine: async (line) => {
|
|
1224
1241
|
await toolHeartbeat.consume(line);
|
|
1225
1242
|
}
|
|
@@ -1402,7 +1419,11 @@ export class ProcessBackedProviderCliService {
|
|
|
1402
1419
|
env: providerProcessEnv(recoveryDispatch, context.runtimeEnvironment),
|
|
1403
1420
|
resumesProviderThread: Boolean(recoveryDispatch.session.resumeProviderThreadId),
|
|
1404
1421
|
stdin: pipePromptToStdin ? providerPrompt : undefined,
|
|
1405
|
-
}, {
|
|
1422
|
+
}, {
|
|
1423
|
+
onStdoutLine: async (line) => await toolHeartbeat.consume(line),
|
|
1424
|
+
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1425
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1426
|
+
}, context.signal);
|
|
1406
1427
|
}
|
|
1407
1428
|
finally {
|
|
1408
1429
|
toolHeartbeat.stop();
|
|
@@ -1519,6 +1540,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1519
1540
|
});
|
|
1520
1541
|
},
|
|
1521
1542
|
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1543
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1522
1544
|
onStdoutLine: async (line) => {
|
|
1523
1545
|
await toolHeartbeat.consume(line);
|
|
1524
1546
|
},
|
|
@@ -1639,6 +1661,7 @@ export class ProcessBackedProviderCliService {
|
|
|
1639
1661
|
providerStarted = true;
|
|
1640
1662
|
},
|
|
1641
1663
|
isToolCallInFlight: toolHeartbeat.isToolCallInFlight,
|
|
1664
|
+
onGenerationStart: toolHeartbeat.startGeneration,
|
|
1642
1665
|
onStdoutLine: async (line) => {
|
|
1643
1666
|
await toolHeartbeat.consume(line);
|
|
1644
1667
|
},
|
|
@@ -475,7 +475,7 @@ function unvalidatedFailureFactsForCode(code, source) {
|
|
|
475
475
|
if (["bridge.lease_retry_exhausted", "bridge.capacity_wait_exhausted"].includes(code)) {
|
|
476
476
|
return facts(code, "resource", "offer", source, "non_retryable", "inspect_failure");
|
|
477
477
|
}
|
|
478
|
-
if (["prepublication_infrastructure_failed", "prepublication_capability_unavailable"].includes(code)) {
|
|
478
|
+
if (["prepublication_infrastructure_failed", "prepublication_capability_unavailable", "host_capacity_timeout", "host_capacity_token_fenced", "host_capacity_ledger_unavailable"].includes(code)) {
|
|
479
479
|
return facts(code, "resource", "validation", source, "retryable", "retry_with_policy");
|
|
480
480
|
}
|
|
481
481
|
if (["prepublication_validation_failed", "prepublication_contract_invalid", "prepublication_execution_scope_invalid"].includes(code)) {
|
package/dist/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const forgeBridgeVersion = "0.1.4-dev.
|
|
1
|
+
export declare const forgeBridgeVersion = "0.1.4-dev.19e5db286f12";
|
package/dist/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const forgeBridgeVersion = "0.1.4-dev.
|
|
1
|
+
export const forgeBridgeVersion = "0.1.4-dev.19e5db286f12";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loucompanion/forge-bridge",
|
|
3
|
-
"version": "0.1.4-dev.
|
|
3
|
+
"version": "0.1.4-dev.19e5db286f12",
|
|
4
4
|
"description": "Forge runner bridge CLI for connecting local developer machines to Forge dispatch.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"type": "module",
|