Skip to content

[backport core/1.54] feat: restore tool-call work summary on reload and chat switch - #18554

Merged
christian-byrne merged 2 commits into
core/1.54from
backport-18282-to-core-1.54
Sep 23, 2026
Merged

christian-byrne merged 2 commits into
core/1.54from
backport-18282-to-core-1.54

Conversation

@comfy-pr-bot

Copy link
Copy Markdown
Member

Backport of #18282 to core/1.54

Automatically created by backport workflow.

## Before

Reloading the page or switching chats mid-thread dropped a completed
turn's tool-call trace: the collapsible "Worked for Xs" work summary
(with the tool names/durations inside it) that shows up live while the
agent is running would not reappear once the transcript was rehydrated
from history. Only the final reply text survived a refresh.

## After

`GET /agent/threads/:id/messages` now returns each assistant message's
`tool_calls`. This PR reads that field and folds it into the same
`ToolPart` entries the live WebSocket `agent_tool_call` handler already
builds, so a reloaded or chat-switched transcript renders through the
exact same `WorkSummary`/`ActivityTrace` components a live turn uses —
no parallel UI. The collapsible starts closed and expands on click
identically for a historical trace as for a live one, since that
behavior is owned by the (stateless) `CollapsibleRoot` the component
already used.

### What changed

