Repository navigation
fix(remote): stop reading a trimmed feed as a broken one - #863
Merged
Merged
Conversation
The lean trim drops whole events, which leaves holes in the `idx` sequence. Three client-side integrity checks still assumed one event per source index, so every one of them rejected a trimmed feed: - `nextEvent` called the jump a gap and reconciled — but reconciling fetches the same trimmed range, so the lane retried forever. That is the sync notice a phone showed above the transcript and could never clear. - `fetchEventsSince`'s snapshot-tail check required `watermark == boundary + events.length`, and `runReconcile` required `watermark == since + events.length`. - The "unknown prefix" (H3) reconcile fired for a run whose first *surviving* frame sits above idx 0 — again for slices the peer is not sending. A trimmed replay page now states how many source events its range held before the trim (`rawEvents`), so the watermark check stays exact instead of being relaxed to "whatever arrived is enough": the raw count proves the tail reached the watermark, and strict ordering within the range still catches a garbled or reordered reply. A page from a peer that trims nothing carries no `rawEvents` and is validated exactly as before, so this is also the boundary for old clients. The live lane needs the peer's answer rather than the page: the client's cursor is told whether this connection agreed to a feed that omits indices (its own `lean_events_v1` ack) and then advances over a hole. A gap verdict is unanswerable by construction when the peer is not sending those slices. Tests cover both directions — a trimmed tail passes with its raw count and is still rejected without one; a jump applies on a feed that omits indices and is still a gap on a feed that does not — and each was falsified by reverting the rule it guards.
huichen
enabled auto-merge (squash)
September 26, 2026 01:23
`npm test` runs jest with `--runInBand`, so a lane left holding its retry timer keeps the process alive after the run: jest prints "did not exit" and then waits forever. CI's Mobile job hung for over an hour on this. A gap verdict schedules that timer, and the "still a gap on an untrimmed feed" test provokes one on purpose. Both new tests now release the engine in a `finally`, the way the neighbouring timer-touching tests already do. Verified with the CI command against a clean tree: `npx jest --runInBand` exits in ~34s; before this it was still running after 200s. Reverting this file alone makes the suite exit again, and so does reverting the source change — the leak was the missing release, not the fix.
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.
What broke
The lean trim (#844) drops whole events, which leaves holes in the
idxsequence. Three client-side integrity checks still assumed one event per source index, so all three rejected a trimmed feed:runCursor.nextEventfetchEventsSincesnapshot tailwatermark == boundary + events.lengthrunReconciletailwatermark == since + events.lengthThe user-visible result on a real phone: during streaming, the transcript sat under "最新内容尚未同步完成,正在重试…" and never cleared — the reconcile could not succeed by construction.
The desktop side already knew this class of hazard:
publish_eventrefuses to drop an oversize event and truncates itsdatainstead, with the comment "so the client's dedup cursor doesn't get a permanent hole". The lean trim dropped events anyway and nothing told the client.The fix
On the wire — a trimmed replay page states how many source events its range held before the trim (
rawEvents). That keeps the watermark check exact rather than relaxed: the raw count proves the tail reached the pinned watermark, and strict ordering plus range bounds still catch a garbled or reordered reply. A page from a peer that trims nothing carries norawEventsand is validated exactly as before.On the live lane — there is no page to annotate, so the client's cursor is told whether this connection agreed to a feed that omits indices (its own
lean_events_v1ack, read through the client ref because the ack lands after the engine is built) and then advances over a hole. A gap verdict is unanswerable when the peer is not sending those slices, so it must not be issued.Verification
npx jest— 128 suites / 2067 tests;tsc --noEmitandeslintclean.remote_host::— 83 passed;cargo fmt --checkandclippy --all-targets -D warningsclean.python3 scripts/docs/check-docs.py— 205 docs OK.Still open (reported, not silently fixed)
The live-lane half trusts the peer's ack instead of a per-event statement. A desktop that trims could also stamp each survivor with how many indices it skipped, which would be verifiable rather than trusted — worthwhile, but a larger wire change than this fix should carry.