Skip to content

fix(orchestrator): register cache cleanup on wizardAbort paths - #1072

Open
fristovic wants to merge 1 commit into
PostHog:mainfrom
fristovic:fix/orchestrator-cache-cleanup-on-abort
Open

fix(orchestrator): register cache cleanup on wizardAbort paths#1072
fristovic wants to merge 1 commit into
PostHog:mainfrom
fristovic:fix/orchestrator-cache-cleanup-on-abort

Conversation

@fristovic

Copy link
Copy Markdown

Problem

After an aborted orchestrator run (accidental Ctrl+C in the wrong terminal window, but I assume errors would produce this as well), the install dir was left with an untracked .posthog-wizard-cache/ (plus.DELETE-ME.md saying it should have been removed when the wizard finished - which initiated my research into this fix).

QueueStore creates that folder as soon as the orchestrator starts, but the wipe only lives in the finally after drainQueue. Abort goes through wizardAbort()process.exit() and never hits that path, and the cache dir was never registered with registerCleanup(). Ctrl+C / SIGTERM have the same gap (run-wizard already calls runCleanups() before exit).

Changes

Extract wipeOrchestratorCache and wire it with the same dual-path pattern as flushScanReport in the program runner:

  • registerCleanup(() => wipeOrchestratorCache(...)) right after new QueueStore(...) — covers abort / SIGINT
  • reuse the helper in the existing finally — covers normal completion

QueueStore stays free of abort/analytics wiring.

Test plan

  • Unit tests in cache-cleanup.test.ts: wipe removes a QueueStore-created cache dir; wipe via registerCleanup / runCleanups; no-op when already gone
  • pnpm exec vitest run src/lib/agent/runner/sequence/orchestrator/__tests__/ (63 tests passed, including the new ones)
  • pnpm build
  • Manual: start an orchestrator run, abort or Ctrl+C, confirm .posthog-wizard-cache/ is gone; successful run still leaves none behind

@fristovic
fristovic requested a review from a team as a code owner August 10, 2026 15:51

@gewenyu99 gewenyu99 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oh 🤦 how did I forget to do this. Good change. I'll test and take this forward!

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.

2 participants