fix(agent-presets): treat absent turn boundary as blank

This commit is contained in:
_Kerman
2026-08-27 23:12:22 +08:00
parent 3a34b7870e
commit 2bcd4cc552
2 changed files with 4 additions and 11 deletions
+2 -4
View File
@@ -715,10 +715,8 @@ export class AgentPresets extends TypertRemoteService {
// model-loop execution; standalone plugin events never open one, so a
// session that has only run commands is still blank.
const boundary = this.selfCtx.sessionProjections.stateOf(agent.session, 'turnBoundary')
if (boundary === undefined) {
throw new Error('agent-presets: select requires the turnBoundary session projection')
}
if (boundary.openTurnStartSeq !== null || boundary.lastTurn > 0) {
if (boundary !== undefined
&& (boundary.openTurnStartSeq !== null || boundary.lastTurn > 0)) {
throw new PresetLockedError(agent.id, agentPreset)
}
const preset = await this.recompose(agent.ctx, agentPreset)
@@ -366,7 +366,7 @@ describe('switching one session\'s composition', () => {
expect(recordedPreset(agent)).toEqual({ agentPreset: 'minimal' })
})
it('fails loudly when a composition omits the turn boundary projection', async () => {
it('treats an absent turn boundary as no prior turn', async () => {
const ctx = await harness()
const agent = await agentOn(ctx, 'sel-no-turn-boundary', 'standard')
const stateOf = ctx.sessionProjections.stateOf.bind(ctx.sessionProjections)
@@ -374,12 +374,7 @@ describe('switching one session\'s composition', () => {
key === 'turnBoundary' ? undefined : stateOf(session, key)
))
const failure = await remoteFailure(ctx.agentPresets.select(agent, 'minimal'))
expect(failure).toMatchObject({
code: 'internal',
message: expect.stringContaining('select requires the turnBoundary session projection') as string,
})
expect(await ctx.agentPresets.select(agent, 'minimal')).toBe('minimal')
})
it('serializes two concurrent switches on one session', async () => {