Skip to content

fix(showcase): langgraph watchdog regression — startup grace period - #4123

Merged
jpr5 merged 1 commit into
mainfrom
fix/langgraph-watchdog-regression
Apr 21, 2026
Merged

jpr5 merged 1 commit into
mainfrom
fix/langgraph-watchdog-regression

Conversation

@jpr5

@jpr5 jpr5 commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Incident

langgraph-typescript is in a restart loop on Railway as of 04-20 17:05 UTC (deployment 58bbebe8-7a94-4f99-b6e4-ffcbb4eb78b9), returning 502 to production traffic.

Root cause

PR #4116 generalized the silent-hang watchdog from crewai-crews to every showcase starter: poll agent health every 30s, kill after 3 consecutive failures (~90s). That's fine for uvicorn/express agents (responsive in <5s), but langgraph-cli dev does a heavy cold-start:

  • Studio browser IPC handshake (createIpcServer)
  • @langchain/langgraph-api JIT spawn (spawnServer)
  • Graph compile

On cold Railway containers this routinely exceeds 90s — the watchdog was killing the process before /ok ever became reachable, producing a kill-loop every ~90s.

Phase 1 findings

Verified the health path is correct — not a path bug:

  • @langchain/[email protected]/dist/cli/up.mjs:27 uses /ok as its own probe.
  • @langchain/[email protected]/dist/api/meta.mjs:64 registers api.get("/ok", ...).
  • langgraph_cli (Python) serves /ok from the same api surface.

The regression is purely a timing issue: 90s strike budget is insufficient for langgraph cold-start on Railway.

Fix — Option B (startup grace)

Added per-framework getWatchdogGraceSeconds() in the generator:

The grace loop waits up to 180s for the first healthy /ok probe before arming the strike counter:

  • First success → fall through immediately and arm the counter.
  • 180s elapsed without success → arm the counter anyway (steady-state watchdog then handles true hangs on the normal 90s schedule).
  • Agent dies during grace → exit grace loop, wait -n in main shell handles it.

Not a revert of #4116. The silent-hang vulnerability class remains covered (still kills after 90s of steady-state failures); the grace only defers the first strike.

Per-starter changes

Starter Grace Behavioral change
langgraph-typescript 180s Fixes restart loop
langgraph-python 180s Preemptive
langgraph-fastapi 180s Preemptive
crewai-crews, ag2, agno, claude-sdk-, google-adk, llamaindex, langroid, mastra, ms-agent-, pydantic-ai, spring-ai, strands 0s None (comment-only diff)

