From c6ff08a305b6ac4fcdd2756d0b68381ff13f7b36 Mon Sep 17 00:00:00 2001 From: Bartok9 <259807879+Bartok9@users.noreply.github.com> Date: Sun, 6 Sep 2026 19:36:18 -0400 Subject: [PATCH] Read empty example Bot PORT as unset, so NaN never reaches Bun.serve Same empty-string trap as agent-bot (#395): PORT= in compose used to bind an ephemeral port while docs still named 4300/4400. --- CHANGELOG.md | 4 ++++ examples/langgraph-bot/src/index.ts | 8 +++++++- examples/mastra-bot/src/index.ts | 8 +++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5900b912c..1a58babc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged. ## Unreleased +### Example LangGraph and Mastra Bots no longer bind an ephemeral port on empty `PORT=` + +An empty `PORT=` in compose or `.env` used to become `NaN` for those two example processes, so they listened on a random port while docs still named 4300/4400. They now use the same `listenPort` helper as `agent-bot`: empty is the documented default, and a prefix typo refuses to start. + ## 0.0.8 ### A desktop shell that installs OpenBot and then becomes it diff --git a/examples/langgraph-bot/src/index.ts b/examples/langgraph-bot/src/index.ts index e8308cc1d..d6f14e197 100644 --- a/examples/langgraph-bot/src/index.ts +++ b/examples/langgraph-bot/src/index.ts @@ -10,6 +10,7 @@ import { import { Annotation, END, START, StateGraph } from "@langchain/langgraph"; import { ChatOpenAI } from "@langchain/openai"; import { serve } from "bun"; +import { listenPort } from "../../shared/listen-port"; /** * A Bot written in LangGraph. @@ -26,7 +27,12 @@ import { serve } from "bun"; * `computer_navigate` and still drives a governed browser. */ -const PORT = Number.parseInt(process.env.PORT ?? "4300", 10); +const resolvedPort = listenPort(process.env.PORT, 4300); +if (!resolvedPort.ok) { + console.error(resolvedPort.reason); + process.exit(1); +} +const PORT = resolvedPort.port; const MODEL = process.env.BOT_MODEL ?? "gpt-5.5"; /** * `gpt-5.6-*` rejects function tools on `/v1/chat/completions` and needs the Responses API, which diff --git a/examples/mastra-bot/src/index.ts b/examples/mastra-bot/src/index.ts index c39b79c3f..919271330 100644 --- a/examples/mastra-bot/src/index.ts +++ b/examples/mastra-bot/src/index.ts @@ -3,6 +3,7 @@ import { EventEncoder } from "@ag-ui/encoder"; import { openai } from "@ai-sdk/openai"; import { Agent } from "@mastra/core/agent"; import { serve } from "bun"; +import { listenPort } from "../../shared/listen-port"; /** * A Bot written in Mastra. @@ -16,7 +17,12 @@ import { serve } from "bun"; * as `agent-bot` and the LangGraph example. */ -const PORT = Number.parseInt(process.env.PORT ?? "4400", 10); +const resolvedPort = listenPort(process.env.PORT, 4400); +if (!resolvedPort.ok) { + console.error(resolvedPort.reason); + process.exit(1); +} +const PORT = resolvedPort.port; const MODEL = process.env.BOT_MODEL ?? "gpt-5.5"; /** * `gpt-5.6-*` rejects function tools on `/v1/chat/completions` and needs the Responses API, which