From 9745a0d43a979d34c44c2a42d8a485d03a25de71 Mon Sep 17 00:00:00 2001 From: Tianyi Cui <53024+tianyicui@users.noreply.github.com> Date: Tue, 14 Jul 2026 23:36:04 +0800 Subject: [PATCH] fix: reject empty configured session ids --- packages/core/agent-loop/src/index.ts | 2 +- packages/core/agent-loop/tests/config-session-id.spec.ts | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/core/agent-loop/src/index.ts b/packages/core/agent-loop/src/index.ts index 8d9a184cc7..325ba7b92d 100644 --- a/packages/core/agent-loop/src/index.ts +++ b/packages/core/agent-loop/src/index.ts @@ -377,7 +377,7 @@ export class AgentLoop extends Service implements AgentFactory { static Config = z.object({ agents: z.array(z.object({ id: z.string().required(), - sessionId: z.string(), + sessionId: z.string().min(1), model: z.string(), cwd: z.string(), resumeSessionId: z.string(), diff --git a/packages/core/agent-loop/tests/config-session-id.spec.ts b/packages/core/agent-loop/tests/config-session-id.spec.ts index 096a6eff9e..bd2a5522df 100644 --- a/packages/core/agent-loop/tests/config-session-id.spec.ts +++ b/packages/core/agent-loop/tests/config-session-id.spec.ts @@ -35,6 +35,15 @@ async function makeCoreContext(): Promise { } describe('config-driven session id', () => { + it('rejects an empty exact id before publishing an agent', async () => { + const ctx = await makeCoreContext() + await expect(ctx.plugin(AgentLoop, { + agents: [{ id: 'main', sessionId: SessionId(''), model: 'mock' }], + })).rejects.toThrow('expected string length >= 1') + expect(ctx.agents.get(SessionId(''))).toBeUndefined() + await ctx.fiber.dispose() + }) + it('accepts one exact fresh id and rejects it alongside a resume id', async () => { const exact = await makeCoreContext() await exact.plugin(AgentLoop, {