Skip to content

test(mcpgateway): wait for the background session close before the recovery check - #1623

Open
SantiagoDePolonia wants to merge 1 commit into
mainfrom
fix/mcpgateway-flaky-unverified-limit-test
Open

SantiagoDePolonia wants to merge 1 commit into
mainfrom
fix/mcpgateway-flaky-unverified-limit-test

Conversation

@SantiagoDePolonia

@SantiagoDePolonia SantiagoDePolonia commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Description

TestHostEndsASessionItCannotRecheckForLong failed intermittently in CI with expected: 404, actual: 200 on its last request (for example on #1621, which does not touch internal/mcpgateway).

When the host ends a session it could not recheck, it unbinds it and closes the SDK session in the background (closeSessions). The test's next request finds no binding and no shared record, so it is passed to the SDK handler; if the background close has not finished yet, the SDK still knows the session and answers 200.

The test now waits for the hosted session to close before that request, as TestLongCallDoesNotReviveADeletedSession already does. Test-only change.

Delaying the background close by 30 ms reproduces the failure on every run; with the fix the whole package passes under the same delay.

View guided diff Turn on auto-fix

Summary by CodeRabbit

  • Tests
    • Expanded coverage for long outages to verify that a hosted session is closed after its host reaches the unverified limit, rather than only being unbound. No user-facing behavior changes are included in this update.

@github-actions github-actions Bot added the size:XS 0-9 effective changed lines (test files excluded in mixed PRs). label Nov 27, 2026
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

Automatic approval withheld

Assessment Current risk Maximum for approval
Merge risk Minimal Moderate
Security architecture risk Unavailable for this commit Low

Commit: 97b58f57ec0e.

No actionable comments were generated in the recent review.

Walkthrough

The long-outage test now captures the hosted server from the session binding and verifies that the hosted session eventually closes after the host reaches its unverified limit.

Changes: Hosted session closure

Layer / File(s) Summary
Capture and verify hosted session closure
internal/mcpgateway/sharedsessions_test.go
The test confirms that a session binding exists, saves its server, and waits for the hosted session to close after the host exceeds its unverified limit.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Change: Other

Possibly related PRs

Merge Risk: Minimal · up to 97b58

This is a test-only change that reduces flakiness in a session-closure test. It has no production impact, so merge risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the change: a test-only fix that waits for the background session close before the recovery check in mcpgateway. It matches the description and objectives, which describe the wait adde…
Description check Passed The description states the failure, its cause, and the fix. It names the affected test, the observed failure (expected 404, actual 200), the root cause (background closeSessions not finished before th…
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.
Full details: Title check

Explanation

The title names the change: a test-only fix that waits for the background session close before the recovery check in mcpgateway. It matches the description and objectives, which describe the wait added before the final request in TestHostEndsASessionItCannotRecheckForLong. The title uses a conventional test(scope) prefix and is 81 characters, slightly over the usual 72-character guideline but still readable.

Full details: Description check

Explanation

The description states the failure, its cause, and the fix. It names the affected test, the observed failure (expected 404, actual 200), the root cause (background closeSessions not finished before the next request), the fix (wait for the hosted session to close, as TestLongCallDoesNotReviveADeletedSession does), and the verification (a 30 ms delay reproduces the failure, and the package passes with the fix). It follows the template's Description section. The template's optional AI Generated section is absent, which is acceptable because it is optional.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

A rabbit checks the session’s place,
Then waits for closure, calm and keen.
The host rejects the stale request,
The server closes, as tests confirm.
The rabbit hops through logs of green.

Recent review info

Automatic approval policy

Commit: 97b58f57ec0e.

Setting Effective value Source
Automatic approvals Enabled Global configuration
Merge risk Moderate Global configuration
Security risk Low Global configuration

Not set means no limit was configured after inheritance. Use @coderabbitai configuration to inspect the resolved settings and their sources.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 7706c3a3-e873-4975-90a2-448f5bdc5316
Commits

Reviewing files that changed from the base of the PR and between 08a0111 and 97b58f5.

Files selected for processing: 1

  • internal/mcpgateway/sharedsessions_test.go

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 1 remain after this review.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 1 file

Auto-approved: Test-only change that fixes an intermittent flake by waiting for the background session close before performing the recovery check, without altering production behavior.

View guided diff | Turn on auto-fix | Re-trigger cubic

@greptile-apps

greptile-apps Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 · The change appears safe to merge.RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The change appears safe to merge.

Reviews (1) · Last reviewed commit: "test(mcpgateway): wait for the backgroun..." · Reviewed by Greptile

@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XS 0-9 effective changed lines (test files excluded in mixed PRs).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants