Repository navigation
Resolve request state from the Octane sandbox, not the booted application - #2
Merged
Merged
Conversation
…ps their instance The renderable callback resolved ProblemRenderer from the application that booted the provider. Under Octane each request is served from a sandboxed clone whose scoped CurrentRequestId holds the request ID, so problems rendered from the base application lost their urn:uuid instance while the X-Request-Id header was still sent. The callback now resolves from Container::getInstance(), which is the sandbox under Octane and the application itself otherwise.
…ient requests under Octane The HTTP client middleware read CurrentTrace from the application captured at boot. Under Octane that is not the sandbox serving the request, so outgoing requests carried no traceparent or tracestate, and anything that ever set the base application's trace would have leaked it onto every request. The middleware now resolves CurrentTrace from Container::getInstance() when the request is sent.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configuration
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This was referenced Oct 20, 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.
Two closures registered at boot captured the application that booted the package and resolved request-scoped state from it at request time. Under Octane every request is served from a sandbox, a clone of the application set as
Container::getInstance(), with freshscoped()bindings. The package keeps request state in scoped bindings, but these two closures read the base application's instances, which no request ever populates. Both were found running the package under Octane with FrankenPHP.Problems lost their
instanceProblemDetailsServiceProviderregistered a renderable that called$this->app->make(ProblemRenderer::class). The renderer takes the request ID from the scopedCurrentRequestId, so under Octane it got the base application's, which is never set. Every problem came back withoutinstance(theurn:uuid:form of the request ID), even though theX-Request-Idheader was on the response. Seen for real on 401 problems.The callback now resolves
ProblemRendererfromContainer::getInstance().Trace context was not propagated to outgoing requests
NegotiationServiceProvidercaptured$app = $this->appinto the HTTP client's global request middleware, which readCurrentTracefrom it. Under Octane outgoing requests carried notraceparentortracestate, so propagation stopped silently. If anything had ever set the base application's trace, it would have leaked one request's trace onto every other request's calls.The middleware now resolves
CurrentTracefromContainer::getInstance()when the request is sent.Outside Octane,
Container::getInstance()is the application itself, so nothing changes there. It is not a facade, so the arch rule against facades in internals still holds. I checked the rest ofsrc/for other closures that capture the booted application and resolve request state later, and found none. The bindings that takestatic fn (Application $app)get the container that resolves them, andTrackOperation, the cursor resolver andSignsOutgoingRequestsalready useContainer::getInstance().Tests
tests/Feature/OctaneSandboxTest.phpsimulates the sandbox without needing Octane installed. It clones the application, forgets its scoped instances, makes it the container instance, and restores the original in afinally. The base application is given different request state on purpose, so these tests also catch a leak:it identifies a problem by the request ID of the sandbox serving the requestit carries the trace of the sandbox serving the request onto outgoing HTTP client requestsI confirmed that both fail on
mainbefore the fix: the first rendered the base application's request ID asinstance, and the second recorded no request with the sandbox'straceparent. Both pass with the fix. Pest, PHPStan (level max) and Pint all pass.There is no API change, so this could go out as a patch release, v0.3.1.