| 1 | # Markdown streaming follow-up |
| 2 | |
| 3 | Branch `native/markdown-streaming`, based on main at `3589c220`. This report |
| 4 | includes the follow-up to Fable's review of `b533757b`. |
| 5 | |
| 6 | ## Message lifetime and large replies |
| 7 | |
| 8 | A session owns a `MarkdownTranscript`, keyed by message identity. Each message |
| 9 | has one background parsing worker. Appended deltas replace the pending request |
| 10 | without cancelling the in-flight parse. Every finished prefix publishes before |
| 11 | the worker parses the latest pending revision. Intermediate revisions do not |
| 12 | queue. Small replies still render synchronously; cached revisions include the |
| 13 | account origin, message ID, exact text and draft/completed state. |
| 14 | |
| 15 | SwiftUI hosts borrow the message's renderer. Disappearance, scrolling and |
| 16 | re-hosting do not stop it. Removing a message from the feed or a snapshot stops |
| 17 | its worker, as does leaving the session. Cancellation and a generation check |
| 18 | reject late results. A completed message settles its final parse, then the |
| 19 | worker exits. Replacing a message's source starts fresh. |
| 20 | |
| 21 | The original 64 KiB test streams 67 updates at 5 ms intervals. The old |
| 22 | cancel-on-delta implementation showed only one distinct height before the |
| 23 | stream ended. The regression requires at least six. A delayed-parser test checks |
| 24 | that prefixes publish, only one parse runs, appends cause no cancellations and |
| 25 | the final completed tree is exact. A deterministic held-parse test sends 67 |
| 26 | pending revisions plus completion and requires exactly two parses: the first |
| 27 | prefix and the latest completed revision. |
| 28 | |
| 29 | ## Mac transcript rows |
| 30 | |
| 31 | `LiveTranscript` retains each row and reply host. A row revision includes its |
| 32 | feed item, width, task details, answer/aside feedback and stopping state. |
| 33 | Unchanged revisions receive no content update or intrinsic-size measurement. |
| 34 | Changed replies update their existing host in place; new and removed IDs alone |
| 35 | attach or detach rows. Ordering changes sort existing views without re-hosting. |
| 36 | Height callbacks resize the changed reply and move later rows without rebuilding |
| 37 | their contents. A width change resizes the existing rows. |
| 38 | |
| 39 | Fable's reproduction is covered two ways: a SwiftUI host is repeatedly detached |
| 40 | and reattached across 67 large deltas, and the actual `EquipoMac.LiveTranscript` |
| 41 | runs 49 historical replies plus one 17–25 KB streaming reply. The first test |
| 42 | failed at one height before the fix. The actual transcript now grows throughout |
| 43 | the stream; a focused run saw 10 growing heights (64 with other layout tests |
| 44 | running concurrently). Completion keeps the same row, and removal cancels its |
| 45 | message parser. |
| 46 | |
| 47 | The performance test uses the production Mac transcript inside an `NSWindow`, |
| 48 | with 50 realistic replies. Before the fix, its median update was 723 ms. After |
| 49 | the fix, a debug run measured 3.44 ms median and 5.50 ms maximum. The 50 ms median |
| 50 | budget allows debug/CI variation while rejecting the original full rebuild by |
| 51 | more than an order of magnitude. Timing is paired with deterministic assertions: |
| 52 | exactly one content revision per changed reply, the same row and host identities, |
| 53 | and no window detach/attach notifications. Removal, reinsertion, ordering and |
| 54 | width changes are checked too. |
| 55 | |
| 56 | The Release test (`swift test --package-path native/apple -c release --filter |
| 57 | MacTranscriptTests`) passed: 2.71 ms median, 4.83 ms maximum for the 50-reply |
| 58 | update; the large reply showed 29 growing heights during 67 deltas. This |
| 59 | uses the real transcript class and window layout, with in-memory test accounts; |
| 60 | it is not a signed-in production-app timing session. No personal Keychain or |
| 61 | signing settings were accessed for the harness. |
| 62 | |
| 63 | ## Open code spans |
| 64 | |
| 65 | The first follow-up matched Goldmark's merging of unmatched emphasis delimiters |
| 66 | into watched fallback backtick text, including adjacent closers. This revision |
| 67 | also ends that watched text at a link/image opener. Bracket labels remain |
| 68 | visible while the code span and destination are still open. |
| 69 | |
| 70 | Every streaming cut of the supplied underscore/asterisk examples and |
| 71 | `[text](url)` / `` inside backticks is checked. The fixed-seed grammar |
| 72 | adds links and images inside open code spans, with quote/list prefixes, optional |
| 73 | closers, destinations and random cuts. The expansion found 322 mismatches before |
| 74 | the bracket fix. There are now 3,586 checked-in cases and 32,000 unique generated |
| 75 | inputs: 35,586 comparisons with zero mismatches. Go Render/RenderDraft output |
| 76 | is unchanged. |
| 77 | |
| 78 | ## Verification |
| 79 | |
| 80 | Tests preceded the fixes. Focused checks use: |
| 81 | |
| 82 | ```sh |
| 83 | EQUIPO_MARKDOWN_DIFFERENTIAL="$PWD/native/build/markdown-differential.json" \ |
| 84 | swift test --package-path native/apple \ |
| 85 | --filter 'MacTranscriptTests|MarkdownParsingStreamTests|MarkdownLayoutTests|ChatMarkdownTests' |
| 86 | native/scripts/check-native.sh |
| 87 | ``` |
| 88 | |
| 89 | The earlier commit's nine guards were broken and restored in eleven mutation |
| 90 | runs. All ten re-review guards were also broken and caught: detaching existing |
| 91 | rows, ignoring row revisions, replacing reply hosts, stopping on disappearance, |
| 92 | losing owner identity, omitting cancellation for removed messages, omitting |
| 93 | session-departure cancellation, hiding open-code link labels, omitting snapshot |
| 94 | removal cleanup and omitting feed removal cleanup. Each focused regression |
| 95 | failed, then the guard was restored; none failed to compile or timed out. |
| 96 | |
| 97 | The revision-guard mutation initially stayed within the broad performance |
| 98 | budget; adding the exact content-update count made that unnecessary work |
| 99 | observable independently of machine speed. |
| 100 | |
| 101 | `native/scripts/check-native.sh` passed: fixture freshness and the generated |
| 102 | corpus, strings/parity, reference scan, 167 Swift tests in 20 suites, Mac build |
| 103 | and unsigned iOS Simulator build. The suite retains the existing known Oficina |
| 104 | ID session issue; no new known issue was introduced. The full-suite Mac stream |
| 105 | also grew through 64 sampled heights during 67 deltas. |
| 106 | |
| 107 | Go tests, vet, staticcheck v0.7.0 for `internal/chatmarkdown`, `make fmt-check` and |
| 108 | `go mod tidy -diff` passed with `GOTOOLCHAIN=go1.26.11 CGO_ENABLED=0`, with that |
| 109 | toolchain on PATH. Local evidence is under `native/build/logs/streaming-review-*`. |
| 110 | |
| 111 | ## Remaining scope |
| 112 | |
| 113 | Fable's random-token finished-reply cases involving lone CR, reference |
| 114 | definitions and nested `<` in angle destinations remain deferred. The current |
| 115 | corpus matches, which does not claim those independent counterexamples match. |
| 116 | No product strings or dependency pins changed. Projects awaits its brief. |
| 117 | |