Skip to content

fix(showcase): prod-mode migration for mastra + claude-sdk-typescript starters - #4133

Closed
jpr5 wants to merge 4 commits into
mainfrom
fix/starter-prod-mode
Closed

jpr5 wants to merge 4 commits into
mainfrom
fix/starter-prod-mode

Conversation

@jpr5

@jpr5 jpr5 commented Apr 21, 2026

Copy link
Copy Markdown
Contributor

Summary

Why

Mirrors #4132 (langgraph-typescript). Dev-mode cold start exceeds 180s watchdog grace on Railway cold containers, producing 502 smoke test failures. Grace bumps do not fix it — the dev-time work (tsx-based compile / mastra rollup) needs to move to image build time so boot is a straight node invocation.

Per-slug opt-in lives in getAgentBuildSteps() / getAgentBuildCopy() in showcase/scripts/generate-starters.ts. Other TS starters (langgraph-typescript, etc.) get empty substitutions and their Dockerfile cache surface is unchanged.

Test plan

  • docker build --platform linux/amd64 green locally for starter-claude-sdk-typescript (tsc ~1.4s), starter-mastra (mastra build ~12.9s), and package-claude-sdk-typescript.
  • pnpm -C showcase/scripts test — 1079/1079 pass (2 tests updated to assert new prod-mode behavior).
  • pnpm -C showcase/scripts validate-pins — FAIL count held at 110, hash matches fail-baseline.json (no drift, no baseline update needed).
  • Railway deploy + smoke test green for showcase-starter-claude-sdk-typescript and showcase-starter-mastra.
  • Next deploy logs of showcase-package-claude-sdk-typescript reveal which phase consumes the 180s+ budget (pre-node / module-load / pre-Anthropic / listening timestamps).

jpr5 added 4 commits April 21, 2026 15:32
…rod-mode entry

