mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-23 21:24:45 +01:00
Configure managed plugin Runner lifecycle (#21065)
## Thinking Path > - Paperclip runs agents in managed environments. > - An agent can use an explicit environment or the instance default. > - A lifecycle plugin must receive the driver that provisions the agent. > - A managed plugin environment also needs to select the Runner process lifecycle. > - This change gives lifecycle selection and provisioning the same environment lookup. ## Linked Issues or Issue Description **What existing behavior does this improve?** Managed plugin environment provisioning and lifecycle configuration. **Current behavior** Lifecycle calls lack the selected plugin driver. Managed plugin configuration cannot select warm Runner execution. **Proposed behavior** Resolve the environment once per lifecycle operation. Pass the driver key for the plugin that serves it. Parse and persist the managed Runner lifecycle mode. The portable ownership and workspace placement changes are in [#21066](https://github.com/paperclipai/paperclip/pull/21066) and [#20743](https://github.com/paperclipai/paperclip/pull/20743). ## What Changed - Share agent environment resolution between required plugin selection and the lifecycle RPC. - Pass `environmentDriverKey` to the plugin that serves the selected environment. - Allow managed plugin environments to set `warm` or `per_turn` and persist the selected mode. - Advertise `pluginEnvironmentRunnerLifecycleMode` in the release capability manifest so senders can check support before including the field. ## Verification - Built shared types, the plugin SDK, and Runner. Server typecheck and SDK source-pin check passed for the initial layer. - The capability contract test failed before the manifest fix and passed after it. Independent verification passed all 160 tests across managed configuration, plugin environment persistence, lifecycle routing, and environment reconciliation. - Routing coverage includes the instance default, an explicit second driver from the same plugin, and an explicit sandbox. - [Hosted CI](https://github.com/paperclipai/paperclip/actions/runs/43193311862) passed on `f07b192c21`. The first attempt timed out in an unchanged workspace-recovery fixture and then collided with a background recovery action. The exact test and all 44 tests in its suite passed locally; the isolated shard retry passed without code changes. ## Risks - Existing managed configuration can omit the lifecycle mode. Senders must check the target release for `pluginEnvironmentRunnerLifecycleMode` before sending the new field. Publishing this signal does not update external deployment tools. ## Model Used - OpenAI Codex GPT-6 with GPT-6.1 Sol agents for implementation and independent review. ## Checklist - [x] Thinking path and model are included. - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] The issue is described using the enhancement template. - [x] Local checks passed and new behavior has tests. - [x] All Paperclip CI gates are green. - [x] Greptile is 5/5 with no open findings. --------- Co-authored-by: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
1af987690d
commit
782d6bead4
11 files changed
+78
-18
No files matched your search
@@ -15,6 +15,15 @@ import { AGENT_LIFECYCLE_STOP_REASON, COMPANY_ARCHIVED_STOP_REASON } from "./gov
|
||||
export function createLifecycleDriver(db: Db, manager: PluginWorkerManager): LifecycleDriver {
|
||||
const { verify } = agentHarnessVerificationService(db, manager);
|
||||
const heartbeat = heartbeatService(db, { pluginWorkerManager: manager });
|
||||
|
||||
async function resolveAgentEnvironment(agent: { id: string; companyId: string }) {
|
||||
const [placement] = await db.select({ environmentId: agents.defaultEnvironmentId }).from(agents)
|
||||
.where(and(eq(agents.id, agent.id), eq(agents.companyId, agent.companyId)));
|
||||
const environmentId = placement?.environmentId ?? (await instanceSettingsService(db).get()).defaultEnvironmentId;
|
||||
const [environment] = environmentId ? await db.select().from(environments).where(eq(environments.id, environmentId)) : [];
|
||||
return environment;
|
||||
}
|
||||
|
||||
return {
|
||||
async onReady(agent) {
|
||||
await db.transaction(tx => promoteDeferredWorkIntents(tx, { companyId: agent.companyId, trigger: "pause_lifted" }));
|
||||
@@ -27,9 +36,7 @@ export function createLifecycleDriver(db: Db, manager: PluginWorkerManager): Lif
|
||||
.where(and(eq(pluginCompanySettings.companyId, agent.companyId), eq(pluginCompanySettings.enabled, false)));
|
||||
const candidates = installed.filter(plugin => !disabled.some(row => row.pluginId === plugin.id) &&
|
||||
plugin.manifestJson.agentLifecycle && plugin.manifestJson.capabilities.includes("agents.lifecycle.manage"));
|
||||
const [row] = await db.select({ environmentId: agents.defaultEnvironmentId }).from(agents).where(eq(agents.id, agent.id));
|
||||
const environmentId = row?.environmentId ?? (await instanceSettingsService(db).get()).defaultEnvironmentId;
|
||||
const [environment] = environmentId ? await db.select().from(environments).where(eq(environments.id, environmentId)) : [];
|
||||
const environment = await resolveAgentEnvironment(agent);
|
||||
if (selected !== null) {
|
||||
const added = candidates.filter(plugin => pluginServesAgentEnvironment(plugin, environment) && !selected.includes(plugin.id));
|
||||
return [...selected, ...added.map(plugin => plugin.id)];
|
||||
@@ -47,8 +54,11 @@ export function createLifecycleDriver(db: Db, manager: PluginWorkerManager): Lif
|
||||
const secrets = agentInstanceSecretService(db);
|
||||
const instanceSecrets = ["preparing", "resuming"].includes(agent.lifecycleState)
|
||||
? await secrets.read({ companyId: agent.companyId, agentId: agent.id, pluginId }) : {};
|
||||
const environment = await resolveAgentEnvironment(agent);
|
||||
const environmentDriverKey = pluginServesAgentEnvironment(plugin, environment) && typeof environment?.config?.driverKey === "string"
|
||||
? environment.config.driverKey : undefined;
|
||||
const request = { companyId: agent.companyId, agentId: agent.id, operationId, version: agent.lifecycleVersion, phase: agent.lifecycleState,
|
||||
instanceSecrets };
|
||||
...(environmentDriverKey ? { environmentDriverKey } : {}), instanceSecrets };
|
||||
const result = await manager.call(plugin.id, "agentLifecycle", request, 30_000);
|
||||
if (!result || result.operationId !== operationId || result.version !== agent.lifecycleVersion || !["complete", "pending"].includes(result.status)) {
|
||||
throw Object.assign(new Error("Invalid lifecycle result"), { code: "invalid_lifecycle_result" });
|
||||
|
||||
@@ -1 +1 @@
|
||||
{ "schemaVersion": 1, "capabilities": ["pluginEnvironments"] }
|
||||
{ "schemaVersion": 1, "capabilities": ["pluginEnvironments", "pluginEnvironmentRunnerLifecycleMode"] }
|
||||
@@ -21,7 +21,7 @@ describe("managed-config-capabilities.json", () => {
|
||||
it("keeps the published contract", () => {
|
||||
expect(JSON.parse(readFileSync(capabilitiesFile, "utf8"))).toEqual({
|
||||
schemaVersion: 1,
|
||||
capabilities: ["pluginEnvironments"],
|
||||
capabilities: ["pluginEnvironments", "pluginEnvironmentRunnerLifecycleMode"],
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -95,7 +95,10 @@ export const MANAGED_ENVIRONMENT_DRIVERS = ["sandbox", "plugin"] as const;
|
||||
* including `instanceDefault`.
|
||||
*/
|
||||
export const MANAGED_CONFIG_CAPABILITIES_SCHEMA_VERSION = 1;
|
||||
export const MANAGED_CONFIG_CAPABILITIES = ["pluginEnvironments"] as const;
|
||||
export const MANAGED_CONFIG_CAPABILITIES = [
|
||||
"pluginEnvironments",
|
||||
"pluginEnvironmentRunnerLifecycleMode",
|
||||
] as const;
|
||||
export type ManagedConfigCapability = (typeof MANAGED_CONFIG_CAPABILITIES)[number];
|
||||
|
||||
function supportsCapability(capability: ManagedConfigCapability): boolean {
|
||||
@@ -126,6 +129,7 @@ export interface ManagedPluginEnvironmentSpec {
|
||||
driverKey: string;
|
||||
/** Driver config, validated by the plugin at ensure time; never carries secrets. */
|
||||
driverConfig: Readonly<Record<string, unknown>>;
|
||||
runnerLifecycleMode?: "warm" | "per_turn";
|
||||
/**
|
||||
* Fill the instance default with this environment when the default is
|
||||
* unset (or names the local environment or a deleted one), before the
|
||||
@@ -230,6 +234,7 @@ const PLUGIN_ENTRY_KEYS = [
|
||||
"pluginKey",
|
||||
"driverKey",
|
||||
"driverConfig",
|
||||
"runnerLifecycleMode",
|
||||
"instanceDefault",
|
||||
] as const;
|
||||
/** Same rule as the plugin environment config schema in `environment-config.ts`. */
|
||||
@@ -367,6 +372,10 @@ function parseManagedEnvironmentsSection(
|
||||
}
|
||||
pluginDrivers.add(pair);
|
||||
const driverConfig = readSecretFreeObject(entry.driverConfig, `${at}.driverConfig`);
|
||||
const runnerLifecycleMode = entry.runnerLifecycleMode;
|
||||
if (runnerLifecycleMode !== undefined && runnerLifecycleMode !== "warm" && runnerLifecycleMode !== "per_turn") {
|
||||
fail(`"${at}.runnerLifecycleMode" must be "warm" or "per_turn"`);
|
||||
}
|
||||
if (entry.instanceDefault !== undefined && typeof entry.instanceDefault !== "boolean") {
|
||||
fail(`"${at}.instanceDefault" must be a boolean when present (got ${describeJsonValue(entry.instanceDefault)})`);
|
||||
}
|
||||
@@ -387,6 +396,7 @@ function parseManagedEnvironmentsSection(
|
||||
pluginKey,
|
||||
driverKey,
|
||||
driverConfig: Object.freeze(driverConfig),
|
||||
...(runnerLifecycleMode ? { runnerLifecycleMode } : {}),
|
||||
instanceDefault,
|
||||
}) as ManagedPluginEnvironmentSpec,
|
||||
);
|
||||
|
||||
@@ -555,6 +555,7 @@ export async function applyManagedEnvironments(
|
||||
pluginKey: spec.pluginKey,
|
||||
driverKey: spec.driverKey,
|
||||
driverConfig: { ...spec.driverConfig },
|
||||
...(spec.runnerLifecycleMode ? { runnerLifecycleMode: spec.runnerLifecycleMode } : {}),
|
||||
workerManager,
|
||||
});
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ export interface ManagedPluginEnvironmentInput {
|
||||
pluginKey: string;
|
||||
driverKey: string;
|
||||
driverConfig?: Record<string, unknown>;
|
||||
runnerLifecycleMode?: "warm" | "per_turn";
|
||||
/** Runs the plugin's own config validation (`environmentValidateConfig`). */
|
||||
workerManager: Pick<PluginWorkerManager, "call" | "isRunning">;
|
||||
}
|
||||
@@ -79,7 +80,8 @@ function servesPair(row: EnvironmentRow, input: { pluginKey: string; driverKey:
|
||||
async function validatedDriverConfig(db: Db, input: ManagedPluginEnvironmentInput): Promise<PluginEnvironmentConfig> {
|
||||
const normalized = normalizeEnvironmentConfig({
|
||||
driver: "plugin",
|
||||
config: { pluginKey: input.pluginKey, driverKey: input.driverKey, driverConfig: input.driverConfig ?? {} },
|
||||
config: { pluginKey: input.pluginKey, driverKey: input.driverKey, driverConfig: input.driverConfig ?? {},
|
||||
...(input.runnerLifecycleMode ? { runnerLifecycleMode: input.runnerLifecycleMode } : {}) },
|
||||
}) as unknown as PluginEnvironmentConfig;
|
||||
return await validatePluginEnvironmentDriverConfig({
|
||||
db,
|
||||
|
||||
Reference in new issue
Block a user