Skip to content

Drain temporary server requests before reusing pages - #416

Merged
max-sixty merged 3 commits into
mainfrom
codex/drain-page-server-handlers
Sep 7, 2026
Merged

max-sixty merged 3 commits into
mainfrom
codex/drain-page-server-handlers

Conversation

@max-sixty

@max-sixty max-sixty commented Sep 7, 2026 •

Copy link
Copy Markdown
Owner

Threaded temporary servers inherited ThreadingHTTPServer's daemon request handlers, so close() drained the accept loop but returned before active handlers exited. The browser fixture could then return a page to PagePool while a news or state request was still finishing an atomic write, making reset race the writer's temporary file.

Make request handlers non-daemon only for the in-process start() mode, where server_close() can join them before the caller reuses or removes the page. A one-second socket timeout prevents an idle or incomplete client from making that join unbounded; the foreground run() mode keeps daemon handlers so an interrupted server process can still exit. The regressions pause an accepted request before an atomic page write and park an accepted connection before its request line, proving both sides of the shutdown contract.

Verification: uv run pytest tests (908 passed); uv run pytest -q -n0 tests/test_interact_server.py (96 passed); uv run pre-commit run --all-files; 242 affected browser cases at -n4 (241 passed, with the sole failure being the suggestion-docking defect since fixed on main), followed by the nine formerly failing/reusing cases on the merged base (9 passed).

This was written by Codex on behalf of max-sixty

@leaf-agent leaf-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The race the PR names is real and the mechanism is right — daemon_threads = False is what puts a handler thread on _Threads, so server_close() joins it. What comes with it is that close() is no longer bounded, and I could reproduce a hang on the fixture path this change is for. Details inline on start().

I'd rather not guess which way you want it resolved, so this is a comment rather than an approval. Say the word and I'll push whichever route you pick.

Comment thread skills/leaf/scripts/leaf/hosting.py Resolved
@max-sixty
max-sixty merged commit 11f9619 into main Sep 7, 2026
13 checks passed
@max-sixty
max-sixty deleted the codex/drain-page-server-handlers branch September 7, 2026 21:51
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