DSH / Atlas
2026-11-06proposedfeature

Chat history consumption classes and interactions

Chat 历史消费的类与交互

Session owns a history page's network lifetime, while Chat owns whether that page can safely enter the current view. Two-phase loading must reuse existing publication and scrolling capabilities without copying business data, consumption intent, and DOM preservation state into one owner.

English

Problem

Session owns a history page's network lifetime, while Chat owns whether that page can safely enter the current view. Two-phase loading must reuse existing publication and scrolling capabilities without copying business data, consumption intent, and DOM preservation state into one owner.

Proposal

History prefetch and safe consumption defines user-visible behavior and trade-offs. This note defines class interactions and lifetimes without adding an independent scroll animation or React commit manager.

Owners and interfaces

OwnerData and operations
SessionloadOlder({ deferConsumption?: boolean }) prepares and optionally consumes a page; consumeOlder() synchronously publishes a valid staged page; historyLoadStatus is idle/loading/pendingConsumption/error, and loadingOlder derives from loading, including Turn jumps
Session request recordHolds generation, starting cursor, page entries, hasMore, Promise, and consumption/invalidation flags; staging does not advance the visible window cursor
ChatNavigationOwns none/auto/manual consumption intent and request exclusion; automatic consumption waits or falls back by blocker, while manual consumption captures an anchor and consumes without blocker-wait subscriptions
ChatViewportReads internal input/motion state and scrollTop, returns a blocker or native/preserve/prepend, and performs distance measurement and existing anchor algorithms
useChatScrollConnects existing reading, scroll, content, and size notifications to consumption checks and settles a pending one-shot correction during commit handling
ChatViewRequests and consumes through injected callbacks and reads state through useSession; renders a fixed-height history control without retaining Session history data or accumulating historyWasPartial
ChatNavigation.checkHistory
  ├─ pendingConsumption + intent=none → retain page until clicked
  ├─ pendingConsumption + intent=manual → beginManualPaging → consumeOlder
  ├─ pendingConsumption + intent=auto → viewport.historyConsumption
  │    ├─ touch/inner-scroll → retain automatic intent before checking motion
  │    ├─ motion/pointer/unavailable → return to button
  │    ├─ native → consumeOlder
  │    ├─ prepend → capture paging position → consumeOlder → correct once after commit
  │    └─ preserve → beginPreserving → consumeOlder
  ├─ loading → no duplicate request; a click records manual intent
  ├─ error → wait for explicit retry
  └─ idle + hasMore + (manual intent or near top without following) → request a page

Session.loadOlder
  → prepareOlder reuses or creates the request
  → await the captured request Promise
  → consumeOlder when request identity remains valid and consumption is not deferred

Session.prepareOlder
  → network prepend → capture the page without publishing eventSource
  → validate progress → pendingConsumption or error

Session.consumeOlder
  → check generation/cursor/consuming
  → synchronous eventSource.prepend → existing Conversation merge and flush
  → clear the request record and publish final status

Data lifetimes

isOpen means only that Session openState === 'open'; it is independent of whether a page is pendingConsumption. historyWasPartial is monotonic for one Client Session instance: once its visible window has hasMore=true, the fact remains until the instance ends, across component remounts and reconnects, without entering the persistent log.

prepareOlder() returns an existing request or creates one, and loadOlder() rechecks identity after awaiting that captured request Promise. An obsolete Promise cannot consume a newer page. A default call consumes the prepared page; deferConsumption retains a valid nonempty page, while an empty terminal page can immediately confirm exhaustion. Consumption retains the request record and sets consuming to prevent synchronous subscriber reentry without borrowing the network loading state.

An ordinary request captures the transport page first. It can be consumed only after the request succeeds and its cursor advances, or an empty page explicitly confirms exhaustion. Failures and empty pages that still claim more history enter error without automatic retry. Window replacement, reconnect, and disposal invalidate old pages; when an in-flight request may have advanced the transport cursor, the existing stream restart restores a baseline before another page is allowed.

loadThrough(seq) is explicit navigation: it first adopts a staged page and then uses existing Turn-aligned paging. An ordinary in-flight request remains exclusive, and the caller continues after it settles. A jump publishes its successful prefix once at completion or a later failure, without delaying live appends. loadingOlder always equals historyLoadStatus === 'loading'.

Consumption intent and wakeups

An automatic request records auto intent; a click records manual intent. Successful consumption, failure, exhaustion, or navigation cancellation clears the intent. A cached page with none intent is neither measured nor consumed by ordinary events; its button records manual intent without requesting it again. Touch and actual inner-scroll retain auto before motion is evaluated; after release the current state is checked again. Motion, pointer, or unavailable positioning otherwise returns auto to none. Manual intent bypasses these automatic blockers once a page is available: beginManualPaging() uses beginPaging() at scrollTop ≤ 0.5; elsewhere it calls beginPreserving() with beginPaging() as fallback. Consumption proceeds even if no anchor is produced. Loading and processing clicks join the current request rather than duplicating it.

