Skip to content

feat(run-ops): read presenters — de-join control-plane relations + read-through hydration#4122

Draft
d-cs wants to merge 12 commits into
runops/pr07-replicationfrom
runops/pr08-presenters
Draft

feat(run-ops): read presenters — de-join control-plane relations + read-through hydration#4122
d-cs wants to merge 12 commits into
runops/pr07-replicationfrom
runops/pr08-presenters

Conversation

@d-cs

@d-cs d-cs commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

What

Reworks the read-side presenters so they no longer depend on control-plane relations being co-located with the run subgraph. This is a read-path-only change — no writes, no schema, no runtime flag flips.

For every presenter that previously joined across what is becoming a database boundary, the join is removed from the primary query and the missing data is instead hydrated per-run through the run store. The pattern is a pair of internal helpers (#callSplit / #callPassthrough): when the split is active, the presenter selects only scalar/id-shaped columns from the primary query and hydrates the run-subgraph fields via a read-through lookup; when it isn't, it falls back to the existing passthrough path. Presenters key their behaviour on id-shape only — they don't consult a per-record "known-migrated" flag.

Presenters touched:

  • ApiBatchResultsPresenter, ApiRetrieveRunPresenter, ApiRunListPresenter, ApiRunResultPresenter
  • ApiWaitpointPresenter, ApiWaitpointListPresenter, WaitpointPresenter, WaitpointListPresenter, WaitpointTagListPresenter
  • BatchPresenter, BatchListPresenter, NextRunListPresenter
  • RunPresenter, RunStreamPresenter, SpanPresenter, TestTaskPresenter

A dead connectedRuns relation is dropped from the ApiWaitpointPresenter hydrate select.

New read-through / read-route tests cover each presenter under both the split-active and passthrough paths. A superseded ApiBatchResultsPresenter.split.test.ts is removed and the remaining ApiBatchResultsPresenter.test.ts trimmed — its coverage is subsumed by the new apiBatchResultsPresenter.readthrough suite.

Why

Part of the run-ops database split. This is PR8 of the series (PR8/9/10) and covers the read path only: it makes presenters correct against a split store before any routes are switched to route reads (PR9) or the split is actually enabled (PR10). Landing the read-side rework on its own keeps the behaviour-changing activation isolated at the top of the stack.

Tests

pnpm run test --filter webapp for the affected presenter suites. New suites exercise both the split-active read-through path and the passthrough path for each reworked presenter.

Notes

Draft, stacked on #4119 (runops/pr07-replication). Review that first; this diff is against it.

Server-change / changeset note to be added at stack-assembly time.

🤖 Generated with Claude Code

@changeset-bot

changeset-bot Bot commented Jul 2, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: fa0d473

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 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c7968d94-4da8-48fc-b66b-b92c66685c31

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This PR introduces optional "read-through" dependency injection across numerous v3 presenters (batch results, run results, run lists, waitpoints, waitpoint lists/tags, batch lists, batches, run/span/run-stream presenters, and test-task) to route database reads between a "new" run-ops Postgres client and a legacy read replica during a migration window. Several presenters replace raw SQL keyset scans with Prisma-based scan/merge/probe helpers supporting split-read routing. Control-plane concerns (project/organization membership, environment resolution, task schedules, locked-worker versions) are separated from run-ops reads via a controlPlaneResolver, with corresponding type updates (e.g., FoundRun, CommonRelatedRunWithVersion). Extensive new integration test suites validate cross-database routing, empty-state probing, single-DB passthrough behavior, and byte-identical parity across Postgres versions.

Related PRs

None referenced.

Suggested labels

None specified.

Suggested reviewers

None specified.

Poem

A rabbit hops between two dens,
new burrow first, legacy then,
splitting reads with careful care,
control-plane truths resolved with flair,
tests galore to prove it's fair. 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description is relevant, but it misses required template sections like Closes #issue, checklist items, changelog, and screenshots. Add the missing template sections, especially Closes #, the checklist, Testing details, Changelog, and Screenshots placeholders.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: de-joining control-plane relations and adding read-through hydration for run-ops presenters.
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.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch runops/pr08-presenters

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.

@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 found 1 potential issue.

Open in Devin Review

Comment thread apps/webapp/app/presenters/v3/ApiBatchResultsPresenter.server.ts
@d-cs d-cs force-pushed the runops/pr07-replication branch from 5de29cb to 5c2d010 Compare July 2, 2026 18:02
@d-cs d-cs force-pushed the runops/pr08-presenters branch from 9b6eee8 to 94eaef6 Compare July 2, 2026 18:02
@pkg-pr-new

pkg-pr-new Bot commented Jul 2, 2026

Copy link
Copy Markdown

Open in StackBlitz

@trigger.dev/build

npm i https://pkg.pr.new/@trigger.dev/build@fa0d473

trigger.dev

npm i https://pkg.pr.new/trigger.dev@fa0d473

@trigger.dev/core

npm i https://pkg.pr.new/@trigger.dev/core@fa0d473

@trigger.dev/python

npm i https://pkg.pr.new/@trigger.dev/python@fa0d473

@trigger.dev/react-hooks

npm i https://pkg.pr.new/@trigger.dev/react-hooks@fa0d473

@trigger.dev/redis-worker

npm i https://pkg.pr.new/@trigger.dev/redis-worker@fa0d473

@trigger.dev/rsc

npm i https://pkg.pr.new/@trigger.dev/rsc@fa0d473

@trigger.dev/schema-to-json

npm i https://pkg.pr.new/@trigger.dev/schema-to-json@fa0d473

@trigger.dev/sdk

npm i https://pkg.pr.new/@trigger.dev/sdk@fa0d473

commit: fa0d473

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

Actionable comments posted: 6

🧹 Nitpick comments (5)
apps/webapp/test/presenters/TaskDetailPresenter.getActivity.test.ts (1)

65-70: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Loosely-typed insert schema.

schema: z.any() bypasses row-shape validation for the ClickHouse insert, so a malformed TaskRunV2 fixture (e.g. wrong field name/type) would silently pass through instead of failing fast at insert time.

apps/webapp/app/presenters/v3/ApiWaitpointPresenter.server.ts (1)

13-18: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Naming inconsistency across sibling presenters.

ApiWaitpointPresenterReadThroughDeps uses newClient/legacyReplica, while ApiWaitpointListPresenter/WaitpointListPresenter in this same PR use runOpsNew/runOpsLegacyReplica for the equivalent concept. Consider aligning naming across the presenter family for consistency.

apps/webapp/test/apiWaitpointPresenter.readthrough.test.ts (1)

30-42: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider using a Proxy wrapper for consistency with the sibling test file.

This recording() uses object-spread ({...client, waitpoint}), while the equivalent helper in waitpointPresenter.readthrough.test.ts uses a Proxy wrapper, which is more robust against Prisma client internals not being plain own-enumerable properties. Not currently broken, but worth aligning the pattern across the two nearly-identical helpers.

apps/webapp/app/presenters/v3/WaitpointTagListPresenter.server.ts (1)

30-41: 📐 Maintainability & Code Quality | 🔵 Trivial

Naming inconsistency for the split-read DI seam across presenters.

This presenter names the constructor option readRoute with fields runOpsNew/runOpsLegacyReplica, while WaitpointPresenter uses readThroughDeps with newClient/legacyReplica for the same conceptual seam. Consider aligning naming across presenters for consistency.

apps/webapp/test/waitpointPresenter.controlPlane.test.ts (1)

104-137: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

This test never actually calls WaitpointPresenter.

The test validates the standalone building blocks (prisma17.waitpoint.findFirst and a locally constructed ControlPlaneResolver) but never exercises WaitpointPresenter.call() itself, despite the describe block being about presenter cross-DB read-through. Since the seeded waitpoint has no connectedRuns, calling WaitpointPresenter.call() directly here wouldn't require mocking clickhouseFactory, making it feasible to assert against the actual presenter output (e.g. result.url, matching apiKey/organizationId-derived fields) rather than just its dependencies.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 75888a07-9162-45ef-b719-038223ee3d18

📥 Commits

Reviewing files that changed from the base of the PR and between 5de29cb and 9b6eee8.

📒 Files selected for processing (37)
  • apps/webapp/app/presenters/v3/ApiBatchResultsPresenter.server.ts
  • apps/webapp/app/presenters/v3/ApiRetrieveRunPresenter.server.ts
  • apps/webapp/app/presenters/v3/ApiRunListPresenter.server.ts
  • apps/webapp/app/presenters/v3/ApiRunResultPresenter.server.ts
  • apps/webapp/app/presenters/v3/ApiWaitpointListPresenter.server.ts
  • apps/webapp/app/presenters/v3/ApiWaitpointPresenter.server.ts
  • apps/webapp/app/presenters/v3/BatchListPresenter.server.ts
  • apps/webapp/app/presenters/v3/BatchPresenter.server.ts
  • apps/webapp/app/presenters/v3/NextRunListPresenter.server.ts
  • apps/webapp/app/presenters/v3/RunPresenter.server.ts
  • apps/webapp/app/presenters/v3/RunStreamPresenter.server.ts
  • apps/webapp/app/presenters/v3/SpanPresenter.server.ts
  • apps/webapp/app/presenters/v3/TestTaskPresenter.server.ts
  • apps/webapp/app/presenters/v3/WaitpointListPresenter.server.ts
  • apps/webapp/app/presenters/v3/WaitpointPresenter.server.ts
  • apps/webapp/app/presenters/v3/WaitpointTagListPresenter.server.ts
  • apps/webapp/test/SpanPresenter.readthrough.test.ts
  • apps/webapp/test/apiBatchResultsPresenter.readthrough.test.ts
  • apps/webapp/test/apiRetrieveRunPresenter.readroute.test.ts
  • apps/webapp/test/apiRunListPresenter.test.ts
  • apps/webapp/test/apiRunResultPresenter.readthrough.test.ts
  • apps/webapp/test/apiWaitpointListPresenter.readroute.test.ts
  • apps/webapp/test/apiWaitpointPresenter.readthrough.test.ts
  • apps/webapp/test/batchListPresenter.readroute.test.ts
  • apps/webapp/test/batchPresenter.test.ts
  • apps/webapp/test/nextRunListPresenter.readthrough.test.ts
  • apps/webapp/test/presenters/ApiBatchResultsPresenter.split.test.ts
  • apps/webapp/test/presenters/ApiBatchResultsPresenter.test.ts
  • apps/webapp/test/presenters/TaskDetailPresenter.getActivity.test.ts
  • apps/webapp/test/presenters/TestTaskPresenter.readthrough.test.ts
  • apps/webapp/test/realtime/clickHouseRunListResolver.test.ts
  • apps/webapp/test/runPresenterReadRoute.test.ts
  • apps/webapp/test/spanPresenterReadthroughDecompose.test.ts
  • apps/webapp/test/waitpointListPresenter.readroute.test.ts
  • apps/webapp/test/waitpointPresenter.controlPlane.test.ts
  • apps/webapp/test/waitpointPresenter.readthrough.test.ts
  • apps/webapp/test/waitpointTagListPresenter.readroute.test.ts
💤 Files with no reviewable changes (1)
  • apps/webapp/test/presenters/ApiBatchResultsPresenter.split.test.ts

Comment thread apps/webapp/app/presenters/v3/BatchListPresenter.server.ts
Comment thread apps/webapp/app/presenters/v3/WaitpointPresenter.server.ts
Comment thread apps/webapp/test/apiRetrieveRunPresenter.readroute.test.ts
Comment thread apps/webapp/test/apiRunResultPresenter.readthrough.test.ts
Comment thread apps/webapp/test/SpanPresenter.readthrough.test.ts
Comment thread apps/webapp/test/waitpointListPresenter.readroute.test.ts
@d-cs d-cs force-pushed the runops/pr07-replication branch from 8fb6e8a to 4e08dc7 Compare July 2, 2026 19:25
@d-cs d-cs force-pushed the runops/pr08-presenters branch from 6e4c0de to 48c395b Compare July 2, 2026 19:25
@d-cs d-cs force-pushed the runops/pr07-replication branch from 4e08dc7 to 11dc0b7 Compare July 2, 2026 20:23
@d-cs d-cs force-pushed the runops/pr08-presenters branch from f8b64bd to e145839 Compare July 2, 2026 20:23
@d-cs d-cs force-pushed the runops/pr07-replication branch from 11dc0b7 to a9bc9e6 Compare July 2, 2026 20:38
@d-cs d-cs force-pushed the runops/pr08-presenters branch from e145839 to 6cd0085 Compare July 2, 2026 20:38
@d-cs d-cs force-pushed the runops/pr07-replication branch from a9bc9e6 to 277ecea Compare July 2, 2026 21:44
@d-cs d-cs force-pushed the runops/pr08-presenters branch from 6cd0085 to 5ccf63f Compare July 2, 2026 21:44
@d-cs d-cs force-pushed the runops/pr07-replication branch from 277ecea to 2bba3b8 Compare July 3, 2026 00:17
@d-cs d-cs force-pushed the runops/pr08-presenters branch 2 times, most recently from f7cf260 to d31f2e9 Compare July 3, 2026 08:51
@d-cs d-cs force-pushed the runops/pr07-replication branch from 0f1da3f to 5a17a98 Compare July 3, 2026 10:02
@d-cs d-cs force-pushed the runops/pr08-presenters branch from d31f2e9 to 4bfd808 Compare July 3, 2026 10:02
@d-cs d-cs force-pushed the runops/pr07-replication branch from 5a17a98 to 6b7fb6d Compare July 3, 2026 10:36
@d-cs d-cs force-pushed the runops/pr08-presenters branch from 4bfd808 to 9197016 Compare July 3, 2026 10:37
d-cs and others added 6 commits July 3, 2026 11:43
…ad-through hydration

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- readRedirectMarker fails open on an unprovisioned marker table
  (undefined_table): the known-migrated read optimization must never
  break the run-list read path when the marker table is absent.
- expose runOps new/legacy handles through the db.server test seam so
  the routed-store reads resolve to the real containers.
- hoist the runStore ref so the vi.mock factory no longer hits a TDZ.
- correct the getActivity bucket expectation: a 6h window buckets into
  72 five-minute buckets (chooseBucketSeconds targets ~72), not 6.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… only

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…r09 presenters

Comment/label hygiene pass over the PR09 presenter read-routing work. No
product logic, assertions, seeds, or test structure changed — only comment
text and test/it titles.

- Remove the SPLIT-NEUTRAL scaffolding comment on TaskDetailPresenter.getActivity.
- Drop `// --- ... ---` comment fencing across the touched test files, keeping
  the behavioral text.
- Strip Task/Step enumeration prefixes from comments and it/test titles, keeping
  the behavioral descriptions.
- Remove Definition-of-Done ("DoD") framing and RED/GREEN TDD phase commentary.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…tPresenter hydrate select

GET /api/v1/waitpoints/tokens/:id returned HTTP 500 under split routing. The
hydrate() select in ApiWaitpointPresenter included the connectedRuns RELATION,
but it is never referenced in the returned object (all scalars) — dead code left
over from the presenters de-join pass (48ae62b70), which stripped relations from
WaitpointListPresenter but missed this one.

Under split routing a standalone cuid token classifies LEGACY, so readThroughRun
probes the scalar-only run-ops NEW client FIRST. The dedicated run-ops Waitpoint
model is scalar-only (relations de-normalized), so Prisma threw
PrismaClientValidationError: Unknown field connectedRuns before the legacy
fallback could run.

Removing the block makes the select all-scalar and valid against both the
control-plane client and the scalar-only run-ops-new client. No return-shape,
type, or SDK change.

Regression test: extends apiWaitpointPresenter.readthrough.test.ts with a
heteroRunOpsPostgresTest case that uses the REAL scalar-only run-ops client
(prisma17) as the split-mode NEW client and seeds a cuid token on the legacy
side. Fails before the fix (Unknown field connectedRuns), passes after
(resolves via the legacy fallback). Not caught by the existing heteroPostgresTest
cases because those run the full control-plane schema on both sides.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
d-cs and others added 6 commits July 3, 2026 11:43
…d-through presenter design

The pr04-era ApiBatchResultsPresenter.split.test.ts asserted a bare
`new ApiBatchResultsPresenter()` routes the batch-row lookup through the
runStore singleton (via vi.mock("~/v3/runStore.server")) so a NEW-resident
ksuid batch resolves. pr08's call() supersedes that contract: a bare
presenter has readThrough === undefined, so splitEnabled is false and it
takes #callPassthrough, which reads this._replica.batchTaskRun directly
(not through runStore). The test therefore fails against pr08 and encodes a
design that no longer exists.

Both cases it covered are already covered by pr08's own
apiBatchResultsPresenter.readthrough.test.ts against the current #callSplit
API: (a) a NEW-resident batch resolving under split (batch row + items on the
NEW DB, resolved via newClient) and (b) a genuinely-missing batch returning
undefined (split on). Remove the redundant, superseded test.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…epair read-side test shims

- WaitpointPresenter: default omitted read-through clients to the presenter's own
  replica instead of the global run-ops singletons, so single-DB/self-host reads
  hydrate the waitpoint and its connected runs from one DB.
- SpanPresenter test: bind proxy-returned store methods to the target so private
  field access holds for all methods (e.g. findRunOnPrimary), not just findRun/findRuns.
- ApiRetrieveRunPresenter read-route test: select scalar lockedToVersionId and fold
  the resolved lockedToVersion per node, matching the presenter's current shape.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… testcontainer

The RunStore singleton is built once at import and its error-normalizing
wrapper memoizes each Prisma model delegate on first access. The test's
delegating proxy returned current.taskRun directly, so the store cached the
first test's container-bound delegate and later tests (fresh containers)
failed with "Database test_0 does not exist". Object-valued delegates now
return a stable per-key sub-proxy the store can safely cache, re-delegating
to the live current client on each access. Production code is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…c empty CH window

Two webapp unit-test shards were red on this branch:

- Shard 6 (apiRetrieveRunPresenter.readroute.test.ts): the
  organizationDataStoresRegistry singleton is constructed at import (pulled in
  transitively via the ClickHouse factory instance) and immediately fires a
  `forever` pRetry(loadFromDatabase) plus a setInterval reload against
  db.server's $replica. In CI (no Postgres on localhost) those retry forever and
  saturate the worker event loop, timing out an awaiting test's hook. Mock the
  instance module to a no-op in test/setup.ts, mirroring the other eager-singleton
  stubs. No unit test uses this singleton — the registry-behavior tests construct
  the class directly — so this is safe and should also help other shards/branches
  that import the presenter graph.

- Shard 2 (nextRunListPresenter.readthrough.test.ts): the two empty-state tests
  seeded a run then assumed it had NOT yet replicated to ClickHouse within the page
  window, so result.runs would be empty. That held on a slow local stack but raced
  on CI, where replication had completed and the run surfaced (length 1, not 0).
  Scope those two calls to a `to` one hour in the past; the CH page filters
  created_at <= to, so a just-created run is deterministically excluded regardless
  of replication timing. The PG existence probe has no time filter, so it still
  finds the row and hasAnyRuns stays true — the exact behavior each test verifies.

Reproduced both failures and verified the fix under a CI-faithful env (DATABASE_URL
+ REDIS at dead ports, GITHUB_ACTIONS=true, --no-file-parallelism): shard 2 now
18 files / 118 tests green, shard 6 now 16 files / 212 tests green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@d-cs d-cs force-pushed the runops/pr07-replication branch from 6b7fb6d to ac94ac3 Compare July 3, 2026 10:44
@d-cs d-cs force-pushed the runops/pr08-presenters branch from 9197016 to fa0d473 Compare July 3, 2026 10:44
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