Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 54 additions & 38 deletions test/e2e/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,14 @@ revision, or closed PR can leave the controller green while coordination is
failed or cancelled and the native job is non-passing. Only a successful native
`E2E / PR Gate` for the current head and base satisfies the required check. An
eligible prerequisite-CI failure records the versioned retry reason
`prerequisite-ci`. A selected child records `child-cancelled` only when a
trusted GitHub-hosted runner-loss annotation is bound to the exact failed job
and workflow commit and no other terminal classification was produced.
Cancellation alone is not retryable. Assertion failures and other selected-E2E
outcomes do not receive a retry reason. An unexpected controller error still
fails the controller workflow and fails coordination closed, which prevents
the native job from passing.
`prerequisite-ci`. A selected child records `child-cancelled` only when the
controller authenticates either a trusted GitHub-hosted runner-loss annotation
or the exact terminal-shutdown fallback against the failed job and workflow
commit, and no other terminal classification was produced. Cancellation alone
is not retryable. Assertion failures and other selected-E2E outcomes do not
receive a retry reason. An unexpected controller error still fails the
controller workflow and fails coordination closed, which prevents the native
job from passing.

On open, synchronization, reopen, transition out of draft, or base retarget,
`.github/workflows/pr-e2e-gate.yaml` reserves `E2E / PR Gate Coordination` for
Expand Down Expand Up @@ -578,24 +579,28 @@ attempt, workflow commit, job check, standard hosted runner group, and runner
name. The controller accepts one canonical runner-loss failure annotation bound
to `.github` at that workflow commit.

When GitHub emits a generic cancellation instead, the controller requires
exactly one failure annotation whose message is `The operation was canceled.`
The annotation must use `.github`, equal start and end lines, null columns, and
empty title and detail fields. Every annotation must use a blob URL bound to the
same workflow commit. The controller accepts at most 20 annotations, bounds
each text field, and limits the normalized annotation evidence to 64 KiB. This
permits trusted bounded non-failure notices beside the sole failure annotation
without allowing annotation output to exhaust the coordinator.

GitHub Actions creates this `.github` failure annotation after the hosted runner
shuts down; NemoClaw workflow code cannot replace its generic message with the
canonical lost-communication annotation. The classifier test `accepts the
exact authenticated terminal shutdown block from run 29988226653` preserves
the observed fallback contract. Remove the fallback and that test together
only after GitHub's documented Jobs or Checks API contract provides an
authenticated structured runner-loss reason for this exact shutdown path.

The generic-cancellation fallback also authenticates the job log. The
When GitHub emits a generic terminal result instead, the controller requires
exactly one failure annotation. Its message must be
`The operation was canceled.` for one completed `cancelled` workload step or
`Process completed with exit code 143.` for one completed `failure` workload
step. The annotation must use `.github`, equal start and end lines, null
columns, and empty title and detail fields. Every annotation must use a blob URL
bound to the same workflow commit. The controller accepts at most 20
annotations, bounds each text field, and limits the normalized annotation
evidence to 64 KiB. This permits trusted bounded non-failure notices beside the
sole failure annotation without allowing annotation output to exhaust the
coordinator.

GitHub Actions creates these `.github` failure annotations after the hosted
runner shuts down; NemoClaw workflow code cannot replace their generic messages
with the canonical lost-communication annotation. The classifier tests
`accepts the exact authenticated terminal shutdown block from run 29988226653`
and `accepts the exit-143 hosted shutdown from run 30026115852` preserve the
two observed fallback contracts. Remove a fallback and its test together only
after GitHub's documented Jobs or Checks API contract provides an authenticated
structured runner-loss reason for that shutdown path.

The terminal-shutdown fallback also authenticates the job log. The
controller requests the GitHub job-log endpoint and accepts only its signed
HTTPS redirect to GitHub Actions result storage. It does not forward the
repository token to that signed URL. A metadata request must return plain,
Expand All @@ -604,19 +609,21 @@ controller then reads at most the final 64 KiB with `If-Match` and requires an
exact partial-content range, length, and matching ETag.