Prefetch reuses the existing 500ms reading sample, scrollend, content commits, and size notifications, coalescing them into one rAF check. It uses no IntersectionObserver or additional sample timer and measures nothing in the raw scroll event. Only a ResizeObserver entry for the scroller itself refreshes cached clientHeight during the callback's read phase; column growth does not reread viewport height. Once internal state permits an automatic request, it reads the history control's distance from the viewport and compares it with two cached viewport heights.

historyConsumption() does not query DOM nodes or measure sizes. FlowMotion.active() exposes existing running, batchScheduled, batch, and settling state as a read-only query; passive listeners maintain input state. Size observation removes detached scrolling targets. Finger release, inner scroll completion, transition completion/cancellation, and existing notifications can wake retained automatic intent. Manual consumption has no fold-completion waiting subscription. Without consumption intent, these notifications do not revive an abandoned automatic page.

Shared anchors and layout reads

For automatic consumption at scrollTop ≤ 0.5, selection uses beginPaging's first paging-anchor rule without a reading-position hit test. measurePaging() only captures a PagingPosition; retainPaging() separately owns persistent preservation and inner-size observation. Stationary preservation and one-shot correction share remount resolution in resolvePaging() and inner/outer calculations in applyPaging().

Persistent preservation and one-shot correction use the same applyPaging() formula to restore the captured screen position, compensating the inner scrollport before the outer one. They do not add changes in scrollTop since capture: native anchoring may have caused those changes. Their lifetimes differ: one-shot correction neither enters paging state nor subscribes to inner-size changes, and releases after one application. finishHistoryPrepend() returns the actual landing, and commit handling immediately saves it through reading.preservePosition() rather than waiting for a later scroll event. A committed transition from pendingConsumption to idle settles the one-shot record even when the visible Node order is unchanged; a closed view or error discards the record without applying it. Geometry invalidation remains conditional on the existing layout-change signal, and no new page token or React publication mechanism is introduced. The actual conversation scrollport uses overscroll-behavior-y: none, without creating smooth scrolling or a new momentum animation.

Distance confirmation still needs current geometry, and one-shot correction after prepend still needs the new position. These reads serve correctness, but placement inside rAF, ResizeObserver, or commit handling alone does not prove they add no layout. Read frequency, read/write ordering, and actual Layout/Paint costs require separate verification; position stability is not performance evidence.

Alternatives considered

Pause publication globally in Conversation. That also blocks live tail output and expands the cross-view impact.

Retain a complete window snapshot in Chat. That copies business data and can overwrite messages received while waiting.

Store separate coordinates and continuously track the first row for one-shot correction. That duplicates existing paging anchors and can expand scroll ownership; share the position record and calculations while keeping lifetimes separate.

Add captured-to-current scroll deltas through preserveMovement. The deltas cannot distinguish reader input from native anchoring for the same prepend, so adding them can compensate twice.

Acceptance criteria

  • Default single-stage calls, deferred consumption, and Turn jumps coexist; an old request cannot consume or overwrite a new one.
  • Ordinary events do not revive automatic fallback; touch/inner-scroll continuation, manual completion, and unmount cleanup have focused verification.
  • One-shot correction uses the existing screen-restoration formula without persistent observation or duplicate native compensation; persistent and inner preservation do not regress.
  • Distance checks use cached viewport height; raw scroll listeners and consumption admission perform no layout reads.

Risks

Screen restoration uses the measured residual displacement after native anchoring rather than adding scroll-position deltas. It does not preserve arbitrary input movement between capture and application or guarantee an uninterrupted momentum trajectory. Near-zero outer positions, native inner anchoring, and input arriving around the prepend require current-build browser verification.

Explicit navigation and multiple views share a Session, so Chat's automatic waiting policy must not move into the global event source. Manual consumption establishes persistent preservation at consumption time; an already active touch can then enter the paging scroll branch instead of reader sampling, constraining movement until a new input releases the anchor. This manual paging limitation remains unresolved. Manual consumption proceeds without preservation if no anchor can be captured, so that structure has no position-stability guarantee. Cancellation, reconnect, and removal of the selected anchor remain distinct lifecycle cases; a missing anchor cannot provide position preservation. One-shot geometry measurement, native inner anchoring, and asynchronous content growth need browser evidence from the current build.

Reports must identify source/artifact versions, real or synthetic inputs, missing conditions, and cleanup results. V8 function or range hits are not TypeScript line/branch percentages; earlier iteration recordings, Chrome/Safari manual feedback, or a successful build do not establish a complete matrix pass for this proposal.

