Skip to content

Fix browser proxy JSON bridge handling in macOS app#44146

Open
caojm93 wants to merge 2 commits intoopenclaw:mainfrom
caojm93:codex/browser-proxy-jsonencoder-fix
Open

Fix browser proxy JSON bridge handling in macOS app#44146
caojm93 wants to merge 2 commits intoopenclaw:mainfrom
caojm93:codex/browser-proxy-jsonencoder-fix

Conversation

@caojm93
Copy link
Copy Markdown

@caojm93 caojm93 commented Mar 12, 2026

Summary

  • replace JSONSerialization bridging in MacNodeBrowserProxy with AnyCodable plus JSONEncoder/JSONDecoder
  • keep browser proxy request/response handling on the Swift side from aborting on non-foundation JSON bridge values
  • add regression coverage for nested request bodies and scalar JSON results

Testing

  • HOME=/tmp/openclaw-home CLANG_MODULE_CACHE_PATH=/tmp/clang-mod-cache SWIFTPM_MODULECACHE_OVERRIDE=/tmp/swiftpm-module-cache swift test --package-path /Users/caojiaming/Documents/Playground/openclaw/apps/macos --filter MacNodeBrowserProxyTests
  • built OpenClaw.app locally from this branch and verified openclaw browser open https://www.baidu.com succeeds without generating a new macOS crash report

Closes #43872

@katoue

This comment was marked as spam.

@caojm93
Copy link
Copy Markdown
Author

caojm93 commented Mar 12, 2026

Fixes the browser proxy crash discussed in:

#43872

That issue includes the original reproduction steps, crash reports, and the NSJSONSerialization -> MacNodeBrowserProxy.makeRequest(...) -> SIGABRT evidence chain.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 12, 2026

Greptile Summary

This PR replaces the JSONSerialization-based JSON bridge in MacNodeBrowserProxy with AnyCodable + JSONEncoder/JSONDecoder, fixing crashes that occurred when non-Foundation JSON values (e.g., nested Swift types bridged via __SwiftValue) passed through the proxy. Two targeted regression tests are added.

Key changes:

  • ProxyFilePayload is made Encodable and its manual asJSON() helper is removed, replaced by a new ProxyResponse: Encodable wrapper struct.
  • Response decoding now uses JSONDecoder().decode(AnyCodable.self, from: data), which handles scalar top-level JSON (e.g., true) that JSONSerialization could produce but the old wrapping pipeline couldn't safely propagate.
  • Request body serialization switches from JSONSerialization.data(withJSONObject: body.foundationValue, options: [.fragmentsAllowed]) to JSONEncoder().encode(body), eliminating the __SwiftValue bridging crash on nested objects.
  • result.foundationValue bridges back to Any for the unchanged collectProxyPaths / loadProxyFiles logic, keeping that code path working without modification.
  • Swift's synthesized Encodable for ProxyResponse uses encodeIfPresent for the optional files property, correctly omitting the key when nil (matching the old behaviour of only setting the key when non-empty).

Confidence Score: 5/5

  • This PR is safe to merge — the changes are narrowly scoped, logically correct, and backed by targeted regression tests.
  • All changed codepaths have been carefully traced. The Codable round-trip is correct for all JSON value kinds (scalars, objects, arrays, null). The optional-nil omission relies on well-defined Swift behaviour (synthesised Encodable uses encodeIfPresent). The foundationValue bridge preserves the existing collectProxyPaths/loadProxyFiles semantics. No edge-case regressions were found.
  • No files require special attention.

Last reviewed commit: 1df314d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: openclaw browser open can crash OpenClaw.app via browser.proxy / MacNodeBrowserProxy.makeRequest

2 participants