Conversation
…hapes
Migrate legacy discourse node block props on read instead of dropping
nodes that fail schema validation. Handles two known shape changes:
- specification: Condition[] → {enabled, query: {conditions, ...}}
- suggestiveRules.isFirstChild: {uid, value} → boolean
On successful migration, writes the fixed data back so subsequent reads
hit the happy path. Nodes that can't be migrated still report to PostHog.
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
📝 WalkthroughWalkthroughA migration helper is introduced to transform legacy block property shapes during parsing. The Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
apps/roam/src/components/settings/utils/accessors.ts (1)
594-601: Consider reportingretryResult.errorinstead ofresult.error.When migration is attempted but still fails validation, the
retryResult.errorwould be more informative for debugging since it reflects the error against the migrated data structure. The originalresult.errorshows why the unmigrated props failed, which is expected.💡 Suggested change
} else { internalError({ - error: result.error, + error: retryResult.error, type: "DG Discourse Node Parse", context: { pageUid, title }, sendEmail: false, }); }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@apps/roam/src/components/settings/utils/accessors.ts` around lines 594 - 601, The internalError call currently logs result.error (the original validation error) after a migration retry; instead use retryResult.error so the logged error reflects validation against the migrated data. Update the error argument passed to internalError in the else branch (the block that currently references result.error) to retryResult.error while keeping the same type ("DG Discourse Node Parse") and context ({ pageUid, title }) and sendEmail flag.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@apps/roam/src/components/settings/utils/accessors.ts`:
- Around line 594-601: The internalError call currently logs result.error (the
original validation error) after a migration retry; instead use
retryResult.error so the logged error reflects validation against the migrated
data. Update the error argument passed to internalError in the else branch (the
block that currently references result.error) to retryResult.error while keeping
the same type ("DG Discourse Node Parse") and context ({ pageUid, title }) and
sendEmail flag.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 5546d478-8daa-40b8-9b06-38f34ec035db
📒 Files selected for processing (1)
apps/roam/src/components/settings/utils/accessors.ts
When migration fails, report retryResult.error (remaining issues) instead of result.error (original issues) so PostHog shows actionable diagnostics.
Set returnNode to "node" (matching DEFAULT_RETURN_NODE and IndexSchema default) instead of "" which bypasses Zod's .default() and would persist incorrect empty values for migrated nodes.
mdroidian
left a comment
There was a problem hiding this comment.
Great video! Very clear, to the point. 💥
https://www.loom.com/share/7d5857d8340e47fca362f3892c199d8c
Migrate legacy discourse node block props on read instead of dropping nodes that fail schema validation. Handles two known shape changes:
On successful migration, writes the fixed data back so subsequent reads hit the happy path. Nodes that can't be migrated still report to PostHog.
We're seeing recurring ZodErrors in PostHog from getAllDiscourseNodes. Two schema shape changes from the block props migration left user-created discourse nodes with stale
data that fails safeParse:
Default nodes get re-initialized on schema mismatch (via initSingleDiscourseNode), but user-created nodes were just silently dropped — they'd fail parse and never show up
in getAllDiscourseNodes.
Fix: When safeParse fails, we try migrating the known legacy shapes before dropping the node. If migration succeeds, we write the fixed data back to block props (so it's a
one-time cost) and include the node. If migration can't fix it, we still report to PostHog so we catch genuinely broken data.
What it doesn't do: No schema changes, no init restructuring. The migration is scoped to the two known shape changes and lives next to the read site where the error is
detected.
Summary by CodeRabbit