Skip to content

fix(ui): prevent programmatic scrollTo from flipping chatUserNearBott… - #76991

Merged
steipete merged 10 commits into
openclaw:mainfrom
nickmopen:fix/webchat-streaming-scroll-upward
May 11, 2026
Merged

steipete merged 10 commits into
openclaw:mainfrom
nickmopen:fix/webchat-streaming-scroll-upward

Conversation

@nickmopen

@nickmopen nickmopen commented May 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Problem: During streaming assistant responses in Control UI/webchat, calling scrollTo() to pin the viewport to the bottom fires a synchronous scroll event. Because new content has grown scrollHeight between the scrollTo call and the event, handleChatScroll computes a large distanceFromBottom (≥ 450 px) and flips chatUserNearBottom to false, breaking the auto-scroll loop for all subsequent streaming tokens.
  • Why it matters: Every user running streaming responses in the webchat could see the viewport drift upward mid-generation, forcing a manual scroll-down while the assistant is still responding.
  • What changed: A chatIsProgrammaticScroll boolean flag is set on the host before each programmatic scrollTo/scrollTop write and cleared via requestAnimationFrame after. handleChatScroll returns early when the flag is set, so our own scroll events cannot corrupt the near-bottom state.
  • What did NOT change: Threshold values, user-initiated scroll detection, force semantics, logs scroll logic, or any non-scroll UI behavior are untouched.

Change Type (select all)

  • Bug fix
  • Feature
  • Refactor required for the fix
  • Docs
  • Security hardening
  • Chore/infra

Scope (select all touched areas)

  • Gateway / orchestration
  • Skills / tool execution
  • Auth / tokens
  • Memory / storage
  • Integrations
  • API / contracts
  • UI / DX
  • CI/CD / infra

Linked Issue/PR

Root Cause (if applicable)

  • Root cause: scheduleChatScroll calls target.scrollTo({top: scrollHeight}) to pin the viewport. This fires a scroll event that handleChatScroll handles. By the time that event fires, streamed content has already grown scrollHeight, so distanceFromBottom = newScrollHeight - oldScrollTop - clientHeight exceeds NEAR_BOTTOM_THRESHOLD (450 px). handleChatScroll then sets chatUserNearBottom = false, and all subsequent streaming ticks see shouldStick = false — auto-scroll breaks.
  • Missing detection / guardrail: No distinction between scroll events caused by the user versus those caused by our own scrollTo calls. handleChatScroll treated both identically.
  • Contributing context: The bug is intermittent because it depends on how fast content grows between the scrollTo call and the scroll event dispatch — slower models or short responses may not trigger it.

Regression Test Plan (if applicable)

  • Coverage level that should have caught this:
    • Unit test
    • Seam / integration test
    • End-to-end test
    • Existing coverage already sufficient
  • Target test or file: app-scroll.test.ts
  • Scenario the test should lock in: When chatIsProgrammaticScroll is true, calling handleChatScroll with a scroll event whose distanceFromBottom exceeds the threshold must NOT flip chatUserNearBottom to false.
  • Why this is the smallest reliable guardrail: Pure unit test, no DOM rendering needed — just the flag + event handler interaction.
  • Existing test that already covers this: None before this PR.
  • If no new test is added, why not: N/A — three new tests added in the "programmatic scroll guard" suite (16 total, all passing).

User-visible / Behavior Changes

  • Streaming assistant responses in Control UI/webchat now stay pinned to the bottom of the viewport. Previously the chat could scroll upward mid-stream and require manual scroll-down.
  • User-initiated scroll-up while streaming still correctly pauses auto-scroll (behavior unchanged).

Diagram (if applicable)

Before:
[streaming token] -> scheduleChatScroll -> scrollTo(bottom)
-> scroll event fires -> handleChatScroll
-> distanceFromBottom > 450 (content grew)
-> chatUserNearBottom = false
-> next token: shouldStick = false -> viewport drifts up

After:
[streaming token] -> scheduleChatScroll -> chatIsProgrammaticScroll = true -> scrollTo(bottom)
-> scroll event fires -> handleChatScroll
-> chatIsProgrammaticScroll == true -> return early (no state change)
-> rAF fires -> chatIsProgrammaticScroll = false
-> next token: chatUserNearBottom still true -> stays pinned

Security Impact (required)

  • New permissions/capabilities? No
  • Secrets/tokens handling changed? No
  • New/changed network calls? No
  • Command/tool execution surface changed? No
  • Data access scope changed? No

Repro + Verification

Environment

  • OS: Linux (Ubuntu, kernel 7.0.0-14-generic) / macOS
  • Runtime/container: npm global install, Node 24
  • Model/provider: OpenAI GPT-5.5
  • Integration/channel: Control UI / webchat
  • Relevant config: default

Steps

  1. Open Control UI webchat
  2. Send a prompt that produces a long streaming assistant response
  3. Watch the chat viewport while tokens stream in

Expected

  • Viewport stays pinned to the newest streamed token throughout generation

Actual (before fix)

  • Viewport scrolls upward intermittently; newest content is no longer visible without manually scrolling down

Evidence

  • Failing test/log before + passing after — app-scroll.test.ts: 16 tests pass after the fix; the new "programmatic scroll guard" suite directly exercises the previously missing guard. Before this PR, handleChatScroll with distanceFromBottom > 450 would unconditionally set chatUserNearBottom = false even during a programmatic scroll.

Behavior Proof

Screen.Recording.2026-05-08.at.4.39.21.PM.mov

