Skip to content

fix(import): clean up local files and _subfiles dirs for remotely-deleted workflows - #89

Closed
jspaans91 wants to merge 1 commit into
ubie-oss:mainfrom
jspaans91:fix/cleanup-orphans-stale-files
Closed

jspaans91 wants to merge 1 commit into
ubie-oss:mainfrom
jspaans91:fix/cleanup-orphans-stale-files

Conversation

@jspaans91

@jspaans91 jspaans91 commented Sep 19, 2026 •

Copy link
Copy Markdown

Summary

  • --cleanup-orphans was documented as deleting "local files without matching remote workflow", but only ever handled files with no embedded workflow ID. A local file whose workflow had since been deleted in n8n (i.e. it has an ID, but that ID no longer exists remotely) was never touched. Now every remote workflow ID seen during the sync pass is tracked, and any local file whose embedded ID isn't in that set gets deleted (respecting --ids scoping, and leaving archived/tag-filtered-out workflows alone since they still exist remotely).
  • --cleanup-subfiles now independently removes any _subfiles/ directory whose encoded workflow ID has no matching local workflow file — whether that's because --cleanup-orphans just deleted it, or the file was already gone (manual deletion, or an older n8n-cli that didn't clean up after itself). This is gated purely on --cleanup-subfiles, not on --cleanup-orphans, matching how the flag is documented.
  • Dry-run mode reports both kinds of cleanup without touching disk.

Test plan

  • Added tests/importer/cleanup-orphans.test.ts covering: stale file deletion, keeping files that still exist remotely, keeping archived (not deleted) workflows, dry-run reporting only, --ids scoping, _subfiles directory cleanup (both tied to a just-deleted workflow and pre-existing orphaned directories with no local file at all), and that _subfiles cleanup requires --cleanup-subfiles independently of --cleanup-orphans.
  • bun test — full suite passes (1997 tests)
  • bunx tsc --noEmit — clean
  • bun run lint — clean on changed files

…ed workflows

--cleanup-orphans only ever handled files missing an embedded workflow ID; a
file whose workflow had since been deleted in n8n was never touched despite
the flag being documented as deleting "local files without matching remote
workflow." Track every remote workflow ID seen during the sync pass and
delete local files whose embedded ID isn't among them (respecting --ids
scoping and leaving archived/filtered-out workflows alone).

--cleanup-subfiles independently cleans up any _subfiles/ directory whose
workflow ID has no matching local file, whether that's because
--cleanup-orphans just removed it or the file was already gone (manual
deletion, or an older n8n-cli that didn't clean up after itself).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@jspaans91
jspaans91 marked this pull request as ready for review September 19, 2026 10:44
@jspaans91
jspaans91 marked this pull request as draft September 19, 2026 10:45
@jspaans91 jspaans91 closed this Sep 19, 2026
@jspaans91
jspaans91 deleted the fix/cleanup-orphans-stale-files branch September 19, 2026 10:46
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