Improve realtime cache invalidation and reconnect handling - #55
Conversation
✅ Deploy Preview for holo-docs canceled.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (6)
🚧 Files skipped from review as they are similar to previous changes (5)
📝 WalkthroughWalkthroughThis PR adds predicate-level cache dependency keys to the DB cache layer, threads normalized update values through ChangesPredicate-aware cache invalidation and realtime subscription contradiction
Realtime client transport error handling and snapshot deduplication
CLI agent-skills prompt update
Sequence Diagram(s)sequenceDiagram
participant update as TableQueryBuilder.update()
participant cache as inferAutomaticQueryCacheInvalidationDependencies
participant runtime as handleDatabaseInvalidation
participant contradiction as isSubscriptionContradictedByInvalidation
participant subscription as RealtimeSubscription
update->>cache: plan, connectionName, normalizedValues
cache-->>update: [table dep, where:col:val, where-exact:col:val, ...]
update->>runtime: DatabaseDependencyInvalidationEvent (batch)
runtime->>contradiction: subscription deps vs batch events
contradiction-->>runtime: contradicted? (skip / refresh)
runtime->>subscription: refresh (if not contradicted)
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/realtime/src/client.ts (1)
613-625:⚠️ Potential issue | 🟠 Major | ⚡ Quick winSynchronous subscribe errors can leave the store stuck in a false-connected state.
If
transport.subscribe(...)invokesonErrorsynchronously, Line 624 overwrites theconnected = falseset in the callback. That can block recovery because futureconnect()calls return early onconnected === true.Suggested fix
+ let subscriptionFailedDuringSetup = false unsubscribe = transport.subscribe<TResult>(name, args, (nextSnapshot) => { if (startupId !== currentStartupId) { return } seenLiveSnapshot = true setSnapshot(nextSnapshot) }, (error) => { + subscriptionFailedDuringSetup = true connected = false handleRealtimeConnectionError(error) }) - connected = true + connected = !subscriptionFailedDuringSetup🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/realtime/src/client.ts` around lines 613 - 625, The issue is that setting `connected = true` on line 624 can overwrite a synchronous `connected = false` assignment that occurs in the error callback (lines 619-622). If transport.subscribe() invokes its onError callback synchronously, the error handler sets connected to false, but then line 624 immediately overwrites it to true, leaving the store in an incorrect connected state. Move the `connected = true` assignment to before the transport.subscribe() call so that any synchronous error callbacks will correctly override the true state with false, allowing proper error recovery on subsequent connect() attempts.
🧹 Nitpick comments (1)
packages/realtime/tests/realtime.test.ts (1)
186-212: 💤 Low valueAdd a guard for unexpected assignment format.
If the assignment regex fails to match (e.g., an unexpected SQL format),
columnbecomesundefined, silently corrupting test data by settingrow[undefined]. While this is test-only code, an explicit guard would make test failures easier to diagnose.🔧 Suggested improvement
const assignments = rawAssignments!.split(', ').map((assignment, index) => { const [, column, rawPlaceholder] = assignment.match(/^"([^"]+)" = \?(\d*)$/) ?? [] + if (!column) { + throw new Error(`RelationalMemoryAdapter: Unexpected assignment format: ${assignment}`) + } const bindingIndex = rawPlaceholder ? Number(rawPlaceholder) - 1 : index - return { column: column!, value: bindings[bindingIndex] } + return { column, value: bindings[bindingIndex] } })🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/realtime/tests/realtime.test.ts` around lines 186 - 212, In the assignments parsing section where rawAssignments is split and mapped, add a guard to handle cases where the assignment regex fails to match. After performing the regex match in the map function over the assignments, check that the match actually succeeded before destructuring the result. If the match is null or the column is undefined, either filter out that assignment or throw an error with a descriptive message about the unexpected SQL format. This will prevent silently corrupting test data by setting row[undefined] and make test failures easier to diagnose.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@packages/db/src/cache.ts`:
- Around line 507-509: The code collects both exact and non-exact predicate
dependencies from plan.predicates (lines 507-508) but only collects non-exact
dependencies from the values record (line 509). Add a call to collect exact
predicate dependencies from values to maintain consistency with how
inferAutomaticInsertCacheInvalidationDependencies handles row records (lines
527-532). After the collectRecordPredicateDependencies call for values, add
another dependencies.push statement that collects exact record predicate
dependencies from the values record using the same connectionName and tableName
parameters.
---
Outside diff comments:
In `@packages/realtime/src/client.ts`:
- Around line 613-625: The issue is that setting `connected = true` on line 624
can overwrite a synchronous `connected = false` assignment that occurs in the
error callback (lines 619-622). If transport.subscribe() invokes its onError
callback synchronously, the error handler sets connected to false, but then line
624 immediately overwrites it to true, leaving the store in an incorrect
connected state. Move the `connected = true` assignment to before the
transport.subscribe() call so that any synchronous error callbacks will
correctly override the true state with false, allowing proper error recovery on
subsequent connect() attempts.
---
Nitpick comments:
In `@packages/realtime/tests/realtime.test.ts`:
- Around line 186-212: In the assignments parsing section where rawAssignments
is split and mapped, add a guard to handle cases where the assignment regex
fails to match. After performing the regex match in the map function over the
assignments, check that the match actually succeeded before destructuring the
result. If the match is null or the column is undefined, either filter out that
assignment or throw an error with a descriptive message about the unexpected SQL
format. This will prevent silently corrupting test data by setting
row[undefined] and make test failures easier to diagnose.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 5d9a2c2f-4d3e-48fc-b02a-83f08bb465e5
📒 Files selected for processing (10)
packages/adapter-next/tests/client.test.tspackages/cli/src/agent-skills.tspackages/cli/tests/cli.test.tspackages/db/src/cache.tspackages/db/src/query/TableQueryBuilder.tspackages/db/tests/query-cache.test.tspackages/realtime/src/client.tspackages/realtime/src/runtime.tspackages/realtime/tests/realtime.client.test.tspackages/realtime/tests/realtime.test.ts
Summary by CodeRabbit
WHEREplaceholder styles andUPDATE.