From 8fabcfff30456c0d9e50fe3011ff3faf706371f6 Mon Sep 17 00:00:00 2001 From: Dotta <34892728+cryppadotta@users.noreply.github.com> Date: Wed, 25 Nov 2026 10:27:26 -0600 Subject: [PATCH] Split oversized native-runtime integration tests for file-parallel CI (#22948) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work. > - The native-runtime integration test lane (`general-server-native-runner`) runs real-process Vitest suites with file parallelism enabled. > - Three oversized files (`plugin-runner-eviction.integration.test.ts` at 307s, `plugin-runner-release-resume.integration.test.ts` at 200s, and `native-runner-restart-diskless.integration.test.ts` at 191s) exceed the 180s per-file budget and bound the entire lane wall-clock time because shards cannot split a single file. > - Each file runs parameterized test matrices serially inside one Vitest worker while other workers sit idle. > - This pull request moves each suite body into a shared helper under `server/src/__tests__/helpers/` and splits the parameterized cases across focused `.integration.test.ts` entrypoints, updating the suite list, nightly manifest, duration manifest, and shard tests. > - The benefit is cutting `Verify Paperclip Runner (vitest native server)` wall-clock time from ~461s down to ~157s while keeping identical test cases and assertions. ## Linked Issues or Issue Description **What existing behavior does this improve?** Execution time of the `general-server-native-runner` Vitest lane in PR and release verification workflows. **Subsystem affected** server/ — REST API & orchestration services **Current behavior** Three parameterized integration test files exceed the 180s `PAPERCLIP_CI_OVERSIZED_TEST_FILE_SECONDS` budget (`plugin-runner-eviction.integration.test.ts` takes 307s, `plugin-runner-release-resume.integration.test.ts` takes 200s, and `native-runner-restart-diskless.integration.test.ts` takes 191s). Because Vitest parallelizes across files, the slowest single file bounds the entire lane to ~461s total job time. **Proposed behavior** Extract each suite body into `server/src/__tests__/helpers/` and run disjoint slices of the exact same parameterized cases across focused `.integration.test.ts` files so Vitest fork workers execute them concurrently. **Reason and benefit** Cuts the `Verify Paperclip Runner (server-integration)` / `vitest native server` CI lane by roughly 5 minutes (461s -> 157s measured in CI) with zero change to test logic, timeouts, or assertions. **Breaking changes** None. All existing test cases remain covered in the same `general-server-native-runner` group. ## What Changed - Extracted `server/src/__tests__/helpers/plugin-runner-eviction.ts` and split its 42 cases across 4 entrypoints by `(codex | claude) x (retired | abrupt)`: - `server/src/services/native-runtime/plugin-runner-eviction-codex-retired.integration.test.ts` (11 cases) - `server/src/services/native-runtime/plugin-runner-eviction-codex-abrupt.integration.test.ts` (10 cases) - `server/src/services/native-runtime/plugin-runner-eviction-claude-retired.integration.test.ts` (11 cases) - `server/src/services/native-runtime/plugin-runner-eviction-claude-abrupt.integration.test.ts` (10 cases) - Extracted `server/src/__tests__/helpers/plugin-runner-release-resume.ts` and split its 19 cases across 2 entrypoints: - `server/src/services/native-runtime/plugin-runner-release-resume-cached.integration.test.ts` (8 cases) - `server/src/services/native-runtime/plugin-runner-release-resume-adopted.integration.test.ts` (11 cases) - Extracted `server/src/__tests__/helpers/native-runner-restart-diskless.ts` and split its 2 cases across 2 entrypoints with isolated embedded Postgres comments: - `server/src/services/native-runtime/native-runner-restart-diskless-direct.integration.test.ts` (`preparedTask: false`) - `server/src/services/native-runtime/native-runner-restart-diskless-prepared-task.integration.test.ts` (`preparedTask: true`) - Updated `scripts/run-vitest-stable.mjs`, `scripts/ci/nightly-only-suites.json`, `scripts/general-server-shard-durations.json`, and `scripts/__tests__/run-vitest-stable-shard.test.mjs` to register the split files and remove the three replaced paths. ## Verification - `node --test scripts/check-test-budget.test.mjs scripts/__tests__/run-vitest-stable-shard.test.mjs scripts/__tests__/run-vitest-stable-pr-mode.test.mjs` (53/53 passed) - `node scripts/check-test-budget.mjs --base origin/master` (passed) - `ci / Verify Paperclip Runner (vitest native server)` passed in 157s on this PR (down from 461s on master). ## Risks - Low risk. Each entrypoint runs a disjoint, exhaustive slice of the original parameterized matrix against the same helper implementation, with no production code changes and no schema migrations. ## Model Used - Google Gemini 3.1 Pro (thinking mode, tool use and code execution) ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge --- .../run-vitest-stable-shard.test.mjs | 30 ++++-- scripts/ci/nightly-only-suites.json | 48 ++++++++-- scripts/general-server-shard-durations.json | 11 ++- scripts/run-vitest-stable.mjs | 11 ++- .../native-runner-restart-diskless.ts} | 32 ++++--- .../helpers/plugin-runner-eviction.ts} | 85 +++++++++-------- .../helpers/plugin-runner-release-resume.ts} | 94 +++++++++++-------- ...estart-diskless-direct.integration.test.ts | 6 ++ ...diskless-prepared-task.integration.test.ts | 6 ++ ...eviction-claude-abrupt.integration.test.ts | 3 + ...viction-claude-retired.integration.test.ts | 3 + ...-eviction-codex-abrupt.integration.test.ts | 3 + ...eviction-codex-retired.integration.test.ts | 3 + ...release-resume-adopted.integration.test.ts | 3 + ...-release-resume-cached.integration.test.ts | 3 + 15 files changed, 224 insertions(+), 117 deletions(-) rename server/src/{services/native-runtime/native-runner-restart-diskless.integration.test.ts => __tests__/helpers/native-runner-restart-diskless.ts} (89%) rename server/src/{services/native-runtime/plugin-runner-eviction.integration.test.ts => __tests__/helpers/plugin-runner-eviction.ts} (91%) rename server/src/{services/native-runtime/plugin-runner-release-resume.integration.test.ts => __tests__/helpers/plugin-runner-release-resume.ts} (90%) create mode 100644 server/src/services/native-runtime/native-runner-restart-diskless-direct.integration.test.ts create mode 100644 server/src/services/native-runtime/native-runner-restart-diskless-prepared-task.integration.test.ts create mode 100644 server/src/services/native-runtime/plugin-runner-eviction-claude-abrupt.integration.test.ts create mode 100644 server/src/services/native-runtime/plugin-runner-eviction-claude-retired.integration.test.ts create mode 100644 server/src/services/native-runtime/plugin-runner-eviction-codex-abrupt.integration.test.ts create mode 100644 server/src/services/native-runtime/plugin-runner-eviction-codex-retired.integration.test.ts create mode 100644 server/src/services/native-runtime/plugin-runner-release-resume-adopted.integration.test.ts create mode 100644 server/src/services/native-runtime/plugin-runner-release-resume-cached.integration.test.ts diff --git a/scripts/__tests__/run-vitest-stable-shard.test.mjs b/scripts/__tests__/run-vitest-stable-shard.test.mjs index 9b4a813fd28..ea7450b6081 100644 --- a/scripts/__tests__/run-vitest-stable-shard.test.mjs +++ b/scripts/__tests__/run-vitest-stable-shard.test.mjs @@ -349,13 +349,21 @@ const usageDeliverySuitePath = "server/src/services/native-runtime/native-usage- const warmCheckpointOwnershipSuitePath = "server/src/services/native-runtime/native-warm-checkpoint-ownership.integration.test.ts"; const warmSuccessorRunnerReleaseSuitePath = "server/src/services/native-runtime/native-warm-successor-runner-release.integration.test.ts"; const pluginWarmOwnerSuitePath = "server/src/services/native-runtime/plugin-runner-task-warm.integration.test.ts"; -const pluginReleaseResumeSuitePath = "server/src/services/native-runtime/plugin-runner-release-resume.integration.test.ts"; -const pluginEvictionSuitePath = "server/src/services/native-runtime/plugin-runner-eviction.integration.test.ts"; +const pluginReleaseResumeSuitePaths = [ + "server/src/services/native-runtime/plugin-runner-release-resume-cached.integration.test.ts", + "server/src/services/native-runtime/plugin-runner-release-resume-adopted.integration.test.ts", +]; +const pluginEvictionSuitePaths = [ + "server/src/services/native-runtime/plugin-runner-eviction-codex-retired.integration.test.ts", + "server/src/services/native-runtime/plugin-runner-eviction-codex-abrupt.integration.test.ts", + "server/src/services/native-runtime/plugin-runner-eviction-claude-retired.integration.test.ts", + "server/src/services/native-runtime/plugin-runner-eviction-claude-abrupt.integration.test.ts", +]; const dotRunnerSuitePath = "server/src/__tests__/dot-runner.test.ts"; const restartRecoverySuitePath = "server/src/services/native-runtime/native-runner-restart-recovery.integration.test.ts"; const cutTurnStartRetrySuitePath = "server/src/services/native-runtime/native-cut-turn-start-retry.integration.test.ts"; -const restartWaitSuites = ["lease-renewal", "preparation", "checkpoint-cost", "diskless"] +const restartWaitSuites = ["lease-renewal", "preparation", "checkpoint-cost", "diskless-direct", "diskless-prepared-task"] .map(name => `server/src/services/native-runtime/native-runner-restart-${name}.integration.test.ts`); // Mirrors pr-trusted.yml (12 shards, called by pr.yml so GITHUB_WORKFLOW is @@ -404,13 +412,14 @@ test("12 PR without-chat shards plus the dedicated chat and native-runner lanes assert.ok(!files.includes(warmCheckpointOwnershipSuitePath)); assert.ok(!files.includes(warmSuccessorRunnerReleaseSuitePath)); assert.ok(!files.includes(pluginWarmOwnerSuitePath)); - assert.ok(!files.includes(pluginReleaseResumeSuitePath)); - assert.ok(!files.includes(pluginEvictionSuitePath)); + for (const suitePath of [...pluginReleaseResumeSuitePaths, ...pluginEvictionSuitePaths]) { + assert.ok(!files.includes(suitePath)); + } const excludedNightly = shards[0].excludedNightlySuites ?? []; for (const shard of shards) { assert.deepEqual(shard.excludedNightlySuites ?? [], excludedNightly, "nightly exclusions must agree across shards"); } - assert.deepEqual([...files, ...excludedNightly, ...allChatSuites, nativeRunnerSuitePath, ingressRetrySuitePath, dotRunnerSuitePath, restartRecoverySuitePath, ...restartWaitSuites, cutTurnStartRetrySuitePath, usageDeliverySuitePath, warmCheckpointOwnershipSuitePath, warmSuccessorRunnerReleaseSuitePath, pluginWarmOwnerSuitePath, pluginReleaseResumeSuitePath, pluginEvictionSuitePath, "server/src/services/native-runtime/plugin-runner-probe.test.ts"].sort(), full.selectedGeneralServerSuites.sort()); + assert.deepEqual([...files, ...excludedNightly, ...allChatSuites, nativeRunnerSuitePath, ingressRetrySuitePath, dotRunnerSuitePath, restartRecoverySuitePath, ...restartWaitSuites, cutTurnStartRetrySuitePath, usageDeliverySuitePath, warmCheckpointOwnershipSuitePath, warmSuccessorRunnerReleaseSuitePath, pluginWarmOwnerSuitePath, ...pluginReleaseResumeSuitePaths, ...pluginEvictionSuitePaths, "server/src/services/native-runtime/plugin-runner-probe.test.ts"].sort(), full.selectedGeneralServerSuites.sort()); assert.equal(new Set(files).size, files.length); const defaultRun = dryRunJson([], prEnv); assert.ok(defaultRun.generalServerSuiteCount === full.generalServerSuiteCount); @@ -435,8 +444,9 @@ for (const [caller, envOverrides] of [["Release", { GITHUB_WORKFLOW: "Release" } assert.ok(files.includes(warmCheckpointOwnershipSuitePath)); assert.ok(files.includes(warmSuccessorRunnerReleaseSuitePath)); assert.ok(files.includes(pluginWarmOwnerSuitePath)); - assert.ok(files.includes(pluginReleaseResumeSuitePath)); - assert.ok(files.includes(pluginEvictionSuitePath)); + for (const suitePath of [...pluginReleaseResumeSuitePaths, ...pluginEvictionSuitePaths]) { + assert.ok(files.includes(suitePath)); + } assert.deepEqual([...files, ...allChatSuites].sort(), full.selectedGeneralServerSuites.sort()); assert.equal(new Set(files).size, files.length); }); @@ -473,8 +483,8 @@ test("the native-runner lane runs exactly the cargo-dependent suites", () => { warmCheckpointOwnershipSuitePath, warmSuccessorRunnerReleaseSuitePath, pluginWarmOwnerSuitePath, - pluginReleaseResumeSuitePath, - pluginEvictionSuitePath, + ...pluginReleaseResumeSuitePaths, + ...pluginEvictionSuitePaths, ]); }); diff --git a/scripts/ci/nightly-only-suites.json b/scripts/ci/nightly-only-suites.json index db4544b0a92..da808b95172 100644 --- a/scripts/ci/nightly-only-suites.json +++ b/scripts/ci/nightly-only-suites.json @@ -476,10 +476,16 @@ "measuredMs": 187000 }, { - "path": "server/src/services/native-runtime/native-runner-restart-diskless.integration.test.ts", + "path": "server/src/services/native-runtime/native-runner-restart-diskless-direct.integration.test.ts", "category": "restart-lease-soak", - "reason": "Real-process diskless runner restart soak (172s)", - "measuredMs": 172000 + "reason": "Real-process diskless runner restart soak (direct task slice)", + "measuredMs": 86000 + }, + { + "path": "server/src/services/native-runtime/native-runner-restart-diskless-prepared-task.integration.test.ts", + "category": "restart-lease-soak", + "reason": "Real-process diskless runner restart soak (prepared task slice)", + "measuredMs": 86000 }, { "path": "server/src/services/native-runtime/native-runner-restart-lease-renewal.integration.test.ts", @@ -536,16 +542,40 @@ "measuredMs": 43404 }, { - "path": "server/src/services/native-runtime/plugin-runner-eviction.integration.test.ts", + "path": "server/src/services/native-runtime/plugin-runner-eviction-claude-abrupt.integration.test.ts", "category": "restart-lease-soak", - "reason": "Real-process plugin runner eviction/release-resume soak (312.5s in run 45238253588)", - "measuredMs": 312473 + "reason": "Real-process plugin runner eviction soak (Claude abrupt exit slice)", + "measuredMs": 78000 }, { - "path": "server/src/services/native-runtime/plugin-runner-release-resume.integration.test.ts", + "path": "server/src/services/native-runtime/plugin-runner-eviction-claude-retired.integration.test.ts", "category": "restart-lease-soak", - "reason": "Real-process plugin runner eviction/release-resume soak (205.8s in run 45238253588)", - "measuredMs": 205790 + "reason": "Real-process plugin runner eviction soak (Claude retired exit slice)", + "measuredMs": 78000 + }, + { + "path": "server/src/services/native-runtime/plugin-runner-eviction-codex-abrupt.integration.test.ts", + "category": "restart-lease-soak", + "reason": "Real-process plugin runner eviction soak (Codex abrupt exit slice)", + "measuredMs": 78000 + }, + { + "path": "server/src/services/native-runtime/plugin-runner-eviction-codex-retired.integration.test.ts", + "category": "restart-lease-soak", + "reason": "Real-process plugin runner eviction soak (Codex retired exit slice)", + "measuredMs": 78000 + }, + { + "path": "server/src/services/native-runtime/plugin-runner-release-resume-adopted.integration.test.ts", + "category": "restart-lease-soak", + "reason": "Real-process plugin runner release-resume soak (adopted modes slice)", + "measuredMs": 120000 + }, + { + "path": "server/src/services/native-runtime/plugin-runner-release-resume-cached.integration.test.ts", + "category": "restart-lease-soak", + "reason": "Real-process plugin runner release-resume soak (cached modes slice)", + "measuredMs": 86000 }, { "path": "server/src/services/native-runtime/provider-pack-archive.test.ts", diff --git a/scripts/general-server-shard-durations.json b/scripts/general-server-shard-durations.json index 357aa07e203..626c6b25d1f 100644 --- a/scripts/general-server-shard-durations.json +++ b/scripts/general-server-shard-durations.json @@ -1480,7 +1480,8 @@ "server/src/services/native-runtime/native-runner-execution-driver.test.ts": 2097, "server/src/services/native-runtime/native-runner-ownership.test.ts": 2963, "server/src/services/native-runtime/native-runner-restart-checkpoint-cost.integration.test.ts": 187000, - "server/src/services/native-runtime/native-runner-restart-diskless.integration.test.ts": 172000, + "server/src/services/native-runtime/native-runner-restart-diskless-direct.integration.test.ts": 86000, + "server/src/services/native-runtime/native-runner-restart-diskless-prepared-task.integration.test.ts": 86000, "server/src/services/native-runtime/native-runner-restart-lease-renewal.integration.test.ts": 119000, "server/src/services/native-runtime/native-runner-restart-preparation.integration.test.ts": 155000, "server/src/services/native-runtime/native-runner-restart-recovery.integration.test.ts": 51000, @@ -1523,10 +1524,14 @@ "server/src/services/native-runtime/paperclip-runner-tool-authority.test.ts": 25186, "server/src/services/native-runtime/plan-mode-status.test.ts": 3142, "server/src/services/native-runtime/plugin-runner-credentials.test.ts": 1927, - "server/src/services/native-runtime/plugin-runner-eviction.integration.test.ts": 312473, + "server/src/services/native-runtime/plugin-runner-eviction-claude-abrupt.integration.test.ts": 78000, + "server/src/services/native-runtime/plugin-runner-eviction-claude-retired.integration.test.ts": 78000, + "server/src/services/native-runtime/plugin-runner-eviction-codex-abrupt.integration.test.ts": 78000, + "server/src/services/native-runtime/plugin-runner-eviction-codex-retired.integration.test.ts": 78000, "server/src/services/native-runtime/plugin-runner-probe-runner-mismatch.test.ts": 6945, "server/src/services/native-runtime/plugin-runner-probe.test.ts": 27899, - "server/src/services/native-runtime/plugin-runner-release-resume.integration.test.ts": 205790, + "server/src/services/native-runtime/plugin-runner-release-resume-adopted.integration.test.ts": 120000, + "server/src/services/native-runtime/plugin-runner-release-resume-cached.integration.test.ts": 86000, "server/src/services/native-runtime/plugin-runner-task-warm.integration.test.ts": 3047, "server/src/services/native-runtime/plugin-runner-task.test.ts": 7276, "server/src/services/native-runtime/provider-api-placement.test.ts": 7041, diff --git a/scripts/run-vitest-stable.mjs b/scripts/run-vitest-stable.mjs index 7e3493368df..287aa06e21d 100644 --- a/scripts/run-vitest-stable.mjs +++ b/scripts/run-vitest-stable.mjs @@ -118,14 +118,19 @@ const nativeRunnerSuites = [ "server/src/services/native-runtime/native-runner-restart-lease-renewal.integration.test.ts", "server/src/services/native-runtime/native-runner-restart-preparation.integration.test.ts", "server/src/services/native-runtime/native-runner-restart-checkpoint-cost.integration.test.ts", - "server/src/services/native-runtime/native-runner-restart-diskless.integration.test.ts", + "server/src/services/native-runtime/native-runner-restart-diskless-direct.integration.test.ts", + "server/src/services/native-runtime/native-runner-restart-diskless-prepared-task.integration.test.ts", "server/src/services/native-runtime/native-cut-turn-start-retry.integration.test.ts", "server/src/services/native-runtime/native-usage-delivery.integration.test.ts", "server/src/services/native-runtime/native-warm-checkpoint-ownership.integration.test.ts", "server/src/services/native-runtime/native-warm-successor-runner-release.integration.test.ts", "server/src/services/native-runtime/plugin-runner-task-warm.integration.test.ts", - "server/src/services/native-runtime/plugin-runner-release-resume.integration.test.ts", - "server/src/services/native-runtime/plugin-runner-eviction.integration.test.ts", + "server/src/services/native-runtime/plugin-runner-release-resume-cached.integration.test.ts", + "server/src/services/native-runtime/plugin-runner-release-resume-adopted.integration.test.ts", + "server/src/services/native-runtime/plugin-runner-eviction-codex-retired.integration.test.ts", + "server/src/services/native-runtime/plugin-runner-eviction-codex-abrupt.integration.test.ts", + "server/src/services/native-runtime/plugin-runner-eviction-claude-retired.integration.test.ts", + "server/src/services/native-runtime/plugin-runner-eviction-claude-abrupt.integration.test.ts", ]; // In the PR workflow (pr.yml, the caller of pr-trusted.yml — reusable // workflows inherit the caller's GITHUB_WORKFLOW), the last Verify Paperclip diff --git a/server/src/services/native-runtime/native-runner-restart-diskless.integration.test.ts b/server/src/__tests__/helpers/native-runner-restart-diskless.ts similarity index 89% rename from server/src/services/native-runtime/native-runner-restart-diskless.integration.test.ts rename to server/src/__tests__/helpers/native-runner-restart-diskless.ts index 8d0b45b74c6..b2320ec05ec 100644 --- a/server/src/services/native-runtime/native-runner-restart-diskless.integration.test.ts +++ b/server/src/__tests__/helpers/native-runner-restart-diskless.ts @@ -16,10 +16,10 @@ import { type RunnerProcessLaunchSpec, } from "../../vendor/paperclip-runner/index.js"; import { registerRunnerPrpAuthority } from "../../realtime/runner-prp-ws.js"; -import { readProcessStartedAt } from "../hot-restart.js"; -import { loadNativeRunnerCheckpoint, registerNativeRunnerCheckpoint, restoreNativeRunnerCheckpoint } from "./native-runner-checkpoint.js"; -import { REMOTE_RUNNER_RECONNECT_GRACE_MS } from "./native-runner-recovery-contract.js"; -import { claimNativeRestartRecoveries } from "./native-restart-recovery.js"; +import { readProcessStartedAt } from "../../services/hot-restart.js"; +import { loadNativeRunnerCheckpoint, registerNativeRunnerCheckpoint, restoreNativeRunnerCheckpoint } from "../../services/native-runtime/native-runner-checkpoint.js"; +import { REMOTE_RUNNER_RECONNECT_GRACE_MS } from "../../services/native-runtime/native-runner-recovery-contract.js"; +import { claimNativeRestartRecoveries } from "../../services/native-runtime/native-restart-recovery.js"; import { nativeRestartFixture, describeEmbeddedPostgres, @@ -28,18 +28,19 @@ import { processAlive, waitForCondition, stopOwnedProcessGroup, -} from "../../__tests__/helpers/native-restart.js"; +} from "./native-restart.js"; -describeEmbeddedPostgres("native runner restart recovery: diskless", () => { - const environment = nativeRestartFixture(); - const { seedRun, transportOptions } = environment; - let runtimeRoot: typeof environment.current.runtimeRoot; - let companyId: typeof environment.current.companyId; - let agentId: typeof environment.current.agentId; - let successor: typeof environment.current.successor; - beforeAll(() => { ({ runtimeRoot, companyId, agentId, successor } = environment.current); }); +export function registerNativeRunnerRestartDisklessSuite(preparedTask: boolean): void { + describeEmbeddedPostgres(`native runner restart recovery: diskless (prepared task: ${preparedTask})`, () => { + const environment = nativeRestartFixture(); + const { seedRun, transportOptions } = environment; + let runtimeRoot: typeof environment.current.runtimeRoot; + let companyId: typeof environment.current.companyId; + let agentId: typeof environment.current.agentId; + let successor: typeof environment.current.successor; + beforeAll(() => { ({ runtimeRoot, companyId, agentId, successor } = environment.current); }); - realProcessIt.each([false, true])("adopts the same runner from Postgres after losing the controller filesystem (prepared task: %s)", async preparedTask => { + realProcessIt.each([preparedTask])("adopts the same runner from Postgres after losing the controller filesystem (prepared task: %s)", async preparedTask => { const fixture = await seedRun(`EMPTY-CONTROLLER-DISK-${preparedTask}`); const controllerRoot = resolve(runtimeRoot, `${fixture.runId}-controller`); const sandboxRoot = resolve(runtimeRoot, `${fixture.runId}-sandbox`); @@ -170,4 +171,5 @@ describeEmbeddedPostgres("native runner restart recovery: diskless", () => { } }, 345_000); -}); + }); +} diff --git a/server/src/services/native-runtime/plugin-runner-eviction.integration.test.ts b/server/src/__tests__/helpers/plugin-runner-eviction.ts similarity index 91% rename from server/src/services/native-runtime/plugin-runner-eviction.integration.test.ts rename to server/src/__tests__/helpers/plugin-runner-eviction.ts index 1cacf5ebcd6..6fc5f9bdcaa 100644 --- a/server/src/services/native-runtime/plugin-runner-eviction.integration.test.ts +++ b/server/src/__tests__/helpers/plugin-runner-eviction.ts @@ -14,19 +14,19 @@ import { environmentTaskOperationSchema, type PluginEnvironmentTaskOperation } f import { readRunnerdArtifactBinding, defaultCapabilityRunnerdBinary, parseNativeExecutionInput, parseNativeRuntimeContext, QUALIFIED_ACPX_PROFILES, type DurableRecoveryIdentity, type RunnerProcessHandle, type RunnerProcessLaunchSpec } from "../../vendor/paperclip-runner/index.js"; import { createRunnerProviderLaunch, runnerLaunchRequirementsDigest, canonicalNativeRuntimeContextDigest } from "@paperclipai/paperclip-runner"; -import { materializeAsset } from "./runtime-context.js"; +import { materializeAsset } from "../../services/native-runtime/runtime-context.js"; import { spawnRunner } from "../../vendor/paperclip-runner/testing.js"; -import { describeEmbeddedPostgres, nativeRestartFixture, realProcessIt, fakeCodexAppServer, waitForCondition } from "../../__tests__/helpers/native-restart.js"; -import { executePaperclipNativeSession, closeIdleWarmNativeSessionsForRestart, readNativeSessionIdleWork, claimWarmNativeInstructionCopy } from "./native-session-executor.js"; +import { describeEmbeddedPostgres, nativeRestartFixture, realProcessIt, fakeCodexAppServer, waitForCondition } from "./native-restart.js"; +import { executePaperclipNativeSession, closeIdleWarmNativeSessionsForRestart, readNativeSessionIdleWork, claimWarmNativeInstructionCopy } from "../../services/native-runtime/native-session-executor.js"; import { resolvePaperclipInstanceRoot } from "../../home-paths.js"; -import { environmentRuntimeService } from "../environment-runtime.js"; -import { environmentService } from "../environments.js"; -import { resolveEnvironmentExecutionTarget } from "../environment-execution-target.js"; -import { executeEnvironmentTask, isSettledReadyRunnerState } from "../environment-task-runtime.js"; -import type { PluginWorkerManager } from "../plugin-worker-manager.js"; -import { reconcileNativeFinalizations } from "./native-finalization-reconciler.js"; -import { buildNativeCompletionContract } from "./completion-contracts.js"; -import { nativeRuntimeContextFixture } from "./runtime-context.test-fixture.js"; +import { environmentRuntimeService } from "../../services/environment-runtime.js"; +import { environmentService } from "../../services/environments.js"; +import { resolveEnvironmentExecutionTarget } from "../../services/environment-execution-target.js"; +import { executeEnvironmentTask, isSettledReadyRunnerState } from "../../services/environment-task-runtime.js"; +import type { PluginWorkerManager } from "../../services/plugin-worker-manager.js"; +import { reconcileNativeFinalizations } from "../../services/native-runtime/native-finalization-reconciler.js"; +import { buildNativeCompletionContract } from "../../services/native-runtime/completion-contracts.js"; +import { nativeRuntimeContextFixture } from "../../services/native-runtime/runtime-context.test-fixture.js"; const { createPrivateHostControlFixture } = await import(new URL("../../../../packages/paperclip-runner/test/support/private-host-control.ts", import.meta.url).href) as { createPrivateHostControlFixture(): { @@ -41,34 +41,42 @@ const sha = (value: string) => createHash("sha256").update(value).digest("hex"); const detachedIdleTimeoutMs = 10_000; const parkId = (source: DurableRecoveryIdentity) => `park_${sha(JSON.stringify(Object.fromEntries(Object.entries(source).sort(([a], [b]) => a.localeCompare(b)))))}`; +const evictionModes = [ + "cached", "detached", "reused lease", "after inspection", "bare unavailable", + "prepared copy", "missing stop", "missing state", "foreign state", "working state", +] as const; + // The only replaced service is the external environment-task/Launcher edge. // Runtime, backend, owner, PRP ingress, checkpoint persistence and native Runner are real. -describeEmbeddedPostgres("plugin Runner eviction through the Core execution entry", () => { - let currentCase: { teardown?: () => Promise } | undefined; - afterEach(async () => { - const finished = currentCase; - currentCase = undefined; - await finished?.teardown?.(); - }); - const environment = nativeRestartFixture(); - const tlsIdentity = { key: Buffer.alloc(0), cert: Buffer.alloc(0) }; - let oldCAs: string[] = [], oldAgent = https.globalAgent; - beforeAll(async () => { - const key = join(environment.current.runtimeRoot, "tls.key"), certificate = join(environment.current.runtimeRoot, "tls.crt"); - execFileSync("openssl", ["req", "-x509", "-newkey", "rsa:2048", "-nodes", "-keyout", key, "-out", certificate, - "-days", "1", "-subj", "/CN=localhost", "-addext", "subjectAltName=IP:127.0.0.1,DNS:localhost"], { stdio: "ignore" }); - tlsIdentity.key = await readFile(key); tlsIdentity.cert = await readFile(certificate); - oldCAs = getCACertificates("default"); oldAgent = https.globalAgent; - const certificates = [...oldCAs, tlsIdentity.cert.toString("utf8")]; - setDefaultCACertificates(certificates); https.globalAgent = new https.Agent({ ca: certificates }); - }); - afterAll(() => { - https.globalAgent.destroy(); https.globalAgent = oldAgent; setDefaultCACertificates(oldCAs); - }); - const nativeIt = process.platform === "win32" ? it.skip : realProcessIt; - nativeIt.for([...(["codex", "claude"] as const).flatMap(harness => (["cached", "detached", "reused lease", "after inspection", "bare unavailable", "prepared copy", "missing stop", "missing state", "foreign state", "working state"] as const).flatMap(mode => - (["retired", "abrupt"] as const).map(exit => [harness, mode, exit] as const))), - ...(["codex", "claude"] as const).map(harness => [harness, "relaunch after inspection", "retired"] as const)])("continues %s with a %s Core owner after its Runner exit is %s", { timeout: 60_000 }, async ([harness, mode, exit], context) => { +export function registerPluginRunnerEvictionSuite(harness: "codex" | "claude", exit: "retired" | "abrupt"): void { + const cases = [ + ...evictionModes.map(mode => [harness, mode, exit] as const), + ...(exit === "retired" ? [[harness, "relaunch after inspection", "retired"] as const] : []), + ]; + describeEmbeddedPostgres(`plugin Runner eviction through the Core execution entry (${harness}, ${exit})`, () => { + let currentCase: { teardown?: () => Promise } | undefined; + afterEach(async () => { + const finished = currentCase; + currentCase = undefined; + await finished?.teardown?.(); + }); + const environment = nativeRestartFixture(); + const tlsIdentity = { key: Buffer.alloc(0), cert: Buffer.alloc(0) }; + let oldCAs: string[] = [], oldAgent = https.globalAgent; + beforeAll(async () => { + const key = join(environment.current.runtimeRoot, "tls.key"), certificate = join(environment.current.runtimeRoot, "tls.crt"); + execFileSync("openssl", ["req", "-x509", "-newkey", "rsa:2048", "-nodes", "-keyout", key, "-out", certificate, + "-days", "1", "-subj", "/CN=localhost", "-addext", "subjectAltName=IP:127.0.0.1,DNS:localhost"], { stdio: "ignore" }); + tlsIdentity.key = await readFile(key); tlsIdentity.cert = await readFile(certificate); + oldCAs = getCACertificates("default"); oldAgent = https.globalAgent; + const certificates = [...oldCAs, tlsIdentity.cert.toString("utf8")]; + setDefaultCACertificates(certificates); https.globalAgent = new https.Agent({ ca: certificates }); + }); + afterAll(() => { + https.globalAgent.destroy(); https.globalAgent = oldAgent; setDefaultCACertificates(oldCAs); + }); + const nativeIt = process.platform === "win32" ? it.skip : realProcessIt; + nativeIt.for(cases)("continues %s with a %s Core owner after its Runner exit is %s", { timeout: 60_000 }, async ([harness, mode, exit], context) => { if (harness === "claude" && !existsSync(fakeAcpxSidecar)) context.skip(); const thisCase: { teardown?: () => Promise } = {}; currentCase = thisCase; @@ -426,4 +434,5 @@ describeEmbeddedPostgres("plugin Runner eviction through the Core execution entr await pendingFollowup?.catch(() => undefined); } }); -}); + }); +} diff --git a/server/src/services/native-runtime/plugin-runner-release-resume.integration.test.ts b/server/src/__tests__/helpers/plugin-runner-release-resume.ts similarity index 90% rename from server/src/services/native-runtime/plugin-runner-release-resume.integration.test.ts rename to server/src/__tests__/helpers/plugin-runner-release-resume.ts index 64f62c73e3f..403de154ed0 100644 --- a/server/src/services/native-runtime/plugin-runner-release-resume.integration.test.ts +++ b/server/src/__tests__/helpers/plugin-runner-release-resume.ts @@ -14,17 +14,17 @@ import { environmentTaskOperationSchema, type PluginEnvironmentTaskOperation } f import { readRunnerdArtifactBinding, defaultCapabilityRunnerdBinary, parseNativeExecutionInput, parseNativeRuntimeContext, QUALIFIED_ACPX_PROFILES, type DurableRecoveryIdentity, type RunnerProcessHandle, type RunnerProcessLaunchSpec } from "../../vendor/paperclip-runner/index.js"; import { createRunnerProviderLaunch, runnerLaunchRequirementsDigest, canonicalNativeRuntimeContextDigest } from "@paperclipai/paperclip-runner"; -import { materializeAsset } from "./runtime-context.js"; +import { materializeAsset } from "../../services/native-runtime/runtime-context.js"; import { spawnRunner } from "../../vendor/paperclip-runner/testing.js"; -import { describeEmbeddedPostgres, nativeRestartFixture, realProcessIt, fakeCodexAppServer, waitForCondition } from "../../__tests__/helpers/native-restart.js"; -import { executePaperclipNativeSession, cancelNativeSession, closeIdleWarmNativeSessionsForRestart, readNativeSessionIdleWork } from "./native-session-executor.js"; +import { describeEmbeddedPostgres, nativeRestartFixture, realProcessIt, fakeCodexAppServer, waitForCondition } from "./native-restart.js"; +import { executePaperclipNativeSession, cancelNativeSession, closeIdleWarmNativeSessionsForRestart, readNativeSessionIdleWork } from "../../services/native-runtime/native-session-executor.js"; import { resolvePaperclipInstanceRoot } from "../../home-paths.js"; -import * as remoteWarmRecovery from "./remote-warm-session-recovery.js"; -import { reconcileNativeFinalizations } from "./native-finalization-reconciler.js"; -import { buildNativeCompletionContract } from "./completion-contracts.js"; -import { nativeRuntimeContextFixture } from "./runtime-context.test-fixture.js"; -import { PROCESS_START_REQUESTED } from "../native-local-process-stop.js"; -import { PaperclipRunnerToolAuthority } from "./paperclip-runner-tool-authority.js"; +import * as remoteWarmRecovery from "../../services/native-runtime/remote-warm-session-recovery.js"; +import { reconcileNativeFinalizations } from "../../services/native-runtime/native-finalization-reconciler.js"; +import { buildNativeCompletionContract } from "../../services/native-runtime/completion-contracts.js"; +import { nativeRuntimeContextFixture } from "../../services/native-runtime/runtime-context.test-fixture.js"; +import { PROCESS_START_REQUESTED } from "../../services/native-local-process-stop.js"; +import { PaperclipRunnerToolAuthority } from "../../services/native-runtime/paperclip-runner-tool-authority.js"; const { createPrivateHostControlFixture } = await import(new URL("../../../../packages/paperclip-runner/test/support/private-host-control.ts", import.meta.url).href) as { createPrivateHostControlFixture(): { @@ -40,36 +40,51 @@ const adoptedIdleTimeoutMs = 10_000; const toolDefinitions = PaperclipRunnerToolAuthority.prototype.definitions; const parkId = (source: DurableRecoveryIdentity) => `park_${sha(JSON.stringify(Object.fromEntries(Object.entries(source).sort(([a], [b]) => a.localeCompare(b)))))}`; +const allReleaseResumeCases = [ + ...(["codex", "claude"] as const).flatMap(harness => (["cached", "adopted", "adopted restart"] as const).map(mode => [harness, mode] as const)), + ["codex", "adopted cancellation"] as const, + ["codex", "adopted legacy cancellation"] as const, + ["codex", "cached cancellation"] as const, + ["codex", "cached held claim"] as const, + ["claude", "cached held claim"] as const, + ["codex", "cached relaunch"] as const, + ["claude", "cached relaunch"] as const, + ["codex", "adopted relaunch"] as const, + ["codex", "adopted restart relaunch"] as const, + ["claude", "adopted restart relaunch"] as const, + ["codex", "cached managed GitHub"] as const, + ["codex", "adopted managed GitHub"] as const, + ["codex", "adopted restart managed GitHub"] as const, +] as const; + // The only replaced service is the external environment-task/Launcher edge. // Runtime, backend, owner, PRP ingress, checkpoint persistence and native Runner are real. -describeEmbeddedPostgres("plugin Runner release/resume through the Core execution entry", () => { - let currentCase: { teardown?: () => Promise } | undefined; - afterEach(async () => { - const finished = currentCase; - currentCase = undefined; - await finished?.teardown?.(); - }); - const environment = nativeRestartFixture(); - const tlsIdentity = { key: Buffer.alloc(0), cert: Buffer.alloc(0) }; - let oldCAs: string[] = [], oldAgent = https.globalAgent; - beforeAll(async () => { - const key = join(environment.current.runtimeRoot, "tls.key"), certificate = join(environment.current.runtimeRoot, "tls.crt"); - execFileSync("openssl", ["req", "-x509", "-newkey", "rsa:2048", "-nodes", "-keyout", key, "-out", certificate, - "-days", "1", "-subj", "/CN=localhost", "-addext", "subjectAltName=IP:127.0.0.1,DNS:localhost"], { stdio: "ignore" }); - tlsIdentity.key = await readFile(key); tlsIdentity.cert = await readFile(certificate); - oldCAs = getCACertificates("default"); oldAgent = https.globalAgent; - const certificates = [...oldCAs, tlsIdentity.cert.toString("utf8")]; - setDefaultCACertificates(certificates); https.globalAgent = new https.Agent({ ca: certificates }); - }); - afterAll(() => { - https.globalAgent.destroy(); https.globalAgent = oldAgent; setDefaultCACertificates(oldCAs); - }); - const nativeIt = process.platform === "win32" ? it.skip : realProcessIt; - nativeIt.for([...(["codex", "claude"] as const).flatMap(harness => (["cached", "adopted", "adopted restart"] as const).map(mode => [harness, mode] as const)), ["codex", "adopted cancellation"] as const, ["codex", "adopted legacy cancellation"] as const, - ["codex", "cached cancellation"] as const, ["codex", "cached held claim"] as const, ["claude", "cached held claim"] as const, - ["codex", "cached relaunch"] as const, ["claude", "cached relaunch"] as const, ["codex", "adopted relaunch"] as const, - ["codex", "adopted restart relaunch"] as const, ["claude", "adopted restart relaunch"] as const, - ["codex", "cached managed GitHub"] as const, ["codex", "adopted managed GitHub"] as const, ["codex", "adopted restart managed GitHub"] as const])("completes %s runs through a retained %s process", { timeout: 60_000 }, async ([harness, mode], context) => { +export function registerPluginRunnerReleaseResumeSuite(group: "cached" | "adopted"): void { + const cases = allReleaseResumeCases.filter(([, mode]) => (group === "adopted") === mode.startsWith("adopted")); + describeEmbeddedPostgres(`plugin Runner release/resume through the Core execution entry (${group})`, () => { + let currentCase: { teardown?: () => Promise } | undefined; + afterEach(async () => { + const finished = currentCase; + currentCase = undefined; + await finished?.teardown?.(); + }); + const environment = nativeRestartFixture(); + const tlsIdentity = { key: Buffer.alloc(0), cert: Buffer.alloc(0) }; + let oldCAs: string[] = [], oldAgent = https.globalAgent; + beforeAll(async () => { + const key = join(environment.current.runtimeRoot, "tls.key"), certificate = join(environment.current.runtimeRoot, "tls.crt"); + execFileSync("openssl", ["req", "-x509", "-newkey", "rsa:2048", "-nodes", "-keyout", key, "-out", certificate, + "-days", "1", "-subj", "/CN=localhost", "-addext", "subjectAltName=IP:127.0.0.1,DNS:localhost"], { stdio: "ignore" }); + tlsIdentity.key = await readFile(key); tlsIdentity.cert = await readFile(certificate); + oldCAs = getCACertificates("default"); oldAgent = https.globalAgent; + const certificates = [...oldCAs, tlsIdentity.cert.toString("utf8")]; + setDefaultCACertificates(certificates); https.globalAgent = new https.Agent({ ca: certificates }); + }); + afterAll(() => { + https.globalAgent.destroy(); https.globalAgent = oldAgent; setDefaultCACertificates(oldCAs); + }); + const nativeIt = process.platform === "win32" ? it.skip : realProcessIt; + nativeIt.for(cases)("completes %s runs through a retained %s process", { timeout: 60_000 }, async ([harness, mode], context) => { if (harness === "claude" && !existsSync(fakeAcpxSidecar)) context.skip(); const thisCase: { teardown?: () => Promise } = {}; currentCase = thisCase; @@ -314,7 +329,7 @@ describeEmbeddedPostgres("plugin Runner release/resume through the Core executio const providerSessionId = (await supervisor()).snapshot.providerSessionId; expect(providerSessionId).toEqual(expect.any(String)); const pid = handle!.child.pid; - const { heartbeatService } = await import("../heartbeat.js"); + const { heartbeatService } = await import("../../services/heartbeat.js"); expect(await heartbeatService(db).prepareIdleWarmNativeSessionsForSleep({ canRetire: () => true })) .toEqual({ closed: 0, busy: 0, failed: 0, failures: [] }); expect(stops).toBe(0); expect(handle!.isExitConfirmed?.()).toBe(false); @@ -420,4 +435,5 @@ describeEmbeddedPostgres("plugin Runner release/resume through the Core executio await pendingFollowup?.catch(() => undefined); } }); -}); + }); +} diff --git a/server/src/services/native-runtime/native-runner-restart-diskless-direct.integration.test.ts b/server/src/services/native-runtime/native-runner-restart-diskless-direct.integration.test.ts new file mode 100644 index 00000000000..c65c9c37293 --- /dev/null +++ b/server/src/services/native-runtime/native-runner-restart-diskless-direct.integration.test.ts @@ -0,0 +1,6 @@ +// Isolated embedded Postgres per file so the direct and prepared-task 60s +// real-clock lease-expiry restart cases run in parallel across Vitest workers +// instead of bounding the native-server lane at ~191s serially. +import { registerNativeRunnerRestartDisklessSuite } from "../../__tests__/helpers/native-runner-restart-diskless.js"; + +registerNativeRunnerRestartDisklessSuite(false); diff --git a/server/src/services/native-runtime/native-runner-restart-diskless-prepared-task.integration.test.ts b/server/src/services/native-runtime/native-runner-restart-diskless-prepared-task.integration.test.ts new file mode 100644 index 00000000000..66e39f965e7 --- /dev/null +++ b/server/src/services/native-runtime/native-runner-restart-diskless-prepared-task.integration.test.ts @@ -0,0 +1,6 @@ +// Isolated embedded Postgres per file so the direct and prepared-task 60s +// real-clock lease-expiry restart cases run in parallel across Vitest workers +// instead of bounding the native-server lane at ~191s serially. +import { registerNativeRunnerRestartDisklessSuite } from "../../__tests__/helpers/native-runner-restart-diskless.js"; + +registerNativeRunnerRestartDisklessSuite(true); diff --git a/server/src/services/native-runtime/plugin-runner-eviction-claude-abrupt.integration.test.ts b/server/src/services/native-runtime/plugin-runner-eviction-claude-abrupt.integration.test.ts new file mode 100644 index 00000000000..f755dc93069 --- /dev/null +++ b/server/src/services/native-runtime/plugin-runner-eviction-claude-abrupt.integration.test.ts @@ -0,0 +1,3 @@ +import { registerPluginRunnerEvictionSuite } from "../../__tests__/helpers/plugin-runner-eviction.js"; + +registerPluginRunnerEvictionSuite("claude", "abrupt"); diff --git a/server/src/services/native-runtime/plugin-runner-eviction-claude-retired.integration.test.ts b/server/src/services/native-runtime/plugin-runner-eviction-claude-retired.integration.test.ts new file mode 100644 index 00000000000..49222f468fc --- /dev/null +++ b/server/src/services/native-runtime/plugin-runner-eviction-claude-retired.integration.test.ts @@ -0,0 +1,3 @@ +import { registerPluginRunnerEvictionSuite } from "../../__tests__/helpers/plugin-runner-eviction.js"; + +registerPluginRunnerEvictionSuite("claude", "retired"); diff --git a/server/src/services/native-runtime/plugin-runner-eviction-codex-abrupt.integration.test.ts b/server/src/services/native-runtime/plugin-runner-eviction-codex-abrupt.integration.test.ts new file mode 100644 index 00000000000..859a494a003 --- /dev/null +++ b/server/src/services/native-runtime/plugin-runner-eviction-codex-abrupt.integration.test.ts @@ -0,0 +1,3 @@ +import { registerPluginRunnerEvictionSuite } from "../../__tests__/helpers/plugin-runner-eviction.js"; + +registerPluginRunnerEvictionSuite("codex", "abrupt"); diff --git a/server/src/services/native-runtime/plugin-runner-eviction-codex-retired.integration.test.ts b/server/src/services/native-runtime/plugin-runner-eviction-codex-retired.integration.test.ts new file mode 100644 index 00000000000..b036f8c4cf3 --- /dev/null +++ b/server/src/services/native-runtime/plugin-runner-eviction-codex-retired.integration.test.ts @@ -0,0 +1,3 @@ +import { registerPluginRunnerEvictionSuite } from "../../__tests__/helpers/plugin-runner-eviction.js"; + +registerPluginRunnerEvictionSuite("codex", "retired"); diff --git a/server/src/services/native-runtime/plugin-runner-release-resume-adopted.integration.test.ts b/server/src/services/native-runtime/plugin-runner-release-resume-adopted.integration.test.ts new file mode 100644 index 00000000000..feee6ea852e --- /dev/null +++ b/server/src/services/native-runtime/plugin-runner-release-resume-adopted.integration.test.ts @@ -0,0 +1,3 @@ +import { registerPluginRunnerReleaseResumeSuite } from "../../__tests__/helpers/plugin-runner-release-resume.js"; + +registerPluginRunnerReleaseResumeSuite("adopted"); diff --git a/server/src/services/native-runtime/plugin-runner-release-resume-cached.integration.test.ts b/server/src/services/native-runtime/plugin-runner-release-resume-cached.integration.test.ts new file mode 100644 index 00000000000..f778e4756ec --- /dev/null +++ b/server/src/services/native-runtime/plugin-runner-release-resume-cached.integration.test.ts @@ -0,0 +1,3 @@ +import { registerPluginRunnerReleaseResumeSuite } from "../../__tests__/helpers/plugin-runner-release-resume.js"; + +registerPluginRunnerReleaseResumeSuite("cached");