From 11d5b06864bdb731be5a6baf06a5f0ee24c64973 Mon Sep 17 00:00:00 2001 From: Devin Foley Date: Tue, 1 Dec 2026 11:26:21 -0800 Subject: [PATCH] fix(runner): give a plugin task prepare 60 s without a startup context (#23396) ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - An environment plugin can run an agent's Runner on remote compute, such as a remote computer > - Before the Runner starts, Core asks the plugin to prepare the task: its workspace, its home, and the agent's instructions and skills > - A warm start gets the startup context's deadline for this step. A cold start has no startup context, so prepare gets the 15 s default for every plugin task call > - On a remote computer, a cold prepare often takes 11-16 s. When several runs start at once, most of them time out > - The timeout does not stop the work. The plugin finishes it, the run fails, and its retry repeats the same prepare, which adds load > - This pull request gives a prepare without a startup context 60 s, the cold admission budget the Runner gives a Claude session > - The benefit is that a slow cold start starts late instead of failing and starting again ## Linked Issues or Issue Description No public issue exists. **What happened?** Agent runs on a plugin-provided remote computer failed at startup with "Plugin-provided Runner execution operation unavailable; reconcile the same task before retrying". The plugin's prepare call ran for about 15 s, then Core stopped waiting. The plugin's later host calls for that task got "Missing or unknown invocation scope". On one agent, about half of all cold starts failed this way while it worked through a backlog. Successful cold starts on the same computer took 17 s at the median for the full Runner startup, so prepare had little margin. **Expected behavior** A cold prepare that takes 20 s finishes, and the run starts 20 s later. **Steps to reproduce** 1. Use an environment plugin that runs Runner tasks on remote compute, with a cold prepare that takes more than 15 s. 2. Start a run for an agent with no warm task on that computer. 3. See the run fail at startup with the error above, and a new run start the same prepare again. **Paperclip version or commit** `master` at 51541be36fe. **Deployment mode** Authenticated deployment with an environment plugin that runs Runner tasks on remote compute. ## What Changed - `executeEnvironmentTask` gives a `prepare` operation without a startup context a 60 s timeout. Before, it got the 15 s default. - A `prepare` with a startup context keeps the context's deadline. Ownership and `describe` calls with session handoff keep 90 s. `copilot_metadata` keeps its probe-bound limit. All other task operations keep 15 s. - The prepare tests in `environment-task-runtime.test.ts` expect 60 s. ## Verification - `pnpm --filter @paperclipai/server typecheck` passes. - `npx vitest run src/__tests__/environment-task-runtime.test.ts src/__tests__/plugin-runner-task.integration.test.ts src/services/heartbeat/run-completion.test.ts` (in `server/`): 3 files, 253 tests pass. - Without the code change, 5 prepare tests in `environment-task-runtime.test.ts` fail on the timeout argument. The submit, stop, status, complete and resume tests still expect 15 s and pass. - I checked what a longer prepare affects downstream: - The run's execution lease is renewed from the moment the run is claimed, so a long prepare does not lose it. - The Runner starts its cold admission deadline after prepare returns, so prepare does not use that budget. ## Risks - Low risk. A prepare that truly hangs now takes 60 s to fail instead of 15 s. Its run stays in startup for that time. - No change for local adapters or sandboxes that do not use plugin Runner tasks, and no change for other task operations. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`) in Claude Code, with tool use (shell, file edits, and read-only database and log queries on a hosted instance for the diagnosis). ## 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 (no documentation describes this timeout) - [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: Paperclip --- server/src/__tests__/environment-task-runtime.test.ts | 4 ++-- server/src/services/environment-task-runtime.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/server/src/__tests__/environment-task-runtime.test.ts b/server/src/__tests__/environment-task-runtime.test.ts index 7a2bc80550c..c7f6f2be838 100644 --- a/server/src/__tests__/environment-task-runtime.test.ts +++ b/server/src/__tests__/environment-task-runtime.test.ts @@ -431,7 +431,7 @@ describe("plugin-provided Runner execution", () => { await expect(executeEnvironmentTask(database().db, accepted as never, { companyId: "company", leaseId, operation: { ...operation, preparationDigest, runDigest } })).resolves.toEqual(result); expect(accepted.call).toHaveBeenCalledWith("original", "environmentTask", expect.objectContaining({ - operation: expect.objectContaining({ preparationDigest, runDigest }) }), 15_000); + operation: expect.objectContaining({ preparationDigest, runDigest }) }), 60_000); const forged = `sha256:${"b".repeat(64)}`; for (const digests of [{ preparationDigest: forged, runDigest }, { preparationDigest, runDigest: forged }, { preparationDigest }, { runDigest }]) { @@ -458,7 +458,7 @@ describe("plugin-provided Runner execution", () => { .resolves.toEqual(result); expect(workers.call).toHaveBeenCalledWith("original", "environmentTask", expect.objectContaining({ companyId: "company", runId: "run", agentId: "agent", projectIds: [projectId], operation, - }), 15_000); + }), 60_000); expect(store.sets).toHaveLength(atSubmit || checked ? 2 : 1); if (atSubmit || checked) expect(new PgDialect().sqlToQuery(store.sets[1].metadata as never).params).toContain(JSON.stringify({ runnerTaskProjectAuthValidation: { configurationId: "configuration-1", provider: "openai", projectIds: [projectId], diff --git a/server/src/services/environment-task-runtime.ts b/server/src/services/environment-task-runtime.ts index 825adbc1fba..ded4de1a616 100644 --- a/server/src/services/environment-task-runtime.ts +++ b/server/src/services/environment-task-runtime.ts @@ -620,7 +620,8 @@ export async function executeEnvironmentTask(db: Db, workers: Pick { // The plugin may have applied the saved claim before its reply was lost. // Keep the same operation ID; the RPC response below still needs validation.