Skip to content

fix(macos): use foundationValue when serializing browser proxy POST body#43069

Merged
frankekn merged 2 commits intoopenclaw:mainfrom
ImLukeF:imlukef/pr-41635-rescue
Mar 11, 2026
Merged

fix(macos): use foundationValue when serializing browser proxy POST body#43069
frankekn merged 2 commits intoopenclaw:mainfrom
ImLukeF:imlukef/pr-41635-rescue

Conversation

@ImLukeF
Copy link
Copy Markdown
Contributor

@ImLukeF ImLukeF commented Mar 11, 2026

Replacement for #41635.

Original contributor: @Effet

This PR preserves the exact original contributor commit on a maintainer-owned rescue branch after the prior rescue PR was removed.

Summary

  • Problem: MacNodeBrowserProxy.makeRequest passes params.body?.value directly to JSONSerialization.data(withJSONObject:). AnyCodable.init(from:) stores decoded JSON objects as [String: AnyCodable] internally — a pure Swift struct (__SwiftValue) that NSJSONSerialization can't handle, causing an NSInvalidArgumentException crash (SIGABRT) on every non-GET request with a JSON body.
  • Why it matters: Any POST/PUT/PATCH request routed through the Mac browser proxy crashes the app. The crash is deterministic and not edge-case.
  • What changed: Use params.body?.foundationValue instead of params.body?.value. foundationValue (already defined in AnyCodable+Helpers.swift) recursively converts [String: AnyCodable][String: Any] so JSONSerialization receives only Foundation-compatible types.
  • What did NOT change: No behavior change for GET requests or response parsing; no new dependencies.

Change Type (select all)

  • Bug fix

Scope (select all touched areas)

  • UI / DX

Linked Issue/PR

User-visible / Behavior Changes

Mac app no longer crashes when making POST/PUT/PATCH requests through the browser proxy.

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: macOS (latest)
  • Runtime: Mac app (MacNodeRuntime)

Steps

  1. Open Mac app with gateway running
  2. Trigger any browser proxy call that uses a non-GET method with a JSON body (e.g. a POST via MacNodeBrowserProxy.request)
  3. App crashes with NSInvalidArgumentException: Invalid type in JSON write (__SwiftValue)

Expected

  • Request serializes and sends successfully

Actual

  • SIGABRT crash in MacNodeBrowserProxy.makeRequest at JSONSerialization.data(withJSONObject:)

Evidence

  • Regression test added: postRequestSerializesNestedBodyWithoutCrash in MacNodeBrowserProxyTests.swift — covers nested dict + array body, was impossible to add before the fix (would crash)

Human Verification (required)

  • Verified scenarios: read crash stack trace, identified root cause in source, confirmed foundationValue is the correct converter, added failing→passing test
  • Edge cases checked: nested objects, arrays, null values all handled by existing foundationValue recursion
  • What you did not verify: live end-to-end POST request through running gateway (no Mac build in this session)

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Failure Recovery (if this breaks)

  • Revert: restore params.body?.value in MacNodeBrowserProxy.swift:149
  • Known bad symptom: app crashes on any browser proxy POST request (same as before fix)

Risks and Mitigations

  • Risk: foundationValue on an unrecognized type falls through to self.value (the default case) — same behavior as before, so no regression risk.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 11, 2026

Greptile Summary

This PR fixes a deterministic SIGABRT crash in MacNodeBrowserProxy.makeRequest by replacing params.body?.value with params.body?.foundationValue when serializing the POST/PUT/PATCH request body via JSONSerialization. The root cause is that AnyCodable.init(from:) stores decoded JSON dictionaries as [String: AnyCodable] — a pure Swift type that NSJSONSerialization cannot serialize — and foundationValue already exists in AnyCodable+Helpers.swift to recursively convert that representation into Foundation-compatible types ([String: Any]). A focused regression test is included.

Changes:

  • MacNodeBrowserProxy.swift (line 149–151): switch from .value to .foundationValue for the request body passed to JSONSerialization
  • MacNodeBrowserProxyTests.swift: add postRequestSerializesNestedBodyWithoutCrash regression test covering nested dict + array bodies

Notes:

  • The fix is minimal and correct. foundationValue handles [String: AnyCodable], [AnyCodable], and all primitive leaf types, so no new edge-case surface is introduced.
  • The test's capturedBody is a var captured by a @Sendable closure. In Swift 6 strict concurrency mode this pattern can produce a compile-time error. It works correctly at runtime given the sequential await, but may need a nonisolated(unsafe) annotation or a Box/ActorIsolated wrapper if the project migrates to Swift 6 strict mode.

Confidence Score: 5/5

  • This PR is safe to merge — it is a minimal, targeted fix for a deterministic crash with a regression test.
  • The change is a one-line fix (.value.foundationValue) with a clear root cause, correct implementation, and a companion regression test. foundationValue is an existing, well-understood utility that handles all the relevant type cases. No new dependencies, no behavior changes for GET requests, and full backward compatibility.
  • No files require special attention. The only minor note is that capturedBody in MacNodeBrowserProxyTests.swift is mutated inside a @Sendable closure, which may need adjustment if the project adopts Swift 6 strict concurrency, but this does not affect correctness today.

Last reviewed commit: b33b805

