Repository navigation
fix(showcase/starters): chown /app to app user to prevent CLI cache-dir crashes - #4099
Merged
Merged
Conversation
jpr5
requested review from
marthakelly,
mme,
ranst91 and
tylerslaton
as code owners
April 19, 2026 16:09
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
📣 Social Copy GeneratorGenerate social media copies (Twitter/X, LinkedIn, Blog Post) for this PR using Claude.
|
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).
jpr5
force-pushed
the
fix/showcase-starters-chown-workdir
branch
from
April 19, 2026 17:42
8f80e07 to
98841aa
Compare
jpr5
added a commit
that referenced
this pull request
Apr 19, 2026
Three interlocking fixes to generate-starters.ts that together restore langgraph-fastapi and langgraph-typescript /api/health to "ok" after #4099 shipped an entrypointOverride feature that accidentally reverted earlier fixes and left gaps for the TS starter. 1. Resolution-aware python import rewrite for langgraph starters. langgraph_cli loads agent modules standalone (not as packages), so the generator rewrites `from .X import ...` to absolute form. The previous flat rewrite produced `from <agentDir>.X import ...`, and the subsequent subdir-aware variant used the file's OWN dir as the package. Both assume sibling targets sit alongside the importing file. langgraph-fastapi violates that: agent.py lives at `src/agents/src/agent.py` but the `tools/` it imports lives at `src/agents/tools/` -- one level up, not inside `src/`. Either prior rewrite produced `from src.agents.src.tools import ...`, a path that doesn't exist, and langgraph_cli crashed on module import with `ModuleNotFoundError: No module named 'src.agents.src.tools'` before ever binding 8123. Walk UP from the file's own dir toward agentDest and rebase the absolute import on the shallowest directory that actually contains `<firstSeg>/` or `<firstSeg>.py`. Correct both for co-located imports (`tools/get_weather.py` importing `.types`) and for sibling-directory imports (`src/agent.py` importing `.tools` from `../tools`). 2. Merge langgraph-typescript agent runtime deps into root package.json. The TS Dockerfile deliberately deletes `agent/package.json` to collapse the ESM package boundary between the Next.js frontend and the agent subtree. Without merging the agent's runtime deps up into the root package.json, the langgraph-cli's runtime import of graph.ts fails with `Cannot find module '@langchain/openai'` and the agent never binds 8123. Add `extraDependencies` to the langgraph-typescript framework def with @langchain/core, @langchain/langgraph, @langchain/langgraph-checkpoint, @langchain/langgraph-cli, @langchain/openai, and @copilotkit/sdk-js. 3. Restore AGENT_LOG_PREFIX process-substitution helper. #4099 inadvertently replaced `cmd &> >(awk … fflush …)` with `cmd 2>&1 | sed …` across every getEntrypointBlock branch. After a pipeline `$!` points at `sed`, not the agent, so `kill -0 $AGENT_PID` and `wait -n $AGENT_PID` monitor the wrong process and mask real crashes; `sed` also line-buffers so crash output can be lost. Restore the helper so the committed starter entrypoint.sh files and regenerated output stay consistent.
4 tasks
jpr5
added a commit
that referenced
this pull request
Apr 19, 2026
…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
zeekay
pushed a commit
to Dream-AI-4444/CopilotKit
that referenced
this pull request
Sep 11, 2026
…ir crashes (CopilotKit#4099) ## Summary **Root cause:** PR CopilotKit#4092 replaced a blanket `RUN chown -R app:app /app` with per-COPY `COPY --chown=app:app` lines. That covers the copied files, but `WORKDIR /app` at the top of the runner stage creates `/app` as root BEFORE the `app` user exists, and `COPY --chown=` only reassigns the copied files — not the parent dir. Result: `/app` stays owned by root. **Symptom:** `starter-mastra` deploy CRASHED on Railway with: ``` Error: EACCES: permission denied, mkdir '/app/.mastra' ``` `npx mastra dev` tries to create its cache dir under CWD at runtime as user `app`, and fails. **Likely co-victims:** any starter whose runtime invokes a Node CLI that writes to CWD. `starter-langgraph-typescript` (uses `@langchain/langgraph-cli dev`) fits the exact same signature — same class of bug, would have hit the same wall once traffic forced a cache write. **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 `showcase/scripts/generate-starters.ts`. Surgical, cheap, idempotent. ## Evidence — local docker build + run **starter-mastra:** ``` $ docker exec starter-mastra-test ls -la /app | head drwxr-xr-x 1 app app 4096 . ← WORKDIR now owned by app drwxr-xr-x 1 root root 4096 .. drwxr-xr-x 4 app app 4096 .mastra ← created successfully by mastra dev ... $ curl http://localhost:13010/api/health {"status":"ok","integration":"mastra","agent":"ok",...} ← HTTP 200 ``` **starter-langgraph-typescript:** ``` $ docker ps --filter name=starter-langgraph-ts-test starter-langgraph-ts-test Up 8 minutes ← stable, not crashlooping $ docker exec starter-langgraph-ts-test touch /app/test-write && echo OK OK $ curl http://localhost:13020/api/health {"status":"degraded","integration":"langgraph-typescript","agent":"down",...} ← HTTP 503 (dummy key) — NOT a crash ``` ## Scope - 17 starter Dockerfiles regenerated - 4 template Dockerfiles updated (the source of truth) - Generator TS untouched — the fix is purely in the Dockerfile templates that the generator copies verbatim - `showcase/scripts` vitest: 1073/1073 green ## Test plan - [x] `pnpm run generate-starters` regenerates without errors - [x] `pnpm test` in `showcase/scripts` — 1073 tests green - [x] `docker build` + `docker run` starter-mastra — container stays up, `/api/health` 200 - [x] `docker build` + `docker run` starter-langgraph-typescript — container stays up 8+ min, `/api/health` 503 degraded (expected on dummy key) - [ ] Railway redeploy of starter-mastra after merge — expect container to boot and reach `running` - [ ] Railway redeploy of starter-langgraph-typescript after merge — expect container to boot and reach `running` Independent of CopilotKit#4096 — branched from `origin/main`, no dependency.
zeekay
pushed a commit
to Dream-AI-4444/CopilotKit
that referenced
this pull request
Sep 11, 2026
Three interlocking fixes to generate-starters.ts that together restore langgraph-fastapi and langgraph-typescript /api/health to "ok" after CopilotKit#4099 shipped an entrypointOverride feature that accidentally reverted earlier fixes and left gaps for the TS starter. 1. Resolution-aware python import rewrite for langgraph starters. langgraph_cli loads agent modules standalone (not as packages), so the generator rewrites `from .X import ...` to absolute form. The previous flat rewrite produced `from <agentDir>.X import ...`, and the subsequent subdir-aware variant used the file's OWN dir as the package. Both assume sibling targets sit alongside the importing file. langgraph-fastapi violates that: agent.py lives at `src/agents/src/agent.py` but the `tools/` it imports lives at `src/agents/tools/` -- one level up, not inside `src/`. Either prior rewrite produced `from src.agents.src.tools import ...`, a path that doesn't exist, and langgraph_cli crashed on module import with `ModuleNotFoundError: No module named 'src.agents.src.tools'` before ever binding 8123. Walk UP from the file's own dir toward agentDest and rebase the absolute import on the shallowest directory that actually contains `<firstSeg>/` or `<firstSeg>.py`. Correct both for co-located imports (`tools/get_weather.py` importing `.types`) and for sibling-directory imports (`src/agent.py` importing `.tools` from `../tools`). 2. Merge langgraph-typescript agent runtime deps into root package.json. The TS Dockerfile deliberately deletes `agent/package.json` to collapse the ESM package boundary between the Next.js frontend and the agent subtree. Without merging the agent's runtime deps up into the root package.json, the langgraph-cli's runtime import of graph.ts fails with `Cannot find module '@langchain/openai'` and the agent never binds 8123. Add `extraDependencies` to the langgraph-typescript framework def with @langchain/core, @langchain/langgraph, @langchain/langgraph-checkpoint, @langchain/langgraph-cli, @langchain/openai, and @copilotkit/sdk-js. 3. Restore AGENT_LOG_PREFIX process-substitution helper. CopilotKit#4099 inadvertently replaced `cmd &> >(awk … fflush …)` with `cmd 2>&1 | sed …` across every getEntrypointBlock branch. After a pipeline `$!` points at `sed`, not the agent, so `kill -0 $AGENT_PID` and `wait -n $AGENT_PID` monitor the wrong process and mask real crashes; `sed` also line-buffers so crash output can be lost. Restore the helper so the committed starter entrypoint.sh files and regenerated output stay consistent.
zeekay
pushed a commit
to Dream-AI-4444/CopilotKit
that referenced
this pull request
Sep 11, 2026
…subprocess (CopilotKit#4101) ## Summary After CopilotKit#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
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Root cause: PR #4092 replaced a blanket
RUN chown -R app:app /appwith per-COPYCOPY --chown=app:applines. That covers the copied files, butWORKDIR /appat the top of the runner stage creates/appas root BEFORE theappuser exists, andCOPY --chown=only reassigns the copied files — not the parent dir. Result:/appstays owned by root.Symptom:
starter-mastradeploy CRASHED on Railway with:npx mastra devtries to create its cache dir under CWD at runtime as userapp, and fails.Likely co-victims: any starter whose runtime invokes a Node CLI that writes to CWD.
starter-langgraph-typescript(uses@langchain/langgraph-cli dev) fits the exact same signature — same class of bug, would have hit the same wall once traffic forced a cache write.Fix: add
RUN chown app:app /appimmediately beforeUSER appin all four Dockerfile templates (typescript, python, dotnet, java), applied uniformly to all 17 generated starters viashowcase/scripts/generate-starters.ts. Surgical, cheap, idempotent.Evidence — local docker build + run
starter-mastra:
starter-langgraph-typescript:
Scope
showcase/scriptsvitest: 1073/1073 greenTest plan
pnpm run generate-startersregenerates without errorspnpm testinshowcase/scripts— 1073 tests greendocker build+docker runstarter-mastra — container stays up,/api/health200docker build+docker runstarter-langgraph-typescript — container stays up 8+ min,/api/health503 degraded (expected on dummy key)runningrunningIndependent of #4096 — branched from
origin/main, no dependency.