fix(codex): defer session persistence until user activity

This commit is contained in:
weishu
2026-07-12 11:00:08 +08:00
parent 65e1708c78
commit 5a377e38b9
35 changed files with 2118 additions and 131 deletions
+29
View File
@@ -32,6 +32,14 @@ vi.mock('@/agent/sessionFactory', () => ({
sessionInfo: harness.sessionInfo
}
}),
bootstrapLazySession: vi.fn(async (options: Record<string, unknown>) => {
harness.bootstrapArgs.push({ ...options, lazy: true })
return {
api: {},
session: harness.session,
sessionInfo: harness.sessionInfo
}
}),
bootstrapExistingSession: vi.fn(async (options: Record<string, unknown>) => {
harness.bootstrapArgs.push(options)
return {
@@ -202,6 +210,27 @@ describe('runCodex', () => {
expect(mockCodexSession.setServiceTier).not.toHaveBeenCalled()
})
it('uses lazy bootstrap for a fresh terminal launch', async () => {
await runCodexImpl({ workingDirectory: '/tmp/project' })
expect(harness.bootstrapArgs[0]).toEqual(expect.objectContaining({
workingDirectory: '/tmp/project',
lazy: true
}))
expect(harness.loopArgs[0]).toEqual(expect.objectContaining({
replayTranscriptHistoryOnStart: true
}))
})
it('keeps eager bootstrap for runner launches', async () => {
await runCodexImpl({
startedBy: 'runner',
workingDirectory: '/tmp/project'
})
expect(harness.bootstrapArgs[0]).not.toHaveProperty('lazy')
})
it('replays transcript history when attaching a new Hapi session to an existing Codex thread', async () => {
await runCodexImpl({
workingDirectory: '/tmp/project',