mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 11:47:42 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The Paperclip Runner runs each agent in an environment: the host, a sandbox provider, or a plugin task environment > - An environment can set `runnerLifecycleMode: "warm"` (and `reuseLease: true` for sandboxes). Then the run keeps its task or sandbox lease alive and reuses it between runs > - Some harnesses are qualified only for per-turn sessions: Google Antigravity, Dot, Muse, Grok Bot, and Cursor Cloud > - The native session policy already keeps these harnesses per-turn. The environment view did not: on a warm plugin environment it leased a warm task, and on a warm sandbox environment it could lease or retain a reusable sandbox (`reuseLease: true`) > - The run-time Antigravity defense refuses a warm lifecycle (`antigravity_warm_unsupported`). An agent on a warm environment saved without error, but its run lifecycle disagreed with what the harness supports > - This pull request makes the environment view use the same per-turn-only declaration as the session policy, clears `reuseLease` on reusable sandboxes for per-turn-only harnesses, and enforces per-turn even over a persisted warm admission > - The benefit is that an agent with a per-turn-only harness saves and runs per-turn on every environment, with no failed runs and no manual fix ## Linked Issues or Issue Description **What happened?** A plugin environment with `runnerLifecycleMode: "warm"` (for example a managed Daytona or Unikraft task environment) or a sandbox environment with `runnerLifecycleMode: "warm"` / `reuseLease: true` overrode the agent's own lifecycle. For a Google Antigravity agent (or Dot, Grok Bot, Muse, Cursor Cloud), the run could lease a warm task or reusable sandbox kept between runs. The native session policy is qualified only per-turn, and Antigravity's run-time check refuses warm. The save-time check did not see the environment lifecycle, so the agent saved without error. **Expected behavior** A harness that supports only per-turn sessions runs per-turn on every environment, including when the environment asks for `warm` or `reuseLease: true`, and even if a pre-fix persisted warm admission exists. The user never saves a configuration that fails at run start. **Steps to reproduce** 1. Create a plugin environment with `runnerLifecycleMode: "warm"`, or a sandbox environment with `runnerLifecycleMode: "warm"` and `reuseLease: true`. 2. Save a Google Antigravity agent with a Google API key on that environment. The save succeeds. 3. Resolve the run environment for that agent (`resolveRunnerEnvironmentForRun`). On master the plugin task lifecycle is `warm` and a reusable sandbox retains `reuseLease: true`. **Deployment mode** Both local (`local_trusted`) and hosted/cloud (`authenticated`) Paperclip Runner deployments using plugin task or remote sandbox environments. ## What Changed - `requiresPerTurnNativeSession` in `server/src/services/native-runtime/native-warm-capability.ts` is now the single declaration of per-turn-only harnesses: Google Antigravity (`acpx_runtime` / `antigravity`), plus `openai_dot_mcp`, `grok_bot_mcp`, `muse_external`, and `cursor_cloud_api`, with an updated doc comment covering all five harnesses and both rationales. - Added `requiresPerTurnNativeSessionForConfig` in `native-warm-capability.ts` so the environment lifecycle view resolves per-turn-only harnesses through the same module, including when full provider-profile validation refuses a config (such as a pending Antigravity rollout without a company grant or an incomplete/invalid external bot config). - The native session policy (`server/src/services/heartbeat/native-lifecycle.ts`) uses `requiresPerTurnNativeSession` instead of duplicating the backend list. - The run environment view (`resolveRunnerEnvironmentForRun`, `resolveWarmRunnerIdleTimeoutMsForRun`, and `runnerLifecycleDefaultNeedsLeaseProbe`) now enforces per-turn-only harnesses ahead of `admittedLifecycleMode`, environment settings, and agent settings (matching `resolveHeartbeatNativeLifecyclePolicy`), and explicitly sets `reuseLease: false` on run-scoped sandbox views when the shared sandbox config has `reuseLease: true`. - Other harnesses continue to honor environment warm settings and admitted warm recovery. ## Verification - `server/src/services/runner-environment-lifecycle.test.ts`: covers all five per-turn-only harnesses (Google Antigravity, Dot, Grok Bot, Muse, Cursor Cloud) and refused external bot configs across warm plugin environments, warm sandboxes with `reuseLease: true`, and persisted `admittedLifecycleMode: "warm"`, plus unaffected harnesses keeping warm/admitted recovery. - `server/src/__tests__/antigravity-save-refusal.test.ts`: verifies saving a Google Antigravity agent with a Google API key on a warm plugin task environment resolves per-turn across the run environment, session policy, and run-time credential check. - `server/src/services/heartbeat/native-lifecycle.test.ts`: passes without changes. - `pnpm --filter @paperclipai/server typecheck` (all layers including `test-tree-0`) and targeted Vitest suites pass locally; full suite verified by CI. ## Risks - Low risk. The change affects only the five per-turn-only harnesses. Their sessions already ran per-turn, so only plugin task and sandbox lease retention change from warm/reusable to per-turn/ephemeral. - A per-turn-only harness no longer keeps a warm task or reusable sandbox between runs on a warm environment, including if an older run had a persisted warm admission. That retention was never qualified for these harnesses. - In the session policy, a saved warm policy for Dot, Muse, Grok Bot, or Cursor Cloud is now ignored; their configuration validators never allowed warm. > For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and discuss it in `#dev` before opening the PR. Feature PRs that overlap with planned core work may need to be redirected — check the roadmap first. See `CONTRIBUTING.md`. ## Model Used - Initial implementation: Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code. - Review fixes & CI verification: Antigravity with 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 --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Paperclip <noreply@paperclip.ing>
165 lines
13 KiB
TypeScript
165 lines
13 KiB
TypeScript
import {describe,expect,it} from "vitest";
|
|
import {resolveRunnerEnvironmentForRun,resolveWarmRunnerIdleTimeoutMsForRun,runnerLifecycleDefaultNeedsLeaseProbe} from "./runner-environment-lifecycle.js";
|
|
|
|
it.each([undefined,"codex","acpx","opencode"])("defaults plugin Runner execution to warm without provider gates: %s",provider=>{
|
|
const environment={driver:"plugin" as const,config:{pluginKey:"fixture",driverKey:"tasks",driverConfig:{}}};
|
|
expect(resolveRunnerEnvironmentForRun(environment,"paperclip_runner",{provider,idleTimeoutMs:1234},undefined,"selected-account:generation")).toMatchObject({config:{runnerLifecycleMode:"warm",runnerIdleTimeoutMs:1234}});
|
|
expect(environment.config).not.toHaveProperty("runnerLifecycleMode");
|
|
});
|
|
it("keeps plugin-owned credentials per-turn without changing admitted recovery",()=>{
|
|
const environment={driver:"plugin" as const,config:{pluginKey:"fixture",driverKey:"tasks",driverConfig:{},runnerLifecycleMode:"warm"}};
|
|
expect(resolveRunnerEnvironmentForRun(environment,"paperclip_runner",{lifecycleMode:"warm"})).toMatchObject({config:{runnerLifecycleMode:"per_turn"}});
|
|
expect(resolveRunnerEnvironmentForRun(environment,"paperclip_runner",{},"warm")).toMatchObject({config:{runnerLifecycleMode:"warm"}});
|
|
});
|
|
it("preserves explicit per-turn settings and the admitted recovery policy",()=>{
|
|
const environment={driver:"plugin" as const,config:{pluginKey:"fixture",driverKey:"tasks",driverConfig:{}}};
|
|
expect(resolveRunnerEnvironmentForRun(environment,"paperclip_runner",{lifecycleMode:"per_turn"},undefined,"account:generation")).toMatchObject({config:{runnerLifecycleMode:"per_turn"}});
|
|
expect(resolveRunnerEnvironmentForRun(environment,"paperclip_runner",{},"per_turn")).toMatchObject({config:{runnerLifecycleMode:"per_turn"}});
|
|
expect(resolveRunnerEnvironmentForRun({...environment,config:{...environment.config,runnerLifecycleMode:"per_turn"}},"paperclip_runner",{lifecycleMode:"warm"},undefined,"account:generation")).toMatchObject({config:{runnerLifecycleMode:"per_turn"}});
|
|
expect(resolveRunnerEnvironmentForRun(environment,"claude_local",{})).toBe(environment);
|
|
});
|
|
it("forwards the run's warm idle window for a warm sandbox-provider run only",()=>{
|
|
const sandbox={driver:"sandbox" as const,config:{provider:"daytona",reuseLease:true}};
|
|
// Agent-level warm with an inherited environment lifecycle: the provider must see the agent's window.
|
|
expect(resolveWarmRunnerIdleTimeoutMsForRun(sandbox,"paperclip_runner",{lifecycleMode:"warm",idleTimeoutMs:900_000})).toBe(900_000);
|
|
// The environment's own window wins over the agent's.
|
|
expect(resolveWarmRunnerIdleTimeoutMsForRun({...sandbox,config:{...sandbox.config,runnerLifecycleMode:"warm",runnerIdleTimeoutMs:600_000}},"paperclip_runner",{idleTimeoutMs:900_000})).toBe(600_000);
|
|
expect(resolveWarmRunnerIdleTimeoutMsForRun(sandbox,"paperclip_runner",{},"warm")).toBe(300_000);
|
|
expect(resolveWarmRunnerIdleTimeoutMsForRun(sandbox,"paperclip_runner",{lifecycleMode:"per_turn",idleTimeoutMs:900_000})).toBeUndefined();
|
|
expect(resolveWarmRunnerIdleTimeoutMsForRun({...sandbox,config:{...sandbox.config,runnerLifecycleMode:"per_turn"}},"paperclip_runner",{lifecycleMode:"warm"})).toBeUndefined();
|
|
expect(resolveWarmRunnerIdleTimeoutMsForRun(sandbox,"claude_local",{lifecycleMode:"warm"})).toBeUndefined();
|
|
expect(resolveWarmRunnerIdleTimeoutMsForRun({driver:"plugin" as const,config:{}},"paperclip_runner",{lifecycleMode:"warm"})).toBeUndefined();
|
|
});
|
|
|
|
describe("remote-sandbox warm default", () => {
|
|
const inheriting = { driver: "sandbox" as const, config: { provider: "daytona", reuseLease: false } };
|
|
const supported = { reusableLeaseSupported: true };
|
|
const opencode = { provider: "opencode", model: "openai/gpt-5" };
|
|
const claude = { provider: "acpx", acpxAgent: "claude", model: "claude-sonnet-4-6" };
|
|
|
|
it.each([
|
|
["Codex", { provider: "codex" }, true],
|
|
// Rule 3: an omitted provider resolves to Codex, as the runtime resolves it.
|
|
["an omitted provider (Codex)", {}, true],
|
|
["OpenCode", opencode, true],
|
|
["ACPX Claude", claude, true],
|
|
["an unmeasured ACPX harness", { provider: "acpx", acpxAgent: "grok", model: "grok-4" }, false],
|
|
["a config the runtime refuses", { provider: "opencode" }, false],
|
|
] as const)("%s on a provider with reusable leases: warm=%s", (_name, adapterConfig, warm) => {
|
|
const resolved = resolveRunnerEnvironmentForRun(inheriting, "paperclip_runner", adapterConfig, undefined, undefined, supported);
|
|
expect(resolved.config.reuseLease).toBe(warm);
|
|
expect(resolveWarmRunnerIdleTimeoutMsForRun(inheriting, "paperclip_runner", adapterConfig, undefined, supported))
|
|
.toBe(warm ? 300_000 : undefined);
|
|
expect(runnerLifecycleDefaultNeedsLeaseProbe(inheriting, "paperclip_runner", adapterConfig)).toBe(warm);
|
|
// The shared environment itself is never rewritten.
|
|
expect(inheriting.config.reuseLease).toBe(false);
|
|
});
|
|
|
|
// Rule 1: a provider without reusable leases (E2B, Modal, fake) keeps master's per-turn behavior.
|
|
it.each([{ provider: "codex" }, {}, claude])("keeps %j per-turn on a provider without reusable leases", (adapterConfig) => {
|
|
for (const context of [{}, { reusableLeaseSupported: false }]) {
|
|
expect(resolveRunnerEnvironmentForRun(inheriting, "paperclip_runner", adapterConfig, undefined, undefined, context)).toBe(inheriting);
|
|
expect(resolveWarmRunnerIdleTimeoutMsForRun(inheriting, "paperclip_runner", adapterConfig, undefined, context)).toBeUndefined();
|
|
}
|
|
});
|
|
|
|
// Rule 2: explicit configuration wins and needs no probe.
|
|
it("honors explicit lifecycles and the configured idle window", () => {
|
|
const pinned = { driver: "sandbox" as const, config: { provider: "daytona", runnerLifecycleMode: "per_turn" } };
|
|
expect(resolveRunnerEnvironmentForRun(pinned, "paperclip_runner", { provider: "codex" }, undefined, undefined, supported)).toBe(pinned);
|
|
expect(runnerLifecycleDefaultNeedsLeaseProbe(pinned, "paperclip_runner", { provider: "codex" })).toBe(false);
|
|
expect(resolveRunnerEnvironmentForRun(inheriting, "paperclip_runner", { provider: "codex", lifecycleMode: "per_turn" }, undefined, undefined, supported)).toBe(inheriting);
|
|
expect(runnerLifecycleDefaultNeedsLeaseProbe(inheriting, "paperclip_runner", { lifecycleMode: "per_turn" })).toBe(false);
|
|
expect(resolveRunnerEnvironmentForRun(inheriting, "paperclip_runner", { provider: "codex" }, "per_turn", undefined, supported)).toBe(inheriting);
|
|
expect(runnerLifecycleDefaultNeedsLeaseProbe(inheriting, "paperclip_runner", {}, "per_turn")).toBe(false);
|
|
expect(resolveWarmRunnerIdleTimeoutMsForRun(inheriting, "paperclip_runner", { idleTimeoutMs: 900_000 }, undefined, supported)).toBe(900_000);
|
|
expect(resolveWarmRunnerIdleTimeoutMsForRun({ ...inheriting, config: { ...inheriting.config, runnerIdleTimeoutMs: 600_000 } },
|
|
"paperclip_runner", { idleTimeoutMs: 900_000 }, undefined, supported)).toBe(600_000);
|
|
});
|
|
|
|
// Rule 2: a managed AI account without a warm session gets no default; managed Codex supports one.
|
|
it("defaults managed AI runs only when the harness supports a managed warm session", () => {
|
|
expect(resolveRunnerEnvironmentForRun(inheriting, "paperclip_runner", claude, undefined, "account:generation", supported)).toBe(inheriting);
|
|
expect(runnerLifecycleDefaultNeedsLeaseProbe(inheriting, "paperclip_runner", claude, undefined, "account:generation")).toBe(false);
|
|
expect(resolveWarmRunnerIdleTimeoutMsForRun(inheriting, "paperclip_runner", claude, undefined,
|
|
{ ...supported, managedAiCredentialIdentity: "account:generation" })).toBeUndefined();
|
|
expect(resolveRunnerEnvironmentForRun(inheriting, "paperclip_runner", {}, undefined, "account:generation", supported).config.reuseLease).toBe(true);
|
|
});
|
|
|
|
it("never applies to plugin tasks or other adapters", () => {
|
|
expect(runnerLifecycleDefaultNeedsLeaseProbe({ driver: "plugin", config: {} }, "paperclip_runner", {})).toBe(false);
|
|
expect(runnerLifecycleDefaultNeedsLeaseProbe(inheriting, "codex_local", {})).toBe(false);
|
|
expect(resolveRunnerEnvironmentForRun(inheriting, "codex_local", {}, undefined, undefined, supported)).toBe(inheriting);
|
|
});
|
|
});
|
|
|
|
describe("per-turn-only harnesses on a warm environment", () => {
|
|
const antigravity = { provider: "acpx", acpxAgent: "antigravity", model: "gemini-3.8-flash-high" };
|
|
const dot = { provider: "openai_dot", dotBindingId: "00000000-0000-4000-8000-000000000001", allowUnmeteredProvider: true };
|
|
const grokBot = { provider: "grok_bot", externalBindingId: "00000000-0000-4000-8000-000000000002", allowUnmeteredProvider: true };
|
|
const muse = { provider: "muse", museBindingId: "00000000-0000-4000-8000-000000000003", allowUnmeteredProvider: true };
|
|
const cursorCloud = { provider: "cursor_cloud", model: "claude-4.5-sonnet", repoUrl: "https://github.com/paperclipai/paperclip" };
|
|
const pluginWarm = { driver: "plugin" as const, config: { pluginKey: "fixture", driverKey: "tasks", driverConfig: {}, runnerLifecycleMode: "warm" } };
|
|
const sandboxWarm = { driver: "sandbox" as const, config: { provider: "daytona", runnerLifecycleMode: "warm" } };
|
|
const sandboxWarmReusable = { driver: "sandbox" as const, config: { provider: "daytona", runnerLifecycleMode: "warm", reuseLease: true } };
|
|
|
|
const perTurnHarnesses = [
|
|
["Google Antigravity", antigravity],
|
|
["Google Antigravity with the agent set to warm", { ...antigravity, lifecycleMode: "warm" }],
|
|
["Dot", dot],
|
|
["Grok Bot", grokBot],
|
|
["Muse", muse],
|
|
["Cursor Cloud", cursorCloud],
|
|
// Even if profile validation refuses the config (for example missing binding or lifecycleMode: "warm"),
|
|
// the environment view still keeps it per-turn rather than falling through to warm.
|
|
["refused Dot config", { provider: "openai_dot", lifecycleMode: "warm" }],
|
|
["refused Grok Bot config", { provider: "grok_bot", lifecycleMode: "warm" }],
|
|
["refused Muse config", { provider: "muse", lifecycleMode: "warm" }],
|
|
["refused Cursor Cloud config", { provider: "cursor_cloud", lifecycleMode: "warm" }],
|
|
] as const;
|
|
|
|
it.each(perTurnHarnesses)(
|
|
"%s keeps a per-turn plugin task", (_name, adapterConfig) => {
|
|
expect(resolveRunnerEnvironmentForRun(pluginWarm, "paperclip_runner", adapterConfig, undefined, "account:generation"))
|
|
.toMatchObject({ config: { runnerLifecycleMode: "per_turn" } });
|
|
expect(resolveRunnerEnvironmentForRun({ ...pluginWarm, config: { ...pluginWarm.config, runnerLifecycleMode: undefined } },
|
|
"paperclip_runner", adapterConfig, undefined, "account:generation")).toMatchObject({ config: { runnerLifecycleMode: "per_turn" } });
|
|
expect(pluginWarm.config.runnerLifecycleMode).toBe("warm");
|
|
});
|
|
|
|
it.each(perTurnHarnesses)(
|
|
"%s keeps an ephemeral sandbox lease even when the environment sets reuseLease: true", (_name, adapterConfig) => {
|
|
const resolved = resolveRunnerEnvironmentForRun(sandboxWarm, "paperclip_runner", adapterConfig, undefined, "account:generation", { reusableLeaseSupported: true });
|
|
expect(resolved).toBe(sandboxWarm);
|
|
expect(resolved.config).not.toHaveProperty("reuseLease");
|
|
|
|
const resolvedReusable = resolveRunnerEnvironmentForRun(sandboxWarmReusable, "paperclip_runner", adapterConfig, undefined, "account:generation", { reusableLeaseSupported: true });
|
|
expect(resolvedReusable.config.reuseLease).toBe(false);
|
|
// The shared environment itself is never rewritten.
|
|
expect(sandboxWarmReusable.config.reuseLease).toBe(true);
|
|
|
|
expect(resolveWarmRunnerIdleTimeoutMsForRun(sandboxWarmReusable, "paperclip_runner", { ...adapterConfig, lifecycleMode: "warm" })).toBeUndefined();
|
|
expect(runnerLifecycleDefaultNeedsLeaseProbe({ driver: "sandbox", config: { provider: "daytona" } }, "paperclip_runner", adapterConfig)).toBe(false);
|
|
});
|
|
|
|
it.each(perTurnHarnesses)(
|
|
"%s overrides a persisted warm admission to per-turn on plugin and sandbox environments", (_name, adapterConfig) => {
|
|
expect(resolveRunnerEnvironmentForRun(pluginWarm, "paperclip_runner", adapterConfig, "warm", "account:generation"))
|
|
.toMatchObject({ config: { runnerLifecycleMode: "per_turn" } });
|
|
expect(resolveRunnerEnvironmentForRun(sandboxWarmReusable, "paperclip_runner", adapterConfig, "warm", "account:generation", { reusableLeaseSupported: true }).config.reuseLease)
|
|
.toBe(false);
|
|
expect(resolveWarmRunnerIdleTimeoutMsForRun(sandboxWarmReusable, "paperclip_runner", adapterConfig, "warm"))
|
|
.toBeUndefined();
|
|
});
|
|
|
|
it("still lets other harnesses use the environment's warm setting and admitted warm recovery", () => {
|
|
expect(resolveRunnerEnvironmentForRun(pluginWarm, "paperclip_runner", { provider: "codex" }, undefined, "account:generation"))
|
|
.toMatchObject({ config: { runnerLifecycleMode: "warm" } });
|
|
expect(resolveRunnerEnvironmentForRun(pluginWarm, "paperclip_runner", { provider: "codex" }, "warm"))
|
|
.toMatchObject({ config: { runnerLifecycleMode: "warm" } });
|
|
expect(resolveRunnerEnvironmentForRun(sandboxWarm, "paperclip_runner", { provider: "codex" }).config).toMatchObject({ reuseLease: true });
|
|
expect(resolveRunnerEnvironmentForRun(sandboxWarmReusable, "paperclip_runner", { provider: "codex" }, "warm").config).toMatchObject({ reuseLease: true });
|
|
});
|
|
});
|
|
|