Skip to content

fix(web): 在子会话所在的工作区显示委派树 / show a delegated Thread's tree in its own workspace - #1044

Merged
iruriQ merged 2 commits into
BytePioneer-AI:mainfrom
sduhantao-maker:fix/web-cross-workspace-thread-tree
Nov 22, 2026
Merged

iruriQ merged 2 commits into
BytePioneer-AI:mainfrom
sduhantao-maker:fix/web-cross-workspace-thread-tree

Conversation

@sduhantao-maker

@sduhantao-maker sduhantao-maker commented Nov 22, 2026 •

Copy link
Copy Markdown
Contributor

摘要

当一个 Web 工作区里只有从其他工作区的会话委派出来的子会话时,侧栏把这个工作区显示为空。侧栏把委派关系建成跨工作区的一棵树,但只在根会话所在的工作区列出这棵树,所以子会话自己的工作区一行都没有;它的「展开显示」会不停加载更早的历史页,也补不出这一行。

Desktop 会在那个项目里列出这个子会话:原生侧栏显示为普通行,装了 Sidebar Thread Tree 扩展时显示父会话的整棵树。现在 Web 也一样:工作区会在子会话的位置列出这棵树,从根会话开始。同一棵树在一个工作区里只出现一次,只在一个工作区内的树不变。

  • workspaceTreeMembers() 取代浏览器工作区投影里只保留根的过滤:工作区成员不是根时,如果它的根不在这个工作区,就把根带进来。threadTreeOrderSource() 同时返回每个后代的根。
  • 置顶排序的成员来源 pinOrderSource() 使用同一个投影,置顶无关会话时不会丢掉 linked 根的手动排序位置。
  • 通过子会话显示的树使用 linked:<workspace>:<id> 行键,同一棵树出现在两个分组时行键仍然唯一;ArrowLeft 在同一前缀下查找父行。
  • 定位当前会话或搜索结果时,仍以根会话自己的工作区为准。
  • docs/architecture/web-thread-tree.md 写明了新规则。

关联 Issue

N/A

测试

基于 main(f2306fba),macOS 27.2.1(arm64):

  • node --import tsx --test apps/web-ui/packages/client/ui-workspace/test/thread-tree.test.ts:15 个通过。
    • 跨工作区:子会话和孙会话在一个工作区、根会话在另一个工作区时,两个工作区都显示根的整棵树;只在一个工作区内的树仍只有一行。
    • 置顶:B 的手动顺序为 [P, X](P 是 linked 根),置顶 A 中无关的会话后,B 的保存顺序仍为 [P, X]。这条测试在第一个提交(07a77c17)上失败,保存顺序变成 [X]。
  • sidebar-window.test.ts:9 个通过。
  • archived-query.test.ts(vitest)在本机加载失败,缺少浏览器全局对象;在修改前的 90618ac 上同样失败,所以没有运行。
  • 用 apps/web-ui/tsconfig.base.json 对改动文件运行 tsc:除了 main 上同样存在的错误(CSS module 声明、Node 类型)外没有新错误。改动文件的 prettier --check 通过。
  • 手动检查:在隔离的 Web 预览中(npm start web -- --port 4401 --host 127.0.0.1 --ch-data <临时目录>,CODEXHOST_EXTERNAL_CLIENT_PORT=off;Node 24.13.1,Rust 1.97.1),临时数据目录里放入所报告的父会话、子会话及其委派记录的副本。用无头 Chrome 157 在 1280×1000 下查看,本分支另在 390×844 下查看:
    • main 上,子会话所在的工作区展开后只有「展开显示」。
    • 本分支上,该工作区列出父会话和「1 个子会话」,展开后子会话在父会话下;父会话自己的工作区仍有这棵树,渲染出的行键都唯一。
    • 在子会话上按 ArrowLeft 会聚焦同一工作区里的父行。控制台没有警告或错误。
    • 置顶排序的修复没有手动检查。未测试:从新增的行打开会话、从搜索结果定位。
  • 症状最初出现在 codexhost 0.23.0 和 Codex Desktop 26.1117.41037 上。

Summary

A Web workspace looked empty when its only Threads were delegated from a Thread in another workspace. The sidebar builds one delegation tree across workspaces and listed each tree only under its root's workspace, so the child's own workspace had no rows. Its "Show more" row kept fetching older history pages, which could never add one.

Desktop lists the child in that project: as a plain row natively, and as its parent's tree with the Sidebar Thread Tree extension. Web now does the same: a workspace also lists such a child's tree, from its root, at the child's place. Each tree appears once per workspace, and a tree inside one workspace is unchanged.

  • workspaceTreeMembers() replaces the root-only filter in the browser's workspace projection: a member that is not a root brings in its root when that root is not in the workspace. threadTreeOrderSource() now also returns each descendant's root.
  • The pin-order source pinOrderSource() uses the same projection, so pinning an unrelated Thread keeps a linked root's manual slot.
  • Rows of a tree shown through a descendant use linked:<workspace>:<id> row keys, so a tree rendered in two groups keeps unique keys. ArrowLeft finds the parent row under the same prefix.
  • Locating the current or a searched Thread still uses the root's own workspace.
  • docs/architecture/web-thread-tree.md states the new rule.

