Skip to content

feat(subagent): ✨ Add parallel delegation#209

Merged
jorben merged 8 commits into
masterfrom
feat/parallel-subagents
May 27, 2026
Merged

feat(subagent): ✨ Add parallel delegation#209
jorben merged 8 commits into
masterfrom
feat/parallel-subagents

Conversation

@jorben
Copy link
Copy Markdown
Contributor

@jorben jorben commented May 27, 2026

Summary

  • Add agent_parallel for bounded concurrent delegation to explore, review, and read-only custom subagents.
  • Add structured batch results with completed, failed, skipped, and batch status metadata.
  • Add helper timeout, global helper concurrency limiting, prompt guidance, and frontend tool-name constant sync.

Test Plan

  • cargo fmt --check --manifest-path src-tauri/Cargo.toml
  • cargo test --locked --manifest-path src-tauri/Cargo.toml
  • npm run typecheck
  • npm run test:unit

🤖 Generated with TiyCode

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 27, 2026

AI Code Review Summary

PR: #209 (feat(subagent): ✨ Add parallel delegation)
Preferred language: English

Overall Assessment

Detected 1 actionable findings, prioritize CRITICAL/HIGH before merge.

Major Findings by Severity

  • HIGH (1)
    • src-tauri/src/core/tool_gateway.rs:640 - Tool execution semaphore can cause deadlock when terminal tools are also counted

Actionable Suggestions

  • Unify tool and terminal semaphore acquisition order (always acquire tool semaphore first) to avoid deadlocks.
  • Add abort-signal short-circuit inside run_parallel_delegate_task before consuming semaphore slots in the tool gateway.
  • Refactor SubagentProfile to expose allowed_tools generically so parallel safety validation is future-proof.
  • Rename copiedCopyTargetId to copiedTargetId for clarity.
  • Add a dedicated semaphore or admission control for parallel helper subagent tool executions to avoid saturating the global tool_execution_semaphore.
  • Run integration tests with 5 concurrent custom helpers, each using multiple tools, to validate that the system does not deadlock or timeout under maximum parallel load.

Potential Risks

  • Deadlock under concurrent terminal tool use from parallel helpers.
  • Parallel cancellation still burns limited execution slots.
  • Future subagent profile types may bypass parallel safety checks.
  • Resource contention between parallel subagent tool calls and main-agent tool calls could degrade performance or cause tool timeouts at high concurrency.

Test Suggestions

  • Integration test: parallel batch cancelled mid-flight should release semaphore permits quickly.
  • Integration test: multiple helpers using terminal-control tools under a max-concurrency smaller than 5.
  • Unit test: parallel safety validation with a hypothetical non-Custom profile that has a tool list.
  • Integration test: parallel subagent with 5 helpers, each calling read/search tools concurrently, verifying no tool timeout or semaphore starvation.
  • Unit test: run_parallel_delegate_task behavior when tool gateway semaphore is fully acquired (simulate contention).
  • E2E test: abort signal propagation during parallel execution to verify fail-fast and skip behavior.

