Skip to content

fix: Run response decorators inside interceptor ScopedValue scope#98

Merged
thced merged 11 commits into
masterfrom
fix/decorator-scoped-values
May 22, 2026
Merged

fix: Run response decorators inside interceptor ScopedValue scope#98
thced merged 11 commits into
masterfrom
fix/decorator-scoped-values

Conversation

@thced

@thced thced commented May 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Move the response-decorator loop into the base case of DispatchHandler.invoke(...) so decorators execute inside every RequestInterceptor's ScopedValue scope. Honors the contract documented in README "Combining the two" — previously a decorator that called CORRELATION_ID.get() threw NoSuchElementException because the interceptor's scope had already unwound.
  • Interceptors now observe the decorated Response on the way back up the stack (a tracing interceptor wrapping next.proceed() sees the final status, headers, and body).
  • A decorator exception now propagates through the interceptor chain — interceptors that try/catch around next.proceed() will observe decorator failures. Documented in README.

Changes

  • DispatchHandler.handle/invoke refactor (one method-pair, ~7 lines).
  • ResponseDecorator javadoc cross-references RequestInterceptor + ScopedValue visibility.
  • README "Combining the two" notes the decorator-exception propagation behavior.
  • Three new unit tests in DispatchHandlerTest + one IT in DecoratorAndInterceptorIT.

Spec: docs/superpowers/specs/2026-05-23-decorator-scoped-value-scope-design.md
Plan: docs/superpowers/plans/2026-05-23-decorator-scoped-value-scope.md

Test plan

  • Unit: decorator reads interceptor-bound ScopedValue and stamps a header
  • Unit: interceptor's next.proceed() returns the decorator-modified Response
  • Unit: interceptor try/catch around next.proceed() catches a throwing decorator; final response carries the catch-block status
  • IT: end-to-end through OpenApiServer — decorator reads TENANT bound by interceptor, stamps X-Tenant-Id
  • mvn verify passes (475 unit + 68 IT, 0 failures)
  • JaCoCo: 100% instruction + branch coverage on DispatchHandler

@sonarqubecloud

Copy link
Copy Markdown

@thced thced merged commit 90ae25f into master May 22, 2026
6 checks passed
@thced thced deleted the fix/decorator-scoped-values branch May 22, 2026 23:01
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