The open-source app everyone uses to manage agents at work
TypeScript acpxagent-orchestrationagent-skillsagentic-aiai-agentsai-engineeringai-governanceai-toolsautonomous-agentsclaudeclaude-codeclaude-skillscodexhermesllmmcpmulti-agentopenclawproject-managementworkflow-automation
fix(server): prevent identifier collision in issue creation
Matt Van Horn21a1e97a81d5
diff --git a/server/src/services/issues.ts b/server/src/services/issues.tsindex 832c4e1761..e279ed38af 100644--- a/server/src/services/issues.ts+++ b/server/src/services/issues.ts@@ -1183,9 +1183,19 @@ export function issueService(db: Db) {if (executionWorkspaceId) {await assertValidExecutionWorkspace(companyId, issueData.projectId, executionWorkspaceId, tx);}+ // Self-correcting counter: use MAX(issue_number) + 1 if the counter+ // has drifted below the actual max, preventing identifier collisions.+ const [maxRow] = await tx+ .select({ maxNum: sql<number>`coalesce(max(${issues.issueNumber}), 0)` })+ .from(issues)+ .where(eq(issues.companyId, companyId));+ const currentMax = maxRow?.maxNum ?? 0;+const [company] = await tx.update(companies)- .set({ issueCounter: sql`${companies.issueCounter} + 1` })+ .set({+ issueCounter: sql`greatest(${companies.issueCounter}, ${currentMax}) + 1`,+ }).where(eq(companies.id, companyId)).returning({ issueCounter: companies.issueCounter, issuePrefix: companies.issuePrefix });