Skip to content

perf(imessage): skip unused inline-code projection - #139912

Merged
steipete merged 2 commits into
mainfrom
codex/perf52-imessage-no-code
Sep 6, 2026
Merged

steipete merged 2 commits into
mainfrom
codex/perf52-imessage-no-code

Conversation

@steipete

@steipete steipete commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

iMessage formatting performs a second attributed-text render to recover inline-code markers even when a reply contains no inline code. It then rebuilds text and native-style offsets despite having no marker edits. The final outbound sanitizer also pays this cost when inspecting rendered projections.

Why This Change Was Made

Skip the code-only render when the parsed representation has no inline-code spans, and return the current text and freshly prepared native ranges when there are no code-marker edits. Construct fallbacks can shift or remove inline-code spans but do not create them. The native-style and code-style renders remain separate to preserve range compaction order. The change adds three production lines and leaves sanitizer policy, verification stages, and limits untouched.

User Impact

Replies without inline code avoid unnecessary formatting work while retaining identical visible text and native styles. Inline-code messages keep the existing marker restoration path. No appearance or transport-contract change is intended.

Evidence

At base 2239858f4dfd0de769e9d80b2f0b3f5452be2b05, fixed baseline/candidate verification followed by B0/C0/C1/B1 measured 42 formatter and full-sanitizer cases. All 44,604 outcomes were saved before assertions and matched complete baseline text/ranges, with independent UTF-16 boundary checks. Plain text, Unicode, native styles, links, lists, headings, fences, dense inline code and raw-sanitizer routes were retained.

Case Forward median µs Reverse median µs
Plain short text, formatter 7.842 → 5.805 (25.98% lower) 7.799 → 6.525 (16.34% lower)
Dense native styles, formatter 280.573 → 245.428 (12.53% lower) 281.116 → 247.906 (11.81% lower)
Dense native styles, full sanitizer 1644.576 → 1599.661 (2.73% lower) 1649.353 → 1606.275 (2.61% lower)

Results are not uniformly faster: 35/84 median comparisons were slower. The largest absolute median increase was full-sanitizer dense inline code, +30.544 µs (+1.50%) in reverse order; the largest relative increase was fenced-only extraction, +1.073 µs (+26.82%) in reverse order. Raw-sanitizer rows remain route controls because their security projection also invokes the formatter. All adverse samples and process resources were retained; no universal speedup or Gateway/delivery-latency claim is made.

Normal focused tests passed 386/386: formatter 23, send 90, monitor behavior 273, including the existing sanitizer cases. Managed P2 review was scoped-clean, exit 0. No new test-only seam or redundant call-count test was added. All 24 normal changed checks passed, including five doctor-contract tests, plugin and plugin-test typechecks, lint and boundary guards. The native owner confirmed closure with no problems in 205.62 seconds under the predeclared resource bounds. No build or live iMessage send is claimed.

Before publication, the unchanged formatter patch was merged with current main, including upstream #139894's unrelated browser-fixture isolation repair. Formatter SHA remains 6d51d9f614874d4bc9b10675d0705355146c548304bb811e94887048cede1848; all previous measurements and tests retain their original base attribution. Fresh hosted CI is required for the composed head.

The first CI run reached a Knip provisioning failure: pnpm dlx could not import its native parser binary from the CI store (ENOENT). This was not an iMessage assertion or lockfile finding. One retry of failed jobs on the unchanged head completed successfully; required CI is green. The original failed log remains retained. No source changes or numerical reruns were used for that retry.

@clawsweeper

clawsweeper Bot commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added channel: imessage Channel integration: imessage size: XS maintainer Maintainer-authored PR labels Sep 6, 2026
@steipete
steipete marked this pull request as ready for review September 6, 2026 07:58
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 Sep 6, 2026
@clawsweeper

clawsweeper Bot commented Sep 6, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 6, 2026, 4:03 AM ET / 08:03 UTC.

ClawSweeper review

What this changes

The iMessage formatter skips inline-code rendering and offset reconstruction when no code markers need restoration, preserving outgoing text and native styles.

Merge readiness

✅ Ready for maintainer review

This remains a useful, bounded optimization absent from the inspected main and latest release. No introduced correctness defect was found; the maintainer-authored PR should proceed through normal review.

