Skip to content

fix: log hook task exceptions instead of silently discarding them#1852

Open
iiitutu wants to merge 1 commit intoMoonshotAI:mainfrom
iiitutu:fix/hook-task-exception-handling
Open

fix: log hook task exceptions instead of silently discarding them#1852
iiitutu wants to merge 1 commit intoMoonshotAI:mainfrom
iiitutu:fix/hook-task-exception-handling

Conversation

@iiitutu
Copy link
Copy Markdown
Contributor

@iiitutu iiitutu commented Apr 13, 2026

Summary

  • Fix silent exception discarding in hook task callbacks across 4 files
  • Replace lambda t: t.exception() if not t.cancelled() else None with proper error logging via logger.error
  • Affects: PreToolUse, PostToolUse, PreLLM, PostCompact, SubagentStop, and wire hook callbacks

Problem

Hook tasks used add_done_callback with a lambda that called t.exception() but never logged the result, causing hook failures to be silently ignored and making debugging extremely difficult.

Solution

Changed the callback to properly log exceptions:

# Before
_hook_task.add_done_callback(lambda t: t.exception() if not t.cancelled() else None)

# After  
_hook_task.add_done_callback(
    lambda t: logger.error("Hook failed: %s", t.exception())
    if not t.cancelled() and t.exception()
    else None
)

Files Modified

  • src/kimi_cli/soul/kimisoul.py (3 locations)
  • src/kimi_cli/soul/toolset.py (2 locations)
  • src/kimi_cli/subagents/runner.py (1 location)
  • src/kimi_cli/hooks/engine.py (1 location)

Open with Devin

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5b27dc2c81

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/kimi_cli/hooks/engine.py Outdated
hook_task: asyncio.Task[None] = asyncio.ensure_future(self._on_wire_hook(handle))
hook_task.add_done_callback(lambda t: t.exception() if not t.cancelled() else None)
hook_task.add_done_callback(
lambda t: logger.error("Hook failed: %s", t.exception())
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Replace %s placeholder in hook error log

logger here is Loguru (used throughout this repo with {} formatting), so logger.error("Hook failed: %s", t.exception()) logs the literal %s and drops the exception details. When a hook task fails, operators only see a generic message and still lose the actual error text, which defeats the purpose of this fix for debugging failed hooks (the same pattern appears in the other updated callbacks in this commit).

Useful? React with 👍 / 👎.

Hook tasks were using add_done_callback with a lambda that called
t.exception() but never logged it, causing failures to be silently
ignored. Now exceptions are properly logged via logger.error.
@iiitutu iiitutu force-pushed the fix/hook-task-exception-handling branch from 5b27dc2 to a916c27 Compare April 13, 2026 02:36
Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

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

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 2 additional findings.

Open in Devin Review

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