refactor: Extract rebuildEvaluator and registerCredentialMappings#737
Open
keelerm84 wants to merge 1 commit into
Open
refactor: Extract rebuildEvaluator and registerCredentialMappings#737keelerm84 wants to merge 1 commit into
keelerm84 wants to merge 1 commit into
Conversation
Pure refactor prep for the synchronous re-anchor work. Pulls two blocks out of envContextImpl into methods the re-anchor path will also call: - rebuildEvaluator: the evaluator-build block from startSDKClient. - registerCredentialMappings: the envStreams / handler / connection-mapper wiring from addCredential. No behavior change. The one reordering: addCredential now registers the connection mapping at the top (inside registerCredentialMappings) rather than at the end; both run under the same c.mu hold, so no observer sees a difference.
This was referenced Jul 6, 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.
Summary
Second slice carved out of #720 (the re-anchor mechanism, SDK-2542), split for reviewability. A pure, behavior-preserving refactor that extracts two blocks out of
envContextImplinto methods the synchronous re-anchor path will also call. Independent of the store-handover slice (#736); both are siblings offfeat/concurrent-keys.rebuildEvaluator-- the evaluator-build block lifted out ofstartSDKClient, so the re-anchor path can rebuild the evaluator against the (handed-over) store without duplicating it.registerCredentialMappings-- the envStreams / handler / connection-mapper wiring lifted out ofaddCredential, so the re-anchor path can register a brand-new anchor's downstream routing on its own.No behavior change. The one reordering:
addCredentialnow adds the connection mapping at the top (insideregisterCredentialMappings) rather than at the end.Why the reorder is safe: it is not because
c.muhides it -- the connection map (envsByCredential) has its own lock, so a request can resolve the newly-added credential the instantAddConnectionMappingreturns, whileaddCredentialstill holdsc.mu. Rather, every env field such a request then reads --GetClient,GetEvaluator,GetStreamHandler,GetInitError-- takesc.mu.RLock, so the request blocks untiladdCredentialcompletes and observes the same committed state regardless of where the mapping was registered inside the lock. The pre-existing window in which a credential is routable before its async SDK client is installed (startSDKClientisgo-spawned and blocks onc.muin both versions) is unchanged. The only new sub-window -- credential routable beforeeventDispatcher.ReplaceCredentialrepoints forwarding -- is benign: the event-relay endpoint converges under its own lock and forwards under the new anchor either way, and during a rotation both the old and new anchor keys are valid (grace period).Verified with
go test -race ./internal/relayenv/,go vet, andmake lint.Split sequence
PR 2 of a 4-slice split of #720: store handover (#736) -> relayenv refactors (this PR) -> credential rotator deferred-flip API -> synchronous re-anchor core.
Note
Medium Risk
Touches credential routing and evaluator setup on the hot path for SDK key rotation; intended as no-op refactor but reorders when credentials become routable relative to event forwarding under
c.mu.Overview
Behavior-preserving refactor in
envContextImplthat pulls two blocks into dedicated helpers so an upcoming synchronous re-anchor path can reuse them without duplicating logic.registerCredentialMappingscentralizes downstream routing for a credential:envStreams, per-stream HTTP handlers, andconnectionMapper.addCredentialnow calls it first, then keeps anchor-only work (asyncstartSDKClient, metrics/eventReplaceCredential). Connection mapping runs earlier in the lock than before (with stream/handler setup) instead of at the end ofaddCredential.rebuildEvaluatorholds the evaluator construction that used to live inline instartSDKClient(data store → evaluator options, including secondary key and big segments).Comments were updated to describe the split; no new call sites beyond the extractions in this PR.
Reviewed by Cursor Bugbot for commit a535418. Bugbot is set up for automated code reviews on this repo. Configure here.