fix(deepagents): base64-encode binary FileData content in StoreBackend store values - #642
Open
Nitsan Cohen (NitsanCohen770) wants to merge 1 commit into
Conversation
…d store values
BaseStore implementations that persist values as JSON (e.g. the Postgres
store's JSONB column) cannot represent a raw Uint8Array: JSON
serialization turns it into a numeric-keyed byte map ({"0":123,...})
that fails FileData validation on read, so any binary file written
through StoreBackend against such a store was stored unreadable.
convertFileDataToStoreValue now base64-encodes binary content with an
encoding: "base64" marker and convertStoreItemToFileData reverses it.
Text content keeps its plain-string representation, and in-memory
stores are unaffected (reads now return a defensive copy rather than an
alias of store-internal state, so the offset/limit identity assertion
becomes a value assertion).
|
Nitsan Cohen (@NitsanCohen770) is attempting to deploy a commit to the LangChain Team on Vercel. A member of the Team first needs to authorize it. |
|
deepagents-acp
deepagents
@langchain/sandbox-standard-tests
@langchain/daytona
@langchain/deno
@langchain/modal
@langchain/node-vfs
@langchain/quickjs
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
StoreBackend.convertFileDataToStoreValuepasses binaryFileData.contenttostore.put()as a rawUint8Array.BaseStoreimplementations that persist values as JSON — e.g. the LangGraph Postgres store, whosevaluecolumn is JSONB — round-trip every value through JSON serialization, which turns aUint8Arrayinto a numeric-keyed byte map:{"content": {"0": 137, "1": 80, "2": 78, ...}}On the way back,
convertStoreItemToFileDatarejects that shape (Store item does not contain valid FileData fields), so any binary file written throughStoreBackendagainst a JSON-backed store is stored successfully and then permanently unreadable. This hits more than images: any extension without a recognized text MIME (.jsonlincluded) takes the binary path inuploadFiles.Fix
convertFileDataToStoreValuebase64-encodes binary content and marks the store value withencoding: "base64";convertStoreItemToFileDatareverses it. Text content keeps its plain-string representation (no store-format change), and values written by in-memory stores as realUint8Arrays still pass through untouched.One existing assertion updated:
read()of a binary file now returns a defensive copy rather than an alias of store-internal state, so the offset/limit identity check (toBe) becomes a value check (toStrictEqual) — object identity across reads was an artifact of the in-memory store returning its internal buffer by reference, not a documented contract.Test
Adds a regression test that wraps
InMemoryStorewith JSON round-tripping onput(the exact behavior of a JSONB-backed store) and asserts a PNG byte payload survivesuploadFiles → readRaw/downloadFilesbyte-for-byte, while text files keep a plain-string store representation with noencodingmarker.Verification
Hit in production against the LangGraph
PostgresStore: every.jsonlfile uploaded throughStoreBackendwas written as an unreadable byte map (verified by inspecting the JSONB rows) and failed FileData validation on read. With this change the same flow round-trips correctly.libs/deepagentsvitest suite: 1178 passing locally (the 6 pre-existing*.int.test.tstypecheck errors about@langchain/sandbox-standard-testsare unrelated and present onmain).