mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-20 18:26:40 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Each task shows an interruption banner. The banner offers Retry when an attempt failed and nothing will move the task forward > - The banner reads the task's newest run. A continuation that the system cancels before it starts can be the newest run, while a different run owns the task and does the work > - In a restart-chaos wave, the banner offered Retry for about 140 seconds while the owning run worked. The task then finished with no click > - A Retry that the user does not need breaks the rule that the needed-Retry rate is 0% > - This pull request makes the banner and the Retry endpoint read the same observed run. That run is the live run that owns the task, or else the newest real attempt > - The benefit is that Retry shows only when nothing will advance the task, and a shown Retry is accepted ## Linked Issues or Issue Description **What happened?** A restart-chaos wave (three release swaps) showed a Retry banner on one task for 141 to 144 seconds. The reason code was `issue_execution_lock_changed`. Nobody clicked Retry, and the task completed. Timeline (UTC): - 14:32:09. Run A starts. - 14:51:12. A user follow-up wakes run B. Run B is queued behind run A. - 14:52:46. Run A succeeds. The system schedules continuation run C (`retryOfRunId` = A, reason `native_agent_blocker_continuation`). Run B starts and takes the task execution lock. - 14:53:16. The dispatch gate cancels C before it starts with `issue_execution_lock_changed`, because run B owns the lock. This is correct de-duplication. - 14:53:17. The banner shows `failed` with Retry. Run C was created after run B, so C is the newest run. The projection reads only the newest run and ignores that run B is running and owns the lock. - 14:55:41. Run B succeeds and the task is done. The banner goes away. Retry was never needed. Run B owned the task for the full banner window. **Expected behavior** The banner does not offer Retry while a run owns the task and is queued or running. A run that the system cancelled before it started because another run took the lock is not a failed attempt. When Retry is shown, pressing it is accepted for the run that the banner shows. **Steps to reproduce** 1. Create a task. Run A succeeds and leaves the task in progress. 2. Queue run B for the same task (for example, a user comment). Create continuation run C after run B. 3. Start run B and set it as the task execution lock owner. 4. Cancel run C before it starts with error code `issue_execution_lock_changed`. 5. Read the task interruption. Before this change: `state: failed`, `canRetry: true`, observed run C. After this change: `state: working`, `canRetry: false`, observed run B. **Paperclip version or commit** `fe0c4aa95d` (master at the time of the wave). ## What Changed - `server/src/services/task-retry-eligibility.ts`: add two shared conditions. - `taskAttemptCondition()`: a run cancelled before it started with `recovery_no_longer_needed`, `issue_closed_before_start` or `issue_execution_lock_changed` is not an attempt. The first two codes were already excluded inline in the projection. `issue_execution_lock_changed` is new. - `liveExecutionOwnerCondition()`: the run is the task's execution lock owner and it is queued or running. - `server/src/services/task-interruption-presentation.ts`: the observed run is the live execution owner when there is one. Otherwise it is the newest attempt, with the same native, first-class and legacy precedence as before. The owner lookup is a primary-key read, so the per-task run scan does not grow. - `server/src/services/task-retry.ts`: Retry admission, the refused chat Retry continuation and the superseded-Retry check use the same attempt filter. Admission also accepts the live execution owner when the request names it. The newest attempt stays acceptable, so the automatic Retry hooks (restart, provider limit, budget resume) keep their behavior. - `heldTaskRetryRefusals` uses the same attempt filter. - New test `server/src/__tests__/task-retry-banner-execution-owner.test.ts`: one state table. Each row asserts the list and detail projection, and when Retry is shown, presses it through `requestTaskRetry`. ### State table (tested as one table) | Row | Runs and lock | Banner | Observed run | Retry press | | --- | --- | --- | --- | --- | | 1 | Continuation scheduled; follow-up running and owns the lock | working, no Retry | follow-up | n/a | | 2 | Continuation cancelled unstarted (`issue_execution_lock_changed`); follow-up running and owns the lock (t032) | working, no Retry | follow-up | n/a | | 3 | Same as row 2, lock pointer cleared mid-transfer | working, no Retry | follow-up | n/a | | 4 | Scheduled continuation overdue past the 2-minute dispatch grace; follow-up running and owns the lock | working, no Retry | follow-up | n/a | | 5 | Newer attempt failed; older queued run owns the lock | working, no Retry | queued owner | automatic Retry of the failed run is still accepted | | 6 | Continuation superseded; follow-up then succeeded | resolved, no Retry | follow-up | n/a | | 7 | Continuation superseded; follow-up then failed | failed, Retry | follow-up | accepted | | 8 | Continuation superseded; predecessor failed; nothing else runs | failed, Retry | predecessor | accepted | | 9 | Continuation started, then lost the lock | failed, Retry | continuation | accepted | | 10 | Lock pointer left on a finished failed run | failed, Retry | that run | accepted | | 11 | Row 2 with native runs (`nativeIssueId`) | working, no Retry | native follow-up | Retry naming the owner is accepted | | 12 | Queued owner past its 15-minute move-forward wait; newer failed attempt | working, Retry (`move_forward`) | queued owner | accepted | Invariants that the table checks: - Retry is never shown while something will advance the task (rows 1 to 6, 11). Row 12 offers only `move_forward` on the owner. - A Retry press that names the live owner is accepted (rows 1, 2, 3, 5, 11, 12). - Retry is always shown when nothing will advance the task (rows 7 to 10). - The shared attempt filter is tested in `heldTaskRetryRefusals`, `retireSupersededTaskRetry` and the refused chat Retry continuation (`person_with_superseded_continuation` in `chat-channels.integration.test.ts`). - When Retry is shown, pressing it is accepted for the observed run (rows 7 to 10). ## Verification - Red: with the service changes removed, rows 1 to 8 fail (8 of 10). Rows 9 and 10 pass on both sides. - Green: `cd server && npx vitest run src/__tests__/task-retry-banner-execution-owner.test.ts` passes 14 of 14. - Related suites pass: `task-interruption-query.test.ts` (includes the query-plan bound test), `task-interruption-automatic-path.test.ts`, `legacy-continuation-authority.test.ts`, `native-closed-session-retry.integration.test.ts`, `interrupted-preparation-restore-retry.test.ts`, and the other server tests that call `taskInterruptionPresentation`, `requestTaskRetry` or `heldTaskRetryRefusals`. - `npx tsc --noEmit -p server/tsconfig.json` passes. ## Risks - Low risk. The change is read-side only. It does not change scheduling, dispatch, the lock, or the run-dispatch gate. - A run cancelled before start with `issue_execution_lock_changed` no longer shows as a failed attempt. If the lock was released and nothing else ran, the banner shows the previous attempt. A failed previous attempt still offers Retry (row 8). - The projection query has one more union branch. It is a primary-key lookup through `issues.execution_run_id`. The existing query-plan bound test passes. - No runner, migration or API contract change. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, used through Claude Code with tool use (shell, file edit, 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 - [ ] I will address all Greptile and reviewer comments before requesting merge Refs #22306 (the earlier fix for a due scheduled retry shown as failed). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>