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 "<id>"`
> - 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
This commit is contained in:
Oke Iyanuoluwa Enoch authored and GitHub committed 2026-11-23 20:24:29 -06:00
1 parent dd6db295a3
commit d2bdad4ae5
2 files changed
+27 -1

No files matched your search

@@ -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() };
+6 -1
View File
@@ -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,