@frankekn frankekn force-pushed the imlukef/pr-41635-rescue branch from b33b805 to 2da99f4 Compare March 11, 2026 10:30
frankekn added a commit to ImLukeF/openclaw that referenced this pull request Mar 11, 2026
@frankekn frankekn force-pushed the imlukef/pr-41635-rescue branch from 2da99f4 to 04c33fa Compare March 11, 2026 11:10
@frankekn frankekn merged commit f063e57 into openclaw:main Mar 11, 2026
20 checks passed
@frankekn
Copy link
Copy Markdown
Contributor

Merged via squash.

Thanks @ImLukeF!

@frankekn
Copy link
Copy Markdown
Contributor

Correction on attribution: thanks @Effet for the original fix.

And thanks @ImLukeF for helping resubmit it as the clean replacement PR.

hydro13 pushed a commit to andyliu/openclaw that referenced this pull request Mar 11, 2026
…ody (openclaw#43069)

Merged via squash.

Prepared head SHA: 04c33fa
Co-authored-by: ImLukeF <[email protected]>
Co-authored-by: frankekn <[email protected]>
Reviewed-by: @frankekn
Treedy2020 pushed a commit to Treedy2020/openclaw that referenced this pull request Mar 11, 2026
…ody (openclaw#43069)

Merged via squash.

Prepared head SHA: 04c33fa
Co-authored-by: ImLukeF <[email protected]>
Co-authored-by: frankekn <[email protected]>
Reviewed-by: @frankekn
mrosmarin added a commit to mrosmarin/openclaw that referenced this pull request Mar 11, 2026
* main: (49 commits)
  fix(agents): add nodes to owner-only tool policy fallbacks
  fix(gateway): propagate real gateway client into plugin subagent runtime
  fix(gateway): enforce caller-scope subsetting in device.token.rotate
  fix(terminal): stabilize skills table width across Terminal.app and iTerm (openclaw#42849)
  fix(models): guard optional model input capabilities  (openclaw#42096)
  macOS/onboarding: prompt for remote gateway auth tokens (openclaw#43100)
  fix(macos): use foundationValue when serializing browser proxy POST body (openclaw#43069)
  feat(ios): add local beta release flow (openclaw#42991)
  docs(changelog): update context pruning PR reference
  fix(context-pruning): cover image-only tool-result pruning
  fix(context-pruning): prune image-containing tool results instead of skipping them (openclaw#41789)
  fix(agents): include azure-openai in Responses API store override (openclaw#42934)
  fix(telegram): fall back on ambiguous first preview sends
  fix(telegram): prevent duplicate messages with slow LLM providers (openclaw#41932)
  Providers: add Opencode Go support (openclaw#42313)
  fix(sandbox): sanitize Docker env before marking OPENCLAW_CLI (openclaw#42256)
  macOS: add chat model selector and persist thinking (openclaw#42314)
  fix: clear pnpm prod audit vulnerabilities
  fix(build): restore full gate
  fix(gateway): split conversation reset from admin reset
  ...
dhoman pushed a commit to dhoman/chrono-claw that referenced this pull request Mar 11, 2026
…ody (openclaw#43069)

Merged via squash.

Prepared head SHA: 04c33fa
Co-authored-by: ImLukeF <[email protected]>
Co-authored-by: frankekn <[email protected]>
Reviewed-by: @frankekn
ahelpercn pushed a commit to ahelpercn/openclaw that referenced this pull request Mar 12, 2026
…ody (openclaw#43069)

Merged via squash.

Prepared head SHA: 04c33fa
Co-authored-by: ImLukeF <[email protected]>
Co-authored-by: frankekn <[email protected]>
Reviewed-by: @frankekn
Ruijie-Ysp pushed a commit to Ruijie-Ysp/clawdbot that referenced this pull request Mar 12, 2026
…ody (openclaw#43069)

Merged via squash.

Prepared head SHA: 04c33fa
Co-authored-by: ImLukeF <[email protected]>
Co-authored-by: frankekn <[email protected]>
Reviewed-by: @frankekn
leozhengliu-pixel pushed a commit to leozhengliu-pixel/openclaw that referenced this pull request Mar 13, 2026
…ody (openclaw#43069)

Merged via squash.

Prepared head SHA: 04c33fa
Co-authored-by: ImLukeF <[email protected]>
Co-authored-by: frankekn <[email protected]>
Reviewed-by: @frankekn
plabzzxx pushed a commit to plabzzxx/openclaw that referenced this pull request Mar 13, 2026
…ody (openclaw#43069)

Merged via squash.

Prepared head SHA: 04c33fa
Co-authored-by: ImLukeF <[email protected]>
Co-authored-by: frankekn <[email protected]>
Reviewed-by: @frankekn
senw-developers pushed a commit to senw-developers/va-openclaw that referenced this pull request Mar 17, 2026
…ody (openclaw#43069)

Merged via squash.

Prepared head SHA: 04c33fa
Co-authored-by: ImLukeF <[email protected]>
Co-authored-by: frankekn <[email protected]>
Reviewed-by: @frankekn
t--becker pushed a commit to t--becker/openclaw that referenced this pull request Mar 19, 2026
…ody (openclaw#43069)

Merged via squash.

Prepared head SHA: 04c33fa
Co-authored-by: ImLukeF <[email protected]>
Co-authored-by: frankekn <[email protected]>
Reviewed-by: @frankekn
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.

macOS app crashes on browser.proxy invoke with Invalid type in JSON write (__SwiftValue)

3 participants