Skip to content

fix: handle already-active CDI request context in deferred destruction#950

Merged
kabir merged 1 commit into
a2aproject:mainfrom
ehsavoie:flaky_test
Jun 23, 2026
Merged

fix: handle already-active CDI request context in deferred destruction#950
kabir merged 1 commit into
a2aproject:mainfrom
ehsavoie:flaky_test

Conversation

@ehsavoie

Copy link
Copy Markdown
Collaborator

When a Quarkus request filter has already activated the CDI request context before runWithDeferredContextDestruction() is called, the method previously skipped the deferred-destruction logic and ran the task directly. This allowed the request filter to call terminate() and destroy @RequestScoped beans while the ManagedExecutor agent thread was still running, causing failures when accessing OIDC token credentials.

Now the method always takes ownership of the context lifecycle: it captures the existing state (or activates a fresh context), deactivates in the finally block so Arc's terminate() becomes a no-op, and defers actual destruction to the SSE response endHandler/closeHandler.

Fixes #949 🦕

When a Quarkus request filter has already activated the CDI request
context before runWithDeferredContextDestruction() is called, the method
previously skipped the deferred-destruction logic and ran the task
directly. This allowed the request filter to call terminate() and
destroy @RequestScoped beans while the ManagedExecutor agent thread was
still running, causing failures when accessing OIDC token credentials.

Now the method always takes ownership of the context lifecycle: it
captures the existing state (or activates a fresh context), deactivates
in the finally block so Arc's terminate() becomes a no-op, and defers
actual destruction to the SSE response endHandler/closeHandler.

This fixes a2aproject#949

Signed-off-by: Emmanuel Hugonnet <ehugonne@redhat.com>
@ehsavoie ehsavoie requested a review from kabir June 23, 2026 13:35

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates VertxSecurityHelper to improve CDI request context lifecycle management during deferred (streaming/SSE) requests. Specifically, if a CDI context is already active, it now captures the existing state and takes ownership of its deferred destruction instead of bypassing the cleanup registration. A comprehensive unit test suite VertxSecurityHelperTest has been added to verify these behaviors under various scenarios. Additionally, minor whitespace cleanup was performed in DefaultRequestHandler. There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

@kabir kabir merged commit 288540a into a2aproject:main Jun 23, 2026
13 checks passed
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.

[Bug]: org.a2aproject.sdk.tests.multiversion.jsonrpc.MultiVersionJSONRPCTest.testRequestScopedBeanAvailableOnAgentExecutorThreadStreaming

2 participants