Repository navigation
refactor(commons): extract InvokeStore fallback into InvocationScoped - #5615
Merged
Merged
Conversation
Seven *Store classes across logger, metrics, and batch each re-implemented the same per-accessor branch 36 times: check AWS_LAMBDA_MAX_CONCURRENCY, assert InvokeStore, get or create under a symbol key, or touch an instance fallback. They had drifted: only LogInvocationStore.setLogLevel guarded on hasContext(), and BatchProcessingStore asserted InvokeStore in 2 of 14 accessors, so failures varied between TypeError and Error. Add InvocationScoped<T> to commons as the @internal ./utils/invocation-scoped subpath export. Test the full mode matrix: flag off, flag on without the global, flag on without an active context, and scoped. Box scoped and shared slots so an explicit undefined shadows the shared value, while an unset slot falls back. Migrate the seven stores to declare cells and retain only domain logic. Unify behavior as fixes: writes outside an active invocation context use the shared value; every accessor throws 'InvokeStore is not available' when the flag is on but the global is missing; MetricsStore.clearMetrics clears the timestamp identically in both modes. Move @aws/lambda-invoke-store to devDependencies in logger, metrics, and batch. Their sources no longer import it, commons carries the runtime augmentation, and tests still use it directly. Keep copy semantics unchanged and out of scope. Leave tracer untouched because its fallback is the X-Ray SDK context rather than an instance field. Refs #5554
svozza
approved these changes
Sep 3, 2026
1 of 2 tasks
This branch was previously deployed
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
Extracts repeated invocation-scoping behavior from seven logger, metrics, and batch stores into a tested commons primitive. This removes inconsistent fallback and error behavior while leaving each store responsible only for its domain logic.
Changes
LogInvocationStore.setLogLevelguarded onhasContext(), whileBatchProcessingStoreassertedInvokeStorein only 2 of 14 accessors, producing inconsistentTypeErrorandErrorfailures.InvocationScoped<T>commons subpath export at./utils/invocation-scoped, with direct coverage for the flag-off, missing-global, inactive-context, and scoped modes. Scoped and shared slots useBox<T>so explicitundefinedshadows the shared value while an unset slot falls back.InvokeStore is not availablewhen required, andMetricsStore.clearMetricsclears its timestamp consistently in both modes.@aws/lambda-invoke-storeto devDependencies in logger, metrics, and batch because their sources no longer import it; commons retains the runtime augmentation while tests continue using it directly.Box<T>deliberately distinguishes an explicitundefinedvalue from an unset slot.import '@aws/lambda-invoke-store'for runtime augmentation.errorspushed beforeprepare()now persist under concurrency; this is deliberate unification and is not externally observable.LogInvocationStorecontinues relying on the existingconfigureBuffer()precondition.lint:ciis clean.Issue number: closes #5554
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.