From ccd810f84d74ce452d858b553eb0cbdb282d715c Mon Sep 17 00:00:00 2001 From: Tianyi Cui <53024+tianyicui@users.noreply.github.com> Date: Tue, 14 Jul 2026 09:36:22 +0800 Subject: [PATCH] fix: normalize empty stdio resume identity --- packages/ui/stdio-agent/src/stdio-chat.ts | 5 +++-- packages/ui/stdio-agent/tests/stdio-chat.spec.ts | 9 +++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/ui/stdio-agent/src/stdio-chat.ts b/packages/ui/stdio-agent/src/stdio-chat.ts index 76347c91e4..17a11168db 100644 --- a/packages/ui/stdio-agent/src/stdio-chat.ts +++ b/packages/ui/stdio-agent/src/stdio-chat.ts @@ -104,9 +104,10 @@ export function createStdioChat(ctx: Context, config: Config, runtime: StdioRunt // with durable parentSession lineage. Keeping the matching candidates also // covers HMR's publish-new-before-dispose-old ordering without ever falling // through to an unrelated root owned by another app or test fixture. - const matchesConfiguredIdentity = (agent: Agent): boolean => config.resumeSessionId === undefined + const resumeSessionId = config.resumeSessionId === '' ? undefined : config.resumeSessionId + const matchesConfiguredIdentity = (agent: Agent): boolean => resumeSessionId === undefined ? agent.id.startsWith('main-session-') - : agent.id === config.resumeSessionId + : agent.id === resumeSessionId const configuredRoots = new Set(ctx.agents.roots().filter(matchesConfiguredIdentity)) let target: Agent | undefined = [...configuredRoots].at(-1) ctx.on('agent/created', (agent) => { diff --git a/packages/ui/stdio-agent/tests/stdio-chat.spec.ts b/packages/ui/stdio-agent/tests/stdio-chat.spec.ts index 668068a72d..2ebc51e14e 100644 --- a/packages/ui/stdio-agent/tests/stdio-chat.spec.ts +++ b/packages/ui/stdio-agent/tests/stdio-chat.spec.ts @@ -747,6 +747,15 @@ describe('createStdioChat input', () => { await new Promise(r => setImmediate(r)) expect(agent.sent).toHaveLength(1) }) + + it('treats an empty resume session id as a fresh configured identity', async () => { + const { ctx, input } = await setup({ welcome: 'w', resumeSessionId: '' }) + const agent = makeAgent('main-session-fresh') + ctx.agents.register(agent) + input.feed('hi') + await new Promise(r => setImmediate(r)) + expect(agent.sent).toHaveLength(1) + }) }) describe('createStdioChat EOF exit', () => {