The authenticated tail must end with exactly one line feed after the
timestamped shutdown error, operation-cancelled error, and orphan-cleanup
record, in that order. Up to 64 unique orphan-process termination records may
follow the cleanup record. Each record must contain a positive process ID and a
bounded process name. The record timestamps must not move backward. The
job must start no later than the cancelled step. The shutdown must occur at or
after that step starts, and the cancellation second must equal the step's
completion time. Cleanup must not precede cancellation. Cleanup and
orphan-process records must finish no later than the job completion time.

A generic cancellation without this log contract, timeout, unknown runner
identity, self-hosted or custom runner group, ordinary failed step, another
non-passing job, incomplete pagination, or mismatched annotation identity
fails closed without a retry.
timestamped shutdown error, matching operation-cancelled or exit-143 error, and
orphan-cleanup record, in that order. Up to 64 unique orphan-process termination
records may follow the cleanup record. Each record must contain a positive
process ID and a bounded process name. The record timestamps must not move
backward. The job must start no later than the interrupted step. The shutdown
must occur at or after that step starts, and the terminal-error second must
equal the step's completion time. Cleanup must not precede the terminal error.
Cleanup and orphan-process records must finish no later than the job completion
time.

A generic terminal result without this log contract, an ordinary exit 143
without the exact preceding shutdown block, timeout, unknown runner identity,
self-hosted or custom runner group, ordinary failed step, another non-passing
job, incomplete pagination, or mismatched annotation identity fails closed
without a retry.

Before the one-time retry dispatch, the controller revalidates the unchanged
internal PR head and base, original child, current coordination-check lineage,
Expand All @@ -627,6 +634,15 @@ including pagination state, log ETag, log length, and log-tail hash. After the
second classification, it validates the live PR head and base and the current
coordination-check lineage again.

The source coordination check binds that original child through the
controller-generated `Selected E2E run <run-id>` summary. The summary label,
linked run ID, repository, and exact Actions run URL must agree. GitHub may set
the check details URL to either that exact child run or the canonical
`/runs/<check-id>` URL for the source check. A malformed selected-run prefix or
any mismatch fails closed. Compatibility checks that predate the selected-run
summary remain eligible only when their details URL is the exact child Actions
run URL.

The controller reserves a distinct replacement coordination check before
dispatch so the native observer can follow the retry without mutating completed
attempt-one history. Attempt two uses separate private state and evidence paths.
Expand Down
73 changes: 55 additions & 18 deletions test/e2e/fixtures/cleanup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ type CleanupFn = () => Promise<void> | void;
type RedactFn = (text: string) => string;
type CleanupProgress = Pick<TestProgress, "activity" | "event">;
const MAX_PROGRESS_CLEANUP_NAME_LENGTH = 120;
export const DEFAULT_CLEANUP_TIMEOUT_MS = 10 * 60_000;

export interface CleanupRegistryOptions {
testSignal?: AbortSignal;
/** Shared deadline for signal-aware cleanup commands; callbacks are still awaited in order. */
timeoutMs?: number;
}

