Files
PaperClipAI/server
DottaandPaperclip f5457565de fix(heartbeat): retry setup on retryable remote_incomplete workspace failures (#23764)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work
> - Before a run starts its provider, Paperclip prepares the task
workspace through a workspace provider plugin using a deterministic
`operationId`
> - A workspace provider can fail preparation with the closed retryable
reason `remote_incomplete` when a remote storage or runtime request does
not finish
> - Setup recorded `remote_incomplete` as a generic `setup_failed` with
no bounded retry, and release recovery immediately marked the task
`blocked` without retrying the same workspace or showing the workspace
failure reason in the escalation notice body
> - This pull request gives a fresh pre-dispatch `remote_incomplete`
answer its own transient setup code, `workspace_storage_incomplete`,
routes it through the bounded bootstrap retry budget (deferring Sentry
reporting until the retry decision), and forwards saved
`workspaceProviderFailure` details into immediate execution-path
escalation notices
> - The benefit is that a task retries the same workspace automatically
across transient remote storage/runtime failures instead of immediately
blocking for a person

## Linked Issues or Issue Description

Refs #23362, #19249

**What happened?**

When a workspace provider returned the closed retryable reason
`remote_incomplete` (`"Workspace storage operation is incomplete; retry
the same workspace"`) during workspace bootstrap (`executionRecovery: {
kind: "bootstrap", providerWorkStarted: false }`), `failRunSetup`
recorded `errorCode: "setup_failed"` and scheduled no retry. Immediately
after, `releaseIssueExecution` treated `setup_failed` as non-retryable
continuation failure and marked the task `blocked` with a generic notice
that omitted the workspace failure reason.

**Expected behavior**

When a legacy run fails before provider dispatch with a retryable
`remote_incomplete` workspace provider answer, setup must classify it as
`workspace_storage_incomplete` and schedule a bounded bootstrap retry of
the same workspace (matching `workspace_storage_pending` and
`plugin_worker_unavailable`). Sentry must report only when no retry is
scheduled or retries are exhausted, and immediate execution-path
escalation notices must include the bounded `workspaceProviderFailure`
message when present.

**Steps to reproduce**

1. Start a legacy run whose workspace preparation calls a workspace
provider plugin.
2. Have the provider reject preparation with
`PluginWorkspaceOperationError("remote_incomplete")`.
3. Before this fix, `failRunSetup` writes `errorCode: "setup_failed"`,
schedules no bounded retry, and `releaseIssueExecution` immediately
blocks the task.

**Paperclip version or commit**

Reproduced on `master` (`01ecbadbf1`).

**Deployment mode**

Self-hosted server and managed plugin workspace environments
(`authenticated` and `local_trusted`).

## What Changed

- `server/src/services/workspace-provider-failure.ts`: add
`WORKSPACE_STORAGE_INCOMPLETE_CODE` (`workspace_storage_incomplete`) and
`findWorkspaceStorageIncompleteFailure` matching `kind === "provider" &&
reason === "remote_incomplete"`.
- `server/src/services/heartbeat/run-completion.ts`: map a fresh
pre-dispatch legacy `remote_incomplete` failure (with no native session
or runner instance) to `workspace_storage_incomplete`, route it through
`scheduleBoundedRetryForRun` (keeping accepted interaction retries owned
by the interaction lane), and defer Sentry reporting via
`workspaceStorageIncompleteRetry`.
- `server/src/services/failed-preparation-retry.ts`,
`server/src/services/heartbeat/retries.ts`,
`server/src/services/legacy-execution-recovery.ts`,
`server/src/services/recovery/service.ts`,
`server/src/services/agent-task-run-telemetry.ts`: handle
`workspace_storage_incomplete` alongside `workspace_storage_pending`.
- `server/src/services/recovery/stranded-notice.ts` &
`server/src/services/heartbeat.ts`: add a stranded escalation notice for
`workspace_storage_incomplete` and pass `workspaceProviderFailure:
readWorkspaceProviderFailure(input.runRow.resultJson)` into
`buildImmediateExecutionPathRecoveryNoticeSeed`.
- `server/src/services/run-failure-diagnostics.ts` &
`server/src/services/run-failure-report.ts`: add
`workspaceStorageIncompleteRetry` deferred Sentry reporting handshake.
- Add red-then-green regression tests in `run-completion.test.ts`,
`workspace-provider-failure.test.ts`,
`run-failure-report-sandbox-resume.test.ts`, and
`heartbeat-retry-scheduling.test.ts`.

## Verification

- Red before the fix:
- `pnpm --dir server exec vitest run
src/services/heartbeat/run-completion.test.ts -t "incomplete workspace
storage"` failed on the `fresh` scenario with `errorCode:
"setup_failed"` instead of `"workspace_storage_incomplete"`.
- Green after the fix:
- Focused `run-completion.test.ts`,
`run-failure-report-sandbox-resume.test.ts`,
`workspace-provider-failure.test.ts`,
`agent-task-run-telemetry.test.ts`, `heartbeat-retry-scheduling.test.ts`
(`bootstrap retries across restart`), and `pnpm --dir server typecheck`
all pass.

## Risks

- Low risk. No database schema, API route, or plugin wire protocol
changes.
- Retry applies only before provider dispatch on a legacy run with no
native session or runner instance, bounded by the existing bootstrap
retry budget (2 retries). Started and native runs keep `setup_failed`
with no automatic retry.
- Every workspace preparation call carries a deterministic `operationId`
derived from workspace ID, generation, and operation payload, and
`remote_incomplete` is explicitly marked `retryable: true` for the same
workspace.

## Model Used

- Google DeepMind Gemini 4 Neon (Medium reasoning budget), via
Antigravity with tool use (code search, file edits, local test
execution, and 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
- [x] All Paperclip CI gates are green
- [x] 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 <noreply@paperclip.ing>
2026-12-04 14:08:47 -06:00
..