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\n\n`parked_request_for_thread` read the thread→request route, then called\n`list_pending` — a store read — without holding the route lock. In that window\na caller-bound abandon can clear the route, or a replacement turn can park a\nnew approval on the same thread and overwrite it (#4774's scenario), while the\noriginal row is still pending. The lookup would then return a row that is no\nlonger the thread's, and its only caller replays what it gets straight onto the\nuser's screen, so a stale row here is a stale approval card.\n\nRe-read the route after the lookup and answer only if it still names the same\nrequest. Raised by @coderabbitai in review.\n\nNarrowing, not closing, and the comment says so: the row can still be decided\nafter the check. That is the pre-existing fire-and-forget property of the\nreplay path, covered on the client by `request_id` idempotency — this only\nstops the lookup from starting with a row it can already tell is not the\nthread's.\n\nNo test. `list_pending` resolves through `store::list_pending(&self.config)`\nrather than an injectable seam, so nothing can force the interleaving, and\nevery reachable *state* is answered identically by both versions: with the\nroute cleared, the old code returns `None` from `pending_for_thread` before it\never reads the store. A state-based test here could not fail for the reason it\nexists, so one is not added.\n\nClaude-Session: https://claude.ai/code/session_01Fu3PXYSu3gV9u9kV6CwH1G\n

M3gA-Mindc38bb01314aa
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.