Skip to content

fix(import): preserve attachment content when fixture embedding fails #1697

Description

@seonghobae

Finding

CodeRabbit review of #1696 exposed a pre-existing data-integrity defect in backend/import_fixtures.py that is outside the retained exception-redaction scope.

Inside the attachment loop, generate_fixture_embedding(...) is called before Attachment(...) is appended to email_obj.attachments. If embedding generation raises, the current except path logs the failure and continues. The enclosing email object is then committed, so the failed attachment is silently omitted even though its parsed filename/content/MIME data was already available.

This is not caused by #1696. #1696 is being narrowed back to the public tool error-response boundary so this independent aggregate mutation is not hidden inside a generated security sweep.

Required repair

Treat attachment persistence and embedding enrichment as separate outcomes. On embedding failure, either:

  • persist the attachment with embedding=None while preserving its parsed content and provenance, if that is the intended aggregate contract; or
  • fail/roll back the entire email import if an attachment embedding is mandatory.

Do not silently commit an Email aggregate with an attachment removed solely because derived embedding generation failed.

Add regression coverage that forces attachment embedding generation to fail and verifies the chosen invariant at commit time. Also verify transaction behavior: no long-lived transaction should remain open across remote/model work, and no partial-write state may be presented as a successful complete import.

Acceptance boundary

  • explicit Email/Attachment aggregate invariant documented in code/doctoring;
  • deterministic test for attachment-embedding failure;
  • no silent attachment loss;
  • commit/rollback behavior verified;
  • real PostgreSQL acceptance when the repository CI foundation permits it;
  • no dependency/security-gate suppression or unrelated exception-redaction changes.

Refs #1696 review finding on backend/import_fixtures.py.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingpriority: highHigh-priority or P1 work

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions