mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-25 16:14:26 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - A blocked task waits on other tasks. When all its blockers are done, Paperclip wakes the assignee. A periodic backstop does this when the normal event is missed. > - The backstop deduplicates wakes with a key that includes the blocked cycle (`blockedTransitionAt`). > - A woken run that fails can leave the task blocked again. That starts a new cycle, so the next sweep sees a new key and wakes the task again. > - When the failure is deterministic, this never stops. One hosted task ran more than 11,000 failed runs in five days, about one every 20 seconds. > - This pull request adds a circuit breaker to the backstop: after each failed attempt, the next dependency wake waits longer (1m, 5m, 25m, ... up to 24h). > - The benefit is that a setup failure can no longer become thousands of automatic runs. ## Linked Issues or Issue Description **What happened?** A blocked task had all blockers done. The issue graph liveness backstop woke its agent with `issue_blockers_resolved`. Each run failed in setup (`durable_prp_canonical_json_too_large`). The task returned to `blocked` with a new `blockedTransitionAt`. The backstop then emitted another wake with a new idempotency key. The activity log of the task had 11,215 `issue.blockers_resolved_wake_emitted` rows, each with a different key, and 11,621 failed runs. **Expected behavior** A wake that did not help is not repeated without limit. Paperclip waits longer after each failure, and then probes again. A newer blocker result, an edit of the blocker set, or a run that does not fail starts a fresh attempt. **Steps to reproduce** 1. Create a blocked task with one done blocker and an agent assignee. 2. Record three `issue_blockers_resolved` wakes for the task, each with a failed run and a different blocked-cycle key. 3. Run `reconcileResolvedDependencyWakes()`. 4. Before this change, the backstop emits a fourth wake. Refs #22705, #22707 (the underlying setup size failure and its retry classification). Those changes stop scheduled retries for that one error. The backstop loop is a separate path and accepts any failure class, so it needs its own breaker. ## What Changed - New `server/src/services/recovery/dependency-wake-circuit-breaker.ts`. It reads this agent's terminal runs on the task (any wake reason), newest first. It reads runs through `heartbeat_runs.issue_id` (indexed). It counts consecutive `failed` or `timed_out` runs that finished after the latest blocker change: blocker completion, succeeded workspace finalize, an added blocker relation, or an `issue.blockers_updated` edit. Each run counts once. A run that did not fail ends the streak. `interrupted` runs (restart, deploy) are neutral. - The wait before the next dependency wake is 1 minute after one failure, then multiplied by 5 per failure, capped at 24 hours. After the wait, one wake probes again, so a fix that ships later is picked up. - `reconcileResolvedDependencyWakeBackstop` calls the breaker before it enqueues a wake. A skipped wake reports its retry time through `onDeferredDeadline`. New counter: `failedWakeBackoffSkipped`. When a task has three or more consecutive failures, the sweep logs one warning with the task ids. - Tests: backstop regressions (production shape, backoff elapsed, reset by a later successful run, reset by a newer blocker result, reset by a blocker-set edit) and unit tests for the policy (duplicate receipts, interrupted runs, capped probe). ## Verification - `cd server && npx vitest run src/__tests__/heartbeat-issue-liveness-escalation.test.ts src/services/recovery/dependency-wake-circuit-breaker.test.ts src/services/workspace-recovery-dependency-finalize.test.ts src/__tests__/issue-blocker-stall-wakeups.test.ts`: all pass. - Red/green: with the backstop hook reverted, the production-shape test fails (`expected 1 to be 0`: the backstop wakes the task again). With the hook, it passes. - Existing backstop tests (self-blocked, same-cycle dedup, blocker completion) still pass. ## Risks - A task whose dependency runs keep failing is woken less often, at most once a day after about six failures. The failed run still shows its own error and action. Before this change the same task ran without limit. - The breaker adds one run read per candidate that passes all earlier checks (four small aggregate reads more only when a recent run failed). It does not run for tasks that are not ready or already have a wake. - No schema change. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, used through Claude Code with tool use (shell, browser, file edits). ## 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: Paperclip <noreply@paperclip.ing> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>