Skip to content

feat(webapp): read realtime run rows from the primary, not the replica#4378

Merged
ericallam merged 3 commits into
mainfrom
fix/realtime-run-reads-from-primary
Jul 26, 2026
Merged

feat(webapp): read realtime run rows from the primary, not the replica#4378
ericallam merged 3 commits into
mainfrom
fix/realtime-run-reads-from-primary

Conversation

@ericallam

Copy link
Copy Markdown
Member

Summary

The realtime runs feed hydrates run rows from read replicas, which means it needs a replica-lag gate to avoid serving a run's previous state right after a write. Setting REALTIME_BACKEND_NATIVE_RUN_READS_FROM_PRIMARY=1 reads those rows from each run store's primary instead, so there is no lag to gate against: no probe, no wake delay, no stale-read retries. Off by default, so nothing changes unless you set it.

Design

The run stores already decide replica-vs-primary from the brand on the read client they are handed: a branded replica keeps the read on the owning store's replica, an unbranded writer escalates it to that store's own primary. So this is a one-line choice at the hydrator, and it stays correct across topologies. With the run-ops split on, each leg lands on its own writer and the caller's client is never forwarded across databases; with the split off, it is the single database's primary.

const runReader = new RunHydrator({
  readClient: runReadsFromPrimary ? prisma : $replica,
  runStore,
});

The same flag skips constructing the lag estimator, since probing a replica the feed no longer reads would be measuring the wrong thing.

Independently, AuroraReplicaLagSource detected Aurora by letting aurora_replica_status() fail, on the assumption that the app-level catch made that free. It isn't: an unresolvable function is a query error the driver reports to the error log on every sample, so a non-Aurora replica produced a continuous stream of error events while the estimator quietly fell through to its next candidate. It now resolves the function with to_regproc and memoizes the answer, so the unparseable call never reaches the wire.

REALTIME_BACKEND_NATIVE_RUN_READS_FROM_PRIMARY=1 hands the run hydrator an
unbranded client, so routed reads escalate to each owning store's own primary
and the replica lag gate is not constructed at all.

Also detect aurora_replica_status() with to_regproc instead of by letting the
call fail: an unresolvable function is a query error the driver reports to the
error log regardless of the app-level catch.
@changeset-bot

changeset-bot Bot commented Jul 26, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 16fc6a2

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Realtime run hydration now uses a generic readClient option, with native and shadow client wiring and tests updated accordingly. A new environment flag allows native realtime reads to use the primary database instead of the replica, disabling replica-lag gating in that mode. Aurora replica-lag detection now probes and caches function availability before sampling, with tests covering unavailable functions and cached probes.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description covers summary and design, but it omits the template's Closes, checklist, testing, changelog, and screenshots sections. Add the missing template sections, including Closes #issue, checklist items, testing steps, changelog, and screenshots or a note that none are needed.
✅ Passed checks (4 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title clearly summarizes the main change: reading realtime run rows from primary instead of the replica.
✨ 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 fix/realtime-run-reads-from-primary

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.

coderabbitai[bot]

This comment was marked as resolved.

@ericallam
ericallam marked this pull request as ready for review July 26, 2026 15:22

@devin-ai-integration devin-ai-integration 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.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@ericallam
ericallam merged commit d390624 into main Jul 26, 2026
40 checks passed
@ericallam
ericallam deleted the fix/realtime-run-reads-from-primary branch July 26, 2026 18:43
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.

2 participants