Skip to content

feat: support to reflection v2 api#124

Open
xavidop wants to merge 2 commits intomainfrom
xavier/reflection-v2-api
Open

feat: support to reflection v2 api#124
xavidop wants to merge 2 commits intomainfrom
xavier/reflection-v2-api

Conversation

@xavidop
Copy link
Copy Markdown
Collaborator

@xavidop xavidop commented Mar 27, 2026

Description

Support for Reflection V2 in Genkit Java

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Code refactoring
  • Performance improvement
  • Test improvements
  • CI/CD improvements

Documentation

  • README updated
  • Plugin documentation updated
  • API documentation updated
  • Sample code updated

Reviewer Notes

Copy link
Copy Markdown

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

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 introduces ReflectionServerV2, which enables the Genkit runtime to act as a WebSocket client for dev tools integration using JSON-RPC 2.0. The Genkit class is updated to conditionally start this server based on the GENKIT_REFLECTION_V2_SERVER environment variable. Feedback identifies a critical bug in handleCancelAction where all active actions are interrupted instead of the specific one requested, and points out an unused stream variable in handleRunAction.

Comment on lines +490 to +495
for (Map.Entry<String, Thread> entry : activeActions.entrySet()) {
// Interrupt the thread to cancel the action
entry.getValue().interrupt();
activeActions.remove(entry.getKey());
found = true;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

critical

The current implementation of handleCancelAction incorrectly interrupts all active actions, rather than the specific action targeted by the traceId. The loop iterates over the entire activeActions map and calls interrupt() on every thread. This can lead to unexpected termination of unrelated, concurrently running actions.

The comment on lines 487-488 acknowledges the difficulty in mapping traceId to a thread, but the implemented logic is critically flawed as it doesn't attempt to match, and the comment on line 488 is misleading as it interrupts all threads, not "all matching threads".

To fix this, you could introduce a mapping from traceId to requestId. This map would be populated in handleRunAction once the traceId is known, and then used in handleCancelAction to find the correct action to interrupt.

Here's a conceptual example of how you could implement this:

  1. Add a new map to the class: private final ConcurrentHashMap<String, String> traceIdToRequestId = new ConcurrentHashMap<>();
  2. In handleRunAction, after getting the traceId, populate the map:
    traceId = result.getTraceId();
    if (traceId != null) {
        traceIdToRequestId.put(traceId, requestId);
    }
  3. In the finally block of handleRunAction, clean up the map:
    if (traceId != null) {
        traceIdToRequestId.remove(traceId);
    }
    activeActions.remove(requestId);
  4. Update handleCancelAction to use this map to find and interrupt the correct thread.

try {
String key = params.has("key") ? params.get("key").asText() : null;
JsonNode input = params.has("input") ? params.get("input") : null;
boolean stream = params.has("stream") && params.get("stream").asBoolean();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

The stream variable is initialized but never used within the handleRunAction method. This appears to be dead code and should be removed to improve code clarity.

@xavidop xavidop changed the title feat: support to refleciton v2 API feat: support to reflection v2 api Mar 27, 2026
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