Skip to content

FIX: Drain requests on shutdown - #2965

Open
Roman Lutz (romanlutz) wants to merge 6 commits into
microsoft:mainfrom
romanlutz:romanlutz-daily-audit-2026-09-26
Open

Roman Lutz (romanlutz) wants to merge 6 commits into
microsoft:mainfrom
romanlutz:romanlutz-daily-audit-2026-09-26

Conversation

@romanlutz

Copy link
Copy Markdown
Contributor

Description

A disconnected HTTP request can leave its middleware-owned child task running after the caller is cancelled. Runtime shutdown previously closed resources without waiting for these retained runtime and management requests. Normal server graceful shutdown can mask this gap, so the regression exercises the real middleware cancellation path directly.

RuntimeLifecycle now closes admission immediately and drains retained requests and any accepted configuration apply before shutting down the scheduler, services, and memory. Shutdown uses one shared, shielded task so repeated caller cancellation cannot interrupt cleanup. Each cleanup phase still runs if an earlier phase fails, and request/cleanup failures are preserved together in an exception group.

This stays within runtime task-lifetime ownership; it does not change MessageSendService task ownership. The MCP notebook changes were split into a separate branch and are absent from this PR's net diff.

Tests and Documentation

Added regressions for disconnected runtime and management requests, shutdown admission, repeated cancellation, child failures and sibling drainage, accepted apply completion, and resource-close ordering. Extended upstream memory-disposal tests to cover failures/cancellation in individual and multiple cleanup phases. Updated the GUI documentation with shutdown behavior.

Validation on the final merged code:

  • uv run --frozen --no-sync pytest -n 4 --dist=loadfile -q tests\unit\backend tests\unit\setup: 2,262 passed, 5 skipped (215 warnings).
  • uv run --frozen --no-sync pre-commit run --files pyrit\backend\services\runtime_lifecycle.py pyrit\backend\middleware\runtime.py tests\unit\backend\test_runtime_lifecycle.py doc\gui\0_gui.md: all applicable hooks passed, including Ruff and ty; hooks without matching files were skipped normally.

The full repository suite, live integration tests, and E2E tests were not run for this update.

JupyText was not run: no paired notebook or executable documentation changes remain in this changeset.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21bf73f6-4b26-4f5f-bb22-01fa72e49186
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21bf73f6-4b26-4f5f-bb22-01fa72e49186
Reverse 55f0ad3 here so this branch contains only the runtime shutdown correction. Preserve the original commit in history; the notebook fix is being moved to the MCP notebook lifecycle session.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Preserve upstream memory disposal after retained request drainage. Complete each cleanup phase and retain all failures without restoring the separately published MCP notebook change.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 21bf73f6-4b26-4f5f-bb22-01fa72e49186
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21bf73f6-4b26-4f5f-bb22-01fa72e49186
Merge the exact main base tested by CI. Re-raise a sole request or cleanup error unchanged, retaining grouped reporting for multiple failures and completing all cleanup stages. Verify error identity and idempotent repeated shutdown without weakening the upstream lifespan regression.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21bf73f6-4b26-4f5f-bb22-01fa72e49186

This branch has not been deployed

No deployments
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.

1 participant