-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix timezones in threads #11498
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix timezones in threads #11498
Conversation
🦋 Changeset detectedLatest commit: b1b5267 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
WalkthroughThis change introduces timezone-aware timestamp columns (createdAtZ/updatedAtZ) in PostgreSQL storage to improve timestamp consistency, with fallback logic for legacy data. It includes a test to verify timestamp parity across different thread retrieval methods. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
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 |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🚨 Redirect Validation FailedThe redirect validation found issues in Action Required: Review and fix the redirect configuration. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
.changeset/lemon-turtles-sort.mdstores/_test-utils/src/domains/memory/threads.tsstores/pg/src/storage/domains/memory/index.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}
📄 CodeRabbit inference engine (CLAUDE.md)
Run
pnpm typecheckto validate TypeScript types across all packages
Files:
stores/_test-utils/src/domains/memory/threads.tsstores/pg/src/storage/domains/memory/index.ts
**/*.{ts,tsx,js,jsx,json,md}
📄 CodeRabbit inference engine (CLAUDE.md)
Run
pnpm prettier:formatto format code andpnpm formatto run linting with auto-fix across all packages
Files:
stores/_test-utils/src/domains/memory/threads.tsstores/pg/src/storage/domains/memory/index.ts
.changeset/*.md
⚙️ CodeRabbit configuration file
.changeset/*.md: Changeset files are really important for keeping track of changes in the project. They'll be used to generate release notes and inform users about updates.Review the changeset file according to these guidelines:
- The target audience are developers
- Write short, direct sentences that anyone can understand. Avoid commit messages, technical jargon, and acronyms. Use action-oriented verbs (Added, Fixed, Improved, Deprecated, Removed)
- Avoid generic phrases like "Update code", "Miscellaneous improvements", or "Bug fixes"
- Highlight outcomes! What does change for the end user? Do not focus on internal implementation details
- Add context like links to issues or PRs when relevant
- If the change is a breaking change or is adding a new feature, ensure that a code example is provided. This code example should show the public API usage (the before and after). Do not show code examples of internal implementation details.
- Keep the formatting easy-to-read and scannable. If necessary, use bullet points or multiple paragraphs (Use bold text as the heading for these sections, do not use markdown headings).
- For larger, more substantial changes, also answer the "Why" behind the changes
- Each changeset file contains a YAML frontmatter at the top. It will be one or more package names followed by a colon and the type of change (patch, minor, major). Do not modify this frontmatter. Check that the description inside the changeset file only applies to the packages listed in the frontmatter. Do not allow descriptions that mention changes to packages not listed in the frontmatter. In these cases, the user must create a separate changeset file for those packages.
Files:
.changeset/lemon-turtles-sort.md
🧠 Learnings (4)
📚 Learning: 2025-11-24T16:42:04.244Z
Learnt from: CR
Repo: mastra-ai/mastra PR: 0
File: packages/codemod/AGENTS.md:0-0
Timestamp: 2025-11-24T16:42:04.244Z
Learning: Applies to packages/codemod/src/test/__fixtures__/**/*.ts : Create test fixtures by copying examples DIRECTLY from migration guides in `docs/src/content/en/guides/migrations/upgrade-to-v1/` without hallucinating or inventing changes
Applied to files:
stores/_test-utils/src/domains/memory/threads.ts
📚 Learning: 2025-11-24T16:42:04.244Z
Learnt from: CR
Repo: mastra-ai/mastra PR: 0
File: packages/codemod/AGENTS.md:0-0
Timestamp: 2025-11-24T16:42:04.244Z
Learning: Applies to packages/codemod/src/test/__fixtures__/**/*.ts : In output fixtures, ensure all NEGATIVE test cases remain EXACTLY IDENTICAL to their input fixture counterparts to verify the codemod only transforms intended patterns
Applied to files:
stores/_test-utils/src/domains/memory/threads.ts
📚 Learning: 2025-11-24T16:42:04.244Z
Learnt from: CR
Repo: mastra-ai/mastra PR: 0
File: packages/codemod/AGENTS.md:0-0
Timestamp: 2025-11-24T16:42:04.244Z
Learning: Applies to packages/codemod/src/test/**/*.test.ts : Include test cases for multiple occurrences of the transformation pattern, aliased imports, type imports, and mixed imports to verify the codemod works consistently
Applied to files:
stores/_test-utils/src/domains/memory/threads.ts
📚 Learning: 2025-11-24T16:42:04.244Z
Learnt from: CR
Repo: mastra-ai/mastra PR: 0
File: packages/codemod/AGENTS.md:0-0
Timestamp: 2025-11-24T16:42:04.244Z
Learning: Applies to packages/codemod/src/test/**/*.test.ts : Do NOT use `UPDATE_SNAPSHOT` to force tests to pass; instead fix the codemod implementation when tests fail
Applied to files:
stores/_test-utils/src/domains/memory/threads.ts
🧬 Code graph analysis (2)
stores/_test-utils/src/domains/memory/threads.ts (1)
stores/_test-utils/src/domains/memory/data.ts (1)
createSampleThread(17-32)
stores/pg/src/storage/domains/memory/index.ts (1)
packages/core/src/memory/types.ts (1)
StorageThreadType(36-43)
🔇 Additional comments (2)
stores/pg/src/storage/domains/memory/index.ts (1)
242-257: LGTM! Timezone-aware column selection with proper fallback.The implementation correctly selects both standard and timezone-aware columns (createdAtZ/updatedAtZ) with fallback logic for legacy data. This matches the pattern already established in
getThreadById(lines 183-184) and ensures consistent UTC timestamp handling across all retrieval methods.stores/_test-utils/src/domains/memory/threads.ts (1)
106-145: LGTM! Comprehensive test for timestamp consistency.The test correctly verifies that timestamps are consistent across
getThreadByIdandlistThreadsByResourceId. The normalization helper function (lines 136-137) properly handles both Date objects and ISO strings, and the assertions validate that all timestamps match, including the updatedAt fromupdateThread.
| Fix thread timestamps being returned in incorrect timezone from listThreadsByResourceId | ||
|
|
||
| The method was not using the timezone-aware columns (createdAtZ/updatedAtZ), causing timestamps to be interpreted in local timezone instead of UTC. Now correctly uses TIMESTAMPTZ columns with fallback for legacy data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Rewrite the description to be more user-friendly and outcome-focused.
Per the coding guidelines, changeset descriptions should be written for developers using simple, direct language that avoids technical jargon. The current description focuses on internal implementation details (TIMESTAMPTZ columns, timezone-aware columns) rather than the user-facing outcome.
Consider rewriting to emphasize what changed for the user:
📝 Suggested rewrite
-Fix thread timestamps being returned in incorrect timezone from listThreadsByResourceId
-
-The method was not using the timezone-aware columns (createdAtZ/updatedAtZ), causing timestamps to be interpreted in local timezone instead of UTC. Now correctly uses TIMESTAMPTZ columns with fallback for legacy data.
+Fixed thread timestamps returned by `listThreadsByResourceId` being in the wrong timezone.
+
+Previously, timestamps were interpreted in the local timezone instead of UTC, causing inconsistencies with timestamps from `getThreadById`. All timestamps are now correctly returned in UTC.Based on coding guidelines for changeset files.
🤖 Prompt for AI Agents
In .changeset/lemon-turtles-sort.md around lines 5 to 7, rewrite the changeset
description to be user-focused and jargon-free: replace the current technical
explanation with a short, outcome-oriented sentence such as "Fix thread
timestamps so they display the correct UTC time when listing threads; legacy
timestamps are handled gracefully," keeping a brief note about fallback for
older data but avoiding database/column-level terms.
## Description Fix thread timestamps being returned in incorrect timezone from `listThreadsByResourceId`. The `listThreadsByResourceId` method was not selecting or using the timezone-aware columns (`createdAtZ`/`updatedAtZ` which are `TIMESTAMPTZ` type). This caused timestamps to be read from the `TIMESTAMP WITHOUT TIME ZONE` columns and interpreted in local timezone instead of UTC. The fix updates `listThreadsByResourceId` to: 1. Select the timezone-aware columns (`createdAtZ`, `updatedAtZ`) 2. Use them with fallback for legacy data (matching the pattern already used in `getThreadById`) ## Related Issue(s) mastra-ai#11496 ## Type of Change - [x] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [ ] Code refactoring - [ ] Performance improvement - [x] Test update ## Checklist - [x] I have made corresponding changes to the documentation (if applicable) - [x] I have added tests that prove my fix is effective or that my feature works <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Bug Fixes** * Patched @mastra/pg to fix thread timestamp handling by implementing timezone-aware timestamp columns with automatic fallback support for legacy data, ensuring consistent timestamp values across operations * **Tests** * Added comprehensive test to verify timestamp consistency across thread retrieval operations, confirming that created and updated timestamps remain synchronized across different data access methods <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
Description
Fix thread timestamps being returned in incorrect timezone from
listThreadsByResourceId.The
listThreadsByResourceIdmethod was not selecting or using the timezone-aware columns (createdAtZ/updatedAtZwhich areTIMESTAMPTZtype). This caused timestamps to be read from theTIMESTAMP WITHOUT TIME ZONEcolumns and interpreted in local timezone instead of UTC.The fix updates
listThreadsByResourceIdto:createdAtZ,updatedAtZ)getThreadById)Related Issue(s)
#11496
Type of Change
Checklist
Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.