Skip to content

fix(tui): enhance sub-agent file write permissions and approval handling#1833

Closed
knqiufan wants to merge 1 commit into
Hmbown:mainfrom
knqiufan:fix/issue-1828-subagent-writes
Closed

fix(tui): enhance sub-agent file write permissions and approval handling#1833
knqiufan wants to merge 1 commit into
Hmbown:mainfrom
knqiufan:fix/issue-1828-subagent-writes

Conversation

@knqiufan
Copy link
Copy Markdown
Contributor

Summary

  • Fixes 子代理无法写入文件 #1828 by allowing approved general and implementer sub-agents to run delegated Suggest file-write tools after agent_open.
  • Keeps Required tools, including shell execution, gated behind parent auto-approval/YOLO mode.
  • Aligns approval_mode=auto with child ToolContext.auto_approve and fails fast after repeated approval-block errors.

Testing

  • cargo test --all-features
  • cargo fmt --all -- --check
  • cargo clippy --all-targets --all-features

Checklist

  • Updated docs or comments as needed
  • Added or updated tests where relevant
  • Verified TUI behavior manually if UI changes

- Approved sub-agents can now write files in delegated roles, allowing `general` and `implementer` children to inherit approved `Suggest` file-write tools after `agent_open` when `approval_mode=auto`.
- Implemented a fail-fast mechanism for repeated approval blocks to improve responsiveness.
- Added tests to verify the new approval logic and delegated write permissions for sub-agents.

This change addresses issues with sub-agent tool execution and enhances the overall approval workflow.
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enables approved sub-agents, specifically those with general or implementer roles, to inherit file-write tools and ensures that approval_mode=auto is consistently propagated to child tool contexts. It also introduces a fail-fast mechanism that terminates sub-agents after three consecutive approval blocks to prevent infinite loops. Review feedback suggests implementing an RAII guard for managing resident leases to ensure they are released on all exit paths and recommends using structured error types instead of string matching for detecting approval blocks.

&agent_id,
format!("step {steps}/{max_steps}: failed after repeated approval blocks"),
);
release_resident_leases_for(&agent_id);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The manual call to release_resident_leases_for here is necessary for this early return, but the same release logic is missing in other early return paths within this function (specifically the Cancelled returns at lines 3370 and 3451). While those lines are not part of this diff, introducing a RAII guard at the start of run_subagent would be a more robust way to ensure leases are always released regardless of how the function exits.

Comment on lines +4379 to +4381
fn is_subagent_approval_block(result: &str) -> bool {
result.starts_with("Error:") && result.contains("requires approval")
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

This heuristic for detecting approval blocks relies on string matching which could be fragile if error messages are ever localized or refactored. While acceptable for now given the internal nature of these errors, consider using a structured error type or a specific error code in the future to make this detection more reliable.

@Hmbown Hmbown mentioned this pull request May 20, 2026
11 tasks
@Hmbown
Copy link
Copy Markdown
Owner

Hmbown commented May 21, 2026

Thanks for the careful subagent write-permission fix. This was harvested into v0.8.40 release PR #1823 as commit 9f0ff4b, and #1823 is now CI-green. Closing as superseded by the release branch; thank you for tightening this path.

@Hmbown Hmbown closed this May 21, 2026
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.

子代理无法写入文件

2 participants