中文

Problem

历史页的网络生命周期属于 Session,能否安全进入当前页面属于 Chat。两阶段加载需要复用现有事件发布与滚动能力,不能把业务数据、消费意图和 DOM 保位状态复制到同一个所有者。

Proposal

用户可见行为与取舍由历史预取与安全消费定义。本文规定类之间的调用与生命周期,不增加独立的滚动动画或 React 提交管理。

所有者与接口

所有者数据与操作
SessionloadOlder({ deferConsumption?: boolean }) 准备并按选项消费一页;consumeOlder() 同步发布有效暂存页;historyLoadStatus 表达 idle/loading/pendingConsumption/error,loadingOlder 从 loading 派生并包含 Turn 跳转
Session 请求记录保存 generation、请求前游标、页内容、hasMore、Promise 与消费/失效标记;缓存页不提前改变可见窗口游标
ChatNavigation保存 none/auto/manual 消费意图和请求互斥;自动按阻塞原因等待或退回按钮,手动采集锚点后消费,不注册阻塞结束等待
ChatViewport读取内部输入/动画状态与 scrollTop,报告阻塞原因或 native/preserve/prepend;执行距离测量和已有锚点算法
useChatScroll把既有阅读、滚动、内容及尺寸通知接到消费检查;在提交阶段结算待执行的一次补偿
ChatView通过注入回调请求/消费,通过 useSession 读取状态;固定高度显示历史控件,不保存 Session 历史数据或累计 historyWasPartial
ChatNavigation.checkHistory
  ├─ pendingConsumption + intent=none → retain page until clicked
  ├─ pendingConsumption + intent=manual → beginManualPaging → consumeOlder
  ├─ pendingConsumption + intent=auto → viewport.historyConsumption
  │    ├─ touch/inner-scroll → retain automatic intent before checking motion
  │    ├─ motion/pointer/unavailable → return to button
  │    ├─ native → consumeOlder
  │    ├─ prepend → capture paging position → consumeOlder → correct once after commit
  │    └─ preserve → beginPreserving → consumeOlder
  ├─ loading → no duplicate request; a click records manual intent
  ├─ error → wait for explicit retry
  └─ idle + hasMore + (manual intent or near top without following) → request a page

Session.loadOlder
  → prepareOlder reuses or creates the request
  → await the captured request Promise
  → consumeOlder when request identity remains valid and consumption is not deferred

Session.prepareOlder
  → network prepend → capture the page without publishing eventSource
  → validate progress → pendingConsumption or error

Session.consumeOlder
  → check generation/cursor/consuming
  → synchronous eventSource.prepend → existing Conversation merge and flush
  → clear the request record and publish final status

数据生命周期

isOpen 只表达会话 openState === 'open',与某页是否 pendingConsumption 无关。historyWasPartial 是客户端 Session 实例的单调事实:可见窗口曾有 hasMore=true 后保留到实例结束,不随组件重挂载或重连清除,不写持久化日志。

prepareOlder() 返回已有请求或创建一个请求,loadOlder() 等待捕获的请求 Promise 后再核对身份。旧 Promise 完成不能消费随后创建的新页。默认调用消费准备好的页;deferConsumption 保留有效非空页,终态空页可以直接确认耗尽。消费期间保持请求记录并设置 consuming,阻止同步订阅者重入,不借用网络 loading 状态。

普通请求先捕获传输返回页,只有请求成功且游标前进,或空页明确表示耗尽时才能消费。失败或空页仍声称有更多则进入 error,不自动重试。窗口替换、重连和销毁使旧页失效;如果在途请求可能已推进传输游标,现有流重启先恢复基线,再允许下一页。

loadThrough(seq) 是显式导航:先采用已有待消费页,再沿既有 Turn 对齐规则加载;普通请求在途时保持互斥,由调用方在其结算后继续。跳转的成功前缀在完成或后续失败时一次发布,实时追加不等待它。loadingOlder 始终等价于 historyLoadStatus === 'loading'。

消费意图与唤醒

自动请求开始时登记 auto,点击登记 manual。消费成功、失败、耗尽或取消导航时清除意图。缓存存在但意图为 none 时,普通事件不测量或消费该缓存;按钮重新登记 manual,不重复取页。touch 与实际 inner-scroll 优先于 motion 判断保留 auto,释放后重新检查当前状态;其余 motion、pointer 或 unavailable 使 auto 退回 none。manual 在页面可用时绕过这些自动阻塞:beginManualPaging() 在 scrollTop ≤ 0.5 时调用 beginPaging();其他位置调用 beginPreserving(),并以 beginPaging() 兜底。没有产生锚点时仍继续消费。加载和处理状态的点击加入当前请求,不重复请求。

