Skip to content

fix(mobile): make OMP terminal momentum refresh-rate independent - #21687

Merged
nwparker merged 1 commit into
mainfrom
nwparker/omp-good
Sep 21, 2026
Merged

nwparker merged 1 commit into
mainfrom
nwparker/omp-good

Conversation

@nwparker

@nwparker nwparker commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10 $\color{#cf222e}{\Huge{\mathbf{−}}}$​4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​6
Prod 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​12 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​6

ELI5

A 144 Hz screen asks for animation frames more often than a 60 Hz screen. OMP terminal momentum used to move a fixed 16 ms on every frame, so the same swipe could travel a different distance depending on the display. This PR measures the real time between frames and keeps the physical scrolling behavior consistent.

What Changed

  • Use the requestAnimationFrame timestamp and performance.now() release anchor for momentum.
  • Scale friction from the existing 16 ms baseline and clamp long stalls to a safe range.
  • Keep terminal-input routing, edge stopping, and normal scroll behavior unchanged.
  • Add regression assertions for elapsed-time motion and refresh-rate-independent friction.
  • Update the generated WebView payload length/hash contract for the intentional payload change.

Why

The fixed per-frame step was refresh-rate dependent. The elapsed-time integration is the smallest change that preserves the existing 60 Hz tuning while making 90/120/144 Hz behavior deterministic. It avoids introducing a new animation library, timer, native dependency, or mobile wire change.

Linked Issue

Relates to #14573 (keep the issue open until physical Android 144 Hz frame evidence is captured).

Visual Proof

N/A — this is WebView gesture physics; the available hosts have no Android 144 Hz device or frame-time capture. The interaction path is covered by the focused scroll-routing tests.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below

Commands and results:

  • pnpm --dir mobile test src/terminal/terminal-webview-scroll-routing.test.ts — 14/14 passed.
  • Branch snapshot payload + scroll contract suite — 15/15 passed.
  • pnpm --dir mobile typecheck — passed.
  • pnpm --dir mobile exec oxlint src/terminal/terminal-webview-html/surface-touch-gestures.ts src/terminal/terminal-webview-scroll-routing.test.ts — passed.
  • pnpm --dir mobile exec oxfmt --check src/terminal/terminal-webview-html/surface-touch-gestures.ts src/terminal/terminal-webview-scroll-routing.test.ts — passed.

AI Disclosure

Internal StablyAI contributor; no external AI disclosure required.

Review

Reviewed the changed momentum path for frame timing, friction scaling, edge termination, terminal-input routing, and payload contract updates. The branch contains one focused commit and three files only.

Agent skill upstream boundary

  • Not applicable; this change does not copy or mechanically translate upstream skill-installer source.

Notes

  • Security: no new input, code execution, storage, or network behavior.
  • Cross-platform: JavaScript runs in the existing mobile WebView; no OS-specific path, shell, or native API changes.
  • SSH/remote: terminal transport and remote session behavior are unchanged.
  • Mobile/backwards compatibility: no RPC, persistence, route, or pairing contract changes.
  • Performance: one timestamp subtraction and Math.pow per momentum frame; no new timer or listener.
  • Residual acceptance: physical Android 144 Hz frame-time capture is still required before closing [Bug]: OMP terminal scrolling appears capped at ~30 FPS on a 144 Hz Android tablet #14573.

Checklist

  • This PR is small and focused
  • I explained what changed and why (including ELI5)
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@nwparker
nwparker force-pushed the nwparker/omp-good branch 2 times, most recently from dc12419 to dfd4f12 Compare September 19, 2026 15:40
@coderabbitai

coderabbitai Bot commented Sep 19, 2026 •

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: 2dac7b87-dd0a-41cf-8805-c0832990c65d

📥 Commits

Reviewing files that changed from the base of the PR and between de87571 and e22ecea.

📒 Files selected for processing (1)
  • mobile/src/terminal/terminal-document-golden.txt

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The momentum scrolling callback now uses elapsed time between animation frames to calculate friction and scroll displacement. The scroll-routing tests capture the updated function signature and verify the timing calculations. The golden terminal output reflects the same changes. The payload hash test updates its expected digest and document length.

Priority: ➖ Normal

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: making mobile OMP terminal momentum scrolling independent of display refresh rate.
Description check ✅ Passed The description is mostly complete. It explains the user impact, implementation, rationale, testing, visual-proof status, compatibility considerations, and remaining Android verification. It reference…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 4 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • Momentum integrates by real frame time: momentumStep now receives the requestAnimationFrame timestamp and derives elapsed (16 ms on the first frame, clamped to [1, 50] ms), then scales both friction (Math.pow(FRICTION, elapsed / 16)) and displacement (vel * elapsed) by it. A fling now covers the same distance over the same wall-clock time at 60/90/120/144 Hz, while the 60 Hz baseline is preserved.
  • Regression assertions updated: the momentum sliceBetween boundaries now match momentumStep(frameTime), and new assertions pin the elapsed expression, the friction exponent, and vel * elapsed.

I verified the units (ts.velY is px/ms from Date.now() deltas, rAF timestamps are ms, so vel * elapsed is px), the closure scoping of lastMomentumTime (fresh per touchend, so launches don't share state), and that the total fling distance is unchanged (16·v0/(1−FRICTION)) — only the completion time was refresh-rate dependent. The focused suite passes 14/14 locally.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

  • First-frame elapsed now measured from touch release: lastMomentumTime is seeded with performance.now() at touchend instead of the === 0 sentinel with a hardcoded 16 ms default, so the first momentum frame integrates the real touch-release-to-first-frame delay (same DOMHighResTimeStamp time origin, clamped to [1, 50] ms). The test now pins performance.now() and the simplified elapsed expression.

This is an improvement over the previous revision — the first frame is now accurate rather than assumed, and the sentinel is gone. The focused suite still passes 14/14 locally.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Honor the native reduced-motion preference in terminal momentum. · surface-touch-gestures.ts:220

mobile/src/terminal/terminal-webview-html/surface-touch-gestures.ts:220
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Honor the native reduced-motion preference in terminal momentum.

When touchend leaves no touches and velocity exceeds MIN_VEL, this WebView starts momentumStep, which keeps requesting frames. TerminalWebView passes XTERM_WEBVIEW_SOURCE without reduced-motion handling. The existing useReducedMotionEnabled hook is used only by onboarding. Pass the native preference into the terminal HTML and skip both momentum scheduling calls when it is enabled.

Source: Learnings

🧹 Nitpick comments (1)
mobile/src/terminal/terminal-webview-scroll-routing.test.ts (1)

181-186: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Test momentum outcomes instead of source text.

These assertions only confirm implementation strings. They can pass while browser-level momentum behavior regresses. Add a browser-level test that drives animation frames at 60 Hz, 90 Hz, and 144 Hz and compares displacement and velocity decay.

Based on learnings: animation behavior requires browser validation, and tests should assert observable behavior instead of implementation details.

Source: Learnings


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: eb0ba0de-db65-47f4-bac8-171075c7d2de

📥 Commits

Reviewing files that changed from the base of the PR and between e8a7be4 and dfd4f12c03b9b4b3e7b5ea33979b390cd7182ffe.

📒 Files selected for processing (2)
  • mobile/src/terminal/terminal-webview-html/surface-touch-gestures.ts
  • mobile/src/terminal/terminal-webview-scroll-routing.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

This increment (delta against the prior pullfrog review at dfd4f12) completes the generated WebView payload contract for the momentum change; the momentum physics itself was reviewed in the two prior runs.

  • Synced the WebView payload contract: terminal-webview-payload-hash.test.ts now pins EXPECTED_SHA256 to 8ca3804… and EXPECTED_LENGTH to 730681, matching the deliberate change to the emitted XTERM_HTML. The length delta (+209) reconciles exactly with the added momentum lines (lastMomentumTime, elapsed, the Math.pow friction, and vel * elapsed).
  • Regression assertions unchanged: the scroll-routing suite still pins the momentumStep(frameTime) boundary and the elapsed/friction/displacement expressions.

Both focused suites pass locally (15/15). No new issues and no open pullfrog threads.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker

Copy link
Copy Markdown
Contributor Author

Verification update: the new mobile bundle, static analysis, payload/scroll verification, and Pullfrog checks pass. The required RPC recording pin job fails before reproduction because the repository manifest still pins baseline 1006ad670aa347d0bcaecddb6c41b8caa245b358, which is not an ancestor of current main or this branch; this PR does not touch mobile/rpc-foundation or the pin guard. I am leaving the PR unmerged rather than changing the recording corpus as unrelated scope.

@nwparker

Copy link
Copy Markdown
Contributor Author

Visual proof

I ran a browser-level visual harness against the exact PR source and recorded the momentum paths at synthetic 60 Hz and 144 Hz frame intervals.

The harness asserts:

  • the PR source contains the elapsed-time integration (Math.pow(FRICTION, elapsed / 16) and vel * elapsed);
  • corrected 60 Hz and 144 Hz paths remain within 2% of each other;
  • the old fixed-16 ms path diverges between refresh rates.

Measured final distances in the passing run:

  • Old 60 Hz: 504.3 px
  • Old 144 Hz: 548.6 px
  • PR 60 Hz: 508.8 px
  • PR 144 Hz: 513.5 px

This is a browser-level proof of the physics change, not physical Android hardware evidence. The linked Android 144 Hz issue should remain open until a real device frame trace is captured.

[email protected]

@nwparker
nwparker force-pushed the nwparker/omp-good branch 2 times, most recently from 6585eea to de87571 Compare September 21, 2026 00:32
@nwparker

Copy link
Copy Markdown
Contributor Author

Visual proof (rebased head)

I reran the browser-level visual harness against the rebased implementation in mobile/src/terminal/document/surface-touch-gestures.ts. The harness asserts the exact generated source contains the elapsed-time integration and compares synthetic 60 Hz and 144 Hz frame intervals.

Passing measurements:

  • Old fixed-16 ms path: 504.3 px at 60 Hz vs 548.6 px at 144 Hz
  • Corrected path: 508.8 px at 60 Hz vs 513.5 px at 144 Hz (0.9% difference)

The video is browser-level proof of the physics change, not physical Android hardware evidence. Issue #14573 remains open pending a real Android 144 Hz frame trace.

[email protected]

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

terminal-document-identity.test.ts fails on this branch — the committed golden fixture still holds the pre-change momentum code.

Reviewed changes

This increment is a rebase onto a newer main (which moved the hand-written document script into src/terminal/document/ modules) plus a re-derived payload contract. The momentum physics is unchanged from the previously reviewed revision.

  • Momentum edit relocated to document/: momentumStep now takes the rAF frameTime and integrates friction (FRICTION ** (elapsed / 16)) and displacement (vel * elapsed) by clamped elapsed wall-clock time in mobile/src/terminal/document/surface-touch-gestures.ts.
  • Payload contract re-derived: EXPECTED_SHA256/EXPECTED_LENGTH updated to 775a1294…/726574; the payload-hash and scroll-routing suites pass 15/15 locally.
  • Regression assertions updated to the new momentumStep(frameTime) boundary and the elapsed/friction/displacement source strings.

⚠️ The committed golden document fixture was not regenerated

terminal-document-identity.test.ts compares the emitted document byte-for-byte against mobile/src/terminal/terminal-document-golden.txt, and that fixture still carries the old momentum code (let momentumStep = function() { vel *= FRICTION; … const delta = vel * 16; }, no lastMomentumTime/elapsed). The suite fails 2/3 on this branch, so pnpm --dir mobile test and CI go red. The payload-hash digest was updated, but the fixture that shows where the bytes moved was not — the test file itself calls an un-updated golden a blocking finding.

Technical details
# Regenerate the terminal document golden fixture

## Affected sites
- `mobile/src/terminal/terminal-document-golden.txt:3264` — still has `let momentumStep = function() {`, `vel *= FRICTION;`, `const delta = vel * 16;`, and no `lastMomentumTime`/`elapsed`
- `mobile/src/terminal/terminal-document-identity.test.ts:39` — byte-for-byte comparison against that fixture (also fails the placeholder round-trip at line 58)

## Required outcome
- `pnpm --dir mobile test src/terminal/terminal-document-identity.test.ts` passes 3/3.
- The fixture diff contains only the momentum lines, with no unrelated drift.

## Suggested approach
- From `mobile/`, run `node scripts/build-terminal-document-fixture.mjs` and commit the regenerated `terminal-document-golden.txt`. Verified locally on this branch: it produces a 6-insert/3-delete diff that is exactly the momentum change, and restores the suite.
- Per the test's own rule, note the fixture update in the commit message so the golden move is reviewable.

Pullfrog  | Fix it ➔ | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

Use elapsed animation-frame time for OMP terminal momentum and update the generated payload contract.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes

This increment (delta against the prior pullfrog review at de87571) resolves that review's blocking finding and completes the generated payload contract; the momentum physics is unchanged from the already-reviewed revision.

  • Regenerated the golden fixture: terminal-document-golden.txt now carries the momentum change (momentumStep(frameTime), elapsed, FRICTION ** (elapsed / 16), vel * elapsed, lastMomentumTime). The diff is exactly the momentum lines with no unrelated drift, and terminal-document-identity.test.ts passes 3/3 byte-for-byte.
  • Payload contract re-derived: EXPECTED_SHA256/EXPECTED_LENGTH set to 775a1294…/726574; the payload-hash suite passes.
  • Regression assertions aligned: the momentum sliceBetween boundaries now match momentumStep(frameTime) and pin performance.now(), the clamped elapsed expression, the friction exponent, and vel * elapsed.

The full mobile/src/terminal suite passes locally (67 files, 630 tests) and pnpm --dir mobile typecheck passes. No prior pullfrog threads were open, and the golden fixture's absence was the only outstanding concern.

Pullfrog  | View workflow run | Using DeepSeek Flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker merged commit bd860f3 into main Sep 21, 2026
24 checks passed
@nwparker
nwparker deleted the nwparker/omp-good branch September 21, 2026 01:01
Jinwoo-H added a commit that referenced this pull request Sep 21, 2026
`bd860f34c1` (#21687, OMP terminal momentum normalised across refresh rates)
landed on main and moved the same three files this branch does.

Document modules #21687 changed: `surface-touch-gestures.ts` only, and only
inside the momentum loop of its touchend handler — `momentumStep` takes the
animation frame's timestamp, holds `lastMomentumTime`, decays by
`FRICTION ** (elapsed / 16)` and scales the delta by `elapsed` instead of a fixed
16 ms. It auto-merged with this branch's change to the line above it
(`touches.length === 0`, fold 5), so the module carries both: the loop is main's
and the count is this branch's. No other document module was touched by either
side in the same file, and there was no module-level conflict to resolve.

`terminal-document-golden.txt` and `terminal-webview-payload-hash.test.ts`
conflicted because both sides re-pinned them. Resolved by regenerating from the
merged modules (`node scripts/build-terminal-document-script.mjs`, then
`build-terminal-document-fixture.mjs`), never by taking a side: the golden now
carries main's six momentum lines and this branch's seven `touchesInRoot` lines,
which is the only reading of the merge that is true of the modules.

Golden byte length: 729,152 on this branch and 726,574 on main, 729,363 merged.
Fixture 111,329 bytes. sha256 0263338994... (ours) and 775a129414... (main's) ->
0be398e4d7...

Claude-Session: https://claude.ai/code/session_01JNnE9qzUZMMnqpZWCqM3nb
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