fix(session): retain fork tail until the first inbox change
This commit is contained in:
1 parent
896a6c3e47
commit
0f8552df7f
11 files changed
+55
-34
No files matched your search
@@ -106,6 +106,9 @@ describe('sessions.fork', () => {
|
||||
source.followup(message('A'))
|
||||
await source.whenIdle()
|
||||
const boundary = source.session.snapshotEvents().at(-1)!.seq
|
||||
const title = source.session.append('session/title', {
|
||||
title: 'Title after A', messageSeqs: [], source: { kind: 'user' },
|
||||
})
|
||||
if (anchor === 'message' || anchor === 'turn-end') {
|
||||
source.followup(message('B'))
|
||||
await source.whenIdle()
|
||||
@@ -129,7 +132,9 @@ describe('sessions.fork', () => {
|
||||
? item.content.flatMap(part => part.type === 'text' ? [part.text] : []) : [])
|
||||
expect(userTexts).toEqual(['A', 'C'])
|
||||
expect(adapter.requests.slice(requestCount)).toHaveLength(1)
|
||||
expect(child.session.inheritedEventCount).toBe(boundary + 1)
|
||||
expect(child.session.inheritedEventCount).toBe(title.seq + 1)
|
||||
expect(child.session.snapshotEvents().slice(0, child.session.inheritedEventCount))
|
||||
.toEqual(original.slice(0, title.seq + 1))
|
||||
expect(source.session.snapshotEvents()).toEqual(original)
|
||||
} finally {
|
||||
await ctx.fiber.dispose()
|
||||
@@ -317,10 +322,9 @@ describe('sessions.fork', () => {
|
||||
await ctx.fiber.dispose()
|
||||
})
|
||||
|
||||
it('inherits model selection through the completed turn and excludes later changes', async () => {
|
||||
it.each(['next-turn', 'next-step', null] as const)('inherits model settings before %s inbox changes', async (target) => {
|
||||
const ctx = await composed()
|
||||
const source = liveAgent(ctx, 'session-routed', 0)
|
||||
source.append('turn/start', { turn: 1 })
|
||||
const source = liveAgent(ctx, 'session-routed', 1)
|
||||
source.append('request/header', {
|
||||
header: {
|
||||
config: {
|
||||
@@ -331,16 +335,28 @@ describe('sessions.fork', () => {
|
||||
},
|
||||
reason: 'initial',
|
||||
})
|
||||
source.append('turn/end', { turn: 1, reason: { kind: 'completed' } })
|
||||
source.append('request/header', {
|
||||
header: { config: { provider: 'later-provider', model: 'later-model' } },
|
||||
reason: 'change',
|
||||
})
|
||||
const inherited = source.snapshotEvents()
|
||||
if (target !== null) {
|
||||
source.append('agent/inbox/spliced', {
|
||||
target, start: 0,
|
||||
inserted: [createUserMessage({
|
||||
content: [{ type: 'text', text: 'next input' }], source: { kind: 'user' },
|
||||
})],
|
||||
})
|
||||
source.append('session/title', {
|
||||
title: 'Title after inbox insertion', messageSeqs: [], source: { kind: 'user' },
|
||||
})
|
||||
source.append('request/header', {
|
||||
header: { config: { provider: 'later-provider', model: 'later-model' } },
|
||||
reason: 'change',
|
||||
})
|
||||
}
|
||||
const response = await remote(ctx).fork(request({ sessionId: source.id }))
|
||||
expect(response.ok).toBe(true)
|
||||
if (!response.ok) return
|
||||
const child = ctx.agents.get(response.value.sessionId)
|
||||
if (child === undefined) throw new Error('fork did not publish the child agent')
|
||||
expect(child.session.snapshotEvents().slice(0, child.session.inheritedEventCount)).toEqual(inherited)
|
||||
const assembly = await child.ctx.systemPrompt.assemble()
|
||||
expect(assembly.variables).toMatchObject({
|
||||
provider: 'inherited-provider',
|
||||
|
||||
Reference in new issue
Block a user