Skip to content

Conversation

@graysonhicks
Copy link
Contributor

@graysonhicks graysonhicks commented Dec 30, 2025

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)

#11496

Type of Change

  • 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
  • Test update

Checklist

  • I have made corresponding changes to the documentation (if applicable)
  • I have added tests that prove my fix is effective or that my feature works

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

✏️ Tip: You can customize this high-level summary in your review settings.

@changeset-bot
Copy link

changeset-bot bot commented Dec 30, 2025

🦋 Changeset detected

Latest commit: b1b5267

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@mastra/pg Patch

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 30, 2025

Walkthrough

This 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

Cohort / File(s) Summary
Release documentation
.changeset/lemon-turtles-sort.md
Patch release note documenting timezone-aware timestamp fix for @mastra/pg
Test utilities
stores/_test-utils/src/domains/memory/threads.ts
New test case verifying consistent timestamp values (createdAt, updatedAt) across getThreadById and listThreadsByResourceId retrieval methods, with validation that updateThread results match observed timestamps
Storage implementation
stores/pg/src/storage/domains/memory/index.ts
Query modified to select timezone-aware columns createdAtZ/updatedAtZ; mapping logic reconstructs thread fields explicitly and uses Z-variant columns with fallback to legacy columns for backward compatibility

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Suggested reviewers

  • abhiaiyer91

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix timezones in threads' is concise (24 characters), uses imperative mood, and directly describes the main change: fixing timezone handling in thread timestamps.
✨ Finishing touches
  • 📝 Generate docstrings

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 and usage tips.

@graysonhicks graysonhicks changed the title first fix timezones in threads Dec 30, 2025
@vercel
Copy link

vercel bot commented Dec 30, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
assistant-ui Ready Ready Preview, Comment Dec 30, 2025 7:57pm
mastra-docs Ready Ready Preview, Comment Dec 30, 2025 7:57pm
mastra-docs-1.x Ready Ready Preview, Comment Dec 30, 2025 7:57pm

@github-actions
Copy link
Contributor

github-actions bot commented Dec 30, 2025

🚨 Redirect Validation Failed

The redirect validation found issues in vercel.json (duplicate sources or broken destination links).

Action Required: Review and fix the redirect configuration.

📋 View workflow logs for details

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between 05b8bee and b1b5267.

📒 Files selected for processing (3)
  • .changeset/lemon-turtles-sort.md
  • stores/_test-utils/src/domains/memory/threads.ts
  • stores/pg/src/storage/domains/memory/index.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Run pnpm typecheck to validate TypeScript types across all packages

Files:

  • stores/_test-utils/src/domains/memory/threads.ts
  • stores/pg/src/storage/domains/memory/index.ts
**/*.{ts,tsx,js,jsx,json,md}

📄 CodeRabbit inference engine (CLAUDE.md)

Run pnpm prettier:format to format code and pnpm format to run linting with auto-fix across all packages

Files:

  • stores/_test-utils/src/domains/memory/threads.ts
  • stores/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 getThreadById and listThreadsByResourceId. 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 from updateThread.

Comment on lines +5 to +7
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.
Copy link
Contributor

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.

@abhiaiyer91 abhiaiyer91 merged commit 46ce908 into main Dec 30, 2025
39 of 40 checks passed
@abhiaiyer91 abhiaiyer91 deleted the fix/11496--timezones-in-threads branch December 30, 2025 22:01
astout55555 pushed a commit to astout55555/mastra that referenced this pull request Jan 6, 2026
## 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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants