Skip to content

fix: decouple background agent context from parent message lifecycle#2392

Merged
dgageot merged 1 commit intodocker:mainfrom
dgageot:board/fix-docker-agent-issue-2357-bcd7a443
Apr 13, 2026
Merged

fix: decouple background agent context from parent message lifecycle#2392
dgageot merged 1 commit intodocker:mainfrom
dgageot:board/fix-docker-agent-issue-2357-bcd7a443

Conversation

@dgageot
Copy link
Copy Markdown
Member

@dgageot dgageot commented Apr 12, 2026

Background agent tasks were cancelled when the parent message context was cancelled (e.g. user sends a new message in the TUI), making background sub-agents with MCP tools flaky.

Changes

  • Use context.WithoutCancel so background tasks survive parent context cancellation while remaining explicitly stoppable via HandleStop
  • Replace statusToString map+function with taskStatus.String() method
  • Extract task.writeOutput() and task.formatView() helper methods
  • Simplify backgroundAgentTools() return type (never errors)
  • Simplify pruneCompleted() to check s != taskRunning

Fixes #2357

Background agent tasks were cancelled when the parent message context
was cancelled (e.g. user sends a new message in the TUI), making
background sub-agents with MCP tools flaky.

Use context.WithoutCancel so background tasks survive parent context
cancellation while remaining explicitly stoppable via HandleStop.

Also simplify the handler code:
- Replace statusToString map+function with taskStatus.String() method
- Extract task.writeOutput() and task.formatView() helper methods
- Simplify backgroundAgentTools() to return []tools.Tool (never errors)
- Simplify pruneCompleted() to check s != taskRunning

Fixes docker#2357

Assisted-By: docker-agent
@dgageot dgageot requested a review from a team as a code owner April 12, 2026 15:47
@dgageot dgageot merged commit 1de9ad5 into docker:main Apr 13, 2026
9 checks passed
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.

sub-agents in background with MCP tools are flaky

2 participants