refactor(server): deduplicate session ID extraction into a shared helper#7158
Merged
Conversation
6 tasks
Copilot
AI
changed the title
[WIP] Fix duplicate code for session ID extraction from headers
refactor(server): deduplicate session ID extraction into a shared helper
Jun 7, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors the internal/server package to eliminate duplicated session ID extraction logic by introducing a single shared helper that reads X-Agent-ID / Authorization from an *http.Request and delegates precedence/validation to auth.ExtractSessionIDFromHeaders.
Changes:
- Added a package-private
extractSessionIDFromRequest(*http.Request) stringhelper ininternal/server/session.go. - Updated
extractAndValidateSessionto use the new helper instead of an inline 3-line header extraction block. - Updated
WithSDKLoggingmiddleware to use the same helper for consistent session ID extraction in logging.
Show a summary per file
| File | Description |
|---|---|
| internal/server/session.go | Adds extractSessionIDFromRequest and uses it from extractAndValidateSession to centralize header-based session ID extraction. |
| internal/server/middleware.go | Switches WithSDKLogging to call extractSessionIDFromRequest to keep logging/session extraction consistent with validation. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 2/2 changed files
- Comments generated: 0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The three-line pattern for extracting a session ID from
X-Agent-ID/Authorizationheaders was copy-pasted in two places in the same package. Because this is security-sensitive (session tracking divergence between logging and validation is a real risk), the duplication is worth eliminating.Changes
internal/server/session.go— adds a package-private helper:session.go(extractAndValidateSession) andmiddleware.go(WithSDKLogging) — each inline 3-line block replaced with a single call to the new helper.No behaviour change; header precedence logic remains in
auth.ExtractSessionIDFromHeaders.