DSH / Atlas
2026-10-18implementedarchitecture

Serve Session-list rows from a summary key set

Serve Session-list rows from a summary key set

A Session-list row carries every registered client view. Four of those views are never rendered by a row: the whole-log turn outline, the whole-log conversation figures, the current todo list, and the host-wide image limits. The outline grows with the Session's log, so a list payload scales with corpus size and log length even though no row shows it. Omitting values from the list needs a rule that keeps the wire and

English

Problem

A Session-list row carries every registered client view. Four of those views are never rendered by a row: the whole-log turn outline, the whole-log conversation figures, the current todo list, and the host-wide image limits. The outline grows with the Session's log, so a list payload scales with corpus size and log length even though no row shows it. Omitting values from the list needs a rule that keeps the wire and client types honest: a summary consumer must not obtain an omitted key, a value that is omitted must still reach an opened Session, and the owning packages must not drift from whatever declaration drives the omission.

Decision

The Session summary is every registered client view except the keys whose SessionProjectionMap entry carries the summary-exclusion mark.

  • packages/session/session-projection/src/types.ts declares the type-only mark SessionProjectionSummaryExcluded<T> over a unique symbol that is never exported and never present at runtime. SessionProjectionViewValue<T> strips it distributively, so a nullable entry keeps its null; SessionProjectionSummaryExcludedKey tests the non-nullish part; SessionProjectionSummaryValues is every view value minus those keys.
  • Each owning package wraps only its own map entry: turnOutline (session-turn-outline), sessionStats (session-stats), todos (tool-todo), imageLimits (session-controller's boot-constant attachment limits, which every Session shares), and contextPressure and contextBreakdown (token-meter). The todo entry is SessionProjectionSummaryExcluded<TodoItem[]> | null, because an intersection with null would absorb the null member.
  • Registration carries the same decision as a plain boolean: wire.summary says whether a Session summary includes the unit, and omitting it means true. A key whose map entry carries the mark declares false so the runtime key set and the client view type agree. The mark itself has no runtime representation — wire.view and viewSchema are typed with SessionProjectionViewValue, which strips it, so the erase in register only widens the state type.
  • packages/session/session-projection/src/index.ts exposes summaryKeys(): ReadonlySet<key>, derived from the live registrations and rebuilt only when a new key registers or a key's last registrant disposes. cachedSnapshot, viewCheckpoint, and snapshot accept ProjectionKeySelection (readonly Key[] | ReadonlySet<Key>) and use a passed set as-is.
  • packages/session/session-projection-cache/src/index.ts forwards that selection unchanged, and packages/api/session-controller/src/list.ts passes summaryKeys() to the live registry's snapshot and to the cold cache read. cachedPredecessorTitle keeps its title-only read.
  • Client types only: SessionSummary.projectionValues narrows to Partial<SessionProjectionSummaryValues>, while SessionProjectionSnapshot.values keeps every view value. No wire field, function, or UI name changes, and an opened Session still receives every key through session/follow, the control baseline, and session.projections.

Estimated effect: with logs whose outlines dominate the projection payload, the four keys are estimated at roughly two thirds of a Session-list response for a few hundred Sessions — the outline alone near 57%, the figures and todo list near 5% together, and the shared image limits near 5% — and at roughly 85% of the same response after transport compression, where the outline's unique text barely compresses while the remaining keys do.

Alternatives considered

A summary-specific read face per source (viewSummaryRecord for checkpoint rows and cachedSummarySnapshot for live cells). Rejected: the summary key set would then be defined and carried by two read faces plus their call sites, and a caller could still pass explicit keys to the complete faces. The derived set plus the existing key-taking faces keeps one definition, one code path, and no per-read key copy.

A hardcoded excluded-key list in the session controller. Rejected: the list would drift from the owning packages, and nothing would fail when a package renamed a key or added a large value.

Filtering keys after the complete block is built. Rejected: the per-row state parse and view work would still happen, and the wire type would keep claiming the excluded keys are present.

Making every projection opt in to summaries. Rejected: it inverts today's default, requires touching every owning package, and silently drops a new large key from summaries whenever a package forgets to opt in.

A lazy per-value read for large projections. Rejected: rows do not need the values at all, and deferring one value per row adds a request shape and loading states the list never had.

Consequences

Bought: a list response no longer scales with outline length or log count, a summary consumer cannot obtain an excluded key through the derived set (the complete faces still serve an explicitly named key), and reading an excluded key from a list row's type is a type error. wire.summary is a plain boolean, so keeping a marked key at false is the registering package's responsibility rather than a compile error.

A list row carries the summary projection, never the full projection: it promises the summary key set and nothing more. A connected Session's client store may hold more values from its control/follow baseline, but those are outside the list contract and must not be read from a row; the opened Session's own baselines keep every value.

No upgrade guide records this change. The externally perceptible part is the wire: session/list rows no longer carry the four keys, and a client type that reads projectionValues.turnOutline no longer compiles. A consumer migrating reads the opened Session instead — its session/follow opening snapshot, the session/control baseline, or a session.projections read — which keep every projected value; the package README and the subsystem page state the rule.

Paid: ProjectionKeySelection is a new public signature type and ReadonlySet joins the catalog's foundation types; summaryKeys() has two invalidation points (a new key, the last disposer) that a future registration path must not miss; the summary key set, like the unit table, is process-wide, so a key excluded by one preset is excluded for every Session; and a nullable value cannot be marked directly — its null must stay outside the wrapper.

Testing

中文

Problem

Session 列表行携带每个已注册的客户端视图。其中四个视图从不被行渲染:整份日志的 turn outline、整份日志的会话统计、当前 todo 清单,以及宿主级的图片上限。outline 随 Session 日志增长,因此列表响应会随语料规模与日志长度增长,而没有一行展示它。从列表省略取值需要一条规则同时守住 wire 与客户端类型:摘要消费方不能取得被省略的键;被省略的值仍要送达打开的 Session;owning package 不得与驱动省略的声明漂移。

Decision

Session 摘要就是每个已注册客户端视图,减去 SessionProjectionMap 条目带摘要排除标记的键。

  • packages/session/session-projection/src/types.ts 声明类型层标记 SessionProjectionSummaryExcluded<T>,它基于一个从不导出、运行时从不存在的 unique symbol。SessionProjectionViewValue<T> 以分发方式去掉标记,可空条目因此保留 null;SessionProjectionSummaryExcludedKey 取非空部分判断;SessionProjectionSummaryValues 是全部视图值减去这些键。
  • 每个 owning package 只包装自己的 map 条目:turnOutline(session-turn-outline)、sessionStats(session-stats)、todos(tool-todo)、imageLimits(session-controller 的启动常量附件上限,每个 Session 共享),以及 contextPressure 和 contextBreakdown(token-meter)。todo 条目写作 SessionProjectionSummaryExcluded<TodoItem[]> | null,因为与 null 求交会吞掉 null 成员。
  • 注册用普通布尔值承载同一决定:wire.summary 表示 Session 摘要是否包含该单元,省略即 true。map 条目带标记的 key 声明 false,让运行时键集合与客户端视图类型一致。标记本身没有运行时表示 —— wire.view 与 viewSchema 的签名已用 SessionProjectionViewValue 去标记,因此 register 里的擦除只是放宽状态类型。
  • packages/session/session-projection/src/index.ts 提供 summaryKeys(): ReadonlySet<key>,从实时注册派生,只有新键注册或某键最后一个注册者注销时才重建。cachedSnapshot、viewCheckpoint、snapshot 接受 ProjectionKeySelection(readonly Key[] | ReadonlySet<Key>),传入 Set 时直接使用。
  • packages/session/session-projection-cache/src/index.ts 原样转发该选择,packages/api/session-controller/src/list.ts 把 summaryKeys() 传给实时注册表的 snapshot 与冷会话的缓存读取。cachedPredecessorTitle 保持只读 title。
  • 客户端只有类型变化:SessionSummary.projectionValues 收窄为 Partial<SessionProjectionSummaryValues>,而 SessionProjectionSnapshot.values 保留全部视图值。wire 字段、函数名与 UI 名称均不变;打开的 Session 仍通过 session/follow、控制基线与 session.projections 收到每个键。

估算效果:当 outline 在投影负载中占主导时,四个键估计占几百个 Session 时列表响应的约三分之二 —— outline 单项约 57%,统计与 todo 合计约 5%,共享的图片上限约 5% —— 占传输压缩后同一响应的约 85%,因为 outline 的唯一文本几乎无法压缩,而其余键可以。

Alternatives considered

为每个来源各做一个摘要专用读取面(checkpoint 行的 viewSummaryRecord 与实时 cell 的 cachedSummarySnapshot)。否决:摘要键集合会由两个读取面及其调用点各定义一次,而调用方仍可向完整读取面传显式键。派生集合加既有带键读取面只保留一处定义、一条代码路径,且每次读取无需复制键。

在 session controller 里硬编码被排除键清单。 否决:清单会与 owning package 漂移,且包改名或新增一个大值时没有任何检查会失败。

先构建完整块再按键过滤。 否决:逐行的 state 解析与 view 工作仍会发生,而且 wire 类型会继续声称被排除键存在。

让每个投影主动选择加入摘要。 否决:这反转了当前默认,需要改动每个 owning package,并且某包忘记加入时新的大键会被静默地从摘要中漏掉。

为大投影做按值惰性读取。 否决:行根本不需要这些值,逐行延迟一个值会引入列表从未有过的请求形状与加载态。

Consequences

换来的:列表响应不再随 outline 长度或日志数量增长;摘要消费方无法通过派生集合取得被排除的键(完整读取面仍按显式键提供);从列表行的类型读取被排除键是类型错误。wire.summary 是普通布尔值,因此让带标记的键保持 false 是注册方自己的责任,而不是编译错误。

列表行携带的是摘要投影,绝不是全量投影:它只承诺摘要键集合,不承诺更多。已连接 Session 的客户端 store 可能因 control/follow 基线持有更多值,但那不属于列表契约,不得从行上读取;打开的 Session 自身的基线保留全部取值。

本次没有升级指南记录该变更。外部可感知的部分在 wire:session/list 行不再携带四个键,读取 projectionValues.turnOutline 的客户端类型不再编译。迁移方式是改读打开的 Session —— 其 session/follow 初始快照、session/control 基线或 session.projections 读取 —— 它们保留全部投影值;包 README 与子系统页写明了该规则。

付出的:ProjectionKeySelection 是新的公开签名类型,ReadonlySet 也需加入 catalog 的 foundation 类型;summaryKeys() 有两个失效点(新键、最后一个 disposer),未来的注册路径不得漏掉;摘要键集合与单元表一样是进程级的,某个 preset 排除的键对所有 Session 都排除;可空值不能直接标记 —— 它的 null 必须留在包装之外。

Testing