Skip to content

fix(showcase/langgraph-typescript): bind liveness probe before heavy module imports - #4148

Merged
jpr5 merged 1 commit into
mainfrom
fix/langgraph-ts-liveness-ordering
Apr 22, 2026
Merged

jpr5 merged 1 commit into
mainfrom
fix/langgraph-ts-liveness-ordering

Conversation

@jpr5

@jpr5 jpr5 commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

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

  • Local Docker build green (amd64)
  • Container serves /ok within <2s of launch (measured: 1.4s)
  • Railway deploy green + smoke passes sustained

…module imports

PR #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.
@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)
chat-with-your-data Ready Ready Preview, Comment Apr 22, 2026 5:22am
docs Ready Ready Preview, Comment Apr 22, 2026 5:22am
form-filling Ready Ready Preview, Comment Apr 22, 2026 5:22am
research-canvas Ready Ready Preview, Comment Apr 22, 2026 5:22am
travel Ready Ready Preview, Comment Apr 22, 2026 5:22am

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

@jpr5
jpr5 merged commit 307172e into main Apr 22, 2026
14 checks passed
@jpr5
jpr5 deleted the fix/langgraph-ts-liveness-ordering branch April 22, 2026 05:24
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

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