Skip to content

fix(showcase): extend watchdog grace to claude-sdk-typescript and mastra - #4124

Merged
jpr5 merged 2 commits into
mainfrom
fix/watchdog-grace-expand
Apr 21, 2026
Merged

jpr5 merged 2 commits into
mainfrom
fix/watchdog-grace-expand

Conversation

@jpr5

@jpr5 jpr5 commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

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

  • bash -n clean on all 3 modified .sh files
  • pnpm -C showcase/scripts test — 1079/1079 pass
  • npx tsc --noEmit in showcase/scripts — clean
  • npx tsx generate-starters.ts is idempotent after the regen
    commit (no further diff)
  • 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

jpr5 added 2 commits April 21, 2026 11:47
…mastra

Two more starters are restart-looping with the same pattern #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 #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 #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 #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.
Regenerated via `cd showcase/scripts && npx tsx generate-starters.ts`
after the getWatchdogGraceSeconds() mapping update in the previous
commit. Only these two starters change — every other framework still
returns 0s from the grace mapping, so their entrypoints are byte-for-
byte identical to main.
@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 6:51pm
docs Ready Ready Preview, Comment Apr 21, 2026 6:51pm
form-filling Ready Ready Preview, Comment Apr 21, 2026 6:51pm
research-canvas Ready Ready Preview, Comment Apr 21, 2026 6:51pm
travel Ready Ready Preview, Comment Apr 21, 2026 6:51pm

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

📣 Social Copy Generator

Generate social media copies (Twitter/X, LinkedIn, Blog Post) for this PR using Claude.

  • Generate social media copies

@jpr5
jpr5 merged commit 2023340 into main Apr 21, 2026
15 checks passed
@jpr5
jpr5 deleted the fix/watchdog-grace-expand branch April 21, 2026 19:19
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 — ed451351 Deployed Apr 21, 2026 by vercel[bot]
Preview – travel — ed451351 Deployed Apr 21, 2026 by vercel[bot]
Preview – docs — ed451351 Deployed Apr 21, 2026 by vercel[bot]
Preview – chat-with-your-data — ed451351 Deployed Apr 21, 2026 by vercel[bot]
Preview – form-filling — ed451351 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