@@ -206,6 +206,7 @@ export function useThreadListActions(): {
206206 const executeAction = useThreadActionExecutor ( ) ;
207207 const snoozeMutation = useAtomCommand ( threadEnvironment . snooze , { reportFailure : false } ) ;
208208 const unsnoozeMutation = useAtomCommand ( threadEnvironment . unsnooze , { reportFailure : false } ) ;
209+ const snoozeInFlightThreadKeys = useRef ( new Set < string > ( ) ) ;
209210
210211 const archiveThread = useCallback (
211212 ( thread : EnvironmentThreadShell ) => {
@@ -219,71 +220,89 @@ export function useThreadListActions(): {
219220 ) ;
220221 const snoozeThread = useCallback (
221222 async ( thread : EnvironmentThreadShell , snoozedUntil : string ) => {
222- if ( ! environmentSupportsSnooze ( thread . environmentId ) ) {
223- Alert . alert (
224- "Could not snooze thread" ,
225- "This environment's server does not support snoozing yet. Update the server to use Snooze." ,
226- ) ;
227- return false ;
228- }
229- if ( ! canSnooze ( thread , { now : new Date ( ) . toISOString ( ) } ) ) {
230- Alert . alert (
231- "Could not snooze thread" ,
232- thread . hasPendingApprovals || thread . hasPendingUserInput
233- ? "This thread is waiting on you. Respond to the pending request before snoozing it."
234- : "This thread is still starting a turn. Try again once it's running." ,
235- ) ;
223+ const key = scopedThreadKey ( thread . environmentId , thread . id ) ;
224+ if ( snoozeInFlightThreadKeys . current . has ( key ) ) {
236225 return false ;
237226 }
227+ snoozeInFlightThreadKeys . current . add ( key ) ;
228+ try {
229+ if ( ! environmentSupportsSnooze ( thread . environmentId ) ) {
230+ Alert . alert (
231+ "Could not snooze thread" ,
232+ "This environment's server does not support snoozing yet. Update the server to use Snooze." ,
233+ ) ;
234+ return false ;
235+ }
236+ if ( ! canSnooze ( thread , { now : new Date ( ) . toISOString ( ) } ) ) {
237+ Alert . alert (
238+ "Could not snooze thread" ,
239+ thread . hasPendingApprovals || thread . hasPendingUserInput
240+ ? "This thread is waiting on you. Respond to the pending request before snoozing it."
241+ : "This thread is still starting a turn. Try again once it's running." ,
242+ ) ;
243+ return false ;
244+ }
238245
239- selectionHaptic ( ) ;
240- const result = await snoozeMutation ( {
241- environmentId : thread . environmentId ,
242- input : {
243- threadId : thread . id ,
244- snoozedUntil,
245- } ,
246- } ) ;
247- if ( result . _tag === "Failure" ) {
248- const error = Cause . squash ( result . cause ) ;
249- Alert . alert (
250- "Could not snooze thread" ,
251- error instanceof Error && error . message . trim ( ) . length > 0
252- ? error . message
253- : "The thread could not be snoozed." ,
254- ) ;
255- return false ;
246+ selectionHaptic ( ) ;
247+ const result = await snoozeMutation ( {
248+ environmentId : thread . environmentId ,
249+ input : {
250+ threadId : thread . id ,
251+ snoozedUntil,
252+ } ,
253+ } ) ;
254+ if ( result . _tag === "Failure" ) {
255+ const error = Cause . squash ( result . cause ) ;
256+ Alert . alert (
257+ "Could not snooze thread" ,
258+ error instanceof Error && error . message . trim ( ) . length > 0
259+ ? error . message
260+ : "The thread could not be snoozed." ,
261+ ) ;
262+ return false ;
263+ }
264+ return true ;
265+ } finally {
266+ snoozeInFlightThreadKeys . current . delete ( key ) ;
256267 }
257- return true ;
258268 } ,
259269 [ snoozeMutation ] ,
260270 ) ;
261271 const unsnoozeThread = useCallback (
262272 async ( thread : EnvironmentThreadShell ) => {
263- if ( ! environmentSupportsSnooze ( thread . environmentId ) ) {
264- Alert . alert (
265- "Could not wake thread" ,
266- "This environment's server does not support snoozing yet. Update the server to wake this thread." ,
267- ) ;
273+ const key = scopedThreadKey ( thread . environmentId , thread . id ) ;
274+ if ( snoozeInFlightThreadKeys . current . has ( key ) ) {
268275 return false ;
269276 }
277+ snoozeInFlightThreadKeys . current . add ( key ) ;
278+ try {
279+ if ( ! environmentSupportsSnooze ( thread . environmentId ) ) {
280+ Alert . alert (
281+ "Could not wake thread" ,
282+ "This environment's server does not support snoozing yet. Update the server to wake this thread." ,
283+ ) ;
284+ return false ;
285+ }
270286
271- selectionHaptic ( ) ;
272- const result = await unsnoozeMutation ( {
273- environmentId : thread . environmentId ,
274- input : { threadId : thread . id , reason : "user" } ,
275- } ) ;
276- if ( result . _tag === "Failure" ) {
277- const error = Cause . squash ( result . cause ) ;
278- Alert . alert (
279- "Could not wake thread" ,
280- error instanceof Error && error . message . trim ( ) . length > 0
281- ? error . message
282- : "The thread could not be woken." ,
283- ) ;
284- return false ;
287+ selectionHaptic ( ) ;
288+ const result = await unsnoozeMutation ( {
289+ environmentId : thread . environmentId ,
290+ input : { threadId : thread . id , reason : "user" } ,
291+ } ) ;
292+ if ( result . _tag === "Failure" ) {
293+ const error = Cause . squash ( result . cause ) ;
294+ Alert . alert (
295+ "Could not wake thread" ,
296+ error instanceof Error && error . message . trim ( ) . length > 0
297+ ? error . message
298+ : "The thread could not be woken." ,
299+ ) ;
300+ return false ;
301+ }
302+ return true ;
303+ } finally {
304+ snoozeInFlightThreadKeys . current . delete ( key ) ;
285305 }
286- return true ;
287306 } ,
288307 [ unsnoozeMutation ] ,
289308 ) ;
0 commit comments