Repository navigation
feat(DB-773): take a SQL session key and report the API's session fallback - #79
Merged
Merged
Conversation
connect() takes session_key, sent as the session request's sessionKey: the API reuses a session only for requests with the same key, so a caller can keep sessions of its own (Waldo keeps one per chat). When a session of the key's own would exceed a quota, the API shares another of the user's sessions and names why in the X-Wherobots-Sql-Session-Fallback header of its redirect. requests follows that redirect, so the driver reads the header from the response history and exposes it as Connection.session_fallback, next to a now-public Connection.session_id. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kcheng486
marked this pull request as ready for review
October 15, 2026 23:51
Salty Hambot: when the session POST is first redirected by a 307 or 308 (to a canonical endpoint, say) before the API's 303, requests keeps both in resp.history, and reading history[0] missed the header, so the connection reported no fallback. Read every hop, latest first. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
sfishel18
approved these changes
Oct 16, 2026
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.
Summary
The driver can now ask for a SQL session of its own and tell the caller when the API gave it a shared one instead.
connect(session_key=...)sendssessionKeyon the session request, and only when set. The API reuses a session only for requests with the same key, and never one opened without a key. Waldo uses this to keep one SQL session per chat, so a heavy query in one chat no longer holds the session another chat's queries run on.Connection.session_fallbackreports when the key didn't get its own session. If a session of the key's own would exceed the org's quota, the API shares another of the user's sessions instead and names the reason (quota) in anX-Wherobots-Sql-Session-Fallbackheader on its 303.requestsfollows that redirect, so the driver reads the header fromresp.history[0]and passes it throughconnect_direct(session_fallback=...). The driver also logs a warning when it happens.Connection.session_idis now public. It was already parsed from the redirect URL, but only kept privately for error messages.New keyword arguments go at the end of each signature. Callers that don't pass a key see no change: the request body is the same as before, and against an API without the header
session_fallbackisNone.Related Issues
sessionKey, the quota fallback and the header.Requester Checklist
Complete these before marking Ready for Review
Visual Proof
Unit tests:
TestConnectSessionKeyintests/test_driver.pycovers the key in the body, the key omitted, the 303's fallback header reachingconnect_directwith and without the header, and the fallback and session id reachingConnectionthrough the realconnect_direct(only the WebSocket stubbed).test_connection_reports_its_session_and_fallbackintests/test_disconnect.pycovers the new properties.End to end against the API change in wherobots/studio-backend#2884. This driver's
connect()(loaded from this branch viaPYTHONPATH) ran against the real API app, served by uvicorn on a test Postgres. The org's CPU quota fit one tiny session, and chat 1's session already used it. The realconnect_directran with only the WebSocket stubbed, since there is no cluster to open one to, and the argumentsConnectionwas built with are printed:Not tested: against a live deployment, since the API change isn't deployed yet.
Size Justification (if L/XL)
N/A: small.
Reviewer Checklist
If these are not met, close the tab — this PR is not ready for review
Model: Claude Opus 5.5 (claude-opus-5-5), harness: Claude Code (VS Code extension).
🤖 Generated with Claude Code