Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix(approval): revalidate the thread route after the durable lookup

M3gA-Mindeec1b23926d4
diff --git a/src/openhuman/security/approval/gate_state.rs b/src/openhuman/security/approval/gate_state.rs
index f8adee1725..6dd5a77e5f 100644
--- a/src/openhuman/security/approval/gate_state.rs
+++ b/src/openhuman/security/approval/gate_state.rs
@@ -207,10 +207,27 @@ impl ApprovalGate {
/// replaying a card the user has already answered.
pub fn parked_request_for_thread(&self, thread_id: &str) -> Option<PendingApproval> {
let request_id = self.pending_for_thread(thread_id)?;
- self.list_pending()
+ let row = self
+ .list_pending()
.ok()?
.into_iter()
- .find(|row| row.request_id == request_id)
+ .find(|row| row.request_id == request_id)?;
+ // Re-read the route before answering. `list_pending` is a store read and
+ // runs without the route lock held, so between the two the mapping can
+ // be cleared by a caller-bound abandon or overwritten by a replacement
+ // turn parking a new approval on the same thread (#4774's scenario).
+ // Either leaves this row pending while it is no longer the thread's, and
+ // the only caller replays what it gets straight onto the user's screen —
+ // so a stale row here is a stale approval card, not a harmless read.
+ //
+ // Narrowing, not closing: the row itself could still be decided after
+ // this check. That is the pre-existing fire-and-forget property of the
+ // replay path, and `request_id` idempotency on the client is what covers
+ // it; this only stops the lookup from *starting* with a row it can
+ // already tell is not the thread's (#6212 review).
+ self.pending_for_thread(thread_id)
+ .is_some_and(|current| current == request_id)
+ .then_some(row)
}
/// Drop the thread → request mapping when it still belongs to this request.