Repository navigation
Make the current client the source of truth for the client id - #21
Merged
Merged
Conversation
The client cookie now always holds the client id of the current client, i.e. what ClientContextInterface returns, decorators included. Before, a request with a cookie kept the cookie's id and the cookie writer never asked the client context. ClientContext recognizes the client by the cookie of the main request and replaces CookieBasedClientContext and DefaultClientContext. CachedClientContext decorates the interface with priority -1024, so it wraps the application's decorators, and keeps the clients in a WeakMap keyed by the request, so it needs no kernel.reset. An internal ClientCookieJar owns reading and writing the cookie and replaces the cookie providers and CookieProviderInterface. Without a request, every call gets an anonymous client. Adds GLOSSARY.md, ADR 0001 and UPGRADE-2.0.md.
This was referenced Nov 9, 2026
…indings Symfony removes the request from the request stack before it dispatches kernel.terminate, so terminate listeners got an anonymous client. The internal MainRequestProvider also returns the request being terminated, and both client contexts use it. Renames ClientContext back to CookieBasedClientContext, registered as setono_client.client_context.cookie_based and aliased by setono_client.client_context.default. Moves the cookie jar to setono_client.cookie.client_cookie_jar, and clarifies the service id convention in CLAUDE.md. Adds functional tests for a decorator of the service id and for kernel.terminate. Uses the glossary's terms (valid, current client, anonymous client) and says bytes where the code counts bytes. Fixes the UPGRADE snippet for reading the cookie, and notes that setono_client.client_context.default no longer includes the cache.
Only the cache needs the request while kernel.terminate runs, as its key: StoreMetadataSubscriber asks for the current client on kernel.finish_request of every main request, so terminate listeners get it from the cache. CachedClientContext now subscribes to kernel.terminate itself, and CookieBasedClientContext reads the RequestStack again. Removes MainRequestProvider. Because Symfony moves a decorated service's tags to its decorator, decorating setono_client.client_context.cached itself now fails to compile; the docs say to decorate the interface or setono_client.client_context.default.
…decoration assertion In v4.3.1, assertContainerBuilderServiceDecoration() passes the service definition to the constraint instead of the container, so it always throws. The lowest CI jobs installed v4.3.1. The DI test 5.x requires symfony-config-test ^5.0, so its ^4.3 alternative was dead too.
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.
Summary
The current client is now the source of truth for the client id. The client cookie always holds the id of the client that
ClientContextInterfacereturns, decorators included. See ADR 0001.StoreCookieSubscriber,StoreMetadataSubscriberandClientValueResolverinject the interface alias, so they see app decorators and the cache.kernel.terminatelisteners still get the request's current client. Symfony pops the request before that event, soCachedClientContextkeeps it, via aWeakReference, between its own terminate listeners at priority 2048 and -2048. Because of that tag, decoratingsetono_client.client_context.cacheditself fails to compile, and the docs say to decorate the interface or.defaultinstead.GLOSSARY.md,docs/adr/0001-…andUPGRADE-2.0.md, updates the README and CLAUDE.md (including the service id convention), and dropssymfony/service-contracts.Evidence
DecoratedClientContextTestagainst 1.x, with a decorator that names the client by a query parameter:setono_client.client_context.default. Moving the cache inside the decorator (priority1024) makes the metadata test fail again.KernelTerminateTest: a terminate listener gets the current client, including when neither the route nor the vetoed cookie subscriber used it (StoreMetadataSubscriber always does). IfCachedClientContextignores terminate, both tests fail with a random anonymous id.AnonymousClientTest: outside a request, two calls give two anonymous clients.composer validate --strictand the dependency analyser clean. The CI matrix (8.1/8.2, lowest) wasn't run locally.Merge Danger
Door: two-way
The PR targets the unreleased
2.xline, so a revert undoes it. The BC check is skipped for PRs into2.x.Blast Radius: consumers
When 2.0.0 ships, three groups of apps are affected:
CookieProviderInterfaceorDefaultClientContext, or that injectsetono_client.client_context.default, need changes.UPGRADE-2.0.mdcovers each case.