From 2e99edf8250a2fca26882ee367d57d454010cee6 Mon Sep 17 00:00:00 2001 From: Ethereal49 Date: Sat, 5 Dec 2026 15:45:21 +0800 Subject: [PATCH] fix(adapter-utils): allow summary slot callbacks from sandboxes (#16535) ## Thinking Path > - Paperclip manages work for companies of AI agents. > - Remote agents use the sandbox callback bridge to reach the controller. > - The built-in Summarizer reads and writes summary slots through that bridge. > - The server and bundled skill already provide these routes. > - The default bridge allowlist rejects all three documented requests. > - This change admits the exact methods and paths, so remote summaries can reach the existing server checks. ## Linked Issues or Issue Description - Fixes: [#16481](https://github.com/paperclipai/paperclip/issues/16481). - Related: [#16534](https://github.com/paperclipai/paperclip/pull/16534) adds a labels read route in the same allowlist. [#14533](https://github.com/paperclipai/paperclip/pull/14533) changes SSH attachment queue reads. Neither adds summary-slot routes. - Related: [#11682](https://github.com/paperclipai/paperclip/pull/11682) adds routine refresh behavior on the server. This change does not include that work. ## What Changed - Add only GET slot, GET slot revisions, and PUT slot to the shared default allowlist. Each pattern matches the full path. - Test all three requests through the file queue. Check that the method, path, query, and JSON body reach the handler. Check that a controller 403 response stays a 403 response. - Add allowlist checks for both transports and rejection checks for wrong methods, missing or extra path segments, similar resource names, and the board-only generate action. ## Verification - On base `185483e0909246b4609980a0e6e7ad3b8dbad1ba`, the new regressions fail: all three queue requests return 403 instead of 200. The allowlist assertion also fails (4 failed). - PASS: `pnpm exec vitest run packages/adapter-utils/src/sandbox-callback-bridge.test.ts packages/adapter-utils/src/http2-bridge-server.test.ts packages/adapter-utils/src/sandbox-callback-bridge-body.test.ts packages/adapter-utils/src/execution-target.test.ts` (162 passed). - PASS: `PAPERCLIP_ENABLE_DARWIN_SSH_ENV_LAB=1 pnpm exec vitest run packages/adapter-utils/src/ssh-fixture.test.ts` (25 passed, no skips). - PASS: `pnpm exec vitest run server/src/__tests__/summary-slot-routes.test.ts server/src/__tests__/summary-slots.test.ts` (31 passed, no skips). These tests use the existing routes and an isolated PostgreSQL database. They cover company access, board write denial, non-Summarizer denial, and generation task/run checks. - PASS: `pnpm --filter @paperclipai/adapter-utils typecheck`, `pnpm --filter @paperclipai/adapter-utils build`, and `git diff --check`. - Local environment: macOS ARM64, Node 26.11.1, pnpm 9.15.4. The first server test attempt could not load the plugin SDK. Building the existing shared/plugin SDK packages resolved that setup failure. One new mock-call assertion also needed correction because the handler receives a second context argument; the tests then passed. - BLOCKED: `pnpm -r typecheck` stops at missing Node types in an uninstalled workspace. `pnpm test:run` and `pnpm build` stop in preflight because the CLI workspace's `tsx` is not installed. Their full test/build bodies did not run. Only the server dependency closure was installed in this isolated worktree. Disk space was limited and Rust/cargo was unavailable. - NOT_RUN: a model-driven SSH Summarizer run against a real Paperclip instance, full repository gates, PR CI, and Greptile. The queue handler's test 403 proves response forwarding; it does not prove controller authorization. The server tests provide separate authorization evidence. ## Risks - The bridge now admits three existing summary-slot operations. Server company access, the summaries feature flag, and the Summarizer task/run write checks remain in force. - No schema or request contract changes. POST generate and unrelated routes stay denied. A real SSH Summarizer run and full CI remain acceptance limits. ## Model Used - OpenAI Codex, `gpt-6.1-sol`, `xhigh` reasoning, for implementation and validation. Read-only assistants used OpenAI `gpt-6-luna` with `max` reasoning for upstream checks, source inspection, and independent review. A browser assistant used OpenAI `gpt-6.1-sol` with `medium` reasoning to prepare the review page. Tools included shell execution, Git/GitHub APIs, Vitest, TypeScript, and browser interaction. The context window size is not exposed by this session. ## 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 linked existing issues or described the issue in-PR - [x] I have not referenced internal/instance-local Paperclip issues or links - [x] My branch name describes the change and contains no internal Paperclip ticket id - [x] I have run the listed targeted tests locally and they pass - [x] I have added or updated tests where applicable - [x] I have checked the existing API/skill documentation; no request contract changed - [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 --- .../src/sandbox-callback-bridge.test.ts | 54 +++++++++++++++++++ .../src/sandbox-callback-bridge.ts | 3 ++ 2 files changed, 57 insertions(+) diff --git a/packages/adapter-utils/src/sandbox-callback-bridge.test.ts b/packages/adapter-utils/src/sandbox-callback-bridge.test.ts index bf59f88667b..9a5e060f4e4 100644 --- a/packages/adapter-utils/src/sandbox-callback-bridge.test.ts +++ b/packages/adapter-utils/src/sandbox-callback-bridge.test.ts @@ -500,6 +500,43 @@ describe("sandbox callback bridge", () => { expect(forwarded).toEqual(["GET /api/openapi.json"]); }); + it.each([ + { method: "GET", suffix: "", query: "?scopeId=project-1", body: "" }, + { method: "GET", suffix: "/revisions", query: "?scopeId=project-1", body: "" }, + { method: "PUT", suffix: "", query: "", body: JSON.stringify({ markdown: "# Summary", scopeId: "project-1" }) }, + ])("relays summary slot $method $suffix and preserves controller denials", async ({ method, suffix, query, body }) => { + const rootDir = await mkdtemp(path.join(os.tmpdir(), "paperclip-bridge-summary-")); + cleanupDirs.push(rootDir); + const queueDir = path.join(rootDir, "queue"); + const directories = sandboxCallbackBridgeDirectories(queueDir); + const handleRequest = vi.fn() + .mockResolvedValueOnce({ status: 200, body: JSON.stringify({ ok: true }) }) + .mockResolvedValueOnce({ status: 403, body: JSON.stringify({ error: "Actor denied" }) }); + const worker = await startSandboxCallbackBridgeWorker({ + client: createFileSystemSandboxCallbackBridgeQueueClient(), queueDir, handleRequest, + }); + cleanupFns.push(() => worker.stop()); + const request = { + method, path: `/api/companies/co-1/summary-slots/project/header${suffix}`, + query, headers: { "content-type": "application/json" }, body, + }; + for (const [index, status] of [200, 403].entries()) { + const id = `summary-${index}`; + await publishBridgeRequest(path.join(directories.requestsDir, `${id}.json`), JSON.stringify({ + id, ...request, createdAt: new Date().toISOString(), + })); + await vi.waitFor(async () => { + expect(await createFileSystemSandboxCallbackBridgeQueueClient().listJsonFiles(directories.responsesDir)) + .toContain(`${id}.json`); + }, { timeout: 5_000 }); + const response = JSON.parse(await readFile(path.join(directories.responsesDir, `${id}.json`), "utf8")); + expect(response.status, response.body).toBe(status); + expect(JSON.parse(response.body)).toEqual(index === 0 ? { ok: true } : { error: "Actor denied" }); + expect(handleRequest.mock.calls[index][0]).toMatchObject(request); + expect(handleRequest).toHaveBeenCalledTimes(index + 1); + } + }); + it("denies non-allowlisted requests by default", async () => { const rootDir = await mkdtemp(path.join(os.tmpdir(), "paperclip-bridge-default-policy-")); cleanupDirs.push(rootDir); @@ -1596,6 +1633,9 @@ describe("sandbox callback bridge", () => { { method: "GET", path: "/api/companies/co-1/approvals" }, { method: "GET", path: "/api/companies/co-1/routines" }, { method: "GET", path: "/api/companies/co-1/skills" }, + { method: "GET", path: "/api/companies/co-1/summary-slots/workspaces_overview/header" }, + { method: "GET", path: "/api/companies/co-1/summary-slots/project/header/revisions" }, + { method: "PUT", path: "/api/companies/co-1/summary-slots/execution_workspace/header" }, { method: "GET", path: "/api/agents/me/mcp-skills/skill-1/files" }, { method: "GET", path: "/api/companies/co-1/email/inboxes" }, { method: "GET", path: "/api/companies/co-1/email/tasks/issue-1" }, @@ -1659,6 +1699,17 @@ describe("sandbox callback bridge", () => { } const denied: Array<{ method: string; path: string }> = [ + { method: "POST", path: "/api/companies/co-1/summary-slots/project/header" }, + { method: "PATCH", path: "/api/companies/co-1/summary-slots/project/header" }, + { method: "DELETE", path: "/api/companies/co-1/summary-slots/project/header" }, + { method: "PUT", path: "/api/companies/co-1/summary-slots/project/header/revisions" }, + { method: "POST", path: "/api/companies/co-1/summary-slots/project/header/generate" }, + { method: "GET", path: "/api/companies/co-1/summary-slots" }, + { method: "GET", path: "/api/companies/co-1/summary-slots/project" }, + { method: "GET", path: "/api/companies/co-1/summary-slots/project/header/extra" }, + { method: "GET", path: "/api/companies/co-1/summary-slots/project/header/revisions/extra" }, + { method: "GET", path: "/api/companies/co-1/summary-slots/project/header/" }, + { method: "GET", path: "/api/companies/co-1/summary-slots-extra/project/header" }, { method: "POST", path: "/api/issues/issue-1/activity" }, { method: "GET", path: "/api/issues/issue-1/activity/extra" }, { method: "GET", path: "/api/companies/co-1/activity" }, @@ -1707,6 +1758,9 @@ describe("sandbox callback bridge", () => { // Both transports admit the full attachment workflow. const http2Allowed: Array<{ method: string; path: string }> = [ + { method: "GET", path: "/api/companies/co-1/summary-slots/workspaces_overview/header" }, + { method: "GET", path: "/api/companies/co-1/summary-slots/project/header/revisions" }, + { method: "PUT", path: "/api/companies/co-1/summary-slots/execution_workspace/header" }, { method: "GET", path: "/api/issues/issue-1/attachments" }, { method: "POST", path: "/api/companies/co-1/issues/issue-1/attachments" }, { method: "GET", path: "/api/attachments/att-1/content" }, diff --git a/packages/adapter-utils/src/sandbox-callback-bridge.ts b/packages/adapter-utils/src/sandbox-callback-bridge.ts index 3da9b934e9b..fb18bb2fc70 100644 --- a/packages/adapter-utils/src/sandbox-callback-bridge.ts +++ b/packages/adapter-utils/src/sandbox-callback-bridge.ts @@ -153,6 +153,9 @@ export const DEFAULT_SANDBOX_CALLBACK_BRIDGE_ROUTE_ALLOWLIST: readonly SandboxCa { method: "GET", path: /^\/api\/companies\/[^/]+\/skills$/ }, { method: "GET", path: /^\/api\/companies\/[^/]+\/skills\/[^/]+$/ }, { method: "GET", path: /^\/api\/companies\/[^/]+\/skills\/[^/]+\/files$/ }, + { method: "GET", path: /^\/api\/companies\/[^/]+\/summary-slots\/[^/]+\/[^/]+$/ }, + { method: "GET", path: /^\/api\/companies\/[^/]+\/summary-slots\/[^/]+\/[^/]+\/revisions$/ }, + { method: "PUT", path: /^\/api\/companies\/[^/]+\/summary-slots\/[^/]+\/[^/]+$/ }, // Supporting files of approved skills from connected apps (MCP Skills). The // controller checks the run, the app grant and the approved file manifest. { method: "GET", path: /^\/api\/agents\/me\/mcp-skills\/[^/]+\/files$/ },