fix(worker): boot ingestion worker through the server-only-aware tsx runner#493
Conversation
…runner Dockerfile.worker ran `node node_modules/tsx/dist/cli.mjs worker/index.ts` directly. worker/index.ts imports src/lib/env, which begins with `import "server-only"` (added in #488). Under bare tsx that import throws, so the production ingestion worker container crash-loops on boot. Route the entrypoint through scripts/run-tsx.mjs, which registers the server-only stub hook so the import resolves outside the Next bundler. Guard it in tests/tsx-server-only-runner.test.ts: the worker CMD must route through run-tsx.mjs and never invoke bare tsx, so this cannot regress. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
This pull request has been ignored for the connected project Preview Branches by Supabase. |
📝 WalkthroughWalkthroughThe worker Docker command now invokes ChangesWorker startup
Estimated code review effort: 2 (Simple) | ~10 minutes Caution Pre-merge checks failedPlease resolve all errors before merging. Addressing warnings is optional.
❌ Failed checks (1 error)
✅ Passed checks (10 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@tests/tsx-server-only-runner.test.ts`:
- Around line 21-28: Update the Dockerfile command assertion in the test to
parse the JSON CMD declaration and compare the complete command vector against
["node", "scripts/run-tsx.mjs", "worker/index.ts"]. Replace the substring-based
checks around cmdLine so direct tsx invocations cannot satisfy the startup
contract.
🪄 Autofix (Beta)
❌ Autofix failed (check again to retry)
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 Plus
Run ID: d065acc1-8106-45da-8a66-7b5af2302cab
📒 Files selected for processing (2)
Dockerfile.workertests/tsx-server-only-runner.test.ts
Addresses CodeRabbit review on #493: parse the JSON exec-form CMD and assert the full ["node","scripts/run-tsx.mjs","worker/index.ts"] vector so bare-tsx variants (["tsx", …], ["npx","tsx", …], or reordered args) cannot slip past substring checks. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Note Autofix is a beta feature. Expect some limitations and changes as we gather feedback and continue to improve it. Autofix skipped. No unresolved CodeRabbit review comments with fix instructions found. |
|
Caution Docstrings generation - FAILED No docstrings were generated. |
Summary
Follow-up to #488. That PR marked
src/lib/env.tswithimport "server-only", butDockerfile.workerstill boots the ingestion worker under bare tsx, which throws on that import — so the production worker container crash-loops on startup.Crash chain (on
maintoday):Dockerfile.worker→CMD ["node", "node_modules/tsx/dist/cli.mjs", "worker/index.ts"](bare tsx, no server-only stub)worker/index.ts→await import("./main")→worker/main.ts→import { env } from "../src/lib/env"src/lib/env.ts:1→import "server-only"→ throws under plain tsx →startWorker().catch(… process.exit(1))→ boot fails.Fix
Route the worker entrypoint through
scripts/run-tsx.mjs(already used by every npmtsxscript since #488), which registers theserver-onlystub hook so the import resolves outside the Next bundler:All three helper scripts (
run-tsx.mjs,enable-server-only-stub.mjs,register-server-only.mjs) and the devDependencytsxare already present in the worker image (COPY . .+ dev-inclusivenpm ci), so no other image change is needed. ACMD-level comment documents why, to prevent a "simplify back to bare tsx" regression.Guard
Extended
tests/tsx-server-only-runner.test.tsto assertDockerfile.worker'sCMDroutes throughscripts/run-tsx.mjs, runsworker/index.ts, and never invokestsx/dist/cli.mjs. This fails on the old line and passes on the new one.Verification
tests/tsx-server-only-runner.test.ts— 4/4 pass (incl. the new worker-boot guard)tsc --noEmitclean;eslint+prettier --checkclean on the changed test fileDockerfile.workeris the only bare-tsx entrypoint in the repo (all npm scripts already route throughrun-tsx.mjs)Container boot was verified by static import-chain analysis, not by building the image (no Docker in this environment); CI's
Buildlane exercises the image build.Clinical Governance Preflight
Not applicable — build/runtime entrypoint only; no change to clinical output, retrieval, data access, or privacy surfaces.
🤖 Generated with Claude Code