Skip to content

Refuse an ended session in words true of it - #1484

Merged
jmrplens merged 4 commits into
issue-1053-discovery-ratefrom
issue-1102-session-sentence
Oct 22, 2026
Merged

jmrplens merged 4 commits into
issue-1053-discovery-ratefrom
issue-1102-session-sentence

Conversation

@jmrplens

@jmrplens jmrplens commented Oct 21, 2026 •

Copy link
Copy Markdown
Owner

Closes #1102.

This is the fifth layer of the authentication-budget stack, on top of the discovery documents' bucket of #1053. It changes the words of the gate's session refusal and nothing about when it refuses, as the decision of 2026-10-17 on the issue set out: one answer for both cases, no record of each credential's ended session IDs, an INFO line of its own for a session the process does not hold, and the WARN line for another credential's session kept.

What was wrong

On --stateless=false the gate answers 404 to a request whose Mcp-Session-Id names no session open for the credential it presents, and the answer said "This session does not belong to the presented credential." That is true of a session another credential opened. It is false of the case a client meets every day, its own session that idled out past --session-timeout, was deleted, went with its credential's pool entry, or was opened before a restart or on another replica: nothing that client presented belongs to anybody else, and the message told it otherwise. Row ADM-007 of the tenant policy register described only the first case too.

What changed

sessionOwnershipFailure in cmd/server/auth_gate.go now answers "This session is not open for the presented credential. Start a new session by sending initialize without a session ID.", which is true of both cases. The status, the code (-32600) and when it is answered are unchanged. I kept one answer rather than two because answering the cases apart would tell a caller whether another credential holds the ID, which INV-019 forbids, and because it would need a record of each credential's ended session IDs, state keyed on a value the caller mints, with a row and a capacity of its own.

checkSessionOwnership tells the cases apart in the log instead. Another credential's session keeps its WARN line, request rejected: session ID does not belong to the presented credential, word for word, since it is true of that case and an operator may already alert on it. An ID the process does not hold gets an INFO line, request rejected: session ID names no session open in this process, through the same once-a-minute throttle as the gates' other refusal lines, since a caller can send any ID it likes. Neither names the ID.

Row ADM-007 in internal/tenancy/decisions_admit.go moves with the gate: its resource is now "a session ID that names no session open for the presented credential", its refusal prefix is the new first sentence, and it records issue 1102's decision. It stays a rule with no value, no table and no capacity, which is the half of the decision a test holds it to.

The e2e phrase the go-sdk client pins expect (test/e2e/http/session_not_found_test.go) and row 68 of docs/development/upstream-bugs.md quote the new words. Row 68 no longer says the call path shows the wrong cause; what a go-sdk v1.8.0 client is left with there is a true refusal on a connection that looks alive, with an error that does not wrap ErrSessionMissing. The HTTP server page, in English and Spanish, says the 404 answers both cases alike, why, and which log line names each, and its refusal table now names that row's condition as ADM-007 does, "an Mcp-Session-Id that names no session open for the presented credential", where it said one "this deployment did not open", which is false of the client's own session that ended.

A last commit puts resolve's doc comment back on resolve. It had drifted above the Mcp-Session-Id header constant beside the check this changes, so godoc read it as part of the constant's comment and resolve had none.

How I tested it

