Skip to content

fix: crewai-crews agent-down + smoke hang - #4114

Merged
jpr5 merged 1 commit into
mainfrom
fix/crewai-crews-agent-down
Apr 21, 2026
Merged

jpr5 merged 1 commit into
mainfrom
fix/crewai-crews-agent-down

Conversation

@jpr5

@jpr5 jpr5 commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Production showcase-crewai-crews was stuck at agent:"down" for ~4-5h on 2026-04-21 (retries #1-8, 503 on /api/health, 30s+ hang on /api/smoke). Railway runtime logs show the FastAPI agent on :8000 handled startup and hundreds of requests cleanly, then silently stopped responding at ~06:56-07:01 UTC after an unhandledRejection: UND_ERR_BODY_TIMEOUT. The Python process did not exit — it hung — so bash's wait -n never fired, the container never restarted, and every subsequent runtime-to-agent request waited out undici's default 5-minute headers timeout (UND_ERR_HEADERS_TIMEOUT in the logs).

Two defensive fixes in the package:

  1. entrypoint.sh — agent watchdog. Poll http://127.0.0.1:8000/health every 30s (5s curl --max-time). After 3 consecutive failures (~90s unreachable), SIGKILL the agent PID so wait -n returns and Railway restarts the container. Also adds [entrypoint] / [agent] / [nextjs] / [watchdog] log prefixes, a startup PID-is-alive check, and PYTHONUNBUFFERED=1 — bringing this package's entrypoint closer to the starter's richer template.

  2. src/app/api/smoke/route.ts — split inner/outer timeouts. UPSTREAM_TIMEOUT_MS = 25_000 on the inner fetch, keeping maxDuration = 60 as the route budget. Previously the single AbortSignal.timeout(45000) on the upstream fetch, when the agent hung, consumed nearly all the 60s envelope before Next.js cut the request — producing HTTP 000 at the caller. Now a wedged agent surfaces as a structured stage: "timeout" JSON response in ~25s.

Upstream showcase-crewai-crews-production.up.railway.app verified RED (503, agent:down) via curl before this PR. Merge will trigger GHCR build + Railway redeploy; recovery expected within ~4 min of deploy.

Test plan

  • Railway deploys latest image after merge; container boots healthy
  • curl https://showcase-crewai-crews-production.up.railway.app/api/health returns 200 agent:"ok"
  • curl https://showcase-crewai-crews-production.up.railway.app/api/smoke returns 200 within ~25s (or 502 stage:"timeout" if aimock glitches)
  • Logs show [entrypoint] / [agent] / [watchdog] prefixes (evidence the new entrypoint is active)
  • Induce hang by sending a malformed agent request; verify watchdog kicks in after ~90s (visible in logs as [watchdog] Agent health probe failed + container restart)
  • Starter service (showcase-starter-crewai-crews) unaffected — only the package entrypoint/smoke route changed

…pstream timeout

Production deploy of showcase-crewai-crews was stuck in agent:"down" for
~4-5h on 2026-04-21. Railway deployment logs show the FastAPI agent on
:8000 was reachable at startup and handled hundreds of requests, then
stopped responding at ~06:56-07:01 UTC after an
unhandledRejection: UND_ERR_BODY_TIMEOUT from the Next.js runtime. The
Python process did not exit — it hung — so bash's wait -n never fired,
the container never restarted, and every subsequent request stacked up
on undici's default 5-minute headers timeout (UND_ERR_HEADERS_TIMEOUT).

Two surgical fixes:

1. entrypoint.sh: add a watchdog goroutine that polls
   http://127.0.0.1:8000/health every 30s with a 5s curl timeout. After
   3 consecutive failures (~90s unreachable) it SIGKILLs the agent PID,
   causing wait -n to return and the container to restart. This converts
   a silent agent hang into a fast, loggable restart. Also adds structured
   [entrypoint] / [agent] / [nextjs] / [watchdog] log prefixes, a startup
   PID-is-alive check, and PYTHONUNBUFFERED=1 so crashes surface before
   the log pipe closes — mirroring the starter entrypoint pattern.

2. src/app/api/smoke/route.ts: split the upstream fetch timeout
   (UPSTREAM_TIMEOUT_MS = 25_000) from the route's overall budget
   (maxDuration = 60). Previously the inner fetch had AbortSignal.timeout(45000)
   which, on a hung agent, burned nearly all of the 60s before Next.js
   killed the request — producing HTTP 000 at the caller instead of a
   structured stage: "timeout" JSON response. With the shorter inner
   timeout the route can report a clean timeout within ~25s even when
   the agent is wedged.

Both fixes are defensive against upstream CrewAI ChatWithCrewFlow
deadlocks (which the logs show happening repeatedly via the pre-existing
"Cannot send 'RUN_FINISHED' while steps are still active" errors). The
watchdog is scoped to this package only; the starter already has a
richer entrypoint with similar intent.
@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 0:42am
docs Ready Ready Preview, Comment Apr 21, 2026 0:42am
form-filling Ready Ready Preview, Comment Apr 21, 2026 0:42am
research-canvas Ready Ready Preview, Comment Apr 21, 2026 0:42am
travel Ready Ready Preview, Comment Apr 21, 2026 0:42am

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 602868f into main Apr 21, 2026
14 checks passed
@jpr5
jpr5 deleted the fix/crewai-crews-agent-down branch April 21, 2026 14:22
jpr5 added a commit that referenced this pull request Apr 21, 2026
…#4115)

## Summary
- Bump `ag-ui-crewai` pin to `>=0.2.0,<0.3.0`. 0.1.5 had three defects
(unguarded `source.state.messages`, orphan `asyncio.create_task`, sync
`completion()`) that wedged the agent on 2026-04-21. All fixed in ag-ui
[PR #1550](ag-ui-protocol/ag-ui#1550), released
as 0.2.0 on 2026-04-18 — our pin was blocking it.
- Remove the pre-bind monkey-patch shim in `src/agent_server.py`;
superseded by 0.2.0's native deferred `ChatWithCrewFlow` construction
(module-scoped `_cached_flow` + `asyncio.Lock` inside
`add_crewai_crew_fastapi_endpoint`). Any LLM hiccup now surfaces as a
5xx on first request instead of a startup crash, which is exactly what
the shim was reaching for. `logging` import dropped since it was only
used by the shim.
- Add `python -u` to the uvicorn invocation in `entrypoint.sh` as a
belt-and-suspenders complement to the existing `PYTHONUNBUFFERED=1`.
`awk '{...; fflush()}'` in the pipe was already line-flushing; `-u` is
not overridable by user code. Railway saw only ~15 log lines over 9h
during the 04-21 incident because of pipe-buffering through a previous
`sed` formulation.
- Update `showcase/scripts/fail-baseline.json`'s `validatePinsFailHash`
to match the new `ag-ui-crewai` spec string in the FAIL set. Pin-drift
FAIL count is unchanged (110); only the hashed line text changed.

Root-cause context: Notion [Showcase starters: silent-hang vulnerability
class](https://www.notion.so/3493aa3818528191bc08f8b2f3fb1e88).

## Test plan
- [x] `pip install -r requirements.txt` resolves `ag-ui-crewai==0.2.0`
(verified locally in a fresh 3.12 venv; no dep conflicts with
`crewai==0.130.0` or `crewai-tools`).
- [x] Agent starts cleanly under `python -u -m uvicorn
agent_server:app`; `/health` returns 200 `{"status":"ok"}` (verified
locally).
- [x] Agent import no longer references the `crewai.cli.crew_chat`
hardening shim; `ag_ui_crewai.endpoint.add_crewai_crew_fastapi_endpoint`
registers without pre-bind LLM calls (verified via FastAPI route
inspection after import).
- [x] `pytest tests/python/` — 94/94 pass.
- [x] `pnpm -C showcase/scripts test` — 1079/1079 pass.
- [x] `validate-pins.ts` — FAIL count matches baseline (110); new hash
committed to `fail-baseline.json`.
- [ ] `/api/smoke` completes against live upstream on Railway (requires
deploy).
- [ ] Railway deploy logs show uvicorn request lines (not just
entrypoint banner).
- [ ] Watchdog from #4114 still loops.

## Intentionally out-of-scope (follow-ups)
- `showcase/starters/crewai-crews/` parity backport (starter still
carries the 0.1.5 pin and the shim).
- The 14-starter watchdog generalisation — tracked in the Notion
proposal above.
jpr5 added a commit that referenced this pull request Apr 21, 2026
…ross starters (#4116)

## 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.sh` on
`origin/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 -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).
pull Bot pushed a commit to mexicanamerican/CopilotKit that referenced this pull request Apr 21, 2026
…caffolding to generator + template

Generalize the watchdog shape proven in showcase/packages/crewai-crews/entrypoint.sh
(PRs CopilotKit#4114 + CopilotKit#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.
pull Bot pushed a commit to mexicanamerican/CopilotKit that referenced this pull request Apr 21, 2026
… 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 CopilotKit#4114 + CopilotKit#4115).
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
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
## Summary

Production `showcase-crewai-crews` was stuck at `agent:"down"` for ~4-5h
on 2026-04-21 (retries CopilotKit#1-8, 503 on `/api/health`, 30s+ hang on
`/api/smoke`). Railway runtime logs show the FastAPI agent on `:8000`
handled startup and hundreds of requests cleanly, then silently
**stopped responding** at ~06:56-07:01 UTC after an `unhandledRejection:
UND_ERR_BODY_TIMEOUT`. The Python process did not exit — it hung — so
bash's `wait -n` never fired, the container never restarted, and every
subsequent runtime-to-agent request waited out undici's default 5-minute
headers timeout (`UND_ERR_HEADERS_TIMEOUT` in the logs).

Two defensive fixes in the package:

1. **`entrypoint.sh` — agent watchdog.** Poll
`http://127.0.0.1:8000/health` every 30s (5s `curl --max-time`). After 3
consecutive failures (~90s unreachable), SIGKILL the agent PID so `wait
-n` returns and Railway restarts the container. Also adds `[entrypoint]`
/ `[agent]` / `[nextjs]` / `[watchdog]` log prefixes, a startup
PID-is-alive check, and `PYTHONUNBUFFERED=1` — bringing this package's
entrypoint closer to the starter's richer template.

2. **`src/app/api/smoke/route.ts` — split inner/outer timeouts.**
`UPSTREAM_TIMEOUT_MS = 25_000` on the inner fetch, keeping `maxDuration
= 60` as the route budget. Previously the single
`AbortSignal.timeout(45000)` on the upstream fetch, when the agent hung,
consumed nearly all the 60s envelope before Next.js cut the request —
producing HTTP 000 at the caller. Now a wedged agent surfaces as a
structured `stage: "timeout"` JSON response in ~25s.

Upstream `showcase-crewai-crews-production.up.railway.app` verified RED
(503, agent:down) via `curl` before this PR. Merge will trigger GHCR
build + Railway redeploy; recovery expected within ~4 min of deploy.

## Test plan

- [ ] Railway deploys latest image after merge; container boots healthy
- [ ] `curl
https://showcase-crewai-crews-production.up.railway.app/api/health`
returns 200 `agent:"ok"`
- [ ] `curl
https://showcase-crewai-crews-production.up.railway.app/api/smoke`
returns 200 within ~25s (or 502 `stage:"timeout"` if aimock glitches)
- [ ] Logs show `[entrypoint]` / `[agent]` / `[watchdog]` prefixes
(evidence the new entrypoint is active)
- [ ] Induce hang by sending a malformed agent request; verify watchdog
kicks in after ~90s (visible in logs as `[watchdog] Agent health probe
failed` + container restart)
- [ ] Starter service (`showcase-starter-crewai-crews`) unaffected —
only the package entrypoint/smoke route changed
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
…CopilotKit#4115)

## Summary
- Bump `ag-ui-crewai` pin to `>=0.2.0,<0.3.0`. 0.1.5 had three defects
(unguarded `source.state.messages`, orphan `asyncio.create_task`, sync
`completion()`) that wedged the agent on 2026-04-21. All fixed in ag-ui
[PR CopilotKit#1550](ag-ui-protocol/ag-ui#1550), released
as 0.2.0 on 2026-04-18 — our pin was blocking it.
- Remove the pre-bind monkey-patch shim in `src/agent_server.py`;
superseded by 0.2.0's native deferred `ChatWithCrewFlow` construction
(module-scoped `_cached_flow` + `asyncio.Lock` inside
`add_crewai_crew_fastapi_endpoint`). Any LLM hiccup now surfaces as a
5xx on first request instead of a startup crash, which is exactly what
the shim was reaching for. `logging` import dropped since it was only
used by the shim.
- Add `python -u` to the uvicorn invocation in `entrypoint.sh` as a
belt-and-suspenders complement to the existing `PYTHONUNBUFFERED=1`.
`awk '{...; fflush()}'` in the pipe was already line-flushing; `-u` is
not overridable by user code. Railway saw only ~15 log lines over 9h
during the 04-21 incident because of pipe-buffering through a previous
`sed` formulation.
- Update `showcase/scripts/fail-baseline.json`'s `validatePinsFailHash`
to match the new `ag-ui-crewai` spec string in the FAIL set. Pin-drift
FAIL count is unchanged (110); only the hashed line text changed.

Root-cause context: Notion [Showcase starters: silent-hang vulnerability
class](https://www.notion.so/3493aa3818528191bc08f8b2f3fb1e88).

## Test plan
- [x] `pip install -r requirements.txt` resolves `ag-ui-crewai==0.2.0`
(verified locally in a fresh 3.12 venv; no dep conflicts with
`crewai==0.130.0` or `crewai-tools`).
- [x] Agent starts cleanly under `python -u -m uvicorn
agent_server:app`; `/health` returns 200 `{"status":"ok"}` (verified
locally).
- [x] Agent import no longer references the `crewai.cli.crew_chat`
hardening shim; `ag_ui_crewai.endpoint.add_crewai_crew_fastapi_endpoint`
registers without pre-bind LLM calls (verified via FastAPI route
inspection after import).
- [x] `pytest tests/python/` — 94/94 pass.
- [x] `pnpm -C showcase/scripts test` — 1079/1079 pass.
- [x] `validate-pins.ts` — FAIL count matches baseline (110); new hash
committed to `fail-baseline.json`.
- [ ] `/api/smoke` completes against live upstream on Railway (requires
deploy).
- [ ] Railway deploy logs show uvicorn request lines (not just
entrypoint banner).
- [ ] Watchdog from CopilotKit#4114 still loops.

## Intentionally out-of-scope (follow-ups)
- `showcase/starters/crewai-crews/` parity backport (starter still
carries the 0.1.5 pin and the shim).
- The 14-starter watchdog generalisation — tracked in the Notion
proposal above.
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
…caffolding to generator + template

Generalize the watchdog shape proven in showcase/packages/crewai-crews/entrypoint.sh
(PRs CopilotKit#4114 + CopilotKit#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.
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
… 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 CopilotKit#4114 + CopilotKit#4115).
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
…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

This branch was successfully deployed

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