What to observe in the recording:

  1. A long streaming assistant response begins — viewport stays pinned to the bottom throughout
  2. User manually scrolls up mid-stream — auto-scroll pauses correctly
  3. User scrolls back to bottom — auto-scroll resumes and stays pinned

Human Verification (required)

  • Verified scenarios: Unit test suite for app-scroll.ts passes (16/16). Flag lifecycle (set before scroll, cleared after rAF) verified in "scheduleChatScroll sets chatIsProgrammaticScroll…" test.
  • Edge cases checked: Flag already cleared before user scroll — real user scroll-up correctly flips chatUserNearBottom to false (verified in third new test). resetChatScroll also clears the flag.
  • What you did not verify: Live browser smoke against a running gateway with a real streaming response.

Review Conversations

  • I replied to or resolved every bot review conversation I addressed in this PR.
  • I left unresolved only the conversations that still need reviewer or maintainer judgment.

Compatibility / Migration

  • Backward compatible? Yes
  • Config/env changes? No
  • Migration needed? No

Risks and Mitigations

  • Risk: requestAnimationFrame fires before the browser dispatches the scroll event in some edge cases (e.g. very fast rAF in a headless environment), clearing the flag too early.
    • Mitigation: In that case the behavior degrades to the pre-fix behavior for that single tick — the retry path in scheduleChatScroll (120 ms timeout) re-scrolls and sets the flag again, recovering on the very next cycle.You've used 74% of your weekly rate limit. Your weekly rate limit will reset on May 10 at 7:00 PM. Learn More

@clawsweeper

clawsweeper Bot commented May 3, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

Summary
Review failed before ClawSweeper could summarize the requested change.

Reproducibility: unclear. The review failed before ClawSweeper could establish a reproduction path.

Real behavior proof
Not applicable: Real behavior proof was not assessed because the Codex review failed.

Next step before merge
Review did not complete, so no work-lane recommendation was made.

Review details

Best possible solution:

Retry the Codex review after fixing the execution failure.

Do we have a high-confidence way to reproduce the issue?

Unclear. The review failed before ClawSweeper could establish a reproduction path.

Is this the best way to solve the issue?

Unclear. Retry the review first so ClawSweeper can evaluate the actual issue and fix direction.

What I checked:

  • failure reason: codex execution failed.
  • codex failure detail: Codex review failed for this PR with exit 1.
  • codex stdout: Per-item Codex failure; continuing with the rest of the shard.

Likely related people:

  • unknown: Codex failed before it could trace repository history. (role: review did not complete; confidence: low)

Remaining risk / open question:

  • No close action taken because the review did not complete.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 556c45cfbfd1.

@nickmopen
nickmopen force-pushed the fix/webchat-streaming-scroll-upward branch from d983e21 to a7d6484 Compare May 4, 2026 14:07
@nickmopen

Copy link
Copy Markdown
Contributor Author

@lily-oc , @steipete Can you review this PR when you have a moment?

@nickmopen
nickmopen force-pushed the fix/webchat-streaming-scroll-upward branch from 9c4e68a to 8df12a9 Compare May 7, 2026 00:16
@openclaw-barnacle openclaw-barnacle Bot added the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 7, 2026
@nickmopen

nickmopen commented May 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Behavior Proof

After fix issue

Screen.Recording.2026-05-08.at.4.39.21.PM.mov

What to observe in the recording:

  1. A long streaming assistant response begins — viewport stays pinned to the bottom throughout
  2. User manually scrolls up mid-stream — auto-scroll pauses correctly
  3. User scrolls back to bottom — auto-scroll resumes and stays pinned

@nickmopen

Copy link
Copy Markdown
Contributor Author

@clawsweeper Re-run

@openclaw-barnacle openclaw-barnacle Bot added the channel: slack Channel integration: slack label May 11, 2026
@steipete
steipete merged commit b90f28e into openclaw:main May 11, 2026
103 of 104 checks passed
@clawsweeper clawsweeper Bot mentioned this pull request May 14, 2026
6 of 25 tasks
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
openclaw#76991)

* fix(ui): prevent programmatic scrollTo from flipping chatUserNearBottom during streaming

* fix(ui): preserve user scroll-up events that arrive during programmatic scroll guard window

* test(ui): add unit coverage for programmatic scroll guard boundary and retry path

* fix(ui): preserve chat scroll bookkeeping

* chore: drop unrelated slack formatting

* test: narrow inbound dedupe claim result

---------

Co-authored-by: Peter Steinberger <[email protected]>
jameslcowan pushed a commit to jameslcowan/openclaw that referenced this pull request Jun 2, 2026
openclaw#76991)

* fix(ui): prevent programmatic scrollTo from flipping chatUserNearBottom during streaming

* fix(ui): preserve user scroll-up events that arrive during programmatic scroll guard window

* test(ui): add unit coverage for programmatic scroll guard boundary and retry path

* fix(ui): preserve chat scroll bookkeeping

* chore: drop unrelated slack formatting

* test: narrow inbound dedupe claim result

---------

Co-authored-by: Peter Steinberger <[email protected]>
sablehead pushed a commit to sablehead/openclaw that referenced this pull request Jun 10, 2026
openclaw#76991)

* fix(ui): prevent programmatic scrollTo from flipping chatUserNearBottom during streaming

* fix(ui): preserve user scroll-up events that arrive during programmatic scroll guard window

* test(ui): add unit coverage for programmatic scroll guard boundary and retry path

* fix(ui): preserve chat scroll bookkeeping

* chore: drop unrelated slack formatting

* test: narrow inbound dedupe claim result

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui channel: slack Channel integration: slack size: M triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Control UI webchat does not stay pinned to bottom during streaming output

2 participants