Skip to content

fix(import): preserve content-type case for multipart boundary matching#1565

Merged
hijzy merged 1 commit into
MemTensor:mem-agent-0424from
hijzy:fix/import-multipart-case-sensitivity
Apr 28, 2026
Merged

fix(import): preserve content-type case for multipart boundary matching#1565
hijzy merged 1 commit into
MemTensor:mem-agent-0424from
hijzy:fix/import-multipart-case-sensitivity

Conversation

@hijzy
Copy link
Copy Markdown
Collaborator

@hijzy hijzy commented Apr 28, 2026

Summary

Fixes "missing 'bundle' file field" error when importing JSON bundles via the viewer's Import page.

Root cause: The import endpoint lowercased the entire content-type header (ct.toLowerCase()) before parsing, which corrupted the case-sensitive boundary value. For example, browsers send a header like boundary=----WebKitFormBoundaryfCbu5kYxjTihKDLq but the request body uses the original-case WebKitFormBoundaryfCbu5kYxjTihKDLq. After lowercasing, no match could be found, parser returned null, and the user saw the misleading "missing 'bundle' file field" error.

Fix: Preserve the original case of the content-type header for boundary parsing; only lowercase a copy used for the type-prefix check.

Other improvements

  • parseMultipartBundle now operates on Buffers directly (no binary encoding round-trip that could corrupt UTF-8 content)
  • Handles boundaries with or without leading dashes in the header value
  • Adds JSON fallback when multipart parsing fails entirely (so users can also POST raw JSON)
  • install.sh: explicit bridge daemon kill step with force-kill fallback for cleaner re-installs

Test plan

  • Import a JSON bundle exported from another agent — verify it succeeds without "missing 'bundle' file field" error
  • Import a JSON bundle with non-ASCII content (Chinese chars) — verify content is not corrupted

Previously the import endpoint lowercased the entire content-type
header before parsing, which corrupted the boundary value (e.g.
WebKitFormBoundaryXyZ → webkitformboundaryxyz). The body retained
the original case, so the parser could not find any boundary match
and returned "missing 'bundle' file field".

Other improvements:
- parseMultipartBundle now operates on Buffers directly (no binary
  encoding round-trip that could corrupt UTF-8 content)
- handles boundaries with or without leading dashes in the header
- adds JSON fallback when multipart parsing fails entirely
- raises import body limit to 100MB so large databases can be uploaded
- install.sh: explicit bridge daemon kill step with force-kill fallback
@hijzy hijzy merged commit cefd957 into MemTensor:mem-agent-0424 Apr 28, 2026
@hijzy hijzy deleted the fix/import-multipart-case-sensitivity branch April 29, 2026 02:43
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