Skip to content

[ES|QL] Fix NPE in the completion operator. #129235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void markSeqNoAsPersisted(long seqNo) {
* @param response The inference response.
*/
public synchronized void onInferenceResponse(long seqNo, InferenceAction.Response response) {
if (failureCollector.hasFailure() == false) {
if (response != null && failureCollector.hasFailure() == false) {
bufferedResponses.put(seqNo, response);
}
checkpoint.markSeqNoAsProcessed(seqNo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,19 @@ public void execute(BulkInferenceRequestIterator requests, ActionListener<List<I
bulkExecutionState.finish();
}

throttledInferenceRunner.doInference(
request,
ActionListener.runAfter(
ActionListener.wrap(
r -> bulkExecutionState.onInferenceResponse(seqNo, r),
e -> bulkExecutionState.onInferenceException(seqNo, e)
),
responseHandler::persistPendingResponses
)
ActionListener<InferenceAction.Response> inferenceResponseListener = ActionListener.runAfter(
ActionListener.wrap(
r -> bulkExecutionState.onInferenceResponse(seqNo, r),
e -> bulkExecutionState.onInferenceException(seqNo, e)
),
responseHandler::persistPendingResponses
);

if (request == null) {
inferenceResponseListener.onResponse(null);
} else {
throttledInferenceRunner.doInference(request, inferenceResponseListener);
}
}
}

Expand Down Expand Up @@ -112,7 +115,6 @@ public synchronized void persistPendingResponses() {
if (bulkExecutionState.hasFailure() == false) {
try {
InferenceAction.Response response = bulkExecutionState.fetchBufferedResponse(persistedSeqNo);
assert response != null;
responses.add(response);
} catch (Exception e) {
bulkExecutionState.addFailure(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public void close() {
*/
@Override
public void addInferenceResponse(InferenceAction.Response inferenceResponse) {
if (inferenceResponse == null) {
outputBlockBuilder.appendNull();
return;
}

ChatCompletionResults completionResults = inferenceResults(inferenceResponse);

if (completionResults == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public InferenceAction.Request next() {
* Wraps a single prompt string into an {@link InferenceAction.Request}.
*/
private InferenceAction.Request inferenceRequest(String prompt) {
if (prompt == null) {
return null;
}

return InferenceAction.Request.builder(inferenceId, TaskType.COMPLETION).setInput(List.of(prompt)).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,17 @@ protected int remaining() {
@Override
protected Page createPage(int positionOffset, int length) {
length = Integer.min(length, remaining());
try (var builder = blockFactory.newBytesRefVectorBuilder(length)) {
try (var builder = blockFactory.newBytesRefBlockBuilder(length)) {
for (int i = 0; i < length; i++) {
builder.appendBytesRef(new BytesRef(randomAlphaOfLength(10)));
if (randomInt() % 100 == 0) {
builder.appendNull();
} else {
builder.appendBytesRef(new BytesRef(randomAlphaOfLength(10)));
}

}
currentPosition += length;
return new Page(builder.build().asBlock());
return new Page(builder.build());
}
}
};
Expand Down