Skip to content

fix(ios): Debug builds nearly overflow the main-thread stack in the chat composer - #165472

Merged
Patrick-Erichsen merged 1 commit into
openclaw:mainfrom
Marvinthebored:fix/ios-composer-stack-depth
Oct 5, 2026
Merged

Patrick-Erichsen merged 1 commit into
openclaw:mainfrom
Marvinthebored:fix/ios-composer-stack-depth

Conversation

@Marvinthebored

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes: a Debug build of the iOS app is within a few percent of overflowing the main-thread stack when the chat composer first draws, so one more view layer in the composer makes the app crash at launch on a real device.

User Impact

User impact: no change for released builds. Developers and testers running Debug builds on a physical iPhone get about 660 KB of stack headroom back in the composer, instead of a launch crash the next time a wrapper or modifier is added there.

Why This Change Was Made

Unoptimized builds keep every nested some View temporary on the stack, and the composer is one chain of nested getters evaluated in a single body. A small closure-backed view evaluates two parts of that chain (the styled composer content and the editor) in their own bodies, which splits the chain. Layout, modifiers and observation are otherwise unchanged; the wrapped subtrees are the same views in the same places.

Evidence

Measured on main bbaabd6ced1 in a Debug simulator build, with lldb stopped at the composer's attachment menu getter during the first composer draw, summing frame sizes on the main thread:

Stack depth at the attachment menu Frames
main 959,744 bytes 162
with this change 299,808 bytes 204
  • The simulator's main thread has 8 MB of stack, which is why this never shows there. An iPhone's main thread has 1,032,192 bytes.
  • How close main is: on a local branch that added two thin wrapper views to the composer, the same measurement read 993,120 bytes and a Debug build on a physical iPhone crashed on its first frame with a main-thread stack overflow (SIGSEGV in the stack guard) while the Swift runtime resolved opaque view types under the attachment menu getter. With the same section view applied there (where it also replaced the two wrappers) the measurement was 249,280 bytes and the app launched. That branch is not part of this PR.
  • Shared kit suite on this head (on main c1b9f4ec91e; it also merges cleanly with c2e6410cd6c, not retested there): 2287 tests in 194 suites passed. SwiftFormat lint clean on the changed file.
  • Not measured: Release builds (optimized frames are far smaller), macOS, and stack depth at other points in the composer.
  • Local toolchain note: Xcode 26.6 / Swift 6.3.3 crashes in the compiler on a method reference passed as a Binding setter in ChatSessionSidebarPages.swift, a file this PR does not change (the same crash occurs on unmodified main). Local runs used an uncommitted one-line workaround in that file to build; CI builds the unmodified tree.

AI-assisted (Claude).

Debug builds keep every nested `some View` temporary on the stack, and the
composer is one chain of nested getters. Measured in a Debug simulator build at
the composer attachment menu, main used 959,744 bytes of main-thread stack; an
iPhone's main thread has 1,032,192. Two closure-backed section views split the
chain and bring the same measurement to 299,808 bytes.
@clawsweeper

clawsweeper Bot commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Oct 5, 2026
@clawsweeper

clawsweeper Bot commented Oct 5, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed October 5, 2026, 5:25 AM ET / 09:25 UTC.

ClawSweeper review

What this changes

The shared native chat composer evaluates its content and editor in separate SwiftUI view bodies to reduce stack use in Debug builds.

Merge readiness

✅ Ready for maintainer review

The PR remains useful: current main still evaluates the composer subtrees inline, and no canonical replacement was found. The narrow patch has no actionable correctness findings and includes real simulator measurements supporting the stack reduction.

Priority: P2
Reviewed head: 3f83cf82f7256aea6f6ab3e956e916a5c59183ea

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused patch with meaningful production-path measurements, appropriately disclosed limitations, and no actionable review findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The captured PR body reports before/after LLDB stack measurements through the real Debug simulator composer draw, directly exercising the two changed rendering boundaries and showing a reduction from 959,744 to 299,808 bytes. Separate-branch iPhone launch recovery is supplemental; Release and macOS behavior are not claimed as measured. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The captured PR body reports before/after LLDB stack measurements through the real Debug simulator composer draw, directly exercising the two changed rendering boundaries and showing a reduction from 959,744 to 299,808 bytes. Separate-branch iPhone launch recovery is supplemental; Release and macOS behavior are not claimed as measured. No stored-data contract changes.
Evidence reviewed 8 items Introduced patch: The pinned introduction delta adds a closure-backed SwiftUI view and uses it at the composer-content and editor boundaries. Existing padding, background, overlay, bindings, and action callbacks remain in place; the complete changed module was inspected.
Current-main necessity: Fetched current main still directly evaluates composerContent and editorContent at both changed boundaries. The branch's rendering separation is therefore absent from current main.
Verified merge result: Raw test-merge parent records match the pinned base followed by the exact PR head. Comparing that merge result with its base reproduces only the composer patch, rather than removing the unrelated base-branch changes.
Findings None None.
Security None None.

How this fits together

The shared native chat composer turns session state, draft text, and attachment controls into the input area used by Apple clients. This change splits rendering evaluation while preserving the existing input bindings and action callbacks.

flowchart TD
  A[Session and draft state] --> B[Native chat composer]
  B --> C[Composer content view body]
  C --> D[Editor view body]
  C --> E[Attachment and toolbar controls]
  D --> F[Rendered chat input]
  E --> F
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Other +10. Total +10 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 1 12 2 +10
Total 1 12 2 +10

Review metrics

Metric Value Why it matters
Reported Debug stack reduction 959,744 → 299,808 bytes; approximately 69% lower The contributor measured the changed production rendering path at the same attachment-menu breakpoint.

Technical review

Best possible solution:

Keep rendering evaluation bounded through the two lightweight view bodies while retaining the composer's existing state and input owners.

Do we have a high-confidence way to reproduce the issue?

No exact current-main device crash was reproduced in this review. The contributor provides a concrete Debug rendering measurement, while the actual device crash required additional wrappers on a separate local branch.

Is this the best way to solve the issue?

Yes: separating evaluation into two SwiftUI bodies is a focused repair that preserves the existing view contents, modifier placement, bindings, and state ownership.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 10080eaf91bc.

Labels

Label changes:

  • add P2: This addresses measured stack pressure in native Debug builds, with no demonstrated impact on optimized released builds.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The captured PR body reports before/after LLDB stack measurements through the real Debug simulator composer draw, directly exercising the two changed rendering boundaries and showing a reduction from 959,744 to 299,808 bytes. Separate-branch iPhone launch recovery is supplemental; Release and macOS behavior are not claimed as measured. No stored-data contract changes.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured PR body reports before/after LLDB stack measurements through the real Debug simulator composer draw, directly exercising the two changed rendering boundaries and showing a reduction from 959,744 to 299,808 bytes. Separate-branch iPhone launch recovery is supplemental; Release and macOS behavior are not claimed as measured. No stored-data contract changes.

Label justifications:

  • P2: This addresses measured stack pressure in native Debug builds, with no demonstrated impact on optimized released builds.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The captured PR body reports before/after LLDB stack measurements through the real Debug simulator composer draw, directly exercising the two changed rendering boundaries and showing a reduction from 959,744 to 299,808 bytes. Separate-branch iPhone launch recovery is supplemental; Release and macOS behavior are not claimed as measured. No stored-data contract changes.
  • proof: sufficient: Contributor real behavior proof is sufficient. The captured PR body reports before/after LLDB stack measurements through the real Debug simulator composer draw, directly exercising the two changed rendering boundaries and showing a reduction from 959,744 to 299,808 bytes. Separate-branch iPhone launch recovery is supplemental; Release and macOS behavior are not claimed as measured. No stored-data contract changes.

Evidence

