Declare RuntimeContext on the API Worker's fetch and drop seven no-op phantoms#215

open1
dev
deslop/runtime-context
opened20d agobyAAviddaram
View on GitHubTwo-way sync enabledPR last imported 20d ago

The API Worker declared fetch as a plain HttpEffect, even though the alchemy runtime gives fetch a RuntimeContext (Platform.ts Main, beta.83). To fit that narrower type, the code piped binding values through RuntimeContext.phantom, and a lazy() helper did the same for Outputs. Seven of lazy's eight calls, plus the LinkSecret phantom, provided a service the Effect never required: yield* of an Output or a Random already returns Accessor<A>, which has no requirement.

Now ApiWorker declares { fetch: HttpEffect<RuntimeContext> }. The per-request database layer reads d1.raw directly, and its requirement flows up to fetch. lazy is gone. The phantom stays only where a binding client call gets captured in a service built at cold start, whose interface has R = never. Upstream beta.83 uses it the same way (examples/cloudflare-better-auth/src/middleware.ts).

diff
1 RuntimeContext.phantom sites
2-index.ts d1.raw -> handle (Auth + database)
3+index.ts d1.raw -> Auth.layer only; database reads d1.raw, fetch provides it
4 index.ts rate limiter (RateLimiter service, R = never)
5-index.ts linkSecret.text (Accessor, needed nothing)
6 index.ts execution.waitUntil (Emails background callback)
7 auth.ts x2 instance.auth (Auth service methods)
8 email.ts client.send (Mail service)
9-r2.ts lazy() x8 call sites
10+r2.ts S3 credentials only (Storage layer built at cold start)
11-index.ts lazy(products.*.id) x3, lazy(webhook.secret)
12-telemetry.ts lazy(traces.*) x2, lazy(token.token)

Checks: vp check --quiet, vp run test (216 passed), vp run build. A pr-0 preview plan matches unchanged origin/dev resource for resource and binding for binding.

Checks

5 successful · 2 skipped · 1 neutral
All checks passed
910eb60

Added 1 commit

  • Declare RuntimeContext on the Worker's fetch and drop no-op phantoms910eb60
Synced from GitHub

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
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2ce4e1d7-4f5a-46fd-83ee-d21b0350f087

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
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Synced from GitHub

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable defects were found.

Summary

ApiWorker.fetch now declares its RuntimeContext requirement, and the per-request database layer keeps that requirement.

  • The API request path carries its runtime context into database work.
  • Resource outputs now flow directly without extra runtime wrappers.

No actionable issues were found. Tests and builds were not rerun during this review.

Reviews (1) · Last reviewed commit: "Declare RuntimeContext on the Worker's f..." · Reviewed by Greptile