From bb453ab6e9124c8423fa7a478d2d677e52e29a32 Mon Sep 17 00:00:00 2001 From: Brad Groux Date: Sat, 31 Jan 2026 00:34:57 -0600 Subject: [PATCH] fix: allow explicit IDs when creating managed list items ManagedListService.create() now accepts an optional 'id' field. If provided, it uses the explicit ID instead of generating slug-nanoid. Also adds duplicate ID check to prevent conflicts. This fixes the corrupted task-type IDs (e.g., 'bug-GdN5rT' instead of 'bug') that were caused by always appending random suffixes. --- server/src/services/managed-list-service.ts | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/server/src/services/managed-list-service.ts b/server/src/services/managed-list-service.ts index a8ae6ddf..0aa84c94 100644 --- a/server/src/services/managed-list-service.ts +++ b/server/src/services/managed-list-service.ts @@ -100,14 +100,19 @@ export class ManagedListService { /** * Create a new item */ - async create(input: Omit): Promise { + async create(input: Omit & { id?: string }): Promise { await this.init(); const now = new Date().toISOString(); - // T extends ManagedListItem which has 'label'; Omit preserves it - const slug = this.slugify((input as Pick).label); - const shortId = nanoid(6); - const id = `${slug}-${shortId}`; + // Use provided id if given (clean, deterministic), otherwise generate one + const id = + (input as { id?: string }).id || + `${this.slugify((input as Pick).label)}-${nanoid(6)}`; + + // Reject duplicate IDs + if (this.items.some((item) => item.id === id)) { + throw new Error(`Item with id '${id}' already exists`); + } // Calculate order as max + 1 const maxOrder = this.items.length > 0 ? Math.max(...this.items.map((item) => item.order)) : -1;