Skip to content

[runtime] Support async execution for cross language resources.#571

Open
wenjin272 wants to merge 2 commits intoapache:mainfrom
wenjin272:cross-async
Open

[runtime] Support async execution for cross language resources.#571
wenjin272 wants to merge 2 commits intoapache:mainfrom
wenjin272:cross-async

Conversation

@wenjin272
Copy link
Copy Markdown
Collaborator

@wenjin272 wenjin272 commented Mar 17, 2026

Linked issue: #448

Purpose of change

When invoking a Java method via Pemja from a Python async thread, if that Java method creates objects using reflection, a ClassNotFoundException may occur because the Python async thread lacks the necessary Java environment context.

In Flink agents, this issue occurs when the Python API calls a Java resource that depends on other Java resources in async thread. For example, the python chat model action call chat of a java chat model setup, and the setup will get the correspond chat model connection, which will construct the connection object by reflection.

To resolve this issue, this pr moves the construction of resources from chat/embed method to open, and the open will invoked in flink mailbox thread. Additionally, we have added a check similar to the one for memory: users are now prohibited from calling get_resource outside of a mailbox thread.

This patch depends on alibaba/pemja#95 in pemja. Therefore, we need to wait for the fix versions for Pemja and Flink 1.20, 2.0, 2.1, and 2.2.

Tests

existed e2e test for cross language resources

API

Yes. Add open for Resource

Documentation

  • doc-needed
  • doc-not-needed
  • doc-included

@github-actions github-actions bot added priority/major Default priority of the PR or issue. fixVersion/0.3.0 The feature or bug should be implemented/fixed in the 0.3.0 version. doc-needed Your PR changes impact docs. labels Mar 17, 2026
@wenjin272 wenjin272 force-pushed the cross-async branch 3 times, most recently from d6497a7 to 632d7b9 Compare March 18, 2026 09:30
@wenjin272
Copy link
Copy Markdown
Collaborator Author

After the code review is complete with no issues, I will add the corresponding documentation updates to this PR.

@github-actions github-actions bot added doc-needed Your PR changes impact docs. and removed doc-needed Your PR changes impact docs. labels Mar 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-needed Your PR changes impact docs. fixVersion/0.3.0 The feature or bug should be implemented/fixed in the 0.3.0 version. priority/major Default priority of the PR or issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant