From d2d61ad668a03caf56378ec54418e41bfb8f3945 Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Thu, 1 Oct 2026 02:29:36 -0700 Subject: [PATCH 1/7] fix(agent): clamp an over-long skill instead of refusing its frame A skill name is a display label; nothing resolves against it. Bounding it with `.max(256)` therefore bought a cosmetic guarantee at the price of the frame it rides on, and in both directions: - live, `useAgentSession`'s `onRaw` drops an `agent_tool_call` that fails the schema, so the row the user is watching never settles and shimmers on "Loading " indefinitely; - on reload, `zAgentMessages` runs through `agentRestClient`'s `request`, which calls `parse`, so a single over-long row throws away the entire thread transcript rather than one tool chip. Before this branch the field was stripped at the `zAgentMessageContent` boundary, so neither could happen; routing the persisted parse through `zPersistedToolCallSummary` is what exposed it. Clamp instead, the same keep-the-frame choice `zAgentMessageDoneData.usage` makes with `.catch`, and the opposite of `node_locator_id`, which is an identity later code resolves and so must refuse a value it cannot honour. Both regressions fail on the rejecting schema and pass on the clamp. --- .../agent/schemas/agentApiSchema.test.ts | 46 ++++++++++++++++++- .../agent/schemas/agentApiSchema.ts | 26 ++++++++++- 2 files changed, 69 insertions(+), 3 deletions(-) diff --git a/src/workbench/extensions/agent/schemas/agentApiSchema.test.ts b/src/workbench/extensions/agent/schemas/agentApiSchema.test.ts index 16fb2a57d55..65df90de9f0 100644 --- a/src/workbench/extensions/agent/schemas/agentApiSchema.test.ts +++ b/src/workbench/extensions/agent/schemas/agentApiSchema.test.ts @@ -1,4 +1,4 @@ -import { describe, expect, it } from 'vitest' +import { assert, describe, expect, it } from 'vitest' import { AGENT_WS_EVENT_TYPES, @@ -114,6 +114,50 @@ describe('agentApiSchema contract subtleties', () => { expect(parsed).toMatchObject({ data: { skill: null } }) }) + it('clamps an over-long skill instead of dropping the tool-call frame', () => { + const parsed = zAgentWsEvent.parse({ + type: 'agent_tool_call', + data: { + tool_call_id: 'call-1', + tool_name: 'load_skill', + status: 'running', + skill: 'a'.repeat(300), + message_id: 'm1', + thread_id: 't1' + } + }) + + assert(parsed.type === 'agent_tool_call') + expect(parsed.data.skill).toBe('a'.repeat(256)) + }) + + it('keeps a whole transcript readable when one persisted skill is over-long', () => { + const parsed = zAgentMessages.parse([ + { + id: 'row-1', + thread_id: 't1', + turn_id: 'turn-a', + seq: 1, + role: 'assistant', + status: 'complete', + content: { + text: 'Done', + tool_calls: [ + { + id: 'audit-row-uuid-1', + tool_call_id: 'call-1', + tool_name: 'load_skill', + status: 'success', + skill: 'a'.repeat(300) + } + ] + } + } + ]) + + expect(parsed[0].content?.tool_calls?.[0].skill).toBe('a'.repeat(256)) + }) + it('accepts agent_message_done with usage null (cancelled turn)', () => { expect( zAgentWsEvent.safeParse({ diff --git a/src/workbench/extensions/agent/schemas/agentApiSchema.ts b/src/workbench/extensions/agent/schemas/agentApiSchema.ts index 627801b3649..21eb51f1206 100644 --- a/src/workbench/extensions/agent/schemas/agentApiSchema.ts +++ b/src/workbench/extensions/agent/schemas/agentApiSchema.ts @@ -95,6 +95,28 @@ export const zAgentRunMode = zGeneratedAgentRunMode.superRefine( ) export type AgentRunModeValue = AgentRunModePreference['mode'] +const SKILL_NAME_MAX = 256 + +/** + * A `load_skill` call's skill name, on both the live and the reload path. It + * is a display label and nothing resolves against it, so an over-long value + * is clamped rather than rejected: rejecting would cost the caller the whole + * frame it rides on. On the live path a refused `agent_tool_call` is dropped + * by `useAgentSession`'s `onRaw`, so the row never settles and keeps + * shimmering "Loading "; on the reload path `zAgentMessages` is run + * through `agentRestClient`'s `request`, which uses `parse`, so one row would + * throw away the entire thread transcript. Same keep-the-frame choice + * `zAgentMessageDoneData.usage` makes with `.catch`, and the opposite of + * `zAgentActiveTabData.node_locator_id`, which is an identity that later code + * resolves and so must refuse a value it cannot honour. + */ +const zSkillName = z + .string() + .nullish() + .transform((skill) => + typeof skill === 'string' ? skill.slice(0, SKILL_NAME_MAX) : skill + ) + /** * One entry of a persisted assistant row's `content.tool_calls` (see * `agentTranscript.ts`'s `parseToolCallEntry`), the reload-path counterpart @@ -115,7 +137,7 @@ export const zPersistedToolCallSummary = zToolCallSummary.extend({ tool_call_id: z.string().optional(), status: z.string(), duration_ms: z.number().optional(), - skill: z.string().max(256).nullish() + skill: zSkillName }) /** @@ -187,7 +209,7 @@ const zAgentToolCallData = z tool_call_id: z.string(), tool_name: z.string(), status: z.enum(['running', 'success', 'error']), - skill: z.string().max(256).nullish(), + skill: zSkillName, args: z.never().optional(), duration_ms: z.number().optional(), message_id: z.string(), From ca4f86281451d01ce002c94fc4b2bd781c4a0d9c Mon Sep 17 00:00:00 2001 From: Christian Byrne Date: Fri, 2 Oct 2026 02:31:25 -0700 Subject: [PATCH 2/7] fix(agent): preserve Unicode when clamping skill names --- .../agent/schemas/agentApiSchema.test.ts | 17 +++++++++++++++++ .../extensions/agent/schemas/agentApiSchema.ts | 4 +++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/workbench/extensions/agent/schemas/agentApiSchema.test.ts b/src/workbench/extensions/agent/schemas/agentApiSchema.test.ts index 65df90de9f0..c023c5f11ab 100644 --- a/src/workbench/extensions/agent/schemas/agentApiSchema.test.ts +++ b/src/workbench/extensions/agent/schemas/agentApiSchema.test.ts @@ -131,6 +131,23 @@ describe('agentApiSchema contract subtleties', () => { expect(parsed.data.skill).toBe('a'.repeat(256)) }) + it('does not split a Unicode code point when clamping a skill', () => { + const parsed = zAgentWsEvent.parse({ + type: 'agent_tool_call', + data: { + tool_call_id: 'call-1', + tool_name: 'load_skill', + status: 'running', + skill: `${'a'.repeat(255)}πŸ˜€tail`, + message_id: 'm1', + thread_id: 't1' + } + }) + + assert(parsed.type === 'agent_tool_call') + expect(parsed.data.skill).toBe(`${'a'.repeat(255)}πŸ˜€`) + }) + it('keeps a whole transcript readable when one persisted skill is over-long', () => { const parsed = zAgentMessages.parse([ { diff --git a/src/workbench/extensions/agent/schemas/agentApiSchema.ts b/src/workbench/extensions/agent/schemas/agentApiSchema.ts index 21eb51f1206..e0521bd8c04 100644 --- a/src/workbench/extensions/agent/schemas/agentApiSchema.ts +++ b/src/workbench/extensions/agent/schemas/agentApiSchema.ts @@ -114,7 +114,9 @@ const zSkillName = z .string() .nullish() .transform((skill) => - typeof skill === 'string' ? skill.slice(0, SKILL_NAME_MAX) : skill + typeof skill === 'string' + ? Array.from(skill).slice(0, SKILL_NAME_MAX).join('') + : skill ) /** From d60d428fd5b109b7c5b05f88fee6365f738e8191 Mon Sep 17 00:00:00 2001 From: bymyself Date: Fri, 2 Oct 2026 22:53:01 +0000 Subject: [PATCH 3/7] docs(agent): keep the skill clamp comment local Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19726#discussion_r4162763661 --- .../extensions/agent/schemas/agentApiSchema.ts | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/src/workbench/extensions/agent/schemas/agentApiSchema.ts b/src/workbench/extensions/agent/schemas/agentApiSchema.ts index e0521bd8c04..923179128d2 100644 --- a/src/workbench/extensions/agent/schemas/agentApiSchema.ts +++ b/src/workbench/extensions/agent/schemas/agentApiSchema.ts @@ -98,17 +98,8 @@ export type AgentRunModeValue = AgentRunModePreference['mode'] const SKILL_NAME_MAX = 256 /** - * A `load_skill` call's skill name, on both the live and the reload path. It - * is a display label and nothing resolves against it, so an over-long value - * is clamped rather than rejected: rejecting would cost the caller the whole - * frame it rides on. On the live path a refused `agent_tool_call` is dropped - * by `useAgentSession`'s `onRaw`, so the row never settles and keeps - * shimmering "Loading "; on the reload path `zAgentMessages` is run - * through `agentRestClient`'s `request`, which uses `parse`, so one row would - * throw away the entire thread transcript. Same keep-the-frame choice - * `zAgentMessageDoneData.usage` makes with `.catch`, and the opposite of - * `zAgentActiveTabData.node_locator_id`, which is an identity that later code - * resolves and so must refuse a value it cannot honour. + * Display-only, so an over-long name is clamped. Rejecting it would drop + * the live frame or the whole persisted transcript. */ const zSkillName = z .string() From 81ef0b3261ed2cdba0dbc1c4bb584a44c181d905 Mon Sep 17 00:00:00 2001 From: bymyself Date: Sat, 3 Oct 2026 06:49:59 +0000 Subject: [PATCH 4/7] test(agent): parse the persisted row before asserting skill --- .../extensions/agent/schemas/agentApiSchema.test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/workbench/extensions/agent/schemas/agentApiSchema.test.ts b/src/workbench/extensions/agent/schemas/agentApiSchema.test.ts index c023c5f11ab..3d45ee24b9d 100644 --- a/src/workbench/extensions/agent/schemas/agentApiSchema.test.ts +++ b/src/workbench/extensions/agent/schemas/agentApiSchema.test.ts @@ -8,6 +8,7 @@ import { zAgentError, zAgentMessage, zAgentMessages, + zPersistedToolCallSummary, zAgentTurnAccepted, zAgentWsEvent } from './agentApiSchema' @@ -172,7 +173,10 @@ describe('agentApiSchema contract subtleties', () => { } ]) - expect(parsed[0].content?.tool_calls?.[0].skill).toBe('a'.repeat(256)) + const toolCall = zPersistedToolCallSummary.parse( + parsed[0].content?.tool_calls?.[0] + ) + expect(toolCall.skill).toBe('a'.repeat(256)) }) it('accepts agent_message_done with usage null (cancelled turn)', () => { From a9307199c31e0f3753f2b516148ebf0ce1d4c1ef Mon Sep 17 00:00:00 2001 From: bymyself Date: Sat, 3 Oct 2026 20:01:21 +0000 Subject: [PATCH 5/7] fix(agent): bound skill-name normalization work Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19987#discussion_r4172079573 --- src/workbench/extensions/agent/schemas/agentApiSchema.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/workbench/extensions/agent/schemas/agentApiSchema.ts b/src/workbench/extensions/agent/schemas/agentApiSchema.ts index 923179128d2..83339aceb33 100644 --- a/src/workbench/extensions/agent/schemas/agentApiSchema.ts +++ b/src/workbench/extensions/agent/schemas/agentApiSchema.ts @@ -106,7 +106,9 @@ const zSkillName = z .nullish() .transform((skill) => typeof skill === 'string' - ? Array.from(skill).slice(0, SKILL_NAME_MAX).join('') + ? Array.from(skill.slice(0, SKILL_NAME_MAX * 2)) + .slice(0, SKILL_NAME_MAX) + .join('') : skill ) From 96a319f2aa469c3eb1d415bf52b55c0e1b00f2be Mon Sep 17 00:00:00 2001 From: bymyself Date: Sat, 3 Oct 2026 20:01:34 +0000 Subject: [PATCH 6/7] docs(agent): describe persisted clamp scope accurately Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19987#discussion_r4172079586 --- src/workbench/extensions/agent/schemas/agentApiSchema.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/workbench/extensions/agent/schemas/agentApiSchema.ts b/src/workbench/extensions/agent/schemas/agentApiSchema.ts index 83339aceb33..8ab748ac722 100644 --- a/src/workbench/extensions/agent/schemas/agentApiSchema.ts +++ b/src/workbench/extensions/agent/schemas/agentApiSchema.ts @@ -99,7 +99,7 @@ const SKILL_NAME_MAX = 256 /** * Display-only, so an over-long name is clamped. Rejecting it would drop - * the live frame or the whole persisted transcript. + * the live frame or the persisted tool call. */ const zSkillName = z .string() From 585182226e6b0d9251e1141c831b42b962ba5bec Mon Sep 17 00:00:00 2001 From: bymyself Date: Sat, 3 Oct 2026 20:02:00 +0000 Subject: [PATCH 7/7] test(agent): exercise persisted clamp through hydration Addresses review feedback: https://github.com/Comfy-Org/ComfyUI_frontend/pull/19987#discussion_r4172079568 --- .../agent/schemas/agentApiSchema.test.ts | 31 ------------------- .../services/agent/agentTranscript.test.ts | 23 ++++++++++++++ 2 files changed, 23 insertions(+), 31 deletions(-) diff --git a/src/workbench/extensions/agent/schemas/agentApiSchema.test.ts b/src/workbench/extensions/agent/schemas/agentApiSchema.test.ts index 3d45ee24b9d..51d00a40dba 100644 --- a/src/workbench/extensions/agent/schemas/agentApiSchema.test.ts +++ b/src/workbench/extensions/agent/schemas/agentApiSchema.test.ts @@ -8,7 +8,6 @@ import { zAgentError, zAgentMessage, zAgentMessages, - zPersistedToolCallSummary, zAgentTurnAccepted, zAgentWsEvent } from './agentApiSchema' @@ -149,36 +148,6 @@ describe('agentApiSchema contract subtleties', () => { expect(parsed.data.skill).toBe(`${'a'.repeat(255)}πŸ˜€`) }) - it('keeps a whole transcript readable when one persisted skill is over-long', () => { - const parsed = zAgentMessages.parse([ - { - id: 'row-1', - thread_id: 't1', - turn_id: 'turn-a', - seq: 1, - role: 'assistant', - status: 'complete', - content: { - text: 'Done', - tool_calls: [ - { - id: 'audit-row-uuid-1', - tool_call_id: 'call-1', - tool_name: 'load_skill', - status: 'success', - skill: 'a'.repeat(300) - } - ] - } - } - ]) - - const toolCall = zPersistedToolCallSummary.parse( - parsed[0].content?.tool_calls?.[0] - ) - expect(toolCall.skill).toBe('a'.repeat(256)) - }) - it('accepts agent_message_done with usage null (cancelled turn)', () => { expect( zAgentWsEvent.safeParse({ diff --git a/src/workbench/extensions/agent/services/agent/agentTranscript.test.ts b/src/workbench/extensions/agent/services/agent/agentTranscript.test.ts index 81832efc009..91ab651aa44 100644 --- a/src/workbench/extensions/agent/services/agent/agentTranscript.test.ts +++ b/src/workbench/extensions/agent/services/agent/agentTranscript.test.ts @@ -276,6 +276,29 @@ describe('normalizeAgentTranscript', () => { ) }) + it('clamps an over-long persisted skill while restoring the transcript', () => { + const message = row(1, 'assistant', 'turn-a', 'Done', 'row-1') + message.content = { + tool_calls: [ + { + id: 'audit-row-uuid-1', + tool_call_id: 'call-1', + tool_name: 'load_skill', + status: 'success', + skill: 'a'.repeat(300) + } + ] + } + + const parsed = zAgentMessages.parse([message]) + + expect(normalizeAgentTranscript(parsed).messages[0].parts[0]).toMatchObject( + { + skill: 'a'.repeat(256) + } + ) + }) + it('retains a persisted tool call with a null skill', () => { const message = row(1, 'assistant', 'turn-a', 'Done', 'row-1') message.content = {