Skip to content

feat(dev): run er-dispatcher as its own process, like the chart does - #630

Merged
athvin merged 1 commit into
mainfrom
bm/dev-stack-two-processes
Nov 6, 2026
Merged

athvin merged 1 commit into
mainfrom
bm/dev-stack-two-processes

Conversation

@athvin

@athvin athvin commented Nov 6, 2026

Copy link
Copy Markdown
Owner

frontend/dev/env.sh set ER_DISPATCH_IN_PROCESS=1, so the local stack ran one process serving the API and draining the queue. Phase 4 of the batch-orchestration design deletes that flag with the legacy arm — and the design had already settled where local dev lands:

make run stays for API-only work and loses ER_DISPATCH_IN_PROCESS in Phase 4.

So up.sh starts er-dispatcher beside er-server: the topology the chart ships (a separate dispatcher Deployment), rather than leaving local dev as the last place a retired one survives.

Three things make this a small change rather than a port:

  • there is a real [[bin]] er-dispatcher target, so no argv[0] trickery is needed outside the image;
  • env.sh already exports the ER_PG_DSN the dispatcher reads;
  • the chart's own Deployment is the proof the daemon runs standalone.

No boot ordering is required, and that's a property rather than a hope

er_server::pg::ensure_schema opens with pg_advisory_xact_lock(hashtext('erserver.ensure_schema'), 0), so concurrent ensures serialise instead of deadlocking. That lock is what retired the API-strictly-before-dispatcher dance the Python stack needed, where the dispatcher's long-lived leader connection blocked the API's DDL forever.

(It also makes a note of mine stale — I had "start the API before the dispatcher or ensure_schema hangs" recorded, which was true before that lock landed.)

The half-up state is reachable again, so it's checked again

With the dispatcher in-process, "the API answers" implied "the queue is being drained", and run.sh's detection of a live-API-no-dispatcher stack was deleted as unreachable.

Two processes bring it back: a dispatcher that dies leaves every job in queued forever while the API keeps answering, and nothing about the API says so. That silence is the original bug the check existed to name — so up.sh asserts the dispatcher survived boot and prints its log when it didn't. The dispatcher is a daemon with no port, so liveness is the process plus the absence of an early exit.

This is the honest cost of the change, and I'd rather pay it with a check than pretend the state is still unreachable.

Details

The flag is left out of env.sh rather than set to 0, with a comment saying where it went. cleanup stops both processes. The three header comments that described the one-process topology now describe this one.

Verified: both binaries build (cargo build --bin er-server --bin er-dispatcher), all three scripts pass bash -n, and make check is green.

Pairs with #629, which fixes the regression I found while implementing the other half of this Phase 4 decision.

🤖 Generated with Claude Code

`frontend/dev/env.sh` set `ER_DISPATCH_IN_PROCESS=1`, so the local stack ran
one process serving the API and draining the queue. Phase 4 of the
batch-orchestration design deletes that flag with the legacy arm, and the
design already settled where local dev lands: "`make run` stays for API-only
work and loses `ER_DISPATCH_IN_PROCESS` in Phase 4."

So `up.sh` starts `er-dispatcher` beside er-server. That is the topology the
chart ships — a separate dispatcher Deployment — and local dev should not be
the last place a retired one survives. Three things make it a small change
rather than a port: there is a real `[[bin]] er-dispatcher` target, so no
`argv[0]` trickery is needed outside the image; `env.sh` already exports the
`ER_PG_DSN` the dispatcher reads; and the chart's own Deployment is the proof
the daemon runs standalone.

**No boot ordering is required, and that is a property rather than a hope.**
`er_server::pg::ensure_schema` opens with
`pg_advisory_xact_lock(hashtext('erserver.ensure_schema'), 0)`, so concurrent
ensures serialise instead of deadlocking. That lock is what retired the
API-strictly-before-dispatcher dance the Python stack needed, where the
dispatcher's long-lived leader connection blocked the API's DDL forever.

**The half-up state is reachable again, so it is checked again.** With the
dispatcher in-process, "the API answers" implied "the queue is being drained",
and `run.sh`'s detection of a live-API-no-dispatcher stack was deleted as
unreachable. Two processes bring it back: a dispatcher that dies leaves every
job in `queued` forever while the API keeps answering, and nothing about the
API says so. That silence is the original bug the check existed to name, so
`up.sh` asserts the dispatcher survived boot and prints its log when it did
not. The dispatcher is a daemon with no port, so liveness is the process plus
the absence of an early exit.

The flag is left OUT of env.sh rather than set to 0, with a comment saying
where it went; `cleanup` stops both processes, and the three header comments
that described the one-process topology now describe this one.

Co-Authored-By: Claude Fable 5 <[email protected]>
@athvin
athvin merged commit 8a74db3 into main Nov 6, 2026
42 checks passed
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.

2 participants