Skip to content

Dev runner supervisor prototype #27

Closed

Description

@allisonmahmood

Question

Runner supervising turbo run dev vs spawning each service with Effect 4's ChildProcess (effect/unstable/process): which gives clean Ctrl-C / stop teardown of server + embedded-postgres, survives the agent's shell exiting (daemonised start, later attach), runs two worktrees side by side without cross-talk, and produces logs an agent can read (per-service prefixed lines, not interleaved noise)?

Throwaway prototype; the answer becomes a requirement on the Effect v4 port map. Input: Local dev environment resolution.

Activity

  1. added
    wayfinder:prototype
    on Aug 26, 2026
  2. allisonmahmood commented on Aug 26, 2026

    @allisonmahmood
    OwnerAuthor

    Prototype findings (not the resolution — awaiting Allison's pick)

    Prototype: branch prototype/dev-runner-supervisor, file scripts/dev-proto/dev.ts. One runner, two supervisors selected by argument:

    tsx scripts/dev-proto/dev.ts <turbo|effect> <up|start|stop|status|logs|dry-run>
    

    Both variants start embedded-postgres in-process identically; they differ only in how the server is launched — turbo run dev as one child, or tsx watch src/start.ts spawned directly with effect/unstable/process. The supervisor is an Effect scope: postgres is acquireRelease, the service is spawner.spawn (scoped, forceKillAfter: 5s), start spawns the supervisor detached + unref and polls /healthz.

    Results against the four criteria

    criterion turbo Effect ChildProcess
    Ctrl-C on foreground up clean, ~150 ms, 0 leftovers clean, ~150 ms, 0 leftovers
    daemonised start → shell exits → stop later clean, 0 leftovers clean, 0 leftovers
    two worktrees side by side both healthy on hashed ports; no turbo daemon spawned; stopping one leaves the other up same
    logs [turbo] @patchy/server:dev: … double prefix plus turbo banner, deprecation warning and npm notice lines [server] …, nothing else

    Teardown is equal because both go through the same Effect scope: NodeRuntime.runMain maps SIGINT/SIGTERM to interruption, finalizers kill the service then stop postgres. Turbo does forward SIGTERM to its tsx watch grandchildren correctly.

    What turbo cost that Effect didn't

    1. Strict env mode stripped PORT and DATABASE_URL. First turbo run silently started the server on :3000 against the JSON DB — exactly the cross-worktree collision the plan exists to prevent. Fix is --env-mode=loose or declaring every service env var in turbo.json; the effect variant passes env directly.
    2. Needs the package-manager binary on PATH. Unable to find package manager binary on this machine (pnpm via mise); the effect variant spawns tsx from node_modules/.bin and doesn't care.
    3. --parallel is deprecated in turbo 2.10; the replacement is persistent/with task config — more turbo.json to own for a dev task that has cache: false and no graph anyway.
    4. Four extra process layers (turbo node shim → turbo binary → pnpm → tsx) and a .turbo/ dir per worktree.

    Turbo bought nothing here: with one persistent, uncached dev task there is no graph to schedule, and the runner already owns the plan.

    Other facts surfaced

    • handle.exitCode is the only thing needed to make a service crash tear the supervisor (and postgres) down — my first cut sat on Effect.never and a dead turbo left postgres running for a minute. Same one-liner in both variants.
    • embedded-postgres initdb took ~5.7 s, of which 5.4 s was "syncing data to disk" — initdbFlags: ["--no-sync"] should bring it near the ~300 ms the options ticket quoted. First start otherwise ~1 s.
    • Running the runner under tsx puts a wrapper pid between start's handle and the supervisor's process.pid; the real runner should run under node --import tsx or be built, so plan.json's pid is the one signals reach.
    • .local/dev/ contents from the prototype: pg/, dev.log, plan.json, storage/ — matches the local-dev decision.

    Recommendation

    Spawn each service directly with Effect's ChildProcess; drop turbo from the dev path (keep it for build/test/lint). Requirement for the port map: the runner is an Effect scope that owns every service handle; teardown is scope closure; start = detached self-spawn + unref + health poll.

  3. allisonmahmood commented on Aug 26, 2026

    @allisonmahmood
    OwnerAuthor

    Resolution

    Spawn each service directly with Effect 4's ChildProcess (effect/unstable/process); turbo is not on the dev path (it stays for build/test/lint). Decided with Allison, 2026-08-26, on the prototype findings (branch prototype/dev-runner-supervisor, throwaway — not merged).

    Requirements the Effect v4 port map inherits:

    • The runner is an Effect scope that owns every service handle: postgres via acquireRelease, each service via spawner.spawn with killSignal: SIGTERM + forceKillAfter. Teardown is scope closure; NodeRuntime.runMain maps SIGINT/SIGTERM to interruption. Any service's exitCode closes the scope, so a crashed service takes the instance down rather than leaving postgres orphaned.
    • start = spawn the supervisor detached, unref it, poll /healthz; stop = SIGTERM the supervisor pid recorded in plan.json. Run the supervisor under node --import tsx (or built), never the tsx CLI wrapper, so the recorded pid is the one signals reach.
    • Env goes straight to each child (no strict-mode declaration layer); log lines carry one [service] prefix written by the runner.
    • initdb with --no-sync (the 5 s fsync dominated first start).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

wayfinder:prototype

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions