Skip to content

fix(core): handle multimodal and null message fields in ChatGPT and Claude importers - #2231

Closed
GEM-ICE wants to merge 1 commit into
basicmachines-co:mainfrom
GEM-ICE:fix/2230-importer-multimodal-null-fields
Closed

GEM-ICE wants to merge 1 commit into
basicmachines-co:mainfrom
GEM-ICE:fix/2230-importer-multimodal-null-fields

Conversation

@GEM-ICE

@GEM-ICE GEM-ICE commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Fixes #2230

What Changed

ChatGPT Importer (src/basic_memory/importers/chatgpt_importer.py)

  • Extracted _is_hidden_message() to safely check metadata before reading is_visually_hidden_from_conversation, preventing AttributeError when "metadata": null in both message formatting and counting.
  • Updated _get_message_content() to:
    • Guard against content: null / non-dict content and parts: null / non-list parts.
    • Support both "text" and "multimodal_text" content types via _extract_part_text(), preserving string parts and structured parts with string "text" fields while skipping None and non-text asset/quote objects.
    • Coalesce None values for code language and text fields so "None" is not rendered into fenced blocks.

Claude Conversations Importer (src/basic_memory/importers/claude_conversations_importer.py)

  • Normalized msg.get("text") to "" when None or non-string so messages with text: null and empty/missing content do not raise TypeError on "\n".join(lines).
  • Preserved top-level msg["text"] when msg["content"] contains only non-text blocks (e.g., thinking, tool_use) or empty text blocks.
  • Guarded attachment iteration against attachments: null, non-dict entries, missing/null file_name, and extracted_content: null.

Tests

  • Added test_import_chatgpt_multimodal_and_null_fields and test_chatgpt_get_message_content_empty_message in tests/cli/test_import_chatgpt.py.
  • Added test_import_conversation_with_null_fields_and_non_text_blocks in tests/cli/test_import_claude_conversations.py.

Why

Real-world exports from GPT-4o (images/audio in multimodal_text, structured parts, explicit null metadata/content) and Claude (extended thinking/tool_use blocks, null text/attachments/extracted_content) either crashed the entire batch import or silently dropped message content.

How Tested

  • ruff check and ruff format --check on all modified files: passed.
  • ty check --python-platform linux on all modified files: passed (0 diagnostics).
  • pytest on new ChatGPT CLI/unit regression tests, all Claude conversation import CLI tests (tests/cli/test_import_claude_conversations.py), and tests/importers/: 53 passed, 1 skipped.

…laude importers

Signed-off-by: ICE0803 <2325043156@qq.com>
@CLAassistant

CLAassistant commented Dec 5, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Dec 5, 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-12-05T08:17:40.869209Z f543e8d 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.

@phernandez

Copy link
Copy Markdown
Member

Thanks @GEM-ICE. CI does not run on fork PRs here, so I moved your commit to #2234 with authorship kept, plus a small cleanup and a changelog entry.

@phernandez

Copy link
Copy Markdown
Member

Merged as #2234 with your commit and authorship kept. Thanks!

@phernandez phernandez closed this Dec 6, 2026
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 and Claude conversation importers crash or silently drop message content on multimodal, thinking, and null fields

3 participants