Skip to content

Commit c325efe

Browse files
committed
feat(satellite): make MCP process restart limit configurable via env
Add MCP_PROCESS_MAX_RESTART_ATTEMPTS environment variable to control the maximum number of automatic restart attempts within a 5-minute window before a process is marked as permanently_failed. Default remains 3 (unchanged behavior). Set to 1 for stricter production environments, or 0 to disable automatic restarts entirely.
1 parent 0651163 commit c325efe

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

services/satellite/.env.example

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,13 @@ MCP_USE_TMPFS=false
167167
# Default: 180 seconds (3 minutes)
168168
MCP_PROCESS_IDLE_TIMEOUT_SECONDS=180
169169

170+
# Process Crash Restart Limit (stdio MCP servers only)
171+
# Maximum number of automatic restart attempts within a 5-minute window
172+
# After this limit is exceeded, the process is marked as permanently_failed
173+
# Set to 0 to disable automatic restarts entirely
174+
# Default: 3
175+
MCP_PROCESS_MAX_RESTART_ATTEMPTS=3
176+
170177
# Runtime Validation (optional)
171178
# Set to 'true' to skip system runtime checks at startup (Node.js, Python)
172179
# By default, satellite validates that required runtimes are installed before starting

services/satellite/src/process/manager.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ export class ProcessManager extends EventEmitter {
6868
this.logBuffer = new LogBuffer(eventBus, logger);
6969
this.spawner = new ProcessSpawner(logger);
7070
this.githubHandler = new GitHubDeploymentHandler(logger, this.logBuffer, backendClient);
71-
this.restartHandler = new RestartHandler(logger, eventBus);
71+
const maxRestartAttempts = parseInt(process.env.MCP_PROCESS_MAX_RESTART_ATTEMPTS || '3', 10);
72+
this.restartHandler = new RestartHandler(logger, eventBus, undefined, maxRestartAttempts);
7273
this.dormantManager = new DormantManager(logger, runtimeState, eventBus);
7374
this.tmpfsManager = new TmpfsManager(logger);
7475
this.cacheManager = new CacheManager(logger);

services/satellite/src/process/restart-handler.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ export class RestartHandler {
2222
constructor(
2323
private logger: Logger,
2424
private eventBus?: EventBus,
25-
private backendStatusCallback?: StatusCallback
25+
private backendStatusCallback?: StatusCallback,
26+
private maxRestartAttempts: number = 3
2627
) {}
2728

2829
/**
@@ -124,8 +125,8 @@ export class RestartHandler {
124125
operation: 'restart_limit_exceeded',
125126
installation_name: installationName,
126127
team_id: processInfo.config.team_id,
127-
max_attempts: 3
128-
}, `Max restart attempts (3) exceeded for ${installationName} - marking as permanently failed`);
128+
max_attempts: this.maxRestartAttempts
129+
}, `Max restart attempts (${this.maxRestartAttempts}) exceeded for ${installationName} - marking as permanently failed`);
129130

130131
// Emit mcp.server.permanently_failed event
131132
try {
@@ -236,7 +237,7 @@ export class RestartHandler {
236237
}
237238

238239
/**
239-
* Check if restart should be attempted (max 3 attempts in 5 minutes)
240+
* Check if restart should be attempted (max attempts in 5 minutes, configurable)
240241
*/
241242
shouldAttemptRestart(installationName: string): boolean {
242243
const now = Date.now();
@@ -249,8 +250,7 @@ export class RestartHandler {
249250
recentAttempts.push(now);
250251
this.restartAttempts.set(installationName, recentAttempts);
251252

252-
// Max 3 attempts in 5 minutes
253-
return recentAttempts.length <= 3;
253+
return recentAttempts.length <= this.maxRestartAttempts;
254254
}
255255

256256
/**

0 commit comments

Comments
 (0)