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

View File

@@ -102,6 +102,22 @@ Sources: [`packages/core/session/src/types.ts:316`](../packages/core/session/src
Source: [`packages/core/agent/src/types.ts:296`](../packages/core/agent/src/types.ts)
### `agent-preset/*`
#### `agent-preset/selected` — log-only
```ts persistence-catalog
/**
* The session's agent preset was chosen after creation, while the session
* was still blank. Log-only: it records the composition later turns ran
* under, so a resumed or forked session rebuilds the same one instead of
* the header's creation-time value.
*/
'agent-preset/selected': { agentPreset: string }
```
Source: [`packages/preset/agent-presets/src/session.ts:26`](../packages/preset/agent-presets/src/session.ts)
### `approval/*`
#### `approval/asked` — log-only