Skip to content

fix: crewai-crews root-cause (ag-ui-crewai 0.2.0 + unbuffered stdout) - #4115

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

jpr5 merged 1 commit into
mainfrom
fix/crewai-crews-root-cause

Conversation

@jpr5

@jpr5 jpr5 commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

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, 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.

Test plan

  • 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).
  • Agent starts cleanly under python -u -m uvicorn agent_server:app; /health returns 200 {"status":"ok"} (verified locally).
  • 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).
  • pytest tests/python/ — 94/94 pass.
  • pnpm -C showcase/scripts test — 1079/1079 pass.
  • 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 fix: crewai-crews agent-down + smoke hang #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.

… + -u flag

Root-cause fix for the 04-21 silent-hang incident on the crewai-crews
Railway deploy. Three tightly-coupled changes:

1. Bump ag-ui-crewai pin from `>=0.1.4,<0.1.6` to `>=0.2.0,<0.3.0`.
   0.1.5 had three defects that wedged the agent: unguarded
   `source.state.messages` access, an orphan `asyncio.create_task` with
   no cancel ref, and a sync `completion()` call that pinned the event
   loop. All three are fixed in ag-ui PR #1550, released as 0.2.0 on
   2026-04-18. Our upper ceiling was blocking the fix.

2. Remove the pre-bind LLM crash hardening shim in `agent_server.py`.
   The shim monkey-patched `crewai.cli.crew_chat.generate_*_description_with_ai`
   to static strings so that `ChatWithCrewFlow.__init__` — which
   ag-ui-crewai <= 0.1.5 invoked at endpoint-registration time, BEFORE
   uvicorn bound its port — could not crash the process before the HTTP
   server was listening. 0.2.0 defers `ChatWithCrewFlow` construction to
   first request via a module-scoped `_cached_flow` + `asyncio.Lock`
   inside `add_crewai_crew_fastapi_endpoint`. Any LLM hiccup now
   surfaces as a 5xx on the first request instead of a startup crash,
   which is what the shim was reaching for. The shim is dead code on
   0.2.0 and has been removed (with `logging` import dropped as it was
   only used by the shim).

3. Add `python -u` to the uvicorn invocation in `entrypoint.sh` as a
   belt-and-suspenders complement to the existing `PYTHONUNBUFFERED=1`
   export. The env var can in principle be un-exported by a child;
   `-u` forces unbuffered stdout/stderr at the interpreter level and
   is not overridable by user code. Combined with `awk '{...; fflush()}'`
   in the pipe (already in place), this guarantees uvicorn request
   lines reach Railway's log stream line-at-a-time. During the 04-21
   incident Railway saw only ~15 log lines over 9h of uptime because
   of buffering through a previous `sed` formulation.

Also updates `showcase/scripts/fail-baseline.json`'s `validatePinsFailHash`
to match the new `ag-ui-crewai` spec string. Pin-drift FAIL count is
unchanged (110); the hash changed only because the `ag-ui-crewai` line
in the FAIL set went from `>=0.1.4,<0.1.6` to `>=0.2.0,<0.3.0`.

Verified locally:
- `pip install -r requirements.txt` resolves `ag-ui-crewai-0.2.0` cleanly.
- `python -u -m uvicorn agent_server:app` starts; `/health` returns
  200 `{"status":"ok"}`; request lines appear in real-time logs.
- `pytest tests/python/` — 94/94 pass.
- `pnpm -C showcase/scripts test` (vitest) — 1079/1079 pass.
- `validate-pins.ts` — count=110 matches baseline; hash updated.

Upstream refs:
- crewAI issue: crewAIInc/crewAI#5510
- ag-ui PR #1550: ag-ui-protocol/ag-ui#1550

Intentionally NOT in this PR:
- `showcase/starters/crewai-crews/` parity backport (the starter still
  carries the 0.1.5 pin and the shim).
