From 3db819854ff28ebc5e875b8d9d0daa74055bef35 Mon Sep 17 00:00:00 2001 From: Dotta Date: Mon, 30 Nov 2026 18:20:59 -0600 Subject: [PATCH] fix(issues): derive scope for imported issues importIssues inserts creatorless rows with originKind 'manual' without setting scope, so the database default of 'board' previously leaked newly imported tasks into includeAgentCreatedTasks=false queries. Derive scope via deriveDefaultIssueScope in importIssues so creatorless imports land in scope 'agent', matching migration backfill and pre-scope visibility behavior. Tested with issue-scope-visibility, issues-creation-visibility, company-portability-import-batching, migration-snapshot-drift, and issue-filters Vitest suites plus db, shared, and server typechecks. Co-Authored-By: Paperclip --- .../__tests__/issue-scope-visibility.test.ts | 33 +++++++++++++++++++ server/src/services/issues.ts | 5 +++ 2 files changed, 38 insertions(+) diff --git a/server/src/__tests__/issue-scope-visibility.test.ts b/server/src/__tests__/issue-scope-visibility.test.ts index 3340aa71ede..588088134fc 100644 --- a/server/src/__tests__/issue-scope-visibility.test.ts +++ b/server/src/__tests__/issue-scope-visibility.test.ts @@ -493,4 +493,37 @@ describeEmbeddedPostgres("issues.scope visibility and lifecycle", () => { .sort(), ).toEqual([boardTask.id, agentTask.id, touchedAgentTask.id].sort()); }); + + it("derives scope='agent' for creatorless imported tasks so includeAgentCreatedTasks=false excludes them", async () => { + const { companyId } = await seedCompanyWithBoardAccess(ctx.db, "Imported scope"); + const svc = issueService(ctx.db); + const importedId = randomUUID(); + + await svc.importIssues(companyId, [ + { + id: importedId, + ref: "imported-task", + projectId: null, + projectWorkspaceId: null, + title: "Imported historical task", + description: null, + assigneeAgentId: null, + status: "todo", + priority: "medium", + billingCode: null, + assigneeAdapterOverrides: null, + executionWorkspaceSettings: null, + labelIds: [], + monitorNotes: null, + monitorScheduledBy: null, + }, + ]); + + const imported = await svc.getById(importedId); + expect(imported?.scope).toBe("agent"); + expect(await svc.list(companyId, { includeAgentCreatedTasks: false })).toEqual([]); + expect((await svc.list(companyId, { scope: "agent" })).map((row) => row.id)).toEqual([ + importedId, + ]); + }); }); diff --git a/server/src/services/issues.ts b/server/src/services/issues.ts index 304ca0eeb84..0141b3b5374 100644 --- a/server/src/services/issues.ts +++ b/server/src/services/issues.ts @@ -11572,6 +11572,11 @@ export function issueService(db: Db) { responsibleUserId: null, requestDepth: clampIssueRequestDepth(undefined), originKind: "manual", + scope: deriveDefaultIssueScope({ + createdByAgentId: null, + createdByUserId: null, + originKind: "manual", + }), // The caller resolves parentId against ids in this same batch, so a // parent always lands in the same insert (rows arrive parents-first). parentId: row.parentId ?? null,