Commit Graph

77 Commits

Author SHA1 Message Date
Jordan Ritter 40adafd199 fix(showcase/scripts/generate-starters): strip langgraph-ts starter start script referencing deleted server.mjs 2026-04-21 19:38:29 -07:00
Jordan Ritter 7971aafe53 docs(showcase/template): correct Node and Temurin version references in README
Template actually pins node:22-slim for both builder and runner stages,
and eclipse-temurin:21-jre (not -jre-alpine) for spring-ai runner. README
called out node:24 + temurin:21-jre-alpine. Align docs with reality.
Node 24 bump is a separate decision not made in this body of work.
2026-04-21 19:05:50 -07:00
Jordan Ritter 400fe8a1ae fix(showcase/starters): regenerate after generator fixes (watchdog cleanup + tsc rootDir + strip langgraph-ts server.mjs)
Mechanical regen; no hand edits. Changes:
- All 17 entrypoint.sh: add '|| true' to cleanup kill (trap + final)
- claude-sdk-typescript Dockerfile: tsc now passes --rootDir .
- langgraph-typescript/agent: remove server.mjs + prune its transitive
  deps from package-lock.json
2026-04-21 19:01:30 -07:00
Jordan Ritter c6437b3443 fix(showcase/scripts/generate-starters): emit || true on watchdog cleanup kill, preserve --rootDir ., strip dead langgraph-ts server.mjs, guard AGENT_DIR expansion
- entrypoint.template.sh: cleanup trap + final kill now tolerate no-match
  (|| true) so trap doesn't abort shell when one of the three PIDs has
  already exited. Package-level entrypoint.sh already had this shape.
- generate-starters.ts: claude-sdk-typescript tsc now uses --rootDir .
  so emitted artifact is /app/dist/agent/index.js (matches entrypoint
  expectation + runner-stage COPY). tsc was inferring agent/ as rootDir
  and stripping the prefix.
- generate-starters.ts: drop server.mjs from langgraph-typescript starter
  output. The starter uses 'npx @langchain/langgraph-cli dev' and never
  invokes server.mjs; the file imports @langchain/langgraph-api/server
  which is not in the starter's extraDependencies (resolution relied on
  transitive hoist via @langchain/langgraph-cli). The file stays in the
  PACKAGE where prod mode does use it.
- generate-starters.ts: assert agentDir non-empty / non-absolute before
  Dockerfile substitution so the 'rm -f {{AGENT_DIR}}/package*.json' line
  can never degrade into 'rm -f /package*.json' across /app.
2026-04-21 19:01:10 -07:00
Jordan Ritter 5ab3a81468 chore(showcase/starter-langgraph-typescript): sync package-lock.json after prod-mode deps 2026-04-21 18:44:03 -07:00
Jordan Ritter bff45416e7 docs(showcase): document multi-stage Dockerfile conventions
Add showcase/starters/template/README.md covering the multi-stage build
convention (builder + runtime split), the >=40% image-size reduction
target, the linux/amd64 platform requirement for local builds, and the
dockerfile_hygiene probe rules (>=2 FROM stages, no dev-dep installs in
the runtime stage).

Expand the header comment on showcase/scripts/generate-starters.ts to
document the >=40% size target, the getAgentBuildSteps/getAgentBuildCopy
handoff in more detail, and the linux/amd64 platform pin in the deploy
workflow.
2026-04-21 18:41:48 -07:00
Jordan Ritter dc49520513 feat(showcase/starters): regenerate 17 starter Dockerfiles for multi-stage builds 2026-04-21 18:14:00 -07:00
Jordan Ritter a32d5752d4 feat(showcase/template): true multi-stage Dockerfile templates with prod-mode tokens
Restructure the shared starter Dockerfile templates so the runtime stage
ships only a minimal base plus built artifacts — no dev toolchains (pip,
pnpm, tsx, *-cli dev) run in the runner stage.

Dockerfile.typescript:
- Add AGENT_BUILD_STEPS / AGENT_BUILD_COPY template tokens so per-slug
  prod-mode compiles (claude-sdk-typescript tsc, mastra `mastra build`)
  can be emitted by the generator. Mirrors PR #4132's langgraph-typescript
  fix for the rest of the TS starter slots — cold start becomes a straight
  `node` call instead of `npx tsx` / `npx mastra dev` on Railway.

