Skip to content
This repository was archived by the owner on Aug 6, 2026. It is now read-only.

Commit 3bfdd0e

Browse files
Fix task archiving when pin sync fails
Generated-By: PostHog Code Task-Id: 4829266a-889b-49eb-bacd-4c1426b27b2b
1 parent 73d1757 commit 3bfdd0e

2 files changed

Lines changed: 39 additions & 4 deletions

File tree

packages/core/src/archive/archiveOrchestration.test.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,26 @@ describe("archiveTask", () => {
113113
expect(harness.deps.togglePin).toHaveBeenCalledWith(TASK_ID);
114114
});
115115

116+
it("archives when reading task pins fails", async () => {
117+
harness.deps.getPinnedTaskIds = vi
118+
.fn()
119+
.mockRejectedValue(new Error("pins unavailable"));
120+
121+
await archiveTask(TASK_ID, harness.deps);
122+
123+
expect(harness.deps.archive).toHaveBeenCalledWith(TASK_ID);
124+
});
125+
126+
it("archives when unpinning fails", async () => {
127+
harness.deps.unpin = vi
128+
.fn()
129+
.mockRejectedValue(new Error("pins unavailable"));
130+
131+
await archiveTask(TASK_ID, harness.deps);
132+
133+
expect(harness.deps.archive).toHaveBeenCalledWith(TASK_ID);
134+
});
135+
116136
it("destroys terminals only after the archive succeeds", async () => {
117137
let clearedWhenArchiveCalled = true;
118138
harness.deps.archive = vi.fn().mockImplementation(async () => {

packages/core/src/archive/archiveOrchestration.ts

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,24 @@ export async function archiveTask(
6767
}
6868

6969
const optimistic = options?.optimistic ?? true;
70-
const pinnedTaskIds = await deps.getPinnedTaskIds();
71-
const wasPinned = pinnedTaskIds.includes(taskId);
70+
let wasPinned = false;
71+
try {
72+
wasPinned = (await deps.getPinnedTaskIds()).includes(taskId);
73+
} catch (error) {
74+
deps.logError("Failed to read task pin state while archiving", error);
75+
}
7276

7377
if (!options?.skipNavigate) {
7478
deps.navigateAwayFromTaskIfActive(taskId);
7579
}
7680

7781
const commandCenterSnapshot = deps.snapshotCommandCenter(taskId);
7882

79-
await deps.unpin(taskId);
83+
try {
84+
await deps.unpin(taskId);
85+
} catch (error) {
86+
deps.logError("Failed to unpin task while archiving", error);
87+
}
8088
deps.removeFromCommandCenter(taskId);
8189

8290
await deps.cache.cancelPathFilter();
@@ -118,7 +126,14 @@ export async function archiveTask(
118126
deps.cache.setArchivedTaskIds((old) => removeArchivedTaskId(old, taskId));
119127
deps.cache.setArchiveList((old) => removeArchivedTask(old, taskId));
120128
if (wasPinned) {
121-
await deps.togglePin(taskId);
129+
try {
130+
await deps.togglePin(taskId);
131+
} catch (pinError) {
132+
deps.logError(
133+
"Failed to restore task pin after archive failure",
134+
pinError,
135+
);
136+
}
122137
}
123138
if (commandCenterSnapshot.index !== -1) {
124139
deps.restoreCommandCenter(taskId, commandCenterSnapshot);

0 commit comments

Comments
 (0)