Repository navigation
fix(mobile): truncate oversize markdown reads instead of failing them - #23676
Conversation
The desktop bridge refused markdown over a private 512 KiB cap with file_too_large, which reached the phone as a generic runtime_error that the reader discarded, so a 632 KB file showed "Couldn't load markdown". Reads now return a UTF-8-boundary prefix under one shared 2 MiB budget, marked truncated with the full byteLength and read-only. The phone shows the truncation like file tabs do and maps refusal codes to real copy, so an older desktop's refusal reads "File too large for mobile preview". Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
The read budget sits above the edit budget, so every truncated document is already read-only as file_too_large. Pin that ordering so a future budget change cannot make a prefix editable, and name the constant as the markdown preview budget, separate from the file preview's own. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
A phone holding a truncated prefix must not write it back; the 256 KiB save guard refuses it as file_too_large before any version check. The shared budget test shrinks to the ordering it pins and names the bridge test as the behavioural pin. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
|
Navigate logical layers of code changes, visualize relationships, and explore their blast radius. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (5)
🚧 Files skipped from review as they are similar to previous changes (1)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthroughMobile Markdown reads now allow content up to 2 MiB and truncate larger documents at a UTF-8 boundary. Truncated responses carry the full byte length through mobile document state and disk fallback. The reader displays status text for truncation, read-only state, stale state, or save errors. Preview failures use specific messages for binary files and files that exceed the mobile preview limit. Priority: ➖ Normal Merge Risk: 🟡 Moderate · up to An oversized Markdown document can still be replaced through a save request even though mobile presents it as read-only. Prevent that replacement before merging. Security Architecture ReviewSecurity architecture risk: 🟡 Moderate · up to Large Markdown files now open as read-only previews, but a client able to send its own save request may be able to replace some files despite that read-only designation. The exposure is limited to an accessible open Markdown tab; the normal phone interface disables saving. Retained concerns
Security review detailsSecurity Blast Radius
Security Findings and Attack Paths
Trust Boundaries and Controls
Resilience and Maintainability Implications
Hardening Proposals
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
Full details: Description checkExplanation The description gives a detailed explanation of the problem, cause, fix, compatibility impact, and tests. However, it omits several required template sections, including Linked Issue, Visual Proof or an explicit N/A explanation, AI Disclosure, Review, Agent skill upstream boundary, Notes, and Checklist. Resolution Add the missing template sections. Include a linked issue under “Linked Issue,” provide before/after visual proof or write ✨ Finishing Touches 💡 1📝 Generate docstrings 💡
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟠 Major · Reject saves based on the current document size. · mobile-markdown-bridge.ts:97-104
src/renderer/src/runtime/mobile-markdown-bridge.ts:97-104
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy liftReject saves based on the current document size.
For a document over 2 MiB, a save request containing at most 256 KiB passes both size checks because they inspect the submitted
content. IfbaseVersionmatches the full document, the request can replace the truncated document with that short content. If the request uses the returned prefix version, it reportsconflictinstead of the requiredfile_too_large. AfterreadCurrentContent, reject an oversized current document before the version and duplicate-save checks.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Advanced
Run ID: 8b96e7fd-d75a-4827-a609-a148abc3b434
📒 Files selected for processing (14)
mobile/src/session/MobileSessionMarkdownReader.tsxmobile/src/session/mobile-markdown-disk-fallback.test.tsmobile/src/session/mobile-markdown-disk-fallback.tsmobile/src/session/mobile-markdown-reader-status.test.tsmobile/src/session/mobile-markdown-reader-status.tsmobile/src/session/mobile-session-route-parity.test.tsmobile/src/session/mobile-session-route-types.tsmobile/src/session/session-read-reply-schema.tsmobile/src/session/use-mobile-session-document-readers.test.tsmobile/src/session/use-mobile-session-document-readers.tssrc/renderer/src/runtime/mobile-markdown-bridge.test.tssrc/renderer/src/runtime/mobile-markdown-bridge.tssrc/shared/mobile-markdown-document.test.tssrc/shared/mobile-markdown-document.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 6 remain after this review.
The read truncation measures the document once. The disk fallback drops its truncated-only read-only text, which the status line never showed, and both truncation fields are optional there. A markdown doc's flag is only ever true, and the schema comment names the hook, not line numbers. Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — a mobile markdown read over the old private 512 KiB cap no longer fails; the host returns a UTF-8-boundary prefix marked truncated, and the phone renders a size note instead of the generic error.
- Shared read budget:
MOBILE_MARKDOWN_READ_MAX_BYTES(2 MiB) added beside the 256 KiB edit cap, withtruncateMobileMarkdownReadreturning either the whole document or aclampUtf8TextPrefixprefix plus the full byte length. - Bridge:
readMobileMarkdownTabtruncates rather than throwingfile_too_large, hashes the prefix forversion, and forwards optionaltruncated/byteLength; the private cap and its throw were removed fromreadFileContent. - Mobile reader:
session-read-reply-schemaaccepts the two optional fields, the ready state carries them, and the disk fallback propagatesbyteLength. - Status line: the inline status logic moved to
markdownReaderStatusText, which shows "Preview truncated. File size: X." (the file tab's wording and formatter) ahead of "Read only". - Refusal mapping: markdown and file tabs share
documentReadErrorMessage, sobinary_file/file_too_largeget real copy and only unknown errors keep their fallback. - Tests: red-first bridge tests (a 632 KB read now succeeds, an over-budget read is cut on a UTF-8 boundary, a save of the prefix is refused), reader tests for an old desktop's refusal and truncation propagation, status precedence, plus a re-pinned route-parity hash and string count.
I traced the save path for data loss and found none: truncated implies over MOBILE_MARKDOWN_EDIT_MAX_BYTES, so the document is never editable, the mobile save action returns early on !editable, and a save carrying the prefix hash conflicts against the full-file hash. Mixed-version behavior matches the described compatibility story. All changed suites, pnpm tc:web/tc:node, the mobile typecheck, and the changed-code quality gate pass locally.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes — the delta since the prior review (0c34d1e → b0423ab) is a type/behavior refactor plus a doc fix on top of the truncation change.
- Measure once:
truncateMobileMarkdownReadnow computesutf8ByteLength(content)a single time and branches on<= MOBILE_MARKDOWN_READ_MAX_BYTES, replacing the limit check followed by a second full measurement. Same whole/truncated decision, one scan. - Fallback doc typed and simplified:
buildMarkdownDiskFallbackDoctakestruncated?: boolean, returnsExtract<MarkdownDocState, { status: 'ready' }>, and no longer sets a truncated-specificreadOnlyReason— the status line owns that copy, so a truncated disk read still renders "Preview truncated. File size: X.". - Narrowed state:
MarkdownDocState.truncatedtightened frombooleantotrue, matching the only two writers (the reader and the disk fallback), which both assign the literal. - Stale reference dropped: the
session-read-reply-schemaJSDoc's line-range citation was replaced with namedreadMarkdownTab/useMobileSessionDocumentReadersreferences, so it no longer drifts when the reader moves.
Re-ran the mobile typecheck, tc:node, and the four mobile suites plus the shared/renderer suites — all pass.
DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

What
A markdown tab over 512 KiB showed "Couldn't load markdown" on the phone (native and OTA alike) while the desktop displayed the same file fine.
Cause. The desktop renderer's mobile markdown bridge kept a private 512 KiB cap and threw
file_too_largeabove it. That code is not on the RPC passthrough list, so the phone received a genericruntime_error; the markdown disk fallback only reacts torenderer_unavailable, and the reader'scatchdiscarded the error and printed the generic message. The cap arrived with the first mobile markdown editor and had no comment or test.Fix. Refusing is replaced by truncating. One shared budget,
MOBILE_MARKDOWN_READ_MAX_BYTES= 2 MiB (sized like the terminal snapshot budget; the relay splice frame cap is 8 MiB), lives insrc/shared/mobile-markdown-document.tsnext to the existing 256 KiB edit cap. Above it the bridge returns a UTF-8-boundary prefix (existingclampUtf8TextPrefix) withtruncated: trueand the fullbyteLength; the document is read-only through the existingfile_too_largereason, andversionhashes the prefix. The private constant and the throw are gone.On the phone the reply schema accepts the two optional fields, the reader status line says "Preview truncated. File size: X." (same wording and formatter as file tabs; before this any read-only reason showed only "Read only"), and markdown and file tabs share one refusal mapper so
binary_file/file_too_largeget real copy and only unknown errors keep the generic message.Compatibility. No new params; the result gains two optional fields sent only when truncated. An older desktop still refuses, and the new phone now shows "File too large for mobile preview" instead of the generic message. An older phone ignores the fields. Host-local; nothing crosses the SSH boundary. The file preview path keeps its own 512 KiB truncation (syntax-highlighted on the phone, different cost).
Tests (red first)
expected { ok: false } to match { ok: true }before); a read between the edit and read budgets returns whole and read-only with notruncatedfield; a read over budget is cut on a UTF-8 boundary,editable: false,readOnlyReason: 'file_too_large',truncated: true, fullbyteLength.runtime_errorwith messagefile_too_largerenders "File too large for mobile preview"; a truncated reply publishestruncated/byteLengthinto the ready state.