Skip to content

fix(mobile): backfill older exchanges a byte-trimmed history tail dropped - #839

Merged
huichen merged 3 commits into
mainfrom
fix/history-gap-trim
Sep 25, 2026
Merged

huichen merged 3 commits into
mainfrom
fix/history-gap-trim

Conversation

@huichen

@huichen huichen commented Sep 25, 2026

Copy link
Copy Markdown
Collaborator

问题

工具调用密集型会话里,如果最近的若干 exchange 序列化后超过桌面 bridge 的 512KB 单页预算,bridge 会把最新一页历史整段裁到只剩最新的 exchange(shed whole oldest exchanges,把游标推过被裁掉的行)。

被裁掉的 exchange 只有在用户手动向上翻页时才会回来。于是:

  • 发一条新消息 → 触发 refresh → 重新读同一个被裁的 tail 页 → 之前所有消息「看着被吃掉」,只剩最新那条 + 刚发的;
  • 杀 App 重进 → 冷启动同样读这个被裁的 tail → 还是一样。

报告会话(20260925-171247):单 exchange ~531KB,tail 页 1.1MB → 裁到 161KB。数据库里 687 条记录完好,无 compaction。

根因

裁剪发生在 bridge 的 prepare_backward_entries_page_with_cap。mobile 的 loadHistory 读到被裁的 tail 后直接提交,不知道「窗口本该有 3 个 exchange,是裁剪让它只剩 1 个」,于是把缺失的 exchange 留给了手动翻页。

修复

  • bridge 在被裁剪的页上显式标记 "trimmed": true;
  • loadHistory 只在收到 trimmed 标记时,向前 backfill 完整的旧 exchange,直到窗口凑满应有的 exchange 数或 journal 读尽。明确 trim 的页才补——天然短的会话不会触发额外读。backward 预算只裁最新页,所以 backfill 读到的是完整 exchange。

复现

新增测试用按真实字节预算的 bridge 模型:7 个 exchange、每个都超预算的 journal,冷启动 + 发消息后 refresh。修复前 refresh 只渲染最新 exchange + 新 run;修复后所有 exchange 都保留。

测试

  • mobile useTimelineController: 87/87 通过(含新复现测试)
  • desktop wire_limits / history Rust 测试通过,clippy + fmt 干净

…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
huichen enabled auto-merge (squash) September 25, 2026 14:07
@huichen
huichen merged commit 6f048c2 into main Sep 25, 2026
12 checks passed
@huichen
huichen deleted the fix/history-gap-trim branch September 25, 2026 14:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant