Skip to content

Handle background tasks in agent response loop - #6685

Open
suhaibmujahid wants to merge 6 commits into
mozilla:masterfrom
suhaibmujahid:worktree-fix-6656-background-tasks
Open

Handle background tasks in agent response loop#6685
suhaibmujahid wants to merge 6 commits into
mozilla:masterfrom
suhaibmujahid:worktree-fix-6656-background-tasks

Conversation

@suhaibmujahid

Copy link
Copy Markdown
Member

Fixes #6656

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread libs/hackbot-runtime/hackbot_runtime/claude.py

if isinstance(msg, TaskStartedMessage):
pending[msg.task_id] = msg.description
elif isinstance(msg, (TaskNotificationMessage, TaskUpdatedMessage)):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Nice catch! Fixed in b871759.

verbose: bool = False,
log: Path | None = None,
actions_recorder: ActionsRecorder | None = None,
background_task_timeout_s: float = 3 * 60 * 60,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

3 hours seems too long for the entire agent run.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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.

@suhaibmujahid
suhaibmujahid marked this pull request as ready for review August 21, 2026 22:24
@suhaibmujahid
suhaibmujahid requested a review from a team as a code owner August 21, 2026 22:24
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.

The bug-fix agent generated a fix but did not use the submit patch tool

3 participants