Priority: P3
Reviewed head: 3d38555ef8b8ff904ae6617dc527c4c2b4fd3fbb

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused optimization with a source-supported invariant, relevant existing coverage, and candidly bounded performance evidence.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored exemption applies. The captured body reports formatter and full-sanitizer equivalence and timing measurements for the unchanged formatter blob; it explicitly claims no live iMessage send.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored exemption applies. The captured body reports formatter and full-sanitizer equivalence and timing measurements for the unchanged formatter blob; it explicitly claims no live iMessage send.
Evidence reviewed 9 items Verified introduced patch: The pinned merge-base-to-head diff contains only the two formatter fast paths. The supplied verified test merge likewise changes only this formatter relative to its main parent.
Fast-path invariant: Construct projection can synthesize bold headings, retain or remove existing styles, and shift spans around text edits; it does not synthesize inline-code styles. Attributed rendering obtains code ranges only from those projected styles. Returning the freshly mapped native ranges when codeRanges is empty preserves the previous zero-shift result.
Production boundary and sanitizer: The final outbound sanitizer calls the formatter both for formatted messages and recursively inspected projections. Role verification and projection limits remain outside the optimized helper and unchanged.
Findings None None.
Security None None.

How this fits together

The iMessage plugin converts Markdown replies into text and native formatting ranges before sending them through imsg. Its outbound sanitizer also invokes this formatter while inspecting rendered text.

flowchart LR
  A[Markdown reply] --> B[Parse text and styles]
  B --> C[Render native formatting]
  B --> D{Inline code present?}
  D -->|Yes| E[Restore code markers]
  D -->|No| F[Keep text and ranges]
  C --> E
  C --> F
  E --> G[Outbound sanitizer]
  F --> G
  G --> H[iMessage transport]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +3. Total +3 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 1 9 6 +3
Tests 0 0 0 0
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 9 6 +3

Review metrics

Metric Value Why it matters
Reported performance tradeoff 35/84 median comparisons slower The measurements support a targeted reduction in unnecessary formatter work, not a universal speedup or delivery-latency claim.

Technical review

Best possible solution:

Keep the local fast paths while preserving separate native-style and code-style rendering and the existing sanitizer checks.

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

Not applicable as a behavioral bug: source confirms the redundant work, while the supplied benchmarks quantify its cost; no runtime execution was performed in this review.

Is this the best way to solve the issue?

Yes. The guards follow the existing projection invariant and avoid unnecessary work without combining renderers, changing public APIs, or weakening sanitization.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a small internal performance optimization with no intended change to visible messages or transport behavior.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored exemption applies. The captured body reports formatter and full-sanitizer equivalence and timing measurements for the unchanged formatter blob; it explicitly claims no live iMessage send.

Label justifications:

  • P3: This is a small internal performance optimization with no intended change to visible messages or transport behavior.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored exemption applies. The captured body reports formatter and full-sanitizer equivalence and timing measurements for the unchanged formatter blob; it explicitly claims no live iMessage send.

Evidence

What I checked:

  • Verified introduced patch: The pinned merge-base-to-head diff contains only the two formatter fast paths. The supplied verified test merge likewise changes only this formatter relative to its main parent. (extensions/imessage/src/markdown-format.ts:57, 3d38555ef8b8)
  • Fast-path invariant: Construct projection can synthesize bold headings, retain or remove existing styles, and shift spans around text edits; it does not synthesize inline-code styles. Attributed rendering obtains code ranges only from those projected styles. Returning the freshly mapped native ranges when codeRanges is empty preserves the previous zero-shift result. (packages/markdown-core/src/construct-fallbacks.ts:29, 3d38555ef8b8)
  • Production boundary and sanitizer: The final outbound sanitizer calls the formatter both for formatted messages and recursively inspected projections. Role verification and projection limits remain outside the optimized helper and unchanged. (extensions/imessage/src/monitor/sanitize-outbound.ts:589, 3d38555ef8b8)
  • Existing behavior coverage: The existing formatter suite checks unchanged plain text, nested native styles, UTF-16 offsets, mixed inline code, multi-backtick delimiters, fenced code, and reference links. It was inspected, not executed during this read-only review. (extensions/imessage/src/markdown-format.test.ts:44, 3d38555ef8b8)
  • Current main still performs the extra work: The fetched main formatter still unconditionally performs the code-only render and reconstructs ranges for empty code ranges. This optimization remains distinct work. (extensions/imessage/src/markdown-format.ts:112, bc7c52983c80)
  • Latest release comparison: The formatter at v2026.9.2 also lacks these fast paths; no shipped implementation of this optimization was established. (extensions/imessage/src/markdown-format.ts:112, 3928bad9badf)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Vincent Koc: 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.

@steipete
steipete merged commit d613fee into main Sep 6, 2026
219 of 221 checks passed
@steipete
steipete deleted the codex/perf52-imessage-no-code branch September 6, 2026 09:09
@steipete

steipete commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: imessage Channel integration: imessage maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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.

1 participant