refactor: tighten ws batch typing and queue cleanup logging

This commit is contained in:
copilot-swe-agent[bot]
2026-06-16 22:50:03 +00:00
committed by GitHub
parent 45158ff45b
commit b66140bfd2
3 changed files with 38 additions and 22 deletions

View File

@@ -70,8 +70,13 @@ class RedisRebuildQueue {
); );
} catch (err) { } catch (err) {
await redis await redis
?.srem(QUEUED_SET_KEY, `${job.type}:${job.id}`) .srem(QUEUED_SET_KEY, `${job.type}:${job.id}`)
.catch(() => undefined); .catch((cleanupErr) =>
logger.warn(
`Rebuild queue: failed to cleanup dedupe key for ${job.type}:${job.id} after enqueue failure:`,
cleanupErr
)
);
logger.error( logger.error(
`Rebuild queue: failed to enqueue ${job.type}:${job.id}:`, `Rebuild queue: failed to enqueue ${job.type}:${job.id}:`,
err err
@@ -138,7 +143,12 @@ class RedisRebuildQueue {
// can be re-queued while this one is in progress. // can be re-queued while this one is in progress.
await redis await redis
.srem(QUEUED_SET_KEY, `${job.type}:${job.id}`) .srem(QUEUED_SET_KEY, `${job.type}:${job.id}`)
.catch(() => undefined); .catch((cleanupErr) =>
logger.warn(
`Rebuild queue: failed to remove dedupe key for ${job.type}:${job.id} on dequeue:`,
cleanupErr
)
);
logger.debug( logger.debug(
`Rebuild queue: processing ${job.type}:${job.id}` `Rebuild queue: processing ${job.type}:${job.id}`

View File

@@ -188,7 +188,7 @@ const wss: WebSocketServer = new WebSocketServer({ noServer: true });
const NODE_ID = uuidv4(); const NODE_ID = uuidv4();
const REDIS_CHANNEL = "websocket_messages"; const REDIS_CHANNEL = "websocket_messages";
const REDIS_DIRECT_BATCH_SIZE = 250; const REDIS_DIRECT_BATCH_SIZE = 250;
const REDIS_DIRECT_FLUSH_MS = 10; const REDIS_DIRECT_FLUSH_INTERVAL_MS = 10;
// Client tracking map (local to this node) // Client tracking map (local to this node)
const connectedClients: Map<string, AuthenticatedWebSocket[]> = new Map(); const connectedClients: Map<string, AuthenticatedWebSocket[]> = new Map();
@@ -234,10 +234,6 @@ const publishDirectBatch = async (
targetClientId: entry.targetClientId, targetClientId: entry.targetClientId,
message: entry.message message: entry.message
})), })),
message: {
type: "batch",
data: {}
},
fromNodeId: NODE_ID fromNodeId: NODE_ID
}; };
@@ -289,7 +285,7 @@ const enqueueRedisDirectMessage = async (
if (!redisDirectFlushTimer) { if (!redisDirectFlushTimer) {
redisDirectFlushTimer = setTimeout(() => { redisDirectFlushTimer = setTimeout(() => {
void flushPendingRedisDirectMessages(); void flushPendingRedisDirectMessages();
}, REDIS_DIRECT_FLUSH_MS); }, REDIS_DIRECT_FLUSH_INTERVAL_MS);
} }
}); });
}; };

View File

@@ -76,16 +76,26 @@ export interface SendMessageOptions {
compress?: boolean; compress?: boolean;
} }
// Redis message type for cross-node communication // Redis message types for cross-node communication
export interface RedisMessage { export type RedisMessage =
type: "direct" | "direct-batch" | "broadcast"; | {
targetClientId?: string; type: "direct";
excludeClientId?: string; targetClientId: string;
message: WSMessage; message: WSMessage;
messages?: { fromNodeId: string;
targetClientId: string; }
message: WSMessage; | {
}[]; type: "direct-batch";
fromNodeId: string; messages: {
options?: SendMessageOptions; targetClientId: string;
} message: WSMessage;
}[];
fromNodeId: string;
}
| {
type: "broadcast";
excludeClientId?: string;
message: WSMessage;
fromNodeId: string;
options?: SendMessageOptions;
};