Skip to content

fix(memory): migrate legacy memories_captured v2 scopes - #1668

Open
sentry[bot] wants to merge 3 commits into
mainfrom
seer/fix/memory-legacy-scopes
Open

fix(memory): migrate legacy memories_captured v2 scopes#1668
sentry[bot] wants to merge 3 commits into
mainfrom
seer/fix/memory-legacy-scopes

Conversation

@sentry

@sentry sentry Bot commented Aug 23, 2026

Copy link
Copy Markdown
Contributor

This PR fixes a ZodError that occurs when reading conversation history containing memories_captured events with legacy scope values.

Problem:
After DB migration #1667, memories_captured events' scope field was updated from 'personal'/'conversation' to 'private'/'public'. However, some existing database rows still contain the old scope values. The capturedMemorySchema in packages/junior-memory/src/events.ts was only validating against the new 'private'/'public' enums, causing Zod validation to fail when encountering legacy scopes.

Solution:
Implemented z.preprocess on the scope field within capturedMemorySchema. This preprocess step uses the existing currentScope helper function to automatically coerce legacy 'personal' values to 'private' and 'conversation' values to 'public' during parsing. This ensures that all scope values conform to the current schema before validation, resolving the ZodError without requiring a data migration.

Fixes JUNIOR-8Q

This PR was automatically generated by Sentry. You can adjust this setting at any time.

@vercel

vercel Bot commented Aug 23, 2026

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
junior-docs Ready Ready Preview Aug 23, 2026 10:53am

Request Review

@cursor cursor 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.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit e26e755. Configure here.

Comment thread packages/junior-memory/src/events.ts Outdated
Comment thread packages/junior-memory/src/events.ts Outdated
.object({
...capturedMemoryFields,
scope: z.enum(MEMORY_SCOPES),
scope: z.preprocess((val) => currentScope(val as any), z.enum(MEMORY_SCOPES)),

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Missing compatibility removal TODO

Low Severity

The new z.preprocess path tolerates legacy personal/conversation scopes at parse time, but there is no TODO(vX.Y.Z) naming that legacy state. Repo comment policy requires a dated removal marker on transitional compatibility branches.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit e26e755. Configure here.

@sentry-junior sentry-junior Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me. Coercing legacy personal/conversation scopes on the v2 memories_captured schema is the right read-path fix for residual pre-migration rows, and currentScope already matches the rename. I updated the events unit test that still expected the old Zod throw so it locks in the coercion instead.

Update the events regression test to assert coerce-on-read instead of
expecting a Zod throw, and drop the preprocess any cast.

@sentry-junior sentry-junior Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good to me. Coercing legacy personal/conversation on the v2 memories_captured parse path is the right fix for residual pre-migration rows, and the events test now locks both directions of the rename. Follow-up on the branch drops the preprocess any cast while keeping currentScope typed for render.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants