diff --git a/server/src/__tests__/issue-summaries-routes.test.ts b/server/src/__tests__/issue-summaries-routes.test.ts index 5e571f625f4..37577f1a6bc 100644 --- a/server/src/__tests__/issue-summaries-routes.test.ts +++ b/server/src/__tests__/issue-summaries-routes.test.ts @@ -101,6 +101,10 @@ describeEmbeddedPostgres("bounded issue summaries", () => { createdByUserId: title === "someone-else" ? "other-user" : title === "scheduled" ? null : user, responsibleUserId: user, }))).returning(); + // A run links the task it created, as the routine service records it. + for (const row of rows.filter(row => row.originRunId)) { + await ctx.db.update(routineRuns).set({ linkedIssueId: row.id }).where(eq(routineRuns.id, row.originRunId!)); + } const res = await request(app(f.actor)).get(url(f.companyId)).query({ ids: rows.map(row => row.id).join(","), navigation: "true" }).expect(200); const byTitle = new Map(res.body.map((row: { title: string }) => [row.title, row])); // Mine keeps routine work out, including runs the person starts manually. diff --git a/server/src/services/issue-summaries.ts b/server/src/services/issue-summaries.ts index 1e2532ae2fc..405e5ec7862 100644 --- a/server/src/services/issue-summaries.ts +++ b/server/src/services/issue-summaries.ts @@ -127,8 +127,11 @@ export async function listIssueNavigationState( exists ( -- The viewer started the routine run that created this task. This is -- recent personal activity, but not Mine participation. + -- The linked-issue index bounds this lookup; the origin-run check keeps + -- only the run that created the task, not later runs coalesced into it. select 1 from ${issues} join ${routineRuns} - on ${routineRuns.id}::text = ${issues.originRunId} and ${routineRuns.companyId} = ${companyId} + on ${routineRuns.linkedIssueId} = ${issues.id} and ${routineRuns.companyId} = ${companyId} + and ${routineRuns.id}::text = ${issues.originRunId} where ${issues.id} = c.id and ${issues.companyId} = ${companyId} and ${issues.createdByUserId} = ${userId} and ${issues.createdByAgentId} is null and ${routineRuns.source} = 'manual'