mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-17 13:01:05 +01:00
## Thinking Path
> - Paperclip is the open source app people use to manage AI agents for
work
> - A task shows a Retry banner when its latest run failed and nothing
else continues the task
> - The banner reads "the latest run" by creation time only
> - The queue cancels a queued system continuation before it starts when
the task no longer needs it. That run is newer than the run that is
really working
> - So a task showed "failed" with Retry for about 79 seconds while its
run was working
> - The stranded-work sweep also queued one of those extra
continuations, because it did not see a native status wake that was
still waiting for dispatch
> - This pull request ignores never-started, superseded continuations in
the banner, and makes the sweep see a pending native status wake
> - The benefit is no false Retry offer while an agent works, and no
duplicate continuation after a slow finalization
## Linked Issues or Issue Description
**What happened?**
In a restart-chaos wave (6 rolling deploys, 207 tasks), one task showed
state `failed` with Retry for 75–79 seconds while its run was running.
Two queued system continuations for that task were cancelled before they
started with `recovery_no_longer_needed`. That cancel is correct. But
the newest cancelled run became the "latest run" in the interruption
projection. The projection then fell through to `{ state: "failed",
canRetry: true }`.
The first of the two extra continuations came from a double queue. The
finishing run asked for its own continuation through a native status
wake (`agent_tool_call_loop`). Its finalization did not apply at once
("native result persisted but finalization did not apply; the
reconciliation loop will retry"), so the dispatch of that wake waited
about 17 seconds. In that window, the stranded-work sweep saw an
`in_progress` task with a succeeded run and no live path, and queued its
own continuation (`issue.productive_terminal_continuation_recovery`).
The sweep's live-path check counted only runs and
`deferred_issue_execution` wakes. It did not count a native status wake
that was still `queued` or `claimed` without a run. When the native
status wake was dispatched later, the queue correctly dropped it. The
dropped wake also carried the better instruction (the tool-loop
guidance).
**Expected behavior**
A task with a running run shows "working" with no Retry. One finished
run produces one continuation.
**Steps to reproduce**
1. Give a task a running run R1.
2. Add a newer run R2 for the task with status `cancelled`, no
`startedAt`, and error code `recovery_no_longer_needed`.
3. Read the task interruption. Before this change: `failed`, `canRetry:
true`, observed run R2.
For the sweep: give an `in_progress` task a succeeded native run and a
`native-status-committer` wake in `queued` or `claimed` with no run. Run
`reconcileStrandedAssignedIssues`. Before this change it queues a second
continuation.
**Paperclip version or commit**
master `c5218f5ec4` (wave), reproduced on `b4fa1c7fb1`.
## What Changed
- `task-interruption-presentation.ts`: the latest-run candidates skip a
run that is `cancelled`, never started (`startedAt` is null), and has
error code `recovery_no_longer_needed` or `issue_closed_before_start`.
The filter is in each per-arm `limit 1` index scan, so the query shape
and cost stay the same.
- `recovery/service.ts`: `hasActiveExecutionPath` also counts a
`native-status-committer` wake in `queued` or `claimed` with no run for
the issue. The native status wake dispatcher owns that wake, so the
sweep does not queue a second continuation and does not escalate the
task while it waits.
- Tests (red on master, green here):
- `task-interruption-query.test.ts`: a running R1 plus a newer
never-started R2 cancelled with each code shows `working`, `canRetry:
false`, observed R1. Negatives keep their behavior: a cancelled run that
had started, and a run a person cancelled, still show `failed` with
Retry.
- `heartbeat-process-recovery.test.ts`: a succeeded native run with its
own status wake still `queued` or `claimed` gets no second continuation
and no escalation.
## Verification
- `pnpm verify` exited 2 (opaque setup dependency), so I ran focused
suites:
- `server/src/__tests__/task-interruption-query.test.ts`,
`task-interruption-automatic-path.test.ts`,
`issue-confirm-run-stopped-routes.test.ts`: 83/83 pass. This includes
the query-plan test that bounds `heartbeat_runs` rows read.
- `server/src/__tests__/heartbeat-process-recovery.test.ts`,
`server/src/services/recovery/*.test.ts`, the interruption suites and
`task-interruption-presentation.test.ts` together: 18 files, 871/871
pass.
- Red/green: the new interruption tests fail on master with `state:
"failed", canRetry: true` and the dropped run as observed run. The new
sweep tests fail on master with `continuationRequeued: 1`.
- `tsc --noEmit` for `server` passes.
## Risks
- Low. The banner change only hides runs that never started and were
dropped as superseded. Person-cancelled runs, started runs, and other
cancel codes behave as before.
- The live-path change makes the sweep wait while a native status wake
is pending. The dispatcher always settles such a wake: it dispatches it,
or marks it skipped. A throttled wake stays queued only until its
throttle time, so the sweep waits at most that long.
## Model Used
- Anthropic Claude Opus 5.5 (`claude-opus-5-5`), agentic coding with
tool use (shell, file edits, test runs).
## 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>