Skip to content

fix(core): preserve relatedRequestId 0 in debounce guard#2135

Open
kiranmagic7 wants to merge 1 commit into
modelcontextprotocol:mainfrom
kiranmagic7:kiran/related-request-id-zero-debounce
Open

fix(core): preserve relatedRequestId 0 in debounce guard#2135
kiranmagic7 wants to merge 1 commit into
modelcontextprotocol:mainfrom
kiranmagic7:kiran/related-request-id-zero-debounce

Conversation

@kiranmagic7

Copy link
Copy Markdown

What changed

  • Treat relatedRequestId as present unless it is undefined when deciding whether a notification can be debounced.
  • Add a regression test for two same-tick debounced notifications with relatedRequestId: 0.
  • Add a patch changeset for @modelcontextprotocol/core.

Why

0 is a valid MCP/JSON-RPC request id. The previous truthiness check treated relatedRequestId: 0 as absent, so simple request-associated notifications could be coalesced by the debounce path while non-zero ids were sent immediately.

Fixes #2117.

Tests

  • pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts -t "relatedRequestId 0" — passes
  • pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts — 151 tests pass
  • pnpm --filter @modelcontextprotocol/core test — 553 tests pass
  • pnpm --filter @modelcontextprotocol/core typecheck — passes
  • pnpm --filter @modelcontextprotocol/core lint — passes
  • pnpm changeset status --since origin/main — reports @modelcontextprotocol/core patch bump

Compatibility / risk

Small behavior fix only: notifications already associated with non-zero request ids bypass debounce; this makes request id 0 follow the same path. Notifications without a related request id remain debounced as before.

@kiranmagic7 kiranmagic7 requested a review from a team as a code owner May 21, 2026 00:38
@changeset-bot

changeset-bot Bot commented May 21, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 69db244

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modelcontextprotocol/core Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented May 21, 2026

Copy link
Copy Markdown

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@2135

@modelcontextprotocol/codemod

npm i https://pkg.pr.new/@modelcontextprotocol/codemod@2135

@modelcontextprotocol/core

npm i https://pkg.pr.new/@modelcontextprotocol/core@2135

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@2135

@modelcontextprotocol/server-legacy

npm i https://pkg.pr.new/@modelcontextprotocol/server-legacy@2135

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@2135

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@2135

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@2135

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@2135

commit: 69db244

@kiranmagic7 kiranmagic7 force-pushed the kiran/related-request-id-zero-debounce branch from ab47799 to 5d11cba Compare June 1, 2026 00:34
@kiranmagic7

kiranmagic7 commented Jun 1, 2026

Copy link
Copy Markdown
Author

Rebased this on current main (head 5d11cba3). Local verification after the rebase:

  • pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts -t "relatedRequestId 0" - 1 passed
  • pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts - 151 passed
  • pnpm --filter @modelcontextprotocol/core test - 553 passed
  • pnpm --filter @modelcontextprotocol/core typecheck - passed
  • pnpm --filter @modelcontextprotocol/core lint - passed
  • pnpm changeset status --since origin/main - reports @modelcontextprotocol/core patch bump

GitHub checks have now completed successfully on the refreshed head.

@kiranmagic7 kiranmagic7 force-pushed the kiran/related-request-id-zero-debounce branch from 5d11cba to 2b6b644 Compare June 3, 2026 00:35
@kiranmagic7

Copy link
Copy Markdown
Author

Rebased this on current main and resolved the packages/core/src/shared/protocol.ts conflict. Latest head is 2b6b644c0dc92f7bc47d59b25f5f31b934459ee1.

Local verification after the rebase:

pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts -t "relatedRequestId 0"
PASS: 1 file, 1 test

pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts
PASS: 1 file, 31 tests

pnpm --filter @modelcontextprotocol/core test
PASS: 20 files, 368 tests

pnpm --filter @modelcontextprotocol/core typecheck
PASS

pnpm --filter @modelcontextprotocol/core lint
PASS

pnpm changeset status --since origin/main
PASS: reports @modelcontextprotocol/core patch bump

git diff --check origin/main...HEAD
PASS

GitHub now reports the branch as mergeable again; checks are running on the refreshed head.

@kiranmagic7

Copy link
Copy Markdown
Author

