Skip to content

fix(mobile): keep older history reachable after a byte-trimmed refresh - #799

Merged
huichen merged 2 commits into
mainfrom
fix/mobile-history-gap
Sep 23, 2026
Merged

huichen merged 2 commits into
mainfrom
fix/mobile-history-gap

Conversation

@huichen

@huichen huichen commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator

问题

在一个本来正常的长会话里追加提问后,移动端只剩最新的提问和回答,前面的内容全部消失,上滑也无法找回。

根因

追加提问触发 timeline 刷新(resend/restart),走 desktop bridge 的 get_session_entries 回拉页。bridge 对超过 512KiB 的回拉页做字节预算截断(prepare_backward_entries_page_with_cap):整段砍掉最旧的对话、把 nextOffset 前移、并始终 hasMore=true。

移动端的 gap-fill 完整性校验(start + entries.length === nextBefore)把这种形状当作游标非法,整个 refresh 抛错失败。失败后 SyncEngine 保留最后一次 commit 的快照——而那个快照只剩 bridge 截断后的 tail(最新一问)。同时分页游标被 abort 污染,loadOlderTimeline 也无法再把旧内容拉回来。

服务端/agent 数据其实一直在(本会话 236 条 display 记录、2 条用户消息都完整),纯是客户端配合 bug。

修复

  1. bridge(desktop/src-tauri):chunked 客户端可显式传 untrimmed: true 跳过回拉页的字节预算截断(chunked 读取本来就分块重组回复,不受单条 512KiB 限制)。
  2. mobile gap-fill(useTimelineController.loadHistory):遇到"flush 校验失败但 hasMore"的 trim 形状时,用 untrimmed 重读同一区间,就地桥接 gap,而不是整个 refresh 失败。
  3. mobile 游标(同文件):retained 游标只在"fresh window 真正并入 retained prefix"(精确衔接或已桥接的 gap)时保留;整窗被替换(restart 改历史)或 tail 越过 retained 页底时,交还给 fresh 游标。

测试

  • 新增 a byte-trimmed gap page re-bridges in place without losing history:模拟 open → loadOlder → 追加提问触发 refresh → 命中截断页,断言旧历史 + 新内容全部保留、游标可继续回拉。
  • mobile 全量 jest:123 suites / 1866 tests 通过。
  • desktop Rust:cargo clippy --all-targets -- -D warnings 干净,cargo test --lib remote 248 通过。

Sending a message in a long session refreshed the timeline through the
desktop bridge, whose 512KiB backward-page budget sheds whole oldest
exchanges and advances the cursor past them. The mobile gap-fill
integrity check (start + entries.length === before) rejected that shape,
failing the whole refresh — the visible conversation collapsed to the
tail, and the stale paging cursor could never rejoin it, so older
questions vanished and could not be scrolled back.

- bridge: a chunked reader may now pass untrimmed to opt out of the
  backward-page byte budget explicitly (it reassembles the reply from
  chunks anyway).
- mobile: on the trimmed shape (flush failure with hasMore), re-read the
  same range untrimmed and bridge the gap from it in the same pass
  instead of throwing.
- mobile: keep the retained paging cursor only while the fresh window
  actually joined the retained prefix (exact join or bridged gap); a
  wholesale-replaced or grown-past window hands paging to its own
  cursor.
@huichen
huichen enabled auto-merge (squash) September 23, 2026 09:44
@huichen
huichen merged commit 0effc59 into main Sep 23, 2026
12 checks passed
@huichen
huichen deleted the fix/mobile-history-gap branch September 23, 2026 09:53
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