- `agentApiSchema.ts`: adds `zPersistedToolCallSummary`, a validated
FE-side schema for one `content.tool_calls` entry (`id`, `tool_name`,
`status`, `duration_ms`), following the same `.extend()`/local-schema
pattern this file already uses for `pending_ask`. `status` is
deliberately `z.string()` rather than a closed enum, since an
unrecognized value must still surface as a failed `ToolPart` rather than
be dropped by schema validation.
- `agentTranscript.ts`: `normalizeAgentTranscript()` now parses each
assistant row's `content.tool_calls` through that schema into
`ToolPart[]` and appends them to that turn's `AssistantMessage.parts`,
ahead of the row's reply text — mirroring how the live event transport
appends tool/text parts into the same array. A restored
`pending`/`running` call clamps to a terminal `done`/`ok:false` state
unless its row is the one actively backed by a live transport (the
run_approval mid-ask case); `ok`/`success` map to success, everything
else terminal maps to failure; duplicate `callId`s within one row are
deduped; malformed `duration_ms` is rejected without dropping the whole
entry.
- `agentEventTransport.ts`: `createAgentEventTransport()` now seeds its
`tool_call_id` map from any `ToolPart`s already on the message it's
given, so a live frame for an already-restored call updates it in place
instead of duplicating it.
- No changes were needed in `agentConversationStore.ts`: `hydrate()`
already assigns `transcript.messages` (which now carries the tool parts)
straight into the store's `messages`, the same field the live turn path
writes to and the same field the rendering components read.
- Unit tests added to `agentTranscript.test.ts` (parsing, ordering,
multiple calls, in-flight status, malformed/missing `tool_calls`,
restore-without-transport clamping, broadened terminal vocabulary,
duration guard, dedup) and `agentConversationStore.test.ts` (hydrate
wiring into `store.messages`, and a chat-switch A→B→A test confirming a
tool-call summary doesn't bleed across chats).
- One Playwright e2e test added
(`browser_tests/tests/agent/agentToolCallHistoryPersistence.spec.ts`):
sends a message, mocks the history GET to return a completed turn with
two tool calls (using both the `ok` and `success` terminal literals),
reloads, and asserts the same work-summary button appears with the exact
expected duration label, stays collapsed by default, and expands to show
both tool names.

### Known limitations

The restored "Worked for Xs" headline is computed client-side from
`totalDurationMs(parts)`, but only tool-call durations are restored —
thinking-span durations are not persisted/parsed in this PR. A turn that
spent significant time thinking can therefore show a different total
live vs. after a reload (or across two tabs on the same conversation,
one reloaded and one not). Persisting/serving the turn's worked-duration
(or its thinking spans) so live and restored render from the same source
is tracked as a follow-up rather than fixed here.

### Compatibility

This is safe to merge independently of the backend change: when a
response has no `tool_calls` key (today's shape, or a user message),
parsing simply returns `undefined` and nothing is appended — covered by
an explicit unit test. The full frontend behavior (tool history actually
showing up after reload) only takes effect once the corresponding cloud
backend change,
[Comfy-Org/cloud#9960](Comfy-Org/cloud#9960),
lands. That PR's shared `persist.ToolCallWireStatus` translation emits
`success`/`error` as the two terminal wire values for both the live and
reload paths, and excludes `pending`/`running` rows from restored
history entirely; this PR's parsing handles that vocabulary (plus the
legacy `ok`/`error` pair and any other unrecognized terminal string,
defensively) either way.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_01RuB3pFMNyS3AE7JYNFNesb

---
_Generated by [Claude
Code](https://claude.ai/code/session_01RuB3pFMNyS3AE7JYNFNesb)_

---------

Co-authored-by: Christian Byrne <cbyrne@comfy.org>
@comfy-pr-bot comfy-pr-bot added the backport Backporting a PR onto a release candidate label Sep 23, 2026
@comfy-pr-bot
comfy-pr-bot enabled auto-merge (squash) September 23, 2026 05:43
@vercel

vercel Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
billing-web Ignored Ignored Sep 23, 2026 6:44am UTC

Request Review

@christian-byrne christian-byrne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified patch-equivalent to the approved source: #18282. Only stable-branch hunk offsets differ.

@christian-byrne
christian-byrne force-pushed the backport-18282-to-core-1.54 branch from 2657cb2 to 4b506c2 Compare September 23, 2026 05:49
@github-actions

github-actions Bot commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

🎨 Storybook: ✅ Built — View Storybook

Details

⏰ Completed at: 09/23/2026, 07:08:23 AM UTC

Links

🎭 Playwright: ✅ 1941 passed, 0 failed

📊 Browser Reports
  • chromium: View Report (✅ 1920 / ❌ 0 / ⚠️ 0 / ⏭️ 13)
  • chromium-2x: View Report (✅ 2 / ❌ 0 / ⚠️ 0 / ⏭️ 0)
  • chromium-0.5x: View Report (✅ 1 / ❌ 0 / ⚠️ 0 / ⏭️ 0)
  • mobile-chrome: View Report (✅ 18 / ❌ 0 / ⚠️ 0 / ⏭️ 0)

@datadog-official

This comment has been minimized.

@github-actions github-actions Bot added the risk:high PR risk grade (advisory shadow check; grader-owned) label Sep 23, 2026
@codecov

codecov Bot commented Sep 23, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@             Coverage Diff             @@
##           core/1.54   #18554    +/-   ##
===========================================
  Coverage      83.62%   83.63%            
===========================================
  Files           2097     2098     +1     
  Lines         123850   123996   +146     
  Branches       31549    31592    +43     
===========================================
+ Hits          103568   103701   +133     
- Misses         20103    20116    +13     
  Partials         179      179            
Flag Coverage Δ
unit 78.64% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...rkbench/extensions/agent/schemas/agentApiSchema.ts 100.00% <100.00%> (ø)
...nsions/agent/services/agent/agentEventTransport.ts 100.00% <100.00%> (ø)
...extensions/agent/services/agent/agentTranscript.ts 97.72% <100.00%> (+1.62%) ⬆️

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@christian-byrne christian-byrne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backport compatibility fix verified: browser typecheck and repository pre-commit/pre-push gates pass.

@christian-byrne
christian-byrne merged commit 97ca6cb into core/1.54 Sep 23, 2026
23 of 24 checks passed
@christian-byrne
christian-byrne deleted the backport-18282-to-core-1.54 branch September 23, 2026 06:47
christian-byrne pushed a commit that referenced this pull request Sep 23, 2026
…oolCallGroup UI (#18579)

## Summary

`browser_tests/tests/agent/agentToolCallHistoryPersistence.spec.ts:24`
("keeps a completed turn work summary after a browser refresh") fails
deterministically on `core/1.54` since #18554. Fixes it by correcting
the test's UI assertion to match this branch's actual, working
agent-panel component.

<details>
<summary>Full context for agent readers</summary>

## Root cause

#18554 backported #18282 ("restore tool-call work summary on reload and
chat switch") from `main`, including a **new** E2E test. The data-layer
change it ported — `agentTranscript.ts`'s `normalizeAgentTranscript`,
which folds a persisted assistant row's `content.tool_calls` into
`ToolPart`s — is **byte-for-byte identical** between `main` and the
backport, and its 49 existing/added unit tests
(`agentTranscript.test.ts`, `agentConversationStore.test.ts`) pass
unchanged. So the actual bug the PR fixes (tool-call history vanishing
on reload) is already correctly fixed on `core/1.54`.

What's missing is a separate, **unrelated, unbackported** UI redesign
that #18282 on `main` happens to sit on top of: `main` replaced the
agent panel's `ToolCallGroup.vue` (dynamic label: `"Ran {count} tool
calls for {seconds} seconds"`) with a
`WorkSummary.vue`/`ActivityTrace.vue` split, where a settled group's
trigger is the static i18n string `agent.worked` ("Worked"). That
redesign was never backported to `core/1.54` — `ToolCallGroup.vue` is
still what's rendered here, and it still (correctly, per its own pinned
tests, e.g. `T-11 / PM-661 / FE-1301` in `ToolCallGroup.test.ts`)
renders the dynamic "Ran N tool calls..." label.

The backported test, however, was carried over verbatim from `main` and
asserts a button named `enMessages.agent.worked` — text that no
component on `core/1.54` renders (`agent.worked` has zero non-test
usages in this codebase). Reproduced locally: the persisted transcript
restores its `ToolPart`s correctly, but the actual rendered trigger
reads `"Ran 2 tool calls for 0.6 seconds"`, so `getByRole('button', {
name: 'Worked', exact: true })` never matches → the reported timeout.

## Fix

Rather than backport the full main-branch `WorkSummary`/`ActivityTrace`
redesign (a large, unrelated surface, under time pressure and not what
this bug is about), this updates the test's assertion to the label
`ToolCallGroup.vue` actually — and correctly — produces for the mocked
2-call, 600ms-total turn: `/ran 2 tool calls for 0\.6 seconds/i`. The
rest of the test (aria-expanded default state, expand-to-reveal
humanized tool names "Search nodes"/"Add node") already passed against
the existing `ToolCallCard.vue`/`agentToolGlyph.ts` and is untouched.

## Verification

- `pnpm eslint` on the changed file: clean.
- `pnpm exec vue-tsc --noEmit`: no errors on the changed file.
- `npx vitest run` on `ToolCallGroup.test.ts` +
`agentTranscript.test.ts`: 49/49 pass (confirms the data-layer restore
and existing `ToolCallGroup` behavior are both intact and untouched by
this change).
- Pre-commit hooks (oxfmt/oxlint/eslint/typecheck) ran clean on commit.
- Could not execute the Playwright browser test itself in this sandbox
(outbound fetch of the Chromium binary from `cdn.playwright.dev` is
blocked by the environment's proxy allowlist); the fix was validated by
reproducing the exact rendered trigger text via the unit-level
`ToolCallGroup.test.ts` coverage instead, plus reading the mocked test
data (`420ms + 180ms` → `0.6s`, `2` calls) against `ToolCallGroup.vue`'s
`statusLabel`/`ranToolCallsTimed` i18n string directly.

Merging via admin bypass given severity — this is blocking #18559 and
#18574's `playwright-tests (cloud)` checks. Posting a post-merge-review
request comment once merged.

</details>

Claude-Session: https://claude.ai/code/session_01UqyourCBfi97xzpBx2W7oY

---
_Generated by [Claude
Code](https://claude.ai/code/session_01UqyourCBfi97xzpBx2W7oY)_

Co-authored-by: claude[bot] <209825114+claude[bot]@users.noreply.github.com>
@DrJKL DrJKL added agent Comfy Agent product, integration, tests or product documentation agent-backport Agent changes targeting a stable cloud/core release branch agent-session Agent sessions, history, turn lifecycle or workflow binding agent-test-playwright Touches Agent-related Playwright tests, fixtures or configuration agent-test-unit Touches Agent-related unit/component tests or their support agent-ui Agent panel, composer, transcript or other user-interface components labels Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent Comfy Agent product, integration, tests or product documentation agent-backport Agent changes targeting a stable cloud/core release branch agent-session Agent sessions, history, turn lifecycle or workflow binding agent-test-playwright Touches Agent-related Playwright tests, fixtures or configuration agent-test-unit Touches Agent-related unit/component tests or their support agent-ui Agent panel, composer, transcript or other user-interface components backport Backporting a PR onto a release candidate risk:high PR risk grade (advisory shadow check; grader-owned)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants