⭐️⭐️⭐️ Open-source, self-hosted alternative to Linear and Plane. Project management and issue tracking where teams and AI agents work side by side to plan and ship products.
TypeScript agenticagileai-agentsbug-reportingbug-trackerganttissue-trackerjirajira-alternativekanbanlinearlinear-alternativeopen-sourceproduct-managementproject-managementroadmapself-hostedsprint-planningteam-collaborationtrello-alternative
fix(api): bound issue texts and make the mention scan linear (#353)
Egor Vasilyev03ee5a88b52a
diff --git a/apps/api/src/modules/issues/__tests__/integration/activity.test.ts b/apps/api/src/modules/issues/__tests__/integration/activity.test.tsindex 398e6bbd..8d89b2cb 100644--- a/apps/api/src/modules/issues/__tests__/integration/activity.test.ts+++ b/apps/api/src/modules/issues/__tests__/integration/activity.test.ts@@ -77,6 +77,14 @@ describe('issue activity', () => {expect(res.status).toBe(400);});+ it('accepts a comment body of 50000 characters and rejects a longer one', async () => {+ const { asOwner, columnId } = await setupProject();+ const issue = (await createIssue(asOwner, columnId)).data!;+ const comments = asOwner.issues({ issueId: issue.id }).comments;+ expect((await comments.post({ body: 'x'.repeat(50_000) })).status).toBe(201);+ expect((await comments.post({ body: 'x'.repeat(50_001) })).status).toBe(400);+ });+it('returns 404 when commenting on a missing issue', async () => {const { asOwner } = await setupProject();const res = await asOwner.issues({ issueId: 999999 }).comments.post({ body: 'x' });@@ -601,6 +609,16 @@ describe('issue activity', () => {expect(page.data?.items.find((i) => i.id === comment.id)?.body).toBe('final');});+ it('bounds an edited comment the way a new one is bounded', async () => {+ const { asOwner, columnId } = await setupProject();+ const issue = (await createIssue(asOwner, columnId)).data!;+ const comment = (await asOwner.issues({ issueId: issue.id }).comments.post({ body: 'draft' }))+ .data!;+ const edit = asOwner.comments({ commentId: comment.id });+ expect((await edit.patch({ body: 'x'.repeat(50_000) })).status).toBe(200);+ expect((await edit.patch({ body: 'x'.repeat(50_001) })).status).toBe(400);+ });+it('logs the edit and the delete in the feed', async () => {const { asOwner, owner, columnId } = await setupProject();const issue = (await createIssue(asOwner, columnId)).data!;diff --git a/apps/api/src/modules/issues/__tests__/integration/issues.test.ts b/apps/api/src/modules/issues/__tests__/integration/issues.test.tsindex 3465c6b6..75718c21 100644--- a/apps/api/src/modules/issues/__tests__/integration/issues.test.ts+++ b/apps/api/src/modules/issues/__tests__/integration/issues.test.ts@@ -123,6 +123,14 @@ describe('issues', () => {expect(new Date(created.data!.dueDate!).getTime()).toBe(new Date('2026-02-01').getTime());});+ it('accepts a description of 50000 characters and rejects a longer one', async () => {+ const { asOwner, columnId } = await setupProject();+ const fits = await createIssue(asOwner, columnId, { description: 'x'.repeat(50_000) });+ expect(fits.status).toBe(201);+ const over = await createIssue(asOwner, columnId, { description: 'x'.repeat(50_001) });+ expect(over.status).toBe(400);+ });+it('hands out an increasing per-project sequence number', async () => {const { asOwner, columnId } = await setupProject();const first = (await createIssue(asOwner, columnId)).data!;@@ -348,6 +356,14 @@ describe('issues', () => {expect(read.data?.title).toBe('Renamed');});+ it('bounds the description the way a new issue is bounded', async () => {+ const { asOwner, columnId } = await setupProject();+ const issue = (await createIssue(asOwner, columnId)).data!;+ const edit = asOwner.issues({ issueId: issue.id });+ expect((await edit.patch({ description: 'x'.repeat(50_000) })).status).toBe(200);+ expect((await edit.patch({ description: 'x'.repeat(50_001) })).status).toBe(400);+ });+it('moves the issue to another column', async () => {const { asOwner, columnId, columnIds } = await setupProject();const target = columnIds[1];@@ -637,6 +653,19 @@ describe('issues', () => {expect((await fieldValue(asOwner, issue.id, field.id))?.value).toBe('hello');});+ it('accepts a text value of 50000 characters and rejects a longer one', async () => {+ const { asOwner, columnId } = await setupProject();+ const field = (+ await asOwner+ .projects({ projectKey: 'MKT' })+ ['custom-fields'].post({ name: 'Steps', fieldType: 'markdown' })+ ).data!;+ const issue = (await createIssue(asOwner, columnId)).data!;+ const value = asOwner.issues({ issueId: issue.id }).fields({ fieldId: field.id });+ expect((await value.put({ value: 'x'.repeat(50_000) })).status).toBe(200);+ expect((await value.put({ value: 'x'.repeat(50_001) })).status).toBe(400);+ });+// A member field holds a user id. Which users it offers is its scope: everyone// the project has, the people only, or the agents only.async function memberField(diff --git a/apps/api/src/modules/issues/model.ts b/apps/api/src/modules/issues/model.tsindex 0488b779..e118aac9 100644--- a/apps/api/src/modules/issues/model.ts+++ b/apps/api/src/modules/issues/model.ts@@ -3,6 +3,10 @@ import { ActivityPayloadResponse } from '#shared/activity';import { DevelopmentLinkResponse } from '#modules/git/model';import { isoDate } from '#shared/schemas';+// Ceiling of every markdown text written on an issue: the description, a comment+// and a custom field value. Each of them is scanned for mentions.+export const ISSUE_TEXT_LIMIT = 50_000;+// t.Numeric validates a numeric path param and coerces the string to a number. A// non-numeric id gets a 400 before it reaches the service.export const issueParams = t.Object({ issueId: t.Numeric() });@@ -441,7 +445,12 @@ export const createIssueBody = t.Object({),),title: t.String({ minLength: 1, description: 'Issue title.' }),- description: t.Optional(t.String({ description: 'Issue description (plain text or markdown).' })),+ description: t.Optional(+ t.String({+ maxLength: ISSUE_TEXT_LIMIT,+ description: 'Issue description (plain text or markdown).',+ }),+ ),priority: t.Optional(t.Nullable(t.String({ description: 'One of: urgent, high, medium, low. Or null.' })),),@@ -558,7 +567,9 @@ export const updateIssueBody = t.Object({t.Nullable(t.String({ description: 'New delegate user id (an AI agent), or null.' })),),title: t.Optional(t.String({ minLength: 1, description: 'New title.' })),- description: t.Optional(t.String({ description: 'New description.' })),+ description: t.Optional(+ t.String({ maxLength: ISSUE_TEXT_LIMIT, description: 'New description.' }),+ ),priority: t.Optional(t.Nullable(t.String({ description: 'One of: urgent, high, medium, low. Or null.' })),),@@ -577,7 +588,9 @@ export const subtaskDispositionQuery = t.Object({});export const setIssueFieldValueBody = t.Object({- value: t.Optional(t.Nullable(t.Union([t.String(), t.Number(), t.Boolean()]))),+ value: t.Optional(+ t.Nullable(t.Union([t.String({ maxLength: ISSUE_TEXT_LIMIT }), t.Number(), t.Boolean()])),+ ),valueEnd: t.Optional(t.Nullable(t.String())),optionIds: t.Optional(t.Array(t.Integer())),});@@ -609,13 +622,19 @@ export const feedRangeQuery = t.Object({),});+const commentText = t.String({+ minLength: 1,+ maxLength: ISSUE_TEXT_LIMIT,+ description: 'Comment text.',+});+export const createCommentBody = t.Object({- body: t.String({ minLength: 1, description: 'Comment text.' }),+ body: commentText,replyToId: t.Optional(t.Number({ description: 'Reply to this comment of the same issue.' })),});export const updateCommentBody = t.Object({- body: t.String({ minLength: 1, description: 'Comment text.' }),+ body: commentText,});export const commentParams = t.Object({diff --git a/apps/api/src/shared/__tests__/unit/mentions.test.ts b/apps/api/src/shared/__tests__/unit/mentions.test.tsindex 422ee273..cd3582c9 100644--- a/apps/api/src/shared/__tests__/unit/mentions.test.ts+++ b/apps/api/src/shared/__tests__/unit/mentions.test.ts@@ -43,6 +43,30 @@ describe('parseMentionHandles', () => {expect(parseMentionHandles('see [the thread](https://x.com/@ada)')).toEqual([]);expect(parseMentionHandles('https://x.com/@ada is theirs')).toEqual([]);});++ it('reads a mention next to markup that never closes', () => {+ expect(parseMentionHandles('[[[ @ada <<< @bob ![ @carol `')).toEqual(['ada', 'bob', 'carol']);+ expect(parseMentionHandles('[a]( [b]( @ada')).toEqual(['ada']);+ expect(parseMentionHandles('[@ada](https://x.com/a_(b)) and [@bob')).toEqual(['bob']);+ });++ // The markup scan must stay linear: an unclosed opener repeated for the whole text+ // is the case where a scan that restarts at every opener goes quadratic.+ it('scans a text of unclosed markup openers in linear time', () => {+ const openers = ['['.repeat(100_000), '<'.repeat(100_000), '[a]('.repeat(25_000)];+ for (const text of openers) {+ const started = performance.now();+ expect(parseMentionHandles(`${text.slice(0, 99_990)} cc @ada`)).toEqual(['ada']);+ expect(performance.now() - started).toBeLessThan(50);+ }+ });++ it('reads nothing from a text longer than any the api accepts', () => {+ const started = performance.now();+ expect(parseMentionHandles('['.repeat(200_000))).toEqual([]);+ expect(parseMentionHandles(`${'x'.repeat(100_000)} @ada`)).toEqual([]);+ expect(performance.now() - started).toBeLessThan(50);+ });});describe('addedMentionHandles', () => {diff --git a/apps/api/src/shared/mentions.ts b/apps/api/src/shared/mentions.tsindex b65261ed..de0ca3a7 100644--- a/apps/api/src/shared/mentions.ts+++ b/apps/api/src/shared/mentions.ts@@ -14,12 +14,19 @@ const MENTION_RE = /(?<![\[email protected]])@([a-zA-Z0-9_](?:[a-zA-Z0-9._-]*[a-zA-Z0-9_])?)/// Markup an @ belongs to rather than addressing anyone: a fenced block, an inline// span of code, a link or an image, and a bare URL. The editor skips the same// markup when it renders the chips, so what reads as a mention is what notifies.+// A span that fails to close stops at the next character that could open the same+// span ([ inside a link, < inside an autolink), so a text of unclosed openers is+// scanned once rather than once per opener.const NOT_A_MENTION_RE =- /```[\s\S]*?```|~~~[\s\S]*?~~~|`[^`]*`|!?\[[^\]]*\]\([^)]*\)|<[^>\s]+>|\bhttps?:\/\/\S+/g;+ /```[\s\S]*?```|~~~[\s\S]*?~~~|`[^`]*`|!?\[[^[\]]*\]\([^)[]*\)|<[^<>\s]+>|\bhttps?:\/\/\S+/g;++// Longer than any text the API accepts; a text past it is not scanned at all.+const MAX_MENTION_TEXT_LENGTH = 100_000;// The distinct handles mentioned in the text, lowercased, in first-seen order.// Usernames are issued case-insensitively, so the comparison is too.export function parseMentionHandles(text: string): string[] {+ if (text.length > MAX_MENTION_TEXT_LENGTH) return [];const handles = new Set<string>();for (const match of text.replace(NOT_A_MENTION_RE, ' ').matchAll(MENTION_RE))handles.add(match[1].toLowerCase());