Tests first, each shown red on the parent as it stood before the stack was rebased onto main (3df394937, now b37e82899) and green on this branch:

  • TestDecisions_EachRowIsWhatTheSpecificationSays/ADM-007 pins the new prefix, and TestDecisions_SessionRefusal_IsOneAnswerByIssue1102 pins the resource, the recorded decision, the absence of any value, table or capacity, and the one refusal.
  • TestMcpServerGate_CheckSessionOwnership_RefusesASessionFromAnotherCredential now holds every refusal (another credential's session, an ID never recorded, a session whose credential was evicted) to the same code and the same full text, and asserts the log: the WARN line for the first, the INFO line for the other two, and neither for a request the check lets through. On the parent the text differed and the INFO line was missing.
  • TestMCPServerGate_EachRefusal_CarriesItsOwnStatusAndCode drives a real foreign session (its old case was in fact an unrecorded ID) and an unrecorded one through the middleware. Since both are answered alike, each also asserts the line the session check logged, WARN for the foreign session and INFO for the unrecorded one, and every other case that it logged neither; without that, a foreign session whose ID was never recorded passes as one, which is how the old case went unnoticed. I checked that both ways: with the foreign case's ID swapped for an unrecorded one, the table without the log assertion still passes and this one fails on the log line. TestMcpServerGate_Middleware_RefusesASessionMintedForAnotherCredential holds POST, GET and DELETE to the full text.
  • TestGate_SessionRefusal_IsOneAnswerOnTheWireAndTwoLinesInTheLog in test/e2e/http drives the binary: another credential's session and an ID the process does not hold are answered with byte-identical bodies, and the server's stderr carries the WARN line for the first and the INFO line for the second. The two go-sdk pins of row 68 pass with the new phrase.

Results on this branch: go test ./internal/tenancy/... ./cmd/server/... ./cmd/audit_tenancy/... passes; make check-tenancy reports 0 findings over 89 rows; make test-e2e-http passes, 708 tests with 8 skipped for want of Docker; statement coverage is 100.0% for cmd/server and internal/tenancy; gobco conditions are 2356/2356 for cmd/server and 454/454 for internal/tenancy; make coverage-mutants over the whole of each package, no file excluded, reports Lived 0 and Timed out 0 on cmd/server (1301 killed, the five in checkSessionOwnership among them, in 3 hours 7 minutes) and on internal/tenancy (255 killed). The 47 and 66 it calls not covered are the tool artifact docs/development/testing/README.md describes, mutations in package-level constant and variable initializers, which carry no statement counter (the gate's error codes and message concatenations, the HTTP timeouts and other durations, the env flag names, the listen endings' and subscription errors' texts, the register's codes, values and iota enumerations), plus two in socket_mode_windows.go and conn_refused_windows.go, which are not compiled on Linux; none is on a line this branch touches; golangci-lint is clean on both packages under e2e and on test/e2e/http under httpe2e; go test -tags e2e -c compiles test/e2e/gitlab/...; make check-test-subtests, check-test-goroutines, check-test-file-names, check-action-ids, check-dead-consts, check-doc-tool-names, check-md-escaping and check-e2e-static and the godoc audit pass; markdownlint, the Markdown table check, the doc link check, and the site's i18n, facts, chips, llms, build and lint checks pass.

I then rebased the stack onto main at a0e4e6cf6, with no conflict and every commit's patch unchanged, so the results above were measured on the branch as it stood on 19746966465. Of the packages this layer touches, main moved cmd/server in two test files (#1472). At this head go build ./..., go vet, golangci-lint --build-tags e2e and go test on cmd/server and internal/tenancy pass, each still at 100.0% of statements, and so do the tests of cmd/audit_tenancy, also at 100.0%; make check-tenancy still reports 0 findings over 89 rows; make test-e2e-http passes with the same 708 tests; and make check-closed-servers and make check-godocs, the two gates main gained since (#1474, #1478), pass. The gobco figures count the conditions of code main did not change, so they stand; I did not repeat the three-hour mutation run.

Tenant policy checklist

This changes a refusal's text and a row's resource, not a limit. VAL-001 to VAL-006, VAL-008, VAL-009 and VAL-011 are unchanged on ADM-007 (Admit, keyed on the session, class C, a rule, nothing kept, not charged, no value, none on stdio). VAL-007 is the change: the gate's 404 with -32600, no Retry-After and no challenge, answer "start over", now in words true of both cases. VAL-010: with telemetry on, the new INFO line is exported as a log record, as the WARN line beside it already is; it carries no attribute but the throttle's count of repeats it held back, so it names no session ID and no credential, and no metric, span or reason changes. VAL-012 does not apply, since nothing here protects one population from another.

The generated testing reference gains the new tests' entries when the top of the stack regenerates it, as the stack's other layers leave theirs.

On --stateless=false the gate answers 404 to a request whose session ID
names no session open for the presented credential, and it said "This
session does not belong to the presented credential." That is true of a
session another credential opened and false of the commoner case, a
client's own session that idled out, was deleted, went with its
credential's pool entry, or was opened before a restart or on another
replica: nothing that client presented belongs to anybody else.

The refusal now says "This session is not open for the presented
credential. Start a new session by sending initialize without a session
ID.", which is true of both. Answering the two apart would tell a caller
whether another credential holds the ID, which INV-019 forbids, and
would need a record of each credential's ended session IDs, keyed on a
value the caller mints. The log tells them apart instead: the WARN line
for another credential's session stays, and an ID the process does not
hold gets an INFO line of its own, throttled like the gates' other
refusal lines.

Row ADM-007 moves with the gate: its resource names both cases, its
refusal the new words, and it records issue 1102's decision. The unit
pins and the e2e phrase the go-sdk client pins expect follow it.
The HTTP module opens a stateful session, presents its ID under another
credential and presents an ID no session was opened under with the
owner's own, which is the state an idle timeout, an eviction or a
restart leaves. Both are answered with the same bytes, a 404 carrying
-32600 and the one sentence, and the server's log carries the WARN line
for the first and the INFO line for the second.
Row 68 of the upstream register quotes the gate's new words and no
longer says the call path shows the wrong cause: what a go-sdk client is
left with there is a refusal on a connection that looks alive, with an
error that does not wrap ErrSessionMissing. The HTTP server page, in
English and Spanish, says the 404 answers another credential's session
and an ended one alike, why, and which log line names each, and its
refusal table names that row's condition as ADM-007 does, an ID that
names no session open for the presented credential, rather than one the
deployment did not open, which is false of a client's own ended session.
The two lines that describe mcpServerGate.resolve had drifted above the
Mcp-Session-Id header constant, so godoc read them as part of the
constant's comment and resolve had none. They sit on resolve again.
@jmrplens
jmrplens added this pull request to stack #1486 October 21, 2026 23:21
@sourcery-ai

sourcery-ai Bot commented Oct 21, 2026

Copy link
Copy Markdown

Sorry @jmrplens, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 4 days and 20 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@greptile-apps greptile-apps 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.

jmrplens has reached the 50-credit limit for trial accounts. To continue receiving code reviews, upgrade your plan.

@coderabbitai

coderabbitai Bot commented Oct 21, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 59 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: jmrplens/gitlab-mcp-server/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: af59c350-b96b-4c3b-ad3d-cc2d7557611e
📥 Commits

Reviewing files that changed from the base of the PR and between b37e828 and 7ca1b41.

📒 Files selected for processing: 9
  • cmd/server/auth_gate.go
  • cmd/server/auth_gate_test.go
  • docs/development/upstream-bugs.md
  • internal/tenancy/decisions_admit.go
  • internal/tenancy/decisions_test.go
  • site/src/content/docs/es/operations/http-server.mdx
  • site/src/content/docs/operations/http-server.mdx
  • test/e2e/http/gate_test.go
  • test/e2e/http/session_not_found_test.go
  • 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

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

@jmrplens jmrplens added this to the 3.4.0 milestone Oct 21, 2026
@jmrplens jmrplens changed the title issue 1102 session sentence Refuse an ended session in words true of it Oct 21, 2026
@github-actions github-actions Bot added the transport stdio and HTTP transports, the server process, and the transport e2e modules label Oct 21, 2026
@sonarqubecloud

Copy link
Copy Markdown

@jmrplens
jmrplens merged commit b6a6eb0 into main Oct 22, 2026
39 checks passed
@jmrplens
jmrplens deleted the issue-1102-session-sentence branch October 22, 2026 03:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

transport stdio and HTTP transports, the server process, and the transport e2e modules v3.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

A client's own ended session is refused as a session that does not belong to its credential

1 participant