Skip to content

Fix: ResultExpanderTools crashes with "Text content cannot be empty" when expandResult returns an empty list#1441

Open
coolduebtn wants to merge 1 commit intoembabel:mainfrom
coolduebtn:fix/result-expander-empty-list-crash
Open

Fix: ResultExpanderTools crashes with "Text content cannot be empty" when expandResult returns an empty list#1441
coolduebtn wants to merge 1 commit intoembabel:mainfrom
coolduebtn:fix/result-expander-empty-list-crash

Conversation

@coolduebtn
Copy link

Closes #1440

Copilot AI review requested due to automatic review settings February 23, 2026 12:37
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes a crash in ResultExpanderTools when ResultExpander.expandResult(...) returns an empty (or fully-filtered) list by returning a non-empty fallback message instead of producing an empty tool response.

Changes:

  • Add empty-list handling to broadenChunk() to avoid returning an empty string.
  • Add empty-list handling to zoomOut() to avoid returning an empty string.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +112 to 116
val chunks = resultExpander.expandResult(chunkId, ResultExpander.Method.SEQUENCE, chunksToAdd)
.filterIsInstance<Chunk>()
if (chunks.isEmpty()) return "No adjacent chunks found for this section."
return chunks.joinToString("\n") { "Chunk ID: ${it.id}\nContent: ${it.text}\n" }
}
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

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

The new empty-result handling in broadenChunk is user-visible behavior and fixes a crash path. Add a unit test that mocks ResultExpander.expandResult(...) returning an empty list (and/or a list with no Chunks) and asserts the non-empty fallback message is returned.

Copilot uses AI. Check for mistakes.
Comment on lines +123 to +126
.filter { it is Embeddable }
if (embeddables.isEmpty()) return "No parent section found."
return embeddables.joinToString("\n") { contentElement ->
"${contentElement.javaClass.simpleName}: id=${contentElement.id}\nContent: ${(contentElement as Embeddable).embeddableValue()}\n"
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

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

Add a unit test for zoomOut covering the case where expandResult(...) returns an empty list (or only non-Embeddable elements) and assert the non-empty fallback message is returned, to prevent regressions of the "Text content cannot be empty" crash.

Suggested change
.filter { it is Embeddable }
if (embeddables.isEmpty()) return "No parent section found."
return embeddables.joinToString("\n") { contentElement ->
"${contentElement.javaClass.simpleName}: id=${contentElement.id}\nContent: ${(contentElement as Embeddable).embeddableValue()}\n"
.filterIsInstance<Embeddable>()
if (embeddables.isEmpty()) return "No parent section found."
return embeddables.joinToString("\n") { embeddable ->
"${embeddable.javaClass.simpleName}: id=${embeddable.id}\nContent: ${embeddable.embeddableValue()}\n"

Copilot uses AI. Check for mistakes.
Comment on lines +112 to +113
val chunks = resultExpander.expandResult(chunkId, ResultExpander.Method.SEQUENCE, chunksToAdd)
.filterIsInstance<Chunk>()
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

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

The chained call indentation is inconsistent with the surrounding style in this file (e.g., results chaining in deduplicateByIdKeepingHighestScore). Align the .filterIsInstance<Chunk>() line under the expression to keep Kotlin formatting consistent and avoid formatter/lint churn.

Copilot uses AI. Check for mistakes.
Comment on lines +122 to +123
val embeddables = resultExpander.expandResult(id, ResultExpander.Method.ZOOM_OUT, 1)
.filter { it is Embeddable }
Copy link

Copilot AI Feb 23, 2026

Choose a reason for hiding this comment

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

The chained call indentation is inconsistent with the rest of this file. Align the .filter { ... } line under the expandResult(...) call for consistent Kotlin formatting.

Copilot uses AI. Check for mistakes.
@johnsonr
Copy link
Contributor

Please sign the commit. Thanks

…crash

Signed-off-by: Chandan Agarwal <chandan.agarwal@cullen-international.com>
@coolduebtn coolduebtn force-pushed the fix/result-expander-empty-list-crash branch from 40cd25b to e2329b5 Compare February 24, 2026 08:25
@coolduebtn
Copy link
Author

Please sign the commit. Thanks

I have signed off the commit. Thanks

Copy link
Contributor

@johnsonr johnsonr left a comment

Choose a reason for hiding this comment

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

Fix looks good but I agree with Copilot that it needs tests that demonstrate the failure no longer occurs.

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: ResultExpanderTools crashes with "Text content cannot be empty" when expandResult returns an empty list

3 participants