Commit b32ba5f
authored
fix(core,nestjs): restore scheduled workflow and prefix handling (#16637)
## Description
This replaces #16113 with the two pieces that are still relevant on
latest main.
It loads the evented workflow registration from the public
`@mastra/core/workflows` barrel so scheduled workflows created from that
entry point promote correctly.
It also makes the NestJS adapter treat requests outside the configured
prefix as non-Mastra routes, including partial prefix matches like
`/apiish/agents` when the prefix is `/api`.
The query coercion changes from #16113 are intentionally not included
because #16268 already fixed that behavior.
## Related issue(s)
Fixes #16112
## Type of change
- [x] Bug fix (non-breaking change that fixes an issue)
- [ ] New feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [ ] Documentation update
- [ ] Code refactoring
- [x] Test update
## Checklist
- [x] I have linked the related issue(s) in the description above
- [x] I have made corresponding changes to the documentation (if
applicable)
- [x] I have added tests that prove my fix is effective or that my
feature works
- [ ] I have addressed all Coderabbit comments on this PR
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## ELI5
This PR fixes two bugs: scheduled workflows imported from the public
workflows entry now register and promote correctly, and the NestJS
adapter only treats requests that truly match the configured prefix as
Mastra routes (so similar-but-different paths like `/apiish/agents` are
ignored).
## Changes Overview
### Core workflow registration
- Ensure evented workflow registration is triggered when consumers
import from the public @mastra/core/workflows barrel by referencing the
evented creator in packages/core/src/workflows/index.ts (imports
createWorkflow from ./evented and keeps a live reference).
- Restores promotion of scheduled workflows declared via the public
barrel while avoiding ESM initialization cycles.
- Tests updated: schedule-promotion.test.ts removed the transitive
side-effect import and now relies on createWorkflow from ./index.
### NestJS route prefix enforcement
- server-adapters/nestjs/src/utils/route-path.ts
- getMastraRoutePath(path, prefix) now returns string | null and returns
null when the path is outside the normalized prefix (only exact prefix
or prefix + '/' are accepted).
- server-adapters/nestjs/src/guards/mastra-route.guard.ts
- If getMastraRoutePath returns null, the guard short-circuits (returns
true) so Mastra auth/rate-limit logic is skipped for non-Mastra routes.
- server-adapters/nestjs/src/controllers/mastra.controller.ts
- handleRequest throws NotFoundException when getMastraRoutePath returns
falsy; normal request handling proceeds for matched routes and
double-slash paths are rejected.
- server-adapters/nestjs/src/interceptors/tracing.interceptor.ts
- Only attempts route matching when a routePath exists; otherwise
matchResult is null to avoid matching on out-of-prefix requests.
- Added tests: server-adapters/nestjs/src/__tests__/route-path.test.ts
covering prefix normalization, exact-match-to-root mapping, and
rejection of out-of-prefix / partial-prefix paths.
### Import refactoring to avoid barrel cycles
- Multiple core files updated to import workflow primitives from
specific modules (e.g., workflows/workflow, workflows/step,
workflows/types) instead of the aggregated workflows barrel to avoid ESM
import cycles while preserving runtime behavior and public APIs (several
updates across agent, evals, loop, and workflow/evented files).
### Changesets and release notes
- .changeset updates to publish patch releases:
- @mastra/core: note that scheduled workflows created via the public
workflows entry now correctly apply declared schedules.
- @mastra/nestjs: note that configured route prefixes are enforced and
partial prefix matches are ignored.
### Tests
- schedule-promotion tests rely on the public barrel behavior (removed
transitive import).
- New Vitest suite for getMastraRoutePath validates strict prefix
handling and normalization.
### Notes
- Query coercion changes from the previously related PR are
intentionally excluded because PR #16268 already addressed that
behavior.
- Classified as a bug fix; fixes issue #16112.
<!-- review_stack_entry_start -->
[](https://app.coderabbit.ai/change-stack/mastra-ai/mastra/pull/16637)
<!-- review_stack_entry_end -->
<!-- end of auto-generated comment: release notes by coderabbit.ai -->1 parent 7bc78d9 commit b32ba5f
31 files changed
Lines changed: 109 additions & 61 deletions
File tree
- .changeset
- packages/core/src
- agent
- workflows/prepare-stream
- evals
- run
- loop
- network
- workflows
- agentic-execution
- agentic-loop
- workflows
- evented
- server-adapters/nestjs/src
- __tests__
- controllers
- guards
- interceptors
- utils
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
83 | | - | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
84 | 86 | | |
85 | 87 | | |
86 | 88 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
| 31 | + | |
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
0 commit comments