export interface CleanupHost {
cleanupSandbox(name: string, options?: ShellProbeRunOptions): Promise<void>;
Expand All @@ -34,10 +41,26 @@ export class CleanupRegistry {
private readonly entries: CleanupEntry[] = [];
private readonly redact: RedactFn;
private readonly progress?: CleanupProgress;

constructor(redact: RedactFn = (text) => text, progress?: CleanupProgress) {
private readonly testSignal: AbortSignal;
private readonly timeoutMs: number;
private cleanupController?: AbortController;

constructor(
redact: RedactFn = (text) => text,
progress?: CleanupProgress,
options: CleanupRegistryOptions = {},
) {
this.redact = redact;
this.progress = progress;
this.testSignal = options.testSignal ?? new AbortController().signal;
this.timeoutMs = options.timeoutMs ?? DEFAULT_CLEANUP_TIMEOUT_MS;
if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs <= 0) {
throw new Error("cleanup timeoutMs must be a positive safe integer");
}
}

currentSignal(): AbortSignal {
return this.cleanupController?.signal ?? this.testSignal;
}

private safeRedact(text: string): string {
Expand Down Expand Up @@ -120,25 +143,39 @@ export class CleanupRegistry {
}

async runAll(): Promise<CleanupResult> {
if (this.cleanupController) {
throw new Error("cleanup is already running");
}

const cleanupController = new AbortController();
this.cleanupController = cleanupController;
const deadline = setTimeout(() => cleanupController.abort(), this.timeoutMs);
deadline.unref();
const result: CleanupResult = { passed: [], failures: [] };
for (const entry of [...this.entries].reverse()) {
const finishProgress = this.startProgress(entry.name);
try {
await entry.run();
result.passed.push(this.safeRedact(entry.name));
this.reportProgress("passed", entry.name);
} catch (error) {
result.failures.push({
name: this.safeRedact(entry.name),
message: this.safeRedact(error instanceof Error ? error.message : String(error)),
});
this.reportProgress("failed", entry.name);
} finally {
finishProgress();
try {
for (const entry of [...this.entries].reverse()) {
const finishProgress = this.startProgress(entry.name);
try {
await entry.run();
result.passed.push(this.safeRedact(entry.name));
this.reportProgress("passed", entry.name);
} catch (error) {
result.failures.push({
name: this.safeRedact(entry.name),
message: this.safeRedact(error instanceof Error ? error.message : String(error)),
});
this.reportProgress("failed", entry.name);
} finally {
finishProgress();
}
}
return result;
} finally {
clearTimeout(deadline);
cleanupController.abort();
this.cleanupController = undefined;
this.entries.length = 0;
}
this.entries.length = 0;
return result;
}
}

Expand Down
6 changes: 4 additions & 2 deletions test/e2e/fixtures/docker-probe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { type ChildProcessProgress, spawnObservedChild } from "./observed-child-
import { buildChildEnv } from "./redaction.ts";
import type { SecretStore } from "./secrets.ts";
import { superviseChild } from "./shell/supervisor.ts";
import type { AbortSignalSource } from "./shell-probe.ts";

export type DockerCommandResult = {
command: string[];
Expand Down Expand Up @@ -104,7 +105,7 @@ export class DockerProbe {
private readonly redact: SecretStore["redact"],
private readonly runDocker?: DockerProbeRunner,
private readonly progress?: ChildProcessProgress,
private readonly signal?: AbortSignal,
private readonly signal?: AbortSignalSource,
) {
this.dockerConfigDir = fs.mkdtempSync(path.join(os.tmpdir(), "nemoclaw-docker-config-"));
}
Expand All @@ -113,6 +114,7 @@ export class DockerProbe {
args: string[],
options: DockerProbeRunOptions = { artifactName: "docker" },
): Promise<DockerCommandResult> {
const signal = typeof this.signal === "function" ? this.signal() : this.signal;
fs.mkdirSync(this.dockerConfigDir, { recursive: true });
const command = ["docker", ...args];
const timeoutMs = options.timeoutMs ?? 30_000;
Expand Down Expand Up @@ -163,7 +165,7 @@ export class DockerProbe {
const supervised = await superviseChild(child, {
timeoutMs,
killGraceMs: 1_000,
signal: this.signal,
signal,
onStdout: (chunk) => {
if (outputExceeded) return;
const next = appendBoundedOutput(stdout, chunk);
Expand Down
14 changes: 8 additions & 6 deletions test/e2e/fixtures/e2e-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,18 +174,20 @@ export const test = base.extend<E2ETargetFixtures>({
},
{ auto: true },
],
docker: async ({ artifacts, progress, secrets, signal, skip }, use) => {
docker: async ({ artifacts, cleanup, progress, secrets, skip }, use) => {
const probe = new DockerProbe(
artifacts,
(text, extra) => secrets.redact(text, extra),
undefined,
progress,
signal,
() => cleanup.currentSignal(),
);
await use(new DockerPrerequisite(probe, skip));
},
cleanup: async ({ artifacts, progress, secrets }, use) => {
const cleanup = new CleanupRegistry((text) => secrets.redact(text), progress);
cleanup: async ({ artifacts, progress, secrets, signal }, use) => {
const cleanup = new CleanupRegistry((text) => secrets.redact(text), progress, {
testSignal: signal,
});
try {
await use(cleanup);
} finally {
Expand All @@ -195,13 +197,13 @@ export const test = base.extend<E2ETargetFixtures>({
assertCleanupPassed(result);
}
},
shellProbe: async ({ artifacts, progress, secrets, signal }, use) => {
shellProbe: async ({ artifacts, cleanup, progress, secrets }, use) => {
await use(
new ShellProbe({
artifacts,
progress,
redact: (text, extraValues) => secrets.redact(text, extraValues),
signal,
signal: () => cleanup.currentSignal(),
}),
);
},
Expand Down
48 changes: 46 additions & 2 deletions test/e2e/fixtures/observed-child-process.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
// SPDX-License-Identifier: Apache-2.0

import { type ChildProcess, type SpawnOptions, spawn } from "node:child_process";
import { isTestProgressCapability, type TestProgressCapability } from "./progress.ts";
import {
type ChildLifecycleOutcome,
type ChildLifecycleTerminalReporter,
isTestProgressCapability,
type TestProgressCapability,
} from "./progress.ts";

export interface ChildProcessProgress extends TestProgressCapability {
activity(label: string): (() => void) | void;
Expand All @@ -15,6 +20,10 @@ export interface ObservedChildProcessOptions {
spawn: SpawnOptions;
}

const NOOP_CHILD_LIFECYCLE_REPORTER: ChildLifecycleTerminalReporter = Object.freeze(
(_outcome: ChildLifecycleOutcome) => undefined,
);

/**
* The single direct asynchronous child-process boundary used by live E2E code.
* It owns content-free activity and timestamp-only output observation so a
Expand All @@ -35,6 +44,13 @@ export function spawnObservedChild(
// Progress diagnostics must never change process execution.
}

let finishChildLifecycle = NOOP_CHILD_LIFECYCLE_REPORTER;
try {
finishChildLifecycle = options.progress.beginChildLifecycle();
} catch {
// Progress diagnostics must never change process execution.
}

let child: ChildProcess;
try {
child = spawn(command, [...args], options.spawn);
Expand All @@ -44,6 +60,11 @@ export function spawnObservedChild(
} catch {
// Progress diagnostics must never replace the spawn failure.
}
try {
finishChildLifecycle("spawn-failed");
} catch {
// Progress diagnostics must never replace the spawn failure.
}
throw error;
}

Expand All @@ -61,12 +82,35 @@ export function spawnObservedChild(
// Child contents never cross this timestamp-only observer boundary.
}
});
child.once("close", () => {
let childSpawned = false;
let childLaunchFailed = false;
child.once("spawn", () => {
childSpawned = true;
});
child.once("error", () => {
if (!childSpawned) childLaunchFailed = true;
});
child.once("close", (code, signal) => {
try {
finishActivity();
} catch {
// Progress diagnostics must never change process completion.
}
try {
finishChildLifecycle(
childLaunchFailed
? "spawn-failed"
: signal !== null
? "signaled"
: code === 0
? "exited-zero"
: code === null
? "closed-unknown"
: "exited-nonzero",
);
} catch {
// Progress diagnostics must never change process completion.
}
});
return child;
}
Loading
Loading