fix(core): reap worktrees for terminated sessions#1532
Conversation
Use a single expression for cleanedTerminatedWorkspace in cleanup() so eslint no-useless-assignment passes while preserving dry-run and kill-path behavior. Made-with: Cursor
Greptile SummaryThis PR fixes a resource-leak bug where managed worktrees could be left on disk after a session's lifecycle was already marked
Confidence Score: 5/5Safe to merge; changes are narrowly scoped to workspace-only cleanup for already-terminated sessions, with no new side effects on live sessions. The fix correctly adds requireExisting: true to the terminated fast-path to avoid spurious destroy calls, invalidates the cache only when a workspace was actually reaped, and keeps runtime/agent teardown skipped for already-terminated sessions. Three targeted regression tests cover the new paths including idempotency on double-cleanup. No files require special attention.
|
| Filename | Overview |
|---|---|
| packages/core/src/session-manager.ts | Core fix: adds destroyManagedWorkspace/hasReapableManagedWorkspace helpers and updates kill() terminated fast-path and cleanup() second loop to reap orphaned worktrees; logic is correct and idempotent. |
| packages/core/src/tests/session-manager/lifecycle.test.ts | Adds three regression tests covering direct kill, cleanup reap, and idempotent double-cleanup for already-terminated sessions; mock isolation is correct via beforeEach/afterEach. |
| packages/core/src/types.ts | Updates KillResult JSDoc to accurately reflect that cleaned and alreadyTerminated can both be true simultaneously. |
| .changeset/reap-terminated-session-worktrees.md | Adds a patch-level changeset entry for @aoagents/ao-core describing the fix. |
Reviews (2): Last reviewed commit: "Merge remote-tracking branch 'upstream/m..." | Re-trigger Greptile
|
Rechecked this after the earlier lint failure: the current PR checks are green, including Lint. I also rebuilt locally before running tests so stale dist output does not affect validation. |
…-1532 # Conflicts: # packages/core/src/session-manager.ts
Problem
ao session cleanupcould report already-terminated sessions as handled while leaving their managed worktrees on disk. This happens when lifecycle metadata reachesterminatedthrough paths such asruntime_lostor a previous interrupted kill before workspace cleanup ran.Closes #1524.
What changed
kill()to safely retry workspace-only cleanup for sessions whose lifecycle is already terminal.cleanup()report already-terminated sessions as cleaned only when it actually reaps a remaining managed worktree or OpenCode mapping.Validation
pnpm --filter @aoagents/ao-core test -- src/__tests__/session-manager/lifecycle.test.tspnpm --filter @aoagents/ao-core typecheckpnpm --filter @aoagents/ao-core build && pnpm --filter @aoagents/ao-plugin-tracker-github build && pnpm --filter @aoagents/ao-plugin-scm-github buildpnpm --filter @aoagents/ao-core testChecklist