diff --git a/.github/workflows/runner-full-stack-e2e.yml b/.github/workflows/runner-full-stack-e2e.yml index 297f74da7ae..df00eb932fa 100644 --- a/.github/workflows/runner-full-stack-e2e.yml +++ b/.github/workflows/runner-full-stack-e2e.yml @@ -797,6 +797,16 @@ jobs: if [ "$NEEDS_NATIVE_BINARIES" = true ]; then pnpm --filter @paperclipai/paperclip-runner build:runner-binaries fi + # The source server imports the plugin SDK from its generated dist. + # Build it once here, with the same certified helper the cell uses, + # instead of in every paid cell. + node scripts/ensure-plugin-build-deps.mjs + for entry in packages/shared/dist/index.js packages/plugins/sdk/dist/index.js; do + if [ ! -f "$entry" ] || [ ! -f "$(dirname "$entry")/.paperclip-build-complete" ]; then + echo "::error::Workspace build output $entry is missing; paid cells would fail before any test runs." + exit 1 + fi + done - name: Package immutable campaign outputs env: @@ -814,6 +824,8 @@ jobs: ) archive_paths=( packages/paperclip-eval-kernel/dist + packages/shared/dist + packages/plugins/sdk/dist ) if [ "$NEEDS_RUNNER_TYPESCRIPT" = true ]; then test -d packages/paperclip-runner/dist @@ -1235,6 +1247,12 @@ jobs: --file runner-e2e-build/runner-e2e-build-bundle.tar.gz \ --directory "$GITHUB_WORKSPACE" test -d packages/paperclip-eval-kernel/dist + for entry in packages/shared/dist/index.js packages/plugins/sdk/dist/index.js; do + if [ ! -f "$entry" ]; then + echo "::error::Campaign outputs lack $entry; the source server cannot start without it." + exit 1 + fi + done if [ "$NEEDS_RUNNER_TYPESCRIPT" = true ]; then test -d packages/paperclip-runner/dist fi diff --git a/server/src/services/native-runtime/native-controller-recovery.ts b/server/src/services/native-runtime/native-controller-recovery.ts index c7523d642f0..806cc82b1b0 100644 --- a/server/src/services/native-runtime/native-controller-recovery.ts +++ b/server/src/services/native-runtime/native-controller-recovery.ts @@ -11,6 +11,9 @@ import { findNativeSessionResumeRun, isNativeSessionId, isUnusedNativeSessionBoo import { insertMigratedNativeRunnerCheckpoint, loadNativeRunnerCheckpoint } from "./native-runner-checkpoint.js"; import { offlineMigrationExecutionWhere } from "../offline-migration-execution.js"; import { redactRunnerApiPayloads } from "./runner-api-log-redaction.js"; +import { NATIVE_AGENT_DIRECTORY_BUSY_WAIT, NATIVE_RETAINED_OWNER_WAIT } from "./native-recovery-wait-codes.js"; + +export { NATIVE_AGENT_DIRECTORY_BUSY_WAIT, NATIVE_RETAINED_OWNER_WAIT }; export const NATIVE_CONTROLLER_RECOVERY_MAX_BYTES = 4 * 1024; @@ -68,7 +71,6 @@ export type NativeControllerRecoveryOutcome = | { kind: "missing_evidence" | "unsupported" | "dependency_unavailable"; reason: string; cause?: unknown } | { kind: "no_prior_execution" }; -export const NATIVE_RETAINED_OWNER_WAIT = "native_controller_recovery_waiting_for_owner"; export type NativeRetainedOwnerWait = { runId: string; controllerBootId: string }; @@ -138,7 +140,6 @@ export async function deferNativeControllerRecovery(db: Db, input: { }); } -export const NATIVE_AGENT_DIRECTORY_BUSY_WAIT = "agent_directory_operation_busy"; export async function deferNativeRunForBusyAgentDirectory(db: Db, input: { companyId: string; runId: string; leaseOwner?: string; retryAt: Date; maxDeferrals: number; diff --git a/server/src/services/native-runtime/native-recovery-wait-codes.ts b/server/src/services/native-runtime/native-recovery-wait-codes.ts new file mode 100644 index 00000000000..cd2b7d46422 --- /dev/null +++ b/server/src/services/native-runtime/native-recovery-wait-codes.ts @@ -0,0 +1,5 @@ +// Dependency-free failure codes shared by native recovery modules. Keep this a +// leaf: checkpoint readers import it, and those readers are also loaded by +// standalone tools that must not pull in the heartbeat service graph. +export const NATIVE_RETAINED_OWNER_WAIT = "native_controller_recovery_waiting_for_owner"; +export const NATIVE_AGENT_DIRECTORY_BUSY_WAIT = "agent_directory_operation_busy"; diff --git a/server/src/services/native-runtime/native-runner-checkpoint.ts b/server/src/services/native-runtime/native-runner-checkpoint.ts index 3a76c84ac17..4a93568dc75 100644 --- a/server/src/services/native-runtime/native-runner-checkpoint.ts +++ b/server/src/services/native-runtime/native-runner-checkpoint.ts @@ -9,7 +9,7 @@ import { createLocalEncryptedCipher, deriveLocalEncryptedInstanceSecret } from " import { legacyControllerBootId } from "../legacy-controller-lease.js"; import { assertNativeSourceCheckpointConsumer, lockSourceRecoveryCoordinators } from "./native-source-recovery-ownership.js"; import { runnerdStateHasNoProviderTurn, runnerdStateIsIncompleteBootstrap } from "./native-bootstrap-proof.js"; -import { NATIVE_RETAINED_OWNER_WAIT } from "./native-controller-recovery.js"; +import { NATIVE_RETAINED_OWNER_WAIT } from "./native-recovery-wait-codes.js"; import { OWN_PROCESS_START_EVENT_TYPES } from "../native-process-start-events.js"; type Binding = { companyId: string; issueId: string; runId: string }; diff --git a/tests/runner-e2e/server-startup-import-graph.test.ts b/tests/runner-e2e/server-startup-import-graph.test.ts new file mode 100644 index 00000000000..d5d1e040f63 --- /dev/null +++ b/tests/runner-e2e/server-startup-import-graph.test.ts @@ -0,0 +1,51 @@ +import path from "node:path"; +import { build, type Plugin } from "esbuild"; +import { describe, expect, it } from "vitest"; + +const repositoryRoot = path.resolve(import.meta.dirname, "../.."); + +// The source-server supervisor builds the plugin SDK (scripts/ensure-plugin-build-deps.mjs) +// before it starts Paperclip. Its own static imports load before that build, so they must +// never reach a workspace package whose entry point is generated output. When they did, +// every paid source cell failed with ERR_MODULE_NOT_FOUND before any test ran. +const BUILT_ONLY_PACKAGES = ["@paperclipai/plugin-sdk"]; + +async function staticImportPath(entry: string, target: string) { + const reached = new Map(); + const externalBare: Plugin = { + name: "external-bare", + setup(context) { + context.onResolve({ filter: /^[^./]/ }, args => { + if (args.path.startsWith("@paperclipai/") && !BUILT_ONLY_PACKAGES.some(name => args.path === name || args.path.startsWith(`${name}/`))) return undefined; + if (args.path === target || args.path.startsWith(`${target}/`)) reached.set(args.path, args.importer); + return { path: args.path, external: true }; + }); + }, + }; + const result = await build({ + entryPoints: [path.join(repositoryRoot, entry)], absWorkingDir: repositoryRoot, + bundle: true, write: false, metafile: true, platform: "node", format: "esm", logLevel: "silent", + plugins: [externalBare], + }); + if (!reached.size) return null; + const parents = new Map([[entry, ""]]); + const queue = [entry]; + while (queue.length) { + const file = queue.shift()!; + for (const imported of result.metafile.inputs[file]?.imports ?? []) { + if (imported.external || parents.has(imported.path)) continue; + parents.set(imported.path, file); + queue.push(imported.path); + } + } + const importer = path.relative(repositoryRoot, [...reached.values()][0]!); + const chain = [target, importer]; + for (let file = parents.get(importer); file; file = parents.get(file)) chain.push(file); + return chain.reverse().join(" -> "); +} + +describe("runner E2E source-server supervisor", () => { + it.each(BUILT_ONLY_PACKAGES)("loads without the generated %s output", async name => { + expect(await staticImportPath("tests/runner-e2e/server.ts", name)).toBeNull(); + }, 60_000); +}); diff --git a/tests/runner-e2e/workflow-security.test.ts b/tests/runner-e2e/workflow-security.test.ts index 49c28b6b7f6..ecf320784b6 100644 --- a/tests/runner-e2e/workflow-security.test.ts +++ b/tests/runner-e2e/workflow-security.test.ts @@ -704,6 +704,11 @@ describe("public repository paid workflow security", () => { expect(buildJob).toContain( "node packages/paperclip-runner/scripts/materialize-opencode-binary.mjs", ); + // The source server imports the plugin SDK from generated output. Build, + // check and ship it once so a missing dist fails here, not in every cell. + expect(buildJob).toContain("node scripts/ensure-plugin-build-deps.mjs"); + expect(buildJob).toMatch(/archive_paths=\(\n(?:\s+\S+\n)*?\s+packages\/plugins\/sdk\/dist\n/u); + expect(testJob).toContain("Campaign outputs lack $entry"); expect(buildJob).toContain("runner-e2e-build-bundle.tar.gz.sha256"); expect(buildJob).toContain("runner-e2e-provider-pack.tar.gz.sha256"); expect(buildJob).toContain(