Skip to content

fix(runtime): enforce basePath segment boundary in single-route mode - #7341

Merged
lukasmoschitz merged 2 commits into
CopilotKit:mainfrom
remote-controlled-man:codex/copilotkit-single-route-basepath
Sep 28, 2026
Merged

lukasmoschitz merged 2 commits into
CopilotKit:mainfrom
remote-controlled-man:codex/copilotkit-single-route-basepath

Conversation

@remote-controlled-man

@remote-controlled-man remote-controlled-man commented Sep 22, 2026 •

Copy link
Copy Markdown

What

In single-route mode, the basePath check in resolveSingleRoute used a bare startsWith, so a path that merely shares a string prefix with the configured base was accepted as a runtime endpoint. With basePath: "/api/copilotkit", a POST to /api/copilotkit-extra with a valid envelope (e.g. {"method":"info"}) is served 200 with runtime info instead of 404.

Multi-route mode already guards this: matchRoute requires the character after basePath to be / or end-of-string (fetch-router.ts), with a pinned regression test that /api/copilotkitextra/info does not match (matchRoute returns null, so the handler answers 404). This change applies the same boundary rule to single-route mode, keeping the / basePath "match everything" special case intact.

Reachability: the documented headless setups (Bun.serve({ fetch: handler }), Deno.serve(handler)) forward every request path to the handler, so prefix-colliding paths are realistically reachable there; the Express/Hono adapters mask this with their own exact routing, which is why the fix belongs in the shared handler.

Test

New regression test in single-route-resource-operations.test.ts: a POST to /api/copilotkit-extra (string-prefix collision with the configured /api/copilotkit base) must 404. RED on base (returns 200 today), GREEN after the fix.

  • @copilotkit/runtime test suite — 2552 passed (184 files), including the new test.
  • pnpm run check-types — clean.

No changeset / version bump per repo conventions.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed single-route request handling so paths that only share a text prefix with the configured base path now correctly return a 404 response.
    • Requests must match the base path exactly or continue with a path separator; the root path remains supported for all routes.

Copilot AI lite review requested due to automatic review settings September 22, 2026 02:39

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@coderabbitai

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

⚙️ Run configuration

Configuration used: Repository: CopilotKit/CopilotKit/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: 454fbcb6-7846-4622-a02b-a2c0c4dfeaaf

📥 Commits

Reviewing files that changed from the base of the PR and between efe7cc7 and 9a09cbf.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository: CopilotKit/CopilotKit/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: edc041c4-b897-4c55-9795-3e2dc9ce791d

📥 Commits

Reviewing files that changed from the base of the PR and between 5eec9b0 and efe7cc7.

📒 Files selected for processing (2)
  • packages/runtime/src/v2/runtime/__tests__/single-route-resource-operations.test.ts
  • packages/runtime/src/v2/runtime/core/fetch-handler.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

Single-route resolution now requires an exact base-path match or a following /. The root base path remains unrestricted. A regression test verifies that /api/copilotkit-extra returns 404 when the base path is /api/copilotkit.

Changes

Single-route boundary validation

Layer / File(s) Summary
Enforce base-path segment boundaries
packages/runtime/src/v2/runtime/core/fetch-handler.ts, packages/runtime/src/v2/runtime/__tests__/single-route-resource-operations.test.ts
resolveSingleRoute rejects non-segment prefixes while preserving exact matches, child paths, and root-path matching. The test verifies a 404 response for /api/copilotkit-extra.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: tylerslaton

Merge Risk: ⚪ Minimal · up to efe7c

Single-route requests with lookalike base paths now return 404 without affecting valid routes. The focused regression coverage supports merging with normal checks.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: enforcing a basePath segment boundary in single-route runtime mode.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Sep 28, 2026

Copy link
Copy Markdown
@copilotkit/a2ui-renderer

pnpm add https://pkg.pr.new/@copilotkit/a2ui-renderer@7341

@copilotkit/agentcore-runner

pnpm add https://pkg.pr.new/@copilotkit/agentcore-runner@7341

@copilotkit/angular

pnpm add https://pkg.pr.new/@copilotkit/angular@7341

@copilotkit/channels

pnpm add https://pkg.pr.new/@copilotkit/channels@7341

@copilotkit/channels-core

pnpm add https://pkg.pr.new/@copilotkit/channels-core@7341

@copilotkit/channels-discord

pnpm add https://pkg.pr.new/@copilotkit/channels-discord@7341

@copilotkit/channels-intelligence

pnpm add https://pkg.pr.new/@copilotkit/channels-intelligence@7341

@copilotkit/channels-slack

pnpm add https://pkg.pr.new/@copilotkit/channels-slack@7341

@copilotkit/channels-teams

pnpm add https://pkg.pr.new/@copilotkit/channels-teams@7341

@copilotkit/channels-telegram

pnpm add https://pkg.pr.new/@copilotkit/channels-telegram@7341

@copilotkit/channels-ui

pnpm add https://pkg.pr.new/@copilotkit/channels-ui@7341

@copilotkit/channels-whatsapp

pnpm add https://pkg.pr.new/@copilotkit/channels-whatsapp@7341

@copilotkit/core

pnpm add https://pkg.pr.new/@copilotkit/core@7341

@copilotkit/intelligence-langgraph

pnpm add https://pkg.pr.new/@copilotkit/intelligence-langgraph@7341

@copilotkit/intelligence-mastra

pnpm add https://pkg.pr.new/@copilotkit/intelligence-mastra@7341

@copilotkit/mcp-apps-renderer

pnpm add https://pkg.pr.new/@copilotkit/mcp-apps-renderer@7341

@copilotkit/react-core

pnpm add https://pkg.pr.new/@copilotkit/react-core@7341

@copilotkit/react-native

pnpm add https://pkg.pr.new/@copilotkit/react-native@7341

@copilotkit/react-textarea

pnpm add https://pkg.pr.new/@copilotkit/react-textarea@7341

@copilotkit/react-ui

pnpm add https://pkg.pr.new/@copilotkit/react-ui@7341

@copilotkit/runtime

pnpm add https://pkg.pr.new/@copilotkit/runtime@7341

@copilotkit/runtime-client-gql

pnpm add https://pkg.pr.new/@copilotkit/runtime-client-gql@7341

@copilotkit/sdk-js

pnpm add https://pkg.pr.new/@copilotkit/sdk-js@7341

@copilotkit/shared

pnpm add https://pkg.pr.new/@copilotkit/shared@7341

@copilotkit/sqlite-runner

pnpm add https://pkg.pr.new/@copilotkit/sqlite-runner@7341

@copilotkit/voice

pnpm add https://pkg.pr.new/@copilotkit/voice@7341

@copilotkit/vue

pnpm add https://pkg.pr.new/@copilotkit/vue@7341

@copilotkit/web-components

pnpm add https://pkg.pr.new/@copilotkit/web-components@7341

@copilotkit/web-inspector

pnpm add https://pkg.pr.new/@copilotkit/web-inspector@7341

commit: 9a09cbf

@lukasmoschitz
lukasmoschitz merged commit 15437bb into CopilotKit:main Sep 28, 2026
60 checks passed
@remote-controlled-man
remote-controlled-man deleted the codex/copilotkit-single-route-basepath branch October 13, 2026 01:25
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.

3 participants