Files touched

  • showcase/scripts/generate-starters.ts — new getWatchdogGraceSeconds() + grace block in getWatchdogBlock()
  • showcase/starters/*/entrypoint.sh — regenerated (17 files; grace block for langgraph-*, comment-only for the other 14)
  • showcase/packages/langgraph-typescript/entrypoint.sh — hand-edited grace block (this package uses its own hand-edited entrypoint, not the template)
  • showcase/packages/langgraph-fastapi/entrypoint.sh — same
  • showcase/packages/langgraph-python/entrypoint.sh — same

Validation

  • bash -n passes on all 19 edited entrypoint.sh files
  • 1079/1079 showcase-scripts vitest pass (pnpm --filter @copilotkit/showcase-scripts test)

References

Test plan

  • CI green
  • Deploy to Railway — watch first boot log for [watchdog] Startup grace: waiting up to 180s... followed by [watchdog] Agent healthy after Ns — arming strike counter
  • Confirm no restart loop on langgraph-typescript

PR #4116 introduced a generalized silent-hang watchdog that polls the
agent health endpoint every 30s and kills the agent after 3 consecutive
failures (~90s). This worked for fast-starting agents (uvicorn,
express) but regressed langgraph-typescript on Railway: `langgraph-cli
dev` does a heavy cold-start (Studio IPC setup + @langchain/langgraph-api
JIT spawn + graph compile) that routinely exceeds 90s on a fresh
container, so the watchdog was killing the process before /ok ever
became reachable — producing the 04-20 17:05 UTC restart loop on
deployment 58bbebe8-7a94-4f99-b6e4-ffcbb4eb78b9.

Phase 1 verification:
  - `@langchain/[email protected]/dist/cli/up.mjs:27` uses /ok as
    its own health probe, and `@langchain/[email protected]/dist/
    api/meta.mjs:64` registers `api.get("/ok", ...)` — so the watchdog
    path is correct. The regression is purely timing.
  - Railway logs show no successful /ok probe before kill-loop starts.

Fix (Option B — startup grace): add a per-framework startup-grace
window in getWatchdogGraceSeconds(). For langgraph-* starters, the
watchdog now waits up to 180s for the first healthy /ok probe before
arming the strike counter. If /ok comes up sooner, fall through
immediately. If 180s elapses without success, arm the counter anyway —
the steady-state watchdog will then handle a true hang on the normal
90s schedule.

Non-langgraph starters (crewai-crews, ag2, agno, etc.) have grace=0 and
behave exactly as before PR #4116 — the 2–3s `sleep` before the health
check is sufficient for uvicorn-based agents.

Files changed:
  - showcase/scripts/generate-starters.ts — new getWatchdogGraceSeconds()
    + grace block in getWatchdogBlock()
  - showcase/starters/*/entrypoint.sh — regenerated (grace block for
    langgraph-*, comment-only for all others)
  - showcase/packages/langgraph-typescript/entrypoint.sh — hand-edited
    grace block (this package uses its own hand-edited entrypoint, not
    the template)
  - showcase/packages/langgraph-fastapi/entrypoint.sh — same
  - showcase/packages/langgraph-python/entrypoint.sh — same

Not a revert of #4116: the silent-hang vulnerability class remains
covered (the watchdog still kills after 90s of steady-state failures;
the grace only defers the first strike).

Validated:
  - bash -n on all 19 edited entrypoint.sh files
  - 1079/1079 showcase-scripts vitest pass
@vercel

