Skip to content

fix(core): batch multi-kind route entries as B4_E1008 - #722

Merged
blove merged 1 commit into
mainfrom
blove/batch-multi-export-routes
Sep 18, 2026
Merged

blove merged 1 commit into
mainfrom
blove/batch-multi-export-routes

Conversation

@blove

@blove blove commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #705, which batched the "no recognisable export" defect. This closes the same gap one layer over.

Problem

A route index.ts exporting more than one of agent, workflow, graph or chain threw a plain Error from inside the recursive route walk:

  • the message did not name the offending file (the runtime's copy in route-module-shape.ts does),
  • it carried no registry code, so no [B4_Exxxx] footer rendered — the one b4 check diagnostic with no docs link,
  • and it aborted the walk, so an app with several surfaced them one per run.

Change

classifyRouteExports (was inferRouteKind) returns a discriminated outcome — kind / multiple / unrecognised — instead of throwing. The walk collects every offending entry, and collectRouteDefinitions throws once as the new B4_E1008, naming each file and the kinds it exported.

2 route entries export more than one route kind:
  • Route entry /…/src/app/first/index.ts must export exactly one of "agent", "workflow", "graph", or "chain" (found: workflow, graph).
    Keep the one this route should run and remove the others, or move them into separate route directories.
  • Route entry /…/src/app/second/index.ts must export exactly one of "agent", "workflow", "graph", or "chain" (found: agent, chain).
    Keep the one this route should run and remove the others, or move them into separate route directories.

On the two codes. B4_E1007 (unrecognised) and B4_E1008 (too many kinds) are distinct defects with distinct codes, and one error carries one code — so an app with both cannot report everything in a single error. Rather than leave that as a silent second round, the B4_E1007 message states what is queued behind it:

Route entry /…/src/app/util/index.ts has no recognisable export (found: helper).
A route index.ts must export a default export of `agent(...)`, or exactly one of "agent", "workflow", "graph", or "chain".
If this directory is not a route, prefix its name with "_" to keep it out of route discovery.
Also: 2 route entries export more than one route kind, reported as B4_E1008 once the above are fixed.

Message compatibility. The substring must export exactly one of "agent", "workflow", "graph", or "chain" is preserved deliberately: isBoundaryError in packages/cli/src/lib/runtime/execute-route-core.ts classifies errors by matching it, and check-command, verify-command and run-command tests assert it.

Tests

  • The existing both-workflow-and-graph case now asserts the B4_E1008 code, the file path, and found: workflow, graph
  • Two multi-kind entries reported in one error
  • Both defects present → B4_E1007 first, with the queued B4_E1008 count
  • B4_E1008 added to the registry assertions in packages/sdk/test/errors.test.ts
  • verify-command.test.ts updated: b4 verify's JSON error now carries code: "B4_E1008", which is the verify-carries-error-codes behaviour working as intended on a defect that previously had no code

errors.mdx regenerated via pnpm docs:errors; cli.mdx documents the code and the two-code hand-off.

Verification

Gate Result
@b4run/core tests 48 files, 550 passed (discover-routes.test.ts 20/20)
@b4run/cli tests 168 files, 2017 passed, 4 skipped
@b4run/sdk / @b4run/langgraph 113 / 9 passed
@b4run/web tests 632 passed
pnpm lint / pnpm typecheck 29 / 54 tasks green

Both rendered messages were also checked through the built CLI's discovery path, not just in-process.

🤖 Generated with Claude Code

A route `index.ts` exporting more than one of `agent`, `workflow`, `graph`
or `chain` threw a plain `Error` from inside the recursive route walk: the
message did not name the offending file, it carried no registry code so no
`[B4_Exxxx]` footer rendered, and an app with several of them surfaced one
per run.

`classifyRouteExports` now returns this outcome instead of throwing, the
walk collects every offending entry, and `collectRouteDefinitions` throws
once as the new `B4_E1008`, naming each file and the kinds it exported.

The two discovery defects carry different codes and so cannot share one
error. When an app has both, the unrecognised entries (`B4_E1007`) are
reported first and the message states how many multi-kind entries are
queued behind them, so the second round is not a surprise.

The wording `must export exactly one of "agent", "workflow", "graph", or
"chain"` is preserved: the runtime's `isBoundaryError` classifier and three
CLI suites match on it.

Co-Authored-By: Claude Opus 5 <[email protected]>
@vercel

vercel Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
b4-run Ready Ready Preview Sep 18, 2026 12:48am UTC

Request Review

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated approval: this PR received an intelligent (AI) code review. See the review comments on this PR.

@blove
blove merged commit 80aa142 into main Sep 18, 2026
30 of 31 checks passed
@blove
blove deleted the blove/batch-multi-export-routes branch September 18, 2026 01:07

This branch was successfully deployed

1 active and 1 inactive deployments
Preview — ee713004 Deployed Sep 18, 2026 by vercel[bot]
vercel-preview — ee713004 Deployed Sep 18, 2026 by blove via vercel-native #2051
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