Repository navigation
fix(mobile): backfill older exchanges a byte-trimmed history tail dropped - #839
Merged
Merged
Conversation
…pped
A tool-dense session whose recent exchanges exceed the desktop bridge's
512KB page budget had its newest history page trimmed to a single exchange
(the bridge sheds whole oldest exchanges to fit one reply, advancing the
cursor past them). Those shed exchanges only ever reappeared if the user
manually paged up — after sending a message, the refresh re-read the same
trimmed tail, so the conversation rendered as if everything before the
latest exchange had been eaten, and a cold app restart showed the same
collapsed window.
The bridge now marks a page it trimmed ("trimmed": true), and loadHistory
backfills whole older exchanges until the window holds its full exchange
count or the journal runs out — but only for an explicitly trimmed page,
so a genuinely short session triggers no extra reads. The backward byte
budget only trims the newest page, so the backfill reads return complete
exchanges.
Reproduced with a byte-accurate bridge model: a 7-exchange journal where
each exchange clears the budget, opened cold then refreshed after a send —
before the fix the refresh rendered only the newest exchange plus the new
run; after it, all exchanges survive.
huichen
enabled auto-merge (squash)
September 25, 2026 14:07
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
工具调用密集型会话里,如果最近的若干 exchange 序列化后超过桌面 bridge 的 512KB 单页预算,bridge 会把最新一页历史整段裁到只剩最新的 exchange(shed whole oldest exchanges,把游标推过被裁掉的行)。
被裁掉的 exchange 只有在用户手动向上翻页时才会回来。于是:
报告会话(20260925-171247):单 exchange ~531KB,tail 页 1.1MB → 裁到 161KB。数据库里 687 条记录完好,无 compaction。
根因
裁剪发生在 bridge 的
prepare_backward_entries_page_with_cap。mobile 的loadHistory读到被裁的 tail 后直接提交,不知道「窗口本该有 3 个 exchange,是裁剪让它只剩 1 个」,于是把缺失的 exchange 留给了手动翻页。修复
"trimmed": true;loadHistory只在收到trimmed标记时,向前 backfill 完整的旧 exchange,直到窗口凑满应有的 exchange 数或 journal 读尽。明确 trim 的页才补——天然短的会话不会触发额外读。backward 预算只裁最新页,所以 backfill 读到的是完整 exchange。复现
新增测试用按真实字节预算的 bridge 模型:7 个 exchange、每个都超预算的 journal,冷启动 + 发消息后 refresh。修复前 refresh 只渲染最新 exchange + 新 run;修复后所有 exchange 都保留。
测试
useTimelineController: 87/87 通过(含新复现测试)wire_limits/historyRust 测试通过,clippy + fmt 干净