What I checked:

  • Introduced patch: The pinned introduction delta adds a closure-backed SwiftUI view and uses it at the composer-content and editor boundaries. Existing padding, background, overlay, bindings, and action callbacks remain in place; the complete changed module was inspected. (apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatComposer.swift:71, 3f83cf82f725)
  • Current-main necessity: Fetched current main still directly evaluates composerContent and editorContent at both changed boundaries. The branch's rendering separation is therefore absent from current main. (apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatComposer.swift:278, 10080eaf91bc)
  • Verified merge result: Raw test-merge parent records match the pinned base followed by the exact PR head. Comparing that merge result with its base reproduces only the composer patch, rather than removing the unrelated base-branch changes. (apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatComposer.swift:288, 83b4a37c74af)
  • Contributor runtime evidence: The complete captured PR body reports LLDB measurements during the first composer draw in a Debug simulator build: 959,744 bytes before versus 299,808 bytes with the two view boundaries. This exercises the production rendering path and supports the stack-reduction claim. The physical-iPhone crash/recovery example used a separate local branch and is supplemental, not exact-head device verification. The disclosed unrelated compiler workaround and unmeasured Release/macOS paths limit the claims appropriately.
  • Entry point and existing pattern: ChatView supplies the composer with the current view model, enablement, and input resolver. Existing shared UI also uses closure-backed View content, including ChatAssistantRunFrame; the new helper introduces no parallel input or state owner. (apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatView.swift:376, 3f83cf82f725)
  • Relevant merged history: Current-main history shows repeated shared-composer work by Peter Steinberger and a prior merged iOS image-paste repair by Marvinthebored. These support routing relevance without establishing who introduced the stack pressure. (apps/shared/OpenClawKit/Sources/OpenClawChatUI/ChatComposer.swift, 10080eaf91bc)

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Marvinthebored: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

@chessing234 chessing234 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed commit 3f83cf82f7256aea6f6ab3e956e916a5c59183ea.

Inspected the SwiftUI composer extraction, bindings, and modifiers. No actionable correctness issue found.

Validation: static source review only; runtime tests were not run. This review makes no assertion that CI or platform tests pass.

@Patrick-Erichsen Patrick-Erichsen self-assigned this Oct 5, 2026
@Patrick-Erichsen

Copy link
Copy Markdown
Contributor

Reviewed exact head 3f83cf82f7256aea6f6ab3e956e916a5c59183ea against current main f753f73acdf1cedf618898c4719c7c0840b3cad2; the composer owner remains unchanged on main.

The two internal closure-backed bodies defer construction while keeping existing state, draft bindings, focus, actions and modifier order in their original owners. Production +12/-2 (net +10) supplies those two construction boundaries; tests are unchanged. Full owner/caller/sibling source review found no introduced P0–P2 defect. Fresh AutoReview is scoped-clean; its sandbox lacked the owner files, so that pass is contextual and supplements the independent full-source review.

I inspected the actual native CI run37289222143: Xcode27 Debug, integration merge 83b4a37c74afad0883fd520148e2d5a7a411f4d1 containing this exact PR head. The real iPhone flow renders, focuses, types/asserts, clears and dismisses the keyboard; the iPad snapshot job passes too. All four downloaded screenshot hashes match the manifest, and I inspected the connected-chat image. Skipped build placeholders are not counted as executed tests.

The reported numeric stack reduction, 2287-test local suite with its unrelated compiler workaround, and physical-device recovery on a different branch remain author-reported. I do not claim an independently measured stack improvement or exact-head physical-device recovery. Direct SwiftUI construction-contract evidence plus the observed native Debug rendering/input flow supports this bounded preparation; required native gates and clean mergeability remain prerequisites to landing.

The latest completed ClawSweeper review has no actionable findings or Rank-up moves. It is older than twelve hours, so @clawsweeper re-review. A refreshed publisher result is requested; no approving GitHub review or automatic merge is being submitted.

@Patrick-Erichsen
Patrick-Erichsen merged commit 04fdb54 into openclaw:main Oct 5, 2026
81 checks passed
@Patrick-Erichsen

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 6, 2026
…aw#165472)

Debug builds keep every nested `some View` temporary on the stack, and the
composer is one chain of nested getters. Measured in a Debug simulator build at
the composer attachment menu, main used 959,744 bytes of main-thread stack; an
iPhone's main thread has 1,032,192. Two closure-backed section views split the
chain and bring the same measurement to 299,808 bytes.

Co-authored-by: Marvinthebored <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: XS status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants