Scope TUI approval requests to their threads (#39372)

## Why

Approval and item IDs can collide across concurrent threads. Tracking pending app-server approvals by ID alone can therefore resolve, submit, or dismiss a request from the wrong thread.

## What changed

- Key command execution, file change, and permissions approvals by both thread ID and approval ID.
- Route approval responses through the originating thread and require the thread to match when processing resolution notifications or dismissing approval prompts.
- Canonicalize parseable thread IDs so equivalent UUID representations still match.

## Testing

- Cover colliding approval IDs across threads, mismatched resolution notifications, prompt dismissal, and response routing for primary and background threads.

GitOrigin-RevId: c2d899a1e4b6a6413c78a0595a5311f5fabb9815
This commit is contained in:
Eric Traut authored and copyberry committed 2026-08-19 02:28:42 +00:00
1 parent fde2156057
commit 8843960ba0
9 files changed
+358 -125

No files matched your search

+6 -3
View File
@@ -126,11 +126,11 @@ impl QueuedInterrupt {
fn matches_resolved_prompt(&self, request: &ResolvedAppServerRequest) -> bool {
match self {
QueuedInterrupt::ExecApproval(ev) => {
matches!(request, ResolvedAppServerRequest::ExecApproval { id }
matches!(request, ResolvedAppServerRequest::ExecApproval { id, .. }
if ev.effective_approval_id() == id.as_str())
}
QueuedInterrupt::ApplyPatchApproval(ev) => {
matches!(request, ResolvedAppServerRequest::FileChangeApproval { id }
matches!(request, ResolvedAppServerRequest::FileChangeApproval { id, .. }
if ev.call_id == id.as_str())
}
QueuedInterrupt::Elicitation { request_id, params } => {
@@ -140,7 +140,7 @@ impl QueuedInterrupt {
} if params.server_name == server_name.as_str() && request_id == resolved_request_id)
}
QueuedInterrupt::RequestPermissions(ev) => {
matches!(request, ResolvedAppServerRequest::PermissionsApproval { id }
matches!(request, ResolvedAppServerRequest::PermissionsApproval { id, .. }
if ev.call_id == id.as_str())
}
QueuedInterrupt::RequestUserInput(ev) => {
@@ -242,6 +242,7 @@ mod tests {
assert!(
!manager.remove_resolved_prompt(&ResolvedAppServerRequest::ExecApproval {
thread_id: "thread-1".to_string(),
id: "call".to_string(),
})
);
@@ -249,6 +250,7 @@ mod tests {
assert!(
manager.remove_resolved_prompt(&ResolvedAppServerRequest::ExecApproval {
thread_id: "thread-1".to_string(),
id: "approval".to_string(),
})
);
@@ -263,6 +265,7 @@ mod tests {
assert!(
!manager.remove_resolved_prompt(&ResolvedAppServerRequest::ExecApproval {
thread_id: "thread-1".to_string(),
id: "call".to_string(),
})
);