mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-16 03:31:44 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The board UI sidebar shows the person's recent tasks on every page, including the Mine inbox > - The sidebar refreshes those rows through `GET /companies/:id/issues/summaries`, which accepted at most five IDs > - `useRecentTasks` sent the chunks one after another, so a 25-task history cost five sequential requests > - On staging each request took 3–6 s, so the recent-task rows settled about 20 s after load and every request competed with the inbox rows > - This pull request raises the per-request cap to 50 and fetches any remaining chunks in parallel > - The benefit is one summaries request for a typical history instead of a serial chain ## Linked Issues or Issue Description **What existing behavior does this improve?** The refresh of the sidebar's recent tasks on page load. **Subsystem affected** Board UI (`ui/src/hooks/useRecentTasks.ts`) and the `/issues/summaries` route bound (`packages/shared`, `server/src/routes/issues.ts`). **Current behavior** A history of N recent tasks sends ceil(N/5) summaries requests in series. Measured on staging on 2026-11-09 for a cold Mine load: five requests of five IDs, started at 1.0 s, 4.3 s, 8.1 s, 12.3 s and 18.4 s, each taking 3.3–6.1 s. **Proposed behavior** Up to 50 recent tasks are one request. Longer histories send their chunks at the same time. **Reason and benefit** The staging server is saturated, so each extra serial round trip delays the sidebar and the inbox rows. One request removes four round trips from a typical load. ## What Changed - `ISSUE_SUMMARIES_MAX_IDS` is now 50 (was 5). The shared validator, the route's 400 message, the service guard and the OpenAPI description use the new bound. - `useRecentTasks` builds all chunks first and fetches them at most three at a time (`RECENT_TASK_SUMMARY_CONCURRENCY`). The recent list has no size cap, so this keeps a long history from becoming a burst. The cache key, omission handling and pruning are unchanged. A failed chunk still fails the batch, so nothing is pruned on a partial failure. - Tests: the route test accepts exactly `MAX` IDs and rejects `MAX + 1`; a hook test checks that at most three chunks are in flight; the API test uses the constant; `useRecentTasks` tests cover a 25-task history in one request and a 103-task history with three chunks in flight together, with and without a failed chunk. - New browser check `tests/perf/collections/recent-task-summaries.spec.ts`: a Mine load with a 12-task history sends summaries requests that each carry all 12 IDs, and the server answers 200 with all 12 tasks. ## Verification - `pnpm verify` (selected Vitest files) passes. - `server`: `npx vitest run src/__tests__/issue-summaries-routes.test.ts src/__tests__/issue-display-status.test.ts` passes (embedded PostgreSQL). - `ui`: `npx vitest run src/hooks/useRecentTasks.test.tsx src/api/issue-summaries.test.ts src/components/task-chat/TaskChatBlockerLinks.test.tsx src/components/CoordinatorSidebar.test.tsx src/components/SidebarRecentTasks.test.tsx` passes. - Browser check against a disposable local instance: `PAPERCLIP_COLLECTION_PERF_BASE_URL=http://127.0.0.1:<port> pnpm exec playwright test --config tests/perf/collections/playwright.config.ts recent-task-summaries.spec.ts`. It passes on this branch. With `master`'s hook and constant it fails: three requests of 5, 5 and 2 IDs. ## Risks - Low risk. The route still validates UUIDs, deduplicates, and applies the same read authorization per row. Blocker attention is computed with set-based queries, so 50 IDs is the same number of queries as 5. - During a rolling deploy, a new UI against an old server would get a 400 for a history above five tasks. The server serves the UI bundle, so both change together on a normal deploy. The sidebar keeps its stored snapshot when the refresh fails. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), Anthropic, via Claude Code with tool use (shell, file edits, browser). 1M-token context window. Extended thinking was off. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
152 lines
6.1 KiB
TypeScript
152 lines
6.1 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import type { ReactNode } from "react";
|
|
import { act } from "react";
|
|
import { createRoot, type Root } from "react-dom/client";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
ISSUE_SUMMARIES_MAX_IDS,
|
|
type IssueBlockerAttention,
|
|
type IssueRelationIssueSummary,
|
|
type IssueSummary,
|
|
} from "@paperclipai/shared";
|
|
import { StatusIcon } from "../StatusIcon";
|
|
import { taskStatusIconProps } from "@/lib/task-status-presentation";
|
|
import { TaskChatPresentationProvider } from "./presentation-mode";
|
|
import { resolveTaskChatLiveWork, TaskChatLiveWorkLinks } from "./TaskChatBlockerLinks";
|
|
|
|
(globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
|
|
|
|
const mockSummaries = vi.hoisted(() => vi.fn());
|
|
|
|
vi.mock("@/api/issues", () => ({
|
|
issuesApi: { summaries: mockSummaries },
|
|
}));
|
|
|
|
vi.mock("@/lib/router", () => ({
|
|
Link: ({ to, children, ...props }: { to: string; children?: ReactNode }) => <a href={to} {...props}>{children}</a>,
|
|
}));
|
|
|
|
vi.mock("@/hooks/useCoordinatorWorkspaceEnabled", () => ({
|
|
useCoordinatorWorkspaceEnabled: () => ({ enabled: false, userId: "user-1" }),
|
|
}));
|
|
|
|
const covered: IssueBlockerAttention = {
|
|
state: "covered",
|
|
reason: "active_dependency",
|
|
unresolvedBlockerCount: 1,
|
|
coveredBlockerCount: 1,
|
|
stalledBlockerCount: 0,
|
|
attentionBlockerCount: 0,
|
|
sampleBlockerIdentifier: null,
|
|
sampleStalledBlockerIdentifier: null,
|
|
};
|
|
|
|
function relation(id: string, identifier: string, status: IssueRelationIssueSummary["status"]): IssueRelationIssueSummary {
|
|
return { id, identifier, title: `Task ${identifier}`, status, priority: "medium", assigneeAgentId: "agent-1", assigneeUserId: null };
|
|
}
|
|
|
|
// The onboarding walk: BRA-1 waits on BRA-2 (running), todo tasks and
|
|
// blocked tasks that are "covered" in the task list. Six steps plus a live
|
|
// terminal blocker; every summaries request stays within the endpoint limit.
|
|
const terminal = relation("bra-9", "BRA-9", "in_progress");
|
|
const blockers = [
|
|
{ ...relation("bra-2", "BRA-2", "in_progress"), terminalBlockers: [terminal] },
|
|
relation("bra-3", "BRA-3", "todo"),
|
|
relation("bra-4", "BRA-4", "todo"),
|
|
relation("bra-5", "BRA-5", "blocked"),
|
|
relation("bra-6", "BRA-6", "todo"),
|
|
relation("bra-7", "BRA-7", "blocked"),
|
|
];
|
|
|
|
const summaries: IssueSummary[] = [...blockers, terminal].map((blocker) => ({
|
|
id: blocker.id,
|
|
companyId: "company-1",
|
|
title: blocker.title,
|
|
identifier: blocker.identifier,
|
|
status: blocker.status,
|
|
updatedAt: new Date("2026-11-06T00:00:00Z"),
|
|
externalConversationState: null,
|
|
...(blocker.status === "blocked" ? { blockerAttention: covered } : {}),
|
|
}));
|
|
|
|
function listGlyph(summary: IssueSummary) {
|
|
return renderToStaticMarkup(<StatusIcon {...taskStatusIconProps(summary)} />);
|
|
}
|
|
|
|
function glyphToken(markup: string): string | null {
|
|
return markup.match(/var\((--status-task-icon-[a-z_]+)\)/)?.[1] ?? null;
|
|
}
|
|
|
|
let container: HTMLDivElement;
|
|
let root: Root;
|
|
|
|
beforeEach(() => {
|
|
mockSummaries.mockReset();
|
|
mockSummaries.mockImplementation(async (_companyId: string, ids: readonly string[]) => {
|
|
if (ids.length > ISSUE_SUMMARIES_MAX_IDS) throw new Error("Too many issue summary IDs");
|
|
return summaries.filter((summary) => ids.includes(summary.id));
|
|
});
|
|
container = document.createElement("div");
|
|
document.body.appendChild(container);
|
|
root = createRoot(container);
|
|
});
|
|
|
|
afterEach(() => {
|
|
act(() => root.unmount());
|
|
container.remove();
|
|
});
|
|
|
|
async function renderStrip(streamlined: boolean) {
|
|
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
|
const liveWork = resolveTaskChatLiveWork(blockers, new Set(["bra-2", "bra-9"]));
|
|
if (!liveWork) throw new Error("expected live work");
|
|
await act(async () => {
|
|
root.render(
|
|
<QueryClientProvider client={queryClient}>
|
|
<TaskChatPresentationProvider mode={streamlined ? "streamlined" : "production"}>
|
|
<TaskChatLiveWorkLinks liveWork={liveWork} placement="bottom" companyId="company-1" />
|
|
</TaskChatPresentationProvider>
|
|
</QueryClientProvider>,
|
|
);
|
|
});
|
|
await vi.waitFor(() => {
|
|
expect(container.innerHTML).not.toContain("var(--status-task-icon-blocked)");
|
|
});
|
|
return container.innerHTML;
|
|
}
|
|
|
|
describe("TaskChatLiveWorkLinks status glyphs (BUG-07)", () => {
|
|
for (const streamlined of [true, false]) {
|
|
it(`draws each waiting task with the task list's glyph and colour token (${streamlined ? "streamlined" : "production"})`, async () => {
|
|
const html = await renderStrip(streamlined);
|
|
const steps = [...container.querySelectorAll('[data-testid="task-chat-live-work-step"]')].map((step) => step.outerHTML);
|
|
expect(steps).toHaveLength(blockers.length);
|
|
|
|
for (const summary of summaries.filter((candidate) => candidate.id !== terminal.id)) {
|
|
const step = steps.find((markup) => markup.includes(`>${summary.identifier}<`));
|
|
expect(step, summary.identifier!).toBeDefined();
|
|
const expected = listGlyph(summary);
|
|
expect(glyphToken(step!), summary.identifier!).toBe(glyphToken(expected));
|
|
const expectedLabel = expected.match(/aria-label="([^"]+)"/)?.[1];
|
|
expect(step!, summary.identifier!).toContain(`aria-label="${expectedLabel}"`);
|
|
}
|
|
|
|
// The live terminal blocker ("Now running") draws the shared glyph too.
|
|
const nowRunning = [...container.querySelectorAll("a")].find((link) => link.textContent?.includes("BRA-9"));
|
|
const nowRunningRow = (streamlined ? nowRunning : nowRunning?.parentElement)?.outerHTML ?? "";
|
|
expect(glyphToken(nowRunningRow)).toBe(glyphToken(listGlyph(summaries.at(-1)!)));
|
|
|
|
// Blocked-but-covered tasks: blue in-queue glyph, never the red blocked one.
|
|
expect(html).toContain("var(--status-task-icon-in_queue)");
|
|
expect(html).not.toContain("var(--status-task-icon-blocked)");
|
|
// Every request stays within the summaries endpoint limit.
|
|
for (const [, ids] of mockSummaries.mock.calls) {
|
|
expect((ids as string[]).length).toBeLessThanOrEqual(ISSUE_SUMMARIES_MAX_IDS);
|
|
}
|
|
});
|
|
}
|
|
});
|