vercel Bot commented Apr 21, 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 21, 2026 5:51pm
docs Ready Ready Preview, Comment Apr 21, 2026 5:51pm
form-filling Ready Ready Preview, Comment Apr 21, 2026 5:51pm
research-canvas Ready Ready Preview, Comment Apr 21, 2026 5:51pm
travel Ready Ready Preview, Comment Apr 21, 2026 5:51pm

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 8708095 into main Apr 21, 2026
15 checks passed
@jpr5
jpr5 deleted the fix/langgraph-watchdog-regression branch April 21, 2026 18:01
jpr5 added a commit that referenced this pull request Apr 21, 2026
…tra (#4124)

## Incident

Two more showcase starters are in a Railway restart loop with the same
shape that #4123 fixed for langgraph-*:

- **`claude-sdk-typescript`** (package, :8000) — restart-looping since
  **04-20 16:54 UTC**. Runs compiled `node /app/agent_server.js`.
- **`mastra`** (starter, :8123/api) — restart-looping since
  **04-20 18:18 UTC**. Runs `npx mastra dev` on :8123 alongside
  Next.js on ${PORT:-10000}.

## Root cause

Same as #4123: PR #4116's watchdog has a 90s (3-strike) kill budget.
For agents whose cold-start path on a fresh Railway container exceeds
90s, the watchdog kills the agent before it ever reports healthy, and
the loop never breaks.

- `node /app/agent_server.js` cold-starts the full
  `@anthropic-ai/claude-agent-sdk` bundle.
- `mastra dev` performs a tsx build + Mastra server boot on first
  request.

Both exceed 90s on cold-start consistently enough to kill-loop in
production.

## Fix

Extend the `getWatchdogGraceSeconds()` mapping in
`showcase/scripts/generate-starters.ts` to return 180s for
`mastra` and `claude-sdk-typescript` in addition to `langgraph-*`.
Regenerate the two starter entrypoints. Also apply the same grace
block inline to the **package-level** `claude-sdk-typescript`
entrypoint (hand-written, not generator-emitted).

## Scope decision

**Per-framework grace, not universal.** Cite the alternative for the
record:

> Universal 180s would avoid future "which framework class needs
> grace" debate and cost basically nothing on fast cold-starts
> (uvicorn < 10s) — a 180s grace just delays the first probe from
> 30s to 180s.

Kept per-framework for this PR:

1. Smaller diff, smaller review surface (4 files vs regenerating all
   17 starters).
2. Matches the existing design comment in
   `getWatchdogGraceSeconds()` which explicitly argues that uvicorn-
   responsive agents should keep 0s so legitimate hangs restart
   quickly.
3. We now have 3 framework classes needing grace; if a 4th appears,
   universalizing becomes cheap and justified on aggregate data.

## Mastra starter — watchdog kept, not dropped

PR #4116's finisher classified **package-level** mastra as N/A
(correct — the package IS the Next.js app, no separate agent). The
**starter** is different: `mastra dev` runs as a legitimate separate
process on :8123 alongside Next.js on :10000. The watchdog there is
correctly supervising that process — grace is the right fix, not a
revert.

## Files

- `showcase/scripts/generate-starters.ts` — mapping + justification
  comment
- `showcase/packages/claude-sdk-typescript/entrypoint.sh` — inline
  grace block (package uses :8000, hand-written entrypoint)
- `showcase/starters/claude-sdk-typescript/entrypoint.sh` —
  regenerated
- `showcase/starters/mastra/entrypoint.sh` — regenerated

Package-level `mastra/entrypoint.sh` is intentionally unchanged
(no watchdog, just `exec npx next start`).

## Test plan

- [x] `bash -n` clean on all 3 modified `.sh` files
- [x] `pnpm -C showcase/scripts test` — 1079/1079 pass
- [x] `npx tsc --noEmit` in `showcase/scripts` — clean
- [x] `npx tsx generate-starters.ts` is idempotent after the regen
      commit (no further diff)
- [x] `validate-pins` — pre-existing failures on main unchanged; no
      new failures introduced by this PR
- [ ] Railway redeploy of `claude-sdk-typescript` package service
      shows `[watchdog] Agent healthy after Ns — arming strike
      counter` and exits the restart loop
- [ ] Railway redeploy of `mastra` starter service shows the same
      grace log line and exits the restart loop

## Refs

- #4123 — prior langgraph grace fix (same pattern)
- #4116 — origin of the generalized watchdog
- #4114 / #4115 — original crewai-crews watchdog
pull Bot pushed a commit to nagyist/CopilotKit that referenced this pull request Apr 21, 2026
…mastra

Two more starters are restart-looping with the same pattern CopilotKit#4123 fixed
for langgraph-*: the 90s (3-strike) watchdog budget is shorter than the
cold-start path on a fresh Railway container, so the agent gets killed
before it ever reports healthy, and the loop never breaks.

Railway evidence:
- claude-sdk-typescript (package, :8000): restart-looping since 04-20
  16:54 UTC. Runs compiled `node /app/agent_server.js` which spins up
  the full @anthropic-ai/claude-agent-sdk. Package entrypoint is hand-
  written (not generator-emitted), so add the same grace block inline
  matching CopilotKit#4123's shape.
- mastra (starter, :8123/api): restart-looping since 04-20 18:18 UTC.
  Runs `mastra dev` on :8123 alongside Next.js on ${PORT:-10000}.
  `mastra dev` performs a tsx build + Mastra server boot on first
  request — legitimate supervised process, grace is the right fix.

Package-level mastra has no watchdog (the entire package IS the Next.js
app; no separate agent to watchdog) — PR CopilotKit#4116's classification of
"N/A" was correct for the package. The starter has a separate Mastra
dev server, so the generator-emitted watchdog is legitimate there.

Per-framework grace (not universal) preserves the CopilotKit#4123 design: uvicorn
and express agents are responsive within the 2-3s sleep before
AGENT_HEALTH_CHECK, so adding grace elsewhere would only delay
legitimate restart on true hangs.

This commit covers the generator mapping + the hand-written package
entrypoint. The regenerated starter entrypoints land in the next commit.
jpr5 added a commit that referenced this pull request Apr 21, 2026
…rect @langchain/langgraph-api server (#4132)

## Summary

Root cause of the 4+ day `langgraph-typescript` flap: `npx
@langchain/langgraph-cli dev` is a dev-mode CLI that compiles TypeScript
on-demand per HTTP request, blocking the single-thread event loop ~5s
per request. On Railway, Studio IPC + `langgraph-api` JIT spawn + graph
compile routinely exceeded the 90s watchdog budget; PR #4123's 180s
grace papered over cold-start but didn't fix steady-state `/schemas`
event-loop blocking.

This PR replaces the CLI with a direct import of `startServer` from
`@langchain/langgraph-api/server` (the same Hono server `dev` wraps,
minus the tsx watcher, Studio handshake, and LangSmith tenant lookup).
Schema extraction runs in a `worker_thread` and is pre-warmed in
parallel with server startup.

Container-tested on `node:22-slim`:
- `/ok` live in <3s (vs. 5-30s dev)
- `/ok` steady-state <10ms
- `/assistants/search` returns the registered `starterAgent` graph
- Pre-warm log: `[server] Pre-warmed schemas in 3402ms`

## Caveats

- Uses `--legacy-peer-deps` for `@langchain/langgraph-sdk` version skew.
- `@langchain/langgraph-api` exports `./server` but it's not officially
public API — exact version pin (`1.1.17`) required.
- `/runs` streaming not end-to-end tested (dummy key);
`/assistants/search` and schema extraction verified.

## Test plan

- [ ] `docker build` of package succeeds (verified locally on
`node:22-slim`, arm64)
- [ ] Railway deploy passes healthcheck within watchdog budget
- [ ] Live probe: `curl
https://showcase-langgraph-typescript-production.up.railway.app/api/health`
returns 200 + `agent: ok`
- [ ] Smoke test run through Studio / demo client end-to-end (real key)

## Related

- Prior attempts: #4116 (watchdog), #4123 (180s grace) — neither
addressed the structural issue
- Proposal context:
https://www.notion.so/3493aa381852814d968df05fc461206d §2c
shaneholloman pushed a commit to shaneholloman/copilotkit that referenced this pull request Apr 21, 2026
…rect @langchain/langgraph-api server

Root cause of the 4+ day langgraph-typescript Railway flap: `npx @langchain/langgraph-cli dev` is a dev-mode CLI that compiles TypeScript on-demand per HTTP request, blocking the single-thread event loop ~5s per /schemas call. On Railway, Studio IPC handshake + langgraph-api JIT spawn + graph compile routinely exceeded the 90s watchdog budget; PR CopilotKit#4123's 180s grace papered over cold-start but didn't fix steady-state event-loop blocking.

Replace the CLI with a direct import of startServer from @langchain/langgraph-api/server (the same Hono server dev wraps, minus the tsx watcher, Studio handshake, and LangSmith tenant lookup). Schema extraction runs in a worker_thread and is pre-warmed in parallel with server startup.

Container-tested on node:22-slim:
- /ok live in <3s (vs. 5-30s dev)
- /ok steady-state <10ms
- /assistants/search returns the registered graph
- Pre-warm log: [server] Pre-warmed schemas in ~1.3-3.4s

Caveats:
- Uses --legacy-peer-deps for @langchain/langgraph-sdk version skew.
- @langchain/langgraph-api exports ./server but it's not officially public API — exact version pin (1.1.17) required.
- /runs streaming not end-to-end tested (dummy key); /assistants/search and schema extraction verified.
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
…opilotKit#4123)

## Incident

`langgraph-typescript` is in a restart loop on Railway as of **04-20
17:05 UTC** (deployment `58bbebe8-7a94-4f99-b6e4-ffcbb4eb78b9`),
returning 502 to production traffic.

## Root cause

PR CopilotKit#4116 generalized the silent-hang watchdog from `crewai-crews` to
every showcase starter: poll agent health every 30s, kill after 3
consecutive failures (~90s). That's fine for uvicorn/express agents
(responsive in <5s), but `langgraph-cli dev` does a heavy cold-start:

- Studio browser IPC handshake (`createIpcServer`)
- `@langchain/langgraph-api` JIT spawn (`spawnServer`)
- Graph compile

On cold Railway containers this routinely exceeds 90s — the watchdog was
killing the process before `/ok` ever became reachable, producing a
kill-loop every ~90s.

## Phase 1 findings

Verified the health path is correct — not a path bug:

- `@langchain/[email protected]/dist/cli/up.mjs:27` uses `/ok` as its
own probe.
- `@langchain/[email protected]/dist/api/meta.mjs:64` registers
`api.get("/ok", ...)`.
- `langgraph_cli` (Python) serves `/ok` from the same api surface.

The regression is purely a **timing** issue: 90s strike budget is
insufficient for langgraph cold-start on Railway.

## Fix — Option B (startup grace)

Added per-framework `getWatchdogGraceSeconds()` in the generator:

- `langgraph-*` starters: **180s grace**
- All other starters: **0s grace** (matches pre-CopilotKit#4116 behavior)

The grace loop waits up to 180s for the first healthy `/ok` probe before
arming the strike counter:

- First success → fall through immediately and arm the counter.
- 180s elapsed without success → arm the counter anyway (steady-state
watchdog then handles true hangs on the normal 90s schedule).
- Agent dies during grace → exit grace loop, `wait -n` in main shell
handles it.

**Not a revert of CopilotKit#4116.** The silent-hang vulnerability class remains
covered (still kills after 90s of steady-state failures); the grace only
defers the first strike.

## Per-starter changes

| Starter | Grace | Behavioral change |
|---|---|---|
| langgraph-typescript | 180s | **Fixes restart loop** |
| langgraph-python | 180s | Preemptive |
| langgraph-fastapi | 180s | Preemptive |
| crewai-crews, ag2, agno, claude-sdk-*, google-adk, llamaindex,
langroid, mastra, ms-agent-*, pydantic-ai, spring-ai, strands | 0s |
None (comment-only diff) |

## Files touched

- `showcase/scripts/generate-starters.ts` — new
`getWatchdogGraceSeconds()` + grace block in `getWatchdogBlock()`
- `showcase/starters/*/entrypoint.sh` — regenerated (17 files; grace
block for langgraph-*, comment-only for the other 14)
- `showcase/packages/langgraph-typescript/entrypoint.sh` — hand-edited
grace block (this package uses its own hand-edited entrypoint, not the
template)
- `showcase/packages/langgraph-fastapi/entrypoint.sh` — same
- `showcase/packages/langgraph-python/entrypoint.sh` — same

## Validation

- `bash -n` passes on all 19 edited `entrypoint.sh` files
- 1079/1079 `showcase-scripts` vitest pass (`pnpm --filter
@copilotkit/showcase-scripts test`)

## References

- Regression source: CopilotKit#4116
- Railway deployment: `58bbebe8-7a94-4f99-b6e4-ffcbb4eb78b9`
- Incident window: 04-20 17:05 UTC — ongoing at PR creation

## Test plan

- [ ] CI green
- [ ] Deploy to Railway — watch first boot log for `[watchdog] Startup
grace: waiting up to 180s...` followed by `[watchdog] Agent healthy
after Ns — arming strike counter`
- [ ] Confirm no restart loop on `langgraph-typescript`
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
…mastra

Two more starters are restart-looping with the same pattern CopilotKit#4123 fixed
for langgraph-*: the 90s (3-strike) watchdog budget is shorter than the
cold-start path on a fresh Railway container, so the agent gets killed
before it ever reports healthy, and the loop never breaks.

Railway evidence:
- claude-sdk-typescript (package, :8000): restart-looping since 04-20
  16:54 UTC. Runs compiled `node /app/agent_server.js` which spins up
  the full @anthropic-ai/claude-agent-sdk. Package entrypoint is hand-
  written (not generator-emitted), so add the same grace block inline
  matching CopilotKit#4123's shape.
- mastra (starter, :8123/api): restart-looping since 04-20 18:18 UTC.
  Runs `mastra dev` on :8123 alongside Next.js on ${PORT:-10000}.
  `mastra dev` performs a tsx build + Mastra server boot on first
  request — legitimate supervised process, grace is the right fix.

Package-level mastra has no watchdog (the entire package IS the Next.js
app; no separate agent to watchdog) — PR CopilotKit#4116's classification of
"N/A" was correct for the package. The starter has a separate Mastra
dev server, so the generator-emitted watchdog is legitimate there.

Per-framework grace (not universal) preserves the CopilotKit#4123 design: uvicorn
and express agents are responsive within the 2-3s sleep before
AGENT_HEALTH_CHECK, so adding grace elsewhere would only delay
legitimate restart on true hangs.

This commit covers the generator mapping + the hand-written package
entrypoint. The regenerated starter entrypoints land in the next commit.
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
…tra (CopilotKit#4124)

## Incident

Two more showcase starters are in a Railway restart loop with the same
shape that CopilotKit#4123 fixed for langgraph-*:

- **`claude-sdk-typescript`** (package, :8000) — restart-looping since
  **04-20 16:54 UTC**. Runs compiled `node /app/agent_server.js`.
- **`mastra`** (starter, :8123/api) — restart-looping since
  **04-20 18:18 UTC**. Runs `npx mastra dev` on :8123 alongside
  Next.js on ${PORT:-10000}.

## Root cause

Same as CopilotKit#4123: PR CopilotKit#4116's watchdog has a 90s (3-strike) kill budget.
For agents whose cold-start path on a fresh Railway container exceeds
90s, the watchdog kills the agent before it ever reports healthy, and
the loop never breaks.

- `node /app/agent_server.js` cold-starts the full
  `@anthropic-ai/claude-agent-sdk` bundle.
- `mastra dev` performs a tsx build + Mastra server boot on first
  request.

Both exceed 90s on cold-start consistently enough to kill-loop in
production.

## Fix

Extend the `getWatchdogGraceSeconds()` mapping in
`showcase/scripts/generate-starters.ts` to return 180s for
`mastra` and `claude-sdk-typescript` in addition to `langgraph-*`.
Regenerate the two starter entrypoints. Also apply the same grace
block inline to the **package-level** `claude-sdk-typescript`
entrypoint (hand-written, not generator-emitted).

## Scope decision

**Per-framework grace, not universal.** Cite the alternative for the
record:

> Universal 180s would avoid future "which framework class needs
> grace" debate and cost basically nothing on fast cold-starts
> (uvicorn < 10s) — a 180s grace just delays the first probe from
> 30s to 180s.

Kept per-framework for this PR:

1. Smaller diff, smaller review surface (4 files vs regenerating all
   17 starters).
2. Matches the existing design comment in
   `getWatchdogGraceSeconds()` which explicitly argues that uvicorn-
   responsive agents should keep 0s so legitimate hangs restart
   quickly.
3. We now have 3 framework classes needing grace; if a 4th appears,
   universalizing becomes cheap and justified on aggregate data.

## Mastra starter — watchdog kept, not dropped

PR CopilotKit#4116's finisher classified **package-level** mastra as N/A
(correct — the package IS the Next.js app, no separate agent). The
**starter** is different: `mastra dev` runs as a legitimate separate
process on :8123 alongside Next.js on :10000. The watchdog there is
correctly supervising that process — grace is the right fix, not a
revert.

## Files

- `showcase/scripts/generate-starters.ts` — mapping + justification
  comment
- `showcase/packages/claude-sdk-typescript/entrypoint.sh` — inline
  grace block (package uses :8000, hand-written entrypoint)
- `showcase/starters/claude-sdk-typescript/entrypoint.sh` —
  regenerated
- `showcase/starters/mastra/entrypoint.sh` — regenerated

Package-level `mastra/entrypoint.sh` is intentionally unchanged
(no watchdog, just `exec npx next start`).

## Test plan

- [x] `bash -n` clean on all 3 modified `.sh` files
- [x] `pnpm -C showcase/scripts test` — 1079/1079 pass
- [x] `npx tsc --noEmit` in `showcase/scripts` — clean
- [x] `npx tsx generate-starters.ts` is idempotent after the regen
      commit (no further diff)
- [x] `validate-pins` — pre-existing failures on main unchanged; no
      new failures introduced by this PR
- [ ] Railway redeploy of `claude-sdk-typescript` package service
      shows `[watchdog] Agent healthy after Ns — arming strike
      counter` and exits the restart loop
- [ ] Railway redeploy of `mastra` starter service shows the same
      grace log line and exits the restart loop

## Refs

- CopilotKit#4123 — prior langgraph grace fix (same pattern)
- CopilotKit#4116 — origin of the generalized watchdog
- CopilotKit#4114 / CopilotKit#4115 — original crewai-crews watchdog
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
…rect @langchain/langgraph-api server

Root cause of the 4+ day langgraph-typescript Railway flap: `npx @langchain/langgraph-cli dev` is a dev-mode CLI that compiles TypeScript on-demand per HTTP request, blocking the single-thread event loop ~5s per /schemas call. On Railway, Studio IPC handshake + langgraph-api JIT spawn + graph compile routinely exceeded the 90s watchdog budget; PR CopilotKit#4123's 180s grace papered over cold-start but didn't fix steady-state event-loop blocking.

Replace the CLI with a direct import of startServer from @langchain/langgraph-api/server (the same Hono server dev wraps, minus the tsx watcher, Studio handshake, and LangSmith tenant lookup). Schema extraction runs in a worker_thread and is pre-warmed in parallel with server startup.

Container-tested on node:22-slim:
- /ok live in <3s (vs. 5-30s dev)
- /ok steady-state <10ms
- /assistants/search returns the registered graph
- Pre-warm log: [server] Pre-warmed schemas in ~1.3-3.4s

Caveats:
- Uses --legacy-peer-deps for @langchain/langgraph-sdk version skew.
- @langchain/langgraph-api exports ./server but it's not officially public API — exact version pin (1.1.17) required.
- /runs streaming not end-to-end tested (dummy key); /assistants/search and schema extraction verified.
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
…rect @langchain/langgraph-api server (CopilotKit#4132)

## Summary

Root cause of the 4+ day `langgraph-typescript` flap: `npx
@langchain/langgraph-cli dev` is a dev-mode CLI that compiles TypeScript
on-demand per HTTP request, blocking the single-thread event loop ~5s
per request. On Railway, Studio IPC + `langgraph-api` JIT spawn + graph
compile routinely exceeded the 90s watchdog budget; PR CopilotKit#4123's 180s
grace papered over cold-start but didn't fix steady-state `/schemas`
event-loop blocking.

This PR replaces the CLI with a direct import of `startServer` from
`@langchain/langgraph-api/server` (the same Hono server `dev` wraps,
minus the tsx watcher, Studio handshake, and LangSmith tenant lookup).
Schema extraction runs in a `worker_thread` and is pre-warmed in
parallel with server startup.

Container-tested on `node:22-slim`:
- `/ok` live in <3s (vs. 5-30s dev)
- `/ok` steady-state <10ms
- `/assistants/search` returns the registered `starterAgent` graph
- Pre-warm log: `[server] Pre-warmed schemas in 3402ms`

## Caveats

- Uses `--legacy-peer-deps` for `@langchain/langgraph-sdk` version skew.
- `@langchain/langgraph-api` exports `./server` but it's not officially
public API — exact version pin (`1.1.17`) required.
- `/runs` streaming not end-to-end tested (dummy key);
`/assistants/search` and schema extraction verified.

## Test plan

- [ ] `docker build` of package succeeds (verified locally on
`node:22-slim`, arm64)
- [ ] Railway deploy passes healthcheck within watchdog budget
- [ ] Live probe: `curl
https://showcase-langgraph-typescript-production.up.railway.app/api/health`
returns 200 + `agent: ok`
- [ ] Smoke test run through Studio / demo client end-to-end (real key)

## Related

- Prior attempts: CopilotKit#4116 (watchdog), CopilotKit#4123 (180s grace) — neither
addressed the structural issue
- Proposal context:
https://www.notion.so/3493aa381852814d968df05fc461206d §2c

This branch was successfully deployed

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