Skip to content
Source
Sign inSign up
TanStack/ai

feat(persistence): generation persistence — client snapshot + durable media bytes #987

ClosedAlemTuzlakwants to merge 37 commits intofeat/persistence-core fromfeat/generation-persistenceopened View on GitHub

AlemTuzlakcommented

Generation Persistence

Stacked on #984 (feat/persistence-core) — please review/merge that first. Rebased onto its current tip.

Generation persistence in two halves:

1. Client resume snapshot (read-only)

As a media generation streams, the client builds a lightweight GenerationResumeSnapshot (run identity, status, errors, result metadata + artifact refs — never the bytes) and writes it to a persistence storage adapter. The option reuses the shared ChatStorageAdapter contract, so localStoragePersistence / sessionStoragePersistence / indexedDBPersistence work with no type argument:

const snapshots = localStoragePersistence({ keyPrefix: 'my-app:generation:' })
useGenerateImage({ connection, persistence: snapshots })

Hooks expose resumeSnapshot / resumeState / pendingArtifacts / resultArtifacts across react/solid/vue/svelte/angular. No resume() action; reconnect to an in-flight stream is the delivery layer's job (resumable streams, #955, merged), wired via a durability adapter + GET handler exactly as for chat.

2. Durable media-byte storage (server, opt-in)

When the persistence backend provides both an artifacts (ArtifactStore) and a blobs (BlobStore) store, withGenerationPersistence writes each generated file's bytes to the blob store (key artifacts/<runId>/<artifactId>), records an ArtifactRecord, attaches PersistedArtifactRefs to the result, and emits generation:artifacts so the client records them. memoryPersistence() ships both stores; any backend implementing the two contracts works. Extraction is customizable via extractArtifacts / nameArtifact.

Changes

  • @tanstack/ai — result-transform machinery (resultTransforms / artifactInputs on GenerationMiddlewareContext, applyGenerationResultTransforms), threadId/runId options on the image/audio/speech/transcription activities, and generation:artifacts emission from streamGenerationResult.
  • @tanstack/ai-utils — base64ToUint8Array.
  • @tanstack/ai-persistence — ArtifactStore + BlobStore contracts, in-memory impls in memoryPersistence(), and byte-persistence in withGenerationPersistence (extractArtifacts/nameArtifact).
  • @tanstack/ai-client + framework hooks (react/solid/vue/svelte/angular) — the client snapshot + persistence option + artifact refs.
  • @tanstack/ai-event-client — optional threadId/runId on generation events.
  • Docs — docs/persistence/generation-persistence.md (client snapshot, byte storage + serve route, reconnect), kiira-verified.
  • Changeset — minor across the affected packages.

Verification

  • Builds green across ai-utils, ai, ai-event-client, ai-client, ai-persistence.
  • test:types — 0 errors in ai / ai-client / ai-persistence.
  • Tests — ai-persistence 78 pass (incl. 12 artifact + the chat resume suites), ai-client generation 50 pass, ai core stream/middleware/activity 92 pass.
  • kiira — doc passes (3 snippets).

Scope note

