#14486·paperclip

Terminal-workspace reaper never reclaims a cancelled issue's workspace

Author: christiananagnostouCreated Sep 28, 2026Updated Sep 28, 2026

Summary

sweepTerminalWorkspaces archives a terminal issue's execution workspace only when the workspace is clean and its work is merged (merged_via_pr or merged_by_ancestry). A cancelled issue's work never merges, so its git worktree is never reclaimed. On an instance where many issues end as cancelled (benchmark clones, abandoned tickets), the volume fills and git worktree add starts to fail.

Evidence (one instance, 7 days)

  • terminal issue workspace reaper skipped all candidates: 979 log lines, 0 archived.
  • A sample sweep: checked: 50, skippedUndelivered: 35, skippedNonTerminalTree: 15, eligible: 0. The cursor rotates correctly (keyset over a frozen boundary), so this is not a scan problem: every terminal candidate fails the delivery rule.
  • 58 of 82 active git_worktree workspaces were terminal, idle ≥ 24 h and clean; the oldest was idle 1,916 h (80 days). Most were cancelled. Reclaiming 20 of them by PATCH /execution-workspaces/{id} {"status":"archived"} freed about 83 MB each, and the volume went from 92 % to 79 %.
  • skippedUndelivered also counts a failed git inspection and a dirty tree, so an operator cannot tell "unmerged" from "dirty" from "inspection failed".

Minimal repro

  1. Create an issue; let an agent run create a git_worktree execution workspace and commit one change; push the branch; open a PR.
  2. Close the PR without merging; set the issue to cancelled.
  3. Leave the workspace clean. Wait past PAPERCLIP_WORKSPACE_REAPER_COOLDOWN_DAYS (or set it to 0).
  4. The reaper sweep logs the workspace under skippedUndelivered on every rotation. The worktree stays on disk.

Proposal

  1. An opt-in rule (for example PAPERCLIP_WORKSPACE_REAPER_REAP_CANCELLED=true): reap a cancelled terminal issue's clean workspace after the cooldown when its commits are reachable from a remote ref (the branch, or the PR head ref such as refs/pull/N/head), so no unpushed work is lost.
  2. Separate counters for the three causes now inside skippedUndelivered: skippedUnmerged, skippedDirty, skippedInspectionFailed.

Pin: 65ec059bd (server/src/services/execution-workspaces.ts, sweepTerminalWorkspaces).

Related: #13874 (local_fs workspaces whose cwd is not a git repo), #7790 (execution workspaces never auto-close). This issue is the git_worktree + cancelled-issue case.