fix(claude-agent): warn on empty result, debug-log hook skips#281
Open
fix(claude-agent): warn on empty result, debug-log hook skips#281
Conversation
- activities.py: log WARNING when Claude returns 0 messages (catches silent failures from model connectivity issues e.g. VPN/proxy down) - hooks.py: log DEBUG when pre/post_tool_use hooks bail early due to missing task_id, making it visible why tool call logs aren't appearing Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…ssages Returning 0 messages means the model was unreachable (VPN down, proxy error, etc). Logging a warning and succeeding caused Temporal to mark the activity as completed, the workflow to continue pointlessly, and the root cause to be invisible. Raising RuntimeError lets Temporal retry the activity or surface the failure clearly in the workflow timeline.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
activities.py: raiseRuntimeErrorwhenrun_claude_agent_activityreturns 0 messages, instead of silently succeeding. This lets Temporal mark the activity as FAILED and retry it, rather than the workflow proceeding pointlessly with empty results.Root cause: when the model API is unreachable (e.g. LiteLLM proxy can't reach Anthropic due to VPN being off), Claude Code runs for minutes internally retrying, then exits cleanly with 0 messages. The activity previously "succeeded" with no observable error, the workflow continued, and the root cause was invisible.
hooks.py: logDEBUGinpre/post_tool_usewhen the early-return fires due to missingtask_id, making it visible why tool call logs aren't appearing.Test plan
FAILEDin Temporal withRuntimeError: Claude returned 0 messages--debugandtask_id=None— should seeDEBUG: Hooks skipping pre_tool_use🤖 Generated with Claude Code
Greptile Summary
This PR improves error observability for the Claude agent Temporal activity. When the Claude SDK returns 0 messages (e.g., due to model API being unreachable behind a VPN), the activity now raises a
RuntimeErrorinstead of silently succeeding with empty results. This lets Temporal mark the activity as FAILED and trigger retries. Additionally, DEBUG-level logging is added to the hook early-return paths to make it clear why tool call logs are absent whentask_idis not set.activities.py: RaisesRuntimeErrorwhenget_results()returns no messages, surfacing connectivity issues to Temporalhooks.py: Adds debug logging inpre_tool_useandpost_tool_usewhen skipping due to missingtask_idortool_use_idConfidence Score: 4/5
activities.pyhas a minor double-cleanup issue worth addressing.Important Files Changed
Flowchart
%%{init: {'theme': 'neutral'}}%% flowchart TD A[run_claude_agent_activity] --> B[Initialize handler & Claude SDK] B --> C[Process messages via receive_response] C --> D[handler.cleanup] D --> E{results has messages?} E -- Yes --> F[Return results to Temporal] E -- No --> G[Raise RuntimeError] G --> H[except block: log error + cleanup again] H --> I[Re-raise → Temporal marks FAILED & retries]Last reviewed commit: 336e088