Durable SQL/R2 artifact+blob backends (Drizzle/Prisma/Cloudflare R2) are not in this PR: memoryPersistence plus any custom ArtifactStore+BlobStore cover the contract today, and the durable backends (which add SQL schema + migrations per package) are a clean follow-up. generateVideo's own job-polling artifact path is likewise deferred (image/audio/speech/transcription persist bytes).

    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on base/target branches other than the default branch.

      Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: defaults

      Review profile: CHILL

      Plan: Pro Plus

      Run ID: 21ef07e1-2cac-46df-81f9-5d36d57a641d

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Commit unit tests in branch `feat/generation-persistence`

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab)commented

      🚀 Changeset Version Preview

      15 package(s) bumped directly, 38 bumped as dependents.

      🟥 Major bumps

      PackageVersionReason
      @tanstack/ai-angular0.3.1 → 1.0.0Changeset
      @tanstack/ai-durable-stream0.0.0 → 1.0.0Changeset
      @tanstack/ai-persistence0.0.0 → 1.0.0Changeset
      @tanstack/ai-persistence-cloudflare0.0.0 → 1.0.0Changeset
      @tanstack/ai-persistence-drizzle0.0.0 → 1.0.0Changeset
      @tanstack/ai-persistence-prisma0.0.0 → 1.0.0Changeset
      @tanstack/ai-preact0.11.1 → 1.0.0Changeset
      @tanstack/ai-react0.18.1 → 1.0.0Changeset
      @tanstack/ai-solid0.15.1 → 1.0.0Changeset
      @tanstack/ai-svelte0.15.1 → 1.0.0Changeset
      @tanstack/ai-vue0.15.1 → 1.0.0Changeset
      @tanstack/ai-acp0.2.3 → 1.0.0Dependent
      @tanstack/ai-anthropic0.16.3 → 1.0.0Dependent
      @tanstack/ai-bedrock0.1.4 → 1.0.0Dependent
      @tanstack/ai-claude-code0.2.3 → 1.0.0Dependent
      @tanstack/ai-code-mode0.3.8 → 1.0.0Dependent
      @tanstack/ai-code-mode-skills0.3.11 → 1.0.0Dependent
      @tanstack/ai-codex0.2.3 → 1.0.0Dependent
      @tanstack/ai-elevenlabs0.2.34 → 1.0.0Dependent
      @tanstack/ai-fal0.9.12 → 1.0.0Dependent
      @tanstack/ai-gemini0.20.1 → 1.0.0Dependent
      @tanstack/ai-grok0.14.9 → 1.0.0Dependent
      @tanstack/ai-grok-build0.2.3 → 1.0.0Dependent
      @tanstack/ai-groq0.5.3 → 1.0.0Dependent
      @tanstack/ai-isolate-node0.1.47 → 1.0.0Dependent
      @tanstack/ai-isolate-quickjs0.1.47 → 1.0.0Dependent
      @tanstack/ai-mistral0.2.3 → 1.0.0Dependent
      @tanstack/ai-ollama0.8.16 → 1.0.0Dependent
      @tanstack/ai-openai0.17.1 → 1.0.0Dependent
      @tanstack/ai-opencode0.2.3 → 1.0.0Dependent
      @tanstack/ai-openrouter0.15.10 → 1.0.0Dependent
      @tanstack/ai-react-ui0.8.15 → 1.0.0Dependent
      @tanstack/ai-sandbox0.2.4 → 1.0.0Dependent
      @tanstack/ai-sandbox-cloudflare0.2.4 → 1.0.0Dependent
      @tanstack/ai-sandbox-daytona0.2.0 → 1.0.0Dependent
      @tanstack/ai-sandbox-docker0.2.0 → 1.0.0Dependent
      @tanstack/ai-sandbox-local-process0.2.0 → 1.0.0Dependent
      @tanstack/ai-sandbox-sprites0.2.1 → 1.0.0Dependent
      @tanstack/ai-sandbox-vercel0.2.0 → 1.0.0Dependent
      @tanstack/ai-solid-ui0.7.14 → 1.0.0Dependent
      @tanstack/openai-base0.9.9 → 1.0.0Dependent

      🟨 Minor bumps

      PackageVersionReason
      @tanstack/ai0.42.0 → 0.43.0Changeset
      @tanstack/ai-client0.22.1 → 0.23.0Changeset
      @tanstack/ai-event-client0.6.8 → 0.7.0Changeset
      @tanstack/ai-utils0.3.1 → 0.4.0Changeset

      🟩 Patch bumps

      PackageVersionReason
      @tanstack/ai-devtools-core0.4.24 → 0.4.25Dependent
      @tanstack/ai-isolate-cloudflare0.2.38 → 0.2.39Dependent
      @tanstack/ai-mcp0.2.5 → 0.2.6Dependent
      @tanstack/ai-vue-ui0.2.34 → 0.2.35Dependent
      @tanstack/preact-ai-devtools0.1.67 → 0.1.68Dependent
      @tanstack/react-ai-devtools0.2.67 → 0.2.68Dependent
      @tanstack/solid-ai-devtools0.2.67 → 0.2.68Dependent
      ag-ui0.0.2 → 0.0.3Dependent
    3. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit 41397c15ac0acfda011d33fefd5fa8179b7e66a9

      CommandStatusDurationResult
      nx run-many --targets=build --exclude=examples/...✅ Succeeded3sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-07-23 15:46:54 UTC

    4. pkg-pr-new[bot](GitHub profile, opens in a new tab)commented

      Open in StackBlitz

      @tanstack/ai

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai@987

      @tanstack/ai-acp

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-acp@987

      @tanstack/ai-angular

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-angular@987

      @tanstack/ai-anthropic

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-anthropic@987

      @tanstack/ai-bedrock

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-bedrock@987

      @tanstack/ai-claude-code

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-claude-code@987

      @tanstack/ai-client

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-client@987

      @tanstack/ai-code-mode

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode@987

      @tanstack/ai-code-mode-skills

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-code-mode-skills@987

      @tanstack/ai-codex

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-codex@987

      @tanstack/ai-devtools-core

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-devtools-core@987

      @tanstack/ai-durable-stream

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-durable-stream@987

      @tanstack/ai-elevenlabs

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-elevenlabs@987

      @tanstack/ai-event-client

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-event-client@987

      @tanstack/ai-fal

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-fal@987

      @tanstack/ai-gemini

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-gemini@987

      @tanstack/ai-grok

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok@987

      @tanstack/ai-grok-build

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-grok-build@987

      @tanstack/ai-groq

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-groq@987

      @tanstack/ai-isolate-cloudflare

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-cloudflare@987

      @tanstack/ai-isolate-node

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-node@987

      @tanstack/ai-isolate-quickjs

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-isolate-quickjs@987

      @tanstack/ai-mcp

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mcp@987

      @tanstack/ai-mistral

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-mistral@987

      @tanstack/ai-ollama

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-ollama@987

      @tanstack/ai-openai

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openai@987

      @tanstack/ai-opencode

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-opencode@987

      @tanstack/ai-openrouter

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-openrouter@987

      @tanstack/ai-persistence

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-persistence@987

      @tanstack/ai-persistence-cloudflare

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-persistence-cloudflare@987

      @tanstack/ai-persistence-drizzle

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-persistence-drizzle@987

      @tanstack/ai-persistence-prisma

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-persistence-prisma@987

      @tanstack/ai-preact

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-preact@987

      @tanstack/ai-react

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react@987

      @tanstack/ai-react-ui

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-react-ui@987

      @tanstack/ai-sandbox

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox@987

      @tanstack/ai-sandbox-cloudflare

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-cloudflare@987

      @tanstack/ai-sandbox-daytona

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-daytona@987

      @tanstack/ai-sandbox-docker

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-docker@987

      @tanstack/ai-sandbox-local-process

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-local-process@987

      @tanstack/ai-sandbox-sprites

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-sprites@987

      @tanstack/ai-sandbox-vercel

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-sandbox-vercel@987

      @tanstack/ai-solid

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid@987

      @tanstack/ai-solid-ui

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-solid-ui@987

      @tanstack/ai-svelte

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-svelte@987

      @tanstack/ai-utils

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-utils@987

      @tanstack/ai-vue

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue@987

      @tanstack/ai-vue-ui

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/ai-vue-ui@987

      @tanstack/openai-base

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/openai-base@987

      @tanstack/preact-ai-devtools

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/preact-ai-devtools@987

      @tanstack/react-ai-devtools

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/react-ai-devtools@987

      @tanstack/solid-ai-devtools

      npm i https://pkg.pr.new/TanStack/ai/@tanstack/solid-ai-devtools@987

      commit: 41397c1

    5. AlemTuzlak changed the title

    6. tombeckenham added labelspersistence

    7. Superseded by a two-PR stack — closing this one, but the feat/generation-persistence branch is staying put, so nothing here is lost.

      • #997 — client-side generation resume snapshot (base feat/persistence-core)
      • #998 — durable generation media-byte storage (stacked on #997)

      Why the split

      Two things happened to the base branch after this PR was opened.

      feat/persistence-core was rebased, so 25 of this PR's 37 commits ended up duplicated on the base under different hashes. That inflated the diff here to 212 files / +19k when the actual new work is 12 commits / 72 files / +5.2k.

      More importantly, 62c99754d refactor(persistence)!: ship the contract, not the backends dropped @tanstack/ai-persistence-drizzle, -prisma, and -cloudflare. This branch still carries 3e0e477b4, which adds them — that's the whole source of the CONFLICTING state, and merging as-is would resurrect the deleted packages. 978996e3b (Prisma 7 support) is dead for the same reason.

      Rebasing would have meant replaying those 25 duplicates against a force-pushed base, so the stack was rebuilt by cherry-picking only the 12 generation-persistence commits onto the current base instead. The history split cleanly at c7a901f46 with zero package overlap between the two halves, which is what made two PRs the natural shape rather than one.

      Both new PRs are MERGEABLE.

      What changed in the rebuild

      The client half (#997) cherry-picked with no manual intervention.

      The server half (#998) needed real reconciliation with the reworked ai-persistence, isolated in a single trailing fix(persistence): reconcile … commit so it's reviewable separately from the cherry-picks. In short: memoryPersistence() keeps the base's no-locks decision and gains only artifacts + blobs; the generation validator now carries both invariants (runs required, and artifacts/blobs as a pair); and the base's "⚠️ TEMPORARY / WRONG SHAPE" warning on withGenerationPersistence is preserved rather than dropped, since the byte path doesn't actually resolve the requestId-vs-runId keying it warns about. Full details in #998's description.

      Heads up on review findings

      Both PRs are drafts and each carries a "Known issues" checklist — the code is as authored here, so the review findings are documented rather than fixed. The two blockers:

      • #997 — dispose() sets disposed = true and nothing ever clears it, so under React StrictMode's mount→cleanup→mount replay every subsequent generate() call is a silent no-op. Reproduced under { wrapper: StrictMode }; StrictMode is on by default in Vite/Next React templates. The fix pattern already exists at devtools.ts:571.
      • #998 — ArtifactStore / BlobStore ship with documented invariants but no conformance-testkit suites, which types.ts calls "the authoritative compatibility gate". Now that backends are app-owned, that testkit is the only thing holding an implementation to the rules.

      Thanks @AlemTuzlak — the work carried over intact, it just needed a different base.

    8. tombeckenham closed this

Sign in to join this conversation.