mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-11-22 11:54:35 +01:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - The browser UI loads plugin UI modules. The host fetches each module, rewrites its imports, and imports it from a random `blob:` URL > - Browser errors go to Sentry. A stack frame from a plugin module names only that random blob URL > - So a Sentry report cannot tell which plugin raised an error. For example, a plugin can abort its own request during an unmount, and the report shows only `blob:https://<host>/<uuid>` > - This pull request records each blob URL with its plugin key, and tags the Sentry event with that plugin key > - The benefit is that a plugin error can go to the correct plugin owner, and the blob URL is never sent ## Linked Issues or Issue Description Refs #22380, which marks the announcement card's own aborts as intentional. Some events in the same Sentry group come from a plugin module instead, and #22380 cannot cover them. **What happened?** Hosted browsers report `AbortError: signal is aborted without reason` as an unhandled rejection. The innermost frame is a React effect cleanup in a `blob:` module at line 5590. Only plugin UI modules run from `blob:` URLs in the main thread. The event has no data that names the plugin. **Expected behavior** A Sentry event from a plugin module names the plugin, so the plugin owner can fix the plugin. **Steps to reproduce** 1. Install a plugin with a UI slot whose effect cleanup calls `controller.abort()` on a pending `fetch` and does not catch the rejection. 2. Open a page with that slot. Then go to a page without it. 3. Sentry records an unhandled `AbortError` whose frame is a `blob:` URL and no plugin key. ## What Changed - `ui/src/lib/plugin-module-origins.ts`: a new, bounded registry (100 recent modules). `rememberPluginModuleUrl` records a blob URL with its plugin key. `readPluginModuleOrigin` finds the innermost `blob:` frame of an event and returns its plugin key, `unmapped`, or nothing. It never throws. - `ui/src/plugins/slots.tsx`: `importPluginModule` records the blob URL with the plugin key before the import. - `ui/src/lib/sentry.ts`: `beforeSend` sets the `browser_plugin_module` tag when an event has a `blob:` frame. The tag holds the plugin key (at most 200 characters) or `unmapped`. It never holds the URL. - Tests for the registry, the loader, and the Sentry hook. ## Verification - `cd ui && npx vitest run src/lib/plugin-module-origins.test.ts src/lib/sentry.test.ts src/plugins/slots-loading.test.tsx src/plugins/slots.test.ts src/hooks/useAnnouncement.test.tsx`: 69/69 pass. - Red first: with the source changes removed and the new tests kept, the Sentry test and the loader test fail (`expected 'unmapped' to be 'fixture.navigation'`). - `cd ui && npx vitest run src/lib src/plugins`: 279 files, 3231 tests pass. - `npx tsc --noEmit -p ui/tsconfig.json`: no errors in the changed files. ## Risks - Low risk. The change adds one tag. It does not drop, group, or change any event. - The tag holds a plugin key, which is a manifest identifier. It holds no URL, path, or user data. - The registry keeps at most 100 entries, so memory stays bounded when modules reload. ## Model Used - Claude Opus 5.5 (`claude-opus-5-5`), with tool use and code execution, in Claude Code. ## 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 - [ ] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: paperclipbugbot <356415228+paperclipbugbot@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
88 lines
4.3 KiB
TypeScript
88 lines
4.3 KiB
TypeScript
// @vitest-environment jsdom
|
|
import { act } from "react";
|
|
import { createRoot, type Root } from "react-dom/client";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
import { afterEach, beforeEach, expect, it, vi } from "vitest";
|
|
import type { PluginUiContribution } from "@/api/plugins";
|
|
import { queryKeys } from "@/lib/queryKeys";
|
|
import { _resetPluginModuleLoader, ensurePluginContributionLoaded, usePluginSlots } from "./slots";
|
|
|
|
const contribution: PluginUiContribution = {
|
|
pluginId: "navigation", pluginKey: "fixture.navigation", displayName: "Navigation", version: "1",
|
|
uiEntryFile: "index.js", launchers: [],
|
|
slots: [{ type: "organizationSwitcher", id: "navigation", displayName: "Organizations", exportName: "Switcher" }],
|
|
};
|
|
let root: Root;
|
|
let container: HTMLDivElement;
|
|
let client: QueryClient;
|
|
function Consumer() {
|
|
const { isLoading } = usePluginSlots({ slotTypes: ["organizationSwitcher"] });
|
|
return <span>{isLoading ? "Loading" : "Ready"}</span>;
|
|
}
|
|
async function render() {
|
|
await act(async () => root.render(<QueryClientProvider client={client}><Consumer /></QueryClientProvider>));
|
|
}
|
|
beforeEach(() => {
|
|
Object.assign(globalThis, { IS_REACT_ACT_ENVIRONMENT: true });
|
|
vi.stubGlobal("__paperclipPluginBridge__", {});
|
|
client = new QueryClient({ defaultOptions: { queries: { retry: false, staleTime: Infinity } } });
|
|
container = document.createElement("div"); document.body.append(container); root = createRoot(container);
|
|
});
|
|
afterEach(async () => {
|
|
await act(async () => root.unmount()); container.remove(); client.clear(); _resetPluginModuleLoader();
|
|
vi.unstubAllGlobals(); vi.restoreAllMocks();
|
|
});
|
|
it("does not wait for or load modules for unrelated slots", async () => {
|
|
const fetch = vi.fn(); vi.stubGlobal("fetch", fetch);
|
|
client.setQueryData(queryKeys.plugins.uiContributions, [{ ...contribution,
|
|
slots: [{ type: "page", id: "other", displayName: "Other", exportName: "Page", routePath: "other" }],
|
|
}]);
|
|
await render();
|
|
expect(container.textContent).toBe("Ready");
|
|
expect(fetch).not.toHaveBeenCalled();
|
|
});
|
|
it("settles when a module import started by another consumer fails", async () => {
|
|
let reject!: (error: Error) => void;
|
|
const fetch = vi.fn(() => new Promise<Response>((_resolve, rejectPromise) => { reject = rejectPromise; }));
|
|
vi.stubGlobal("fetch", fetch); vi.spyOn(console, "error").mockImplementation(() => {});
|
|
client.setQueryData(queryKeys.plugins.uiContributions, [contribution]);
|
|
const loading = ensurePluginContributionLoaded(contribution);
|
|
await render();
|
|
expect(container.textContent).toBe("Loading");
|
|
await act(async () => { reject(new Error("unavailable")); await loading; });
|
|
expect(container.textContent).toBe("Ready");
|
|
expect(fetch).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it("does not load agent tabs that have not opted into task side panels", async () => {
|
|
const fetch = vi.fn(); vi.stubGlobal("fetch", fetch);
|
|
client.setQueryData(queryKeys.plugins.uiContributions, [{ ...contribution,
|
|
slots: [{ type: "detailTab", entityTypes: ["agent"], id: "details", displayName: "Details", exportName: "Details" }],
|
|
}]);
|
|
function TaskConsumer() {
|
|
const { slots } = usePluginSlots({ slotTypes: ["detailTab"], entityType: "agent", taskSidePanel: true });
|
|
return <span>{slots.length}</span>;
|
|
}
|
|
await act(async () => root.render(<QueryClientProvider client={client}><TaskConsumer /></QueryClientProvider>));
|
|
expect(container.textContent).toBe("0");
|
|
expect(fetch).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("records each plugin module's blob URL with its plugin key for error attribution", async () => {
|
|
const { readPluginModuleOrigin, __resetPluginModuleOrigins } = await import("@/lib/plugin-module-origins");
|
|
__resetPluginModuleOrigins();
|
|
vi.stubGlobal("fetch", vi.fn(async () => new Response("export const Switcher = () => null;")));
|
|
vi.spyOn(URL, "createObjectURL").mockReturnValue("blob:http://localhost/plugin-module");
|
|
vi.spyOn(URL, "revokeObjectURL").mockImplementation(() => {});
|
|
vi.spyOn(console, "error").mockImplementation(() => {});
|
|
try {
|
|
// jsdom cannot import the blob URL; the loader logs that failure and settles.
|
|
await ensurePluginContributionLoaded(contribution);
|
|
expect(readPluginModuleOrigin([
|
|
{ stacktrace: { frames: [{ filename: "blob:http://localhost/plugin-module" }] } },
|
|
])).toBe("fixture.navigation");
|
|
} finally {
|
|
__resetPluginModuleOrigins();
|
|
}
|
|
});
|