Repository navigation
Studio: don't crash the app when a tool arg isn't a string - #9641
Conversation
|
Codex Review: Didn't find any major issues. Nice work! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
GitHub Actions reproductionThe crash and its fix are reproduced on Actions in one run, 3 jobs. Same workflow, same runner image, same The probe takes the argument derivation straight out of each shipped card — the way
4 crashed → 2 crashed → 0 crashed, each asserted exactly. The two that survived the first pass are reachable the same way the ones it fixed are:
On severity: |
Studio before/afterTwo isolated installs on this box,
Both sides were seeded with the same stored thread through the real chat-history API (
BEFORE is not a broken card — it is a blank white page carrying |
CI triage35 pass, 1 fail. The failure is not this PR's.
|
de19960 to
bbf5502
Compare
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
The args are covered, but the same crash is still reachable through the image card's RESULT and through a tool name. parseImageSize guards nullish only, so a provider that answers "size": 1024 reached .match on a number; the metadata line joins size, quality and mime, and Array.join calls ToString on each, so an object whose own toString is null throws "Cannot convert object to primitive value"; extensionForMime calls .toLowerCase on a mime that is the chunk's own inlineData.mimeType on the Gemini path. These sit on the same result object whose prompt this branch already coerces, for the same reason: Studio takes a user-set base_url. A tool name lands in tool-fallback whenever it matches nothing in thread.tsx's by_name map, which a non-string always does, and formatMcpToolName then calls .startsWith on it. message-response-details-sheet.tsx and use-chat-search-index already guard typeof toolName === "string"; this was the one place that did not. Serialised objects are now capped at 100k characters. The engines disagree about how long a string may be -- V8 stops at ~512Mi and throws, JSC at ~2Gi -- so an uncapped serialisation renders as "" in Chrome and as hundreds of megabytes of DOM in Safari. Only the JSON branch is capped, so every string argument is returned exactly as before. The catch is not unreachable, and the comment now says what was measured: Chrome, Firefox and Safari all parse at least 4,000,000 levels of nesting, and then Firefox throws InternalError: too much recursion and Safari RangeError out of JSON.stringify where Chrome returns the string. On two of three engines that catch is load-bearing for ordinary wire data. Measured across the three engines with each card's own derivation lifted out of its source: 139 of 344 renders killed the whole app before this branch, 0 after, identically in Chromium, Firefox and WebKit. Of the 205 inputs that already rendered, 142 are byte-identical and the other 63 are non-strings that used to print [object Object].
Review, cross-engine simulation, and two more holes of the same classReviewed at The crash, reproduced independentlyEach card's own
Identical counts in all three. The new test file also fails on the base for the right reason ( Two more paths of the same class, now fixed
One thing the coercion introduced, also fixedSerialising an object creates a string where the old code threw, and the engines cap string length differently: V8 at ~512 MiB with a While measuring that: the Nothing that worked before changesOf the 205 inputs that already rendered on the base, 142 are byte-identical on this branch and the other 63 are all non-strings that previously printed Everything that was run
CI noteThe Follow-ups, deliberately not in this branchSame bug class, different layer, so they want their own change:
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 67f5cdc8a3
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if (typeof value === "object") { | ||
| // `?? ""` because a `toJSON` can return undefined, a function or a symbol, | ||
| // for which JSON.stringify returns undefined rather than a string. | ||
| const json = JSON.stringify(value) ?? ""; |
There was a problem hiding this comment.
Apply the cap while serializing large object arguments
When a model supplies a large object or array as an argument, JSON.stringify still traverses the complete value and allocates the entire serialized string before the 100,000-character slice is applied. Reopening a persisted thread containing a multi-megabyte malformed argument can therefore block the UI and temporarily duplicate the whole payload in memory, whereas the previous object coercion was constant-size; enforce the limit during serialization rather than after materializing the full JSON.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
The mechanism is described correctly, JSON.stringify does materialize the whole string before the slice. The magnitude is not, and the comparison to a constant-size predecessor points at code that was removed for being a crash: String() on {"toString":null} throws "Cannot convert object to primitive value", which is the P1 on this same file earlier in this PR.
Measured on this branch, Node 24, against the wire payload that has to exist for the value to reach the card at all:
wire 0.2 MB JSON.parse 0.4 ms / +0.2 MB toolArgText 0.3 ms / +0.1 MB out=100001 chars
wire 2.1 MB JSON.parse 4.1 ms / +0.8 MB toolArgText 2.2 ms / +1.0 MB out=100001 chars
wire 21 MB JSON.parse 42.1 ms / +7.6 MB toolArgText 27.8 ms / +10.5 MB out=100001 chars
The helper is cheaper than the parse that is its own precondition. chat-adapter.ts:6597 and :6646 JSON.parse the full argsText and keep both the raw string and the parsed graph on the message part, so on reopening a persisted thread that payload is already resident twice, permanently, before this function runs. The transient third copy is the smallest of the three and the only one that is bounded on the way out.
Enforcing the limit during serialization has no cheap form. There is no streaming or bounded JSON.stringify in the platform and no TC39 proposal for one (the closest is the WICG async-JSON discussion, which stalled on needing a full synchronous copy first). A replacer cannot see accumulated output length, so a budget there is an estimate over pre-escaping values, and MDN notes the replacer is invoked per key-value pair and is slower than plain JSON.stringify on large objects, which is exactly the input this is meant to protect. A real bound means a streaming serializer dependency (json-stream-lite, big-json) inside a helper whose entire contract is that it cannot throw, and this repo pins and supply-chain-audits frontend deps.
Also worth noting that this path is unreachable on a well-formed call: a string argument takes the early return and is never serialized, so everything here is already the malformed-input branch.
Leaving the cap where it is. It bounds what reaches the DOM, which is the cost that actually shows up as a frozen tab.
|
Confirmed this on main, where tool-ui-python.tsx:144 and tool-ui-code-execution.tsx:137 still call string methods straight on the model's argument and take the whole app down on a persisted thread. Note #9640 adds the same guard in tool-ui-python.tsx, so the two overlap and we should reconcile them before either lands. |
Also moves the toolArgText docblock back onto the function, where a second docblock for the cap constant had displaced it. Comments only, AST verified.
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Cuts the preamble that restated tool-arg-text.ts's own docblock. Comments only, AST verified.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
* Studio: coerce model-supplied tool args before the cards render them * Studio: coerce the two tool cards the first pass missed, behind one helper * Studio: serialise object tool args instead of coercing them * Studio: coerce the provider-controlled fields the args pass missed The args are covered, but the same crash is still reachable through the image card's RESULT and through a tool name. parseImageSize guards nullish only, so a provider that answers "size": 1024 reached .match on a number; the metadata line joins size, quality and mime, and Array.join calls ToString on each, so an object whose own toString is null throws "Cannot convert object to primitive value"; extensionForMime calls .toLowerCase on a mime that is the chunk's own inlineData.mimeType on the Gemini path. These sit on the same result object whose prompt this branch already coerces, for the same reason: Studio takes a user-set base_url. A tool name lands in tool-fallback whenever it matches nothing in thread.tsx's by_name map, which a non-string always does, and formatMcpToolName then calls .startsWith on it. message-response-details-sheet.tsx and use-chat-search-index already guard typeof toolName === "string"; this was the one place that did not. Serialised objects are now capped at 100k characters. The engines disagree about how long a string may be -- V8 stops at ~512Mi and throws, JSC at ~2Gi -- so an uncapped serialisation renders as "" in Chrome and as hundreds of megabytes of DOM in Safari. Only the JSON branch is capped, so every string argument is returned exactly as before. The catch is not unreachable, and the comment now says what was measured: Chrome, Firefox and Safari all parse at least 4,000,000 levels of nesting, and then Firefox throws InternalError: too much recursion and Safari RangeError out of JSON.stringify where Chrome returns the string. On two of three engines that catch is load-bearing for ordinary wire data. Measured across the three engines with each card's own derivation lifted out of its source: 139 of 344 renders killed the whole app before this branch, 0 after, identically in Chromium, Firefox and WebKit. Of the 205 inputs that already rendered, 142 are byte-identical and the other 63 are non-strings that used to print [object Object]. * Studio: tighten the tool arg coercion comments Also moves the toolArgText docblock back onto the function, where a second docblock for the cap constant had displaced it. Comments only, AST verified. * Studio: trim the tool arg coercion test comments Cuts the preamble that restated tool-arg-text.ts's own docblock. Comments only, AST verified. --------- Co-authored-by: danielhanchen <[email protected]>

If a model sends a tool call with a number instead of a string, the whole app dies and shows "Something went wrong!". Reopening the chat brings it right back, because the bad message is saved.
The python card does
code.split("\n")on whatever the model sent.?? ""only covers null and undefined, so a number goes straight to.splitand throws. A tool card has no boundary above it — the nearest catcher is the router's — so the entire UI unmounts.markdown-block-boundary.tsxdocuments the same failure measured on a Markdown block.Every card now reads its text arguments through one helper,
toolArgText, so a number renders as42instead of taking the session with it:pythoncode.split("\n")terminalcommand.slice(0, 60)code_executioncommand.replace(/\s+/g, " ")image_generationprompt.trim()web_searchquery,url.trim(),.startsWith()— already coercedsearch_knowledge_basequerycode_executionandimage_generationwere missed in the first pass and crash the same way.code_executionarguments are the model's ownserver_tool_useJSON forwarded untouched (external_provider.py:2818);image_generationcarriesrevised_promptfrom the provider, and Studio accepts a user-supplied OpenAI-compatiblebase_url, so that string is third-party controlled.The arg interfaces now say
unknownrather thanstring, so an uncoerced read is a type error rather than a runtime one.render_htmlis left alone: it already guards withtypeof === "string", which is crash-safe by a different rule.Tests cover the coercion behaviourally and assert through the TypeScript AST that every card uses it, with a closed-world check that fails when a new
tool-ui-*.tsxappears unaccounted for — a new card is how this comes back.