Skip to content

fix(importers): prevent colliding filenames from overwriting conversations - #2171

Open
aloneangel45 wants to merge 1 commit into
basicmachines-co:mainfrom
aloneangel45:fix/2140-chatgpt-importer-filename-collisions
Open

aloneangel45 wants to merge 1 commit into
basicmachines-co:mainfrom
aloneangel45:fix/2140-chatgpt-importer-filename-collisions

Conversation

@aloneangel45

Copy link
Copy Markdown

Summary

Prevents ChatGPTImporter and ClaudeConversationsImporter from silently overwriting distinct conversations when two entries resolve to the same normalized output filename within an import batch (for example an untitled conversation falling back to Untitled conversation <id> alongside an explicit title "Untitled conversation <id>", distinct punctuation collapsing under clean_filename, or case-only differences on case-insensitive filesystems).

Changes

  • src/basic_memory/importers/base.py:
    • Added Importer.resolve_unique_import_paths(path, seen_paths, disambiguator=None), tracking normalized (casefold()) target paths per import batch and appending a deterministic suffix (-<disambiguator>, falling back to -2, -3, ...) when a path collides with an earlier conversation, while keeping non-colliding filenames and re-import updates unchanged.
  • src/basic_memory/importers/chatgpt_importer.py:
    • Extracted _stable_id (shared between _resolve_title and import_data) and switched ChatGPTImporter.import_data to resolve_unique_import_paths with clean_filename(stable_id)[:32] as disambiguator.
  • src/basic_memory/importers/claude_conversations_importer.py:
    • Updated ClaudeConversationsImporter.import_data to use resolve_unique_import_paths with clean_filename(uuid)[:32] as disambiguator.
  • tests/importers/test_conversation_filename_collisions.py:
    • Added regression tests covering ChatGPT untitled-vs-titled fallback collisions (plus deterministic re-import), normalized/case-folded ChatGPT title collisions, and Claude conversation filename collisions.

Verification

  • Pre-fix pytest --noconftest tests/importers/test_conversation_filename_collisions.py -q: 3 failed (PRE_FIX_EXIT=1), confirming the second file overwrote the first.
  • Post-fix:
    • ruff check and ruff format --check on the 4 modified/new files: 0 issues
    • pytest --noconftest tests/importers/test_conversation_filename_collisions.py tests/importers/test_importer_base.py tests/importers/test_importer_utils.py tests/importers/test_import_directory_containment.py tests/importers/test_project_zip_import.py tests/importers/test_memory_json_records.py tests/importers/test_chatgpt_graphs.py -v: 34 passed, 1 skipped (Windows symlink test skipped)

Fixes #2140

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T16:51:27.516997Z 2c90e33 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2c90e330c0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/basic_memory/importers/base.py Outdated
Comment on lines +133 to +135
candidates = [path]
if disambiguator:
candidates.append(f"{path}-{disambiguator}")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep collision paths stable across input order

When a colliding pair is re-imported after the source list order changes, this gives the first item the bare path and only suffixes the later item; the previously suffixed item then moves to the bare path while its old suffixed file remains, leaving duplicate notes with changing permalinks. Preserve the same ID-to-path mapping across batches.

AGENTS.md reference: AGENTS.md:L159-L161

Useful? React with 👍 / 👎.

@aloneangel45

Copy link
Copy Markdown
Author

Updated in 704e2c4 to address the review feedback and DCO sign-off:

  • Added Importer.plan_unique_import_paths in src/basic_memory/importers/base.py and wired both ChatGPTImporter and ClaudeConversationsImporter through two-pass batch planning: unique base paths are reserved first, and colliding entries receive their stable ID disambiguator (-id) regardless of batch input order.
  • Added reversed-order regression assertions and unique-disambiguator collision coverage in ests/importers/test_conversation_filename_collisions.py.
  • Re-signed commit with Signed-off-by for DCO.

@aloneangel45
aloneangel45 force-pushed the fix/2140-chatgpt-importer-filename-collisions branch from 2c90e33 to 704e2c4 Compare November 29, 2026 17:11
…tions

Signed-off-by: aloneangel45 <aloneangel45@users.noreply.github.com>
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.

[BUG] ChatGPT import silently overwrites distinct conversations with colliding filenames

2 participants