Friendly follow-up: this still looks ready for maintainer/code-owner review. Latest head 2b6b644c0dc92f7bc47d59b25f5f31b934459ee1 is mergeable from the PR view, all 13 GitHub checks are passing, and the focused relatedRequestId 0 regression verification is in the previous update. Happy to adjust anything maintainers want changed.

@kiranmagic7 kiranmagic7 force-pushed the kiran/related-request-id-zero-debounce branch from 2b6b644 to 72f0af9 Compare June 9, 2026 00:08
@kiranmagic7

Copy link
Copy Markdown
Author

Rebased this on current main and refreshed the branch. Latest head is 72f0af98.

Local verification after the rebase:

pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts -t "relatedRequestId 0"
PASS: 1 file, 1 test

pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts
PASS: 1 file, 31 tests

pnpm --filter @modelcontextprotocol/core test
PASS: 22 files, 464 tests

pnpm --filter @modelcontextprotocol/core typecheck
PASS

pnpm --filter @modelcontextprotocol/core lint
PASS

pnpm changeset status --since origin/main
PASS: reports @modelcontextprotocol/core patch bump

git diff --check origin/main...HEAD
PASS

GitHub checks should restart on the refreshed head.

@kiranmagic7 kiranmagic7 force-pushed the kiran/related-request-id-zero-debounce branch from 72f0af9 to 6da1da1 Compare June 11, 2026 15:03
@kiranmagic7

Copy link
Copy Markdown
Author

Rebased this on current main and refreshed the branch. Latest head is 6da1da1f.

Local verification after the rebase:

pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts -t "relatedRequestId 0"
PASS: 1 file, 1 test

pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts
PASS: 1 file, 31 tests

pnpm --filter @modelcontextprotocol/core test
PASS: 23 files, 474 tests

pnpm --filter @modelcontextprotocol/core typecheck
PASS

pnpm --filter @modelcontextprotocol/core lint
PASS

pnpm changeset status --since origin/main
PASS: reports @modelcontextprotocol/core patch bump

git diff --check origin/main...HEAD
PASS

GitHub checks should restart on the refreshed head.

@kiranmagic7 kiranmagic7 force-pushed the kiran/related-request-id-zero-debounce branch from 6da1da1 to cb7b48d Compare June 12, 2026 05:34
@kiranmagic7

kiranmagic7 commented Jun 12, 2026

Copy link
Copy Markdown
Author

Rebased this on current main and refreshed the branch. Latest head is cb7b48da.

Local verification after the rebase:

pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts -t "relatedRequestId 0"
PASS: 1 file, 1 test

pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts
PASS: 1 file, 31 tests

pnpm --filter @modelcontextprotocol/core test
PASS: 23 files, 474 tests

pnpm --filter @modelcontextprotocol/core typecheck
PASS

pnpm --filter @modelcontextprotocol/core lint
PASS

pnpm changeset status --since origin/main
PASS: reports @modelcontextprotocol/core patch bump

git diff --check origin/main...HEAD
PASS

GitHub checks completed successfully on the refreshed head: 13/13 visible checks passing.

@kiranmagic7 kiranmagic7 force-pushed the kiran/related-request-id-zero-debounce branch from cb7b48d to ae8e282 Compare June 13, 2026 05:34
@kiranmagic7

Copy link
Copy Markdown
Author

Rebased this on current main and refreshed the branch. Latest head is ae8e2827.

Local verification after the rebase:

pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts -t "relatedRequestId 0"
PASS: 1 file, 1 test

pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts
PASS: 1 file, 31 tests

pnpm --filter @modelcontextprotocol/core test
PASS: 23 files, 474 tests

pnpm --filter @modelcontextprotocol/core typecheck
PASS

pnpm --filter @modelcontextprotocol/core lint
PASS

pnpm changeset status --since origin/main
PASS: reports @modelcontextprotocol/core patch bump

git diff --check origin/main...HEAD
PASS

GitHub checks completed successfully on the refreshed head: 13/13 visible checks passing.

@kiranmagic7 kiranmagic7 force-pushed the kiran/related-request-id-zero-debounce branch from ae8e282 to 2771a65 Compare June 15, 2026 15:09
@kiranmagic7

Copy link
Copy Markdown
Author

Rebased this on current main again (new head: 2771a652). Focused test still passes:

pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts -t "relatedRequestId 0"
✓ test/shared/protocol.test.ts (31 tests | 30 skipped) 5ms
1 passed

No logic change — rebase only. Waiting on required review.

