Skip to content

Commit bff2a60

Browse files
committed
fix: address CodeRabbit findings on bridge architecture
- Replace no-op spawn() timeout with manual setTimeout + proc.kill() - Add Partials.Channel to Discord adapter for DM support - Add discord-bridge and slack-bridge to show_status() and do_stop() - Normalize error messages in catch blocks for non-Error throws
1 parent ea3fb46 commit bff2a60

4 files changed

Lines changed: 15 additions & 5 deletions

File tree

‎scripts/adapters/messaging/discord.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Uses discord.js for WebSocket-based gateway connection.
88
*/
99

10-
const { Client, GatewayIntentBits } = require("discord.js");
10+
const { Client, GatewayIntentBits, Partials } = require("discord.js");
1111

1212
module.exports = function createAdapter(config) {
1313
const TOKEN = process.env[config.credentials.token_env];
@@ -27,6 +27,7 @@ module.exports = function createAdapter(config) {
2727
GatewayIntentBits.MessageContent,
2828
GatewayIntentBits.DirectMessages,
2929
],
30+
partials: [Partials.Channel],
3031
});
3132

3233
client.on("messageCreate", async (message) => {

‎scripts/bridge-core.js‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,22 @@ function runAgentInSandbox(message, sessionId) {
6363
`-m ${shellQuote(message)} --session-id ${shellQuote(safeSessionId)}`;
6464

6565
const proc = spawn("ssh", ["-T", "-F", confPath, `openshell-${SANDBOX}`, cmd], {
66-
timeout: 120000,
6766
stdio: ["ignore", "pipe", "pipe"],
6867
});
6968

69+
// spawn() does not support timeout — implement manually
70+
const killTimer = setTimeout(() => {
71+
proc.kill("SIGTERM");
72+
}, 120000);
73+
7074
let stdout = "";
7175
let stderr = "";
7276

7377
proc.stdout.on("data", (d) => (stdout += d.toString()));
7478
proc.stderr.on("data", (d) => (stderr += d.toString()));
7579

7680
proc.on("close", (code) => {
81+
clearTimeout(killTimer);
7782
try {
7883
fs.unlinkSync(confPath);
7984
fs.rmdirSync(confDir);
@@ -106,7 +111,8 @@ function runAgentInSandbox(message, sessionId) {
106111
});
107112

108113
proc.on("error", (err) => {
109-
resolve(`Error: ${err.message}`);
114+
clearTimeout(killTimer);
115+
resolve(`Error: ${err && err.message ? err.message : String(err)}`);
110116
});
111117
});
112118
}

‎scripts/bridge.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,8 @@ async function runBridge(config) {
165165
}
166166
} catch (err) {
167167
clearInterval(typingInterval);
168-
await msg.reply(`Error: ${err.message}`).catch(() => {});
168+
const errorMsg = err && err.message ? err.message : String(err);
169+
await msg.reply(`Error: ${errorMsg}`).catch(() => {});
169170
}
170171
}
171172

‎scripts/start-services.sh‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ stop_service() {
9494
show_status() {
9595
mkdir -p "$PIDDIR"
9696
echo ""
97-
for svc in telegram-bridge cloudflared; do
97+
for svc in telegram-bridge discord-bridge slack-bridge cloudflared; do
9898
if is_running "$svc"; then
9999
echo -e " ${GREEN}●${NC} $svc (PID $(cat "$PIDDIR/$svc.pid"))"
100100
else
@@ -115,6 +115,8 @@ show_status() {
115115
do_stop() {
116116
mkdir -p "$PIDDIR"
117117
stop_service cloudflared
118+
stop_service slack-bridge
119+
stop_service discord-bridge
118120
stop_service telegram-bridge
119121
info "All services stopped."
120122
}

0 commit comments

Comments
 (0)