Uh oh!
There was an error while loading. Please reload this page.
fix(ai-persistence): persist chat run usage - #1129
Conversation
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: Your plan includes up to 8 reviews per rolling hour; 6 remain after this review. 📝 WalkthroughWalkthroughThe persistence middleware now aggregates token usage across provider calls and preserves it through interrupted, completed, failed, and aborted runs. Tests, an end-to-end scenario, documentation, and a patch changeset cover the behavior. ChangesUsage persistence
Estimated code review effort: 3 (Moderate) | ~25 minutes Merge Risk:⚪ Minimal · up to This change persists accumulated chat-run usage across completion, interruption, failure, abort, and continuation paths; no actionable merge-blocking risk remains beyond normal checks and review. Sequence Diagram(s)sequenceDiagram
participant ChatEngine
participant withPersistence
participant RunRecord
ChatEngine->>withPersistence: emit usage for each provider call
withPersistence->>withPersistence: accumulate usage
withPersistence->>RunRecord: persist aggregate at interruption or terminal state
RunRecord-->>withPersistence: restore usage for continuation
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ 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 |
View your CI Pipeline Execution ↗ for commit 9fa0e0b
☁️ Nx Cloud last updated this comment at |
@tanstack/ai@tanstack/ai-acp@tanstack/ai-angular@tanstack/ai-anthropic@tanstack/ai-bedrock@tanstack/ai-byteplus@tanstack/ai-claude-code@tanstack/ai-client@tanstack/ai-code-mode@tanstack/ai-code-mode-snippets@tanstack/ai-codex@tanstack/ai-cohere@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-daytona@tanstack/ai-isolate-node@tanstack/ai-isolate-quickjs@tanstack/ai-isolate-quickjs-bun@tanstack/ai-mcp@tanstack/ai-memory@tanstack/ai-mistral@tanstack/ai-ollama@tanstack/ai-openai@tanstack/ai-opencode@tanstack/ai-openrouter@tanstack/ai-perplexity@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-vercel-gateway@tanstack/ai-vue@tanstack/ai-vue-ui@tanstack/openai-base@tanstack/preact-ai-devtools@tanstack/react-ai-devtools@tanstack/solid-ai-devtoolscommit: |
Uh oh!
There was an error while loading. Please reload this page.
Resolved 4 conflicts. Both sides were kept in every case: - packages/ai/src/adapter-internals.ts Additive on both sides. Kept the interrupt exports and main's structured-output-text / structured-output-events exports. - packages/ai-persistence/src/middleware.ts (onFinish) Kept this branch's try/catch and its saveThread -> commitPendingResumes -> completeRun order, so a failed batch write still calls failRun and leaves pending resumes retryable. Took main's accumulated usage from #1129: completeRun now gets `state?.usage ?? info.usage`, and failRun in the catch gets `state?.usage` so every terminal path persists usage the same way onError already does. - packages/ai-persistence/tests/interrupts.test.ts Unioned the imports. Kept this branch's schema fixtures and the isInterruptFinished predicate, plus main's usage-aware interruptFinished(runId, usage) signature. - docs/persistence/chat-persistence.md Kept this branch's atomic-commitBatch and legacy-sequential-fallback paragraphs and folded in main's sentence about terminal paths retaining usage.
Fixes#1128
🎯 Changes
✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit
New Features
Bug Fixes
Documentation