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
> - A run can fail setup with "The workspace still has an unfinished
writer or save operation." when the task's own remote workspace is still
held by an earlier writer run that never finished saving.
> - #22103 stopped the assigned-work sweep from looping a board
escalation behind such a hold. Staging still showed these failures in
pairs.
> - Each pair is one continuation (a sweep continuation, a delivered
fresh continuation, or a comment that reopened the task) whose run fails
on the hold, followed by an immediate bounded `transient_failure` retry
from the failure path, which fails the same way.
> - `scheduleBoundedRetryForRun` never reads the workspace hold before
it schedules that retry.
> - This pull request makes the retry scheduler, the assigned-work sweep
and stranded recovery agree: while the hold refuses a start, nobody
starts another run; the task goes to the board-owned stranded hold,
which the sweep (#22103) and the released-writer pass (#21221) continue
once the writer releases.
> - The benefit is one failed run per held workspace instead of repeated
pairs, and no task left in progress with nothing moving it.
## Linked Issues or Issue Description
Refs #22103
Refs #21221
Refs #21394
Refs #23051
**What happened?**
On staging, tasks whose workspace writer hold stayed refused produced
failed runs in pairs, seconds apart:
- A continuation run failed setup with the writer-pending message
(`setup_failed`, `executionRecovery: { kind: "bootstrap",
providerWorkStarted: false }`).
- The failure path then scheduled a bounded `transient_failure` retry of
that run (`scheduledRetryAttempt: 1`), which failed setup on the same
hold.
One pair started from a delivered fresh continuation (`source:
execution.reconciled`), another from an assigned-work sweep continuation
of a task a comment had reopened (`source:
issue.assigned_work_invariant`, `assignedWorkViolation: retry_offered`).
**Expected behavior**
While the task's workspace writer hold refuses a start, no retry or
continuation is started. The task is escalated once to the board-owned
stranded hold and continued once after the hold releases.
**Steps to reproduce**
1. Bind an in-progress task to an execution workspace whose remote
workspace writer is an ended run with dirty, unsaved state (the hold
refuses a start).
2. Fail the task's latest run with `setup_failed` and the writer-pending
message, before provider work, as an assigned-work continuation.
3. Call `scheduleBoundedRetryForRun` for that run: before this change it
schedules a retry.
4. Run the assigned-work check: before this change it continues the task
(`retry_offered`).
5. Run stranded recovery: before this change it skips the task because
the sweep owns the failed continuation, so with the sweep held back the
task would have no path.
**Paperclip version or commit**
`master` at ab2183aae.
**Deployment mode**
Hosted (cloud sandbox workspaces).
## What Changed
- `server/src/services/remote-workspace-writer-hold.ts`: add
`failedRunWorkspaceHoldRefusesStart(db, run)`: true when the run failed
setup with the writer-pending message and its task's workspace hold
still refuses a start (`remoteWorkspaceHoldRefusesStart`). Export
`REMOTE_WORKSPACE_WRITER_PENDING_CODE`, the code reservation already
uses.
- `server/src/services/heartbeat/retries.ts`:
`scheduleBoundedRetryForRun` returns `not_scheduled` with `errorCode:
remote_workspace_writer_pending` for such a run. Other runs do not read
the database for this check.
- `server/src/services/recovery/assigned-work-sweep.ts` (+
`assigned-work-invariant.ts` fact): the hold read from #22103 now also
covers a task whose latest run failed on the hold. For an open task with
a `retry_offered` or `no_pending_path` violation behind a refused hold,
the sweep reports `left_to_hold_owner` instead of continuing it,
including in the locked re-check.
- `server/src/services/recovery/service.ts`: stranded continuation
recovery does not count such a failed run as owned by the sweep, so it
escalates the task to the board hold instead of skipping it.
- Tests: `retries.test.ts` (refused hold: no retry and no successor;
released hold: retry scheduled) and `released-writer-escalation.test.ts`
(reopened task behind the refused hold: sweep leaves it, stranded
recovery escalates with no successor run, and the released-writer pass
continues it once after release).
## Verification
- `cd server && npx vitest run src/services/heartbeat/retries.test.ts
src/__tests__/released-writer-escalation.test.ts
src/__tests__/assigned-work-invariant.test.ts
src/services/heartbeat/recovery.test.ts`: 210/210 pass.
- The 19 other server test files that call
`reconcileStrandedAssignedIssues` pass on this head (18 files: 1,350
passed, 19 skipped; `workspace-recovery-admission.test.ts`: 149/149).
- Each part is needed. With the scheduler check removed, the retries
test schedules a retry (`scheduled`, expected `not_scheduled`). With the
stranded ownership change removed, the escalation test leaves the task
in progress (expected `blocked`). With the sweep change removed, the
sweep continues the task (expected `left_to_hold_owner`).
- I could not run the full server `tsc` locally (the sandbox's memory
limit stops it). CI must confirm typecheck, build and the full suite.
## Risks
- Low to medium. The new reads happen only for runs that failed setup
with the writer-pending message: one join from the task to its execution
workspace and one hold read.
- A task behind a long refused hold now waits on the board-owned
stranded hold instead of failing repeatedly. The sweep and the
released-writer pass already continue that hold when the writer
releases.
- If the hold is already free when these paths look, behavior is
unchanged: the retry is scheduled and the sweep continues the task.
## Model Used
- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, used through Claude
Code with tool use (shell, git, GitHub CLI) 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
- [ ] I have updated relevant documentation to reflect my changes (not
needed: no command or documented behavior 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>