Skip to content

fix(kanban): defer scratch workspace cleanup until linked children finish (#33774)#41352

Merged
teknium1 merged 2 commits into
mainfrom
hermes/hermes-c9e85db8
Jun 7, 2026
Merged

fix(kanban): defer scratch workspace cleanup until linked children finish (#33774)#41352
teknium1 merged 2 commits into
mainfrom
hermes/hermes-c9e85db8

Conversation

@teknium1

@teknium1 teknium1 commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Summary

A Kanban scratch parent now keeps its workspace until every linked child is terminal, so dependency-chain handoffs (parents=[A]) can actually read A's artifacts.

Previously complete_task_cleanup_workspace shutil.rmtree'd a scratch dir the instant the task completed, with no check for active children. A child created with parents=[A] started, found $HERMES_KANBAN_WORKSPACE already deleted, and either crashed with FileNotFoundError or silently re-derived A's output. (#33774)

Changes

  • hermes_cli/kanban_db.py:
    • _cleanup_workspace: defer the rmtree when task_links shows any child still in todo/ready/running. (@annguyenNous)
    • _try_cleanup_parent_workspaces: after a child completes, sweep any parent whose children are now all terminal. (@annguyenNous)
    • Follow-up fix: a non-scratch (dir/worktree) child returned early and never ran the parent sweep — leaking the scratch parent's deferred dir forever. Run the sweep before that early return.
  • tests/hermes_cli/test_kanban_db.py: +3 regression tests (deferred-while-child-active, swept-after-last-child, dir-child-unblocks-scratch-parent).

Validation

scenario before after
scratch parent completes, child still active parent dir deleted parent dir survives
last child completes (already gone) parent dir swept
dir child of scratch parent completes parent dir leaks forever parent dir swept

tests/hermes_cli/test_kanban_db.py cleanup/handoff subset: 9/9 pass. E2E verified end-to-end with real DB + file I/O in an isolated HERMES_HOME — A writes summary.txt/guide.md, completes; artifacts survive; B reads them; both scratch dirs reaped once terminal.

Salvages #33916 (@annguyenNous) onto current main with authorship preserved. Supersedes #38454 (different lifecycle approach — never-delete-on-complete). The decomposer's "everything forced to scratch" complaint in the issue comments is already addressed by #37172 / #37182 (children inherit the root workspace).

Closes #33774.

Infographic

deferred-scratch-cleanup

@github-actions

github-actions Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

🔎 Lint report: hermes/hermes-c9e85db8 vs origin/main

ruff

Total: 0 on HEAD, 0 on base (➖ 0)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 0 pre-existing issues carried over.

ty (type checker)

Total: 10011 on HEAD, 10007 on base (🆕 +4)

🆕 New issues: none

✅ Fixed issues: none

Unchanged: 5195 pre-existing issues carried over.

Diagnostics are surfaced as warnings — this check never fails the build.

@alt-glitch alt-glitch added type/bug Something isn't working P3 Low — cosmetic, nice to have comp/cli CLI entry point, hermes_cli/, setup wizard labels Jun 7, 2026
annguyenNous and others added 2 commits June 7, 2026 09:21
…33774)

When a Kanban task with workspace_kind=scratch completes, the
_cleanup_workspace() function immediately deletes the workspace
directory. If the task has children linked via task_links, those
children find the workspace deleted when they start.

This fix adds two checks:
1. Before deleting, check if any children are still active
   (todo/ready/running). If so, defer cleanup.
2. After a child completes, check if parent workspace can now
   be cleaned up (all children terminal).

Fixes #33774
…etion + tests

Follow-up on the deferred-cleanup salvage (#33774): _cleanup_workspace
returned early for a non-scratch ('dir'/'worktree') task and never ran the
parent sweep, so a scratch parent waiting on a 'dir' child would leak its
deferred workspace forever. Run the parent sweep before the early return.

Adds regression tests: deferred-while-child-active, swept-after-last-child,
and dir-child-unblocks-scratch-parent.
@teknium1 teknium1 force-pushed the hermes/hermes-c9e85db8 branch from 465a07f to 710d089 Compare June 7, 2026 16:21
@teknium1 teknium1 merged commit 76f0178 into main Jun 7, 2026
23 checks passed
@teknium1 teknium1 deleted the hermes/hermes-c9e85db8 branch June 7, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Kanban parent-child handoff: scratch workspace GC destroys artifacts before child can read them

3 participants