Skip to content

Preview: a value JSON has no form for no longer ends the app on macOS and iOS, and a script's error is reported - #1200

Merged
Tryanks merged 1 commit into
mainfrom
claude/preview-evaluate-crash
Nov 27, 2026
Merged

Tryanks merged 1 commit into
mainfrom
claude/preview-evaluate-crash

Conversation

@Tryanks

@Tryanks Tryanks commented Nov 27, 2026 •

Copy link
Copy Markdown
Owner

Summary

On macOS and iOS a preview_evaluate whose value held a NaN, an infinity or a Date ended the whole app. 0.5.1 went down this way on [window.__tr, Date.now()-window.__tt], where __tt was undefined.

The cause is in lb-wry 0.53.3: its evaluation callback gives WebKit's result object to NSJSONSerialization, which raises on a value JSON has no form for, and nothing catches the exception. The same callback drops the NSError WebKit reports, so a syntax error or a thrown exception came back as "". Tcode carries it at the owner of the evaluation, on these two platforms only:

 evaluate_in_page                                  (crates/ui/src/preview_panel/lifecycle.rs)
   android         → RawWebView::evaluate_json
-  everything else → wry / webview2 evaluate_script_with_callback
+  linux, windows  → wry / webview2 evaluate_script_with_callback
+  macos, ios      → page_agent::evaluate          (crates/ui/src/preview_panel/page_agent.rs)
+    evaluateJavaScript: "JSON.stringify(<expression>)"
+      NSError        → the call's error: the thrown exception's message where WebKit gives one
+      nil            → "" (undefined), as before
+      NSString       → the JSON text, parsed as on every engine
+      anything else  → error: the page replaced JSON.stringify

The page makes the JSON, which is what WebView2, Android and WebKitGTK already hand back from the engine, so no Foundation serialization is left on the path.

What an agent sees differently on macOS and iOS:

js before now
[undefined, NaN] the app exits [null, null]
Infinity, new Date(0) not run in the app; NSJSONSerialization raises on both when called alone null, "1970-01-01T00:00:00.000Z"
window.__tt=1; 2 "" error: SyntaxError: Unexpected token ';'. …
(()=>{throw new Error("boom")})() "" error: Error: boom
new Promise(…) "" {}
a cyclic object, 10n not run error: TypeError: JSON.stringify cannot serialize …
document.body not run {}
any, before the first page is opened error: preview panel dropped request; by lb-wry's source the script then runs unheard at the next navigation, which was not observed runs in WebKit's empty page: location.href → "about:blank"

Not changed: on Linux lb-wry still answers a script's error with "", and WebView2 and Android report it as their engines do.

Evidence

Both builds are tcode debug builds on a throwaway TCODE_DATA_DIR, macOS 27.2.1, each with a real thread and a real WKWebView on data:text/html,<title>t</title><p>hi</p>; the calls are tools/call requests to the thread's own preview MCP server.

  • Before (ed81cdc50):
    preview_evaluate {"js": "[window.__tr, Date.now()-window.__nope]"}
      -> transport failure: IncompleteRead
    *** Terminating app due to uncaught exception 'NSInvalidArgumentException',
        reason: 'Invalid number value (NaN) in JSON write'
    exit status: 134
    
    After, the same call and the rest in one run, the app still up at the end and preview_snapshot answering after the page had replaced JSON.stringify:
    "ok"                                          -> "ok"
    ({a:1})                                       -> {"a": 1}
    JSON.stringify({a:1})                         -> "{\"a\":1}"
    undefined                                     -> ""
    [window.__tr, Date.now()-window.__nope]       -> [null, null]
    NaN                                           -> null
    [Infinity, -Infinity, 0.1, 42, true, null]    -> [null, null, 0.1, 42, true, null]
    ({when: new Date(0)})                         -> {"when": "1970-01-01T00:00:00.000Z"}
    window.__tt=1; 2                              -> ERROR SyntaxError: Unexpected token ';'. Expected ')' to end a compound expression.
    (()=>{throw new Error("boom")})()             -> ERROR Error: boom
    (()=>{const a={};a.a=a;return a})()           -> ERROR TypeError: JSON.stringify cannot serialize cyclic structures.
    10n                                           -> ERROR TypeError: JSON.stringify cannot serialize BigInt.
    new Promise(r=>r(1))                          -> {}
    (()=>1)                                       -> ""
    (JSON.stringify = () => NaN, 1)               -> 1
    2                                             -> ERROR the page's JSON.stringify did not return text
    
  • cargo fmt --all --check, cargo clippy --workspace --all-targets --locked -- -D warnings and cargo nextest run --workspace --locked (1514 passed) on macOS; RUSTFLAGS='-D warnings' cargo check -p tcode-ios --target aarch64-apple-ios-sim --locked. iOS is compiled, not run.

No test is added. What failed is WebKit's result meeting Foundation, which only a real engine shows; a test of the wrapper's text would assert a string the code under test writes.

Merge Danger

Door: two-way

Blast Radius: preview_evaluate on macOS and iOS

An agent that relied on "" for a failing expression now gets a tool error instead.

… and iOS, and a script's error is reported

preview_evaluate went through lb-wry's evaluation callback, which gives
WebKit's result object to NSJSONSerialization. That raises on a NaN, an
infinity or a Date anywhere in the value, and the exception ends the
process. The callback also drops the error WebKit reports, so a syntax error
or a thrown exception came back as an empty string.

On macOS and iOS Tcode now calls evaluateJavaScript itself: the page makes
the JSON of its value, which is what WebView2, Android and WebKitGTK already
hand back, and WebKit's error is the call's error.
@Tryanks
Tryanks force-pushed the claude/preview-evaluate-crash branch from bbf0beb to 3944a96 Compare November 27, 2026 01:45
@Tryanks
Tryanks enabled auto-merge November 27, 2026 01:49
@Tryanks
Tryanks merged commit 5c267a3 into main Nov 27, 2026
13 checks passed
@Tryanks
Tryanks deleted the claude/preview-evaluate-crash branch November 27, 2026 01:59
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