mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-12-03 11:47:42 +01:00
fix(workspaces): resolve issue identifiers on task workspace routes (#20658)
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Each task can have a task workspace, and the API lets agents and board users inspect and change it > - The routes `GET` and `PUT /api/issues/:id/workspace` and `POST /api/issues/:id/workspace/repositories` are in their own router > - The issues router changes an issue identifier (for example `ABC-12`) to the issue UUID, but that resolver does not apply to this router > - So these routes send the identifier into a UUID comparison, Postgres refuses it, and the API returns 500 > - This pull request makes these routes accept an issue identifier, and return 404 for a value that is not an identifier and not a UUID > - The benefit is that the workspace routes act like the other issue routes, and a bad value gives a clear 4xx, not a 500 ## Linked Issues or Issue Description I searched the open and closed issues and pull requests for this problem. I did not find one. Related issues show the same class of error on other routes: #20356, #13504, #17332. They do not touch these routes. **What happened?** `GET /api/issues/ABC-12/workspace` and `PUT /api/issues/ABC-12/workspace` return `500 {"error":"Internal server error"}`. The server log shows `DrizzleQueryError` caused by `PostgresError: invalid input syntax for type uuid: "ABC-12"`. The same request with the issue UUID returns 200. Other issue routes, for example `GET /api/issues/ABC-12` and `GET /api/issues/ABC-12/comments`, accept the identifier. A value that is not an identifier and not a UUID (for example `not-a-task`) also returns 500. **Expected behavior** The workspace routes accept an issue identifier, as the other issue routes do. The agent skill reference (`skills/paperclip/references/issue-workspaces.md`) writes these routes with `:issueId`, so agents send identifiers. A value that does not identify an issue returns a 4xx. **Steps to reproduce** 1. Create an issue. Note its identifier (for example `ABC-12`). 2. Send `GET /api/issues/ABC-12/workspace` as a board user or as an agent. 3. See `500 Internal server error` and the UUID syntax error in the server log. 4. Send the same request with the issue UUID. See 200. **Paperclip version or commit** Seen on release `2026.1106.0`. The route code is the same on `master` at `4f33bb357`. **Deployment mode** Authenticated, private exposure. Installed from npm. Embedded Postgres. **Agent adapter(s) involved** Not adapter-specific (core bug). An agent found it with the Claude Code adapter. ## What Changed - `server/src/routes/task-workspaces.ts`: the shared `task()` lookup now uses `normalizeIssueIdentifier` and `isUuidLike` from `@paperclipai/shared`. An identifier matches `issues.identifier`. A UUID matches `issues.id`. Any other value returns `404 Task not found` before the query. - The lookup keeps the same read condition (`issueReadSqlCondition`) and the same access checks. An identifier that the actor cannot read gets the same 404 as a UUID that the actor cannot read. - `server/src/__tests__/task-workspace-binding.test.ts`: one new test. It reads and selects a workspace with the identifier (in lower case for the read), and checks 404 for `not-a-task` and for an unknown identifier. - No documentation change. The skill reference already writes these routes with `:issueId`. ## Verification - Red before the fix: `npx vitest run src/__tests__/task-workspace-binding.test.ts -t "resolves an issue identifier"` failed with `expected 500 to be 200`. - Green after the fix: the same command passes. - The three test files that mount these routes pass: `task-workspace-binding.test.ts`, `heartbeat-repository-catalog-recovery.test.ts` and `workspace-preparation-history.test.ts` (117 tests). - `pnpm --filter @paperclipai/server typecheck` passes. - `pnpm verify --base upstream/master` keeps 2,498 test files, because `server/src/app.ts` imports the route. I stopped the local run after 75 minutes, in the first of its 10 jobs. In that part, four files failed: `file-resources-git-scan-load`, `git-restore-point-expiration`, `git-workspace-expiration` and `issue-recovery-assignments`. None of them imports the changed route or `app.ts`. On the base revision, the same four files also stall on this machine: a test database connection stays idle in a transaction, and the cleanup waits for its lock. - The CI checks on this pull request run the full suite. All checks pass. - Manual check on a release `2026.1106.0` instance before the fix: identifier 500, UUID 200, `not-a-task` 500. ## Risks - Low risk. The change touches one lookup in one route file. - A UUID still matches by id, with the same checks. `isUuidLike` accepts UUID versions 1 to 5. Issue ids come from `gen_random_uuid()` (version 4). - A value that is not a UUID and not an identifier now returns 404 instead of 500. No client can depend on the old 500. ## Model Used - Anthropic Claude Opus 5.5 (`claude-opus-5-5`). Capabilities: extended reasoning, tool use and code execution. The harness does not show the context window size. ## 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 - [x] All Paperclip CI gates are green - [x] 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>
This commit is contained in:
1 parent
432ca25efa
commit
4363be6069
2 files changed
+29
-2
No files matched your search
@@ -850,4 +850,27 @@ const support = await getEmbeddedPostgresTestSupport();
|
||||
selection: { kind: "existing", workspaceId: other.workspaceId } })).rejects.toThrow("unavailable or inaccessible");
|
||||
expect((await svc.inspectTaskWorkspace(f.companyId, f.issueId, f.actor)).pendingSelection).toBeNull();
|
||||
});
|
||||
|
||||
it("resolves an issue identifier on the task workspace routes and answers 404 for an unknown reference", async () => {
|
||||
const f = await fixture(), svc = executionWorkspaceService(db);
|
||||
await svc.bindTaskWorkspace(f.companyId, f.issueId, f.workspaceId);
|
||||
const identifier = `W${f.issueId.slice(0, 6).toUpperCase()}-41`;
|
||||
await db.update(issues).set({ identifier }).where(eq(issues.id, f.issueId));
|
||||
const app = express();
|
||||
app.use(express.json());
|
||||
app.use((req, _res, next) => { req.actor = f.actor; next(); });
|
||||
app.use("/api", taskWorkspaceRoutes(db));
|
||||
app.use(errorHandler);
|
||||
const inspected = await request(app).get(`/api/issues/${identifier.toLowerCase()}/workspace`);
|
||||
expect(inspected.status).toBe(200);
|
||||
expect(inspected.body).toMatchObject({ workspace: { id: f.workspaceId }, bindingRevision: 1 });
|
||||
const selection = { selection: { kind: "task_directory" }, expectedBindingRevision: 1, requestKey: "identifier-selection" };
|
||||
expect((await request(app).put(`/api/issues/${identifier}/workspace`).send(selection)).status).toBe(200);
|
||||
expect((await svc.inspectTaskWorkspace(f.companyId, f.issueId, f.actor)).pendingSelection).toMatchObject({ requestKey: selection.requestKey });
|
||||
for (const ref of ["not-a-task", `${identifier}9`]) {
|
||||
const missing = await request(app).get(`/api/issues/${ref}/workspace`);
|
||||
expect(missing.status).toBe(404);
|
||||
expect(missing.body.error).toBe("Task not found");
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -1,7 +1,7 @@
|
||||
import { and, eq } from "drizzle-orm";
|
||||
import { issues, type Db } from "@paperclipai/db";
|
||||
import { Router, type Request } from "express";
|
||||
import { prepareWorkspaceRepositorySchema, selectTaskWorkspaceSchema } from "@paperclipai/shared";
|
||||
import { isUuidLike, normalizeIssueIdentifier, prepareWorkspaceRepositorySchema, selectTaskWorkspaceSchema } from "@paperclipai/shared";
|
||||
import { accessService } from "../services/access.js";
|
||||
import { executionWorkspaceService } from "../services/execution-workspaces.js";
|
||||
import { issueReadSqlCondition } from "../services/authorization.js";
|
||||
@@ -15,7 +15,11 @@ export function taskWorkspaceRoutes(db: Db) {
|
||||
const router = Router();
|
||||
const workspaces = executionWorkspaceService(db);
|
||||
async function task(req: Request, write = false) {
|
||||
const [issue] = await db.select().from(issues).where(and(eq(issues.id, req.params.id as string), await issueReadSqlCondition(db, req.actor)));
|
||||
const ref = String(req.params.id).trim();
|
||||
const identifier = normalizeIssueIdentifier(ref);
|
||||
if (!identifier && !isUuidLike(ref)) throw notFound("Task not found");
|
||||
const match = identifier ? eq(issues.identifier, identifier) : eq(issues.id, ref);
|
||||
const [issue] = await db.select().from(issues).where(and(match, await issueReadSqlCondition(db, req.actor)));
|
||||
if (!issue) throw notFound("Task not found");
|
||||
if (!hasCompanyAccess(req, issue.companyId)) throw notFound("Task not found");
|
||||
assertCompanyAccess(req, issue.companyId);
|
||||
|
||||
Reference in new issue
Block a user