Skip to content

Commit 99d84dc

Browse files
committed
fix(channels): fail channel start when the durable ingress queue is denied
An untrusted channel plugin cannot open its durable ingress queue, but the shared ingress monitor resolved the queue lazily, so start() armed the poll timer anyway and every tick re-invoked the throwing factory. On a production gateway that produced one INFO-level "slack ingress drain failed" line per second for 26+ hours while Slack reported connected and healthy and every inbound event was silently dropped. Open the queue before arming the poll timer so an unusable monitor fails channel start through the caller instead of spinning. Also report the actual denied capability: openChannelIngressQueue and openSyncKeyedStore both announced themselves as openKeyedStore, and the message named neither the plugin nor its origin.
1 parent 28ecf95 commit 99d84dc

5 files changed

Lines changed: 50 additions & 6 deletions

File tree

‎docs/plugins/sdk-runtime.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ two-party event loops that do not go through the shared inbound reply runner.
775775
`openChannelIngressDrain(...)` opens the core channel-agnostic worker over that queue (or creates a queue when none is supplied). The drain owns stale-claim recovery, per-lane claim serialization, complete-at-adoption or complete-on-dispatch-return, retry/dead-letter disposition, optional pre-adoption supersede, and claim→adoption stall timeout. Wire claim ownership into reply generation with `turnAdoptionLifecycle` (via `bindIngressLifecycleToReplyOptions` from `plugin-sdk/channel-outbound`). Channel plugins keep accept-side enqueue, lane derivation, non-retryable classification, and any supersede authorization policy.
776776

777777
<Warning>
778-
`openBlobStore`, `openKeyedStore`, `openSyncKeyedStore`, `withLease`, `openChannelIngressQueue`, and `openChannelIngressDrain` are available only to bundled plugins and trusted official plugin installations in this release.
778+
`openBlobStore`, `openKeyedStore`, `openSyncKeyedStore`, `withLease`, `openChannelIngressQueue`, and `openChannelIngressDrain` are available only to bundled plugins and trusted official plugin installations in this release. The rejection names the plugin id and the origin it loaded from; a channel plugin loaded from `plugins.load.paths` or an unofficial install is untrusted, so its ingress monitor fails channel start instead of running without a durable queue.
779779
</Warning>
780780

781781
</Accordion>

‎src/channels/message/ingress-monitor.test.ts‎

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { afterEach, describe, expect, it, vi } from "vitest";
22
import { useAutoCleanupTempDirTracker } from "../../../test/helpers/temp-dir.js";
33
import { closeOpenClawStateDatabaseForTest } from "../../state/openclaw-state-db.js";
4+
import { sleep } from "../../utils/sleep.js";
45
import {
56
createChannelIngressMonitor,
67
type ChannelIngressMonitorDeliveryResult,
@@ -27,7 +28,7 @@ async function withQueue<T>(
2728
}
2829

2930
function createMonitor(
30-
queue: ChannelIngressQueue<StoredEvent>,
31+
queue: ChannelIngressQueue<StoredEvent> | (() => ChannelIngressQueue<StoredEvent>),
3132
deliver: (
3233
raw: RawEvent,
3334
lifecycle: ChannelIngressMonitorLifecycle,
@@ -493,6 +494,30 @@ describe("channel ingress monitor", () => {
493494
});
494495
});
495496

497+
it("fails start once when the durable queue cannot be opened", async () => {
498+
const denial = new Error(
499+
'openChannelIngressQueue is only available for trusted plugins in this release. Plugin "slack" loaded with origin "config"',
500+
);
501+
const queueFactory = vi.fn((): ChannelIngressQueue<StoredEvent> => {
502+
throw denial;
503+
});
504+
const onError = vi.fn();
505+
const monitor = createMonitor(queueFactory, vi.fn(), undefined, onError, undefined, 1);
506+
507+
expect(() => monitor.start()).toThrow(denial);
508+
expect(monitor.isRunning()).toBe(false);
509+
// An armed poll timer would have retried the denied factory many times over this window.
510+
await sleep(25);
511+
expect(queueFactory).toHaveBeenCalledOnce();
512+
expect(onError).not.toHaveBeenCalled();
513+
514+
// Accepted transport input still fails closed rather than being silently dropped.
515+
await expect(monitor.admit({ id: "event-denied", lane: "a", text: "hello" })).rejects.toBe(
516+
denial,
517+
);
518+
await monitor.stop();
519+
});
520+
496521
it("can defer delivery-idle waiting to a channel-owned shutdown grace", async () => {
497522
await withQueue(async (queue) => {
498523
let releaseDelivery!: () => void;

‎src/channels/message/ingress-monitor.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,10 @@ export function createChannelIngressMonitor<TRaw, TBody, TStoredPayload, TMetada
601601
if (running || stopped || isAborted()) {
602602
return;
603603
}
604+
// Open the durable queue before arming the poll timer. A monitor without a queue can
605+
// neither admit nor drain, so channel start must fail through the caller instead of
606+
// running a timer that reports the same unrecoverable error on every tick.
607+
getQueue();
604608
running = true;
605609
pollTimer = setInterval(requestDrain, options.pollIntervalMs);
606610
pollTimer.unref?.();

‎src/plugin-state/plugin-state-store.runtime.test.ts‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ describe("plugin runtime state proxy", () => {
264264
).toThrow("openKeyedStore is only available for trusted plugins");
265265
expect(() =>
266266
api.runtime.state.openSyncKeyedStore({ namespace: "runtime", maxEntries: 10 }),
267-
).toThrow("openKeyedStore is only available for trusted plugins");
267+
).toThrow("openSyncKeyedStore is only available for trusted plugins");
268268
expect(() =>
269269
api.runtime.state.openBlobStore({
270270
namespace: "runtime",
@@ -287,6 +287,17 @@ describe("plugin runtime state proxy", () => {
287287
).toThrow("withLease is only available for trusted plugins");
288288
});
289289

290+
it("names the denied capability, plugin, and origin for channel ingress queues", () => {
291+
const registry = createTestPluginRegistry();
292+
const record = createPluginRecord("slack", "config");
293+
registry.registry.plugins.push(record);
294+
const api = registry.createApi(record, { config: {} });
295+
296+
expect(() => api.runtime.state.openChannelIngressQueue()).toThrow(
297+
/openChannelIngressQueue is only available for trusted plugins in this release\. Plugin "slack" loaded with origin "config"/,
298+
);
299+
});
300+
290301
it("rejects untrusted global plugins", () => {
291302
const registry = createTestPluginRegistry();
292303
const record = createPluginRecord("diffs", "global");

‎src/plugins/registry-runtime.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -540,15 +540,19 @@ export function createPluginRuntimeResolver(state: PluginRegistryState) {
540540
methodName:
541541
| "openBlobStore"
542542
| "openKeyedStore"
543+
| "openSyncKeyedStore"
543544
| "withLease"
545+
| "openChannelIngressQueue"
544546
| "openChannelIngressDrain",
545547
) => {
546548
const record =
547549
pluginRuntimeRecordById.get(pluginId) ??
548550
registry.plugins.find((entry) => entry.id === pluginId);
549551
if (record?.origin !== "bundled" && record?.trustedOfficialInstall !== true) {
552+
// Name the denied plugin and its origin: several plugins share this gate, and a
553+
// bare capability name cannot tell an operator which install needs replacing.
550554
throw new Error(
551-
`${methodName} is only available for trusted plugins in this release.`,
555+
`${methodName} is only available for trusted plugins in this release. Plugin "${pluginId}" loaded with origin "${record?.origin ?? "unknown"}"; reinstall it from its official npm package or ClawHub listing to enable trusted plugin state.`,
552556
);
553557
}
554558
};
@@ -567,7 +571,7 @@ export function createPluginRuntimeResolver(state: PluginRegistryState) {
567571
openSyncKeyedStore: <T>(
568572
options: OpenKeyedStoreOptions,
569573
): PluginStateSyncKeyedStore<T> => {
570-
assertPluginStateAllowed("openKeyedStore");
574+
assertPluginStateAllowed("openSyncKeyedStore");
571575
return createPluginStateSyncKeyedStore<T>(pluginId, options);
572576
},
573577
withLease: <T>(
@@ -580,7 +584,7 @@ export function createPluginRuntimeResolver(state: PluginRegistryState) {
580584
openChannelIngressQueue: <TPayload, TMetadata = unknown, TCompletedMetadata = unknown>(
581585
options?: Omit<Parameters<typeof createChannelIngressQueue>[0], "channelId">,
582586
) => {
583-
assertPluginStateAllowed("openKeyedStore");
587+
assertPluginStateAllowed("openChannelIngressQueue");
584588
const stateDir = options?.stateDir ?? baseState.resolveStateDir();
585589
return createChannelIngressQueue<TPayload, TMetadata, TCompletedMetadata>({
586590
...options,

0 commit comments

Comments
 (0)