File-Level Coverage Notes

  • src-tauri/Cargo.toml: Minor dependency version update; no performance impact.
  • src-tauri/src/core/agent_session_execution.rs: Parallel subagent execution is bounded by max concurrency (5) and task limit (5). No unbounded concurrency or memory issues. Sorting and serialization of small result sets is negligible.
  • src-tauri/src/core/agent_session_tools.rs: Trivial change adding Parallel variant returning None; no performance impact.
  • src-tauri/src/core/prompt/providers.rs: String changes only; no performance impact.
  • src-tauri/src/core/subagent/mod.rs: No performance impact; module exports only.
  • src-tauri/src/core/subagent/orchestrator.rs: Subagent tool executions now use a standard timeout instead of None, preventing runaway helpers. This may improve overall throughput by avoiding stuck tasks.
  • src-tauri/src/core/subagent/parallel_contract.rs: Constants enforce bounded concurrency and task counts. No performance concerns.
  • src-tauri/src/core/subagent/runtime_orchestration.rs: No performance impact; tool definition extensions only.
  • src-tauri/src/core/tool_gateway.rs: Adding semaphores (max 5 concurrent tools, max 1 terminal control) reduces contention and improves stability. The slight reduction in parallelism is intentional and beneficial for resource fairness.
  • src/modules/workbench-shell/ui/runtime-thread-surface-state.ts: New copy-state functions perform linear scans but operate on message arrays; negligible overhead for typical thread lengths.
  • src/modules/workbench-shell/ui/runtime-thread-surface.test.tsx: No performance impact; unit tests only.
  • src/modules/workbench-shell/ui/runtime-thread-surface.tsx: Assistant run copy state is derived via useMemo with a full scan of presentationEntries on each timeline change. For very large threads with frequent streaming updates this could cause noticeable recomputation, but it's unlikely in typical use. Consider incremental updates if profiling shows a bottleneck. (Potential but unconfirmed performance overhead for large threads with rapid updates.)
  • src/shared/constants/tool-names.test.ts: No performance impact; test additions.
  • src/shared/constants/tool-names.ts: No performance impact; constant addition.

Inline Downgraded Items (processed but not inline)

  • None

Coverage Status

  • Target files: 14
  • Covered files: 14
  • Uncovered files: 0
  • No-patch/binary covered as file-level: 0
  • Findings with unknown confidence (N/A): 0

Uncovered list:

  • None

No-patch covered list:

  • None

Runtime/Budget

  • Rounds used: 1/4
  • Planned batches: 1
  • Executed batches: 1
  • Sub-agent runs: 3
  • Planner calls: 1
  • Reviewer calls: 3
  • Model calls: 4/64
  • Structured-output summary-only degradation: NO

Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Automated PR review completed.

  • Findings kept: 0
  • Findings with unknown confidence: 0
  • Inline comments attempted: 1
  • Target files: 10
  • Covered files: 10
  • Uncovered files: 0
    See the summary comment for detailed analysis and coverage details.

@@ -1,7 +1,10 @@
use std::sync::atomic::Ordering;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated review completed for this PR diff. No concrete inline issue was selected after aggregation.

jorben added 2 commits May 27, 2026 19:59
Replace per-message copy with per-run copy for assistant messages so
that clicking copy aggregates all text across the run. The copy button
now appears only on the last copyable plain assistant message per run,
and blurs on mouse leave to prevent stale focus state.
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Automated PR review completed.

  • Findings kept: 0
  • Findings with unknown confidence: 0
  • Inline comments attempted: 1
  • Target files: 10
  • Covered files: 10
  • Uncovered files: 0
    See the summary comment for detailed analysis and coverage details.

@@ -1,7 +1,10 @@
use std::sync::atomic::Ordering;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Automated review completed for this PR diff. No concrete inline issue was selected after aggregation.

@jorben jorben merged commit f6d0f21 into master May 27, 2026
4 checks passed
@jorben jorben deleted the feat/parallel-subagents branch May 27, 2026 12:32
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Automated PR review completed.

  • Findings kept: 1
  • Findings with unknown confidence: 0
  • Inline comments attempted: 1
  • Target files: 14
  • Covered files: 14
  • Uncovered files: 0
    See the summary comment for detailed analysis and coverage details.

} else {
None
};
let _tool_execution_permit = self
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[HIGH] Tool execution semaphore can cause deadlock when terminal tools are also counted

Acquiring both a terminal-control semaphore and a general tool semaphore together can deadlock when multiple helpers compete for terminal tools under concurrency limits.

Suggestion: Use try_acquire with fallback, or acquire the tool semaphore first and only then acquire the terminal semaphore; or unify them into a single resource-permit model.

Risk: Under heavy parallel load with terminal tools, tool executions may hang until timeout instead of progressing.

Confidence: 0.85

[From SubAgent: general]

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.

1 participant