Files
PaperClipAI/server
DottaandClaude Opus 5.5 7eaf38130b fix(tasks): keep a due automatic retry working while it is dispatched (#22306)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - When a run fails for a reason that Paperclip retries by itself,
Paperclip saves a new run in the `scheduled_retry` state. The task shows
"retry scheduled" and does not show a Retry button.
> - When the retry time comes, the run stays `scheduled_retry` until the
dispatcher promotes it to `queued`. This takes a few seconds.
> - In that gap, the task view does not see a future retry time and does
not see a queued run. So it falls through to "failed, Retry available".
> - In a restart test wave, two tasks showed a Retry banner for about 4
seconds this way. Both then continued without a click. A person can
click Retry in that window and start a second, competing retry.
> - This pull request treats a due automatic retry the same way as a due
native resume: the task shows "working" while the dispatcher promotes
it, for the same 2 minute grace.
> - The benefit is that an automatic retry never shows a Retry button. A
retry that never starts still shows one Retry after the grace.

## Linked Issues or Issue Description

**What happened?**
After an automatic retry became due, the task showed "failed" with a
Retry button for one poll (about 4 seconds). Then the retry started by
itself. Two tasks in a 197-task restart test wave showed this. One retry
came from an environment provider timeout
(`environment_provider_unavailable`). The other came from a
`native_environment_blocker` retry.

**Expected behavior**
A task whose automatic retry is due and not yet dispatched shows that
Paperclip is working. It does not offer Retry.

**Steps to reproduce**
1. Make a run fail with a cause that Paperclip retries automatically
(for example a transient failure).
2. Watch the task while the retry time passes.
3. Before the dispatcher promotes the retry run to `queued`, the task
interruption shows `state: "failed"` and `canRetry: true`.

**Paperclip version or commit**
`master` at 1c67687998.

## What Changed

- `server/src/services/task-interruption-presentation.ts`: a
`scheduled_retry` run whose retry time has passed shows `working` (no
Retry) for `NATIVE_RESUME_DISPATCH_GRACE_MS` (2 minutes), the same rule
that a due native resume already uses. After the grace, a retry that
never started still falls through to one Retry.
- `server/src/services/task-interruption-presentation.test.ts`: adds a
regression test for a just-due `transient_failure` and
`native_environment_blocker` retry (0 s to 119 s overdue). One existing
assertion now uses a retry that is 10 minutes overdue, so it still
proves that a stuck retry offers Retry.

## Verification

- Red: with the old source, the 2 new tests fail (`state: "failed"`,
`canRetry: true`).
- Green: `cd server && npx vitest run
src/services/task-interruption-presentation.test.ts` passes (75 tests).
- `pnpm verify` for the affected tests (result in the PR comments below
if it changes).
- Evidence from the wave: for task t118 the samples show
`retry_scheduled` from 06:27:40 to 06:28:03, then `failed`/`canRetry:
true` at 06:28:07 while the retry run was still `scheduled_retry`, then
`working` at 06:28:11 when it was `queued`. Task t181 shows the same
sequence at 06:45:22.

## Risks

- Low risk. This changes only presentation. It does not change dispatch
or retry state.
- A retry that is due but cannot start now shows "working" for up to 2
minutes before Retry appears. This is the same grace that a native
resume already has.

## Model Used

- Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, via Claude Code with
tool use (shell, file edit). Extended reasoning on.

## 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: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-19 02:43:48 -06:00
..