Skip to content

refactor: extract _require_session for the session endpoints - #127

Merged
dolonet merged 1 commit into
dolonet:mainfrom
gorevds:refactor/require-session-helper
Jun 25, 2026
Merged

refactor: extract _require_session for the session endpoints#127
dolonet merged 1 commit into
dolonet:mainfrom
gorevds:refactor/require-session-helper

Conversation

@gorevds

@gorevds gorevds commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator

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 extracts Handler._require_session(sid) (-47 net lines in server.py).

Behavior fix folded in

_SessionPlaceholder rejection is now uniform. Previously only /api/stream rejected 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

  • New test_placeholder_session_404s_on_plain_endpoints pins placeholder→404 across output/input/resize/ls (fails on pre-change code with AttributeError).
  • Full suite: 487 tests OK.

Known follow-up (out of scope)

/api/disconnect can still pop a placeholder mid-connect (dropping the in-flight slot reservation) and would AttributeError on terminate=true. Worth its own small fix.

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.
@dolonet
dolonet merged commit 910beb3 into dolonet:main Jun 25, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants