mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 05:30:42 +00:00
fix(discord): raise carbon slow listener threshold
This commit is contained in:
@@ -40,6 +40,7 @@ type CreateClientFn = (
|
||||
handlers: ConstructorParameters<typeof Client>[1],
|
||||
plugins: ConstructorParameters<typeof Client>[2],
|
||||
) => Client;
|
||||
type CarbonEventQueueOptions = NonNullable<ConstructorParameters<typeof Client>[0]["eventQueue"]>;
|
||||
|
||||
type ListenerCompatClient = Client & {
|
||||
plugins?: Array<{ id: string; plugin: Plugin }>;
|
||||
@@ -116,7 +117,10 @@ export function createDiscordMonitorClient(params: {
|
||||
modals: Modal[];
|
||||
voiceEnabled: boolean;
|
||||
discordConfig: Parameters<typeof resolveDiscordPresenceUpdate>[0] & {
|
||||
eventQueue?: { listenerTimeout?: number };
|
||||
eventQueue?: Pick<
|
||||
CarbonEventQueueOptions,
|
||||
"listenerTimeout" | "maxQueueSize" | "maxConcurrency"
|
||||
>;
|
||||
};
|
||||
runtime: RuntimeEnv;
|
||||
createClient: CreateClientFn;
|
||||
@@ -145,8 +149,9 @@ export function createDiscordMonitorClient(params: {
|
||||
// Discord normalization/enqueue work).
|
||||
const eventQueueOpts = {
|
||||
listenerTimeout: 120_000,
|
||||
slowListenerThreshold: 30_000,
|
||||
...params.discordConfig.eventQueue,
|
||||
};
|
||||
} satisfies CarbonEventQueueOptions;
|
||||
const readyListener = createDiscordStatusReadyListener({
|
||||
discordConfig: params.discordConfig,
|
||||
getAutoPresenceController: () => autoPresenceController,
|
||||
|
||||
@@ -97,21 +97,23 @@ describe("monitorDiscordProvider", () => {
|
||||
) => Promise<{ status: string; reason?: string }>;
|
||||
};
|
||||
|
||||
const getConstructedEventQueue = (): { listenerTimeout?: number } | undefined => {
|
||||
const getConstructedEventQueue = ():
|
||||
| { listenerTimeout?: number; slowListenerThreshold?: number }
|
||||
| undefined => {
|
||||
expect(clientConstructorOptionsMock).toHaveBeenCalledTimes(1);
|
||||
const opts = clientConstructorOptionsMock.mock.calls[0]?.[0] as {
|
||||
eventQueue?: { listenerTimeout?: number };
|
||||
eventQueue?: { listenerTimeout?: number; slowListenerThreshold?: number };
|
||||
};
|
||||
return opts.eventQueue;
|
||||
};
|
||||
|
||||
const getConstructedClientOptions = (): {
|
||||
eventQueue?: { listenerTimeout?: number };
|
||||
eventQueue?: { listenerTimeout?: number; slowListenerThreshold?: number };
|
||||
} => {
|
||||
expect(clientConstructorOptionsMock).toHaveBeenCalledTimes(1);
|
||||
return (
|
||||
(clientConstructorOptionsMock.mock.calls[0]?.[0] as {
|
||||
eventQueue?: { listenerTimeout?: number };
|
||||
eventQueue?: { listenerTimeout?: number; slowListenerThreshold?: number };
|
||||
}) ?? {}
|
||||
);
|
||||
};
|
||||
@@ -573,14 +575,17 @@ describe("monitorDiscordProvider", () => {
|
||||
expect(drained[0]?.message).toContain("4014");
|
||||
});
|
||||
|
||||
it("passes default eventQueue.listenerTimeout of 120s to Carbon Client", async () => {
|
||||
it("passes OpenClaw EventQueue defaults to Carbon Client", async () => {
|
||||
await monitorDiscordProvider({
|
||||
config: baseConfig(),
|
||||
runtime: baseRuntime(),
|
||||
});
|
||||
|
||||
const eventQueue = getConstructedEventQueue();
|
||||
expect(eventQueue).toEqual({ listenerTimeout: 120_000 });
|
||||
expect(eventQueue).toEqual({
|
||||
listenerTimeout: 120_000,
|
||||
slowListenerThreshold: 30_000,
|
||||
});
|
||||
});
|
||||
|
||||
it("forwards custom eventQueue config from discord config to Carbon Client", async () => {
|
||||
|
||||
@@ -85,20 +85,6 @@ describe("enableConsoleCapture", () => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it.each(["DiscordMessageListener", "DiscordReactionListener", "DiscordReactionRemoveListener"])(
|
||||
"suppresses discord EventQueue slow listener duplicates for %s",
|
||||
(listener) => {
|
||||
setLoggerOverride({ level: "info", file: tempLogPath() });
|
||||
const warn = vi.fn();
|
||||
console.warn = warn;
|
||||
enableConsoleCapture();
|
||||
console.warn(
|
||||
`[EventQueue] Slow listener detected: ${listener} took 12.3 seconds for event MESSAGE_CREATE`,
|
||||
);
|
||||
expect(warn).not.toHaveBeenCalled();
|
||||
},
|
||||
);
|
||||
|
||||
it("does not double-prefix timestamps", () => {
|
||||
setLoggerOverride({ level: "info", file: tempLogPath() });
|
||||
const warn = vi.fn();
|
||||
|
||||
@@ -146,12 +146,6 @@ const SUPPRESSED_CONSOLE_PREFIXES = [
|
||||
"Session already open",
|
||||
] as const;
|
||||
|
||||
const SUPPRESSED_DISCORD_EVENTQUEUE_LISTENERS = [
|
||||
"DiscordMessageListener",
|
||||
"DiscordReactionListener",
|
||||
"DiscordReactionRemoveListener",
|
||||
] as const;
|
||||
|
||||
function shouldSuppressConsoleMessage(message: string): boolean {
|
||||
if (isVerbose()) {
|
||||
return false;
|
||||
@@ -159,12 +153,6 @@ function shouldSuppressConsoleMessage(message: string): boolean {
|
||||
if (SUPPRESSED_CONSOLE_PREFIXES.some((prefix) => message.startsWith(prefix))) {
|
||||
return true;
|
||||
}
|
||||
if (
|
||||
message.startsWith("[EventQueue] Slow listener detected") &&
|
||||
SUPPRESSED_DISCORD_EVENTQUEUE_LISTENERS.some((listener) => message.includes(listener))
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user