diff --git a/doc/plugins/PLUGIN_RUNNER_EXECUTION.md b/doc/plugins/PLUGIN_RUNNER_EXECUTION.md index 13c14082d53..6ec33ef15d9 100644 --- a/doc/plugins/PLUGIN_RUNNER_EXECUTION.md +++ b/doc/plugins/PLUGIN_RUNNER_EXECUTION.md @@ -370,6 +370,11 @@ a Core-managed credential identity before lease acquisition. The saved warm preference does not bypass account ownership checks. Drivers without warm capability and setup probes remain ephemeral. +For a warm lease, `onEnvironmentAcquireLease` receives `runnerLifecyclePolicy` +with the idle window that Core records for the Runner. A provider with its own +idle shutdown can use it to stop only after that window. Core does not send +the field for other lifecycle modes. + Plugin task execution uses the public, run-scoped GitHub credential broker when the provider advertises its versioned contract. Warm preparation updates the command capability before admitting the new run. Restart recovery retains diff --git a/packages/plugins/sdk/src/protocol.ts b/packages/plugins/sdk/src/protocol.ts index 97ee5337227..6cbc6424126 100644 --- a/packages/plugins/sdk/src/protocol.ts +++ b/packages/plugins/sdk/src/protocol.ts @@ -693,6 +693,7 @@ export interface PluginEnvironmentAcquireLeaseParams extends PluginEnvironmentDr * lifetime. */ requestedExpiresAt?: string | null; + runnerLifecyclePolicy?: { mode: "warm"; idleTimeoutMs: number }; } export interface PluginEnvironmentResumeLeaseParams extends PluginEnvironmentDriverBaseParams { diff --git a/server/src/__tests__/environment-runtime.test.ts b/server/src/__tests__/environment-runtime.test.ts index 93d4e6c2e5c..0e1a32e8997 100644 --- a/server/src/__tests__/environment-runtime.test.ts +++ b/server/src/__tests__/environment-runtime.test.ts @@ -1316,7 +1316,7 @@ describeEmbeddedPostgres("environmentRuntimeService", () => { await db.insert(issues).values({ id: issueId, companyId: seeded.companyId, title: "Portable session", status: "in_progress" }); await db.insert(heartbeatRuns).values({ id: nextRunId, companyId: seeded.companyId, agentId: seeded.agentId, status: "running" }); let acquisitions = 0; - const call = vi.fn(async (_plugin: string, method: string) => { + const call = vi.fn(async (_plugin: string, method: string, _params?: unknown) => { if (method === "environmentAcquireLease") return { providerLeaseId: `sandbox-${++acquisitions}`, metadata: { ownershipGeneration: `generation-${acquisitions}` } }; if (method === "environmentResumeLease") return { providerLeaseId: "sandbox-1", metadata: {} }; @@ -1332,6 +1332,9 @@ describeEmbeddedPostgres("environmentRuntimeService", () => { const acquisitionInput = { ...input, selectedEnvironmentId: seeded.environment.id, localEnvironmentId: randomUUID(), admittedLifecycleMode: "warm" as const, executionWorkspaceSettings: null }; const first = await orchestrator.acquireForRun({ ...acquisitionInput, heartbeatRunId: seeded.runId }); + expect(call.mock.calls.find(([, method]) => method === "environmentAcquireLease")?.[2]) + .toMatchObject({ runnerLifecyclePolicy: { mode: "warm", idleTimeoutMs: 300_000 } }); + expect(first.lease.metadata?.runnerTaskLifecyclePolicy).toEqual({ mode: "warm", idleTimeoutMs: 300_000 }); await db.update(environmentLeases).set({ status: "retained", metadata: { ...first.lease.metadata, runnerTaskIdentity: { sessionId }, ...(mode === "legacy resume" ? {} : { runnerTaskAccountIdentity: "test-account" }), @@ -6447,6 +6450,8 @@ describeEmbeddedPostgres("environmentRuntimeService", () => { runId, workspaceMode: undefined, }, ...(defaultAcquireTimeoutMs === undefined ? [] : [330_000])); + expect(vi.mocked(workerManager.call).mock.calls.find(([, method]) => method === "environmentAcquireLease")?.[2]) + .not.toHaveProperty("runnerLifecyclePolicy"); expect(acquired.lease.providerLeaseId).toBe("plugin-lease-1"); expect(acquired.lease.expiresAt?.toISOString()).toBe(expiresAt); expect(acquired.lease.metadata).toMatchObject({ diff --git a/server/src/services/environment-runtime.ts b/server/src/services/environment-runtime.ts index 98ec81e6b20..78ea669145a 100644 --- a/server/src/services/environment-runtime.ts +++ b/server/src/services/environment-runtime.ts @@ -3617,6 +3617,7 @@ function createPluginEnvironmentDriver( executionWorkspaceId: input.executionWorkspaceId ?? undefined, adapterType: input.adapterType ?? undefined, executionWorkspaceSettings: input.executionWorkspaceSettings, + ...(lifecyclePolicy.mode === "warm" ? { runnerLifecyclePolicy: lifecyclePolicy } : {}), // Forward a caller deadline so the provider configures a provider-side // expiry at or before it and returns the real provider expiry. ...(requestedExpiresAtParam(input.requestedExpiresAt) !== undefined diff --git a/tests/runner-e2e/source-sdk-public-inputs.json b/tests/runner-e2e/source-sdk-public-inputs.json index 9b0cdb49514..284e4959589 100644 --- a/tests/runner-e2e/source-sdk-public-inputs.json +++ b/tests/runner-e2e/source-sdk-public-inputs.json @@ -20,7 +20,7 @@ "packages/plugins/sdk/src/index.ts": "4e573c181198ea98442321cc136341741e856ff7", "packages/plugins/sdk/src/invocation-tracer.ts": "b28ac4aa4bc3e82658abac4a8081ed4508008696", "packages/plugins/sdk/src/protocol.duplex-channel.test.ts": "18255eb3d63038dc459240c111cbcb29fcba25cc", - "packages/plugins/sdk/src/protocol.ts": "97ee5337227e3a1ede6801fe5b7586cc6785edad", + "packages/plugins/sdk/src/protocol.ts": "6cbc642412650a511c60b23f5625ac018d189f9d", "packages/plugins/sdk/src/testing.ts": "fa99065efa867d8f8a9372cb4a448b8f9d687883", "packages/plugins/sdk/src/types.ts": "80375e46504f96c7c0c1f156319dfb81275d16cc", "packages/plugins/sdk/src/ui/clipboard.ts": "1f42069c97d731e636a6ad5481dad22d20c0ed63",