Mirrors PR #4132's fix for langgraph-typescript. Dev-mode `npx tsx
agent/index.ts` at container boot was doing a fresh in-process TS compile
on every cold start, routinely blowing past the 180s watchdog grace on
Railway cold containers — same failure class that #4132 fixed for
langgraph-typescript.

Push the TS compile to image build time (matching flags from
showcase/packages/claude-sdk-typescript/Dockerfile so starter and package
produce equivalent runtime shapes), and run the compiled
`/app/dist/agent/index.js` at boot. Cold start is now a straight `node`
invocation.

Implementation is driven through the shared Dockerfile.typescript template
so langgraph-typescript and mastra slots stay untouched; per-slug opt-in
lives in getAgentBuildSteps() / getAgentBuildCopy() in generate-starters.ts.

Verified with `docker build --platform linux/amd64` locally — tsc compile
completes in ~1.4s at image build time.
…e entry

Mirrors PR #4132's fix for langgraph-typescript. Dev-mode `npx mastra dev`
at container boot was doing a tsx-based build on first request, routinely
blowing past the 180s watchdog grace on Railway cold containers — same
failure class that #4132 fixed for langgraph-typescript.

Push `mastra build` to image build time (bundles the Mastra server into
.mastra/output/index.mjs with its own node_modules), and run
`node /app/.mastra/output/index.mjs` at boot. Cold start is now a
straight `node` invocation.

Emitter logic lives in getAgentBuildSteps() / getAgentBuildCopy() in
generate-starters.ts alongside the sibling claude-sdk-typescript slot.

Verified with `docker build --platform linux/amd64` locally — mastra
build step completes in ~12.9s at image build time, producing a
self-contained .mastra/output/.
…entation

Package-level service claims to listen on :8000 but Railway health probes
fail. Narrow the cold-start window by timestamping each phase from
entrypoint exec to first /health-serving moment:

- entrypoint.sh: print `[entrypoint] pre-node <ISO>` immediately before
  `node /app/agent_server.js`, pairing with the agent_server.ts prints
  below to chain timestamps across the exec boundary.
- agent_server.ts: print `[agent_server] module loaded <ISO>` before any
  side-effect imports (so import-time hangs surface distinctly from
  init-time hangs), `[agent_server] pre-Anthropic <ISO>` right before
  `new Anthropic(...)`, and include an ISO timestamp in the existing
  app.listen() callback so we can read the delta directly.

No behavior change — only logs added. Next deploy cycle should reveal
which phase consumes the budget and whether the failure mode is
listen-but-unreachable vs. listen-never-reached.
PR #4132 replaced `langgraph-cli dev` with a direct
@langchain/langgraph-api server call in the package. The starter
generator copies package agent code into the starter tree, but the
starter was not regenerated at merge time. Run `pnpm -C showcase/scripts
generate-starters` to pick up:

- agent/package.json: add @langchain/langgraph-api pin (1.1.17),
  @langchain/langgraph-sdk, langchain, tsx, typescript deps; new `start`
  script invoking `node --import tsx server.mjs`
- agent/package-lock.json: regenerated to match
- agent/server.mjs: new direct server entrypoint (from the package)

Pure regen — no manual edits. Verified with `git diff` that each
file matches the equivalent file under showcase/packages/langgraph-typescript/.
@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 Building Building Preview, Comment Apr 21, 2026 10:33pm
docs Building Building Preview, Comment Apr 21, 2026 10:33pm
form-filling Building Building Preview, Comment Apr 21, 2026 10:33pm
research-canvas Building Building Preview, Comment Apr 21, 2026 10:33pm
travel Building Building Preview, Comment Apr 21, 2026 10:33pm

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 commented Apr 21, 2026

Copy link
Copy Markdown
Contributor Author

Folding into upcoming body-of-work Docker refactor PR; branch preserved locally.

@jpr5 jpr5 closed this Apr 21, 2026
jpr5 added a commit that referenced this pull request Apr 22, 2026
…ers, 17 packages (#4147)

## Summary
- Rewrite starter Dockerfile templates (`typescript`, `python`, `java`,
`dotnet`) as true multi-stage: builder has dev tools, runner is minimal.
No `pip`/`npm`/`pnpm`/`tsx`/`*-cli dev` in runtime stages.
- Encode prod-mode behaviors for `claude-sdk-typescript`, `mastra`,
`langgraph-typescript` directly in the TS template + generator
conditionals (folds in the pattern from #4132 for langgraph-ts; adds
parallel migration for claude-sdk-ts + mastra).
- Regenerate all 17 starter Dockerfiles.
- Rewrite all 17 package Dockerfiles to match the template shape
(multi-stage, venv builder for Python, 3-stage Python runtime, `USER
app`, etc.).
- Cold-start instrumentation on `claude-sdk-typescript` package
(absorbed from closed PR #4133).
- Pin `platforms: linux/amd64` in the showcase deploy workflow
(`docker/build-push-action` step) to match what Railway + GHCR require.
- Template `README.md` documenting multi-stage conventions, size target,
platform mandate, and the `dockerfile_hygiene` probe.
- `generate-starters.ts` strips the `langgraph-typescript` starter's
dead `server.mjs` + its `start` script (both reference deps only needed
in the package's prod-mode path).

## Why
Railway cold starts exceed the 180s watchdog grace when the runtime
stage boots via `langgraph-cli dev` / `npx mastra dev` / `npx tsx` — the
dev-mode work (TS compile, Rollup bundle, native libsql init) blocks the
health probe. #4132 proved the fix is to move this to image build time
for langgraph-ts. This PR generalizes that shape to all TS starters that
need it and reshapes every Dockerfile in the tree so runners no longer
carry dev toolchains.

Secondary outcomes:
- Smaller runtime images (pip/npm toolchain moved to builder only).
- Consistent `--platform linux/amd64` pinning end-to-end.
- No `pnpm install --frozen-lockfile` in the TS starter template
(starters are no-lockfile by design).
- `validate-pins` ratchet re-baselined to match the regenerated spec
strings.

## Test plan
- [ ] `docker build --platform linux/amd64` green for every starter (17)
and package (17) locally
- [ ] `pnpm -C showcase/scripts` vitest: 1085/1085 pass
- [ ] `tsc --noEmit -p showcase/scripts/tsconfig.json` clean
- [ ] `oxfmt --check` + `oxlint` clean on touched TS files
- [ ] validate-pins: count 110, hash matches updated baseline
- [ ] CI Showcase Validate green on PR HEAD
- [ ] Post-merge: showcase deploy for mastra + claude-sdk-typescript
goes green (currently flapping)
@jpr5
jpr5 deleted the fix/starter-prod-mode branch April 29, 2026 06:33
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
…ers, 17 packages (CopilotKit#4147)

## Summary
- Rewrite starter Dockerfile templates (`typescript`, `python`, `java`,
`dotnet`) as true multi-stage: builder has dev tools, runner is minimal.
No `pip`/`npm`/`pnpm`/`tsx`/`*-cli dev` in runtime stages.
- Encode prod-mode behaviors for `claude-sdk-typescript`, `mastra`,
`langgraph-typescript` directly in the TS template + generator
conditionals (folds in the pattern from CopilotKit#4132 for langgraph-ts; adds
parallel migration for claude-sdk-ts + mastra).
- Regenerate all 17 starter Dockerfiles.
- Rewrite all 17 package Dockerfiles to match the template shape
(multi-stage, venv builder for Python, 3-stage Python runtime, `USER
app`, etc.).
- Cold-start instrumentation on `claude-sdk-typescript` package
(absorbed from closed PR CopilotKit#4133).
- Pin `platforms: linux/amd64` in the showcase deploy workflow
(`docker/build-push-action` step) to match what Railway + GHCR require.
- Template `README.md` documenting multi-stage conventions, size target,
platform mandate, and the `dockerfile_hygiene` probe.
- `generate-starters.ts` strips the `langgraph-typescript` starter's
dead `server.mjs` + its `start` script (both reference deps only needed
in the package's prod-mode path).

## Why
Railway cold starts exceed the 180s watchdog grace when the runtime
stage boots via `langgraph-cli dev` / `npx mastra dev` / `npx tsx` — the
dev-mode work (TS compile, Rollup bundle, native libsql init) blocks the
health probe. CopilotKit#4132 proved the fix is to move this to image build time
for langgraph-ts. This PR generalizes that shape to all TS starters that
need it and reshapes every Dockerfile in the tree so runners no longer
carry dev toolchains.

Secondary outcomes:
- Smaller runtime images (pip/npm toolchain moved to builder only).
- Consistent `--platform linux/amd64` pinning end-to-end.
- No `pnpm install --frozen-lockfile` in the TS starter template
(starters are no-lockfile by design).
- `validate-pins` ratchet re-baselined to match the regenerated spec
strings.

## Test plan
- [ ] `docker build --platform linux/amd64` green for every starter (17)
and package (17) locally
- [ ] `pnpm -C showcase/scripts` vitest: 1085/1085 pass
- [ ] `tsc --noEmit -p showcase/scripts/tsconfig.json` clean
- [ ] `oxfmt --check` + `oxlint` clean on touched TS files
- [ ] validate-pins: count 110, hash matches updated baseline
- [ ] CI Showcase Validate green on PR HEAD
- [ ] Post-merge: showcase deploy for mastra + claude-sdk-typescript
goes green (currently flapping)

This branch was successfully deployed

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