Skip to content

Conversation

@YangLi-leo
Copy link
Contributor

Summary

Fix resource leak caused by orphan processes when operations are cancelled.

Changes

  • Add CancelledError handling in bash tool to clean up subprocesses properly
  • Add CancelledError handling in task tool for subagent cancellation
  • Return proper ToolError instead of propagating exception

Update config directory path from ~/.config/kimi/ to ~/.kimi/ to match the actual implementation.

The config directory was changed to ~/.kimi/, but AGENTS.md was not updated accordingly.
Add CancelledError handling in bash and task tool to clean up subprocesses and provide better error messages.

Return proper ToolError instead of propagating exception
  - Resolved import conflicts in task tool (Wire -> WireUISide)
  - Maintained CancelledError handling additions
@YangLi-leo YangLi-leo changed the title Fix/cancelled error handling fix: Handle CancelledError in bash and task tools Oct 25, 2025
@YangLi-leo
Copy link
Contributor Author

I think the reason i failed CI is the refactoring of Wire to WireUI, The core fix for CancelledError is correct. Happy to update for the new API if needed.

@stdrc
Copy link
Collaborator

stdrc commented Oct 25, 2025

I think the reason i failed CI is the refactoring of Wire to WireUI, The core fix for CancelledError is correct. Happy to update for the new API if needed.

Yes I'm refactoring the codebase to prepare for Kimi CLI SDK. I'll update you once I complete, you can resolve conflicts then.

@stdrc
Copy link
Collaborator

stdrc commented Oct 25, 2025

BTW could you provide a reproducible case that this CancelledError is somehow visible to the user? IIUC cancellation of a tool call task will be properly handled by kosong

@YangLi-leo
Copy link
Contributor Author

YangLi-leo commented Oct 25, 2025

you are right, the CancelledError can be solved by https://github.com/MoonshotAI/kosong/blob/main/src/kosong/__init__.py#L41, but this part can solve the FIXME comment about processing cleanup while letting kosong handle the error response: except asyncio.CancelledError:
# Handle user cancellation (Ctrl+C or ESC key)
process.kill()
with contextlib.suppress(Exception):
# Wait for process to exit with protection, ignore cleanup failures
await asyncio.shield(asyncio.wait_for(process.wait(), timeout=2.0))
raise

@stdrc
Copy link
Collaborator

stdrc commented Oct 27, 2025

but this part can solve the FIXME comment about processing cleanup

Which FIXME comment?

@YangLi-leo
Copy link
Contributor Author

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.

2 participants