refactor: extract _require_session for the session endpoints - #127
Merged
Conversation
Ten endpoint handlers hand-rolled the same sid-validate / registry-lookup / 404 dance. Fold it into Handler._require_session(), which also unifies _SessionPlaceholder rejection: previously only /api/stream rejected placeholders; every other endpoint hit inside the connect window dereferenced attributes the placeholder's __slots__ omit and died with AttributeError (a 500 from /api/input, a dropped connection elsewhere). Now all of them answer the same 404 the registry miss gets a moment later. The upload family keeps its inline sid-shape check because its response precedence (sid shape -> path validation -> registry existence) is pinned by the dispatch tests; only the lookup half moved into the helper there. No wire-visible change for live sessions; new regression test pins the placeholder->404 behavior across output/input/resize/ls.
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.
What
Ten endpoint handlers (
input,output,resize,tmux_capture,tmux_options,upload,upload_finalize,upload_cancel,ls,download) hand-rolled the same sid-validate / registry-lookup / 404 block. This extractsHandler._require_session(sid)(-47 net lines in server.py).Behavior fix folded in
_SessionPlaceholderrejection is now uniform. Previously only/api/streamrejected placeholders; any other endpoint hit during the connect window dereferenced attributes the placeholder's__slots__omit and died with AttributeError — a 500 from/api/input(its write is wrapped in try/except), a dropped connection with no response everywhere else. All endpoints now answer the same 404 a registry miss gets.Deliberately preserved
The upload family's response precedence (sid shape → path/tmp/final validation → registry existence) is pinned by the dispatch tests, so those three handlers keep their inline sid-shape check and only the lookup half moved into the helper.
Tests
test_placeholder_session_404s_on_plain_endpointspins placeholder→404 across output/input/resize/ls (fails on pre-change code with AttributeError).Known follow-up (out of scope)
/api/disconnectcan still pop a placeholder mid-connect (dropping the in-flight slot reservation) and would AttributeError onterminate=true. Worth its own small fix.