Repository navigation
fix(showcase/langgraph-typescript): restore watchdog health probe after prod-mode migration - #4140
Merged
Merged
Conversation
… break watchdog restart loop PR #4132 migrated away from `langgraph-cli dev` to the @langchain/langgraph-api `startServer` Hono server. That server does bind `/ok` via its meta routes, but only AFTER `registerFromEnv` imports the graph and spawns the N workers — on Railway that window has been exceeding the watchdog's 180s startup grace plus the 90s strike budget, producing an infinite restart loop (deploy ddc88ef9 is currently flapping ~every 4m30s). Move liveness off the heavy Hono path entirely: - server.mjs now spins up a bare node:http server on port 8124 (configurable via HEALTH_PORT) *synchronously before any await*, answering GET /ok with {"status":"ok"}. Always live within ms of `node` boot. - entrypoint.sh watchdog now probes 127.0.0.1:8124/ok instead of :8123/ok. The liveness port is independent of whether :8123 has finished graph import, so the probe reflects what the watchdog actually cares about: is the Node process alive and its event loop responsive. A true hang (event loop pinned) still fails the probe and triggers container restart, so the existing hang-detection behavior is preserved. Local Docker smoke (amd64): curl /ok returned 200 within 20s of container start; LangGraph API logged "listening on 0.0.0.0:8123" ~15s later as normal.
jpr5
requested review from
marthakelly,
mme,
ranst91 and
tylerslaton
as code owners
April 22, 2026 00:12
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
Contributor
📣 Social Copy GeneratorGenerate social media copies (Twitter/X, LinkedIn, Blog Post) for this PR using Claude.
|
2 of 3 tasks
jpr5
added a commit
that referenced
this pull request
Apr 22, 2026
…module imports (#4148) ## Summary - Split `server.mjs` into `liveness.mjs` (new entry) + `server.mjs` (actual langgraph-api server). - `liveness.mjs` binds `/ok` on :8124 first, then dynamic-imports `server.mjs` to kick off the real langgraph bootstrap. - `src/agent/package.json` `start` script now runs `node --import tsx liveness.mjs` as the entry. ## Why #4140 put the probe inside `server.mjs` under the belief it would bind "synchronously before any await." ES module semantics say otherwise — all top-level `import` declarations resolve before any module-body code runs. Cold start of `@langchain/langgraph-api` + graph transpile takes ~4m30s on Railway, but watchdog grace (180s) + strikes (90s) = 270s kills before the probe ever opens. Dynamic import defers the heavy load until after liveness is already serving 200. ## Test plan - [x] Local Docker build green (amd64) - [x] Container serves /ok within <2s of launch (measured: 1.4s) - [ ] Railway deploy green + smoke passes sustained
pull Bot
pushed a commit
to TheRakeshPurohit/CopilotKit
that referenced
this pull request
Apr 22, 2026
…module imports PR CopilotKit#4140 placed the liveness probe inside server.mjs under the belief it would bind "synchronously before any await." That is not how ES modules work — all top-level `import` statements resolve before any module-body code runs. `@langchain/langgraph-api/server` takes ~4m30s to cold-import on Railway (graph eval + tsx transpile), but the watchdog's 180s grace + 3x30s strikes = 270s kills the container ~4s before the probe would have bound. Kill-loop forever. Split into: - `src/agent/liveness.mjs` (new entry): binds :8124/ok immediately using only `node:http`, then dynamic-imports server.mjs so the heavy langgraph bootstrap runs AFTER :8124 is already serving 200. - `src/agent/server.mjs`: removed the now-dead sibling-probe code; comment block explains why. - `src/agent/package.json`: `start` script now runs `node --import tsx liveness.mjs` instead of `server.mjs`. - `entrypoint.sh`: comments updated to describe the new ordering. Local smoke (docker build + run on linux/amd64): /ok returns 200 within 1.4s of container launch vs the previous ~4m34s.
zeekay
pushed a commit
to Dream-AI-4444/CopilotKit
that referenced
this pull request
Sep 11, 2026
…er prod-mode migration (CopilotKit#4140) ## Summary - Root cause: CopilotKit#4132 migrated langgraph-typescript from `langgraph-cli dev` (which exposed `/ok` immediately) to `@langchain/langgraph-api` `startServer`. That server DOES register `/ok` via its meta routes, but only binds the port AFTER `registerFromEnv` imports the graph and spawns the N workers. On Railway that window has been exceeding the watchdog's 180s startup grace + 90s strike budget, producing an infinite restart loop (deploy `ddc88ef9` is flapping ~every 4m30s). - Fix: move liveness off the heavy Hono path entirely. `server.mjs` now starts a bare `node:http` server on port 8124 (configurable via `HEALTH_PORT`) synchronously before any `await`, answering `GET /ok` with `{"status":"ok"}`. `entrypoint.sh` watchdog now probes `127.0.0.1:8124/ok` instead of `:8123/ok`. ## Why The service has been 502-ing all day. Railway deploy `ddc88ef9` never serves a single `/api/health` 200 despite `[server] LangGraph API listening on 0.0.0.0:8123` landing in the logs — the `listening` callback fires after the watchdog has already killed PID 4 and triggered a restart. Liveness on a sibling port is independent of whether :8123 has finished its graph import, so the probe reflects what the watchdog actually cares about: is the Node process alive and its event loop responsive. A true hang (event loop pinned) still fails the probe and triggers container restart, so hang-detection is preserved. ## Test plan - [x] Local Docker build green (`--platform linux/amd64`, depot) - [x] Local container `curl http://127.0.0.1:8124/ok` returns `HTTP=200 {"status":"ok"}` within 20s of boot - [x] `[server] Liveness probe listening on 0.0.0.0:8124` emitted before `[server] LangGraph API listening on 0.0.0.0:8123` - [ ] Railway redeploy recovers `/api/health` + `/api/smoke`
zeekay
pushed a commit
to Dream-AI-4444/CopilotKit
that referenced
this pull request
Sep 11, 2026
…module imports PR CopilotKit#4140 placed the liveness probe inside server.mjs under the belief it would bind "synchronously before any await." That is not how ES modules work — all top-level `import` statements resolve before any module-body code runs. `@langchain/langgraph-api/server` takes ~4m30s to cold-import on Railway (graph eval + tsx transpile), but the watchdog's 180s grace + 3x30s strikes = 270s kills the container ~4s before the probe would have bound. Kill-loop forever. Split into: - `src/agent/liveness.mjs` (new entry): binds :8124/ok immediately using only `node:http`, then dynamic-imports server.mjs so the heavy langgraph bootstrap runs AFTER :8124 is already serving 200. - `src/agent/server.mjs`: removed the now-dead sibling-probe code; comment block explains why. - `src/agent/package.json`: `start` script now runs `node --import tsx liveness.mjs` instead of `server.mjs`. - `entrypoint.sh`: comments updated to describe the new ordering. Local smoke (docker build + run on linux/amd64): /ok returns 200 within 1.4s of container launch vs the previous ~4m34s.
zeekay
pushed a commit
to Dream-AI-4444/CopilotKit
that referenced
this pull request
Sep 11, 2026
…module imports (CopilotKit#4148) ## Summary - Split `server.mjs` into `liveness.mjs` (new entry) + `server.mjs` (actual langgraph-api server). - `liveness.mjs` binds `/ok` on :8124 first, then dynamic-imports `server.mjs` to kick off the real langgraph bootstrap. - `src/agent/package.json` `start` script now runs `node --import tsx liveness.mjs` as the entry. ## Why CopilotKit#4140 put the probe inside `server.mjs` under the belief it would bind "synchronously before any await." ES module semantics say otherwise — all top-level `import` declarations resolve before any module-body code runs. Cold start of `@langchain/langgraph-api` + graph transpile takes ~4m30s on Railway, but watchdog grace (180s) + strikes (90s) = 270s kills before the probe ever opens. Dynamic import defers the heavy load until after liveness is already serving 200. ## Test plan - [x] Local Docker build green (amd64) - [x] Container serves /ok within <2s of launch (measured: 1.4s) - [ ] Railway deploy green + smoke passes sustained
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
langgraph-cli dev(which exposed/okimmediately) to@langchain/langgraph-apistartServer. That server DOES register/okvia its meta routes, but only binds the port AFTERregisterFromEnvimports the graph and spawns the N workers. On Railway that window has been exceeding the watchdog's 180s startup grace + 90s strike budget, producing an infinite restart loop (deployddc88ef9is flapping ~every 4m30s).server.mjsnow starts a barenode:httpserver on port 8124 (configurable viaHEALTH_PORT) synchronously before anyawait, answeringGET /okwith{"status":"ok"}.entrypoint.shwatchdog now probes127.0.0.1:8124/okinstead of:8123/ok.Why
The service has been 502-ing all day. Railway deploy
ddc88ef9never serves a single/api/health200 despite[server] LangGraph API listening on 0.0.0.0:8123landing in the logs — thelisteningcallback fires after the watchdog has already killed PID 4 and triggered a restart.Liveness on a sibling port is independent of whether :8123 has finished its graph import, so the probe reflects what the watchdog actually cares about: is the Node process alive and its event loop responsive. A true hang (event loop pinned) still fails the probe and triggers container restart, so hang-detection is preserved.
Test plan
--platform linux/amd64, depot)curl http://127.0.0.1:8124/okreturnsHTTP=200 {"status":"ok"}within 20s of boot[server] Liveness probe listening on 0.0.0.0:8124emitted before[server] LangGraph API listening on 0.0.0.0:8123/api/health+/api/smoke