Skip to content

fix(init): make the scaffolded starter find the runtime and explain when it can't - #217

Merged
AbirAbbas merged 2 commits into
mainfrom
fix/init-starter-runtime-url
Sep 2, 2026
Merged

fix(init): make the scaffolded starter find the runtime and explain when it can't#217
AbirAbbas merged 2 commits into
mainfrom
fix/init-starter-runtime-url

Conversation

@AbirAbbas

Copy link
Copy Markdown
Contributor

Summary

Follow-up to #216, from the next thing the reporter hit. af-stack init my-ai-product then npm start printed "Could not reach the backend" followed by a raw AgentField 404 body. Two causes, both in the scaffolded starter:

  • It assumed the runtime is at localhost:8080, and could not tell "nothing there" from "something else there". af-stack dev deliberately moves the API off 8080 whenever the port is busy (on the reporter's machine 8080 is an AgentField control plane), but the starter never said where the real URL comes from.
  • npm start never read .env. It ran plain node src/index.mjs, so the documented cp .env.example .env and "set AF_STACK_URL" had no effect at all.

Changes

  • The starter loads .env itself with no dependency (real environment wins), tolerates a pasted …/api/v1 suffix, and probes /health before its first call. It now distinguishes three failures and gives the fix for each: nothing listening, something listening that is not a BackAI runtime, and an auth rejection. Each points at the "API runtime" line of af-stack dev's output as the source of the URL.
  • The scaffold's next steps, README, and .env.example say the same thing.
  • Both af-stack dev banners print Your apps AF_STACK_URL=http://localhost:<port>, the exact line to copy, since the "API runtime" line ends in /api/v1 and is not what an app wants.

Verification

  • Six tests drive the real src/index.mjs with Node against fake backends: a BackAI runtime (lists agents, exit 0), .env honoured, /api/v1 suffix tolerated, a foreign server on the port (exit 1, names the cause and the fix), nothing listening (exit 1), and a 401 (names AF_STACK_API_KEY). They skip when node is absent.
  • Replayed the reporter's exact sequence against this machine's real port 8080, which is held by an AgentField container: the starter now prints "Something is listening at http://localhost:8080, but it is not a BackAI runtime" with the af-stack dev / AF_STACK_URL instructions.
  • Full go build, go vet, go test ./... pass; golangci-lint v2.13.1 in CI's new-issues mode reports 0 new issues.

🤖 Generated with Claude Code

AbirAbbas and others added 2 commits September 2, 2026 12:21
The starter `af-stack init <name>` writes assumed the runtime was at
localhost:8080 and, on any failure, printed "Could not reach the
backend" plus a raw response body. Two things made that wrong in
practice: `af-stack dev` moves the API off :8080 whenever the port is
busy (the reporter's :8080 was an AgentField control plane, whose 404
body the starter dumped verbatim), and `npm start` ran plain `node
src/index.mjs`, which never read .env — so the documented `cp
.env.example .env` and "set AF_STACK_URL" did nothing.

The starter now loads .env itself (no dependency; real env wins),
tolerates a pasted ".../api/v1" suffix, and probes /health before the
first call so it can tell the three cases apart: nothing listening,
something listening that is not a BackAI runtime, and an auth
rejection — each with the fix, including where the real URL comes from
("API runtime" in af-stack dev's output). The scaffold's next steps,
README, and .env.example say the same. Tests drive the real file with
node against fake backends for each case.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Abir Abbas <abirabbas1998@gmail.com>
Both "what runs where" banners list the API as ".../api/v1", which is
not what an app's AF_STACK_URL wants, and neither said which line to
copy when preflight had moved the port. Add "Your apps
AF_STACK_URL=http://localhost:<port>" to both.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Signed-off-by: Abir Abbas <abirabbas1998@gmail.com>
@AbirAbbas
AbirAbbas merged commit cbc63ae into main Sep 2, 2026
30 checks passed
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