Repository navigation
tasks: clean up finished tasks without discarding unmerged work (#160) - #162
Conversation
DELETE /api/tasks/:id already refuses with 409 UNMERGED_WORK unless forced, and the chat has asked again and resent with ?force=1 since #129. The Kanban card and the Schedule list did not: they surfaced the raw refusal in a toast and stopped, so a task whose worktree still held unmerged commits or uncommitted changes could not be deleted from either screen at all. Both now go through the same small request helper: the first refusal becomes the question, naming the branch and the worktree the delete would destroy; Cancel destroys nothing, a confirmed second attempt carries ?force=1, and a forced attempt that is still refused is reported instead of asking again in a loop. test/task-delete-unmerged.test.js runs the real helper from both pages in a vm, pins the wiring of both delete buttons, and checks the new string in all five languages. Local: the new suite 13/13, i18n-completeness 139/139, schedule-actions 15/15, kanban-schedule 42/42, kanban-run-badges 40/40, sidebar-ux 8/8, kanban-group-button 6/6 under Node 24.22.1.
The board could not clean up finished tasks whose worktree still held work: the API answered 409 and the only way out was manual git in the container. The bulk action now removes only cards with nothing to lose and returns the rest for review, where each one is merged (the change is wanted) or force-deleted after the same confirmation the single card delete asks. The bulk call never sends force; merge goes through the worktree manager with the worker's own commit rule.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c9451f4940
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (runningTaskAborts.has(task.id) || task.status === 'in_progress') { | ||
| return res.status(409).json({ error: 'task is still running', code: 'TASK_RUNNING' }); | ||
| } |
There was a problem hiding this comment.
Guard merges against other workers sharing the worktree
When a finished chain member appears in the cleanup review while a later member is running, this guard checks only the finished member's ID. Chain members share the worktree and branch through setupChainWorktree().applyTask(), so the subsequent commitAll() and merge publish the running sibling's unfinished edits into the project branch. Executing this handler with a finished member and a running sibling reproduced a successful merge containing those unfinished edits. Reject the merge while any worker sharing the worktree is active, or restrict chain merges to the existing chain-completion path.
Useful? React with 👍 / 👎.
| if (task.workdir) { | ||
| const wtStatus = WM.getStatus({ worktreeDir: task.workdir, defaultBranch }); |
There was a problem hiding this comment.
Allow merging a surviving branch when its worktree is gone
If a task's worktree directory has been removed but its branch retains unmerged commits, hasUnmergedWork() deliberately preserves the task and returns it for review. However, the stored workdir remains truthy, so this unconditional status lookup throws before mergeBranch() can merge the surviving branch. Reproducing this state returns HTTP 500 (spawnSync git ENOENT), leaving the review's Merge action unusable despite recoverable committed work. Skip the worktree commit step when the directory is absent while still merging the retained branch.
Useful? React with 👍 / 👎.
Implements the bulk half of #160 with the owner's rule: nothing is thrown away unseen.
A finished or cancelled card whose worktree still holds unmerged commits or uncommitted
files is not deleted by the bulk action. It comes back in the response with its branch
and path, and the next step is a decision about that one card:
card is removed through the ordinary delete (nothing left to lose).
card already asks, behind the same confirmation naming the branch and the worktree.
The bulk call itself never sends
force. Only cards with nothing to lose go in one pass.What changed
task-purge.js— the decision table, as a pure function: candidates aredone/cancelledonly; a running card, an unmerged tree, or an unreadable tree is returned for review, never
removed. An inspection that threw reads as "keep", not "delete".
server.js— onetaskHasUnmergedWork()gate and onedeleteTaskRow()teardown shared bythe existing
DELETE /api/tasks/:idand the new purge (the two doors used to carry twocopies of the same logic). New
POST /api/tasks/purge,GET /api/tasks/:id/git-statusandPOST /api/tasks/:id/git-merge. The merge commits uncommitted edits first, only while thetree is still on the task's own branch, then merges through the worktree manager — the same
rule the worker's auto-merge follows. A running card refuses to merge with
409 TASK_RUNNING.public/kanban.html— a Clean up action in the board header opens the review: the bulkstep reports how many cards went and lists every card that was kept, with Merge and Delete
without merging per row, in all five languages.
CLAUDE.md,package.json— the two new suites are in the chain and described.Expiry (
SESSION_TTL_DAYS) already skips sessions whose worktree holds work withfailSafe: true, so item 4 of #160 needs no override — the unattended path already keepswhat nobody was asked about.
Evidence
test/task-purge.test.js— 12 tests: the decision table (statuses, running, unmerged,unreadable, junk input), the source contract (the bulk call carries no
force; merge onlycommits on the task's branch), and the real
_purgeActin avm: Cancel destroys nothing,a confirmed delete is the only request carrying
?force=1, a merge is followed by theordinary delete, and a refused merge removes nothing.
test/task-purge-e2e.test.js— 23 checks against a real server and a real git repo: thebulk purge removes a clean card with its tree and branch, returns the card holding an
unmerged commit in
review(row, tree and branch intact), refuses to merge a running card,then merges the reviewed card (the commit lands on the default branch), and the ordinary
delete removes it. 23 passed, 0 failed.
task-delete-unmerged13,worktree-manager121,worktree-safety10,kanban-run-badges40,kanban-group-button6,sidebar-ux8,session-expiry18,i18n-completeness139.Closes the bulk item of #160. The per-card merge is new API surface; nothing in it is reachable
from a screen other than this review, so no existing flow changes shape.