Dockerfile.python:
- Split pip install into a dedicated agent-builder stage that carries
  full `python:3.12` (with compilers + dev headers needed for wheels
  that don't ship pre-built for -slim), and produces a self-contained
  /opt/venv. The runner then COPYs /opt/venv as a single opaque tree —
  no pip, no build tools in the final image.

Dockerfile.java and Dockerfile.dotnet already implement the true
multi-stage shape (temurin-21 JDK / dotnet-9 SDK builder + JRE / aspnet
runtime); no structural changes needed.

Regenerating the 17 starter Dockerfiles happens in the next commit
block — this commit is template-authoring only.
2026-04-21 17:20:33 -07:00
Jordan Ritter ed45135100 chore(showcase): regenerate claude-sdk-typescript + mastra starters
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.
2026-04-21 11:48:02 -07:00
Jordan Ritter f5b7a65b3d fix(showcase): langgraph watchdog regression — add startup grace period
PR #4116 introduced a generalized silent-hang watchdog that polls the
agent health endpoint every 30s and kills the agent after 3 consecutive
failures (~90s). This worked for fast-starting agents (uvicorn,
express) but regressed langgraph-typescript on Railway: `langgraph-cli
dev` does a heavy cold-start (Studio IPC setup + @langchain/langgraph-api
JIT spawn + graph compile) that routinely exceeds 90s on a fresh
container, so the watchdog was killing the process before /ok ever
became reachable — producing the 04-20 17:05 UTC restart loop on
deployment 58bbebe8-7a94-4f99-b6e4-ffcbb4eb78b9.

Phase 1 verification:
  - `@langchain/langgraph-cli@1.1.17/dist/cli/up.mjs:27` uses /ok as
    its own health probe, and `@langchain/langgraph-api@1.1.17/dist/
    api/meta.mjs:64` registers `api.get("/ok", ...)` — so the watchdog
    path is correct. The regression is purely timing.
  - Railway logs show no successful /ok probe before kill-loop starts.

Fix (Option B — startup grace): add a per-framework startup-grace
window in getWatchdogGraceSeconds(). For langgraph-* starters, the
watchdog now waits up to 180s for the first healthy /ok probe before
arming the strike counter. If /ok comes up sooner, fall through
immediately. If 180s elapses without success, arm the counter anyway —
the steady-state watchdog will then handle a true hang on the normal
90s schedule.

Non-langgraph starters (crewai-crews, ag2, agno, etc.) have grace=0 and
behave exactly as before PR #4116 — the 2–3s `sleep` before the health
check is sufficient for uvicorn-based agents.

Files changed:
  - showcase/scripts/generate-starters.ts — new getWatchdogGraceSeconds()
    + grace block in getWatchdogBlock()
  - showcase/starters/*/entrypoint.sh — regenerated (grace block for
    langgraph-*, comment-only for all others)
  - showcase/packages/langgraph-typescript/entrypoint.sh — hand-edited
    grace block (this package uses its own hand-edited entrypoint, not
    the template)
  - showcase/packages/langgraph-fastapi/entrypoint.sh — same
  - showcase/packages/langgraph-python/entrypoint.sh — same

Not a revert of #4116: the silent-hang vulnerability class remains
covered (the watchdog still kills after 90s of steady-state failures;
the grace only defers the first strike).

Validated:
  - bash -n on all 19 edited entrypoint.sh files
  - 1079/1079 showcase-scripts vitest pass
2026-04-21 10:48:07 -07:00
Jordan Ritter c17914d480 fix(showcase/starters): regenerate entrypoints + crewai-crews content from upgraded generator
Regenerates all 16 starter entrypoint.sh files from the new template. Every
starter now ships:
  - $WATCHDOG_PID tracked in cleanup + kill block
  - PYTHONUNBUFFERED=1 export (harmless for Java/Node/.NET)
  - Explicit `wait -n $AGENT_PID $NEXTJS_PID` (excludes the watchdog so its
    exit doesn't short-circuit the agent's true status)
  - Per-framework health probe (see prior commit for path matrix)

Also reflects the crewai-crews root-cause fix (already on origin/main via
commit 9379b8855): ag-ui-crewai >=0.2.0 bump and drop of the crewai.cli
monkey-patch shim. These files are regenerated from showcase/packages/
crewai-crews source.
2026-04-21 09:20:50 -07:00
Jordan Ritter de3db5e72e fix(showcase/scripts): add silent-hang watchdog + unbuffered-stdout scaffolding to generator + template
Generalize the watchdog shape proven in showcase/packages/crewai-crews/entrypoint.sh
(PRs #4114 + #4115) so that every Bucket-B starter gets:
  - PYTHONUNBUFFERED=1 export (harmless for non-Python frameworks)
  - A backgrounded watchdog subshell that polls the agent health endpoint
    every 30s and kills the agent after 3 consecutive failures, letting
    wait -n + container runtime handle the restart through the normal path.
  - python -u on uvicorn / langgraph_cli invocations (Python frameworks).
  - awk ... fflush() log prefixing (replaces the previous sed pipe; keeps $!
    pointing at the real agent process).

Per-framework agent health paths:
  * FastAPI / uvicorn agents                                     -> /health
  * langgraph-python, langgraph-fastapi, langgraph-typescript    -> /ok
  * claude-sdk-typescript, ms-agent-dotnet, spring-ai            -> /health
  * mastra                                                        -> /api

Spring Boot starter also gets a 60s /health startup probe (replacing the
blind sleep 5) because JVM warmup + context refresh can exceed 30s.
2026-04-21 09:20:36 -07:00
Jordan Ritter 82e9769f5c fix(showcase/starters/langroid): restore /api/health 200 by dropping sed log-prefix wrappers and gating Next.js on agent readiness
Production showcase-starter-langroid returns ``{"status":"degraded","agent":"down"}`` HTTP 503
at ``/api/health`` — the exact path the showcase-deploy workflow's ``ALL_SERVICES.health_path``
verify step asserts, so the next CI redeploy of this starter would fail verification.

Root cause: two compounding bugs in ``showcase/starters/langroid/entrypoint.sh``.

1. Process-substitution log prefixers suppressed stdout. Both backgrounded
   services were wrapped with ``> >(sed 's/^/[agent] /') 2>&1 &`` /
   ``> >(sed 's/^/[nextjs] /') 2>&1 &``. In Railway's V2 runtime this shape
   reliably produced ZERO ``[agent]``/``[nextjs]`` log lines (confirmed against
   several weeks of Railway logs for this service) and correlated with
   agent-unreachable 503s at ``/api/health``. The package entrypoint
   (``showcase/packages/langroid/entrypoint.sh``) uses the plain-``&`` pattern
   with no wrapper, stays green on the same Railway runtime, and shows full
   uvicorn ``INFO:`` startup logs including ``127.0.0.1:...  "GET /health
   HTTP/1.1" 200 OK`` from Next.js's fetch. Match the working package pattern.

2. Cold-start race amplified by ``sleepApplication=true``. Railway sleeps
   idle services. On wake, Next.js is ready in <1s but Python + langroid
   imports take 10-20s. Without a readiness gate, Next.js answered the first
   post-wake ``/api/health`` probe with ``agent:"down"`` before uvicorn had
   bound port 8123. The deploy workflow's verify step then saw the 503 and
   reported the deploy as unhealthy. Add a 30s readiness probe that curls
   ``http://127.0.0.1:8123/health`` in a loop before starting Next.js. The
   IPv4 literal (``127.0.0.1`` not ``localhost``) is load-bearing — Node
   22+'s fetch resolves ``localhost`` to IPv6 ``::1`` first, and uvicorn
   binds IPv4 only; the readiness probe must not false-negative on resolver
   semantics alone.

Also export ``PYTHONUNBUFFERED=1`` so Python import-time tracebacks (e.g.
langroid module-load failures) reach the container log immediately instead
of sitting in userspace buffers until process exit closes them off.

Verification:
- Built langroid starter image locally from this branch. ``/api/health``
  returns 200 with ``{"status":"ok","agent":"ok"}``. Full uvicorn INFO
  logs visible including ``127.0.0.1:xxxxx - "GET /health HTTP/1.1"
  200 OK`` confirming Next.js -> agent path works.
- Readiness probe fires before Next.js launch: ``[entrypoint] Agent
  /health ready after 3s``.
- New regression guards in ``starter-consistency.test.ts`` cover all four
  invariants (no sed wrapping around uvicorn, no sed wrapping around next
  start, ``PYTHONUNBUFFERED=1`` export, readiness probe on 127.0.0.1:8123
  before ``next start``). Verified red→green (reverted entrypoint -> 4
  fails; restored -> 4 pass). Full showcase/scripts suite: 1079/1079 pass.
2026-04-20 13:53:08 -07:00
Atai Barkai 7644f180a6 fix(showcase): restore shared-state-read-write scaffolds + regen starters
Post-merge CI caught two regressions:

1. shared-state-read-write demo directories were on disk but never
   committed — 16 packages' manifests reference the demo but the
   page.tsx scaffolds weren't tracked. This failed validate-parity,
   bundle-demo-content tests, and drift-check transitively.

2. langgraph-python starter templates drifted after main added
   docstring region markers to weather-tool-backend; regenerating
   via `npx tsx generate-starters.ts` syncs the 17 starters.

Bundle (showcase/shell/src/data/demo-content.json) regenerated to
pick up the new demo content.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 21:34:13 -07:00
Atai Barkai a1ed347faa Merge remote-tracking branch 'origin/main' into atai/2026-04-18/feature-port-no-docker-restructure
# Conflicts:
#	showcase/scripts/__tests__/bundle-demo-content.test.ts
#	showcase/scripts/lib/manifest.ts
#	showcase/scripts/validate-parity.ts
2026-04-19 16:40:48 -07:00
Atai Barkai 41fe1eb2e6 feat(showcase/langgraph-python): add hitl-in-app cell — async frontend-tool HITL with in-app popup
Introduces the "In-App Human in the Loop" cell, demonstrating the
canonical async useFrontendTool HITL pattern where the approval UI
lives OUTSIDE the chat surface.

Flow:
- Agent calls `request_user_approval` (frontend-registered)
- The async handler returns a Promise and stashes its `resolve` in
  component state
- An app-level modal dialog (portal'd to <body>, grid-sibling of
  CopilotChat — NOT inside the chat bubble tree) opens with the
  agent's message + optional context
- User clicks Approve / Reject (with optional note) → completion
  callback fires `resolve({ approved, reason })`
- Handler returns the value to the agent, which continues based on
  approval outcome

Files:
- src/agents/hitl_in_app.py — support-ops agent with tools=[] and a
  system prompt that requires calling `request_user_approval` before
  any customer-affecting action
- src/app/demos/hitl-in-app/page.tsx — layout (support-inbox panel +
  CopilotChat + app-level modal), frontend-tool registration,
  resolve-capture pattern, suggestions
- src/app/demos/hitl-in-app/approval-dialog.tsx — modal (createPortal
  to document.body) with Approve/Reject + optional reason textarea
- langgraph.json — register `hitl_in_app` graph

Starter mirror auto-generated.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-19 15:56:21 -07:00
Jordan Ritter 55b1445f9d chore(showcase/starters): regenerate to pick up #4101 tool-import + entrypoint fixes
PR #4101 updated both the resolution-aware import rewriter and the
entrypoint `$!` -> agent PID fix, but the regeneration in the merged
commit didn't include all affected files. `origin/main` at 2087950ee
still contained:

- langgraph-fastapi + langgraph-python: `src/agents/tools/*.py` importing
  `from src.agents.types`, `from src.agents.get_weather`, etc. — the
  old flat-rewrite output, which crashes with
  `ModuleNotFoundError: No module named 'src.agents.types'` at agent
  import time. langgraph-fastapi on Railway was failing its health probe
  with `agent: down` for this reason.
- All 15 generated entrypoint.sh files still had the old
  `2>&1 | sed 's/^/[agent] /' &` pattern, meaning `$!` pointed at `sed`
  instead of the agent subprocess. Every `kill -0 $AGENT_PID` /
  `wait -n` check was monitoring the wrong process, and Python crash
  output was also line-buffered inside the pipe so tracebacks never hit
  the container log.

Re-running `pnpm -C showcase/scripts generate-starters` with #4101's
resolution-aware rewriter produces the correct `src.agents.tools.*`
imports for both langgraph starters and the intended
`&> >(awk '{print "[agent] " $0; fflush()}')` process-substitution form
for every entrypoint.sh. No generator changes — purely regenerated
output catching up to the script that's already on main.
2026-04-19 12:59:49 -07:00
Jordan Ritter 2087950eea fix(showcase/starters): restore langgraph-{fastapi,typescript} agent subprocess (#4101)
## Summary

After #4099 both `starter-langgraph-fastapi` and
`starter-langgraph-typescript` returned `/api/health` =
`{"status":"degraded","agent":"down"}` on Railway. Three interlocking
regressions in `generate-starters.ts`:

- **Import rewrite was flat, not resolution-aware.** langgraph-fastapi's
`agent.py` lives at `<agentDir>/src/agent.py` and imports `.tools`, but
`tools/` lives at `<agentDir>/tools/` (one level up). Both the flat
`<agentDir>.tools` rewrite and the file-dir-based `<agentDir>.src.tools`
rewrite pointed at nonexistent paths. langgraph_cli crashed with
`ModuleNotFoundError: No module named 'src.agents.src.tools'` before
binding 8123.
- **langgraph-typescript root `package.json` missing agent deps.** The
TS Dockerfile deletes `agent/package.json` to collapse the ESM package
boundary, but there was no mechanism to lift the agent's runtime deps
(`@langchain/openai` et al.) into the root `package.json`. `npx
@langchain/langgraph-cli dev` died with `Cannot find module
'@langchain/openai'`.
- **`AGENT_LOG_PREFIX` was accidentally reverted** to `cmd 2>&1 | sed
…`. After a pipeline `$!` points at `sed`, so `kill -0 $AGENT_PID` /
`wait -n $AGENT_PID` monitor the prefixer, not the agent. `sed` also
line-buffers so crash output can be lost.

Fix all three in the generator and regenerate the two affected starters.
Committed starter entrypoint.sh files across the fleet are already on
`awk &> >(…)` (they were regenerated at some earlier point) — this PR
re-aligns the generator with their committed state, so future regens
stay consistent.

## Verification

- `docker build` + `docker run` on both starters locally:
- fastapi:
`{"status":"ok","integration":"langgraph-fastapi","agent":"ok"}`
- typescript:
`{"status":"ok","integration":"langgraph-typescript","agent":"ok"}`
- `entrypoint` logs show `Agent server started (PID: N)` with N
belonging to the agent, not an awk/sed prefixer.
- `pnpm test` in `showcase/scripts/`: 1075/1075 pass.
- `tsc --noEmit` on the generator: clean.
- No changes to `langgraph-python` output (resolution-aware rewriter is
a superset of the prior subdir-aware behavior when all imports already
resolve).

## Test plan

- [ ] Merge + wait for showcase deploy workflow to redeploy both
services
- [ ] `curl https://starter-langgraph-fastapi.up.railway.app/api/health`
returns `agent: "ok"`
- [ ] `curl
https://starter-langgraph-typescript.up.railway.app/api/health` returns
`agent: "ok"`
- [ ] Smoke-test a chat turn on each starter to confirm the agent
actually responds
2026-04-19 12:41:14 -07:00
Jordan Ritter c6b1617bef chore(showcase/starters): regenerate all starters post-generator fix 2026-04-19 12:17:50 -07:00
Jordan Ritter 70f8df05a4 chore(showcase/starters): regenerate langgraph-{fastapi,typescript} after generator fix
langgraph-fastapi/src/agents/src/agent.py now imports
`src.agents.tools.*` (module exists) rather than `src.agents.src.tools.*`
(nonexistent path) -- fixes the ModuleNotFoundError crash that held
/api/health at agent: "down".

langgraph-typescript/package.json now includes @langchain/core,
@langchain/langgraph, @langchain/langgraph-checkpoint,
@langchain/langgraph-cli, @langchain/openai, and @copilotkit/sdk-js so
the agent subtree can resolve its runtime imports after the Dockerfile
deletes agent/package.json.

Local docker build + run verified: both /api/health return
{"status":"ok","agent":"ok"} and their entrypoint logs show
`Agent server started` with the captured PID belonging to the agent,
not an awk/sed prefixer.
2026-04-19 12:13:40 -07:00
Jordan Ritter 6e1aa87072 chore(showcase/starters): regenerate all starters after #4098
#4098 landed two generator-level changes that affect every starter slug but only
langroid was regenerated in that PR:

1. rewritePythonImports now strips `import sys` when sys.path.insert is removed
   and no other `sys` reference survives in the file (paired with existing
   osUsed detection).
2. starters/template/entrypoint.template.sh switched from pipeline
   (`2>&1 | sed 's/^/[agent] /'`) to process substitution
   (`&> >(awk '{print "[agent] " $0; fflush()}')`) so $! captures the real
   agent PID, not sed's — prior pattern masked uvicorn crashes behind sed's
   exit code.

Regenerate the remaining 16 starters so drift-check passes on main.

No source logic change.
2026-04-19 11:41:50 -07:00
Jordan Ritter ede34dabc1 chore(showcase/langroid): regenerate starter after source+generator updates 2026-04-19 11:39:06 -07:00
Jordan Ritter 2dea75a5ab fix(showcase/langroid): non-root Dockerfile + pin direct Python deps
Package Dockerfile:
- Create unprivileged app:app user (UID/GID 1001) matching starter Dockerfile
- USER app drop with --chown=app:app on COPY for security parity
- ENV PORT=10000 / ENV HOSTNAME=0.0.0.0 so child processes inherit defaults
- Preserves PYTHONPATH=/app/shared/python for shared-tools imports

requirements.txt (package + starter): pin httpx, pydantic, openai directly
rather than relying on transitive resolution from langroid / fastapi.
agui_adapter.py imports these symbols directly — the module's contract
shouldn't depend on upstream pin discipline we don't control.
2026-04-19 11:38:44 -07:00
Jordan Ritter c2234312b8 fix(showcase/langroid): provider-aware entrypoint credential guard + graceful shutdown
Replace the OPENAI_API_KEY-hardcoded credential guard with a provider-aware
_check_key that inspects LANGROID_MODEL's prefix and probes the correct env
var for that provider:

- openai/ → WARN (not a langroid-native prefix; use bare model names)
- anthropic/ → WARN (not routable; suggest litellm/anthropic/<model>)
- litellm/anthropic/ → ANTHROPIC_API_KEY
- gemini/ → GEMINI_API_KEY
- openrouter/, groq/, cerebras/, glhf/, minimax/, portkey/, deepseek/ → dedicated keys
- ollama/, local/, vllm/, llamacpp/ → NO_KEY_REQUIRED (local inference)
- langdb/, litellm-proxy/, litellm/<non-anthropic>/ → NO_KEY_REQUIRED_* (credentials
  resolved via config, not env)

Under REQUIRE_LANGROID_API_KEY=1 a missing credential FATALs the boot; the
default is warn-and-continue so dev containers boot cleanly.

Process lifecycle hardening:
- Use process substitution `> >(sed ...)` instead of pipelines so $! captures
  the real python/next PID (not sed's) — prior pipeline pattern would mask
  uvicorn crashes behind sed's exit code
- Trap cleanup with `set +e` at entry (trap may fire from FATAL `exit 1` path
  where set -e would otherwise abort the cleanup loop)
- 5s SIGTERM→SIGKILL grace window on the surviving child
- Extended exit-code case statement (0, 1, 2, 126, 127, 130, 137, 139, 143, 255)
- Survivor-kill diagnostics distinguish EPERM from ESRCH
- wait -n with explicit positional PIDs so unrelated subshell reaps can't
  satisfy the wait

.env.example updates document the multi-provider options so operators
discover them from the file itself, not entrypoint.sh.

.gitattributes enforces LF on *.sh so Windows contributors regenerating
the starter don't silently ship CRLF entrypoints.
2026-04-19 11:38:32 -07:00
Jordan Ritter 98841aaba5 fix(showcase/starters): chown WORKDIR to app user in Dockerfiles
Root cause: `WORKDIR /app` at the top of the runner stage creates /app
owned by root BEFORE the unprivileged `app` user is created. The
`COPY --chown=app:app` lines added in #4092 only reassign the files
being copied, NOT the /app directory itself.

Symptom: starter-mastra CRASHED on Railway with
  EACCES: permission denied, mkdir '/app/.mastra'
when `npx mastra dev` tried to create its cache dir under CWD as user
`app`. Likely co-victim class: any starter whose runtime invokes a Node
CLI that writes to CWD (e.g. langgraph-typescript via @langchain/langgraph-cli dev).

Fix: add `RUN chown app:app /app` immediately before `USER app` in all
four Dockerfile templates (typescript, python, dotnet, java), applied
uniformly to all 17 generated starters via the generator.

Verified locally:
 - docker build + run starter-mastra → container stays up, /app owned
   by app:app, /app/.mastra created successfully, /api/health returns 200.
 - docker build + run starter-langgraph-typescript → container stays up
   (8+ min), write to /app succeeds, /api/health returns 503 degraded
   (expected on dummy OPENAI_API_KEY) — NOT a crash.

All 17 starter Dockerfiles regenerated via
  pnpm run generate-starters
and the existing showcase/scripts vitest suite stays green (1073 tests).
2026-04-19 10:40:12 -07:00
Jordan Ritter de586ececd chore(showcase): regenerate starters post-#4095 rebase
- Regenerate agno starter to pick up agno>=2.5.17 (from #4095)
- Ratchet validate-pins fail-baseline hash to match new FAIL set
  (count unchanged at 110; hash rotates because agno Dojo/showcase
  pair now reflects the SDK upgrade)
2026-04-19 09:00:11 -07:00
Jordan Ritter dfd8346bc1 fix(showcase/starters/langgraph-fastapi): correct src.agents.tools.* imports
generate-starters.ts rewrites relative imports to absolute for langgraph
starters because langgraph_cli loads modules standalone rather than as
packages. The rewrite was flat:

  from .X import ...  ->  from <agentDir>.X import ...

For a file at <agentDir>/tools/get_weather.py, `from .types import ...`
resolves to `tools.types` — the CURRENT package — not `<agentDir>.types`.
The flat rewrite dropped the `tools` segment and produced:

  ModuleNotFoundError: No module named 'src.agents.types'

at startup. The agent crashed during module import; the entrypoint
pipe swallowed the traceback (see previous commit for the pipe bug);
the 2-3s sleep guard happened to fire while `sed` was still alive; and
Railway's /api/health probe reported `agent: "error"`.

Make the rewrite subdir-aware: compute the file's containing Python
package from its relative path under agentDest, and prepend that to the
relative import target. So `from .types import ...` inside
`src/agents/tools/get_weather.py` becomes
`from src.agents.tools.types import ...`.

langgraph-python has the same broken imports in its tools/__init__.py
but doesn't crash at runtime because main.py doesn't import from tools
(dead path). Regenerating fixes the dead code too.
2026-04-19 08:57:44 -07:00
Jordan Ritter de815ae2d5 fix(showcase/starters): capture real agent PID in entrypoint.sh + unbuffer stderr
The entrypoint.sh template used `cmd 2>&1 | sed 's/^/[agent] /' &`
followed by `AGENT_PID=\$!`. After a pipeline, `\$!` points to the LAST
command in the pipe (the `sed` process), not the agent. Every subsequent
`kill -0 \$AGENT_PID` and `wait -n \$AGENT_PID` was therefore monitoring
`sed`, which stays alive until its stdin closes — long after the agent has
crashed. Railway restarts the container mid-loop; the health probe sees
`{status: "degraded", agent: "down"}` for a few seconds during each cycle.

A second, compounding bug: `sed` buffers by default, and Python agents
buffer their own stdout, so a stack trace emitted during module import
could sit in userspace memory until the pipe closed — by which point the
log was discarded and the real cause of the crash was lost.

Fix both by switching to bash process substitution:
  cmd &> >(awk '{print "[agent] " \$0; fflush()}') &
  AGENT_PID=\$!
Process substitution does not create a pipeline, so `\$!` remains the
agent's PID. `awk` with `fflush()` flushes each prefixed line to the
container log immediately. Also export `PYTHONUNBUFFERED=1` at the
entrypoint level so Python-based agents don't buffer before awk.

Applies to all 17 starters (python, langgraph-python, langgraph-fastapi,
langgraph-typescript, mastra, typescript, java/spring-ai, csharp/
ms-agent-dotnet). Done once in generate-starters.ts + the template +
regenerated entrypoint.sh files.
2026-04-19 08:57:44 -07:00
Jordan Ritter 20efc40960 fix(showcase/starters): serve /health via middleware to bypass FastAPI mount shadow
Python FastAPI showcase starters were registering an @app.get("/health")
handler BEFORE app.mount("/", ...) (or the adapter's equivalent catch-all).
Starlette's Mount at "/" is a prefix match that swallows every subsequent
request including /health, so the decorated handler never fired and the
Next.js /api/health probe saw a non-JSON agent response and flagged the
starter as "degraded".

Install a HealthMiddleware (BaseHTTPMiddleware) that short-circuits
GET /health above the routing layer, which runs before any Mount can
claim the path. The agent mount is kept intact so AG-UI traffic at / is
unaffected.

Affects 10 Python agent starters: ag2, agno, claude-sdk-python,
crewai-crews, google-adk, langroid, llamaindex, ms-agent-python,
pydantic-ai, strands.
2026-04-19 08:57:44 -07:00
Jordan Ritter e851ea70e6 fix(showcase/starters): regenerate google-adk starter after Gemini rewrite 2026-04-19 07:57:13 -07:00
Jordan Ritter c591ad71b1 perf(showcase): replace recursive chown with COPY --chown in starter Dockerfiles
Every starter Dockerfile ended with `RUN chown -R app:app /app`, which
recursively walks the full `/app` tree (Next.js `node_modules` dominates
— ~50k files) to fix ownership after the fact. On the 23-way Depot
runner fan-out used by .github/workflows/deploy-showcase-services.yml
this step consistently took 5+ minutes under I/O contention, busting
the 15-minute GH Actions job budget before the image could even finish
pushing (run 24621469277 — 22/23 services cancelled).

The standard Docker idiom is `COPY --chown=<user>:<group>` which applies
ownership during the copy step itself — no extra layer, no full-tree
traversal, zero runtime cost.

Changes:
  - Create the `app` user right after `WORKDIR /app` in every runner
    stage so `--chown=app:app` resolves by name.
  - Add `--chown=app:app` to every COPY instruction that lands files
    under `/app` in the runner stage (including `COPY --from=frontend`
    and `COPY --from=<agent-builder>` multi-stage copies).
  - Drop the trailing `RUN chown -R app:app /app` (or the tail of the
    compound RUN in the TS starters).
  - For langgraph starters, fold `chown app:app /app/.langgraph_api`
    into the mkdir RUN so langgraph_cli's scratch dir is still writable
    by the runtime user.
  - Update showcase/scripts/generate-starters.ts so the shared templates
    (Dockerfile.python/typescript/dotnet/java) emit the new pattern and
    the framework-specific COPY lines (`COPY ${dest} ./` for extra files
    and `COPY agent_server.py ./` for Python starters) include `--chown`.

Local verification (Docker Desktop, single starter, no contention):
  ag2 pre-fix:  3:03 total, `RUN chown -R app:app /app` = 50.1s
  ag2 post-fix: 1:39 total, no chown step
  langgraph-fastapi post-fix: 1:41 (langgraph_api chown is 0.2s)
  mastra post-fix: 2:16

Smoke test on ag2 image: container starts clean, all files under /app
owned by app:app, /api/health returns 200.

Under the 23-way Depot fan-out the real-world win is substantially
larger than the local 50s baseline because recursive chown degrades
super-linearly with concurrent I/O pressure.

Failed run that motivated this: https://github.com/CopilotKit/CopilotKit/actions/runs/24621469277
2026-04-19 07:41:55 -07:00
Jordan Ritter de27e9453f fix(showcase/starters): add .NET build outputs to template .gitignore
ms-agent-dotnet starter was hand-patched with bin/, obj/, *.user, *.suo
but the template wasn't updated — drift-check kept flagging it on regen.
Add the entries to the template so all 17 starters pick them up uniformly
(harmless for non-.NET starters).
2026-04-18 20:47:51 -07:00
Jordan Ritter 51e6f4869d fix(showcase/starters): regenerate after R5 spring-ai template changes
R5 added BoundedToolCallingManagerConfig, OpenAiApiKeyValidator, and
WebClientConfig to showcase/packages/spring-ai/agent/ plus updated
application.properties and pom.xml. Starters were out of sync so
drift-check failed. Ran generate-starters.ts to sync.

Also add bin/ and obj/ .NET build artifacts to ms-agent-dotnet starter
.gitignore so generator output stays clean.
2026-04-18 20:44:39 -07:00
Atai Barkai 06baa53db2 chore(showcase): regenerate starters to unblock drift-check
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-18 18:47:30 -07:00
Jordan Ritter 60836bee8f fix(showcase/crewai-crews): greppable prod-guard WARNING + CORS intent doc + test hardening (CR8)
Three small CR8 fixes bundled by area (crewai-crews Python):

* aimock_toggle.py: prod-guard WARNING now uses a grep-friendly prefix
  `aimock_toggle: DISABLED (prod-guard: VAR=value)`. Rationale in-file:
  `ENV=production` is a common shell-profile default that can silently
  disable the toggle in dev/CI without the operator realizing; a
  consistent greppable prefix lets them find unexpected refusals without
  reading every WARNING line. Strengthened the refusal test to assert
  exactly one WARNING is emitted with that prefix (regression guard
  against future iteration of _PROD_ENV_VARS firing past the first match).

* agent_server.py: added a `CORSMiddleware` comment documenting why
  `allow_origins=["*"]` is intentional for this LOCAL DEMO STARTER — the
  agent binds to localhost:8000 (or :8123 inside a generated starter
  container) and is only reached by the Next.js frontend during
  development. Pointed at `.env.example` / a future `CORS_ORIGIN` env var
  as the path for real deployments. No behavior change.

* test_aimock_toggle.py: `test_default_arg_path_mutates_os_environ` now
  `monkeypatch.delenv`s every entry in `_PROD_ENV_VARS` before asserting
  `enabled is True`. A CI runner or dev shell that exports e.g.
  `ENV=production` or `RAILWAY_ENVIRONMENT=production` would otherwise
  silently flip this test from "toggle enabled" to "prod-guard refused"
  and the enabled-True assertion would fail for the wrong reason.
  monkeypatch restores on teardown so other tests are unaffected.

Regenerated crewai-crews starter to mirror the package changes.
2026-04-18 03:42:20 -07:00
Jordan Ritter 806294704c fix(showcase/starters): scope NODE_ENV=production to Next.js in non-Python Dockerfiles (CR8)
The R6 "scope NODE_ENV to Next.js invocation only" fix landed for the
Python Dockerfile template but missed the .NET / Java / TypeScript
templates — they still set `ENV NODE_ENV=production` at the image level,
which leaks into every child process. That's surprising for the TS
templates specifically (mastra dev, langgraph-cli dev, tsx) because those
frameworks gate HMR / source maps / telemetry on `NODE_ENV` and should
NOT see "production" when they're running as the agent backend behind
Next.js.

Fix: remove image-level `ENV NODE_ENV=production` from all three non-Python
Dockerfile templates. The entrypoint template already binds
`env NODE_ENV=production npx next start` so Next.js still sees the value —
only the child agent processes get their environment back. Added a lang-
specific comment to each template explaining the intent and calling out
the affected child processes.

Regenerated the 5 affected starter Dockerfiles
(claude-sdk-typescript, langgraph-typescript, mastra, ms-agent-dotnet,
spring-ai) via `tsx generate-starters.ts`; diffs are byte-identical to the
template change.
2026-04-18 03:41:56 -07:00
Jordan Ritter 789cd14a47 chore(showcase/starters): regenerate after CR7 prod-guard + docs sync
Propagates the crewai-crews aimock_toggle.py (adds RAILWAY_ENVIRONMENT_NAME
to `_PROD_ENV_VARS` + updated header comment) and .env.example (full
prod-guard var enumeration) from packages/ to starters/ via
generate-starters.ts. Only crewai-crews ships aimock_toggle.py today so
only that starter changes; other starters re-generate byte-identical.

Verified: `tsx generate-starters.ts --check` OK across all 17 starters.
2026-04-18 03:26:26 -07:00
Jordan Ritter 830d60c908 chore(showcase/starters): regenerate after CR6 template fixes
Downstream of the template refactor: Dockerfile + entrypoint.sh across
all 17 starters regenerated to pick up the generic NODE_ENV comment,
the `env NODE_ENV=production` invocation form, and the langgraph-only
gating of `/app/.langgraph_api`. Non-langgraph starters lose the
spurious mkdir layer they never used.
2026-04-18 02:59:57 -07:00
Jordan Ritter 2ee92f6862 refactor(showcase/starters): generic NODE_ENV docs; gate .langgraph_api (CR6)
- Reword the NODE_ENV=production comment in Dockerfile + entrypoint
  templates to generic language. The previous comment mentioned
  `aimock_toggle.py refuses to apply` — that text got rendered
  verbatim into .NET / TypeScript / Java starters via the shared
  template, misleading readers who don't have a Python toggle. New
  comment describes the general behavior (image-level NODE_ENV leaks
  into every child process, most of which don't interpret it like
  Next.js does).
- Use `env NODE_ENV=production npx next start` instead of bare
  `NODE_ENV=production npx next start` in entrypoint.sh. `env` prefix
  is the syntactically robust form across shells.
- Gate the `RUN mkdir -p /app/.langgraph_api` layer to langgraph-*
  starters only via a new `{{LANGGRAPH_MKDIR}}` template variable.
  Creating that directory in crewai / agno / pydantic-ai / claude-sdk
  / etc. was copy-paste residue — langgraph_cli is the only thing
  that ever writes there.
- Apply the same NODE_ENV rewording to the crewai-crews SOURCE
  Dockerfile + entrypoint (the templates' downstream consumers
  regenerate via generate-starters, but the source package is hand-
  maintained).
2026-04-18 02:59:56 -07:00
Jordan Ritter 05367c3539 chore(showcase/starters): regenerate after aimock + Dockerfile fixes
Regenerate all 17 starters via `tsx generate-starters.ts` to propagate:

- aimock_toggle.py: prod-guard only fires when AIMOCK_URL is set;
  dummy key renamed to `sk-aimock-dev-ci-only` (from previous file).
- agent_server.py: removed dead `main()`/RELOAD entrypoint (non-langgraph
  Python starters).
- Dockerfile + entrypoint.sh: `NODE_ENV=production` moved from global
  image ENV onto the `npx next start` invocation so the Python agent
  doesn't inherit the prod-guard that would silently disable aimock.
- langgraph-fastapi/.env.example: source-package port fix already propagated
  (port was already correct at :8123 for this starter; no content change
  beyond reflowing the comment from the source package).

The starter regen is a single atomic commit (separate from the source
edits) so reviewers can inspect which input edit produced which starter
output without wading through unrelated edits in the same diff.
2026-04-18 02:59:52 -07:00
Jordan Ritter fd752ae1d8 fix(showcase): scope NODE_ENV=production to Next.js invocation only, not image-level ENV
M9: `ENV NODE_ENV=production` at the Dockerfile level propagates to every
process spawned by the entrypoint — including the Python agent. The
aimock toggle (aimock_toggle.py) refuses to apply when `NODE_ENV=production`
is set, so a Docker-based smoke test with `AIMOCK_URL` exported would
silently get a no-op toggle and hit real OpenAI instead of aimock.

Move `NODE_ENV=production` out of the global Dockerfile ENV blocks and
inline it on the `npx next start` invocation in entrypoint.sh. Next.js
still treats the server as production (that's all Next looks at), but the
Python sibling process is no longer subject to a production-guard that
only ever made sense for the JS runtime.

Affected: crewai-crews package Dockerfile + entrypoint.sh, plus the
starter template (Dockerfile.python + entrypoint.template.sh) — the
starter regen in a follow-up commit propagates this to all 17 starters.
2026-04-18 02:59:49 -07:00
Jordan Ritter 76f0c13c85 feat(showcase/starters): regen with aimock + .env propagation
Regenerated from showcase/scripts/generate-starters.ts with the updated
propagation rules. Every starter whose package ships .env.example now carries
one (port-rewritten to :8123 where AGENT_URL points at localhost), and the
crewai-crews starter additionally carries aimock_toggle.py alongside the
agent_server.

OPENAI_API_KEY placeholder text in every package + starter .env.example now
reads 'replace-with-your-key' (not a fake sk-... value), so users who skip
editing get a loud 401 from real OpenAI instead of a silent aimock success
masking misconfig.
2026-04-18 02:12:08 -07:00
Jordan Ritter c8276ee923 feat(showcase): internal feature-matrix shell + canonical demo/code routes (#4039)
## Summary

Adds a new internal-facing showcase app — `showcase/shell-internal` —
that renders a **feature × integration grid**. Each cell links to one of
two new **canonical standalone routes** on the main `shell` app, or
shows a red ✗ when the feature isn't supported.

## What's new

### 1. Two canonical standalone routes in `showcase/shell`

These give every (integration × feature) pair a single, embeddable URL
for each artifact — useful for docs, marketing, and tooling.

- **`/integrations/[slug]/[demo]/preview`** — iframe-only hosted demo,
no chrome
- **`/integrations/[slug]/[demo]/code`** — code viewer only. Supports
URL params for future refinements:
  - `?file=<filename>` — which file tab to show
  - `?lines=10-20` or `?lines=10-20,35` — highlight specific line ranges

Example:
`/integrations/langgraph-python/agentic-chat/code?file=page.tsx&lines=15-22`

### 2. `showcase/shell-internal` — a new Next.js app on port 3002

- Single grid page: **rows = features**, **columns =
integrations/frameworks** (transpose of shell's existing `/matrix` page,
which has integrations as rows)
- Each cell has **two mini-links** — green `▶ demo` and blue `</> code`
— pointing at the canonical `shell` routes, or a red `✗` if not
supported
- Reads `showcase/shell/src/data/registry.json` directly via relative
import — single source of truth, no duplicate data
- `NEXT_PUBLIC_SHELL_URL` env var (default `http://localhost:3000`) to
point the cells at a deployed `shell` in non-local environments

### 3. Small fix: drop `--turbopack` from shell's dev script

`showcase/shell`'s Next.js 15.4.10 turbopack panics (`"Next.js package
not found"`) on this repo's multi-lockfile layout. Switching to webpack
dev resolves it; production builds (which don't use turbopack) are
unaffected.

## Why two apps instead of one

`shell-internal` could have hosted the demo and code pages itself, but
keeping them in `shell`:

- Makes the canonical URLs reusable outside internal ops (docs,
marketing, linking into product)
- Avoids duplicating the demo-rendering and code-viewer plumbing across
two apps

Internal shell stays a pure overview.

## Test plan

- [ ] `cd showcase/shell && npm run dev` — confirm shell starts on :3000
(webpack, no turbopack panic)
- [ ] `cd showcase/shell-internal && npm install && npm run dev` —
confirm shell-internal starts on :3002
- [ ] Open http://localhost:3002 — verify the feature × integration grid
renders
- [ ] Click a `▶ demo` cell — verify it opens
`http://localhost:3000/integrations/<slug>/<feature>/preview` with only
the iframe demo
- [ ] Click a `</> code` cell — verify it opens
`http://localhost:3000/integrations/<slug>/<feature>/code` with the code
viewer
- [ ] In the code route, try `?file=<name>` and `?lines=10-20` URL
params — verify file switches and lines highlight
- [ ] Verify red ✗ shows for unsupported (integration × feature)
combinations

🤖 Generated with [Claude Code](https://claude.com/claude-code)
2026-04-17 19:18:59 -07:00
Atai Barkai f1cd005b2e chore(showcase): regenerate langgraph-python starter
Syncs the starter with the slimmed showcase package:
- Trimmed `src/agents/main.py` (create_agent + CopilotKitMiddleware,
  no backend tools).
- Removed `a2ui_dynamic_schema.py`, `a2ui_fixed_schema.py`,
  `todos.py`, `tool_wrappers.py`.

Generated via `npx tsx showcase/scripts/generate-starters.ts`.
`--check` passes.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-17 17:53:05 -07:00
Jordan Ritter f2152f514c fix(showcase-starters): copilotkit route health probes hit /health not /ok (+ mastra /api/health) 2026-04-17 16:22:48 -07:00
Jordan Ritter 2a5632a573 fix(showcase-starters): health probe hits /health not /ok (matches agent server route) 2026-04-17 16:22:48 -07:00
Jordan Ritter b970853efa fix: replace assert patch-verification with explicit raise (survives python -O) 2026-04-16 13:07:34 -07:00
Jordan Ritter d5c86c1b32 fix: guard crewai monkey-patch against upstream drift, pin ag-ui-crewai ceiling
Addresses CR R1 CRITICAL finding on PR #3974.

setattr() on a Python module always succeeds regardless of prior
attribute existence. Without a guard, an upstream rename of
generate_input_description_with_ai or generate_crew_description_with_ai
in a future crewai release would silently no-op the patch, leaving the
real functions in place. The pre-bind LLM crash bug would quietly
reappear in production with a green PR.

Changes:

- Add hasattr() guard in both agent_server.py files that raises
  RuntimeError with an actionable drift message if either symbol
  disappears upstream.
- Add post-assignment assert to defend against import-order weirdness
  or module re-imports shadowing the reference.
- Add an info-level log line so operators can see the shim is active
  and know to remove it after adoption.
- Add upstream issue link (crewAIInc/crewAI#5510) and explicit ag-ui-crewai
  release status to the comment block.
- Pin ag-ui-crewai upper bound to <0.1.6 in both requirements.txt files
  so the shim's applicability window is enforced by pip — upgrading past
  0.1.5 forces the engineer to confront the version mismatch and remove
  the shim.

Applied to both showcase/packages/crewai-crews/src/agent_server.py and
showcase/starters/crewai-crews/agent_server.py to keep the demo and
starter trees in sync.

Verified locally:

- Docker build succeeds (showcase/packages/crewai-crews).
- Hardened container starts cleanly with OPENAI_BASE_URL set to an
  unreachable host; /health returns 200 on both agent (8000) and
  Next.js (10000) ports.
- Negative case: deleting generate_input_description_with_ai from the
  installed crewai module inside the container and re-importing
  agent_server raises RuntimeError with the upstream-drift message, as
  expected.
2026-04-16 13:01:49 -07:00
Jordan Ritter e68d546b11 fix: CR findings — type safety, error handling, test coverage (#3945)
## Summary

Addresses all findings from 7-agent MSAL code review of the starter
crash fix PRs (#3933, #3941, #3943).

**Agent server (claude-sdk-typescript):**
- Remove 6 unnecessary `as any` casts — use TypeScript discriminated
union narrowing on `msg.role`
- Add `ANTHROPIC_API_KEY` validation on startup (exit if missing)
- Add `console.warn` logging to empty catch blocks (tool args + schema
parse failures)
- Sanitize error messages sent to client — no raw `err.message` in SSE
stream
- Fix misleading comment about system/developer role handling
- Set explicit 2MB JSON body limit on Express
- Remove unused `assistantMsgId` variable

**Generation script:**
- Remove dead `_agentDir` parameter from `rewritePythonImports`
- Add warning when `PIN_OVERRIDES` dep not found in framework
dependencies

**Tests (3 new):**
- Context-aware import rewriting for files inside `tools/` directory
- `from agents.X import` relative import rewriting
- `PIN_OVERRIDES` integration test for mastra version pinning

## Test plan

- [x] 254 generate-starters tests pass (3 new)
- [x] Drift check passes
- [x] Pre-commit hooks pass
2026-04-15 21:15:58 -07:00
Jordan Ritter 73ac51f287 fix: address CR Round 4 findings — toolCallId guard, error emit safety
- Guard TOOL_CALL_ARGS emission with if(toolCallId) check, matching
  the existing guard on TOOL_CALL_END
- Wrap catch-block emit() in nested try/catch to handle client
  disconnect during error reporting
2026-04-15 17:53:42 -07:00