- The 14-starter watchdog generalisation.
Both belong to the silent-hang vulnerability-class work tracked
separately.
@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 3:52pm
docs Ready Ready Preview, Comment Apr 21, 2026 3:52pm
form-filling Ready Ready Preview, Comment Apr 21, 2026 3:52pm
research-canvas Ready Ready Preview, Comment Apr 21, 2026 3:52pm
travel Ready Ready Preview, Comment Apr 21, 2026 3:52pm

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 db184eb into main Apr 21, 2026
14 checks passed
@jpr5
jpr5 deleted the fix/crewai-crews-root-cause branch April 21, 2026 16:03
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
## Summary

Bump the Dojo-side `ag-ui-crewai` pin to match the showcase counterpart
([#4115](#4115)) and close
the validate-pins drift.

- `examples/integrations/crewai-crews/agent/requirements.txt`:
`ag-ui-crewai>=0.1.5` → `ag-ui-crewai>=0.2.0,<0.3.0`

## Why

`ag-ui-crewai` 0.1.5 has three known defects that took down crewai-crews
in prod for 9h on 2026-04-21:

1. Unguarded `.messages` access on state
2. Orphan `asyncio.create_task` (fire-and-forget without tracking)
3. Sync `completion(` call in an async path

All three are fixed upstream in ag-ui PR
[#1550](ag-ui-protocol/ag-ui#1550), shipped as
ag-ui-crewai `0.2.0`.

Showcase already moved to `0.2.x` in
[#4115](#4115) (merged
today). Dojo is the user-facing reference repo — leaving it on `0.1.5`
means every reader clones the broken version.

## Pre-flight verification

### Pip resolve (Python 3.12 venv, `pip install --dry-run`)

Clean resolution. Picked `ag-ui-crewai-0.2.0` alongside
`ag-ui-protocol-0.1.17`, `crewai-0.130.0`, `crewai-tools-0.47.1`. No
conflicts reported.

Relevant tail of resolver output:

```
Would install ... ag-ui-crewai-0.2.0 ag-ui-protocol-0.1.17 crewai-0.130.0 crewai-tools-0.47.1 ...
```

### Consumer code audit

Grepped `examples/integrations/crewai-crews/` for any pattern matching
the 0.1.5 defect paths:

- `\.state\.messages` / `state\[.messages.\]` → no matches
- `source\.state\.messages` → no matches
- `asyncio\.create_task` → no matches
- `crewai\.completion\(` / `litellm\.completion\(` → no matches
- `messages|create_task|completion` across the whole `agent/` directory
→ no matches

The Dojo integration consists of `server.py`, `crew.py`, `main.py`,
`tools/custom_tool.py` — none of them directly access `.state.messages`,
schedule orphan tasks, or invoke sync `completion()`. The 0.2.0 bump is
purely a transitive fix; no consumer-side code changes are needed.

## Test plan

- [x] `pip install --dry-run -r
examples/integrations/crewai-crews/agent/requirements.txt` resolves
cleanly (Python 3.12)
- [x] Grep confirms no consumer code hits 0.1.5 defect paths
- [ ] validate-pins CI job goes green (drift closed against showcase)
- [ ] Basic CrewAI flow runs in the dev environment against the updated
pin

## Related

- Showcase counterpart:
[#4115](#4115)
- Upstream fix:
[ag-ui-protocol/ag-ui#1550](ag-ui-protocol/ag-ui#1550)
jenningsloy318 pushed a commit to JMaiGC/CopilotKit that referenced this pull request Apr 21, 2026
ag-ui-crewai 0.1.5 contains three defects that took down crewai-crews
in prod for 9h on 2026-04-21: unguarded .messages access, orphan
asyncio.create_task, and sync completion() calls. All three are fixed
in 0.2.0 (ag-ui PR CopilotKit#1550).

Showcase already moved to 0.2.x in PR CopilotKit#4115. Dojo is the user-facing
reference — leaving it on 0.1.5 means every reader clones the broken
version. This closes the validate-pins drift.

Pip dry-run resolves ag-ui-crewai-0.2.0 cleanly with no conflicts.
Grep of examples/integrations/crewai-crews/ confirms no consumer code
touches the 0.1.5 defect paths (.state.messages, create_task,
completion sync).
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
…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
ag-ui-crewai 0.1.5 contains three defects that took down crewai-crews
in prod for 9h on 2026-04-21: unguarded .messages access, orphan
asyncio.create_task, and sync completion() calls. All three are fixed
in 0.2.0 (ag-ui PR CopilotKit#1550).

Showcase already moved to 0.2.x in PR CopilotKit#4115. Dojo is the user-facing
reference — leaving it on 0.1.5 means every reader clones the broken
version. This closes the validate-pins drift.

Pip dry-run resolves ag-ui-crewai-0.2.0 cleanly with no conflicts.
Grep of examples/integrations/crewai-crews/ confirms no consumer code
touches the 0.1.5 defect paths (.state.messages, create_task,
completion sync).
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
…t#4122)

## Summary

Bump the Dojo-side `ag-ui-crewai` pin to match the showcase counterpart
([CopilotKit#4115](CopilotKit#4115)) and close
the validate-pins drift.

- `examples/integrations/crewai-crews/agent/requirements.txt`:
`ag-ui-crewai>=0.1.5` → `ag-ui-crewai>=0.2.0,<0.3.0`

## Why

`ag-ui-crewai` 0.1.5 has three known defects that took down crewai-crews
in prod for 9h on 2026-04-21:

1. Unguarded `.messages` access on state
2. Orphan `asyncio.create_task` (fire-and-forget without tracking)
3. Sync `completion(` call in an async path

All three are fixed upstream in ag-ui PR
[CopilotKit#1550](ag-ui-protocol/ag-ui#1550), shipped as
ag-ui-crewai `0.2.0`.

Showcase already moved to `0.2.x` in
[CopilotKit#4115](CopilotKit#4115) (merged
today). Dojo is the user-facing reference repo — leaving it on `0.1.5`
means every reader clones the broken version.

## Pre-flight verification

### Pip resolve (Python 3.12 venv, `pip install --dry-run`)

Clean resolution. Picked `ag-ui-crewai-0.2.0` alongside
`ag-ui-protocol-0.1.17`, `crewai-0.130.0`, `crewai-tools-0.47.1`. No
conflicts reported.

Relevant tail of resolver output:

```
Would install ... ag-ui-crewai-0.2.0 ag-ui-protocol-0.1.17 crewai-0.130.0 crewai-tools-0.47.1 ...
```

### Consumer code audit

Grepped `examples/integrations/crewai-crews/` for any pattern matching
the 0.1.5 defect paths:

- `\.state\.messages` / `state\[.messages.\]` → no matches
- `source\.state\.messages` → no matches
- `asyncio\.create_task` → no matches
- `crewai\.completion\(` / `litellm\.completion\(` → no matches
- `messages|create_task|completion` across the whole `agent/` directory
→ no matches

The Dojo integration consists of `server.py`, `crew.py`, `main.py`,
`tools/custom_tool.py` — none of them directly access `.state.messages`,
schedule orphan tasks, or invoke sync `completion()`. The 0.2.0 bump is
purely a transitive fix; no consumer-side code changes are needed.

## Test plan

- [x] `pip install --dry-run -r
examples/integrations/crewai-crews/agent/requirements.txt` resolves
cleanly (Python 3.12)
- [x] Grep confirms no consumer code hits 0.1.5 defect paths
- [ ] validate-pins CI job goes green (drift closed against showcase)
- [ ] Basic CrewAI flow runs in the dev environment against the updated
pin

## Related

- Showcase counterpart:
[CopilotKit#4115](CopilotKit#4115)
- Upstream fix:
[ag-ui-protocol/ag-ui#1550](ag-ui-protocol/ag-ui#1550)
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 — 9379b885 Deployed Apr 21, 2026 by vercel[bot]
Preview – travel — 9379b885 Deployed Apr 21, 2026 by vercel[bot]
Preview – docs — 9379b885 Deployed Apr 21, 2026 by vercel[bot]
Preview – form-filling — 9379b885 Deployed Apr 21, 2026 by vercel[bot]
Preview – chat-with-your-data — 9379b885 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