Skip to content

fix(app): end timeline scrolls at the live offset - #94

Closed
trmosala wants to merge 5 commits into
CM-Split-v2from
timeline-history-paging
Closed

trmosala wants to merge 5 commits into
CM-Split-v2from
timeline-history-paging

Conversation

@trmosala

Copy link
Copy Markdown
Owner

Summary

Loading older history no longer skips parts when a page's anchor write lands inside the virtualizer's scroll-reset window (#89).

The timeline uses the TanStack virtual-core defaults: no useScrollendEvent, and a 150 ms isScrollingResetDelay. Core observeOffset debounces the end-of-scroll callback cb(offset, false) with the offset stored by the last scroll event, and never re-reads scrollTop.

When a prepend compensation or anchor write moves scrollTop inside that window, and a long task holds the write's own scroll event past the delay, the stale end delivery resets the core scrollOffset. The core callback also zeroes scrollAdjustments. The next page's compensation then works from the stale offset. Its writes land at the stale offset plus the delta, so the parts in between are never mounted.

  • packages/app/src/session/timeline/observe-element-offset.ts: deliver now reports the live element.scrollTop for end-of-scroll (isScrolling = false) deliveries.
    • Deliveries during scrolling are unchanged.
    • This matches the existing places that already report the live scrollTop: the wrapper's reconnect check and pinColdBottom in virtualizer.tsx.
  • Late scroll event: if the write's own scroll event arrives afterwards, the core either drops it as a repeat of the stored offset or delivers it normally. The core restarts its debounce before either, so the isScrolling reset still happens. This is the same path the reconnect check's live report already takes.
  • Unchanged: the virtual-core patch, virtualizer.tsx and every e2e assertion. No timeout, retry or fixture changes.

Root cause evidence

  • Repro on the base: the case "mounts every part once and in order" failed in all 4 local runs on the base (the baseline repro and 3 instrumented runs).
    • The number of lost parts varied: 58 parts across 3 skips in one run, 2 parts in another.
    • In every run, the set of parts never seen equals the set the timeout reports as missing.
  • Instrumented run 3: 262 offset deliveries (169 during scrolling, 46 live end deliveries, 47 stale end deliveries).
    • All 47 stale end deliveries repeated the offset of the last scroll delivery, 136–507 ms after it.
    • 39 of them came after a write and undid it. For example, the core offset went from 2704 to 64 while the live scrollTop stayed at 2704.
  • Ruled out:
    • empty parts, collapsed groups, an early paging stop
    • non-contiguous mounting, detached rows above the view, very large edit-diff steps
    • Recording the accepted state into the test's seen set would only hide the jump, so it is not a fix.
  • Alternatives rejected:
    • useScrollendEvent: true changes the reset timing and the reconnect deadline, and browsers without scrollend would keep the bug.
    • Patching the core fallback would grow the existing core patch.

Tests

  • New unit test, observe-element-offset.test.ts: "ends a scroll at the live offset after a write without its own scroll event".
    • Steps: a scroll event at 100, then scrollTop = 2620 with no event (happy-dom's setter dispatches none), then a wait past the reset delay.
    • Red on the base: received [100, false] instead of [2620, false]. The other 4 tests pass.
    • Green: 5/5. All timeline unit files with the test:unit flags: 27 pass across 3 files.
  • E2E on a production build (one worker, no retries):
    • The focused case with --repeat-each=3: 3 passed.
    • The whole e2e/regression/timeline-history.spec.ts: 6 passed. This covers prepend anchoring, completion and interruption, and hydration.
    • Locally that is 4/4 failures before the fix and 4/4 passes after. This case is flaky on hosted Linux and Windows, so the hosted runs decide.
  • timeline-stability scroll-interaction.spec.ts: 8 passed, 1 failed.
    • The failure, "tracks keyboard scrolling from a focused timeline descendant", is pre-existing. It fails 3/3 on the base (only observe-element-offset.ts reverted) and 3/3 with the fix, each time a 60 s wait for prt_descendant_keyboard_01_shell at L280.
    • Likely cause, outside this PR: the test sets shellToolPartsExpanded: false, and the shell renders inside a collapsed "Used 1 Shell" group, so no element carries that part ID.
  • Checks:
    • bun typecheck in packages/app: pass.
    • Root bun run check: 37/37 tasks, lint 0 errors. @opencode/app:typecheck ran fresh; the other tasks were cached.
    • The pre-push hook re-ran the root check: 37/37.

Performance

e2e/performance/timeline/session-entry-benchmark.spec.ts, "entry: cold session from Home", 10 repeats per side on a production build, one worker, no retries. The baseline reverts only observe-element-offset.ts. All 20 runs passed with no missing or invalid records.

Metric Base median / p95 With fix median / p95
First correct frame 932.00 / 1089.90 ms 859.20 / 968.30 ms
Stable 1023.45 / 1263.40 ms 948.80 / 1027.00 ms

No regression was observed. The sample is small and sequential, with the base always first, so it shows neither equivalence nor a gain. The fix adds one scrollTop read per end-of-scroll delivery.

Dependency

This branch is based on the #87 head 98b57d5349 (cm-ci-runners), not directly on CM-Split-v2, because #89 is one of the cases blocking that CI branch. Until #87 merges, this PR's diff against CM-Split-v2 includes #87's commits. The #89 change is the single commit 327962621e.

Not verified here

  • Hosted Linux and Windows CI for this branch.
  • macOS was not run.

Refs #89

tiisetso added 5 commits October 20, 2026 09:15
Replace unavailable Blacksmith labels with ubuntu-24.04 and windows-2025
for PR tests and duplicate checks. Preserve every job, matrix entry and
command while allowing this fork's queued checks to start.
The virtualizer core's reset-delay fallback ends a scroll with the offset read by the last scroll event. When a history prepend or anchor write moves scrollTop and a long task holds that write's own scroll event past the delay, the stale end delivery resets the core offset. Later prepend compensation then targets the stale offset, so loaded history rows are skipped. End-of-scroll deliveries now report the live scrollTop; scrolling deliveries are unchanged.

Refs #89
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@trmosala

Copy link
Copy Markdown
Owner Author

Coordinator source review of exact commit 327962621e18794f01d632dc038bbf2358578c77: no blocking findings. Against its reviewed CI parent, the change is limited to the offset wrapper and its regression test. The production caller is vertical, still applies its existing touch translation, and ignores deliveries for inactive views. The change keeps active scrolling deliveries and cleanup suppression intact.

Independently ran the offset test file with the package's solid/happy-dom flags: 5 pass, 11 expectations. Inspected the unchanged production history regression and the reported 3-repeat/full-file results. The PR correctly discloses the auxiliary stability test's 3/3 baseline and 3/3 candidate failures and the small sequential benchmark sample. This does not claim that auxiliary case is fixed or that performance equivalence is proven.

The exact commit is now in the local V2 integration worktree with the other reviewed fixes. The target branch remains unchanged. Required Linux/Windows checks on the final combined head remain a merge gate; #89 stays open pending that integration.

@trmosala

Copy link
Copy Markdown
Owner Author

Superseded by PR #96, squashed into CM-Split-v2 as 290d7d6353c0c7a4a356af780b5687f2dcfe5cfc. This PR's current head was checked against the reviewed head and is an ancestor of integration source 68ab9205709350385471eb2d383b3cff3c18e678; the squash commit's tree matches that source exactly. Later corrections and the actual private dependency pin are included there.

Closing this earlier PR as superseded, not claiming it was independently merged. Its branch remains intact. Final combined verification is deferred until the scoped implementation issues are closed, as requested by the user.

@trmosala trmosala closed this Oct 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant