Repository navigation
fix(showcase): generalize silent-hang watchdog + unbuffered stdout across starters - #4116
Merged
Merged
Conversation
…caffolding to generator + template Generalize the watchdog shape proven in showcase/packages/crewai-crews/entrypoint.sh (PRs #4114 + #4115) so that every Bucket-B starter gets: - PYTHONUNBUFFERED=1 export (harmless for non-Python frameworks) - A backgrounded watchdog subshell that polls the agent health endpoint every 30s and kills the agent after 3 consecutive failures, letting wait -n + container runtime handle the restart through the normal path. - python -u on uvicorn / langgraph_cli invocations (Python frameworks). - awk ... fflush() log prefixing (replaces the previous sed pipe; keeps $! pointing at the real agent process). Per-framework agent health paths: * FastAPI / uvicorn agents -> /health * langgraph-python, langgraph-fastapi, langgraph-typescript -> /ok * claude-sdk-typescript, ms-agent-dotnet, spring-ai -> /health * mastra -> /api Spring Boot starter also gets a 60s /health startup probe (replacing the blind sleep 5) because JVM warmup + context refresh can exceed 30s.
… from upgraded generator
Regenerates all 16 starter entrypoint.sh files from the new template. Every
starter now ships:
- $WATCHDOG_PID tracked in cleanup + kill block
- PYTHONUNBUFFERED=1 export (harmless for Java/Node/.NET)
- Explicit `wait -n $AGENT_PID $NEXTJS_PID` (excludes the watchdog so its
exit doesn't short-circuit the agent's true status)
- Per-framework health probe (see prior commit for path matrix)
Also reflects the crewai-crews root-cause fix (already on origin/main via
commit 9379b88): ag-ui-crewai >=0.2.0 bump and drop of the crewai.cli
monkey-patch shim. These files are regenerated from showcase/packages/
crewai-crews source.
… spring-ai
Hand-applied watchdog + unbuffered-stdout block for every Bucket-B package
entrypoint where the shape couldn't come from the starter generator:
* ag2, agno, claude-sdk-python, claude-sdk-typescript, google-adk,
langgraph-fastapi, langgraph-python, langgraph-typescript, langroid,
llamaindex, ms-agent-dotnet, ms-agent-python, pydantic-ai, strands
-> watchdog polls the framework-native health endpoint; Python variants
also get `python -u` + awk fflush log prefixing.
* spring-ai (Bucket C) -> watchdog extends the existing startup probe;
polls :8000/health every 30s and kills PID on 3 consecutive failures.
Added WATCHDOG_PID cleanup to the post-wait block.
* mastra is single-`exec next start` on the package side — no agent
process to probe, so no watchdog needed (N/A).
Reference shape: showcase/packages/crewai-crews/entrypoint.sh (unchanged
from origin/main; proven in production via PRs #4114 + #4115).
jpr5
requested review from
marthakelly,
mme,
ranst91 and
tylerslaton
as code owners
April 21, 2026 16:21
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📣 Social Copy GeneratorGenerate social media copies (Twitter/X, LinkedIn, Blog Post) for this PR using Claude.
|
3 tasks
jpr5
added a commit
that referenced
this pull request
Apr 21, 2026
…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 #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-#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 #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: #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`
jenningsloy318
pushed a commit
to JMaiGC/CopilotKit
that referenced
this pull request
Apr 21, 2026
PR CopilotKit#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 CopilotKit#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 CopilotKit#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
5 of 7 tasks
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.
4 tasks
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
zeekay
pushed a commit
to Dream-AI-4444/CopilotKit
that referenced
this pull request
Sep 11, 2026
…ross starters (CopilotKit#4116) ## Summary Generalizes the silent-hang watchdog + unbuffered-stdout shape proven in `showcase/packages/crewai-crews/entrypoint.sh` (PRs CopilotKit#4114 + CopilotKit#4115) to every Bucket-B starter, the Bucket-C spring-ai starter, the generator, and the shared starter template. **Reference shape:** `showcase/packages/crewai-crews/entrypoint.sh` on `origin/main` (unchanged in this PR; we generalize from it). **Notion proposal:** https://www.notion.so/3493aa3818528191bc08f8b2f3fb1e88 **Prior art:** CopilotKit#4114 (watchdog), CopilotKit#4115 (unbuffered stdout) ## What the watchdog does A backgrounded subshell polls the agent's health endpoint every 30s; after 3 consecutive failures (~90s), it `kill -9`s the agent so `wait -n` returns and the container runtime restarts via the normal path rather than a forced `exit` that would bypass logging. ## Per-starter coverage | Slug | Framework | Agent port | Health path | Watchdog applied | |---|---|---|---|---| | ag2 | Python / FastAPI | 8123 | `/health` | Yes | | agno | Python / FastAPI | 8123 | `/health` | Yes | | claude-sdk-python | Python / FastAPI | 8123 | `/health` | Yes | | claude-sdk-typescript | TypeScript / Express | 8123 | `/health` | Yes | | crewai-crews | Python / FastAPI | 8123 | `/health` | Yes (via regen from template; matches reference shape) | | google-adk | Python / FastAPI | 8123 | `/health` | Yes | | langgraph-fastapi | Python / langgraph_cli | 8123 | `/ok` | Yes | | langgraph-python | Python / langgraph_cli | 8123 | `/ok` | Yes | | langgraph-typescript | TS / @langchain/langgraph-cli | 8123 | `/ok` | Yes | | langroid | Python / FastAPI | 8123 | `/health` | Yes | | llamaindex | Python / FastAPI | 8123 | `/health` | Yes | | mastra | TypeScript / mastra dev | 8123 | `/api` | Yes (starter only; package side is single `exec next start` — N/A) | | ms-agent-dotnet | .NET / ASP.NET | 8123 | `/health` | Yes | | ms-agent-python | Python / FastAPI | 8123 | `/health` | Yes | | pydantic-ai | Python / FastAPI | 8123 | `/health` | Yes | | spring-ai | Java / Spring Boot | 8123 (starter) / 8000 (package) | `/health` | Yes; extends the existing 60s startup probe | | strands | Python / FastAPI | 8123 | `/health` | Yes | ## Per-package coverage (hand-applied, not regen-able) Every `showcase/packages/<slug>/entrypoint.sh` that runs a separate agent process received the watchdog + unbuffered block. Python variants also received `python -u` on their uvicorn / langgraph_cli invocations and `awk ... fflush()` log prefixing (replacing the prior `sed` pipe formulation so `$!` correctly captures the agent PID). **N/A:** `packages/mastra/entrypoint.sh` is a single `exec npx next start` — no backgrounded agent to watch. ## Generator + template changes - `showcase/scripts/generate-starters.ts` — new `getAgentHealthPath()` + `getWatchdogBlock()` helpers, plus Spring Boot `/health` 60s startup probe. - `showcase/starters/template/entrypoint.template.sh` — adds `$WATCHDOG_PID` to cleanup, injects `{{WATCHDOG_BLOCK}}`, narrows the final `wait -n` to `$AGENT_PID $NEXTJS_PID` only. ## Out of scope (not touched) - `showcase/packages/crewai-crews/entrypoint.sh` (reference shape; already correct on main). - `showcase/{shell,shell-dashboard,shell-docs}` (separate workstream). - Any agent source (Python / TS / Java / .NET). - Dependency version bumps. ## Test plan - [x] `bash -n` clean on all 32 modified `.sh` files. - [x] `pnpm -C showcase/scripts test` — 1079/1079 tests pass (includes starter-output snapshots). - [x] Watchdog marker present in every modified `packages/<slug>/entrypoint.sh` except mastra (intentional N/A). - [x] `PYTHONUNBUFFERED=1` present in every Python-based package entrypoint. - [ ] CI green before merge. - [ ] Post-merge: observe one deploy per starter on Railway to confirm watchdog doesn't false-positive against a healthy agent. ## Judgment calls (documented) - **`starters/crewai-crews/agent/{requirements.txt,agent_server.py}`**: kept as regen output. These match the current `packages/crewai-crews/` source (shimless, `ag-ui-crewai >=0.2.0`) that landed on main in commit 9379b88. Reverting would re-desync the starter from the upstream source the generator reads. - **`langgraph-typescript` packages side**: classified as Bucket B. The file on `origin/main` backgrounds `@langchain/langgraph-cli dev` on `:8123` and then `exec`s Next.js — the langgraph process can hang independently, so the watchdog applies. - **`mastra` packages side**: classified as N/A. The file on `origin/main` is a single `exec npx next start` with no backgrounded agent. - **`mastra` starter side**: Bucket B (the starter DOES run `mastra dev` on `:8123`). Watchdog probes `/api` (mastra's REST surface; no dedicated health endpoint but returns 200 once the dev server is ready).
zeekay
pushed a commit
to Dream-AI-4444/CopilotKit
that referenced
this pull request
Sep 11, 2026
PR CopilotKit#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 CopilotKit#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 CopilotKit#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
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 (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
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
Generalizes the silent-hang watchdog + unbuffered-stdout shape proven in
showcase/packages/crewai-crews/entrypoint.sh(PRs #4114 + #4115) to every Bucket-B starter, the Bucket-C spring-ai starter, the generator, and the shared starter template.Reference shape:
showcase/packages/crewai-crews/entrypoint.shonorigin/main(unchanged in this PR; we generalize from it).Notion proposal: https://www.notion.so/3493aa3818528191bc08f8b2f3fb1e88
Prior art: #4114 (watchdog), #4115 (unbuffered stdout)
What the watchdog does
A backgrounded subshell polls the agent's health endpoint every 30s; after 3 consecutive failures (~90s), it
kill -9s the agent sowait -nreturns and the container runtime restarts via the normal path rather than a forcedexitthat would bypass logging.Per-starter coverage
/health/health/health/health/health/health/ok/ok/ok/health/health/apiexec next start— N/A)/health/health/health/health/healthPer-package coverage (hand-applied, not regen-able)
Every
showcase/packages/<slug>/entrypoint.shthat runs a separate agent process received the watchdog + unbuffered block. Python variants also receivedpython -uon their uvicorn / langgraph_cli invocations andawk ... fflush()log prefixing (replacing the priorsedpipe formulation so$!correctly captures the agent PID).N/A:
packages/mastra/entrypoint.shis a singleexec npx next start— no backgrounded agent to watch.Generator + template changes
showcase/scripts/generate-starters.ts— newgetAgentHealthPath()+getWatchdogBlock()helpers, plus Spring Boot/health60s startup probe.showcase/starters/template/entrypoint.template.sh— adds$WATCHDOG_PIDto cleanup, injects{{WATCHDOG_BLOCK}}, narrows the finalwait -nto$AGENT_PID $NEXTJS_PIDonly.Out of scope (not touched)
showcase/packages/crewai-crews/entrypoint.sh(reference shape; already correct on main).showcase/{shell,shell-dashboard,shell-docs}(separate workstream).Test plan
bash -nclean on all 32 modified.shfiles.pnpm -C showcase/scripts test— 1079/1079 tests pass (includes starter-output snapshots).packages/<slug>/entrypoint.shexcept mastra (intentional N/A).PYTHONUNBUFFERED=1present in every Python-based package entrypoint.Judgment calls (documented)
starters/crewai-crews/agent/{requirements.txt,agent_server.py}: kept as regen output. These match the currentpackages/crewai-crews/source (shimless,ag-ui-crewai >=0.2.0) that landed on main in commit 9379b88. Reverting would re-desync the starter from the upstream source the generator reads.langgraph-typescriptpackages side: classified as Bucket B. The file onorigin/mainbackgrounds@langchain/langgraph-cli devon:8123and thenexecs Next.js — the langgraph process can hang independently, so the watchdog applies.mastrapackages side: classified as N/A. The file onorigin/mainis a singleexec npx next startwith no backgrounded agent.mastrastarter side: Bucket B (the starter DOES runmastra devon:8123). Watchdog probes/api(mastra's REST surface; no dedicated health endpoint but returns 200 once the dev server is ready).