Skip to content

Resolve request state from the Octane sandbox, not the booted application - #2

Merged
JustSteveKing merged 2 commits into
mainfrom
fix/octane-sandbox-resolution
Oct 20, 2026
Merged

JustSteveKing merged 2 commits into
mainfrom
fix/octane-sandbox-resolution

Conversation

@JustSteveKing

Copy link
Copy Markdown
Owner

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 fresh scoped() 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 instance

ProblemDetailsServiceProvider registered a renderable that called $this->app->make(ProblemRenderer::class). The renderer takes the request ID from the scoped CurrentRequestId, so under Octane it got the base application's, which is never set. Every problem came back without instance (the urn:uuid: form of the request ID), even though the X-Request-Id header was on the response. Seen for real on 401 problems.

The callback now resolves ProblemRenderer from Container::getInstance().

Trace context was not propagated to outgoing requests

NegotiationServiceProvider captured $app = $this->app into the HTTP client's global request middleware, which read CurrentTrace from it. Under Octane outgoing requests carried no traceparent or tracestate, 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 CurrentTrace from Container::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 of src/ for other closures that capture the booted application and resolve request state later, and found none. The bindings that take static fn (Application $app) get the container that resolves them, and TrackOperation, the cursor resolver and SignsOutgoingRequests already use Container::getInstance().

Tests

tests/Feature/OctaneSandboxTest.php simulates the sandbox without needing Octane installed. It clones the application, forgets its scoped instances, makes it the container instance, and restores the original in a finally. 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 request
  • it carries the trace of the sandbox serving the request onto outgoing HTTP client requests

I confirmed that both fail on main before the fix: the first rendered the base application's request ID as instance, and the second recorded no request with the sandbox's traceparent. 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.

…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.
@coderabbitai

coderabbitai Bot commented Oct 20, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 275bc018-e8fd-4a75-a9f1-a006cf99e4cb
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@JustSteveKing
JustSteveKing merged commit 3f92ba4 into main Oct 20, 2026
7 checks passed
@JustSteveKing
JustSteveKing deleted the fix/octane-sandbox-resolution branch October 20, 2026 10:42
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