Related issues

N/A

Test plan

On main (f2306fb), macOS 27.2.1 (arm64):

  • node --import tsx --test apps/web-ui/packages/client/ui-workspace/test/thread-tree.test.ts: 15 passed.
    • Cross-workspace: with a child and a grandchild in one workspace and their root in another, both workspaces show the root's whole tree; a tree that stays in one workspace keeps a single row.
    • Pinning: B is manually ordered [P, X] (P is a linked root); pinning an unrelated Thread in A keeps B's saved order at [P, X]. The case fails on the first commit (07a77c1), where the saved order becomes [X].
  • sidebar-window.test.ts: 9 passed.
  • archived-query.test.ts (vitest) does not load here: a browser global is missing. It fails the same way on 90618ac, before these changes, so it was not run.
  • tsc over the changed files with apps/web-ui/tsconfig.base.json: no errors beyond those main reports for the same files (CSS module declarations, Node types). prettier --check on the changed files: passed.
  • By hand, in an isolated Web preview (npm start web -- --port 4401 --host 127.0.0.1 --ch-data <temp dir> with CODEXHOST_EXTERNAL_CLIENT_PORT=off; Node 24.13.1, Rust 1.97.1). The temp data directory held copies of the reported parent Thread, child Thread and their Delegation record. Viewed in headless Chrome 157 at 1280×1000, and this branch also at 390×844:
    • On main, the child's workspace expanded to only "Show more".
    • On this branch, that workspace lists the parent with "1 child session", and expanding the parent shows the child under it. The parent's own workspace still lists the tree, and every rendered row key is unique.
    • ArrowLeft on the child focuses the parent row in the same workspace. The console showed no warnings or errors.
    • The pin-order fix was not checked by hand. Not tried: opening a Thread from the added rows, and revealing one from search.
  • The symptom was first seen with codexhost 0.23.0 and Codex Desktop 26.1117.41037.

@coderabbitai

coderabbitai Bot commented Nov 22, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • 功能更新
    • 当子会话属于其他工作区时,该工作区也会显示从顶层会话开始的完整会话树;同一棵树在每个工作区内仅显示一次。
    • 当前会话定位和搜索结果仍按顶层会话所属工作区展示。
  • 修复
    • 调整置顶会话时,跨工作区显示的顶层会话会保留原有排序位置,避免无关会话置顶后顺序错乱。
    • 改进侧栏的父级导航,使跨工作区会话树中的行能够正确定位父会话。

本次更新调整 Thread 树的 Workspace 成员投影。跨工作区子 Thread 所属的 Workspace 现在也会显示对应根节点及其树后代。侧栏同步调整分组归属、行键和父行查找,并新增相关测试与架构文档说明。

Changes: 跨工作区 Thread 树投影

Layer / File(s) Summary
Thread 树成员投影
apps/web-ui/packages/client/ui-workspace/src/client/thread-tree-order.ts, apps/web-ui/packages/client/ui-workspace/src/client/pin-order.ts, apps/web-ui/packages/client/ui-workspace/test/thread-tree.test.ts
ThreadTreeOrder 新增后代到根节点的映射。workspaceTreeMembers 按 Workspace 成员顺序生成成员列表,并标记因后代而加入的关联根节点。固定顺序逻辑改用该投影;测试覆盖关联根和固定顺序行为。
Workspace 列表与侧栏集成
apps/web-ui/packages/client/ui-workspace/src/client/rows/WorkspaceBrowser.tsx, apps/web-ui/packages/client/ui-workspace/src/client/rows/sidebar-keyboard.ts, apps/web-ui/packages/client/ui-workspace/test/thread-tree.test.ts, docs/architecture/web-thread-tree.md
Workspace 列表使用投影结果;当前会话和搜索结果的分组查找排除关联根。关联行使用带 Workspace 标识的行键,父行查找支持 linked: 键。架构文档说明跨 Workspace 树的呈现行为。

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Browser as WorkspaceBrowser
  participant Projection as workspaceTreeMembers
  participant Tree as SessionTree
  Browser->>Projection: 传入 Workspace 成员与 Thread 树顺序
  Projection-->>Browser: 返回成员列表和关联根
  Browser->>Tree: 传入 Workspace 列表和关联根映射
  Tree-->>Browser: 生成带分组标识的行键
Loading

Possibly related PRs

  • BytePioneer-AI/codex-host#838:该 PR 建立侧栏 Thread 树及根会话分组行为;本次更新调整相关的 Workspace 树成员投影。

Suggested reviewers: bytepioneer-ai

Merge Risk: Minimal · up to 1d601

