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

Commit 72ea06a

Browse files
Preserve pin state when archive lookup fails
Generated-By: PostHog Code Task-Id: 4829266a-889b-49eb-bacd-4c1426b27b2b
1 parent 3bfdd0e commit 72ea06a

2 files changed

Lines changed: 20 additions & 5 deletions

File tree

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,20 @@ describe("archiveTask", () => {
123123
expect(harness.deps.archive).toHaveBeenCalledWith(TASK_ID);
124124
});
125125

126+
it("preserves pin state when reading task pins and archiving fail", async () => {
127+
harness.deps.getPinnedTaskIds = vi
128+
.fn()
129+
.mockRejectedValue(new Error("pins unavailable"));
130+
harness.deps.archive = vi.fn().mockRejectedValue(new Error("boom"));
131+
132+
await expect(archiveTask(TASK_ID, harness.deps)).rejects.toThrow("boom");
133+
134+
expect(harness.deps.unpin).not.toHaveBeenCalled();
135+
expect(harness.deps.togglePin).not.toHaveBeenCalled();
136+
});
137+
126138
it("archives when unpinning fails", async () => {
139+
harness.deps.getPinnedTaskIds = vi.fn().mockResolvedValue([TASK_ID]);
127140
harness.deps.unpin = vi
128141
.fn()
129142
.mockRejectedValue(new Error("pins unavailable"));

packages/core/src/archive/archiveOrchestration.ts

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

6969
const optimistic = options?.optimistic ?? true;
70-
let wasPinned = false;
70+
let wasPinned: boolean | undefined;
7171
try {
7272
wasPinned = (await deps.getPinnedTaskIds()).includes(taskId);
7373
} catch (error) {
@@ -80,10 +80,12 @@ export async function archiveTask(
8080

8181
const commandCenterSnapshot = deps.snapshotCommandCenter(taskId);
8282

83-
try {
84-
await deps.unpin(taskId);
85-
} catch (error) {
86-
deps.logError("Failed to unpin task while archiving", error);
83+
if (wasPinned) {
84+
try {
85+
await deps.unpin(taskId);
86+
} catch (error) {
87+
deps.logError("Failed to unpin task while archiving", error);
88+
}
8789
}
8890
deps.removeFromCommandCenter(taskId);
8991

0 commit comments

Comments
 (0)