Skip to content

feat(host): expose linked child session lifecycle - #1400

Merged
likun666661 merged 3 commits into
mainfrom
agent/child-session-host-lifecycle
Jul 23, 2026
Merged

likun666661 merged 3 commits into
mainfrom
agent/child-session-host-lifecycle

Conversation

@likun666661

Copy link
Copy Markdown
Member

Summary

This is PR 4, the final slice of #1366.

  • Project durable child-session lineage into a parent-first tree in Desktop and the TUI without conflating ordinary branches.
  • Keep orphaned or cyclic relations visible as roots so corrupted or partially migrated metadata cannot hide an inspectable session.
  • Render child sessions as normal selectable Desktop rows and TUI entries; direct resume/follow-up continues through the existing Session APIs.
  • Prevent implicit --continue from silently promoting the latest child session, while preserving explicit --resume <child-session-id>.
  • Fan nested spawn/resume/retry events onto the child Session's existing Desktop renderer and Open Gateway channels, while retaining the parent tool's presentation callbacks.
  • Cover Runtime Host restart, isolated child history, child-only compaction, usage/tool activity ownership, and two-client observation of one child event stream.

Design boundary

This does not add a second agent runtime or a subagent-specific protocol. A child remains a normal Session with durable parent metadata; the host only projects the relation and routes the already-existing Session event stream.

Forked parent context is intentionally not included here. That changes creation semantics and data-copy policy, so it should remain a separate follow-up rather than expanding this lifecycle/observation PR.

Validation

  • npm run build
  • npm run typecheck
  • npm run lint
  • npm run format:check
  • Desktop full suite: 2,825 tests passed
  • Focused core, CLI, Runtime, child-observation, and multi-client Open Gateway tests passed
  • npm run test:fast reaches two unrelated macOS sandbox failures (/usr/local executable-root ordering and Homebrew rg/PCRE2 dylib access); both reproduce unchanged on origin/main

Closes #1366

中文

概要

这是 #1366 的 PR 4,也是最后一个实现切片。

  • 在 Desktop 和 TUI 中把持久化的 child-session 关系投影为父子树,同时不把普通 branch 混进 subagent 关系。
  • 父会话缺失或关系成环时,child 会话仍作为根节点显示,避免异常或迁移不完整的元数据让会话不可观察。
  • child session 在 Desktop 和 TUI 中仍是普通、可直接选择的会话;继续追问和恢复沿用现有 Session API。
  • --continue 不再无意中把最近的 child session 当成主会话,但显式 --resume <child-session-id> 仍然支持。
  • 嵌套 spawn/resume/retry 的事件会进入 child Session 已有的 Desktop renderer 与 Open Gateway 事件通道,同时保留父工具调用原有的展示回调。
  • 增加 Runtime Host 重启、child 上下文隔离、child 独立压缩、usage/tool activity 归属,以及两个 client 同时观察一个 child stream 的覆盖。

设计边界

这个 PR 不增加第二套 agent runtime,也不引入 subagent 专用协议。child 仍然是带有持久化父关系元数据的普通 Session;host 只负责关系投影和复用既有 Session event stream 的路由。

父会话上下文 fork 有不同的创建语义和数据复制策略,因此有意留作独立后续,不扩张这个 lifecycle/observation PR。

验证

  • npm run build
  • npm run typecheck
  • npm run lint
  • npm run format:check
  • Desktop 全量测试:2,825 个通过
  • core、CLI、Runtime、child observation、Open Gateway 多客户端聚焦测试通过
  • npm run test:fast 仅剩两个与本 PR 无关的 macOS sandbox 失败(/usr/local executable-root 顺序,以及 Homebrew rg/PCRE2 dylib 访问);两项都能在未改动的 origin/main 上复现

@likun666661

Copy link
Copy Markdown
Member Author

I found two Desktop projection issues that should be addressed before merging. The event fan-out and CLI behavior look good overall.

[P1] Apply navigation filtering to child sessions too

filterSessions() only sees sidebarSessionTree.roots, while SessionTreeRow recursively renders every descendant from the unfiltered childrenByParentId. This makes child lifecycle actions inconsistent:

  • an archived child remains visible in Chats under an active parent;
  • a flagged child does not appear in Flagged unless its parent is flagged;
  • an active child disappears from Chats when its parent is archived.

Since child rows expose the normal archive/flag actions, the tree projection needs to be filter-aware—for example, retain the necessary ancestor path for a matching descendant or promote the matching child—and pass a correspondingly filtered child map. Please add coverage for independently archived/flagged parents and children.

Relevant code: apps/desktop/src/renderer/app-shell.tsx:345-357 and packages/ui/src/session-history-list.tsx:402-439.

[P2] Preserve linked children across revision collapse

Collapsing revisions before building the linked-session tree detaches children from non-selected physical revisions. For example, if parent-v1 spawned a child and edit-and-resend later makes parent-v2 the visible representative, collapseSessionRevisions() removes parent-v1; projectLinkedSessionTree() then treats the child as an orphan and promotes it to a top-level root. That loses the intended nesting and exposes a durable child as an ordinary top-level chat.

Please aggregate children across the revision family or remap their parent to the selected representative, and add an edit-and-resend regression test.

@likun666661
likun666661 marked this pull request as ready for review July 23, 2026 14:49
@likun666661
likun666661 merged commit 70a08ff into main Jul 23, 2026
3 checks passed
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.

design(runtime): model subagents as linked child sessions

1 participant