Skip to content

fix(showcase/langgraph-typescript): restore watchdog health probe after prod-mode migration - #4140

Merged
jpr5 merged 2 commits into
mainfrom
fix/langgraph-ts-ok-probe
Apr 22, 2026
Merged

jpr5 merged 2 commits into
mainfrom
fix/langgraph-ts-ok-probe

Conversation

@jpr5

@jpr5 jpr5 commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Root cause: fix(showcase/langgraph-typescript): replace langgraph-cli dev with direct @langchain/langgraph-api server #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

  • Local Docker build green (--platform linux/amd64, depot)
  • Local container curl http://127.0.0.1:8124/ok returns HTTP=200 {"status":"ok"} within 20s of boot
  • [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

… 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.
@vercel

vercel Bot commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Apr 22, 2026 0:24am
research-canvas Ready Ready Preview, Comment Apr 22, 2026 0:24am
travel Ready Ready Preview, Comment Apr 22, 2026 0:24am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
chat-with-your-data Skipped Skipped Apr 22, 2026 0:24am
form-filling Skipped Skipped Apr 22, 2026 0:24am

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

📣 Social Copy Generator

Generate social media copies (Twitter/X, LinkedIn, Blog Post) for this PR using Claude.

  • Generate social media copies

@vercel
vercel Bot temporarily deployed to Preview – form-filling April 22, 2026 00:20 Inactive
@vercel
vercel Bot temporarily deployed to Preview – chat-with-your-data April 22, 2026 00:20 Inactive
@jpr5
jpr5 merged commit 8a39783 into main Apr 22, 2026
1 check passed
@jpr5
jpr5 deleted the fix/langgraph-ts-ok-probe branch April 22, 2026 03:10
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

3 active and 2 inactive deployments
Preview – research-canvas — a912322c Deployed Apr 22, 2026 by vercel[bot]
Preview – travel — a912322c Deployed Apr 22, 2026 by vercel[bot]
Preview – docs — a912322c Deployed Apr 22, 2026 by vercel[bot]
Preview – chat-with-your-data — a912322c Deployed Apr 22, 2026 by vercel[bot]
Preview – form-filling — a912322c Deployed Apr 22, 2026 by vercel[bot]
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.

1 participant