Skip to content

feat: implement message type/name persistence, rehydration and calendar date fixes#732

Merged
ngoiyaeric merged 1 commit into
mainfrom
jules-11147334533270605937-41a6fe8f
Jul 12, 2026
Merged

feat: implement message type/name persistence, rehydration and calendar date fixes#732
ngoiyaeric merged 1 commit into
mainfrom
jules-11147334533270605937-41a6fe8f

Conversation

@ngoiyaeric

@ngoiyaeric ngoiyaeric commented Jul 12, 2026

Copy link
Copy Markdown
Collaborator

This pull request implements the persistence of type and name message discriminators, full rehydration of AIMessage objects, fixes anonymous retrieval defects, and solves the driver-level Date-vs-string parameter mismatch in calendar queries.


PR created automatically by Jules for task 11147334533270605937 started by @ngoiyaeric

Summary by CodeRabbit

  • Bug Fixes
    • Prevented internal end-of-stream markers and unsupported message types from appearing in restored chat interfaces.
    • Improved loading of public chats when no signed-in user is present.
    • Preserved message metadata when chats are saved and reopened.
    • Improved calendar note retrieval for date ranges.
    • Updated offline caching assets to ensure the latest application resources are available.

…ar date fixes

Co-authored-by: ngoiyaeric <115367894+ngoiyaeric@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@qodo-code-review

Copy link
Copy Markdown
Contributor

Qodo reviews are paused for this user.

Troubleshooting steps vary by plan Learn more →

On a Teams plan?
Reviews resume once this user has a paid seat and their Git account is linked in Qodo.
Link Git account →

Using GitHub Enterprise Server, GitLab Self-Managed, or Bitbucket Data Center?
These require an Enterprise plan - Contact us
Contact us →

@vercel

vercel Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
qcx Ready Ready Preview, Comment Jul 12, 2026 7:32am

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: cf7a6b7c-c4e0-498c-98fa-1902b799c6f5

📥 Commits

Reviewing files that changed from the base of the PR and between e773257 and a25a892.

📒 Files selected for processing (11)
  • app/actions.tsx
  • app/search/[id]/page.tsx
  • drizzle/migrations/0009_add_message_type_name.sql
  • drizzle/migrations/meta/0006_snapshot.json
  • drizzle/migrations/meta/_journal.json
  • lib/actions/calendar.ts
  • lib/actions/chat-db.ts
  • lib/actions/chat.ts
  • lib/db/schema.ts
  • public/sw.js
  • tests/targeted.test.ts
📜 Recent review details
🧰 Additional context used
🪛 ast-grep (0.44.1)
public/sw.js

[warning] Avoid using the initial state variable in setState
Context: setTimeout(t,e)
Note: [CWE-710] Improper Adherence to Coding Standards. Security best practice.

(setstate-same-var)

🔇 Additional comments (19)
public/sw.js (1)

2-2: LGTM!

lib/actions/calendar.ts (2)

3-3: Typed comparators correctly fix the Date-vs-string binding mismatch.

The whereConditions array using gte/lte against calendarNotes.date (a timestamptz column) is the right approach — Drizzle's column-aware value mapping will properly serialize JavaScript Date objects as typed timestamp parameters, avoiding the postgres.js untyped binding issue described in the comments. The conditional chatId push is clean and idiomatic.

Also applies to: 30-37


56-64: Structured error logging adds valuable diagnostic context.

All three catch blocks now include the operation name and relevant identifiers (userId, chatId/noteId, date/startDate/endDate), which will significantly improve debugging when queries fail in production.

Also applies to: 91-97, 123-128

lib/db/schema.ts (1)

70-71: LGTM!

lib/actions/chat.ts (3)

140-152: LGTM!


166-166: LGTM!


215-216: LGTM!

lib/actions/chat-db.ts (3)

22-28: LGTM!


147-155: LGTM!


277-277: LGTM!

tests/targeted.test.ts (3)

34-80: LGTM!


82-112: LGTM!


114-145: LGTM!

drizzle/migrations/0009_add_message_type_name.sql (1)

1-3: 🗄️ Data Integrity & Integration

No snapshot mismatch here The journal already includes 0009_add_message_type_name, and 0006_snapshot.json is the latest snapshot tracked under drizzle/migrations/meta/.

			> Likely an incorrect or invalid review comment.
