Repository navigation
Conversation
An inline image larger than about 500k base64 characters never reached the model, however high maxToolResultChars was set: projectArtifactPayload and projectAnthropicArtifactContent replaced it with "[omitted 1 oversized atomic tool-content block: image_url]". jsonStringLength walked every character against MAX_STRUCTURED_CHARACTER_WORK, and compactToolContent shares one allowance between its measurements of the same content. A large data URL exhausted it, measured as Number.MAX_SAFE_INTEGER and was omitted. A base64 data URL needs no JSON escaping, so jsonStringLength now returns its length plus the quotes when the whole string matches one and stays within HARD_MAX_TOTAL_TOOL_OUTPUT_SIZE, the ceiling isProviderImageUrl already applies to inline images. Every other string keeps the bounded walk, and the caller's cap still applies.
This branch has not been deployed
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.
jsonStringLengthwalks every character againstMAX_STRUCTURED_CHARACTER_WORK(1M), andcompactToolContentmeasures the same content more than once with one shared allowance (originalChars, then the normalized length). A data URL over ~500k characters exhausts it. The content then measures asNumber.MAX_SAFE_INTEGER, and the atomic block is omitted whatever the cap allows.length + 2.jsonStringLengthnow returns that for a string that fully matches a base64 data URL and is no longer thanHARD_MAX_TOTAL_TOOL_OUTPUT_SIZE, the ceilingisProviderImageUrlalready applies to inline images.Related to #602 (the same report) and #603 (the same approach). Their author withdrew both without review, and the behavior is unchanged in 4.2.1. We have run the equivalent change as a patch on 4.0.4 in a LibreChat deployment since 2026-11-04.
Verification
mainat708c9118: 600k and 3.2M-character images kept under an 8M cap, and both artifact projections keep a 600k-character image", a data URL above the ceiling and a plain 1.1M-character string still exhaust the walknpx jest src/utils src/messages src/graphs/__tests__/Graph.contextOverflow.test.ts--testPathIgnorePatternsas invalidate.yml)npm run typecheck, ESLint andsort-imports --checkon the touched files,git diff --checknpm run build:dev,npx tsc -p tsconfig.build.json,npm run check:circular-deps,test:circular-deps,test:light-entries,test:typecheckEach measurement of a data URL now costs one native regex pass instead of a character walk capped at 1M: about 14 ms for a 3.2M-character URL on our machine. The ceiling bounds that cost. The changed lines follow the pre-commit Prettier and ESLint pass. Existing formatting drift elsewhere in
formatAgentMessages.test.tsis left untouched.Not run: live provider requests or Langfuse export. The change only alters how a string is measured, not what is sent or traced.