Merged
Conversation
- Add pending_approvals queue (VecDeque) in app.rs to serialize tool approvals - Fix y/n dialog on subsequent tools by marking blocks by call_id instead of active block - Remove unused Status::Queued variant from transcript.rs and all tool impls - Refactor ToolExecutor with WaitingFor enum (Nothing/Effect/Approval) instead of separate Option fields - Add poll_receiver() helper and NoopWaker at module level to reduce duplication - Single poll_waiting() method replaces check_pending_effect/check_pending_approval
Core fix: - Spawn handlers in separate tokio tasks to prevent output loss when select! loop drops futures mid-await - Add WaitingFor::Handler variant to track spawned handler execution - Add 10ms sleep when waiting for user approval to prevent busy-polling - Reduce poll_waiting logs to trace level UI improvements: - Add custom blocks for list_background_tasks and get_background_task - Render as list_background_tasks() and get_background_task(task_id) - Follow same pattern as ShellBlock with status, approval prompt, results Config support: - Add list_background_tasks and get_background_task to ToolsConfig - Support auto-approve filters (e.g., allow = [".*"]) Documentation: - Add comprehensive src/tools/README.md for adding new tools Tests: - Add ToolExecutor tests for concurrent background tools - Verify no output loss with multiple concurrent tasks
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
Adds support for running tools in the background with a
background: trueparameter, spawning sub-agents for parallel research tasks, and fixes critical concurrency bugs.Features
Background Tool Execution
Any tool can now be run in the background by passing
background: true. The tool returns immediately with a task_id, allowing the conversation to continue while work happens in parallel.Sub-Agents (
mcp_task)New
mcp_tasktool spawns a background sub-agent to handle research and analysis tasks:get_background_taskTask Management Tools
list_background_tasks- Shows all running/completed background tasksget_background_task(task_id)- Retrieves result and removes from trackingBoth have custom UI rendering and support auto-approve via config:
Bug Fixes
Background Tool Output Loss
Problem: When multiple background tools ran concurrently, some would lose their output entirely.
Root cause: The main
select!loop could drop futures mid-await, losing handler results stored in local variables.Fix: Spawn handlers in separate tokio tasks. Results sent via oneshot channel and polled in
poll_waiting(). Spawned tasks run to completion regardless of executor state.Concurrent Tool Approval
Problem: When Claude called multiple tools at once, only the first showed the y/n approval prompt.
Fix: Added
pending_approvalsqueue in app.rs to serialize approvals. Each tool gets its turn for the approval dialog.Busy-Polling While Waiting for Approval
Problem: Tight loop when waiting for user input, spamming logs and wasting CPU.
Fix: 10ms sleep when blocked on approval/effects. Reduced poll logs to trace level.
Architecture Changes
WaitingFor State Machine
Replaced separate
Optionfields with enum:Tool Block Status
Status::QueuedvariantDocumentation
Added comprehensive
src/tools/README.mdcovering:Testing
Stats