HTML Notes Processing#
Meeting notes fetched from Google Calendar and Outlook often contain HTML markup. MeetingBar strips that markup in two separate pipelines:
- Notes display —
String.htmlTagsStripped()inMeetingBar/Extensions/String.swiftconverts HTML notes to plain text before showing them in the menu. - Link detection —
htmlTagsStrippedForMeetingLinks(_:)inMeetingBar/Meetings/MeetingLinkDetector.swiftstrips HTML so the regex engine can match meeting URLs embedded inside tagged notes. The stripped result is probed as astrippedHTMLNotescandidate, which has a lower source priority (20) than rawnotes(30).
The NSAttributedString(html:) Leak (Root Cause)#
Both call sites historically used NSAttributedString(html: dataUTF16, options: [.documentType: .html], ...) to do the conversion . That initializer routes work through Apple's com.apple.textkit.nsattributedstringagent XPC service.
The problem: each call opens a new XPC connection and leaks ~2 Mach ports that are never reclaimed. Because link detection runs on every calendar refresh for every event with HTML notes, the process Mach port table grows unboundedly. The kernel eventually kills MeetingBar with EXC_GUARD ("allocating too many mach ports") — observed in the field at 305,834 ports.
This exact nsattributedstringagent connection flood is visible in system logs immediately after each EventKit CADEventPredicate activity:
[com.apple.xpc:connection] activating connection: … name=com.apple.textkit.nsattributedstringagent
[com.apple.xpc:connection] activating connection: … name=com.apple.textkit.nsattributedstringagent
… (repeated per event per refresh)
The root cause traces back to PR #144 and was present in the 5.0 codebase unchanged from the 4.11 rewrite.
The Fix: HTMLPlainText (PR #953)#
PR #953 ("Strip HTML notes without leaking mach ports") replaces both NSAttributedString(html:) call sites with a pure-Foundation stripper, HTMLPlainText, implemented inside MeetingLinkDetector.swift so both the logic target and the app binary share it without any XPC involvement.
HTMLPlainText behavior:
- Block-level tags (
<p>,<div>,<br>, etc.) become newlines; all other tags are removed. <script>and<style>element bodies are stripped entirely.- HTML entities are decoded: all numeric forms (
{/{) and a named table covering the five XML names, common symbols, and the full Latin-1 accented-letter set (e.g.,café,München). Named entities outside the table are left as written. - Regexes are precompiled as static
NSRegularExpressioninstances to avoid per-call recompilation overhead. - Entity scanning is bounded to prevent runaway work on malformed input.
After the fix: no nsattributedstringagent connections appear in the log, and the Mach port count stays flat across repeated strip calls.
One behavior change: the notes-display path now decodes numeric + Latin-1/common named entities instead of the full HTML named set. Rare named entities that aren't in the table show as written (e.g., ) rather than decoded.
Icon-Cache Growth & App Termination#
The Mach port leak is compounded by icon-cache growth: each XPC connection may cause TextKit to cache rendering resources. Over long uptime sessions with many HTML-noted events, both the port table and memory usage climb. The kernel-level kill via EXC_GUARD / port-space exhaustion is the terminal failure mode. Issues #716, #721, #872, and #888 are all linked to this same nsattributedstringagent signature.
Key Files#
| File | Role |
|---|---|
MeetingBar/Extensions/String.swift | String.htmlTagsStripped() — notes display path |
MeetingBar/Meetings/MeetingLinkDetector.swift | htmlTagsStrippedForMeetingLinks(), HTMLPlainText, link detection pipeline |
MeetingBarLogicTests/MeetingLinkDetectorTests.swift | Mach port leak regression test (400-iteration port-count check) |
MeetingBarTests/HelpersTests.swift | cleanUpNotes behavioral tests |
Related Redirect Cleanup#
HTML notes from Google Calendar often wrap links in google.<tld>/url?q=<encoded> redirects. cleanupGoogleRedirects(rawText:) unwraps these in a bounded loop (max 32 passes for nesting depth) before the regex engine runs. Similarly, cleanupOutlookSafeLinks(rawText:) unwraps Outlook SafeLink wrappers. Both guards prevent infinite loops on malformed input. These redirect cleanups run independently of and before HTML stripping in the candidate-collection path.