Repository navigation
Answer each page route with a starlette response - #777
Merged
Merged
Conversation
#774 moved the transport to starlette and uvicorn, but the per-request object kept `BaseHTTPRequestHandler`'s shape: a route left its answer on `self.response` after assembling a `_headers` list through `send_header` and `end_headers`, and a `close_connection` flag decided whether the answer ended the connection. Each route now returns the response it answers with. The headers every response carries — the `Leaf-*` delivery identity, the key cookie, `nosniff`, and `Connection: close` where a route declined to drain a declared body — are one `_delivery_headers()`, applied once in `respond()`; the website adapter extends that instead of overriding `end_headers`. The key gate stays the single gate in `_answer`, and the layer gate stays on the POST path, where it needs the view revision the request names. `Handler` becomes `PageEndpoint`, bound to its page by an ordinary constructor rather than by a `type()` subclass, so `handler_for` becomes `page_endpoint` and hands back a `partial`. The server incarnation id and the news stream's reader-recency throttle move onto `LeafHTTPServer`, which is what they are facts about. `self.command` becomes `self.method`, and the path and query arrive already apart, which removes the fourteen `urlsplit(self.path)` calls that split them again per route. `layer` is derived from `layer_identity` rather than stored beside it, and the website adapter's `bootstrap` binding, which nothing read, is deleted. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
leaf-agent
approved these changes
Sep 18, 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.
TODO.md's item 25. #774 moved the transport to starlette and uvicorn, but the per-request object keptBaseHTTPRequestHandler's shape: a route left its answer onself.responseafter assembling a_headerslist throughsend_headerandend_headers, and aclose_connectionflag decided whether the answer ended the connection. That is a compatibility layer inside a finished cutover, so it goes rather than getting renamed.Behaviour at the HTTP boundary is unchanged, deliberately: same status codes, same header sets on the same paths, same refusals, same
Connection: closeon a declared body no route drained.Reading the diff
skills/leaf/scripts/leaf/http.pycarries the change;worker/server.pyandskills/leaf/scripts/leaf/mcp_page.pyare the two transports that subclass it, andhosting.pyis the seam to uvicorn.Routes return responses.
_get,_post,_select_pageand the_serve_*helpers each return astarletteresponse, orNonewhere they have nothing to answer with.self.responseis gone.One place for the shared headers.
_delivery_headers()returns theLeaf-*delivery identity, the key cookie,nosniff, andConnection: close, andrespond()applies it once to whatever the route returned. The website adapter extends it ({"Leaf-Session": "active", **super()._delivery_headers()}) instead of overridingend_headers. The key gate was already the single gate in_answerand stayed there. The layer gate stays on the POST path, where it needs the view revision the request names;response_layerandset_cookieare both decided inside routes, so ASGI middleware would still leave the routes writing torequest.stateand would make the website's extra header a second middleware wrapping an app that does not otherwise exist.Construction.
HandlerbecomesPageEndpoint, bound to its page by an ordinary constructor rather than by atype()subclass, sohandler_forbecomespage_endpointand hands back apartial.LeafHTTPServertakes that endpoint and now owns the two facts that were living on the handler class:server_id, the incarnation a tab watches, andviewed_at, the news stream's reader-recency throttle.Fallout.
self.commandbecomesself.method; the path and query arrive already apart, removing the fourteenurlsplit(self.path)calls that split them again per route;layeris derived fromlayer_identityrather than stored beside it, which drops an assignment each multiplexed transport had to remember; and the website adapter'sbootstrapbinding, which nothing read, is deleted.Checks
Green locally:
ruff, the everyday suite (1138), and a completeuv run pytest tests --run-nightly(2703). No TypeScript changed, so neither the worker nor the browser-framework gate is in scope.