A local-first multi-agent app development platform, built on PenguinHarness
fix(web): 流式回复时向上滚,视图不再被拽回底部
lmlihengf7b93ea3ed34
diff --git a/changelog/unreleased/2026-10-27-chat-scroll-up-bounce.md b/changelog/unreleased/2026-10-27-chat-scroll-up-bounce.mdnew file mode 100644index 00000000..d5d2acc8--- /dev/null+++ b/changelog/unreleased/2026-10-27-chat-scroll-up-bounce.md@@ -0,0 +1,41 @@+# Scrolling up in a conversation no longer bounces back down while a reply streams++- **Date:** 2026-10-27+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[中文](2026-10-27-chat-scroll-up-bounce.zh.md)++While a reply was streaming, wheeling up from the bottom of the conversation was often followed by+a small jump back down: the view moved by the text that had just arrived. Following the bottom now+stops at the first tick of an upward wheel and stays off until the reader scrolls back down.++## Details++- The transcript listens for the wheel itself, with a listener that is not passive and never+ prevents the scroll, so the browser hands the page the first tick of a gesture before it scrolls;+ the rest of the gesture stays asynchronous. A stream update arriving in between no longer snaps+ the view back to the bottom under the reader's first upward tick.+- Following resumes only when the reader's own scroll brings the view back within 80px of the+ bottom. The scroll event of an earlier snap, which arrives a frame later with nothing moved, no+ longer turns following back on after the reader has started scrolling up.+- A streaming update, a resize of the transcript and the selection menu closing read where the view+ stands before snapping it (`followToBottom`), so a scroll the browser has made but not yet+ reported (a key, the scrollbar, an outline jump) is left in place instead of being undone.+- The transcript's scroller carries `data-stream-scroll`, which the browser spec below needs: it+ has to watch that element itself, frame by frame.+- `packages/web/e2e/scroll-follow-bounce.spec.mjs` streams a reply in each theme with the renderer+ slowed four times, wheels up from the bottom and records every frame, wheel event and programmatic+ scroll. It fails on a snap that lands after the gesture could already be on screen, on a frame+ showing a snap combined with the gesture, on text moving back up after the gesture moved it down,+ and on any movement in the second after the gesture. It runs on demand, outside CI.+- Ported from upstream `0c7725c2` (#1250), applied as its own change rather than merged. Not taken:+ upstream's `overflow-anchor: none` on `[data-arrive]` — this tree has no per-run arrival elements+ (its `fade` reveal paces a prefix of the reply's text, `packages/ui/src/.../stream-reveal.ts`), and+ measured here the two-state spec shows no anchoring-only drift in Frost without it.++## Compatibility++- No dependency, stored-data or config change. The wheel, touch and scroll paths behave as before+ for a reader at the bottom; only an upward wheel during a stream behaves differently.diff --git a/changelog/unreleased/2026-10-27-chat-scroll-up-bounce.zh.md b/changelog/unreleased/2026-10-27-chat-scroll-up-bounce.zh.mdnew file mode 100644index 00000000..a503bb23--- /dev/null+++ b/changelog/unreleased/2026-10-27-chat-scroll-up-bounce.zh.md@@ -0,0 +1,32 @@+# 回复流式输出时向上滚动,对话不再回弹++- **Date:** 2026-10-27+- **Type:** fix+- **Scope:** `web`+- **Breaking:** no++[English](2026-10-27-chat-scroll-up-bounce.md)++回复还在流式输出时,从对话底部用滚轮向上滚,常常紧跟着往下弹回一小段:视图被刚到的文字带了下去。现在+向上滚轮的第一格就停止跟随底部,直到读者自己滚回底部才恢复。++## 细节++- 消息流自己监听滚轮,监听器不是被动的,也从不阻止滚动,于是浏览器先把手势的第一格交给页面,再滚动;+ 手势其余部分仍是异步的。在这之间到达的流式更新不会再把视图贴回读者第一格滚轮下面。+- 只有读者自己的滚动把视图带回距底部 80px 以内时才恢复跟随。先前一次贴底的滚动事件晚一帧才到,位置+ 没有变化,它不会在读者已经开始向上滚之后重新打开跟随。+- 流式更新、消息流尺寸变化以及选区菜单关闭时,先读视图当前的位置再决定要不要贴底(`followToBottom`):+ 浏览器已经执行但还没报告的滚动(按键、拖动滚动条、大纲跳转)保持原位,不被撤销。+- 转写区的滚动容器带上 `data-stream-scroll`,下面的浏览器用例需要它:用例要逐帧观察这个元素本身。+- `packages/web/e2e/scroll-follow-bounce.spec.mjs` 在每个主题下流式输出一条回复,渲染进程降速四倍,+ 从底部向上滚,逐帧记录滚动位置、滚轮事件和程序发起的滚动。以下情况判为失败:手势可能已经显示在屏幕上+ 之后才发生的贴底;某一帧显示贴底与手势叠加;手势把文字往下带之后文字又往上移;手势结束后一秒内有任何+ 移动。它按需运行,不在 CI 中。+- 移植自上游 `0c7725c2`(#1250),照改动落、不是合分支。未取上游那条 `[data-arrive]` 上的+ `overflow-anchor: none`:本树没有「逐段到达」的元素(它的 `fade` 是按速率放出回复文本的前缀,见+ `packages/ui/src/.../stream-reveal.ts`),而且本轮两态实测里 Frost 没有出现只由锚点造成的漂移。++## 兼容性++- 不涉及依赖、存储数据或配置。停在底部时的滚轮、触摸与滚动行为与从前一致,只有流式期间的向上滚轮不同。diff --git a/docs/FORK-PROGRESS.md b/docs/FORK-PROGRESS.mdindex cc3ccff5..cb2dd82c 100644--- a/docs/FORK-PROGRESS.md+++ b/docs/FORK-PROGRESS.md@@ -1039,6 +1039,22 @@ mock 路由导入序、`chat-page.tsx` 的旧探针体),自带 4 份用例页,本树一个窗口一份)、终端面板关闭前重核 `dockSessionId()`(`terminal-panel.tsx` 本树没有)、自愈路径的 `adoptBrowserSession` / `reownTerminals`(本树没有这两个函数)、它那份 jsdom 用例(本树不装 jsdom,改由真浏览器取证)。+- [x] **5.53 流式回复时向上滚,视图不再被拽回底部**(上游 `0c7725c2` `#1250`,**2026-10-27 第一百四十轮+ 落地**,提交见该节):三条成因、三处修法 —— ①滚轮改由**原生非被动**监听器接管(`message-stream.tsx`+ 的一个 effect 挂 `wheel`、`{ passive: false }`、从不 `preventDefault`,并删掉 React 的 `onWheel`):+ 浏览器先把手势第一格交给页面再滚动,于是「跟随」在视图移动之前就关了;②`stream-follow.ts` 的+ `scrolled()` 只在**位置真的变了**时才恢复跟随(`dist < 80 && m.scrollTop !== prev`)—— 先前一次贴底+ 自己晚一帧的滚动事件位置未变,不再在读着向上滚之后把跟随打开;③新增 `observed()` 与 `followToBottom`+ (提交 effect、ResizeObserver、选区菜单放行三处都改用它):贴底之前先按「那条滚动事件将会读到的样子」+ 判一次实时位置,浏览器已经执行但还没报告的滚动(按键、滚动条、大纲跳转)不再被撤销;`observed()` 在+ 还没报告过任何位置时(刚进对话)不置一词,否则打开在底部的对话会被判成「停住了」而永远不贴底。+ **有意未取**上游 F4(`packages/ui/src/theme.css` 的 `.ui-stream [data-arrive] { overflow-anchor: none }`):+ 本树没有「逐段到达」的元素(`fade` 是按速率放出回复文本的前缀,见 `stream-reveal.ts`),而且两态实测+ 里 Frost 没有出现只由锚点造成的漂移(改前 6/6 手势的回弹全是 late-snap / composed)。另给转写区的+ 滚动容器加了 `data-stream-scroll`(新 spec 要逐帧看这个元素本身,本树没有上游的+ `data-find-region="conversation"`)。**为什么是这一条**:表上最靠前的未勾选条目仍是 2.2c / 3.5 /+ 3.6 / 4.x / 5.6 / 5.10(桌面壳一侧与既有部署单元、拍板、模型 key、明令不动、新依赖),而这一笔正是+ 第一百三十八轮末尾点名的「下一轮」,用户看得见的真缺陷、改动全在 web、不引入新依赖。- **不学**:阿里云 OSS 分发(`feat/aliyun-oss-release-distribution`)、模型库「官方推荐」与 TokenDance推荐分组(`FORK.md` 已写明不搬)、`web-mod-1…12` 那类大模块化重构(与我们改过的 77 个文件重叠,现在合进来是净亏)。@@ -2290,6 +2306,7 @@ v0.2.2」——它只加台账里 v0.2.2 那一节与两行表格,**跟本轮| 2026-10-26 | 5.50 | **在局域网地址上打开 Web App 时,密钥授权改为粘贴授权码**(上游 `12a58d4f` `#1328` 移植,照改动落、不是合分支;上游 8 文件 / +289 −17 → 本树落下 5 个跟踪文件 / +133 −17 与 changelog 一对:上游那份前端用例要 jsdom(`packages/web` 不装),改由真浏览器取证,服务端用例的表头注释按本树现状手写合并):服务端新增导出 `openedMode(asked, origin)` —— `manual` 永不升级;`callback` 只在 `https:` 或 `http:` 且主机为 `localhost` / `[::1]` / `127.x.x.x`(授权页 `callback_url` 的判据)时保留,解析不出的地址一并降级;`start` 用它同时决定回调地址与流程记录的模式(被降级的流程拒绝投递授权码,与手动流程完全一致)并返回 `mode`;`ModelOAuthStartResponse.mode` 为必填。Web 侧 `ModelOAuthDialog` 新增 `redirectRefused`,与 `manual` 合成 `byHand` 取代各处判断(授权码那一步、不轮询、不给跳转开关),只看应答里的 `mode === "manual"`,对没有该字段的旧服务端行为照旧。**本地化**:本树已改名的 `ADELIE_TRUST_PROXY` 等措辞沿用;changelog 按本仓写法改名到本轮日期、去掉上游 PR 行、写明移植来源 | 六包 `typecheck` **`EXIT=0`**(六个 `Done`;`gen:ifaces` 重写 `src/ifaces.json` 后与版本库逐字节相同 —— 195 接口 / 590 类型,本笔不动组件契约)· `npx oxlint` 五个文件 **0 警告 0 错误** · 五个源码 / 用例文件与一对 changelog `prettier --check` 干净 · `git diff --check` 干净 · 逐包 test **`EXIT=0`、0 失败**:core **1425** / 6 跳过(69 文件 + 1 跳过)· ui **1053**(130)· cli **561**(38)· server **204 文件 / 2995 通过 / 4 跳过** · web **269 文件 / 3283 通过 / 2 跳过** · hmr 无测试文件 · **反证(单测)**:在 `openedMode` 开头插一句 `return asked;` → `test/model-oauth.test.ts` **2 failed / 44 passed**(「非回环明文 HTTP 按手动开」与 LAN 路由那两条都挂在 `expected "manual", received "callback"`),还原后 **46 全过** · **本轮主证据(真服务端 ×2 + 真浏览器:改前 / 改后两态 + 回环对照)**:`packages/{core,server,web}` 各自单独重建;两份服务端产物(`r136/before-server-dist` 取自把四份源码 stash 掉的树)与两份 web 产物(`r136/{before,after}-dist`)分别挂在一次性数据根 `/root/adelie-fork-data/r136-{before,after}` 上,**改后起在 `localhost:8954`、改前起在 `localhost:8955`**(`ADELIE_SEED_ADMIN_PASSWORD` + 登录页表单拿 cookie;空数据根不需要模型 key——即 3.6 那个卡点);浏览器用 `--host-resolver-rules=MAP app.lan 127.0.0.1` 以 **`http://app.lan:<port>`(明文 HTTP + 非回环主机名)** 访问,三腿读数:**改后 @ LAN** —— `POST …/model-oauth/start` 回 `mode: "manual"`、`authorizeUrl` 里**没有 `callback_url`**、`code_challenge_method=S256`,弹窗同时有「授权码」输入框 + 那句粘贴提示 + 「提交授权码」,**没有**「授权页跳不回来?改为手动填写授权码」这个开关(截图 `r136/shots/after-lan.png`);**改前 @ LAN** —— 应答无 `mode` 字段、`callback_url` 就是 `http://app.lan:8955/…`(正是授权页会拒的那个),弹窗只有「打开授权页」+ 那个开关、**没有授权码框**(`r136/shots/before-lan.png`);**改后 @ localhost(回环对照,行为不变)** —— 应答 `mode: "callback"`、`callback_url` 是 `http://localhost:8954/…`、开关照旧在(`r136/shots/after-localhost.png`)。三腿 console 各 **0 error**、**无一条 ≥400**(登录前的 `/api/me` 401 属这个 App 的正常首访)· 端口只用 8954 / 8955(跑完都已停),3003 / 3004 / 4000 / 7364 / 7369 一个没碰;数据只落在 `/root/adelie-fork-data/r136-{after,before}`,探针 / 两态产物 / 截图都在 scratchpad 的 `r136/` 下(`packages/*/dist` 是构建产物,未 `git add`) | 见本行提交 || 2026-10-27 | 5.51 | **底部停靠栏拉到最大时不再盖住输入区**(上游 `bf3395ff` `#1325` 移植,照改动落、不是合分支;上游 11 文件 / +324 −34 → 本树落下 8 个跟踪文件(5 改 3 新)+ changelog 一对 + 1 处端到端视口):停靠状态的高度上限原先只按对话列(含工具行)的 85% 算,没有谁给输入区留位置,输入区就被压到停靠栏下面、点不到。新增 `features/dock/bottom-dock-size.ts`(纯逻辑:上限 = 工具行以下那片区域 − 量出来的输入区高度 − 一条消息带,仍受 0.85 封顶;空间不够先让消息带、再让 140px 最小高度,输入区永远让),新增 `features/dock/composer-height.ts`(`ResizeObserver` 喂的小 store,停靠栏 / 拖动夹取 / 落点预览读同一个数,重挂载后仍留着),`dock-panel.tsx` 量列与区域、上限跌破时走既有 `snap` 路径同提交让出,`dock-drag.tsx` 预览同一函数,`chat-page.tsx` 给输入区那个框挂测量 ref(本树输入区是普通 `<div>`,上游的 `WallpaperSurface` 本树没有),`dock-state.ts` 的尺寸常量搬走、`DOCK_RATIO_MAX` 反向导入,`e2e/dock.spec.mjs` 的尺寸用例改在 1280×1100 下跑。**本地化**:changelog 按本仓写法改名到本轮日期、去掉上游 PR 行、写明移植来源;新用例里那条读源码的断言改成认本树的 `<div ref={measureComposer}>` | 六包 `typecheck` **`EXIT=0`**(六个 `Done`;`gen:ifaces` 报 **`src/ifaces.json unchanged`**,195 接口 / 590 类型)· `npx oxlint` 15 个文件 **0 警告 0 错误** · 八个源码 / 用例文件与一对 changelog `prettier --check` 干净 · `git diff --check` 干净 · 逐包 test **`EXIT=0`、0 失败**:core **1425** / 6 跳过(70 文件)+ 1 跳过 · ui **1053**(130)· cli **561**(38)· server **204 文件 / 2995 通过 / 4 跳过** · web **270 文件 / 3292 通过 / 2 跳过**(本笔 +1 文件 / +9 用例)· hmr 无测试文件 · **本轮主证据(真服务端 ×2 + 真浏览器,两态四场景)**:服务端产物同一份(本笔只动 web),两份 web 产物 `r51/{after,before}-dist`(`[data-dock-area]` 选择器计数 5 / 1 两端核过)分别挂在一次性数据根 `/root/adelie-fork-data/r51-{after,before}` 上,**改后 `localhost:8956`、改前 `localhost:8957`**(`ADELIE_SEED_ADMIN_PASSWORD` + 模型指向本仓自带 mock LLM(8977);空数据根不需要模型 key —— 即 3.6 那个卡点);两态都把已存排布预置成「底部停靠栏开着轨迹观测、比例 0.85」(最大所存比例),1280×800 下读 `composer.bottom − dock.top`:**改前** 空输入区 **122px**(停靠栏 655px,鼠标落在输入区正中命中的是停靠栏的 header)、输入区涨到 7 行 **238px**、窗口压到 1280×560 **274px**,且 `textarea.click()` 被停靠栏挡下(Playwright 报 intercepts pointer events);**改后** 四态(空 / 涨到 7 行 / 1280×560 / 清空)**全是 0**,停靠栏随之让出 423 → 307 → 140 → 423,输入区正中命中 `textarea`,点击一次就进得去。截图 `r51/shots/{before,after}-{empty,grown,short,cleared}.png`(改前那张里输入区整块不见、只剩上方的上下文提示;改后那张里输入框完整地停在停靠栏上方);两态 console 各 **0 error**、**无一条 ≥400** · **相邻回归(真浏览器单 spec)**:`dock.spec.mjs` 10 条 + `mobile-dock.spec.mjs` 1 条 **11 passed(25.4s)**,其中被改视口的那条也在内 · **反证(同一份 spec,去掉这轮的视口改动)**:默认 1280×720 下「尺寸与排布在刷新后仍在」**1 failed**(`expect(after - before).toBeGreaterThan(80)`:默认高度已经顶到新上限,往上拖 120px 长不了)—— 与上游 PR 的说法一致 · 端口只用 8956 / 8957 / 8977 与单 spec 那套 8958 / 8978(跑完都已停),3003 / 3004 / 4000 / 7364 / 7369 一个没碰;数据只落在 `/root/adelie-fork-data/r51-{after,before,e2e}`,探针 / 两态产物 / 截图都在 scratchpad 的 `r51/` 下(`packages/*/dist`、`packages/web/test-results/` 都是产物,未 `git add`) | 见本行提交 || 2026-10-27 | 5.52 | **停靠面板只属于各自的 Session**(上游 `ce9b3e69` `#1335` 移植,照改动落、不是合分支;上游 16 文件 / +377 −85 → 本树落下 **9 个跟踪文件(7 改 2 补测试)** + changelog 一对,另 9 行是 `dock-state.ts` 里把写 scope 映射那段收成 `writeScopes()`):`useSessionStream` 的 `SessionStreamState` 多一个 `sessionId`(写明下面这些状态属于哪个 Session),`advancePanelTaskScope` 忽略「观察到的流不是这个 Session」的那次渲染(切换后的一次渲染仍带着上一个 Session 的模型与任务状态),chat page 只在 `currentDockScope()` 就是该 Session 时才自动打开子智能体面板;`adoptDockScope(from, sessionId, stillOpen)` 只移交 `from` 自己的布局、不碰屏幕上的那份,并返回「用户是否仍在 `from` 上」,草稿首次发送(发送开始时记下 `dockScope`、`openRef` 记页面是否还挂着)与自愈的 `syncHealedSessionId` 据此才 `navigate`;交给面板的四个请求(`fileOpenRequest` / `memoryRequest` / `subagentFocus` / `subagentTaskScope`)改为**渲染期**按路由丢弃(`commandsFor`)而不是渲染后靠效果清除;`dock-panel.tsx` 的 `closeWhenAllowed(key)` 记住发起关闭时的 scope,答复回来时只在仍是同一对话才关;`browser-layer.tsx` 的「面板显示时保留一个标签页」改为在效果里读**当下**的停靠栏(`isTabShown(BROWSER_TAB)`)。**有意未取**(本树没有它们要用的东西):与 `state.scope` 比对的那半(要上游 #1105 的按会话分片标签页)、`terminal-panel.tsx` 的 `dockSessionId()` 重核、自愈里的 `adoptBrowserSession` / `reownTerminals`、它的 jsdom 用例(本树不装 jsdom) | 六包 `typecheck` **`EXIT=0`**(六个 `Done`;`gen:ifaces` 报 **`src/ifaces.json unchanged`**,195 接口 / 590 类型)· `npx oxlint` 9 个文件 **0 警告 0 错误** · 九个源码 / 用例文件与一对 changelog `prettier --check` 干净 · `git diff --check` 干净 · 逐包 test **`EXIT=0`、0 失败**:core **1425** / 6 跳过(70 文件)· ui **1053**(130)· cli **561**(38)· server **204 文件 / 2995 通过 / 4 跳过** · web **270 文件 / 3295 通过 / 2 跳过**(本笔 +3 用例)· hmr 无测试文件 · **反证(单测)**:把 7 份源码退回 `HEAD`、只留新用例 → `dock-state.test.ts` + `panel-task-scope.test.ts` **5 failed / 48 passed**(三条新的 `adoptDockScope` 用例、既有的「移交时不覆盖」与其 fullscreen 版、以及「忽略上一个 Session 的流」那条),放回本笔 → **53 全过** · **本轮主证据(真服务端 ×2 + 真浏览器,两态同一套探针)**:本笔只动 web,两态 web 产物 `r138/{after,before}-dist`(主包 md5 `480cebb2…` / `7a1de418…`,两端核过确实是两份不同的东西)挂在两个一次性数据根 `/root/adelie-fork-data/r138-{after,before}` 上、**改后 8961 / 改前 8962**(`ADELIE_SEED_ADMIN_PASSWORD`,模型指向本仓自带 mock LLM 8971;空数据根不需要模型 key —— 即 3.6 那个卡点)。流程:会话 A 里发「run a subagent」(mock 的派生子智能体触发词)→ 等 A 自己的停靠栏出现子智能体标签 → 点侧栏里另一条空会话 B(**应用内路由切换**,整页刷新复现不了这个泄漏)→ 读 `penguin.dock.layout`。**改前**:`A=["agents"]`、切过去的 **`B=["agents"]`**(截图 `r138/shots/before-2-switched-to-b.png`:空会话右侧栏挂着「智能体面板」,上面写着「本次任务尚未派生子智能体」),回到 A 后 B 仍留着;**改后**:`A=["agents"]`、**`B=[]`**(`after-2-switched-to-b.png`:干净的新对话),回到 A 照旧是 `["agents"]` 且调用关系与子会话都在(`after-3-back-in-a.png`)。两态 console 各只有一条 403(`/api/projects/…/machines`,**两态一模一样**、属非管理员账号的既有行为,与本轮无关),无其它错误 · **相邻回归(真浏览器四个 spec)**:`dock` 10 + `mobile-dock` 1 + `draft` 1 + `subagent` 4(含「每块面板跟着自己的会话、不泄漏」与「auto-open 生命周期 / 草稿流」两条正对本轮)**18 passed(1.2m)** · 端口只用 8961 / 8962 / 8971 与相邻回归那套 8930 / 8931(跑完都已停),3003 / 3004 / 4000 / 7364 / 7369 一个没碰;数据只落在 `/root/adelie-fork-data/r138-{after,before,e2e}`,探针 / 两态产物 / 截图都在 scratchpad 的 `r138/` 下(`packages/web/dist`、`packages/web/test-results/` 都是产物,未 `git add`) | 见本行提交 |+| 2026-10-27 | 5.53 | **流式回复时向上滚,视图不再被拽回底部**(上游 `0c7725c2` `#1250` 移植,照改动落、不是合分支;上游 8 文件 / +523 −34 → 本树落下 **7 个跟踪文件(3 改 3 新 1 补测试)** + changelog 一对):三条成因、三处修法 —— ①`message-stream.tsx` 的滚轮改由**原生非被动**监听器接管(effect 里 `addEventListener("wheel", …, { passive: false })`、从不 `preventDefault`,React 的 `onWheel` 删掉),浏览器先把手势第一格交给页面再滚动,跟随因此在视图移动之前就关了;②`stream-follow.ts` 的 `scrolled()` 只在位置真的变了时才恢复跟随(`dist < 80 && m.scrollTop !== prev`),先前一次贴底自己晚一帧、位置未变的滚动事件不再在读着向上滚之后把跟随打开;③新增 `observed()` + `followToBottom()`(提交 effect、ResizeObserver、选区菜单放行三处都改用它):贴底之前先按「那条滚动事件将会读到的样子」判一次实时位置,浏览器已执行但未报告的滚动(按键 / 滚动条 / 大纲跳转)不再被撤销,而 `observed()` 在任何位置都还没报告过时(刚进对话)不置一词,否则打开在底部的对话会被判成停住、永不贴底。**有意未取**:上游 F4(`.ui-stream [data-arrive] { overflow-anchor: none }`)—— 本树没有逐段到达的元素(`fade` 是按速率放出回复前缀,见 `stream-reveal.ts`),两态实测里 Frost 也没有只由锚点造成的漂移;另给转写区滚动容器加 `data-stream-scroll`(新 spec 要逐帧看这个元素,本树没有上游的 `data-find-region="conversation"`) | 六包 `typecheck` **`EXIT=0`**(六个 `Done`;`gen:ifaces` 报 **`src/ifaces.json unchanged`**,195 接口 / 590 类型)· `npx oxlint` 5 个改动文件 **0 警告 0 错误** · 5 个源码 / 用例文件与一对 changelog `prettier --check` 干净 · `git diff --check` 干净 · 逐包 test **`EXIT=0`、0 失败**:core **1425** / 6 跳过(70 文件)· ui **1053**(130)· cli **561**(38)· server **204 文件 / 2995 通过 / 4 跳过** · web **270 文件 / 3299 通过 / 2 跳过**(本笔 +4 用例)· hmr 无测试文件 · **反证(三处定向变异,各自只压中自己那条用例)**:只把 ② 退回 `if (dist < 80) stick = true;` → `stream-follow.test.ts` **1 failed / 19 passed**(「手势起在贴底与它的滚动事件之间」那条,`expected true to be false`);去掉 `followToBottom` 里的 `observed()` → **1 failed**(「浏览器已经移上去、还没报告」那条);让 `observed()` 第一次读数也参与判定 → **1 failed**(「刚进对话时第一次读数不置一词」那条);还原后 **20 全过**;另把整份 `stream-follow.ts` 退回 `HEAD` → **4 failed**(含 `followToBottom is not a function`)· **本轮主证据(真服务端两态 × 真浏览器,同一份 spec 同一套 mock)**:本笔只动 web,两态 web 产物 `r140/{after,before}-dist`(主包 md5 `7d28025e…` / `26a306b1…`;两端核过确实是两份不同的东西 —— `observed` 出现 2 / 0 次、`passive:!1` 7 / 6 处、`onWheel` 2 / 3 处)挂在两个一次性数据根 `/root/adelie-fork-data/r140-{after,before}` 上、**改后 8982 / 改前 8983**(`ADELIE_SEED_ADMIN_PASSWORD`,模型指向本仓自带 mock LLM 8981;空数据根不需要模型 key —— 即 3.6 那个卡点)。`scroll-follow-bounce.spec.mjs` 每个主题 6 个手势、渲染进程降速四倍:**改前 Primer 5/6 · Frost 6/6 · Console 5/6 = 16/18 个手势回弹**(`late-snap` 与 `composed` 两类,日志 `r140/before-run.log`),**改后 18/18 个手势 0 回弹、`stillDrift` 全 0**(三主题各 6 个手势,1.6 min 跑完,三个 `✓`),`textMovedDown` 141–500px 说明滚轮的确把文字往上带了、不是空测 · **console**:改后态另起探针打开同一条会话、发一条真消息、滚轮上滚 5 格(`r140/probe.mjs`),`scrollTop` 620 → 320(正好 −300)而回复从 1153 涨到 2855,页面只有一条 **403 `/api/projects/…/machines`**(非管理员账号的既有行为,改前态一模一样),**无其它 error、无 pageerror**;截图 `r140/shots/after-chat.png`(流式回复、布局、底部输入区都正常)· **相邻回归(真浏览器)**:`chat` 1 + `outline` 2 + `selection-menu` 2(含「打开的选区菜单扣住实时回复的自动跟随、关闭后追平」那条正压在 `followToBottom` 上)**5 passed(1.0m)** · 端口只用 8981 / 8982 / 8983(跑完都已停),3003 / 3004 / 4000 / 7364 / 7369 一个没碰;数据只落在 `/root/adelie-fork-data/r140-{after,before}`,两态产物 / 日志 / 探针 / 截图都在 scratchpad 的 `r140/` 下(`packages/web/dist`、`packages/web/test-results/` 都是产物,未 `git add`) | 见本行提交 |> **2026-10-11 与另一条线的交汇(第三十七轮)**:定时任务触发时(07:00)`git status --short` **不干净**@@ -16989,3 +17006,100 @@ sandbox-dsh 21(+1 跳过)· sandbox-bwrap 29。- 上次发版 **`v0.5.8`**(2026-10-26 23:07 CST)。自那以后 `main` 上 10 个提交,其中**功能性 3 个**(`eaf62138` 5.50、`9d661d8f` 5.51、`ec337e6c` 5.52),其余是台账与 changelog。- **3 < 10 → 不发版**,不动版本号。++## 第一百四十轮:流式回复时向上滚,视图不再被拽回底部(2026-10-27,条目 5.53)++### 开工自检++- `/root/adelie-fork` 在 `main` 上,`git status --short` **干净**;`HEAD` = **`573588d3`**,与+ `origin/main` 齐(`git fetch` 后 `Already up to date`)。没切分支、没碰 `legacy/main`、没推 upstream。+- 全程 `git status --porcelain` 只有本笔自己的文件,没撞上别的会话。+- **为什么不是表上第一条未勾选的 2.2c**:它还差的三件全在纪律之内做不了 —— 写侧剩下的六个别名全在+ `packages/desktop`(本轮明令不碰桌面壳,依赖没装)、`adelie-app.service` 那台既有单元属发布动作、+ 第四件(画廊 mock 与 `packages/docs`)是第十三轮有意留到发布期的。所以按第一百三十八轮末尾写下的+ 「下一轮:`0c7725c2`」走,那正是本轮这一条。++### 改了什么++- 上游 `0c7725c2`(#1250,8 文件 / +523 −34)照改动落,不是合分支。落下 **7 个跟踪文件**(3 改 3 新+ 1 补测试)+ changelog 一对(按本仓写法改名到本轮日期、去掉上游 PR 行、写明移植来源)。+- `packages/web/src/features/chat/message-stream.tsx`:滚轮改由原生非被动监听器接管(一个 effect 里+ `addEventListener("wheel", …, { passive: false })`,从不 `preventDefault`),React 的 `onWheel` 删掉;+ 三处贴底改走 `followToBottom`;转写区滚动容器加 `data-stream-scroll`。+- `packages/web/src/features/chat/stream-follow.ts`:`scrolled()` 只在位置真的变了时恢复跟随;+ 新增 `observed()` 与 `followToBottom()`(贴底前先按「那条滚动事件将会读到的样子」判一次实时位置,+ 任何位置都还没报告过时不置一词)。+- `packages/web/e2e/scroll-follow-bounce.spec.mjs`(新,306 行):三主题 × 6 手势,逐帧记录滚动位置、+ 滚轮事件与程序发起的滚动;`packages/web/e2e/mock-llm.mjs` 加「scroll bounce test」分支(每 50ms+ 一段三行,共 80 段);`packages/web/test/stream-follow.test.ts` 加三条用例。+- **合并时三处冲突这样解**:`packages/ui/src/theme.css` 取本树(上游那段 `.ui-stream [data-arrive]`+ 本树没有 → 见下);`message-stream.tsx` 只取新的滚轮 effect,上游上下文里带着的「查找栏加载更早」+ effect(`FIND_LOAD_OLDER_EVENT`)本树没有那个功能、不引入;`mock-llm.mjs` 的头注释保留本树的+ 「read deep path test」、只加上「scroll bounce test」(上游同段的「sticky rows test」本树没有该+ spec,不加)。++### 有意未取++- **上游 F4**(Frost 里 `[data-arrive]` 的 `overflow-anchor: none`):本树没有「逐段到达」的元素 ——+ 它的 `fade` 是按速率放出回复文本的前缀(`packages/ui/src/components/chat/assistant-text/stream-reveal.ts`),+ 不存在那段被浏览器锚定的 span。两态实测也印证:改前 Frost 的 6/6 回弹全是 `late-snap` / `composed`,+ 没有只由锚点造成的漂移;改后在三主题、含 Frost 在内 18/18 手势 **stillDrift 全 0**。+- 上游 spec 用的 `[data-find-region="conversation"]` 本树没有(本树没有查找栏),故给滚动容器加+ `data-stream-scroll` —— 与 5.51 的 `[data-dock-area]` 同一做法(只为取证挂的惰性属性)。++### 验证(都不是推测)++- 六包 `typecheck` **`EXIT=0`**(六个 `Done`;`gen:ifaces` 报 **`src/ifaces.json unchanged`**,+ 195 接口 / 590 类型 —— 本笔不动服务契约)。+- 逐包 test **`EXIT=0`、0 失败**:core **1425** / 6 跳过(70 文件)· ui **1053**(130)·+ cli **561**(38)· server **204 文件 / 2995 通过 / 4 跳过** · web **270 文件 / 3299 通过 / 2 跳过**+ (比上一轮 +4,即三条新用例 + 既有一条的分组变化)· hmr 无测试文件。+- `npx oxlint` 五个改动文件 **0 警告 0 错误**;五个源码 / 用例文件与一对 changelog `prettier --check`+ 干净;`git diff --check` 干净。+- **反证(三处定向变异,各自只压中自己那条用例)**:+ ① 只把 `scrolled()` 退回 `if (dist < 80) stick = true;` → **1 failed / 19 passed**,挂在「手势起在+ 贴底与它的滚动事件之间」那条(`expected true to be false`);+ ② 去掉 `followToBottom` 里的 `observed()` → **1 failed**,挂在「浏览器已经移上去、还没报告」那条;+ ③ 让 `observed()` 的第一次读数也参与判定 → **1 failed**,挂在「刚进对话时第一次读数不置一词」那条;+ 还原后该文件 **20 全过**。另把整份 `stream-follow.ts` 退回 `HEAD` → **4 failed**(含+ `followToBottom is not a function`)—— 说明新用例确实压在本笔的行为上,不是空转。+- **本轮主证据(真服务端两态 × 真浏览器,同一份 spec、同一套自带 mock)**:本笔只动 web,两份 web 产物+ `r140/{after,before}-dist`(主包 md5 `7d28025ebdde6e56916e4dd66d7ebd98` /+ `26a306b1bad3974165a77c7cfa964fd9`;两端核过确实是两份不同的东西:`observed` 出现 2 / 0 次、+ `passive:!1` 7 / 6 处、`onWheel` 2 / 3 处;`before` 那份是在把两个源码文件退回 `HEAD` 后单独重建的,+ 只额外保留了 `data-stream-scroll` 这一个惰性属性,让同一份 spec 两态都能拿到滚动容器)分别挂在两个+ 一次性数据根 `/root/adelie-fork-data/r140-{after,before}` 上,**改后 `localhost:8982`、改前+ `localhost:8983`**(`ADELIE_SEED_ADMIN_PASSWORD=penguin-2026` + 登录拿 cookie;模型指向本仓自带+ mock LLM 的 8981,空数据根不需要模型 key —— 即 3.6 那个卡点)。+ `scroll-follow-bounce.spec.mjs` 每个主题 6 个手势、`Emulation.setCPUThrottlingRate 4`:+ **改前 Primer 5/6 · Frost 6/6 · Console 5/6 = 16/18 个手势回弹**(种类是 `late-snap` 与 `composed`,+ 逐条在 `r140/before-run.log` 里,例如 Primer 手势 4:`t=20/98/165` 三次迟到贴底 + 一帧 `composed`);+ **改后三主题 6/6/6 全 0 回弹**、`stillDrift` 每次都是 0、`grewWhileStill` 1500–1800px(说明+ 手势之后回复确实还在长),三个测试各 `✓`,合计 **18/18 干净(1.6 min)**。+- **console**:改后态另用探针(`r140/probe.mjs`)打开一条真会话、发一条消息、等它长到需要滚动且仍贴在+ 底部,再滚轮上滚 5 格:`scrollTop` 620 → 320(正好 −300 = 5×60),同一时间 `scrollHeight` 从 1153+ 涨到 2855 —— 文字一直往下长、视图停在读者留下的位置。页面**只有一条 403**+ (`GET /api/projects/…/machines`,非管理员账号的既有行为,改前态一模一样),**无其它 error、+ 无 pageerror**;截图 `r140/shots/after-chat.png`(流式回复、布局、底部输入区都正常)。+- **相邻回归(真浏览器)**:`chat` 1 + `outline` 2 + `selection-menu` 2 —— **5 passed(1.0m)**,+ 其中 `selection-menu` 那条「打开的选区菜单扣住实时回复的自动跟随、关闭后追平」正压在+ `followToBottom` 上(选区菜单放行是三个调用点之一)。+- 端口只用 8981 / 8982 / 8983(跑完都已停),3003 / 3004 / 4000 / 7364 / 7369 一个没碰;数据只落在+ `/root/adelie-fork-data/r140-{after,before}`,两态产物、日志、探针、截图都在 scratchpad 的 `r140/`+ 下(`packages/web/dist`、`packages/web/test-results/` 是产物,未 `git add`)。++### 没做 / 还差什么++- **上游 spec 里「合成器自己的帧」仍然看不见**(上游自己也是这么写的):spec 只看页面能看到的东西+ (主线程帧、滚轮事件、`scrollTop` 的写入)。已经提交但尚未激活的那一帧与滚轮首帧的竞争,从 JavaScript+ 里测不到;本轮的结论只覆盖「主线程能看到的那几种签名」从 16/18 变成 0/18。+- **2.2c 仍不能勾**:剩下的三件(桌面壳一侧六个变量、`adelie-app.service`、画廊 mock 与 `docs` 的+ 文本)都在本轮纪律之外,理由见「开工自检」。+- 下一轮:`12a58d4f` 之后那几笔要新前置的(`#1272` / `#1268` 的 API socket 面);再往后若要坐实+ 5.52 里浏览器标签页那一半,得先把上游 #1105 的按会话分片标签页立起来。++### 版本:未到阈值++- 上次发版 **`v0.5.8`**(2026-10-26 23:07 CST)。自那以后 `main` 上的提交里功能性的是 5.50 / 5.51 /+ 5.52 与本轮 5.53,远不到 10。+- 不动版本号、不发 npm、不发安装包。diff --git a/packages/web/e2e/mock-llm.mjs b/packages/web/e2e/mock-llm.mjsindex 5aaf6078..acf785a3 100644--- a/packages/web/e2e/mock-llm.mjs+++ b/packages/web/e2e/mock-llm.mjs@@ -30,6 +30,8 @@* (reload-midstream.spec reloads while the TEXT streams)* - "read deep path test <path>" -> tool_use(read_file) on <path>, then a short final text* (path-hints.spec: the card's shortened subtitle keeps the whole path one hover away)+ * - "scroll bounce test" -> a three-line paragraph every 50ms for ~4s, for every request of+ * that conversation (scroll-follow-bounce.spec wheels up while each reply streams)* - last message has tool_result -> final text (turn 2)* - otherwise (first user turn) -> thinking + text + tool_use(exec_command)*/@@ -639,6 +641,39 @@ const server = http.createServer((req, res) => {return;}+ // Scroll-bounce test case (scroll-follow-bounce.spec): a reply that grows by a visible step+ // on every commit — one three-line paragraph every 50ms for ~4s — so the reader can wheel up+ // from the bottom while the transcript is still following new text. Every request of that+ // conversation answers this way, so the spec can stream one reply per gesture.+ if (flat.includes("scroll bounce test")) {+ sse(res, "content_block_start", {+ type: "content_block_start",+ index: 0,+ content_block: { type: "text", text: "" },+ });+ const filler =+ "The transcript keeps following this reply while it grows, and a reader who scrolls " ++ "up from the bottom must stay exactly where the gesture left them, however much text " ++ "arrives below, until they scroll back down or press the button that returns them.";+ let n = 0;+ const tick = () => {+ n += 1;+ sse(res, "content_block_delta", {+ type: "content_block_delta",+ index: 0,+ delta: { type: "text_delta", text: `Paragraph ${n}. ${filler}\n\n` },+ });+ if (n < 80) {+ setTimeout(tick, 50);+ } else {+ sse(res, "content_block_stop", { type: "content_block_stop", index: 0 });+ messageStop(res, "end_turn", 4000);+ }+ };+ tick();+ return;+ }+if (wantsSubagent && !hasToolResult) {block(res, 0, { type: "tool_use", id: "toolu_mock_sub", name: "run_subagent", input: {} }, [{ type: "input_json_delta", partial_json: '{"prompt": ' },diff --git a/packages/web/e2e/scroll-follow-bounce.spec.mjs b/packages/web/e2e/scroll-follow-bounce.spec.mjsnew file mode 100644index 00000000..198afba1--- /dev/null+++ b/packages/web/e2e/scroll-follow-bounce.spec.mjs@@ -0,0 +1,306 @@+/**+ * Scrolling up while a reply streams: the transcript must not bounce back down.+ *+ * In each theme (Primer shows each commit at once, so the commit snaps the view; Frost and+ * Console grow the reply every reveal frame, so the resize observer snaps it):+ *+ * - Given a reply streaming a paragraph every 50ms with the view following the bottom, and a+ * renderer slowed four times, when the reader wheels up from the bottom in small steps, the+ * view never moves back down: no snap to the bottom lands after the browser was free to put+ * the gesture on screen, no frame shows a snap composed with the gesture, and once the+ * gesture has moved the text down no frame moves it back up.+ * - For the second after the gesture, while the reply keeps growing below, the text on screen+ * does not move at all: following stays off until the reader scrolls back down.+ *+ * The page records, while armed, every animation frame (the transcript's scrollTop and where a+ * paragraph that was on screen when the gesture began sits in the viewport), every wheel event+ * and every programmatic scrollTop write on the transcript. One line per gesture is printed+ * with the prefix BOUNCE (BOUNCE_DUMP=1 adds the raw recording); BOUNCE_GESTURES overrides the+ * number of gestures per theme, 6 by default.+ *+ * The browser scrolls a wheel the page cannot cancel on the compositor at once and tells the+ * page later; one the page can cancel waits until the page has handled it. A snap is late when+ * it raises scrollTop after that point — the first wheel's creation, or its handling — since+ * it then lands on a gesture the screen may already show. These are what the page can observe:+ * the compositor's own frames are not visible to it.+ */+import { test, expect } from "@playwright/test";+import { provisionAndLogin, login } from "./auth.mjs";++const BASE = process.env.BASE_URL;+const MOCK = process.env.MOCK_URL;+const USER = "scrollbounce";+const PASSWORD = "password123";+const GESTURES = Number(process.env.BOUNCE_GESTURES ?? 6);+/** The three themes: stored id → name. */+const THEMES = { github: "Primer", modern: "Frost", geek: "Console" };+/** The transcript's scroller (message-stream.tsx marks it for the specs that watch a gesture). */+const SCROLLER = "[data-stream-scroll]";++test.use({ viewport: { width: 1280, height: 720 } });++let projectId;++test.beforeAll(async ({ browser }) => {+ const page = await browser.newPage();+ await provisionAndLogin(page.request, USER, PASSWORD);+ projectId = (await (await page.request.get(`${BASE}/api/projects`)).json()).projects[0].projectId;+ const models = await page.request.put(`${BASE}/api/projects/${projectId}/models`, {+ data: {+ defaultModel: { provider: "custom", modelId: "claude-4-8" },+ models: [+ {+ provider: "custom",+ modelId: "claude-4-8",+ apiKey: "sk-mock",+ baseUrl: MOCK,+ contextWindow: 200000,+ },+ ],+ },+ });+ expect(models.ok(), await models.text()).toBeTruthy();+ await page.close();+});++/** Page side: the recorder, installed once the transcript has mounted. */+function installRecorder(selector) {+ const el = document.querySelector(selector);+ const native = Object.getOwnPropertyDescriptor(Element.prototype, "scrollTop");+ const rec = { on: false, frames: [], wheels: [], writes: [] };+ /** Paragraph identities, so a frame can say where the same text sat in the one before. */+ const ids = new WeakMap();+ let nextId = 0;+ /** [id, top] of each paragraph on screen: what the reader sees, wherever the anchor is. */+ const onScreen = () => {+ const box = el.getBoundingClientRect();+ const ps = el.querySelectorAll("p");+ const seen = [];+ for (let i = Math.max(0, ps.length - 60); i < ps.length; i += 1) {+ const r = ps[i].getBoundingClientRect();+ if (r.bottom <= box.top || r.top >= box.bottom) continue;+ if (!ids.has(ps[i])) ids.set(ps[i], (nextId += 1));+ seen.push([ids.get(ps[i]), r.top]);+ }+ return seen;+ };+ Object.defineProperty(el, "scrollTop", {+ configurable: true,+ get() {+ return native.get.call(this);+ },+ set(value) {+ const before = native.get.call(this);+ native.set.call(this, value);+ if (rec.on) rec.writes.push({ t: performance.now(), before, after: native.get.call(this) });+ },+ });+ window.addEventListener(+ "wheel",+ (e) => {+ if (!rec.on) return;+ rec.wheels.push({ t: performance.now(), ts: e.timeStamp, cancelable: e.cancelable });+ },+ { capture: true, passive: true },+ );+ const frame = () => {+ if (rec.on) {+ rec.frames.push({+ t: performance.now(),+ top: native.get.call(el),+ h: el.scrollHeight,+ seen: onScreen(),+ });+ }+ requestAnimationFrame(frame);+ };+ requestAnimationFrame(frame);+ window.__bounce = {+ start() {+ rec.frames = [];+ rec.wheels = [];+ rec.writes = [];+ rec.on = true;+ },+ stop() {+ rec.on = false;+ return { frames: rec.frames, wheels: rec.wheels, writes: rec.writes };+ },+ toBottom() {+ el.scrollTop = el.scrollHeight;+ },+ following(minHeight) {+ return (+ el.scrollHeight > minHeight && el.scrollHeight - native.get.call(el) - el.clientHeight <= 1+ );+ },+ height() {+ return el.scrollHeight;+ },+ };+}++/**+ * The bounces in one gesture's recording, by kind (see the header), and what the gesture did;+ * `stillFrom` starts the stay-put window.+ */+function analyze({ frames, wheels, writes }, stillFrom) {+ const first = wheels[0];+ if (first === undefined) return { bounces: [{ kind: "no-wheel" }] };+ const freeAt = first.cancelable ? first.t : first.ts;+ const rising = writes.filter((w) => w.after > w.before + 0.5);+ const bounces = rising+ .filter((w) => w.t >= freeAt)+ .map((w) => ({+ kind: "late-snap",+ t: Math.round(w.t - first.ts),+ from: w.before,+ to: w.after,+ }));+ /** How far the text on screen moved down since the frame before (the median paragraph). */+ const moved = (prev, f) => {+ const was = new Map(prev.seen);+ const d = f.seen.filter(([id]) => was.has(id)).map(([id, top]) => top - was.get(id));+ if (d.length === 0) return 0;+ d.sort((x, y) => x - y);+ return d[Math.floor(d.length / 2)];+ };+ let movedDown = false;+ let travel = 0;+ const path = [];+ for (let i = 1; i < frames.length; i += 1) {+ const prev = frames[i - 1];+ const f = frames[i];+ if (f.t < first.ts) continue;+ const snap = rising.filter((w) => w.t >= prev.t && w.t <= f.t).at(-1);+ if (f.top > prev.top + 0.5 && snap !== undefined && f.top < snap.after - 0.5) {+ bounces.push({+ kind: "composed",+ t: Math.round(f.t - first.ts),+ snap: snap.after,+ to: f.top,+ });+ }+ const d = moved(prev, f);+ travel += d;+ path.push({ t: f.t, travel });+ if (d > 0.5) movedDown = true;+ else if (movedDown && d < -0.5) {+ bounces.push({ kind: "after-up", t: Math.round(f.t - first.ts), by: -d });+ }+ }+ const still = path.filter((p) => p.t >= stillFrom).map((p) => p.travel);+ const tail = frames.filter((f) => f.t >= stillFrom);+ return {+ bounces,+ firstWheelCancelable: first.cancelable,+ wheelLatency: Math.round(first.t - first.ts),+ textMovedDown: Math.round(still[0] ?? travel),+ stillDrift: still.length > 0 ? Math.max(...still) - Math.min(...still) : null,+ grewWhileStill: tail.length > 0 ? tail[tail.length - 1].h - tail[0].h : 0,+ };+}++/** Waits until `want` replies have shown their paragraph `n`. */+const paragraphShown = (page, n, want) =>+ page.waitForFunction(+ ([selector, n, want]) =>+ [...document.querySelectorAll(`${selector} p`)].filter((p) =>+ p.textContent.startsWith(`Paragraph ${n}.`),+ ).length >= want,+ [SCROLLER, n, want],+ { polling: 100, timeout: 30_000 },+ );++for (const [theme, name] of Object.entries(THEMES)) {+ test(`${name}: wheeling up while a reply streams never moves the view back down`, async ({+ page,+ }) => {+ test.setTimeout(60_000 + GESTURES * 20_000);+ await page.addInitScript((id) => localStorage.setItem("penguin.themeId", id), theme);+ await login(page.request, USER, PASSWORD);+ const created = await page.request.post(+ `${BASE}/api/projects/${projectId}/agents/default_agent/sessions`,+ { data: { provider: "custom", modelId: "claude-4-8", approvalMode: "allow-all" } },+ );+ expect(created.ok(), await created.text()).toBeTruthy();+ const sessionId = (await created.json()).session.sessionId;+ await page.goto(`/chat/${sessionId}`);+ const input = page.getByPlaceholder(/输入消息/);+ await input.waitFor();++ const cdp = await page.context().newCDPSession(page);+ const results = [];+ for (let i = 1; i <= GESTURES; i += 1) {+ await input.fill(`scroll bounce test ${i}`);+ await page.keyboard.press("Enter");+ await paragraphShown(page, 6, i);+ if (i === 1) {+ // The transcript mounts with the conversation's first message.+ await page.evaluate(installRecorder, SCROLLER);+ const box = await page.locator(SCROLLER).boundingBox();+ await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);+ }+ await cdp.send("Emulation.setCPUThrottlingRate", { rate: 4 });+ // Following: put the view at the bottom and watch it stay there while the reply grows.+ // A commit can land between the jump and its scroll event and leave the view short of+ // the bottom, not following; the jump is then simply taken again.+ await expect+ .poll(+ async () => {+ await page.evaluate(() => window.__bounce.toBottom());+ const h0 = await page.evaluate(() => window.__bounce.height());+ return page+ .waitForFunction((h) => window.__bounce.following(h + 200), h0, {+ polling: "raf",+ timeout: 1500,+ })+ .then(+ () => true,+ () => false,+ );+ },+ { timeout: 10_000, intervals: [0] },+ )+ .toBe(true);+ await page.evaluate(() => window.__bounce.start());+ // Following was just confirmed on a commit, so start each gesture at a different point of+ // the commit cycle (a golden-ratio walk over 0–140ms): the race is with the next commit.+ await page.waitForTimeout(100 + Math.round(((i * 0.618034) % 1) * 140));+ for (let k = 0; k < 10; k += 1) {+ await page.mouse.wheel(0, -50);+ await page.waitForTimeout(30);+ }+ await page.waitForTimeout(400);+ const stillFrom = await page.evaluate(() => performance.now());+ await page.waitForTimeout(1000);+ const recording = await page.evaluate(() => window.__bounce.stop());+ await cdp.send("Emulation.setCPUThrottlingRate", { rate: 1 });+ const r = { theme: name, gesture: i, ...analyze(recording, stillFrom) };+ results.push(r);+ console.log(`BOUNCE ${JSON.stringify(r)}`);+ if (process.env.BOUNCE_DUMP) console.log(`BOUNCE-DUMP ${JSON.stringify(recording)}`);+ // The reply finishes before the next one is sent.+ await paragraphShown(page, 80, i);+ await expect(page.getByRole("button", { name: "停止", exact: true })).toHaveCount(0, {+ timeout: 30_000,+ });+ }++ const bounced = results.filter((r) => r.bounces.length > 0).length;+ console.log(`BOUNCE-SUMMARY ${name}: ${bounced}/${results.length} gestures bounced`);+ for (const r of results) {+ expect.soft(r.bounces, `gesture ${r.gesture}: bounced`).toEqual([]);+ expect+ .soft(r.textMovedDown, `gesture ${r.gesture}: the wheel scrolled up`)+ .toBeGreaterThan(100);+ expect+ .soft(r.stillDrift, `gesture ${r.gesture}: moved after the gesture`)+ .toBeLessThanOrEqual(0.5);+ }+ // The stay-put window means something only while the reply still grows below it.+ expect(results.filter((r) => r.grewWhileStill > 0).length).toBeGreaterThanOrEqual(+ Math.ceil(results.length / 2),+ );+ });+}diff --git a/packages/web/src/features/chat/message-stream.tsx b/packages/web/src/features/chat/message-stream.tsxindex 50bdd7fc..422fd399 100644--- a/packages/web/src/features/chat/message-stream.tsx+++ b/packages/web/src/features/chat/message-stream.tsx@@ -18,7 +18,7 @@ import type { PendingApproval } from "./use-session-stream";import { MessageItem } from "./message-item";import { WorkspaceLinksProvider } from "./workspace-links";import { SessionWorkGroup, isWorkItem } from "./work-group";-import { createStreamFollow, stickToBottom } from "./stream-follow";+import { createStreamFollow, followToBottom, stickToBottom } from "./stream-follow";import type { StreamFollow } from "./stream-follow";import type { ForkTarget } from "./task-stats-line";import { useStreamSelectionMenu } from "./stream-selection-menu";@@ -335,7 +335,7 @@ export function MessageStream({follow.hold(menuOpen);if (menuOpen) return;const el = scrollRef.current;- if (el && follow.snaps && !returningRef.current) stickToBottom(el, follow);+ if (el && !returningRef.current) followToBottom(el, follow);syncJump();// syncJump is recreated per render; the effect keys on the menu's open state only.// eslint-disable-next-line react-hooks/exhaustive-deps@@ -348,7 +348,9 @@ export function MessageStream({// Every snap goes through stickToBottom, which reports the landed position to the follow// model synchronously — the snap's async scroll event otherwise races late content growth// and could misinitialize follow as "parked above the bottom" right after entering a- // conversation (see stream-follow.ts).+ // conversation (see stream-follow.ts). A following view's snap goes through followToBottom,+ // which first judges the live position, so a scroll the browser has applied but not yet+ // reported (a key, the scrollbar, a find or outline jump) is never undone.useLayoutEffect(() => {const el = scrollRef.current;// Prepend scroll anchoring: when older windows land ABOVE the viewport, keep the@@ -374,7 +376,7 @@ export function MessageStream({}lastPrependedRef.current = prepended;if (el) lastHeightRef.current = el.scrollHeight;- if (el && follow.snaps && !returningRef.current) stickToBottom(el, follow);+ if (el && !returningRef.current) followToBottom(el, follow);if (el) recordAnchor(el);syncJump();// syncJump is recreated per render; the effect intentionally keys on stream growth only.@@ -393,7 +395,7 @@ export function MessageStream({if (!el || typeof ResizeObserver === "undefined") return;const ro = new ResizeObserver(() => {lastHeightRef.current = el.scrollHeight;- if (follow.snaps && !returningRef.current) stickToBottom(el, follow);+ if (!returningRef.current) followToBottom(el, follow);syncJump();});ro.observe(el);@@ -405,6 +407,28 @@ export function MessageStream({// eslint-disable-next-line react-hooks/exhaustive-deps}, [follow]);+ // The wheel is heard natively, by a listener that is not passive and never prevents the+ // default. React registers its wheel handlers as passive, and the browser then scrolls on the+ // compositor first and tells the page up to a frame later: a stream commit in between would+ // still follow, and its snap would pull the view back down under the reader's first upward+ // tick. A blocking listener makes the browser hand the page the first wheel event of a gesture+ // before it scrolls (the rest of the gesture stays asynchronous), so follow is off before the+ // view moves.+ useEffect(() => {+ const el = scrollRef.current;+ if (!el) return;+ const onWheel = (e: WheelEvent) => {+ follow.wheel(e.deltaY);+ if (e.deltaY < 0) cancelReturn(); // user takes over: the glide stops within a frame+ syncJump();+ };+ el.addEventListener("wheel", onWheel, { passive: false });+ return () => el.removeEventListener("wheel", onWheel);+ // cancelReturn and syncJump are recreated per render but read only refs, state setters and+ // the stable follow object.+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [follow]);+/** Back-to-bottom: glide down to the live bottom (reduced motion gets an instant jump); follow re-engages on arrival. */const jumpToLatest = () => {const el = scrollRef.current;@@ -460,11 +484,10 @@ export function MessageStream({onContextMenu={selectionMenu.hostProps.onContextMenu}onKeyDown={selectionMenu.hostProps.onKeyDown}onScroll={onScroll}- onWheel={(e) => {- follow.wheel(e.deltaY);- if (e.deltaY < 0) cancelReturn(); // user takes over: the glide stops within a frame- syncJump();- }}+ // data-stream-scroll: the transcript's scroller, for the browser specs that have to+ // watch a scroll gesture frame by frame (scroll-follow-bounce.spec.mjs) — those need+ // this element itself, not anything inside it.+ data-stream-scrollonTouchStart={(e) => {const t = e.touches[0];if (t) follow.touchStart(t.clientY);diff --git a/packages/web/src/features/chat/stream-follow.ts b/packages/web/src/features/chat/stream-follow.tsindex 4f596fca..9c06a94d 100644--- a/packages/web/src/features/chat/stream-follow.ts+++ b/packages/web/src/features/chat/stream-follow.ts@@ -9,10 +9,13 @@* an "80px from bottom" threshold — otherwise a short scroll area with less than 80px of* scrollable slack could never exit, and streaming updates would keep fighting the upward* gesture back and forth.- * - Resume: only resumes once the user brings the viewport back near the bottom (within 80px).- * Programmatic stick-to-bottom only happens while following (idempotent); content shrinking- * (e.g. a group collapsing) that clamps scrollTop downward while still touching the bottom- * (≤1px) doesn't count as scrolling up and doesn't change intent.+ * - Resume: only resumes once the user's own scroll brings the viewport back near the bottom+ * (within 80px). A scroll event that moved nothing changes nothing: a programmatic snap's own+ * event arrives a frame later with the position the snap already reported, and the user may+ * have started scrolling up in between, so reading it as "near the bottom" would undo that+ * intent and let the next streaming update snap the view back down under the gesture. Content+ * shrinking (e.g. a group collapsing) that clamps scrollTop downward while still touching the+ * bottom (≤1px) doesn't count as scrolling up.* - The first scroll event has no direction to judge from, so it initializes from position* (≥80px from bottom is treated as being at a historical position, i.e. not following) — this* doesn't depend on the call-ordering guarantee of "must stick to bottom programmatically right@@ -20,6 +23,10 @@* landed position synchronously: the snap's own scroll event only arrives at the next* rendering update, and content growing in between (an image decoding, a font swap) would* otherwise make that first event look like a historical position and wrongly exit follow.+ * - Live reading: the browser can move the view before it dispatches the scroll event that+ * reports the move (a key, the scrollbar, a find or outline jump), so a streaming snap first+ * judges the live position the way that event will (`observed`, via `followToBottom`) and+ * never undoes a move it has not been told about yet.* - Hold: something anchored to the content can hold the view still — the selection menu hangs* off a point in the stream, and a snap would move that point out from under it. A hold only* defers acting on the intent (`snaps`); it never changes the intent (`stick`), so the user's@@ -45,8 +52,14 @@ export interface StreamFollow {/** Touch drag: finger moving down = content scrolling up, exits follow. */touchMove(clientY: number): void;touchEnd(): void;- /** scroll event (user scrolling and programmatic stick-to-bottom share this path): moving up exits; otherwise nearing the bottom resumes; the first event initializes from position. */+ /** scroll event (user scrolling and programmatic stick-to-bottom share this path): moving up exits; moving down to near the bottom resumes; an event that moved nothing changes nothing; the first event initializes from position. */scrolled(m: ScrollMetrics): void;+ /**+ * A live reading of the position taken right before a snap, judged as its scroll event will+ * be. With no position reported yet there is nothing to judge it against, and it is ignored:+ * only a real scroll event or a snap may seed the model.+ */+ observed(m: ScrollMetrics): void;/** Explicit re-entry (the back-to-bottom button): resumes follow immediately — the caller scrolls to the bottom right after, and the resulting scroll event sees a bottom position, keeping it stuck. */resume(): void;}@@ -56,6 +69,20 @@ export function createStreamFollow(): StreamFollow {let held = false;let lastTop: number | null = null;let touchY: number | null = null;+ const scrolled = (m: ScrollMetrics) => {+ const dist = m.scrollHeight - m.scrollTop - m.clientHeight;+ const prev = lastTop;+ lastTop = m.scrollTop;+ if (prev === null) {+ stick = dist < 80;+ return;+ }+ if (m.scrollTop < prev && dist > 1) {+ stick = false;+ return;+ }+ if (dist < 80 && m.scrollTop !== prev) stick = true;+ };return {get stick() {return stick;@@ -79,19 +106,9 @@ export function createStreamFollow(): StreamFollow {touchEnd() {touchY = null;},- scrolled(m) {- const dist = m.scrollHeight - m.scrollTop - m.clientHeight;- const prev = lastTop;- lastTop = m.scrollTop;- if (prev === null) {- stick = dist < 80;- return;- }- if (m.scrollTop < prev && dist > 1) {- stick = false;- return;- }- if (dist < 80) stick = true;+ scrolled,+ observed(m) {+ if (lastTop !== null) scrolled(m);},resume() {stick = true;@@ -124,9 +141,21 @@ export interface ScrollContainer {*/export function stickToBottom(el: ScrollContainer, follow: StreamFollow): void {el.scrollTop = el.scrollHeight; // The browser clamps to the real bottom; read back the clamped value below.- follow.scrolled({- scrollTop: el.scrollTop,- scrollHeight: el.scrollHeight,- clientHeight: el.clientHeight,- });+ follow.scrolled(metricsOf(el));+}++/**+ * The snap a following view takes when the transcript grows or resizes (a stream commit, a+ * resize, the selection menu letting go): the live position is judged first (`observed`), so a+ * move the browser has made but not reported yet exits follow instead of being undone, and the+ * view snaps only if it still follows after that.+ */+export function followToBottom(el: ScrollContainer, follow: StreamFollow): void {+ if (!follow.snaps) return;+ follow.observed(metricsOf(el));+ if (follow.snaps) stickToBottom(el, follow);+}++function metricsOf(el: ScrollContainer): ScrollMetrics {+ return { scrollTop: el.scrollTop, scrollHeight: el.scrollHeight, clientHeight: el.clientHeight };}diff --git a/packages/web/test/stream-follow.test.ts b/packages/web/test/stream-follow.test.tsindex cd393508..ab8f22cf 100644--- a/packages/web/test/stream-follow.test.ts+++ b/packages/web/test/stream-follow.test.ts@@ -10,11 +10,21 @@* - A programmatic snap reports where it landed at once, so growth racing its scroll event* (entering a conversation, back-to-bottom) keeps follow; content that fits clamps to 0; a* real upward scroll right after still exits.+ * - The reader starts wheeling up between a snap and that snap's own delayed scroll event: the+ * event moved nothing, so follow stays off and the next streaming update does not snap.+ * - A streaming snap reads the live position first: a view the browser moved up without a+ * scroll event yet is left where it is and stops following; a view at the old bottom snaps+ * to the new one; before any position was reported (entering a conversation) the reading+ * decides nothing and the view still lands at the bottom.* - While held (the selection menu is open) the view does not snap, the user's own scrolling* still decides the intent, and the release catches a following view up.*/import { describe, expect, it } from "vitest";-import { createStreamFollow, stickToBottom } from "../src/features/chat/stream-follow";+import {+ createStreamFollow,+ followToBottom,+ stickToBottom,+} from "../src/features/chat/stream-follow";/** Short scroll area: content 500px, viewport 460px, scrollable slack only 40px (always under the 80px threshold). */const SHORT = { scrollHeight: 500, clientHeight: 460 };@@ -176,6 +186,55 @@ describe("stickToBottom", () => {});});+describe("a gesture starting between a snap and its scroll event", () => {+ it("a wheel-up after the snap stays in force when the snap's own scroll event arrives", () => {+ const f = createStreamFollow();+ const el = fakeContainer(2000, 460);+ // A streaming commit snaps the view; the browser dispatches its scroll event a frame later.+ stickToBottom(el, f);+ // The reader's first upward tick reaches the page before that event does.+ f.wheel(-3);+ // The snap's event reads the position the snap already reported: nothing moved.+ f.scrolled(el.metrics());+ expect(f.stick).toBe(false);+ // So the next streaming update does not snap the view back down under the gesture.+ expect(f.snaps).toBe(false);+ });+});++describe("followToBottom", () => {+ it("leaves a view the browser moved up, before reporting it, where it is and stops following", () => {+ const f = createStreamFollow();+ const el = fakeContainer(2000, 460);+ stickToBottom(el, f);+ // A key, the scrollbar or a find jump moved the view; its scroll event has not arrived.+ el.scrollTop = 1200;+ el.scrollHeight += 300; // a streaming commit grows the reply below+ followToBottom(el, f);+ expect(el.scrollTop).toBe(1200);+ expect(f.stick).toBe(false);+ });++ it("snaps a view still at the old bottom to the new bottom", () => {+ const f = createStreamFollow();+ const el = fakeContainer(2000, 460);+ stickToBottom(el, f);+ el.scrollHeight += 300;+ followToBottom(el, f);+ expect(el.scrollTop).toBe(1840);+ expect(f.stick).toBe(true);+ });++ it("lands a conversation opened above its bottom at the bottom: the first reading decides nothing", () => {+ const f = createStreamFollow();+ // Entering a long conversation: the transcript mounts at the top, no position reported yet.+ const el = fakeContainer(2000, 460);+ followToBottom(el, f);+ expect(el.scrollTop).toBe(1540);+ expect(f.stick).toBe(true);+ });+});+describe("hold", () => {it("defers the snap without touching the intent, and the release catches a following view up", () => {const f = createStreamFollow();