The change shows a delegated Thread's tree in the workspace containing a child, even when the root belongs to another workspace. It also keeps pin ordering consistent with the browser's projection. The only remaining concern is a narrow archived-filter edge case with a low-impact outcome, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
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.
Title check Passed 标题准确描述了主要变更:子会话所在工作区会显示委派树。标题中的英文副本与中文描述一致,且与变更集的核心目标相符。
Description check Passed 描述与变更集高度相关。它说明了问题原因、涉及的函数(workspaceTreeMembers、threadTreeOrderSource、pinOrderSource)、行键规则、ArrowLeft 行为、文档更新以及测试与手动验证情况。
Finishing Touches

Generate unit tests (beta)

  • Create a new PR
Fix failing CI checks

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

@iruriQ

iruriQ commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

感谢修复跨工作区委派树显示为空的问题!深审 90618ace 后,行 key 隔离与键盘导航处理都很清晰;发现 1 处排序回归 需先修正(同时跨工作区展示整棵树的产品体验也会同步给维护者确认):

  • P2 — 置顶无关会话会清掉 linked 树在子工作区的手动排序(apps/web-ui/packages/client/ui-workspace/src/client/rows/WorkspaceBrowser.tsx:1427、pin-order.ts:36、stores.ts:206):新展示投影纳入了 linked root,但置顶排序来源仍只认原始工作区成员中的根,且置顶时会重写各工作区保存顺序。实测逻辑:B 中将 linked 根 P 排在 X 前面([P, X]),随后置顶 A 中任意无关会话,B 的顺序会被清回 [X, P]。建议让置顶排序复用同一工作区成员投影,并补对应单测。

@iruriQ iruriQ added the awaiting-author Waiting for the author to respond or update the PR. label Nov 22, 2026
A Web workspace looked empty when its only Threads were delegated from a
Thread in another workspace: the sidebar builds one delegation tree across
workspaces and listed each tree only under its root's workspace. Its
"Show more" row kept fetching older pages, which could never add a row.

A workspace now also lists such a child's tree, from its root, at the
child's place, as the Desktop sidebar tree extension does. Each tree
appears once per workspace. Rows of a tree shown through a descendant use
group-scoped row keys, and locating the current or a searched Thread still
uses its root's own workspace.
Pinning a Thread rewrites the saved order of every account from the
pin-order source. That source still listed only a Workspace's own roots,
so the root of a tree shown there through a delegated child dropped out
of the saved order, and the next render put it back last: [P, X] became
[X, P] after pinning an unrelated Thread elsewhere.

The pin-order source now takes each Workspace's members from the same
projection the browser lists, including such linked roots.
@sduhantao-maker
sduhantao-maker force-pushed the fix/web-cross-workspace-thread-tree branch from 90618ac to 1d60145 Compare November 22, 2026 12:52
@sduhantao-maker sduhantao-maker changed the title fix(web): show a delegated Thread's tree in its own workspace fix(web): 在子会话所在的工作区显示委派树 / show a delegated Thread's tree in its own workspace Nov 22, 2026
@sduhantao-maker

Copy link
Copy Markdown
Contributor Author

感谢细致的审查,这个排序回归确实存在,已在 1d60145 修复。pinOrderSource() 现在用侧栏显示时同一个 workspaceTreeMembers() 投影生成各工作区的成员,linked 根会留在子工作区的保存顺序里。thread-tree.test.ts 新增一条测试覆盖你给的场景:B 的手动顺序为 [P, X],置顶 A 中无关的会话后仍为 [P, X]。这条测试在修复前失败,保存顺序变成 [X]。

另外,我把分支上两个提交的作者邮箱改成了 GitHub 的 noreply 地址,所以原来的 90618ac 现在是 07a77c1,代码没有变化。跨工作区显示整棵树的产品取舍等维护者确认。

Thanks for the careful review. The ordering regression is real and is fixed in 1d60145. pinOrderSource() now builds each workspace's members from the same workspaceTreeMembers() projection the sidebar renders, so a linked root keeps its slot in the child workspace's saved order. A new case in thread-tree.test.ts covers your scenario: B is manually ordered [P, X], and pinning an unrelated Thread in A keeps B at [P, X]. It fails before the fix, where the saved order becomes [X].

I also changed the author email of both commits on the branch to the GitHub noreply address, so 90618ac is now 07a77c1 with no code changes. Showing the whole tree across workspaces is left to the maintainers to confirm.

@iruriQ
iruriQ merged commit cb6b706 into BytePioneer-AI:main Nov 22, 2026
5 of 8 checks passed
@iruriQ

iruriQ commented Nov 22, 2026

Copy link
Copy Markdown
Collaborator

已复核 1d6014581 置顶排序修复,与 #1038 合并后测试和 Web UI 构建均通过,已合入 main,感谢贡献!

iruriQ pushed a commit that referenced this pull request Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-author Waiting for the author to respond or update the PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants