Run plugin asgi_wrapper middleware inside the startup-arming layer - #2891
Open
asg017 wants to merge 4 commits into
Open
Run plugin asgi_wrapper middleware inside the startup-arming layer#2891asg017 wants to merge 4 commits into
asg017 wants to merge 4 commits into
Conversation
This was referenced Aug 31, 2026
asg017
force-pushed
the
asg017/first-request-5-wrapper-reorder
branch
from
August 31, 2026 20:05
c558ea7 to
352961c
Compare
asg017
force-pushed
the
asg017/first-request-5-wrapper-reorder
branch
from
August 31, 2026 20:27
352961c to
7a7fa81
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## asg017/first-request-4-shutdown-hook #2891 +/- ##
====================================================================
Coverage 0.00% 0.00%
====================================================================
Files 74 74
Lines 12461 12461
====================================================================
Misses 12461 12461 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
asg017
force-pushed
the
asg017/first-request-5-wrapper-reorder
branch
from
August 31, 2026 21:25
7a7fa81 to
5ea77b3
Compare
simonw
force-pushed
the
asg017/first-request-5-wrapper-reorder
branch
from
September 1, 2026 16:32
5ea77b3 to
f9ab3d8
Compare
simonw
force-pushed
the
asg017/first-request-5-wrapper-reorder
branch
from
September 1, 2026 16:39
f9ab3d8 to
74c898a
Compare
asg017
marked this pull request as ready for review
September 2, 2026 16:42
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012U7coQfVu8nK2R4q2mCULA
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012U7coQfVu8nK2R4q2mCULA
Rolled down from the stack's docs-only tip PR: the lifecycle section now states that startup completes before plugin asgi_wrapper middleware sees any request, and the RELEASE_NOTES_DRAFT_05.md scratch file is gone - its content lands in the changelog in the tasks-endpoint PR at the top of the stack. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012U7coQfVu8nK2R4q2mCULA
asg017
force-pushed
the
asg017/first-request-5-wrapper-reorder
branch
from
September 2, 2026 16:49
89ad91d to
c2f7735
Compare
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.
Some ASGI middlware fixes. To be honest, not 100% sure how this is relevant or what it fixes, but Claude was insistent. Seems to handle some corner cases of plugin hooks that need to be ran after startup finishes?
🤖 Claude-generated PR description
Fifth PR in the startup/lifecycle stack, on top of #2890.
What this does
Reorders the ASGI middleware assembly in
Datasette.app()so pluginasgi_wrappermiddleware runs inside the startup-arming layer (AsgiRunOnFirstRequest) but still outsideAsgiLifespan. Wrappers get a single, simple contract: everyhttp/websocketscope they see arrives after startup has fully completed — on both the lifespan path and the first-request fallback.Why
Previously the wrapper loop was outermost, which had two consequences:
startuphook had run internal-database migrations);lifespanscopes are unaffected:AsgiRunOnFirstRequestignores them, so plugins that inspect or wrap lifespan events see identical message flow.Changes
datasette/app.py: thepm.hook.asgi_wrapperloop moves belowAsgiRunOnFirstRequestin the stack; comment documents the layering contract.docs/internals.rst: the "Application lifecycle" section now states that startup completes before pluginasgi_wrappermiddleware sees any request (rolled down from the former docs-only tip PR Document the plugin lifecycle contract, shutdown hook and background tasks #2893). The wrapper-reorder release notes land in the changelog in Add /-/tasks introspection endpoint for supervised background tasks #2892 at the top of the stack.Tests
Three new tests in
tests/test_lifespan.py: a wrapper asserting startup has completed before anyhttpscope (fails on the pre-reorderapp()), a short-circuiting 403 wrapper that no longer prevents startup, and a recording wrapper pinning thatlifespanscopes still reach wrappers.Stack created with GitHub Stacks CLI • Give Feedback 💬