Skip to content

tasks: clean up finished tasks without discarding unmerged work (#160) - #162

Merged
Lexus2016 merged 3 commits into
mainfrom
feat/task-purge-review
Nov 27, 2026
Merged

Lexus2016 merged 3 commits into
mainfrom
feat/task-purge-review

Conversation

@Lexus2016

Copy link
Copy Markdown
Owner

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:

  • Merge — the change is wanted; merged into the project's default branch and then the
    card is removed through the ordinary delete (nothing left to lose).
  • Delete without merging — the change is not wanted; the same force delete the single
    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 are done/cancelled
    only; 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 — one taskHasUnmergedWork() gate and one deleteTaskRow() teardown shared by
    the existing DELETE /api/tasks/:id and the new purge (the two doors used to carry two
    copies of the same logic). New POST /api/tasks/purge, GET /api/tasks/:id/git-status and
    POST /api/tasks/:id/git-merge. The merge commits uncommitted edits first, only while the
    tree 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 bulk
    step 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 with
failSafe: true, so item 4 of #160 needs no override — the unattended path already keeps
what 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 only
    commits on the task's branch), and the real _purgeAct in a vm: Cancel destroys nothing,
    a confirmed delete is the only request carrying ?force=1, a merge is followed by the
    ordinary delete, and a refused merge removes nothing.
  • test/task-purge-e2e.test.js — 23 checks against a real server and a real git repo: the
    bulk 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.
  • Existing suites re-run green here: task-delete-unmerged 13, worktree-manager 121,
    worktree-safety 10, kanban-run-badges 40, kanban-group-button 6, sidebar-ux 8,
    session-expiry 18, i18n-completeness 139.

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.

Lexus2016 and others added 2 commits November 27, 2026 18:06
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.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-27T18:46:30.667617Z c9451f4 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread server.js
Comment on lines +7837 to +7839
if (runningTaskAborts.has(task.id) || task.status === 'in_progress') {
return res.status(409).json({ error: 'task is still running', code: 'TASK_RUNNING' });
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment thread server.js
Comment on lines +7846 to +7847
if (task.workdir) {
const wtStatus = WM.getStatus({ worktreeDir: task.workdir, defaultBranch });

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@Lexus2016
Lexus2016 merged commit 4862657 into main Nov 27, 2026
3 checks passed
@Lexus2016
Lexus2016 deleted the feat/task-purge-review branch November 27, 2026 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant