fix(web): record which preset a session actually runs

The creation header names the preset a session STARTED with and is frozen,
which is correct — it is a creation fact. Switching is legal only while a
session is blank, and that looked like enough: no history exists yet.

It is not, because the switch's effect outlives the blank window. The user
switches, then sends the first message; every turn from there runs under the
new composition while the header still names the old one. The session is
then locked around a misrecorded preset, and resume reads the header to
rebuild it — composing one preset's tools over a history another produced,
which is exactly the replay the blank-only lock exists to prevent, reached
by another route. A picker showed `standard` for a session running
`core-web`.

A switch is now an `agent-preset/selected` event appended after the swap
commits, and `resolveSessionPreset()` (last selection, else the header) is
what every reconstruction reads: the summary, resume, the conflict guard,
and the fork introduced one layer down.
This commit is contained in:
Yichen Jiang
2026-08-05 15:46:44 +08:00
parent a2ab09003f
commit 98fbe0ee94
18 changed files with 192 additions and 44 deletions
+4 -4
View File
@@ -109,15 +109,15 @@ serviceFor<K extends string & keyof Context>(agent: { ctx: Context }, name: K):
* therefore restores the previous composition rather than leaving the agent
* with nothing.
* @param agentCtx - the agent's scope context.
* @param id - the profile to compose the agent from instead.
* @returns the profile now installed.
* @throws when the profile is unknown or its composition is unusable; the
* @param id - the preset to compose the agent from instead.
* @returns the preset now installed.
* @throws when the preset is unknown or its composition is unusable; the
* previous composition is restored first.
*/
async recompose(agentCtx: Context, id: string): Promise<AgentPreset>
```
Source: [`packages/preset/agent-presets/src/index.ts:56`](../../packages/preset/agent-presets/src/index.ts)
Source: [`packages/preset/agent-presets/src/index.ts:57`](../../packages/preset/agent-presets/src/index.ts)
## `ctx.agents` — `AgentRegistry`