Skip to content

fix(showcase/starters): restore langgraph-{fastapi,typescript} agent subprocess - #4101

Merged
jpr5 merged 3 commits into
mainfrom
fix/restore-langgraph-starters
Apr 19, 2026
Merged

jpr5 merged 3 commits into
mainfrom
fix/restore-langgraph-starters

Conversation

@jpr5

@jpr5 jpr5 commented Apr 19, 2026

Copy link
Copy Markdown
Contributor

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

jpr5 added 2 commits April 19, 2026 12:13
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.
…fter 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.
@vercel

vercel Bot commented Apr 19, 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 19, 2026 7:22pm
docs Ready Ready Preview, Comment Apr 19, 2026 7:22pm
form-filling Ready Ready Preview, Comment Apr 19, 2026 7:22pm
research-canvas Ready Ready Preview, Comment Apr 19, 2026 7:22pm
travel Ready Ready Preview, Comment Apr 19, 2026 7:22pm

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 2087950 into main Apr 19, 2026
13 checks passed
@jpr5
jpr5 deleted the fix/restore-langgraph-starters branch April 19, 2026 19:41
jpr5 added a commit that referenced this pull request Apr 19, 2026
…ntrypoint 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 2087950
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.
jpr5 added a commit that referenced this pull request Apr 19, 2026
…raph + entrypoint (#4102)

## Summary

PR #4101 updated the resolution-aware import rewriter and the entrypoint
`$!` -> agent PID fix, but the regeneration in that merge didn't include
all affected files. After merge, `origin/main` at `2087950ee` still had
stale output — and `showcase-starter-langgraph-fastapi-production` has
been returning `503 {"agent":"down"}` on `/api/health` as a result.

Root cause:
- `showcase/starters/langgraph-fastapi/src/agents/tools/*.py` still
imported `from src.agents.types` / `src.agents.get_weather` / etc. (old
flat-rewrite output). `src/agents/src/agent.py` imports
`src.agents.tools`, which loads `tools/__init__.py`, which fails with
`ModuleNotFoundError: No module named 'src.agents.types'`. The agent
subprocess crashes during langgraph_cli's graph import step;
`/api/health` flips to 503.
- langgraph-python has the same broken imports in its tools/ barrel.
- All 15 generated `entrypoint.sh` files still used `2>&1 | sed
's/^/[agent] /' &`, so `$!` (used for `kill -0 $AGENT_PID` and `wait
-n`) tracked `sed`, not the agent. Stack traces also got line-buffered
inside the pipe and never reached the container log.

Fix: rerun `pnpm -C showcase/scripts generate-starters` (the script
already on main from #4101). Pure regeneration — no source changes.

Verified locally:
- `tools/__init__.py` now emits `from src.agents.tools.types import ...`
(resolution-aware rewrite finds `<agentDest>/tools/types.py` one parent
away).
- `entrypoint.sh` now emits `&> >(awk '{print "[agent] " $0;
fflush()}')`.

Once merged, the Railway drift rebuild will pick up the new image for
langgraph-fastapi and `/api/health` should return green within one
redeploy cycle.

## Test plan
- [ ] CI green
- [ ] After merge + drift rebuild, `curl
https://showcase-starter-langgraph-fastapi-production-c7d2.up.railway.app/api/health`
returns `200 {"agent":"up"}`
- [ ] langgraph-python health stays green (same tools/ fix applied, same
container architecture)
ataibarkai added a commit that referenced this pull request Apr 19, 2026
…n merge

Re-ran generate-registry + validate-pins after merging main (which brought
in PR #4098 langroid + #4100/#4101/#4102 starter regens) and the non-root
+ PID-capture column sweep. FAIL count unchanged at 110; hash drifts
because the FAIL set is the same strands entries but ordering normalized.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
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
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
…import + entrypoint fixes

PR CopilotKit#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 2087950
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 CopilotKit#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.
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
… for langgraph + entrypoint (CopilotKit#4102)

## Summary

PR CopilotKit#4101 updated the resolution-aware import rewriter and the entrypoint
`$!` -> agent PID fix, but the regeneration in that merge didn't include
all affected files. After merge, `origin/main` at `2087950ee` still had
stale output — and `showcase-starter-langgraph-fastapi-production` has
been returning `503 {"agent":"down"}` on `/api/health` as a result.

Root cause:
- `showcase/starters/langgraph-fastapi/src/agents/tools/*.py` still
imported `from src.agents.types` / `src.agents.get_weather` / etc. (old
flat-rewrite output). `src/agents/src/agent.py` imports
`src.agents.tools`, which loads `tools/__init__.py`, which fails with
`ModuleNotFoundError: No module named 'src.agents.types'`. The agent
subprocess crashes during langgraph_cli's graph import step;
`/api/health` flips to 503.
- langgraph-python has the same broken imports in its tools/ barrel.
- All 15 generated `entrypoint.sh` files still used `2>&1 | sed
's/^/[agent] /' &`, so `$!` (used for `kill -0 $AGENT_PID` and `wait
-n`) tracked `sed`, not the agent. Stack traces also got line-buffered
inside the pipe and never reached the container log.

Fix: rerun `pnpm -C showcase/scripts generate-starters` (the script
already on main from CopilotKit#4101). Pure regeneration — no source changes.

Verified locally:
- `tools/__init__.py` now emits `from src.agents.tools.types import ...`
(resolution-aware rewrite finds `<agentDest>/tools/types.py` one parent
away).
- `entrypoint.sh` now emits `&> >(awk '{print "[agent] " $0;
fflush()}')`.

Once merged, the Railway drift rebuild will pick up the new image for
langgraph-fastapi and `/api/health` should return green within one
redeploy cycle.

## Test plan
- [ ] CI green
- [ ] After merge + drift rebuild, `curl
https://showcase-starter-langgraph-fastapi-production-c7d2.up.railway.app/api/health`
returns `200 {"agent":"up"}`
- [ ] langgraph-python health stays green (same tools/ fix applied, same
container architecture)

This branch was successfully deployed

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