From d2bdad4ae54cce1a5b2a64c3cacbd598ef53d7ed Mon Sep 17 00:00:00 2001 From: Oke Iyanuoluwa Enoch <70354778+Iyanuoluwa007@users.noreply.github.com> Date: Tue, 24 Nov 2026 02:24:29 +0000 Subject: [PATCH] fix(plugins): report WORKER_UNAVAILABLE when no worker is registered for a bridge call (#19286) ## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Plugin UIs call their workers through the bridge routes `bridge/data` and `bridge/action` > - `mapRpcErrorToBridgeError` turns a worker call failure into a bridge error code for the client > - For a plugin with no registered worker, the worker manager rejects with `PluginWorkerUnavailableError` and the message `No worker registered for plugin ""` > - The mapper matched only the substrings `not running` and `not registered`, so this case became `UNKNOWN` > - This pull request makes the mapper recognize the typed error that the worker manager already throws > - The benefit is that clients get `WORKER_UNAVAILABLE` for every "no live worker" case, and the result does not depend on message wording ## Linked Issues or Issue Description Fixes #19092 Refs #19007 (the parent issue that #19092 was split out of) I searched open and closed PRs for `19092`, `mapRpcErrorToBridgeError` and `WORKER_UNAVAILABLE`. I found no related PR. ## What Changed - `mapRpcErrorToBridgeError` in `server/src/routes/plugins.ts` returns `WORKER_UNAVAILABLE` when `findPluginWorkerUnavailableError(err)` finds a `PluginWorkerUnavailableError`, including one wrapped in a `cause` chain. The existing substring checks stay as a fallback. - Added a route test in `server/src/__tests__/plugin-routes-authz.test.ts`. The worker manager mock rejects with the same error and message that `plugin-worker-manager.ts` produces when no worker is registered. The test expects a 502 with `code: "WORKER_UNAVAILABLE"`. ## Verification - `pnpm exec vitest run server/src/__tests__/plugin-routes-authz.test.ts --testTimeout=60000`: 38 of 39 tests pass, including the new test. - The one failure is `lists bundled monorepo plugin packages`. It fails the same way on unmodified `master` on my Windows machine, because the postinstall step could not create the plugin SDK symlinks there. It is not related to this change. - Without the fix, the new test receives `code: "UNKNOWN"`. ## Risks - Low risk. Only errors that the worker manager already classifies as worker-unavailable change their bridge code, from `UNKNOWN` to `WORKER_UNAVAILABLE`. The HTTP status stays 502. Nothing is dispatched to a worker in this case, before or after the change. ## Model Used - Claude Opus 5.5 (Anthropic, model ID `claude-opus-5-5`), used through Claude Code with tool use (shell, file editing). It assisted with code reading, the change, tests and this description. I reviewed the change. ## 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 --- .../src/__tests__/plugin-routes-authz.test.ts | 21 +++++++++++++++++++ server/src/routes/plugins.ts | 7 ++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/server/src/__tests__/plugin-routes-authz.test.ts b/server/src/__tests__/plugin-routes-authz.test.ts index 49b08a9efea..5bdcb9f4680 100644 --- a/server/src/__tests__/plugin-routes-authz.test.ts +++ b/server/src/__tests__/plugin-routes-authz.test.ts @@ -1,6 +1,7 @@ import express from "express"; import request from "supertest"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; +import { PluginWorkerUnavailableError } from "../services/plugin-worker-unavailable-error.js"; const mockRegistry = vi.hoisted(() => ({ getById: vi.fn(), @@ -1014,6 +1015,26 @@ describe("plugin tool and bridge authz", () => { }); }); + it("reports WORKER_UNAVAILABLE when no worker is registered for the plugin", async () => { + readyPlugin(); + const message = `No worker registered for plugin "${pluginId}"`; + const call = vi.fn().mockRejectedValue( + new PluginWorkerUnavailableError({ pluginId, workerStatus: null, message }), + ); + const { app } = await createApp(boardActor(), {}, { + bridgeDeps: { + workerManager: { call }, + }, + }); + + const res = await request(app) + .post(`/api/plugins/${pluginId}/data/source-objects`) + .send({ companyId: companyA }); + + expect(res.status).toBe(502); + expect(res.body).toMatchObject({ code: "WORKER_UNAVAILABLE", message }); + }); + it("rejects manual job triggers for non-admin board users", async () => { const scheduler = { triggerJob: vi.fn() }; const jobStore = { getJobByIdForPlugin: vi.fn() }; diff --git a/server/src/routes/plugins.ts b/server/src/routes/plugins.ts index 0479f3466c6..488f4eb1560 100644 --- a/server/src/routes/plugins.ts +++ b/server/src/routes/plugins.ts @@ -67,6 +67,7 @@ import type { PluginToolDispatcher } from "../services/plugin-tool-dispatcher.js import { ToolGatewayHttpError, type ToolGatewayService } from "../services/tool-gateway.js"; import type { PluginPerformActionActorContext, ToolRunContext } from "@paperclipai/plugin-sdk"; import { JsonRpcCallError, PLUGIN_RPC_ERROR_CODES } from "@paperclipai/plugin-sdk"; +import { findPluginWorkerUnavailableError } from "../services/plugin-worker-unavailable-error.js"; import { assertAuthenticated, assertBoard, @@ -1374,7 +1375,11 @@ export function pluginRoutes( const message = err instanceof Error ? err.message : String(err); // Worker not running — surface as WORKER_UNAVAILABLE - if (message.includes("not running") || message.includes("not registered")) { + if ( + findPluginWorkerUnavailableError(err) || + message.includes("not running") || + message.includes("not registered") + ) { return { code: "WORKER_UNAVAILABLE", message,