Skip to content

fix(desktop): preserve session reading positions across pane eviction - #1665

Merged
vastsa merged 2 commits into
vastsa:mainfrom
new-Beginner:fix/session-reading-position
Oct 14, 2026
Merged

vastsa merged 2 commits into
vastsa:mainfrom
new-Beginner:fix/session-reading-position

Conversation

@new-Beginner

Copy link
Copy Markdown
Contributor

Summary

Fix conversation reading positions being lost when switching sessions, including returns after the original pane has been evicted.

  • Restore the last visible-layout scroll sample for retained panes instead of the stale bottom offset.
  • Keep renderer-lifetime message/viewport bookmarks and explicit disclosure choices independent of the bounded DOM cache. Reuse bounded history reads when the bookmarked message is outside the latest page, without search focus/highlighting or writes to live/model-input messages.
  • Let real input, search, return-to-latest and new turns supersede restoration; reject stale reads during session switches and revalidation.
  • Preserve the three-pane retention limit. No database, persistence, IPC/protocol, provider or permission changes. First visits and pinned revisits still follow latest; bookmarks are not restored after renderer/app restart.
  • Synchronize the existing interaction specs and E2E-071g scenario.

Reproduction and regression coverage

On the old code, an isolated React/Chromium test read at scrollTop 650, switched away and back, and returned at approximately 5556 (the stale bottom). Restoring the visible scroll sample fixed the warm return, but A → B → C → D → E → A still lost its position after A actually unmounted. The added regressions now cover both paths, expanded-content restoration, input cancellation, cold/pinned initialization, and new-turn follow.

The production SessionPane/store/API fixture mocks only the preload IPC boundary. It verifies restoration when revalidation returns a latest page that excludes the old anchor, no search highlight, unchanged live input, the three-pane bound, and return-to-latest. Runtime tests cover cancellation, search priority, session changes/eviction/new turns, missing anchors, IO errors and selection revalidation.

Validation

Task candidate: 9c8868c8cc84bc1b515cc146992a2f5e3aa62c7c
Base main: 4f6890ecd4fd75683168333d433d93720fe9a215
Environment: Windows; Node 24.19.0; pnpm 12.8.1; isolated Electron fixtures (no running Desktop, real Host or provider).

Passed on this candidate:

  • pnpm check:pr-base
  • pnpm --filter @pi-desktop/desktop typecheck
  • pnpm --filter @pi-desktop/desktop build
  • pnpm lint
  • Targeted Node suites: transcript-scroll, session-panes, session-switch-performance, interaction-performance, transcript-reading, transcript-search-focus and transcript-disclosure-anchor — 86/86 passed.
  • node scripts/e2e-transcript-reading-position.mjs
  • node scripts/e2e-transcript-minimap-jump.mjs
  • node scripts/e2e-transcript-disclosure-anchor.mjs
  • git diff --check

Limitations: the full Desktop suite was attempted on the earlier a20a9ca99 base but exceeded 600 seconds and reported failures outside the changed surfaces (including settings/service, release-script and other tests). It is not claimed passing. One plugin-block failure passed 3/3 when rerun alone. No live user-instance or paid-provider checks were performed. This PR does not change those unrelated surfaces.

Keep renderer-lifetime reading bookmarks separate from the bounded pane
cache so returning to a conversation restores its message and viewport
offset even after the pane unmounts or its history page is revalidated.

Let user input, search and new turns supersede restoration without
changing persistence or the three-pane retention limit. Cover the
lifecycle and stale reads with isolated renderer and runtime regressions.
@muzimu217

Copy link
Copy Markdown
Contributor

审读了 diff(+800/-54,20 文件)并跟了 CI 失败,方向对、测试面也厚,但当前 JS job 是红的,且失败原因就是本 PR 自身——合并前需要处理。

CI 失败定位(阻塞项)

JS job 失败在 4 个既有契约测试上,它们不在本 PR 的 diff 里,但断言的正则匹配的是本 PR 重构掉的源码形状:

  • apps/desktop/test/transcript-disclosure-reading.test.mjs
    • "holding a disclosure leaves follow without a delayed grab-back" — 断言 /const releaseFollow = useCallback\(\(\) => \{\s*cancelFollowScroll\(\);\s*pinnedRef\.current = false;\s*setShowJump\(true\);/ 失配
    • "real input, a new turn and every navigation drop the held position" — 断言 /const jumpToLatest = useCallback\(\(\) => \{\s*releaseDisclosureAnchor\(\);\s*pinnedRef\.current = true;/ 失配
  • apps/desktop/test/transcript-window.test.mjs
    • "the transcript bounds mounted history and escalates at the top" 与 "the window is owned per session pane, so no switch can inherit a budget" 同样失配

这几条是仓库惯用的源码契约断言(正则匹配实现形状)。既然本 PR 重排了 ChatTranscript.tsx / useTranscriptScroll.ts 里的 releaseFollow / jumpToLatest 等函数体,对应的契约断言就需要同步更新——要么改断言以匹配新形状(保持语义不降级),要么调整实现让形状兼容。请顺带确认重构后这些行为本身没变(比如 disclosure hold 的取消语义、pane 级预算归属)。

复核要点(无阻塞,供参考)

  • project-slice.ts 的一处改动:clearLocalSessionState 里加 forgetTranscriptReadingState(id)——位置合理(会话级状态清理点)。提醒一下:同文件另有他人正在改([Bug] 项目被归档后再次新建,无法在侧边栏中显示 #1653 的归档标记修复),合入顺序上注意别互相覆盖。
  • 边界声明清晰:书签不跨 renderer/应用重启、首次访问仍走 latest、不写 live/model-input 消息——这些边界与 ADR 0137 的 retained-pane 语义一致,值得在合并说明里保留。
  • 文档同步(ADR 0137 + 两份 spec + E2E-071g)做得完整;新增的两个 e2e 脚本(e2e-transcript-reading-position.mjs 等)覆盖了 A→B→C→D→E→A 的真实卸载路径,这是原实现漏掉的关键场景。

修好 CI 后我可以再看一遍。

Keep the disclosure and window contracts aligned with the new renderer-lifetime reading bookmark hook. The old source assertions failed against the intended refactor even though the targeted behavior and runtime tests pass.
@vastsa
vastsa merged commit cd91b99 into vastsa:main Oct 14, 2026
6 checks passed
@muzimu217

Copy link
Copy Markdown
Contributor

CI 已绿(JS job 6m49s 全过),阻塞解除。复核了 2a81a5c93 的断言更新:四条契约测试的修改都有语义支撑——releaseFollow / jumpToLatest 新增的 cancelReadingPosition() 调用与"真实输入/显式回底会取消挂起的恢复"这条边界一致;windowSize 初始化改为 savedReadingPosition?.windowSize ?? TRANSCRIPT_WINDOW_MIN 正是新功能本身(窗口大小跟随书签恢复),per-pane 归属断言保持不变。没有语义降级,我此前的阻塞项解除,LGTM。

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.

3 participants