Skip to content

withPersistence does not apply cancelled client-tool resume entries #1088

Closed

Description

@kolaworld

TanStack AI version

0.44.0

Framework/Library version

@tanstack/ai-client: 0.23.2 | @tanstack/ai-persistence: 0.1.2 | @tanstack/ai-svelte: 0.16.2

Describe the bug and the steps to reproduce it

#1086 covers the client-side gap: recognizing that server hydration installed hidden client-tool interrupts so an application can call cancelInterrupts(). That issue stops once the cancelled resume batch is submitted.

The server-authoritative resume path then drops those cancellations.

  1. The client submits cancelled resume entries for the pending client-tool interrupts.
  2. withPersistence onConfig translates persisted pending interrupts into resumeToolState and clears config.resume, so the engine skips ephemeral reconstruction middleware.ts#L1475-L1486.
  3. resumeToolStateFromPending() handles approvals and resolved client-tool results, but never maps a cancelled client-tool entry into cancelledToolCallIds middleware.ts#L393-L423.

The ephemeral path already does the right thing: cancelled bindings are added to cancelledToolCallIds in interrupt-resume.ts#L631-L633. The tool executor then emits an output-error result (Tool execution cancelled) instead of re-interrupting tool-calls.ts#L806-L813.

Because persistence clears config.resume and supplies an incomplete resumeToolState, the engine still sees the stored tool call as unhandled and emits another client-tool interrupt instead of an output-error. Cancelling a hydrated orphaned client tool therefore cannot complete the turn under withPersistence.

Expected behavior

resumeToolStateFromPending() should mirror the ephemeral resume translator:

  • cancelled client-tool (and approval) entries populate cancelledToolCallIds
  • resolved client-tool entries continue to populate clientToolResults
  • a resume batch that is only cancellations still produces a non-empty resumeToolState so the engine does not fall through to a fresh interrupt

Your Minimal, Reproducible Example - (Sandbox Highly Recommended)

https://stackblitz.com/edit/vitejs-vite-ewvk7m7x?file=package.json,index.html,src%2Fmain.ts

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

None

Terms & Code of Conduct

  • I agree to follow this project's Code of Conduct
  • I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions