Skip to content

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

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

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

Conversation

@comfy-pr-bot

Copy link
Copy Markdown
Member

Backport of #18282 to cloud/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-cloud-1.54 branch from 410d8ef to 4010c14 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:06 AM UTC

Links

🎭 Playwright: ✅ 1938 passed, 0 failed · 1 flaky

📊 Browser Reports
  • chromium: View Report (✅ 1917 / ❌ 0 / ⚠️ 1 / ⏭️ 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              @@
##             cloud/1.54   #18555   +/-   ##
=============================================
  Coverage              ?   78.70%           
=============================================
  Files                 ?     2010           
  Lines                 ?   111244           
  Branches              ?    33593           
=============================================
  Hits                  ?    87554           
  Misses                ?    23511           
  Partials              ?      179           
Flag Coverage Δ
unit 78.70% <100.00%> (?)

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%> (ø)
🚀 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 f738dc1 into cloud/1.54 Sep 23, 2026
23 of 24 checks passed
@christian-byrne
christian-byrne deleted the backport-18282-to-cloud-1.54 branch September 23, 2026 06:47
christian-byrne added a commit that referenced this pull request Sep 23, 2026
…ession (#18581) (#18582)

## Summary
Repair the release-only failing assertion introduced by #18555, with
chat-switch coverage from #18581.

## Changes
- cloud/1.54 has ToolCallGroup, not main’s WorkSummary. Its exact
accessible name for the existing payload is "Ran 2 tool calls for 0.6
seconds", not "Worked".
- Preserve all collapse/expand and visible-call assertions. Also require
exactly two rows with their separate 0.4s/0.2s durations, no summary in
a new chat, and restoration via chat history.
- Test-only; no runtime, package pins, feature flags, or deployment
changes. #18574 remains untouched.

## Review Focus
Baseline e790192 reproduced the exact line-132 failure. Its
accessibility snapshot already showed the completed two-call summary and
"Found it." Hydration was working; the backport had assumed a newer
renderer. This is an exact branch-contract adaptation, not a fallback
selector or skipped assertion.

Validation: Cloud browser test plus adjacent prompt-history test: 2
passed (32.3s), retries disabled.
Transcript/store/transport/ToolCallGroup/glyph unit tests: 117 passed.
Browser typecheck, targeted ESLint/oxfmt passed. Await exact-head CI and
source #18581 before merge.

---------

Co-authored-by: Amp <amp@ampcode.com>
christian-byrne added a commit that referenced this pull request Sep 23, 2026
## Summary
Preserve the tool-call reload regression and extend it through New chat
→ chat history → original chat, including exact rendered row counts and
labels.

## Changes
- Keep all existing collapsed/expanded and visible-label assertions;
ensure no summary leaks into the new chat and both calls return.
- Source follow-up to #18282. The Cloud backport #18555 expects main’s
"Worked" label, but cloud/1.54 still renders "Ran 2 tool calls for 0.6
seconds". That release-specific adaptation will be a separate backport,
not a runtime or package change.

## Review Focus
Check the preserved GET content.tool_calls fixture, both terminal
success vocabularies, and reload/chat-switch behavior. No deployment or
feature-flag changes.

Validation: targeted Cloud Playwright 1 passed (23.6s);
transcript/store/transport/WorkSummary/glyph Vitest 139 passed; browser
typecheck, targeted ESLint and oxfmt passed. Release baseline
independently reproduced the exact line-132 failure while its
accessibility tree already contained the correct two-call summary.

---------

Co-authored-by: Amp <amp@ampcode.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 labels Sep 24, 2026
@DrJKL DrJKL added the agent-ui Agent panel, composer, transcript or other user-interface components label 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