Reuse retained Runner descriptions during startup (#21004)

This commit is contained in:
Nicky Leach authored and GitHub committed 2026-11-11 21:20:08 -08:00
1 parent cf1def0ca6
commit d68088465c
7 files changed
+41 -24

No files matched your search

@@ -17722,7 +17722,8 @@ describe("runnerd provider runtime wiring", () => {
}
});
it.each(["codex", "opencode", "acpx"] as const)("uses a task-only %s driver without exposing Core paths or transferring the agent home", async (kind) => {
it.each([["codex", undefined], ["opencode", undefined], ["acpx", undefined], ["codex", "task"], ["codex", "previous-task"]] as const)(
"uses a task-only %s driver with a prior description for %s without exposing Core paths or transferring the agent home", async (kind, describedTask) => {
const taskExecution = { ...execution, provider: kind === "codex" ? execution.provider
: kind === "opencode" ? { kind, model: "openai/test", permissionMode: "deny" }
: { kind, agent: "claude", model: "claude-sonnet-4-6", permissionMode: "deny-all", claudeEffort: "high" } } as NativeExecutionInput;
@@ -17735,12 +17736,16 @@ describe("runnerd provider runtime wiring", () => {
const readWorkspaceFile = vi.fn(async () => Buffer.from("proof"));
const release = vi.fn(async () => {}), resume = vi.fn(async () => "resumed" as const);
const owner = vi.spyOn(pluginTaskRuntime, "createPluginRunnerTaskOwner").mockReturnValue({ launcher, registration, driver, readWorkspaceFile, release, resume, isRetired: () => false, retireSupersededTask: async () => false, retiredBeforeClaim: () => false, credentialsUpdated: vi.fn(), rebind:vi.fn() });
const description = { kind: "description" as const, launchPreparationVersion: 1 as const, projectAuthCheckVersion: 1 as const,
releaseResumeVersion: 1 as const, ...(kind === "codex" ? { workspaceFileReadVersion: 1 as const } : {}),
taskId: "task", runner: { version: "fixture", digest: `sha256:${"a".repeat(64)}` } };
const task = vi.fn(async (operation: unknown) => {
environmentTaskOperationSchema.parse(operation);
return { kind: "description", launchPreparationVersion: 1, projectAuthCheckVersion: 1, releaseResumeVersion: 1, ...(kind === "codex" ? { workspaceFileReadVersion: 1 } : {}), taskId: "task", runner: { version: "fixture", digest: `sha256:${"a".repeat(64)}` } };
return description;
});
const target = { kind: "remote", transport: "sandbox", providerKey: "plugin", leaseId: "plugin-task-lease",
remoteCwd: "/unused", runnerTask: task, runnerTaskProjectIds: ["10000000-0000-4000-8000-000000000001"] } as const;
remoteCwd: "/unused", runnerTask: task, runnerTaskProjectIds: ["10000000-0000-4000-8000-000000000001"],
sandboxLeaseAcquisition: { outcome: "created", providerLeaseId: "task" } } as const;
const updates: Array<{ table: unknown; values: Record<string, unknown> }> = [];
state.createBackend.mockClear(); state.createTransport.mockClear();
try {
@@ -17748,6 +17753,7 @@ describe("runnerd provider runtime wiring", () => {
.rejects.toThrow("runner_ingress_unavailable");
await createRunnerdBackend({ db: leaseDb(execution, {}, {}, updates), execution: taskExecution, runnerInstanceId: "runner", runnerExecutionTarget: target,
runnerIngressAuthorized: true,
...(describedTask ? { pluginTaskDescription: { ...description, taskId: describedTask } } : {}),
runnerEnvironment: { HOME: "/controller/private", PATH: "/controller/bin", OPENAI_API_KEY: "fixture-secret",
PAPERCLIP_NATIVE_MCP_NAME: "assigned", PAPERCLIP_NATIVE_MCP_URL: "http://localhost/mcp/gateways/assigned-test",
PAPERCLIP_NATIVE_MCP_TOKEN: "fixture-mcp-secret" } });
@@ -17770,7 +17776,7 @@ describe("runnerd provider runtime wiring", () => {
for (const key of ["environment", "codexCommand", "codexArgs", "runnerRuntimePaths", "readRunnerState", "archiveExternalRunnerState"]) {
expect(options).not.toHaveProperty(key);
}
expect(task.mock.calls).toEqual([[{ kind: "describe" }]]);
expect(task.mock.calls).toEqual(describedTask === "task" ? [] : [[{ kind: "describe" }]]);
expect(release).not.toHaveBeenCalled();
expect(resume).not.toHaveBeenCalled();
const binding = state.toolAuthorityDefinitions.mock.calls.at(-1)![0] as unknown as {
@@ -10686,6 +10686,7 @@ async function executePaperclipNativeSessionAttempt(
});
let retainedTransition: VerifiedWarmTransitionBinding | undefined;
let remoteWarmRecovery: RemoteWarmSessionRecovery | undefined;
let pluginTaskDescription: Extract<ReturnType<typeof environmentTaskResultSchema.parse>,{kind:"description"}> | undefined;
const cachedReleasedOwner = warmNativeSessions.get(nativeSessionScopeKey(input.execution));
if (cachedReleasedOwner?.released) {
const proof = releasedWarmRunner(readWarmNativeEnvelope(input.execution));
@@ -10728,7 +10729,9 @@ async function executePaperclipNativeSessionAttempt(
if (taskTarget.transport === "sandbox" && taskTarget.runnerTask && taskTarget.leaseId &&
durableIdentityMatchesSession(identity,input.execution) && identity.runId !== input.execution.binding.runId) {
// Inspection can replace a stopped retained task before deciding between adoption and checkpoint recovery.
await taskTarget.runnerTask({kind:"describe"});
const description = environmentTaskResultSchema.parse(await taskTarget.runnerTask({kind:"describe"}));
if (description.kind !== "description") throw new Error("Plugin Runner description unavailable");
pluginTaskDescription = description;
if (taskTarget.sandboxLeaseAcquisition?.outcome !== "resumed") {
await recoverPluginRunnerCheckpoint(input, root);
}
@@ -11709,7 +11712,6 @@ async function executePaperclipNativeSessionAttempt(
);
let existingWarmSession: NativeSession | undefined;
let reusingReleasedRunner = false;
let pluginTaskDescription: Extract<ReturnType<typeof environmentTaskResultSchema.parse>,{kind:"description"}> | undefined;
let managedCredentialSession: NativeSession | undefined;
let githubAccess: NativeGitHubAccess | undefined;
let releaseGitHubRun: (() => void) | undefined;
@@ -11747,7 +11749,9 @@ async function executePaperclipNativeSessionAttempt(
if (entry) entry.preparingRunId = undefined;
const taskTarget=input.runnerExecutionTarget;
if ((entry?.pluginTaskId || remoteWarmRecovery?.releasedSource) && taskTarget?.kind === "remote" && taskTarget.transport === "sandbox" && taskTarget.runnerTask) {
const description=environmentTaskResultSchema.parse(await (executionContext
const priorDescription = pluginTaskDescription?.taskId === taskTarget.sandboxLeaseAcquisition?.providerLeaseId
? pluginTaskDescription : undefined;
const description=priorDescription ?? environmentTaskResultSchema.parse(await (executionContext
? executionContext.wait(() => taskTarget.runnerTask!({kind:"describe"}, { executionContext }))
: taskTarget.runnerTask({kind:"describe"})));
if(description.kind !== "description") throw new Error("Plugin Runner description unavailable");
@@ -12058,7 +12062,7 @@ async function executePaperclipNativeSessionAttempt(
const description = environmentTaskResultSchema.parse(await (executionContext ? executionContext.wait(inspect) : inspect()));
if (description.kind !== "description" || description.taskId === retainedTaskId) return false;
existingWarmSession = undefined;
pluginTaskDescription = undefined;
pluginTaskDescription = description;
await finishStartupContextForFallback();
persistedWarmSession = loadWarmNativeCheckpoint(input.execution, warmConfigDigest, target.kind);
runnerdBackend = await createExecutionBackend();
@@ -16013,7 +16017,9 @@ async function createRunnerdBackendWithinSessionClaim(
if(stopped.kind!=="status" || stopped.executionStopped!==true) throw new Error("Plugin Runner termination is unconfirmed; reconcile the saved task");
await pluginTask({kind:"complete"});
}
const description = input.pluginTaskDescription ?? environmentTaskResultSchema.parse(await pluginTask({ kind: "describe" }));
const priorDescription = input.pluginTaskDescription?.taskId === remoteTarget.sandboxLeaseAcquisition?.providerLeaseId
? input.pluginTaskDescription : undefined;
const description = priorDescription ?? environmentTaskResultSchema.parse(await pluginTask({ kind: "describe" }));
if (description.kind !== "description" || description.launchPreparationVersion !== 1 || description.projectAuthCheckVersion !== 1) throw new Error("Plugin Runner launch preparation v1 unavailable");
const saved = durableBinding ? durableIdentity as RunnerdDurableIdentity : undefined;
const prior = saved ? {