Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@marius-kilocode
Copy link
Collaborator

Summary

Fixes an intermittent issue where list_files (recursive) and search_files tools show "Total: 0 items" and "Found: 0 matches" even when files exist.

Problem

The issue is a race condition in message handling that occurs more frequently in long-running sessions. When the extension sends a partial message followed by a complete message, the complete message can sometimes be lost or rejected due to IPC timing issues. The hidePartialMessages filter then removes the partial message, showing "0 items".

Solution

Added autoCompleteOrphanedPartialTools() function that marks partial tool messages as complete when:

  1. There's a subsequent message (tool has finished)
  2. The tool message has non-empty content (content exists but partial flag wasn't cleared)

This acts as a safety net to ensure tool results are displayed even when the complete message is lost.

Technical Details

  • Tool messages use type: "ask" with ask: "tool", NOT type: "say" with say: "tool"
  • The function is called during message reconciliation in updateChatMessagesAtom
  • Added comprehensive tests for the new function

Testing

  • All 2129 CLI tests pass
  • Type check passes
  • Lint passes

Files Changed

  • cli/src/state/atoms/extension.ts - Added autoCompleteOrphanedPartialTools() function
  • cli/src/state/atoms/__tests__/tool-message-completion.spec.ts - Added tests
  • .changeset/fix-cli-partial-tool-messages.md - Changeset

@changeset-bot
Copy link

changeset-bot bot commented Jan 20, 2026

🦋 Changeset detected

Latest commit: 700deb6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@kilocode/cli Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@marius-kilocode marius-kilocode requested a review from a team January 20, 2026 17:24
@kiloconnect
Copy link
Contributor

kiloconnect bot commented Jan 20, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Previous Issue Resolved

The previous review flagged an issue with incorrect content checking for tool messages. This has been fixed in the current version. The code now properly parses the JSON and checks the content field:

let hasContent = false
try {
    const parsed = JSON.parse(msg.text || "{}")
    hasContent = parsed.content && parsed.content.trim().length > 0
} catch {
    // If parsing fails, fall back to checking text directly
    hasContent = Boolean(msg.text && msg.text.trim().length > 0)
}
Files Reviewed (3 files)
  • .changeset/fix-cli-partial-tool-messages.md - Changeset describing the fix
  • cli/src/state/atoms/__tests__/tool-message-completion.spec.ts - Comprehensive test coverage for tool message completion scenarios
  • cli/src/state/atoms/extension.ts - Implementation of autoCompleteOrphanedPartialTools function

Summary

This PR adds a CLI-only workaround for an extension bug where list_files and search_files tools show "Total: 0 items" or "Found: 0 matches" even when files exist. The fix:

  1. Adds autoCompleteOrphanedPartialTools() function that marks partial tool messages as complete when:

    • There's a subsequent message (indicating the tool completed)
    • The tool message has non-empty content (but partial flag wasn't cleared)
  2. Includes comprehensive test coverage for various race conditions and edge cases

The implementation is well-structured and the tests are thorough.

The previous implementation checked if msg.text was non-empty, but for
tool messages, msg.text is always a JSON string containing a content
property. Even when content is empty, the text field itself is non-empty.

This fix parses the JSON and checks if the content field is non-empty,
with a fallback to checking text directly if parsing fails.
@marius-kilocode marius-kilocode merged commit 96c2b39 into main Jan 22, 2026
12 checks passed
@marius-kilocode marius-kilocode deleted the list_files_recursive_webview-ui branch January 22, 2026 14:04
maywzh pushed a commit to maywzh/kilocode that referenced this pull request Jan 25, 2026
…-Org#5250)

* fix(cli): Fix empty tool output for list_files and search_files

* fix(cli): Parse JSON to check content field for tool messages

The previous implementation checked if msg.text was non-empty, but for
tool messages, msg.text is always a JSON string containing a content
property. Even when content is empty, the text field itself is non-empty.

This fix parses the JSON and checks if the content field is non-empty,
with a fallback to checking text directly if parsing fails.
maywzh pushed a commit to maywzh/kilocode that referenced this pull request Jan 25, 2026
…-Org#5250)

* fix(cli): Fix empty tool output for list_files and search_files

* fix(cli): Parse JSON to check content field for tool messages

The previous implementation checked if msg.text was non-empty, but for
tool messages, msg.text is always a JSON string containing a content
property. Even when content is empty, the text field itself is non-empty.

This fix parses the JSON and checks if the content field is non-empty,
with a fallback to checking text directly if parsing fails.
catrielmuller pushed a commit that referenced this pull request Jan 26, 2026
* fix(cli): Fix empty tool output for list_files and search_files

* fix(cli): Parse JSON to check content field for tool messages

The previous implementation checked if msg.text was non-empty, but for
tool messages, msg.text is always a JSON string containing a content
property. Even when content is empty, the text field itself is non-empty.

This fix parses the JSON and checks if the content field is non-empty,
with a fallback to checking text directly if parsing fails.
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.

3 participants