drizzle/migrations/meta/0006_snapshot.json (1)

576-587: LGTM!

drizzle/migrations/meta/_journal.json (1)

46-52: LGTM!

app/actions.tsx (1)

664-664: LGTM!

Also applies to: 713-714, 775-776, 875-875

app/search/[id]/page.tsx (2)

21-21: LGTM!


51-55: LGTM!


Walkthrough

Chat message metadata now persists through the database and rehydrates into UI state, synthetic and unsupported messages are filtered, public chat lookup accepts missing users, calendar date queries use typed comparisons, error logs gain context, tests cover these paths, and service-worker assets are refreshed.

Changes

Chat message persistence and rehydration

Layer / File(s) Summary
Message metadata schema and storage
lib/db/schema.ts, drizzle/migrations/*, lib/actions/chat.ts, lib/actions/chat-db.ts
messages now stores nullable type and name fields, and chat save/upsert paths persist them.
AI state filtering and rehydration
app/actions.tsx, app/search/[id]/page.tsx
Synthetic end/end messages and unsupported UI entries are excluded, while persisted message metadata is restored.
Public chat lookup
lib/actions/chat-db.ts, app/search/[id]/page.tsx, lib/actions/chat.ts
Unauthenticated chat lookup passes a missing user ID instead of an anonymous sentinel, with structured chat error logs.
Persistence and UI-state tests
tests/targeted.test.ts
Tests cover message metadata persistence, rehydration, and UI-state filtering.

Calendar note querying and diagnostics

Layer / File(s) Summary
Typed calendar date filtering
lib/actions/calendar.ts, tests/targeted.test.ts
Calendar retrieval uses typed gte/lte bounds, adds contextual error logging, and tests exact-day filtering.

Service-worker assets

Layer / File(s) Summary
Updated precache manifest
public/sw.js
Precached build assets and revision hashes are refreshed.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant AIState
  participant saveChat
  participant MessagesDB
  participant SearchPage
  AIState->>saveChat: persist filtered messages with type and name
  saveChat->>MessagesDB: insert or upsert message metadata
  SearchPage->>MessagesDB: load chat messages
  MessagesDB-->>SearchPage: return content, role, type, and name
Loading

Possibly related PRs

Suggested labels: Review effort 2/5

Poem

A bunny tucked messages safe in the burrow,
With names and types in a neat little row.
End markers hopped out of sight,
Calendar dates came out right,
And fresh service-worker seeds now glow.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main changes: message type/name persistence, rehydration, and calendar date query fixes.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jules-11147334533270605937-41a6fe8f

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install failed. For unrecoverable errors, disable the tool in CodeRabbit configuration.


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.

@charliecreates charliecreates Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs changes before merge. The added targeted test cannot run as written, and existing persisted chats are not made compatible with the new discriminator-based rehydration.

Comment thread tests/targeted.test.ts

// Mock getCurrentUserIdOnServer
const originalGetCurrentUserIdOnServer = auth.getCurrentUserIdOnServer;
auth.getCurrentUserIdOnServer = async () => dummyUserId;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

auth is an ESM namespace import, so this binding is read-only: TypeScript reports an assignment-to-read-only-import error and Bun/ESM will throw when the test module is evaluated. Since tsconfig.json includes every **/*.ts, the PR build/typecheck will fail before these tests can run. Use Bun's module mocking mechanism (or dependency injection) instead of assigning to the imported namespace.

Comment thread app/search/[id]/page.tsx
// For instance, if a message with role 'tool' should have a 'name',
// or if some messages have a specific 'type' based on content or other flags.
// This mapping assumes standard user/assistant messages primarily.
type: dbMsg.type ? (dbMsg.type as AIMessage['type']) : undefined,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All existing messages rows get NULL for these newly added columns, and this migration neither backfills them nor derives legacy discriminators during rehydration. getUIStateFromAIState drops every message whose type is falsy, so opening any chat saved before this deployment produces an empty UI. Add a backward-compatible derivation/backfill before relying on dbMsg.type here.

@ngoiyaeric ngoiyaeric merged commit 097871f into main Jul 12, 2026
5 checks passed
@ngoiyaeric ngoiyaeric mentioned this pull request Jul 12, 2026
ngoiyaeric added a commit that referenced this pull request Jul 12, 2026
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.

1 participant