Handle background tasks in agent response loop - #6685
Conversation
There was a problem hiding this comment.
Pull request overview
Adds background-task-aware response handling so the bug-fix agent waits for deferred work before accepting its final result.
Changes:
- Tracks task lifecycle messages and waits for a settled result.
- Adds timeout and failure handling.
- Adds regression tests for completion and timeout scenarios.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
libs/hackbot-runtime/hackbot_runtime/claude.py |
Adds settled-response handling. |
libs/hackbot-runtime/tests/test_claude.py |
Tests task lifecycle behavior. |
agents/bug-fix/hackbot_agents/bug_fix/agent.py |
Integrates the new response loop. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| if isinstance(msg, TaskStartedMessage): | ||
| pending[msg.task_id] = msg.description | ||
| elif isinstance(msg, (TaskNotificationMessage, TaskUpdatedMessage)): |
There was a problem hiding this comment.
It would be better to limit pending-task tracking only to local_agent and local_workflow , since these are the tasks whose completion runs a follow-up. ( Background shells and monitors may run indefinitely). Found it here https://github.com/anthropics/claude-agent-sdk-python/blob/main/src/claude_agent_sdk/_internal/query.py#L38-L52
| verbose: bool = False, | ||
| log: Path | None = None, | ||
| actions_recorder: ActionsRecorder | None = None, | ||
| background_task_timeout_s: float = 3 * 60 * 60, |
There was a problem hiding this comment.
3 hours seems too long for the entire agent run.
There was a problem hiding this comment.
I agree, but I think about it as a safeguard, that should never happen, but if it happened this is to make it less bad. We should have a sign when this happens and act on it by solving the underlying issues instead of just reducing the general timeout.
Fixes #6656