From 9b93d563c2cbbde509a1c88b957b2719b9112d15 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 28 Oct 2026 17:21:01 +0000 Subject: [PATCH 1/4] test(mobile): reproduce #26536 un-settle dropped while settle is pending These tests reproduce #26536: with a settle on a thread still pending, unsettleThread on the same thread returns false without issuing the unsettle command or alerting. Co-Authored-By: Claude Opus 5.5 --- .../home/useThreadListActions.test.ts | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/apps/mobile/src/features/home/useThreadListActions.test.ts b/apps/mobile/src/features/home/useThreadListActions.test.ts index ec0f6a14558d..a288ca9ad122 100644 --- a/apps/mobile/src/features/home/useThreadListActions.test.ts +++ b/apps/mobile/src/features/home/useThreadListActions.test.ts @@ -30,6 +30,7 @@ const state = vi.hoisted(() => ({ buttons?: { text: string; onPress?: () => void }[]; }[], afterRequest: undefined as (() => void) | undefined, + heldActions: new Map>(), })); vi.mock("react", () => ({ @@ -138,6 +139,7 @@ vi.mock("../../state/threads", () => ({ input: { threadId: string; orderKey?: string }; }) => { state.requests.push({ action, ...request }); + await state.heldActions.get(action); if (!state.scopes.get(request.environmentId)?.has(AuthOrchestrationOperateScope)) { return AsyncResult.failure(Cause.fail(new Error("Thread operation denied"))); } @@ -192,6 +194,7 @@ beforeEach(() => { state.dialogs = []; state.alerts = []; state.afterRequest = undefined; + state.heldActions = new Map(); }); afterEach(() => { @@ -463,6 +466,24 @@ describe("thread action undo", () => { }); }); +describe("thread actions while another action is pending", () => { + it("un-settles a thread whose settle is still pending", async () => { + const actions = useThreadListActions(); + const thread = makeThread(); + const settleResponse = Promise.withResolvers(); + state.heldActions.set("settle", settleResponse.promise); + + const settled = actions.settleThread(thread); + const unsettled = actions.unsettleThread(thread); + settleResponse.resolve(); + + const results = await Promise.all([settled, unsettled]); + + expect(state.requests.map(({ action }) => action)).toEqual(["settle", "unsettle"]); + expect(results).toEqual([true, true]); + }); +}); + describe("thread archive guard", () => { it("keeps active provider runs out of the archive", async () => { const thread = makeThread({ From 5c97813013c539863c229fe829263ecb2c9d2400 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 28 Oct 2026 17:23:16 +0000 Subject: [PATCH 2/4] fix(mobile): un-settle while a settle is pending is no longer dropped The thread-list action guard was keyed only by thread, so any second action on a thread with a pending action returned false silently. Key it by action and thread: repeats of the pending action stay a no-op, and a different action runs behind it through the per-thread serial command scheduler and reports its own failure. Fixes pingdotgg/t3code#26536 Co-Authored-By: Claude Opus 5.5 --- apps/mobile/src/features/home/useThreadListActions.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/mobile/src/features/home/useThreadListActions.ts b/apps/mobile/src/features/home/useThreadListActions.ts index cac37f055280..51ddf00d7a85 100644 --- a/apps/mobile/src/features/home/useThreadListActions.ts +++ b/apps/mobile/src/features/home/useThreadListActions.ts @@ -90,7 +90,7 @@ function useThreadActionExecutor( const deleteMutation = useAtomCommand(threadEnvironment.delete, { reportFailure: false }); const settleMutation = useAtomCommand(threadEnvironment.settle, { reportFailure: false }); const unsettleMutation = useAtomCommand(threadEnvironment.unsettle, { reportFailure: false }); - const inFlightThreadKeys = useRef(new Set()); + const inFlightActionKeys = useRef(new Set()); const executeAction = async ( action: ThreadListAction, @@ -99,11 +99,13 @@ function useThreadActionExecutor( ) => { if (!checkThreadOperationPermission(thread, actionFailureTitle(action))) return false; const key = scopedThreadKey(thread.environmentId, thread.id); - if (inFlightThreadKeys.current.has(key)) { + // Only a repeat of the pending action is dropped; other actions queue behind it per thread. + const actionKey = JSON.stringify([action, key]); + if (inFlightActionKeys.current.has(actionKey)) { return false; } - inFlightThreadKeys.current.add(key); + inFlightActionKeys.current.add(actionKey); selectionHaptic(); const succeeded = await (async () => { if ( @@ -162,7 +164,7 @@ function useThreadActionExecutor( onCompleted?.(action, thread); return true; })(); - inFlightThreadKeys.current.delete(key); + inFlightActionKeys.current.delete(actionKey); return succeeded; }; From 2385af810d111098ed4de50726d8aef1f84e03cb Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 28 Oct 2026 17:31:06 +0000 Subject: [PATCH 3/4] fix(mobile): settle again after un-settle while the first settle is pending Only a repeat of the latest pending action on a thread is dropped now, so settle, un-settle, settle all reach the per-thread command queue in order. Co-Authored-By: Claude Opus 5.5 --- .../features/home/useThreadListActions.test.ts | 17 +++++++++++++++++ .../src/features/home/useThreadListActions.ts | 12 ++++++------ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/apps/mobile/src/features/home/useThreadListActions.test.ts b/apps/mobile/src/features/home/useThreadListActions.test.ts index a288ca9ad122..740df8033b41 100644 --- a/apps/mobile/src/features/home/useThreadListActions.test.ts +++ b/apps/mobile/src/features/home/useThreadListActions.test.ts @@ -482,6 +482,23 @@ describe("thread actions while another action is pending", () => { expect(state.requests.map(({ action }) => action)).toEqual(["settle", "unsettle"]); expect(results).toEqual([true, true]); }); + + it("settles again after un-settling while the first settle is still pending", async () => { + const actions = useThreadListActions(); + const thread = makeThread(); + const settleResponse = Promise.withResolvers(); + state.heldActions.set("settle", settleResponse.promise); + + const pending = [ + actions.settleThread(thread), + actions.unsettleThread(thread), + actions.settleThread(thread), + ]; + settleResponse.resolve(); + + expect(await Promise.all(pending)).toEqual([true, true, true]); + expect(state.requests.map(({ action }) => action)).toEqual(["settle", "unsettle", "settle"]); + }); }); describe("thread archive guard", () => { diff --git a/apps/mobile/src/features/home/useThreadListActions.ts b/apps/mobile/src/features/home/useThreadListActions.ts index 51ddf00d7a85..cf081b016327 100644 --- a/apps/mobile/src/features/home/useThreadListActions.ts +++ b/apps/mobile/src/features/home/useThreadListActions.ts @@ -90,7 +90,7 @@ function useThreadActionExecutor( const deleteMutation = useAtomCommand(threadEnvironment.delete, { reportFailure: false }); const settleMutation = useAtomCommand(threadEnvironment.settle, { reportFailure: false }); const unsettleMutation = useAtomCommand(threadEnvironment.unsettle, { reportFailure: false }); - const inFlightActionKeys = useRef(new Set()); + const latestPendingActions = useRef(new Map()); const executeAction = async ( action: ThreadListAction, @@ -99,13 +99,13 @@ function useThreadActionExecutor( ) => { if (!checkThreadOperationPermission(thread, actionFailureTitle(action))) return false; const key = scopedThreadKey(thread.environmentId, thread.id); - // Only a repeat of the pending action is dropped; other actions queue behind it per thread. - const actionKey = JSON.stringify([action, key]); - if (inFlightActionKeys.current.has(actionKey)) { + // Only a repeat of the latest pending action is dropped; others queue behind it per thread. + if (latestPendingActions.current.get(key)?.action === action) { return false; } - inFlightActionKeys.current.add(actionKey); + const pending = { action }; + latestPendingActions.current.set(key, pending); selectionHaptic(); const succeeded = await (async () => { if ( @@ -164,7 +164,7 @@ function useThreadActionExecutor( onCompleted?.(action, thread); return true; })(); - inFlightActionKeys.current.delete(actionKey); + if (latestPendingActions.current.get(key) === pending) latestPendingActions.current.delete(key); return succeeded; }; From e4fc9faeb40906411176c32eb933c1a93845f81a Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Wed, 11 Nov 2026 00:32:31 +0000 Subject: [PATCH 4/4] test(mobile): fold pending-action cases into one regression test AI-assisted; verified with the tests and tools listed above. --- .../home/useThreadListActions.test.ts | 52 ++++++------------- .../src/features/home/useThreadListActions.ts | 2 +- 2 files changed, 18 insertions(+), 36 deletions(-) diff --git a/apps/mobile/src/features/home/useThreadListActions.test.ts b/apps/mobile/src/features/home/useThreadListActions.test.ts index 9e41473413a6..428bbaf7b9b3 100644 --- a/apps/mobile/src/features/home/useThreadListActions.test.ts +++ b/apps/mobile/src/features/home/useThreadListActions.test.ts @@ -409,6 +409,23 @@ describe("thread action undo", () => { expect(state.archivedRefreshes).toEqual([primaryEnvironmentId]); }); + it("sends a different action while one is pending for the same thread", async () => { + const actions = useThreadListActions(); + const thread = makeThread(); + const settleResponse = Promise.withResolvers(); + state.heldActions.set("settle", settleResponse.promise); + + const pending = [ + actions.settleThread(thread), + actions.unsettleThread(thread), + actions.settleThread(thread), + ]; + settleResponse.resolve(); + + expect(await Promise.all(pending)).toEqual([true, true, true]); + expect(state.requests.map(({ action }) => action)).toEqual(["settle", "unsettle", "settle"]); + }); + it("restores pin placement and snooze after settling, only once", async () => { const thread = makeThread({ pinnedAt: "2026-09-02T00:00:00.000Z", @@ -544,41 +561,6 @@ describe("thread action undo", () => { }); }); -describe("thread actions while another action is pending", () => { - it("un-settles a thread whose settle is still pending", async () => { - const actions = useThreadListActions(); - const thread = makeThread(); - const settleResponse = Promise.withResolvers(); - state.heldActions.set("settle", settleResponse.promise); - - const settled = actions.settleThread(thread); - const unsettled = actions.unsettleThread(thread); - settleResponse.resolve(); - - const results = await Promise.all([settled, unsettled]); - - expect(state.requests.map(({ action }) => action)).toEqual(["settle", "unsettle"]); - expect(results).toEqual([true, true]); - }); - - it("settles again after un-settling while the first settle is still pending", async () => { - const actions = useThreadListActions(); - const thread = makeThread(); - const settleResponse = Promise.withResolvers(); - state.heldActions.set("settle", settleResponse.promise); - - const pending = [ - actions.settleThread(thread), - actions.unsettleThread(thread), - actions.settleThread(thread), - ]; - settleResponse.resolve(); - - expect(await Promise.all(pending)).toEqual([true, true, true]); - expect(state.requests.map(({ action }) => action)).toEqual(["settle", "unsettle", "settle"]); - }); -}); - describe("thread archive guard", () => { it("keeps active provider runs out of the archive", async () => { const thread = makeThread({ diff --git a/apps/mobile/src/features/home/useThreadListActions.ts b/apps/mobile/src/features/home/useThreadListActions.ts index d14aacb90ac0..9d44d971c1f0 100644 --- a/apps/mobile/src/features/home/useThreadListActions.ts +++ b/apps/mobile/src/features/home/useThreadListActions.ts @@ -100,7 +100,7 @@ function useThreadActionExecutor( ) => { if (!checkThreadOperationPermission(thread, actionFailureTitle(action))) return false; const key = scopedThreadKey(thread.environmentId, thread.id); - // Only a repeat of the latest pending action is dropped; others queue behind it per thread. + // Drop only a repeat of the latest pending action; Settle → Un-settle → Settle must all send. if (latestPendingActions.current.get(key)?.action === action) { return false; }