历史预取复用已有 500ms 阅读采样、scrollend、内容提交和尺寸通知,并合并为一次 rAF 检查。不使用 IntersectionObserver,不新增采样计时器,不在原始 scroll 事件中测量。仅 scroller 自身的 ResizeObserver 条目在回调读阶段更新 clientHeight 缓存,column 增长不重新读取视口高度。内部状态允许自动请求时,读取历史控件相对视口的位置,与缓存的两屏高度比较。

historyConsumption() 不查询 DOM 或测量尺寸。FlowMotion.active() 从已有 running、batchScheduled、batch、settling 状态提供只读查询;输入状态来自被动事件监听。滚动目标失效的清理在尺寸观察处进行。手指释放、内层滚动结束、过渡结束/取消和既有通知可以唤醒保留的自动意图;手动消费不注册折叠结束等待。没有消费意图时这些通知不恢复已经放弃的自动页。

锚点复用与布局读取

自动消费在顶部 scrollTop ≤ 0.5 时使用 beginPaging 的首条分页锚点规则,不先执行阅读位置命中检测。measurePaging() 只采集 PagingPosition;retainPaging() 单独拥有持续保位和内层尺寸观察。普通静止保位与一次补偿共用 resolvePaging() 的重挂载查找及 applyPaging() 的内外层计算。

持续保位和一次补偿用相同的 applyPaging() 公式恢复采集时的屏幕位置,先补内层、再补外层。计算不叠加采集后 scrollTop 的变化,因为这些变化可能已经来自原生锚定。两者只区分生命周期:一次补偿不进入 paging 状态、不注册内层尺寸观察,应用一次后释放。finishHistoryPrepend() 返回实际落点,提交处理立即通过 reading.preservePosition() 保存阅读位置,不依赖后续 scroll 事件。已提交的 pendingConsumption 到 idle 状态转换,即使可见 Node 顺序未变化,也会结算一次补偿记录;视图关闭或进入 error 时丢弃记录,不应用补偿。几何失效仍只由已有布局变化信号触发,不增加页 token 或 React 发布机制。会话实际滚动容器设置 overscroll-behavior-y: none,不创建平滑滚动或新的惯性动画。

距离检查仍需要当前几何;前插后的一次补偿仍需要读取新位置。这些读数有正确性用途,但不能仅凭位于 rAF、ResizeObserver 或提交回调中,就认定不会增加布局。读取频率、读写顺序及实际 Layout/Paint 成本分别验收;位置不漂移不能替代性能证明。

Alternatives considered

在 Conversation 全局暂停发布。 会同时阻止尾部实时输出,扩大跨视图影响。

在 Chat 保存完整窗口快照。 复制业务数据,消费时可能覆盖等待期间的新消息。

为一次补偿另存坐标并持续追踪首行。 与既有分页锚点重复,并可能扩大滚动控制;共享位置记录和计算,只区分生命周期。

通过 preserveMovement 叠加采集后滚动增量。 该增量无法区分读者输入与同一次前插的原生锚定,叠加后可能重复补偿。

Acceptance criteria

  • 默认单阶段调用、延迟消费及 Turn 跳转共存,旧请求不能消费或覆盖新请求。
  • auto 回退不会被普通事件恢复;触摸与内层滚动续接、manual 完成承诺和卸载清理都有定向验证。
  • 一次补偿使用既有屏幕位置恢复公式,不注册持续观察、不重复原生补偿;持续保位和内层补偿不退化。
  • 距离读取使用缓存视口高度;原始滚动监听与消费准入不读取布局。

Risks

屏幕位置恢复使用原生锚定后测得的剩余位移,而不是叠加滚动位置增量。它不保留采集到应用之间任意输入造成的移动,也不保证惯性轨迹连续。外层近零位置、内层原生锚定以及前插附近到达的输入,都需要当前构建的浏览器验证。

显式导航与多个视图共享 Session,不能把 Chat 的自动等待条件放进全局事件源。手动消费在消费时建立持续保位;已经进行的触摸随后可能进入 paging 滚动分支而非读者采样,移动受限直到新输入释放锚点。这项手动分页限制仍未解决。手动消费在无法采集锚点时仍继续,因此该结构不保证位置稳定。取消、重连和所选锚点被移除属于不同生命周期情况;锚点缺失时无法提供位置保留。一次补偿的布局测量、内层浏览器锚定及异步内容增长需要当前构建的浏览器证据。

验收报告应列明源码/产物版本、真实或合成输入、未覆盖条件以及清理结果。V8 函数或区间命中不等于 TypeScript 行/分支百分比;早期迭代的录像、Chrome/Safari 手工体验和单个构建通过不能证明本提案的完整矩阵已通过。