DSH / Atlas
2026-10-20implementedarchitecture

New Session reuses a blank Session, matching a requested preset

新会话复用空白会话,指定预设时按预设匹配

In 0.2.0-rc.2, New Session (the sidebar button, the Workspace "+" button, and the shortcut, all calling `uiWorkspace.startSession` without options) reused the Workspace's first blank Session. PR #5775, first released in `dsh-v0.2.1-alpha.2`, changed it to create a fresh Session and Agent on every call, so that New Session composes the current preset definition after the user changes one instead of keeping a reused bl

English

Problem

In 0.2.0-rc.2, New Session (the sidebar button, the Workspace "+" button, and the shortcut, all calling uiWorkspace.startSession without options) reused the Workspace's first blank Session. PR #5775, first released in dsh-v0.2.1-alpha.2, changed it to create a fresh Session and Agent on every call, so that New Session composes the current preset definition after the user changes one instead of keeping a reused blank's earlier composition (upgrade guide).

A blank Session that is not current is hidden from the Session tree, and New Session is the only way back to it. After that change, a user who types a draft into a blank Session, switches to another Session, and clicks New Session lands in another empty Session; the original draft stays in localStorage under the old Session id, but no control returns to it. 0.2.1-rc.2 therefore loses New Session's unsent drafts.

The Creator entries (startSession(…, { agentPreset: 'cordis', prompt, clearPreviousDraft: false })) also reuse the first blank Session and switch it to Creator: an existing ordinary draft stays under Creator mode and the Creator prompt is not filled in, and New Session can likewise take over a Creator blank.

Decision

Only the Client (ui-workspace) changes; the Host is unchanged:

  • startSession without options takes the reuse path again and follows the same rule as openWorkspace, connectWorkspace, and startSession with options.
  • createInWorkspace names the first unstarted, unarchived blank Session that is still a Workspace member. A request that names a preset skips a blank whose listed preset (projectionValues.agentPreset) is a different one, while a blank with no listed preset remains eligible; a request without a preset may name any blank, which the Host switches to its default preset. The Host creates a Session when no blank is eligible.

As a result, New Session returns to the original blank Session with its unsent draft, and preset flows such as the Creator entries do not take over a blank that lists another preset, so an ordinary draft is not moved under Creator. No persisted state is added, and the Client does not read the preset roster.

Alternatives considered

Revert the PR #5775 change completely, reusing the first blank for every request. Drafts come back, but preset flows such as the Creator entries take over the blank holding the user's ordinary draft, switch it to Creator, keep the draft there, and cannot fill in their prompt.

Keep creating a fresh Session and move the abandoned blank's draft into it. This needs rules for which blank to move from when several exist, how to treat attachments, and whether to archive the old Session, which is more change and state than reusing blanks.

Let a request without a preset reuse only a blank of the Host default preset. The Client does not know the default preset and would have to request the agentPresets.list() roster.

Record a persisted source-to-blank-Session map in the Client. It duplicates the preset each blank already records and must handle stale entries and per-origin isolation.

Clear the existing draft in place when the preset changes (clearPreviousDraft: true). It deletes a draft the user was writing in the other mode.

Also change the Host to always call presets.select when reusing a loaded blank. It fully keeps #5775's goal but is outside this Client-only fix; see Deferred work.

Verification

  • ui-workspace unit tests: New Session without options returns to the existing blank; a request without a preset reuses any blank, a request with a preset reuses only a blank listing the same preset, and a new Session is created when none matches. navigation.ts has 100% per-file coverage.
  • Regression localization: the same unit probe on the PR #5775 commit that made this change and on its parent, plus a browser reproduction on builds of both, confirmed that the draft loss comes from that change.

Consequences

  • New Session no longer guarantees the current preset definition: a reused blank whose Agent is still loaded in the Host with the same preset id keeps its creation-time composition; a blank resumed after a Host restart composes the current definition.
  • New Session may reuse a blank left by a preset flow such as the Creator entries; the Host switches it back to the default preset and its draft stays.
  • The new-session-blank-reuse upgrade guide records the change relative to 0.2.1-rc.2.

Deferred work

  • Host reuseLive (packages/api/session-controller/src/agent.ts) returns the loaded Agent unchanged when the preset id matches and does not call presets.select. select decides whether a definition was registered again by comparing Generation objects: when they are the same it does nothing; when they differ it recomposes under the same Session id with the current definition and records agent-preset/selected; on a started Session it throws agent-preset/locked, and the caller creates a new Session instead. Removing the target === current early return and always calling select keeps drafts while meeting #5775's goal that New Session composes the current definition; it needs a Host test, and updates to the reuseLive JSDoc and to the upgrade guide's statement that the current preset definition is no longer guaranteed.

中文

问题

0.2.0-rc.2 中,新会话(左侧栏按钮、工作区“+”和快捷键,均调用不带选项的 uiWorkspace.startSession)复用工作区内第一个空白会话。PR #5775(首次发布于 dsh-v0.2.1-alpha.2)改为每次新建 Session 与 Agent,目的是在用户修改预设定义后,新会话按当前定义装配,而不是沿用复用空白会话的旧装配(升级指南)。

空白会话不是当前会话时不在 Session 树中显示,返回它的唯一入口是新会话。改为每次新建后,用户在空白会话中写下草稿、切到其他会话再点新会话,会进入另一个空的 Session;原草稿仍按会话 id 保存在 localStorage,但没有界面入口可以回到它。0.2.1-rc.2 因此丢失新会话的未发送草稿。

此外,创造模式入口(startSession(…, { agentPreset: 'cordis', prompt, clearPreviousDraft: false }))复用第一个空白会话并把它切换到 Creator:已有普通草稿时,草稿留在 Creator 模式下,Creator 提示语不会填入;反之新会话也可能接管 Creator 的空白会话。

决策

只修改前端(ui-workspace),Host 不变:

  • 不带选项的 startSession 重新走复用分支,与 openWorkspace、connectWorkspace 和带选项的 startSession 使用同一规则。
  • createInWorkspace 在未开始、未归档、仍属于该工作区的空白会话中选第一个。请求指明预设时,跳过列出的预设(projectionValues.agentPreset)为其他值的空白会话,未列出预设的空白会话仍可用;请求未指明预设时任何空白会话都可用,由 Host 切换到默认预设。没有可用的空白会话时由 Host 新建。

结果:新会话回到原来的空白会话,未发送的草稿保留;创造模式等预设流程不会接管列出其他预设的空白会话,用户的普通草稿不会被切到 Creator 下。不新增持久化状态,前端也不读取预设名单。

考虑过的替代方案

完全回退 PR #5775 的这项改动,所有请求都复用第一个空白会话。 草稿可以回来,但创造模式等预设流程会接管用户普通草稿所在的空白会话,把它切到 Creator,草稿留在 Creator 下,提示语也填不进去。

保持每次新建,把被丢下的空白会话中的草稿迁移到新会话。 需要定义多个空白会话时迁移哪一个、附件如何处理、旧会话是否归档,改动和状态都比按预设复用多。

未指明预设的请求只复用 Host 默认预设的空白会话。 前端不知道默认预设,需要额外请求 agentPresets.list() 名单。

在前端记录“来源 → 空白会话 id”的映射并持久化。 与空白会话自身记录的预设重复,需要处理映射过期、按浏览器 origin 隔离等问题。

预设变化时在原会话上清空草稿(clearPreviousDraft: true)。 会删除用户在另一种模式下写到一半的草稿。

同时修改 Host,让复用内存中的空白会话时总是调用 presets.select。 能完整保留 #5775 的目的,但不在本次只修前端的范围内,见“推迟工作”。

验证

  • ui-workspace 单元测试:不带选项的新会话回到已有空白会话;未指明预设时复用任何空白会话,指明预设时只复用列出相同预设的空白会话,没有时新建。navigation.ts 逐文件覆盖率 100%。
  • 回归定位:在 PR #5775 中做出这项改动的提交及其父提交上运行同一单元探针,以及在两侧构建上用浏览器复现,确认草稿丢失由该改动引入。

后果

  • 新会话不再保证使用当前预设定义:复用的空白会话若其 Agent 仍在 Host 内存中且预设 id 相同,沿用创建时的装配;Host 重启后恢复的空白会话按当前定义装配。
  • 新会话可能复用创造模式等预设流程留下的空白会话,Host 把它切回默认预设,其中的草稿保留。
  • 升级指南 new-session-blank-reuse 记录相对 0.2.1-rc.2 的行为变化。

推迟工作

  • Host reuseLive(packages/api/session-controller/src/agent.ts)在预设 id 相同时直接返回内存中的 Agent,不调用 presets.select。select 用定义的 Generation 对象是否相同判断定义是否重新注册过:相同则不做任何事;不同则在同一会话 id 上按当前定义重新装配并记录 agent-preset/selected;会话已开始时抛出 agent-preset/locked,调用方改为新建。去掉 target === current 的提前返回、改为总是调用 select,可以在保留草稿的同时满足 #5775“新会话按当前定义装配”的目的;需要配套 Host 测试,并更新 reuseLive 的 JSDoc 和上述升级指南中“不再保证当前预设定义”的说明。