fix(memory): reject malformed embedding batch JSONL bytes#110502
Conversation
Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
|
Codex review: needs real behavior proof before merge. Reviewed July 18, 2026, 3:27 AM ET / 07:27 UTC. Summary PR surface: Source +6, Tests +24. Total +30 across 2 files. Reproducibility: yes. in source: permissive Review metrics: none identified. Stored data model Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Keep fatal decoding at the shared JSONL boundary and add redacted after-fix evidence from a real OpenAI, Gemini, or Voyage batch retrieval showing a valid batch completes and the malformed-output handling is exercised through the provider path. Do we have a high-confidence way to reproduce the issue? Yes in source: permissive Is this the best way to solve the issue? Yes for the code path: fatal UTF-8 decoding at the shared record boundary rejects corruption before provider-specific handling and avoids divergent checks in OpenAI, Google/Gemini, and Voyage callers. AGENTS.md: unclear because the file could not be read completely. Codex review notes: model internal, reasoning high; reviewed against e9f798ecc424. Label changesLabel justifications:
Evidence reviewedPR surface: Source +6, Tests +24. Total +30 across 2 files. View PR surface stats
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
Review history (3 earlier review cycles) |
|
Merged via squash.
|
…10502) Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
Additional instructions
MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.
AI-assisted: yes. This PR was prepared with Codex assistance.
What Problem This Solves
Fixes an issue where users running memory embedding batch workflows could have malformed provider JSONL output accepted after invalid UTF-8 bytes were rewritten as replacement characters.
The affected path is the shared embedding batch output reader used by the OpenAI, Gemini, and Voyage batch readers. When a provider output line was otherwise valid JSON, a bad byte inside a string could become a
U+FFFDreplacement character beforeJSON.parse, which could corrupt fields such ascustom_idor provider error text instead of reporting a malformed batch record.Why This Change Was Made
The batch output reader now decodes each JSONL record with fatal UTF-8 handling and maps decode failures to the existing malformed-record error shape. This keeps the fix at the shared JSONL boundary and leaves the existing record byte cap, physical-record counting, stream cancellation, and provider-specific output-line handling unchanged.
This is not a vector/embedding metadata schema change and does not alter persisted embedding rows, metadata shape, or migration behavior. It only rejects malformed provider output bytes before those bytes can become parsed JSON records.
User Impact
Malformed embedding batch output now fails clearly as a malformed JSONL record instead of silently carrying corrupted replacement characters into memory embedding result processing. Valid UTF-8 JSONL output continues to parse as before across OpenAI, Gemini, and Voyage batch readers.
Evidence
Runtime proof from the embedding-batch provider path:
This proof exercises
runOpenAiEmbeddingBatches(...)and the provider batch-output download path rather than callingreadEmbeddingBatchJsonl(...)directly. The OpenAI-compatible batch flow matches the output-file shape used by provider batch APIs: completed batch metadata points to an output file, and the reader downloads/files/{output_file_id}/contentbefore parsing JSONL records.Focused validation:
Passed: 4 focused Vitest test files/suites covering the shared JSONL reader plus OpenAI, Google/Gemini, and Voyage embedding batch callers.
Additional checks:
Both passed. Full local
pnpm build && pnpm check && pnpm testwas not run; the focused validation above covers the touched reader and its provider callers, and GitHub CI is running the broader lanes.The new regression test in
packages/memory-host-sdk/src/host/batch-output.test.tsfeeds invalid UTF-8 bytes (0xc3, 0x28) inside a JSONL string and verifies the reader rejects it astest.batch-output: malformed JSONL record. It covers both newline-terminated records and an unterminated final record.User-realistic proof / call chain:
The focused test covers the shared reader where provider JSONL bytes first become text, and the provider embedding batch test files were rerun to check the sibling OpenAI, Google/Gemini, and Voyage callers still accept valid JSONL output.
Dependency contract checked:
TextDecoder(utf-8, { fatal: true })throws on malformed data instead of replacing bad bytes withU+FFFD; the PR relies on that built-in decoder behavior to fail closed beforeJSON.parse.