You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Local dev for a multi-service Effect monorepo — the options #11
What is the best available shape for a local dev environment in a pnpm + Turborepo monorepo heading to Effect 4 with more than one service? Dev runners (how t3code's works, and the alternatives); per-worktree ports and state so parallel agents don't collide; a .local/dev/env so the CLI can never hit a remote instance by accident; --dry-run --json; hermetic Postgres for tests (testcontainers, embedded-postgres, pglite, docker compose — trade-offs, startup cost, CI parity); seeding from fixtures; a development export condition so tests and dev servers resolve workspace packages from source; dev version stamping <version>-dev.<sha>[.dirty].
Output: docs/research/local-dev-options.md on branch research/local-dev-options. Waits on it: Local dev environment.
Research written up and adversarially verified against every cited source (every t3code line reference, Node/Vite/Vitest/Turborepo/pnpm/git/Postgres/testcontainers/PGlite/Compose docs, npm dist-tags, and the local measurements re-run). Corrections from verification: process.loadEnvFile is added in v21.7/v20.12 (not v20.10); --env-file is not in the NODE_OPTIONS allow-list; testcontainers' withReuse() does not exempt a container from Ryuk; Compose's ephemeral-port form is - "5432" (the IP::port form is not in the spec); PGlite's dump is documented as "only designed for importing back into PGlite" (not "incompatible with PGDATA"); t3code bundles the server with vp pack and builds the web app with vp build; tsx documents Node flag passthrough (was an open question).
Runner. t3code's dev-runner.ts is a 930-line Effect 4 CLI that computes a plan (mode, ports, state dir, env), logs it, and spawns vp run … --parallel dev with that env. Nothing off the shelf does the plan part: Turborepo runs persistent tasks but never assigns ports or state; concurrently, mprocs and process-compose run processes with static env. Recommend the same shape as t3code — a small Effect 4 CLI under scripts/ that owns the plan and delegates process supervision to turbo run dev (or per-package commands) — not a third-party supervisor.
Per-worktree ports. t3code derives a port offset from a hash of the linked-worktree path ((Hash.string(path) >>> 0) % 3000 + 1), then scans upward for a free pair, so ports are stable per worktree yet never collide. A linked worktree is detectable without git by reading the .gitfile's gitdir: pointer, which ends in worktrees/<id>. Recommend copying this exactly.
Per-worktree state. t3code defaults state to <worktree>/.t3 and makes that outrank an ambient T3CODE_HOME, so a worktree cannot land on shared data by accident; only an explicit --home-dir wins. Patchy already gitignores .local/, and git ignores are what keeps it safe in every worktree since info/exclude lives in the shared common dir. Recommend <worktree>/.local/dev/ for ports, env, Postgres data, and logs.
.local/dev/env. Today the CLI resolves its target as flag → PATCHY_API_URL → ~/.patchy config → http://localhost:3000, so a config file pointing at a remote instance wins over "I'm in a dev checkout". Node's --env-file / process.loadEnvFile cannot fix this: the process environment beats the file (documented for --env-file; verified for both on Node 26.7). Recommend the runner write.local/dev/env and the CLI read it by walking up from cwd, ranking it above env and config, with only --api-url overriding — the same precedence rule t3code uses for state. Effect 4 ships ConfigProvider.fromDotEnv, orElse, and layerAdd({ asPrimary }) for exactly this layering.
--dry-run --json. t3code's --dry-run resolves and logs the plan, and returns before any side effect (including tailnet sharing). Precedents for JSON: turbo run --dry=json prints tasks, hashes, commands, and env; Docker Compose has a global --dry-run and compose config --format json. Effect 4's CLI has no built-in dry-run or JSON mode — it is an app-defined flag. Recommend one Plan schema that --dry-run --json prints, the runner writes to .local/dev/plan.json, and tests/agents read.
Hermetic Postgres — measured. On this machine (i7-11800H, Node 26.7, Linux x64): embedded-postgres 17.10 does initdb in ~300–330 ms and starts in ~20 ms (real postgres binaries, 60 MB on disk); PGlite 0.5.7 (Postgres 18.3 in WASM, alpha, single connection) takes ~1.0 s cold / ~0.8 s warm to instantiate in-process. Docker-based options could not be timed here: the research host's user is not in the docker group, which is itself a data point for agent machines. Testcontainers needs Docker or a Docker-socket-compatible runtime (Podman, Colima, Rancher Desktop); Compose needs Docker.
Recommend embedded-postgres for dev servers and integration tests, CI included, one cluster per worktree (its own port or a Unix socket directory, which cannot collide at all), and one cluster per Vitest run started in globalSetup with the URL passed by provide/inject. It is real Postgres with the same pg driver Effect 4's @effect/sql-pg rc uses, needs no Docker, and starts in a third of a second. Keep the postgres:17-alpine service container in CI only if image parity is wanted; PGlite is the unit-test option if Effect's @effect/sql-pglite (rc for Effect 4) is adopted, with the caveat that it is Postgres 18, single-connection, alpha.
Per-test isolation on real Postgres is CREATE DATABASE … TEMPLATE <seeded> — what testcontainers' snapshot()/restoreSnapshot() do internally — with the one constraint that the template must have no open connections during the copy. Turn on Postgres's documented non-durable settings (fsync=off, synchronous_commit=off, full_page_writes=off) for test clusters.
Seeding. Patchy already keeps seed SQL as TypeScript fixtures (SEED_DEPLOYED_ROWS_SQL); that form works on every backend. /docker-entrypoint-initdb.d runs only when the data directory is empty and only in Docker; pg_dump plain format restores through any client, the archive formats need pg_restore; PGlite has dumpDataDir/loadDataDir (~330 ms / ~240 ms for an empty DB here), whose output is "only designed for importing back into PGlite". Recommend fixtures as SQL applied through the migration runner, then template-cloned.
development export condition — verified. With exports: { development: ./src/index.ts, types: …, import: ./dist/index.js }, resolution goes to src under node -C development, NODE_OPTIONS=--conditions=development, tsx --conditions=development, tsc with customConditions: ["development"], and Vitest by default (Vitest sets NODE_ENV=test, and Vite's development|production slot picks development unless NODE_ENV=production); plain node, plain tsx, and NODE_ENV=production vitest resolve dist. Turborepo's strict env mode passes NODE_OPTIONS through; pnpm sets it via nodeOptions in pnpm-workspace.yaml; esbuild needs conditions set explicitly. The alternative is t3code's: each exports entry points at a src/*.ts file unconditionally, the server is bundled with vp pack and the web app built with vp build for release, with pnpm publishConfig.exports available to swap to dist for published packages.
Node type stripping (default since 23.6/22.18, stable in 25.2/24.12) requires .ts import specifiers and import type, and ignores tsconfig.json; Patchy's sources use .js specifiers, so dropping tsx means adopting rewriteRelativeImportExtensions/allowImportingTsExtensions or keeping tsx.
Version stamping. The CLI stamps __PATCHY_VERSION__ from package.json at bundle time and falls back to 0.0.0-dev. <version>-dev.<sha>[.dirty] is valid semver only if the sha is not all digits with a leading zero (numeric identifiers must not have leading zeros), and alphanumeric identifiers compare lexically, so sha-only prereleases do not sort. Prefix the sha with g as git describe does, and put a monotonic identifier first if ordering matters — t3code uses -nightly.<date>.<runNumber>, Node uses -nightly<date><sha>. A prerelease never satisfies ^x.y.z without includePrerelease, so dev builds cannot be picked up by accident. git describe --dirty is the reference for the dirty mark.
Open questions
embedded-postgres maintenance risk. Every npm version carries a -beta.N suffix; the README says it was created by BMD Studio, is maintained by Studio Falkland, tracks zonky's binaries, and "aims to track the PostgreSQL support policy". The sources do not say what "beta" means for the package or how quickly minor Postgres releases land. Whether that is acceptable for the default path, or whether Docker/testcontainers should stay a first-class alternative, is a judgment call the sources cannot settle.
Docker startup and CI cost were not measured because the research host had no Docker socket access; the comparison table's Docker rows are qualitative. Likewise the CI-side cost of embedded-postgres (~60 MB platform package per fresh install, cacheable with the pnpm store) was not measured.
Turborepo as supervisor vs. bare ChildProcess. The docs say nothing about signal handling for persistent tasks under a parent that also holds a Postgres child, or about running the same repo from several worktrees at once. t3code spawns vp directly with detached: false. Needs a prototype.
PGlite fidelity gaps beyond "single user/connection" are not enumerated by its docs; whether Patchy's migrations and queries behave identically on the WASM build (18.3) versus the 17.x servers is untested here.
development condition on imports (#internal/*) was not tested; Node documents that --conditions applies to both exports and imports.
Effect 4 API stability: effect/unstable/cli and effect/unstable/process are under unstable in 4.0.0-rc.112; ticket Effect 4 landscape #6 should say what that implies for scripts that depend on them.
Activity
allisonmahmood commentedon Aug 26, 2026
Resolution
Research written up and adversarially verified against every cited source (every t3code line reference, Node/Vite/Vitest/Turborepo/pnpm/git/Postgres/testcontainers/PGlite/Compose docs, npm dist-tags, and the local measurements re-run). Corrections from verification:
process.loadEnvFileis added in v21.7/v20.12 (not v20.10);--env-fileis not in theNODE_OPTIONSallow-list; testcontainers'withReuse()does not exempt a container from Ryuk; Compose's ephemeral-port form is- "5432"(theIP::portform is not in the spec); PGlite's dump is documented as "only designed for importing back into PGlite" (not "incompatible with PGDATA"); t3code bundles the server withvp packand builds the web app withvp build; tsx documents Node flag passthrough (was an open question).File: https://github.com/allisonmahmood/patchy-cloud/blob/research/local-dev-options/docs/research/local-dev-options.md
Summary
dev-runner.tsis a 930-line Effect 4 CLI that computes a plan (mode, ports, state dir, env), logs it, and spawnsvp run … --parallel devwith that env. Nothing off the shelf does the plan part: Turborepo runs persistent tasks but never assigns ports or state; concurrently, mprocs and process-compose run processes with static env. Recommend the same shape as t3code — a small Effect 4 CLI underscripts/that owns the plan and delegates process supervision toturbo run dev(or per-package commands) — not a third-party supervisor.(Hash.string(path) >>> 0) % 3000 + 1), then scans upward for a free pair, so ports are stable per worktree yet never collide. A linked worktree is detectable without git by reading the.gitfile'sgitdir:pointer, which ends inworktrees/<id>. Recommend copying this exactly.<worktree>/.t3and makes that outrank an ambientT3CODE_HOME, so a worktree cannot land on shared data by accident; only an explicit--home-dirwins. Patchy already gitignores.local/, and git ignores are what keeps it safe in every worktree sinceinfo/excludelives in the shared common dir. Recommend<worktree>/.local/dev/for ports, env, Postgres data, and logs..local/dev/env. Today the CLI resolves its target as flag →PATCHY_API_URL→~/.patchyconfig →http://localhost:3000, so a config file pointing at a remote instance wins over "I'm in a dev checkout". Node's--env-file/process.loadEnvFilecannot fix this: the process environment beats the file (documented for--env-file; verified for both on Node 26.7). Recommend the runner write.local/dev/envand the CLI read it by walking up fromcwd, ranking it above env and config, with only--api-urloverriding — the same precedence rule t3code uses for state. Effect 4 shipsConfigProvider.fromDotEnv,orElse, andlayerAdd({ asPrimary })for exactly this layering.--dry-run --json. t3code's--dry-runresolves and logs the plan, and returns before any side effect (including tailnet sharing). Precedents for JSON:turbo run --dry=jsonprints tasks, hashes, commands, and env; Docker Compose has a global--dry-runandcompose config --format json. Effect 4's CLI has no built-in dry-run or JSON mode — it is an app-defined flag. Recommend onePlanschema that--dry-run --jsonprints, the runner writes to.local/dev/plan.json, and tests/agents read.initdbin ~300–330 ms and starts in ~20 ms (realpostgresbinaries, 60 MB on disk); PGlite 0.5.7 (Postgres 18.3 in WASM, alpha, single connection) takes ~1.0 s cold / ~0.8 s warm to instantiate in-process. Docker-based options could not be timed here: the research host's user is not in thedockergroup, which is itself a data point for agent machines. Testcontainers needs Docker or a Docker-socket-compatible runtime (Podman, Colima, Rancher Desktop); Compose needs Docker.globalSetupwith the URL passed byprovide/inject. It is real Postgres with the samepgdriver Effect 4's@effect/sql-pgrc uses, needs no Docker, and starts in a third of a second. Keep thepostgres:17-alpineservice container in CI only if image parity is wanted; PGlite is the unit-test option if Effect's@effect/sql-pglite(rc for Effect 4) is adopted, with the caveat that it is Postgres 18, single-connection, alpha.CREATE DATABASE … TEMPLATE <seeded>— what testcontainers'snapshot()/restoreSnapshot()do internally — with the one constraint that the template must have no open connections during the copy. Turn on Postgres's documented non-durable settings (fsync=off,synchronous_commit=off,full_page_writes=off) for test clusters.SEED_DEPLOYED_ROWS_SQL); that form works on every backend./docker-entrypoint-initdb.druns only when the data directory is empty and only in Docker;pg_dumpplain format restores through any client, the archive formats needpg_restore; PGlite hasdumpDataDir/loadDataDir(~330 ms / ~240 ms for an empty DB here), whose output is "only designed for importing back into PGlite". Recommend fixtures as SQL applied through the migration runner, then template-cloned.developmentexport condition — verified. Withexports: { development: ./src/index.ts, types: …, import: ./dist/index.js }, resolution goes tosrcundernode -C development,NODE_OPTIONS=--conditions=development,tsx --conditions=development,tscwithcustomConditions: ["development"], and Vitest by default (Vitest setsNODE_ENV=test, and Vite'sdevelopment|productionslot picksdevelopmentunlessNODE_ENV=production); plainnode, plaintsx, andNODE_ENV=production vitestresolvedist. Turborepo's strict env mode passesNODE_OPTIONSthrough; pnpm sets it vianodeOptionsinpnpm-workspace.yaml; esbuild needsconditionsset explicitly. The alternative is t3code's: eachexportsentry points at asrc/*.tsfile unconditionally, the server is bundled withvp packand the web app built withvp buildfor release, with pnpmpublishConfig.exportsavailable to swap todistfor published packages..tsimport specifiers andimport type, and ignorestsconfig.json; Patchy's sources use.jsspecifiers, so dropping tsx means adoptingrewriteRelativeImportExtensions/allowImportingTsExtensionsor keeping tsx.__PATCHY_VERSION__frompackage.jsonat bundle time and falls back to0.0.0-dev.<version>-dev.<sha>[.dirty]is valid semver only if the sha is not all digits with a leading zero (numeric identifiers must not have leading zeros), and alphanumeric identifiers compare lexically, so sha-only prereleases do not sort. Prefix the sha withgasgit describedoes, and put a monotonic identifier first if ordering matters — t3code uses-nightly.<date>.<runNumber>, Node uses-nightly<date><sha>. A prerelease never satisfies^x.y.zwithoutincludePrerelease, so dev builds cannot be picked up by accident.git describe --dirtyis the reference for the dirty mark.Open questions
-beta.Nsuffix; the README says it was created by BMD Studio, is maintained by Studio Falkland, tracks zonky's binaries, and "aims to track the PostgreSQL support policy". The sources do not say what "beta" means for the package or how quickly minor Postgres releases land. Whether that is acceptable for the default path, or whether Docker/testcontainers should stay a first-class alternative, is a judgment call the sources cannot settle.ChildProcess. The docs say nothing about signal handling for persistent tasks under a parent that also holds a Postgres child, or about running the same repo from several worktrees at once. t3code spawnsvpdirectly withdetached: false. Needs a prototype.developmentcondition onimports(#internal/*) was not tested; Node documents that--conditionsapplies to bothexportsandimports.effect/unstable/cliandeffect/unstable/processare underunstablein4.0.0-rc.112; ticket Effect 4 landscape #6 should say what that implies for scripts that depend on them.