mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-05 06:03:51 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Before a run starts its agent, Paperclip prepares the task workspace through a workspace provider plugin > - A hosted agent computer can apply an update. While it updates, it finishes its running tasks and refuses new workspaces > - The provider can only report this refusal as a generic `remote_incomplete` failure. Setup retries that failure two times in about 90 seconds (#23764), but an update can wait for running tasks for an hour > - So each new task on that computer fails setup, reports an error, and stops, although it only had to wait > - This pull request adds the closed provider reason `runtime_updating` and a separate wait lane for it. Setup holds the run and retries the same workspace every 2 minutes for up to 1 hour. The wait does not use the failure retry budget, and Paperclip does not report the run as a failure while the wait continues > - The benefit is that new tasks wait for an updating agent computer and then start, instead of failing ## Linked Issues or Issue Description Refs #23764, #23362 **What happened?** A hosted agent computer refused every new workspace preparation while it applied an update and finished its long running tasks. The provider reported each refusal as `remote_incomplete`. Setup failed each new run. Every retry of the same workspace failed the same way, and each failure was reported to error tracking. On one staging stack this happened 34 times in two hours, for two agents. **Expected behavior** A provider can say that the selected runtime is updating. Setup then holds the run and retries the same workspace after the update. The retry does not spend the failure budget. Paperclip reports the failure only if the wait ends without success. **Steps to reproduce** 1. Start a legacy run whose workspace preparation calls a workspace provider plugin. 2. Have the provider reject preparation because its runtime is updating. Before this change, the only fitting reason is `remote_incomplete`. 3. Setup records `workspace_storage_incomplete` and retries two times (30 s and 60 s). Then the task stops and the failure is reported, while the runtime is still updating. **Paperclip version or commit** `master` at `30334c1f03`. **Deployment mode** Hosted (Paperclip Cloud agent computers). A self-hosted workspace provider can use the same reason. ## What Changed - `packages/plugins/sdk/src/workspace-operation-error.ts`: add the closed reason `runtime_updating` ("the selected runtime is applying an update and refuses new workspaces until it finishes"). - `server/src/services/workspace-provider-failure.ts`: give `runtime_updating` a fixed, retryable message. Map it to the new setup code `workspace_runtime_updating`. Add `WORKSPACE_RUNTIME_UPDATING_RETRY` (reason `runtime_update_wait`, 30 attempts, 2 minutes apart). Add the code to `WORKSPACE_STORAGE_RETRY_CODES`, so the existing deferred error report also covers it. - `server/src/services/heartbeat/run-completion.ts` and `heartbeat/retries.ts`: schedule a failed pre-dispatch `workspace_runtime_updating` run with the wait lane, and use the lane's budget in `failedRunRetryBudgetSpent`. This is the same pattern as `runner_revision_mismatch`. - `server/src/services/execution-recovery-attempt.ts`, `modules/run-dispatch/domain/wake-context.ts`, `task-interruption-presentation.ts`: `runtime_update_wait` is an uncharged preparation wait. An answered interaction keeps its continuation through the wait, and the task shows a wait, not a failure. - `failed-preparation-retry.ts`, `legacy-execution-recovery.ts`, `recovery/service.ts`, `agent-task-run-telemetry.ts`: treat `workspace_runtime_updating` like the other transient workspace preparation codes. - `recovery/stranded-notice.ts`: add a notice for a wait that ended without success ("Agent computer was still updating"). ## Verification - Red before the change (test files only, source reverted): 9 new tests fail in `workspace-provider-failure.test.ts`, `execution-recovery-attempt.test.ts`, `heartbeat/retries.test.ts`, `heartbeat/run-completion.test.ts` and `run-failure-report-sandbox-resume.test.ts`. - `pnpm verify` did not run: its workspace link repair failed for `plugin-orchestration-smoke-example`, before test selection. The SDK change also affects many packages, so CI supplies the broad coverage. - Green after the change: the same 5 files pass (267 tests). Related files also pass: `task-interruption-automatic-path`, `task-interruption-query`, `wake-context`, `stranded-notice-remote-workspace-environment`, `task-interruption-presentation` (181 tests); `agent-task-run-telemetry`, `legacy-continuation-authority`, `heartbeat-retry-scheduling` (179 tests); plugin SDK `workspace-operation-error`, `workspace-provider` (20 tests). - `pnpm --dir server typecheck` and `pnpm --filter @paperclipai/plugin-sdk typecheck`: pass (server typecheck run with `PAPERCLIP_TYPECHECK_LOW_MEMORY=1` because of a local memory limit). - CI supplies the full suite. - Review follow-up (`cf73701742`, `d7540263bd`): update waits keep their count in `executionRetryAccounting` (`runtimeUpdateWaits`) across other retry lanes. An answered interaction whose update wait runs out is escalated like an exhausted storage wait. The pinned SDK input registry is refreshed. The two new tests failed before the fix and pass after it. `execution-recovery-attempt`, `heartbeat/retries`, `workspace-provider-failure` and `run-failure-report-sandbox-resume` pass (83 tests). `heartbeat/run-completion` and `modules/wake-queue` pass (577 tests). `tests/runner-e2e/source-sdk-public-inputs` passes (13 tests). `pnpm --dir server typecheck` passes. ## Risks - Low risk. No schema, migration, API route or wire protocol shape change. The reason set is closed and validated on both sides. An older Core that receives `runtime_updating` treats it as an unknown provider failure, as before. - A provider must not send `runtime_updating` before the new SDK is available to it. The SDK constructor rejects an unknown reason, so a provider update has to follow this change. - The wait is a bounded scheduled retry after a real refusal, not idle polling: at most 30 retries in one hour per waiting run. Each retry is one workspace preparation call. When the wait ends without success, the run is reported and the task shows a named notice with a Retry action. - Only legacy runs that fail before provider dispatch use the lane. Started and native runs keep `setup_failed`. ## Model Used - Anthropic Claude Opus 5.5 (`claude-opus-5-5`), via Claude Code with tool use (code search, file edits, shell, local test execution, GitHub CLI). ## 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 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: paperclipbugbot <356415228+paperclipbugbot@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
101 lines
3.3 KiB
TypeScript
101 lines
3.3 KiB
TypeScript
import type { Db } from "@paperclipai/db";
|
|
import { createPostgresRunDispatchAdapter } from "./adapters/postgres.js";
|
|
import {
|
|
createCancelStaleQueuedRun,
|
|
createDispatchResolvedInteractionIfCurrent,
|
|
createEvaluateScheduledRetryGate,
|
|
createPromoteDueScheduledRetries,
|
|
createPromoteScheduledRetry,
|
|
} from "./application/use-cases.js";
|
|
import type { RunDispatchWriter, ScheduledRetryReader } from "./application/ports.js";
|
|
|
|
export {
|
|
MAX_TURN_CONTINUATION_RETRY_REASON,
|
|
WORKSPACE_BUSY_RETRY_REASON,
|
|
AI_CONNECTION_BUSY_RETRY_REASON,
|
|
AI_CONNECTION_POOL_WAIT_RETRY_REASON,
|
|
RUNNER_REVISION_WAIT_RETRY_REASON,
|
|
STORAGE_UNAVAILABLE_WAIT_RETRY_REASON,
|
|
RUNTIME_UPDATE_WAIT_RETRY_REASON,
|
|
AGENT_DIRECTORY_BUSY_RETRY_REASON,
|
|
PREPARATION_WAIT_RETRY_REASONS,
|
|
isPreparationWaitRetryReason,
|
|
INTERACTION_CONTINUATION_INFRA_RETRY_REASON,
|
|
INTERACTION_CONTINUATION_INFRA_WAKE_REASON,
|
|
WAKE_COMMENT_IDS_KEY,
|
|
CHAT_CONVERSATION_ID_KEY,
|
|
readWakeChatConversationId,
|
|
wakeChatConversationsConflict,
|
|
RESOLVED_INTERACTION_CONTINUATION_STATUSES,
|
|
isNonAssigneeWorkspaceBusyRetry,
|
|
WORKSPACE_BUSY_HOLDER_STALE_AFTER_MS,
|
|
WORKSPACE_BUSY_WAIT_KEY,
|
|
readWorkspaceBusyWait,
|
|
workspaceBusyWaitKey,
|
|
extractWakeCommentIds,
|
|
deriveCommentId,
|
|
allowsIssueInteractionWake,
|
|
allowsDependencyBlockedWake,
|
|
isResolvedInteractionContinuationWakeContext,
|
|
} from "./domain/wake-context.js";
|
|
export type {
|
|
RetryReasonKind,
|
|
BudgetBlockFacts,
|
|
PauseHoldFacts,
|
|
DependencyBlockFacts,
|
|
DispositionRepairFacts,
|
|
ReviewParticipantFacts,
|
|
ScheduledRetryGateErrorCode,
|
|
GateDecision,
|
|
ScheduledRetryFacts,
|
|
QueuedRunStalenessErrorCode,
|
|
StalenessDecision,
|
|
QueuedRunFacts,
|
|
} from "./domain/policy.js";
|
|
export type {
|
|
PostCommitEffect,
|
|
PromoteScheduledRetryOutcome,
|
|
CancelStaleQueuedRunOutcome,
|
|
} from "./application/types.js";
|
|
export { RunDispatchApplicationError } from "./application/types.js";
|
|
|
|
export type { WorkspaceBusyWait } from "./domain/wake-context.js";
|
|
export { wakeWorkspaceBusyWaitersInTx } from "./adapters/workspace-busy-wait.js";
|
|
|
|
export type RunDispatchDeps = {
|
|
/** Overrides the Postgres adapter; a test builds its module against a fake instead. */
|
|
adapter?: ScheduledRetryReader & RunDispatchWriter;
|
|
};
|
|
|
|
/**
|
|
* Composes the run-dispatch module: the Postgres adapter and its semantic
|
|
* use cases. `heartbeat.ts` holds the only caller: it builds one
|
|
* instance per process and delegates the scheduled-retry promotion gate and
|
|
* the queued-run staleness gate to it.
|
|
*/
|
|
export function createRunDispatch(db: Db, deps: RunDispatchDeps = {}) {
|
|
const adapter = deps.adapter ?? createPostgresRunDispatchAdapter(db);
|
|
|
|
const promoteScheduledRetry = createPromoteScheduledRetry({
|
|
writer: adapter,
|
|
});
|
|
|
|
return {
|
|
nextScheduledRetryAt: (input: { cutoff: Date | null }) => adapter.nextScheduledRetryAt(input),
|
|
evaluateScheduledRetryGate: createEvaluateScheduledRetryGate({ reader: adapter }),
|
|
promoteScheduledRetry,
|
|
promoteDueScheduledRetries: createPromoteDueScheduledRetries({
|
|
reader: adapter,
|
|
promoteScheduledRetry,
|
|
}),
|
|
cancelStaleQueuedRun: createCancelStaleQueuedRun({
|
|
writer: adapter,
|
|
}),
|
|
dispatchResolvedInteractionIfCurrent: createDispatchResolvedInteractionIfCurrent({
|
|
writer: adapter,
|
|
}),
|
|
};
|
|
}
|
|
|
|
export type RunDispatch = ReturnType<typeof createRunDispatch>;
|