Skip to content

⭐️⭐️⭐️ 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.

perf(api): bound project activity text for internal agents (#643)

I'm Groot 🌳8160e1b88359
diff --git a/apps/api/src/modules/agents/core/__tests__/integration/route-tools.test.ts b/apps/api/src/modules/agents/core/__tests__/integration/route-tools.test.ts
index 55a8b078..4c5243fa 100644
--- a/apps/api/src/modules/agents/core/__tests__/integration/route-tools.test.ts
+++ b/apps/api/src/modules/agents/core/__tests__/integration/route-tools.test.ts
@@ -82,6 +82,85 @@ describe('internal agent route tools', () => {
expect(tools.update_issue).toBeUndefined();
});
+ it('previews project activity only for the internal agent and retains full history', async () => {
+ const { asOwner } = await setup();
+ const view = await asOwner.projects({ projectKey: 'MKT' }).get();
+ const columnId = view.data!.columns[0]!.id;
+ const created = await asOwner.projects({ projectKey: 'MKT' }).issues.post({
+ columnId,
+ title: 'Large description',
+ });
+ expect(created.status).toBe(201);
+ const issueId = created.data!.id;
+ const description = 'Description detail. '.repeat(200);
+ const updated = await asOwner.issues({ issueId }).patch({ description });
+ expect(updated.status).toBe(200);
+ const tools = await toolsFor(asOwner, []);
+
+ const result = await run(tools, 'get_project_activity', { action: 'description', limit: 1 });
+ expect(result).toMatchObject({
+ items: [
+ {
+ issueId,
+ action: 'description',
+ payload: { to: { value: description.slice(0, 1000) } },
+ truncatedFields: [{ field: 'payload.to.value', originalLength: description.length }],
+ },
+ ],
+ nextCursor: null,
+ });
+
+ const rest = await asOwner.projects({ projectKey: 'MKT' }).analytics.activity.get({
+ query: { action: 'description' },
+ });
+ expect(rest.data?.items[0]?.payload.to?.value).toBe(description);
+ expect(rest.data?.items[0]).not.toHaveProperty('truncatedFields');
+ expect(await run(tools, 'list_issue_activity', { issueId })).toMatchObject({
+ items: expect.arrayContaining([
+ expect.objectContaining({
+ action: 'description',
+ payload: { to: { value: description } },
+ }),
+ ]),
+ });
+ expect(await run(tools, 'get_issue', { issueId })).toMatchObject({ description });
+ });
+
+ it('keeps project activity cursors and rejects a project supplied by the model', async () => {
+ const { asOwner } = await setup();
+ await createProject(asOwner, { key: 'OPS', name: 'Operations' });
+ const view = await asOwner.projects({ projectKey: 'MKT' }).get();
+ const columnId = view.data!.columns[0]!.id;
+ for (const title of ['Alpha', 'Beta']) {
+ await asOwner.projects({ projectKey: 'MKT' }).issues.post({ columnId, title });
+ }
+ const tools = await toolsFor(asOwner, []);
+ const rest = await asOwner.projects({ projectKey: 'MKT' }).analytics.activity.get({
+ query: { limit: 1 },
+ });
+ const first = await run(tools, 'get_project_activity', { limit: 1, projectKey: 'OPS' });
+ expect(first).toMatchObject({ nextCursor: rest.data!.nextCursor });
+ const second = await run(tools, 'get_project_activity', {
+ limit: 1,
+ cursor: JSON.stringify(rest.data!.nextCursor),
+ });
+ expect(second).toMatchObject({
+ items: [expect.objectContaining({ issueTitle: 'Alpha' })],
+ nextCursor: null,
+ });
+ });
+
+ it('preserves project activity errors for an agent without dashboard read permission', async () => {
+ const { asOwner } = await setup();
+ const role = await createRole(asOwner, 'MKT', {
+ name: 'No dashboards',
+ permissions: { dashboards: { read: false } },
+ });
+ expect(role.status).toBe(201);
+ const tools = await toolsFor(asOwner, [], role.data!.id);
+ expect(await run(tools, 'get_project_activity')).toMatchObject({ error: expect.anything() });
+ });
+
it('reaches the real route: a create lands in the project, authored by the agent', async () => {
const { asOwner } = await setup();
const view = await asOwner.projects({ projectKey: 'MKT' }).get();
diff --git a/apps/api/src/modules/agents/core/__tests__/unit/activity-result.test.ts b/apps/api/src/modules/agents/core/__tests__/unit/activity-result.test.ts
new file mode 100644
index 00000000..02f2aba9
--- /dev/null
+++ b/apps/api/src/modules/agents/core/__tests__/unit/activity-result.test.ts
@@ -0,0 +1,94 @@
+import { describe, expect, it } from 'bun:test';
+import type { ActivityItem, ActivityPage } from '#modules/analytics/service';
+import { compactProjectActivity } from '../../runtime/tools/activity-result';
+
+const item: ActivityItem = {
+ id: 7,
+ issueId: 3,
+ issueSequence: 2,
+ issueTitle: 'Prepare launch',
+ kind: 'activity',
+ actorUserId: 'user-1',
+ actorName: 'Owner',
+ body: null,
+ action: 'description',
+ payload: {},
+ createdAt: '2026-10-21T00:00:00.000Z',
+};
+
+describe('internal agent project activity previews', () => {
+ it('bounds large text while preserving event metadata, order and pagination', () => {
+ const long = 'x'.repeat(100_000);
+ const page: ActivityPage = {
+ items: [
+ {
+ ...item,
+ body: long,
+ payload: {
+ subject: { value: long, id: 'field-1' },
+ from: { value: long, id: 11, stateType: 'started' },
+ to: { value: long, repo: 'owner/repo', number: 42, date: '2026-10-21' },
+ },
+ },
+ { ...item, id: 6, action: 'status', payload: { to: { value: 'Done' } } },
+ ],
+ nextCursor: { id: 6, ts: '2026-10-20 23:59:59.123456+00' },
+ };
+ const original = structuredClone(page);
+ const result = compactProjectActivity(page);
+
+ expect(result).toMatchObject({
+ items: [
+ {
+ ...item,
+ body: long.slice(0, 1000),
+ payload: {
+ subject: { ...page.items[0]!.payload.subject, value: long.slice(0, 1000) },
+ from: { ...page.items[0]!.payload.from, value: long.slice(0, 1000) },
+ to: { ...page.items[0]!.payload.to, value: long.slice(0, 1000) },
+ },
+ truncatedFields: [
+ { field: 'body', originalLength: 100_000 },
+ { field: 'payload.subject.value', originalLength: 100_000 },
+ { field: 'payload.from.value', originalLength: 100_000 },
+ { field: 'payload.to.value', originalLength: 100_000 },
+ ],
+ },
+ page.items[1],
+ ],
+ nextCursor: page.nextCursor,
+ });
+ expect(JSON.stringify(result).length).toBeLessThan(JSON.stringify(page).length / 50);
+ expect(page).toEqual(original);
+ });
+
+ it('preserves null, absent, empty and exactly-at-limit values without truncation metadata', () => {
+ const page: ActivityPage = {
+ items: [
+ { ...item, body: '', payload: { from: { value: null }, to: { value: 'x'.repeat(1000) } } },
+ item,
+ ],
+ nextCursor: null,
+ };
+ expect(compactProjectActivity(page)).toEqual(page);
+ });
+
+ it('does not split a surrogate pair at the preview boundary', () => {
+ const value = `${'x'.repeat(999)}😀tail`;
+ const result = compactProjectActivity({
+ items: [{ ...item, payload: { to: { value } } }],
+ nextCursor: null,
+ });
+ expect(result.items[0]).toMatchObject({
+ payload: { to: { value: 'x'.repeat(999) } },
+ truncatedFields: [{ field: 'payload.to.value', originalLength: value.length }],
+ });
+ });
+
+ it('preserves an empty page', () => {
+ expect(compactProjectActivity({ items: [], nextCursor: null })).toEqual({
+ items: [],
+ nextCursor: null,
+ });
+ });
+});
diff --git a/apps/api/src/modules/agents/core/runtime/tools/activity-result.ts b/apps/api/src/modules/agents/core/runtime/tools/activity-result.ts
new file mode 100644
index 00000000..67b1d7e5
--- /dev/null
+++ b/apps/api/src/modules/agents/core/runtime/tools/activity-result.ts
@@ -0,0 +1,27 @@
+import type { ActivityPage } from '#modules/analytics/service';
+
+export function compactProjectActivity(page: ActivityPage) {
+ return {
+ ...page,
+ items: page.items.map((item) => {
+ const truncatedFields: { field: string; originalLength: number }[] = [];
+ const preview = (value: string | null, field: string) => {
+ if (value === null || value.length <= 1000) return value;
+ truncatedFields.push({ field, originalLength: value.length });
+ return value.slice(0, 1000).replace(/[\uD800-\uDBFF]$/, '');
+ };
+
+ const body = preview(item.body, 'body');
+ const payload = { ...item.payload };
+ for (const side of ['subject', 'from', 'to'] as const) {
+ const value = payload[side];
+ if (value) {
+ payload[side] = { ...value, value: preview(value.value, `payload.${side}.value`) };
+ }
+ }
+
+ if (truncatedFields.length === 0) return item;
+ return { ...item, body, payload, truncatedFields };
+ }),
+ };
+}
diff --git a/apps/api/src/modules/agents/core/runtime/tools/catalog.ts b/apps/api/src/modules/agents/core/runtime/tools/catalog.ts
index d79a5b41..9c71729f 100644
--- a/apps/api/src/modules/agents/core/runtime/tools/catalog.ts
+++ b/apps/api/src/modules/agents/core/runtime/tools/catalog.ts
@@ -352,6 +352,10 @@ export const ALWAYS_ON_ACTIONS: ToolMeta[] = [
group: 'project',
label: 'Read project activity',
description: 'Read the comments and changes across all issues of the project, by period.',
+ overrides: {
+ description:
+ 'Read project comments and changes by period, with cursor pagination. Text values are previews of at most 1000 UTF-16 code units; truncatedFields names shortened values and their original lengths. Read list_issue_activity for full historical entries, or get_issue for the current description.',
+ },
always: true,
},
{
diff --git a/apps/api/src/modules/agents/core/runtime/tools/route-tools.ts b/apps/api/src/modules/agents/core/runtime/tools/route-tools.ts
index 793f870f..8b245bc4 100644
--- a/apps/api/src/modules/agents/core/runtime/tools/route-tools.ts
+++ b/apps/api/src/modules/agents/core/runtime/tools/route-tools.ts
@@ -1,10 +1,12 @@
import { createTool } from '@mastra/core/tools';
import type { z } from 'zod';
import type { ProjectRow } from '#modules/projects/service';
+import type { ActivityPage } from '#modules/analytics/service';
import { routeTools, withoutFields, type McpInputSchema, type McpRouteTool } from '#mcp/generate';
import type { Permission } from '#shared/guards';
import { dispatchTool } from '#mcp/dispatch';
import { getMcpApp } from '#mcp/app-ref';
+import { compactProjectActivity } from './activity-result';
import {
AGENT_ACTIONS,
ALWAYS_ON_ACTIONS,
@@ -121,7 +123,11 @@ function buildOne(
const body = parseBody(text);
// A route failure is returned to the model as a result rather than thrown, so
// it can correct the call instead of the run aborting. Custom tools do the same.
- return isError ? { error: body } : body;
+ if (isError) return { error: body };
+ if (route.name === 'get_project_activity') {
+ return compactProjectActivity(body as ActivityPage);
+ }
+ return body;
},
});
}
diff --git a/docs/mcp-results.md b/docs/mcp-results.md
index 3162633e..9297d50b 100644
--- a/docs/mcp-results.md
+++ b/docs/mcp-results.md
@@ -6,6 +6,19 @@ contains the original REST response body, including an empty string for HTTP 204
clients can continue reading that text. The internal agent runtime keeps its existing result
format.
+## Internal agent project activity
+
+The internal agent's `get_project_activity` result preserves the route's event metadata
+and cursor. Comment bodies and `payload.subject/from/to.value` strings longer than
+1000 UTF-16 code units are shortened to a preview. Each affected event includes
+`truncatedFields: [{ field, originalLength }]`, where `field` is the path of a shortened
+value and `originalLength` uses the same units. A preview never ends with half of a
+surrogate pair.
+
+`list_issue_activity` reads the full historical entries when needed. `get_issue` reads
+the current description, which can differ from a historical description. Stored activity,
+REST/UI responses and external MCP results retain the full text.
+
## Attachment urls and images
The body is the REST body with one change: the path of an issue or initiative attachment,