Skip to content

fix(ids): include content blocks in content hash #466

Closed

Description

@Sinity

Problem

message_content_hash() and conversation_content_hash() in pipeline/ids.py:157-227 only hash id, role, text, and timestamp. Content blocks — tool_use, tool_result, thinking blocks with their types, tool names, tool inputs — are completely excluded.

Two conversations whose messages have identical text but different tool calls or tool inputs produce the same content hash. During re-import, the UPSERT at ingest_batch.py:175 checks WHERE content_hash != excluded.content_hash — if the hash matches, all message/attachment/block writes are skipped.

Impact: Structural changes in content blocks are silently lost during re-parsing and re-ingestion. This is a data-loss bug for any archive containing tool-use conversations (Claude Code, ChatGPT with tools).

Affected code

  • pipeline/ids.py:157-175 — message_content_hash() builds 4-field payload
  • pipeline/ids.py:178-227 — conversation_content_hash() same 4-field per message
  • pipeline/services/ingest_batch.py:433 — _check_content_unchanged() gates on hash match
  • pipeline/prepare_enrichment.py:33 — existing.content_hash != content_hash comparison

Fix direction

Include content block data in the hash: for each block, hash at minimum type, tool_name (for tool_use), tool_id (for tool_result), and text. The _normalize_for_hash() helper should handle blocks the same way it handles message fields.

Discovered during adversarial audit 2026-04-26.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:pipelinearea:storagetype:fix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions