FN-5872: clear active-session registry on PR cleanup

Ensure PR-mode merge cleanup removes stale active-session registry state before deleting worktrees.

- unregister the task worktree from the active-session registry during merged-task artifact cleanup
- export the active-session registry from the engine entrypoint for lifecycle cleanup usage
- add CLI and engine regression coverage for registry cleanup and missing-entry best-effort behavior
- add a patch changeset for the published CLI package

Files changed:
 .changeset/fn-5872-registry-cleanup.md             |  5 ++++
 .../src/commands/__tests__/task-lifecycle.test.ts  | 29 +++++++++++++++++++++-
 packages/cli/src/commands/task-lifecycle.ts        |  8 +++++-
 .../pr-mode-worktree-invariants.test.ts            | 11 +++++---
 packages/engine/src/index.ts                       |  1 +
 5 files changed, 49 insertions(+), 5 deletions(-)

Fusion-Task-Id: FN-5872

Fusion-Task-Lineage: d4db24a3-7ae0-4d07-b029-7f30b2f65d2e
This commit is contained in:
gsxdsm
2026-06-02 07:46:38 -07:00
parent 336010007c
commit 7d20a997b9
5 changed files with 49 additions and 5 deletions

View File

@@ -283,10 +283,15 @@ describe("FN-5420 reliability interactions: PR mode worktree invariants", () =>
expect(releaseSpy).toHaveBeenCalledWith(path, "FN-5455-THROW");
});
it.skip("FN-5456 follow-up required: cleanup should clear active-session registry entry", async () => {
const path = "/tmp/fn-5456-session";
activeSessionRegistry.registerPath(path, { taskId: "FN-5456", kind: "executor", ownerKey: "FN-5456" });
it("FN-5872: cleanup clears active-session registry entry", async () => {
const path = "/tmp/fn-5872-session";
activeSessionRegistry.registerPath(path, { taskId: "FN-5872", kind: "executor", ownerKey: "FN-5872" });
expect(activeSessionRegistry.lookupByPath(path)).not.toBeNull();
const { cleanupMergedTaskArtifacts } = await loadPrLifecycleModule();
await cleanupMergedTaskArtifacts("/tmp", { id: "FN-5872", worktree: path } as any);
expect(activeSessionRegistry.lookupByPath(path)).toBeNull();
});
it("FN-5420/FN-5279: mergeIntegrationWorktree setting does not gate PR-mode processing", async () => {

View File

@@ -172,6 +172,7 @@ export {
type MockScript,
type MockScriptContext,
} from "./providers/index.js";
export { activeSessionRegistry } from "./active-session-registry.js";
export { WorktreePool, scanIdleWorktrees, cleanupOrphanedWorktrees, reapOrphanWorktrees } from "./worktree-pool.js";
export {
pruneWorktreeAdminEntries,