feat(persistence): client-side generation resume snapshot#997
feat(persistence): client-side generation resume snapshot#997tombeckenham wants to merge 8 commits into
Conversation
Layer a lightweight, read-only resume snapshot onto media generation. As a run streams, the client builds a GenerationResumeSnapshot (run identity, status, errors, result metadata + artifact refs — never media bytes) and writes it to an optional GenerationServerPersistence store. - ai-client: GenerationResumeSnapshot types + updateGenerationResumeSnapshot reducer; GenerationClient/VideoGenerationClient observe chunks, persist snapshots (serialized queue, warn-not-throw), expose getResumeSnapshot(); disposed guard. No resume() action (stream re-attach is PR #955). - ai-event-client: optional threadId/runId on generation events. - react/solid/vue/svelte/angular hooks: persistence + initialResumeSnapshot options; expose resumeSnapshot/resumeState (+ pending/result artifacts). - example: Persisted mode on the image generation route. - docs: persistence/generation-persistence.md + nav entry. Pairs with the existing withGenerationPersistence server middleware.
Drop the bespoke `GenerationServerPersistence` type and the `{ server }`
option wrapper. The `persistence` option is now a bare storage adapter
reusing the shared `ChatStorageAdapter` contract (aliased as
`GenerationPersistence`), so `localStoragePersistence` /
`sessionStoragePersistence` / `indexedDBPersistence` work for generations
exactly as they do for chat — matching main's ergonomics.
…istence (no call-site generic)
Default `localStoragePersistence` / `sessionStoragePersistence` /
`indexedDBPersistence` to a value-agnostic `TValue` so a bare, unannotated
call works for BOTH chat and generation persistence — the consuming
`persistence` option constrains the stored value. Generation docs/example now
use `localStoragePersistence({ keyPrefix })` with no type declaration.
PR #955 (resumable streams) is merged, so delivery durability is available today — it was wrongly described as an unlanded future feature. Rewrite the generation-persistence doc: the server example now wires a durability adapter + GET handler, and the delivery section explains that a dropped mid-generation connection re-attaches through the same adapters useChat uses. Clarify that the read-only snapshot carries run state (incl. runId) across reloads, while hooks do not auto-resume on mount.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
🚀 Changeset Version Preview16 package(s) bumped directly, 34 bumped as dependents. 🟥 Major bumps
🟨 Minor bumps
🟩 Patch bumps
|
|
View your CI Pipeline Execution ↗ for commit 34c8b69
☁️ Nx Cloud last updated this comment at |
@tanstack/ai
@tanstack/ai-acp
@tanstack/ai-angular
@tanstack/ai-anthropic
@tanstack/ai-bedrock
@tanstack/ai-claude-code
@tanstack/ai-client
@tanstack/ai-code-mode
@tanstack/ai-code-mode-skills
@tanstack/ai-codex
@tanstack/ai-devtools-core
@tanstack/ai-durable-stream
@tanstack/ai-elevenlabs
@tanstack/ai-event-client
@tanstack/ai-fal
@tanstack/ai-gemini
@tanstack/ai-grok
@tanstack/ai-grok-build
@tanstack/ai-groq
@tanstack/ai-isolate-cloudflare
@tanstack/ai-isolate-node
@tanstack/ai-isolate-quickjs
@tanstack/ai-mcp
@tanstack/ai-memory
@tanstack/ai-mistral
@tanstack/ai-ollama
@tanstack/ai-openai
@tanstack/ai-opencode
@tanstack/ai-openrouter
@tanstack/ai-persistence
@tanstack/ai-preact
@tanstack/ai-react
@tanstack/ai-react-ui
@tanstack/ai-sandbox
@tanstack/ai-sandbox-cloudflare
@tanstack/ai-sandbox-daytona
@tanstack/ai-sandbox-docker
@tanstack/ai-sandbox-local-process
@tanstack/ai-sandbox-sprites
@tanstack/ai-sandbox-vercel
@tanstack/ai-solid
@tanstack/ai-solid-ui
@tanstack/ai-svelte
@tanstack/ai-utils
@tanstack/ai-vue
@tanstack/ai-vue-ui
@tanstack/openai-base
@tanstack/preact-ai-devtools
@tanstack/react-ai-devtools
@tanstack/solid-ai-devtools
commit: |
🎯 Changes
Stack 1 of 2. Split out of #987, rebuilt on the current
feat/persistence-core(which dropped the packaged backends in62c99754d). Stacked follow-up: the durable media-byte half.Client-side generation persistence: a lightweight, read-only resume snapshot for media generation activities.
As a run streams, the client builds a
GenerationResumeSnapshot— run identity, status, errors, and result metadata, but never the generated media bytes — and writes it to apersistencestorage adapter. The option reuses the sameChatStorageAdaptercontract as chat, solocalStoragePersistence/sessionStoragePersistence/indexedDBPersistencework with no type argument.Generation hooks (
useGenerateImage,useGenerateVideo,useGenerateAudio,useGenerateSpeech,useGeneration,useSummarize,useTranscription, plus the Solid/Vue/Svelte/Angular equivalents) acceptpersistenceandinitialResumeSnapshot, and exposeresumeSnapshot/resumeState/pendingArtifacts/resultArtifacts.There is no
resume()action and no restart of provider work — generation still only begins whengenerate(...)is called. Reconnecting to an in-flight stream is the delivery layer's job (resumable streams, #955), wired via adurabilityadapter +GEThandler exactly as for chat.PersistedArtifactRefalready exists on the base branch as dormant wire surface, so this half consumes it and is independently mergeable — thegeneration:artifactsevent simply never fires until the stacked byte-storage PR lands.Packages
@tanstack/ai-client— the resume-snapshot reducer, thepersistenceoption, artifact refs.@tanstack/ai-event-client— optionalthreadId/runIdon generation events.docs/persistence/generation-persistence.md, kiira-verified.Carried over from review of #987; tracked here rather than silently shipped.
generate().dispose()setsdisposed = trueand nothing ever clears it, so after StrictMode's mount→cleanup→mount replay against the same memoized client everygenerate()call returns immediately. Reproduced under{ wrapper: StrictMode }. The fix pattern already exists atdevtools.ts:571. Affectsgeneration-client.tsandvideo-generation-client.ts.persistence.getItem— apps must read storage themselves and passinitialResumeSnapshot. Either wire hydration (as chat does atclient-persistor.ts:129) or rewrite the section.console.warnper chunk on quota errors.fetcher(non-streaming) path never records a snapshot at all.getResumePersistenceError()is dead public API — zero call sites.tanstack-ai:key prefix, so auseChat({id})anduseGenerateImage({id})on one adapter collide.threadId/runIdwere added to 18 devtools event interfaces but no emit site populates them.localStoragePersistence<TValue = ChatPersistedState>to<TValue = any>(3 oxlint suppressions) so the factories can be reused for generations. That degrades the already-shipped chat path; it arguably belongs infeat/persistence-coreon its own merits.✅ Checklist
pnpm run test:pr. — ran the affected subset:build,test:types,test:lib,test:oxlintgreen across ai, ai-utils, ai-event-client, ai-client, ai-persistence + the four framework packages.🚀 Release Impact