@kiranmagic7 kiranmagic7 force-pushed the kiran/related-request-id-zero-debounce branch from 2771a65 to 6916938 Compare June 16, 2026 15:06
@kiranmagic7

Copy link
Copy Markdown
Author

Rebased on current origin/main again (new head: 69169383). No logic change; rebase only.

Focused verification on the refreshed head:

pnpm install --frozen-lockfile
PASS

pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts -t "relatedRequestId 0"
PASS: 1 file passed, 1 test passed, 30 skipped

git diff --check origin/main...HEAD
PASS

GitHub checks should restart on the refreshed branch.

@kiranmagic7

Copy link
Copy Markdown
Author

Current status check on head 691693835ac56766bbd310f5dda6274f3912ef27: all 13 visible checks are passing, including test (22), test (24), runtime shards, e2e, server conformance, publint, and continuous releases. The branch is mergeable from the PR view and only needs maintainer review.

Review focus is still the narrow debounce-guard behavior: preserve relatedRequestId: 0 instead of treating it as absent. Happy to adjust anything maintainers want changed.

@kiranmagic7 kiranmagic7 force-pushed the kiran/related-request-id-zero-debounce branch from 6916938 to 48a32db Compare June 25, 2026 15:04
@kiranmagic7

Copy link
Copy Markdown
Author

Rebased this on current main to clear the behind state. New head: 48a32db00f84a039d0a6d0d0a1907d5d899eb91e.

Validation on the refreshed head:

git diff --check
PASS

pnpm --filter @modelcontextprotocol/core exec vitest run test/shared/protocol.test.ts -t "relatedRequestId 0"
PASS: 1 file, 1 test, 30 skipped

pnpm --filter @modelcontextprotocol/core typecheck
PASS

pnpm changeset status --since origin/main
PASS: @modelcontextprotocol/core patch bump listed

The PR-visible diff is still limited to the debounce guard, the regression test, and the patch changeset.

@kiranmagic7 kiranmagic7 force-pushed the kiran/related-request-id-zero-debounce branch from 48a32db to a108cf1 Compare June 26, 2026 05:36
@kiranmagic7

Copy link
Copy Markdown
Author

Rebased on current main to clear the dirty state. New head: a108cf1cbacb9857df8f8e94bb490ce9874ec1de.

Upstream moved the protocol implementation/tests into packages/core-internal, and the rebase kept the PR diff scoped to that debounce guard, the focused regression test, and the patch changeset.

Validation on the refreshed head:

pnpm install --frozen-lockfile
PASS

pnpm --filter @modelcontextprotocol/core-internal exec vitest run test/shared/protocol.test.ts -t "relatedRequestId 0"
PASS: 1 file, 1 test, 30 skipped

pnpm --filter @modelcontextprotocol/core-internal exec vitest run test/shared/protocol.test.ts
PASS: 1 file, 31 tests

pnpm --filter @modelcontextprotocol/core-internal typecheck
PASS

pnpm --filter @modelcontextprotocol/core-internal lint
PASS

pnpm changeset status --since origin/main
PASS: @modelcontextprotocol/core patch bump listed

git diff --check origin/main...HEAD
PASS

GitHub checks are running on the refreshed branch.

@kiranmagic7 kiranmagic7 force-pushed the kiran/related-request-id-zero-debounce branch from a108cf1 to 69db244 Compare June 26, 2026 15:03
@kiranmagic7

Copy link
Copy Markdown
Author

Rebased on current main again to clear the behind state. New head: 69db244499cf2f6f29accdab3f026dfdbff9c4fd.

Local verification on the refreshed head:

git diff --check origin/main...HEAD
pnpm --filter @modelcontextprotocol/core-internal exec vitest run test/shared/protocol.test.ts -t "relatedRequestId 0"   # 1 passed, 39 skipped
pnpm --filter @modelcontextprotocol/core-internal exec vitest run test/shared/protocol.test.ts                         # 40 passed
pnpm --filter @modelcontextprotocol/core-internal typecheck
pnpm --filter @modelcontextprotocol/core-internal lint
pnpm changeset status --since origin/main   # @modelcontextprotocol/core patch bump

Hosted checks are green on this head as well: build, test (20/22/24), e2e (20/22/24), runtime tests, conformance, examples, pkg-publish, and Continuous Releases all 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.

relatedRequestId 0 is treated as absent by notification debounce guard

1 participant