fix: use custom session id generator when provided#715
fix: use custom session id generator when provided#715ezynda3 merged 3 commits intomark3labs:mainfrom
Conversation
WalkthroughAdds a configurable session ID generator to the SSE server (new Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested labels
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 🧹 Recent nitpick comments
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. 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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@server/sse.go`:
- Around line 428-432: The custom sessionIDGenFunc may return an empty string
which creates a session key of "" that handleMessage ignores; after calling
sessionIDGenFunc (the sessionID variable) add validation that sessionID is
non-empty and treat an empty value as an error (return http.Error with a 500
status and descriptive message), and optionally log the failure; update the code
paths that store sessions (where sessions are inserted using sessionID) to rely
on this validation so no session with key "" is ever created and handleMessage
continues to reject missing sessionId as intended.
🧹 Nitpick comments (1)
server/sse.go (1)
428-432: Consider logging the underlying error for observability.The error returned by
sessionIDGenFuncis silently discarded — the client gets a generic 500 but operators have no way to diagnose why the generator failed. A singlelog.Printfwould match the logging style already used elsewhere in this file (e.g., line 603, 617).💡 Suggested improvement
sessionID, err := s.sessionIDGenFunc(r.Context(), r) if err != nil { + log.Printf("failed to generate session ID: %v", err) http.Error(w, "Failed to create session ID", http.StatusInternalServerError) return }
add sessionID check Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Description
TThis PR adds support for a user-provided custom session ID generator.
In sse.go, a custom session ID generator is now used when configured; the default generator is used only if none is provided.
In streamable_http.go, handleGet now generates session IDs using the custom generator instead of always using a UUID.
These changes ensure consistent and configurable session ID generation across both SSE and HTTP streams.
Type of Change
Checklist
Additional Information
N/A
Summary by CodeRabbit
New Features
Bug Fixes