fix(gateway): optimize gateway start robustness in version 0.1.19 (#244)
Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Haze <hazeone@users.noreply.github.com>
This commit is contained in:
60
electron/gateway/startup-recovery.ts
Normal file
60
electron/gateway/startup-recovery.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Gateway startup recovery heuristics.
|
||||
*
|
||||
* This module is intentionally dependency-free so it can be unit-tested
|
||||
* without Electron/runtime mocks.
|
||||
*/
|
||||
|
||||
const INVALID_CONFIG_PATTERNS: RegExp[] = [
|
||||
/\binvalid config\b/i,
|
||||
/\bconfig invalid\b/i,
|
||||
/\bunrecognized key\b/i,
|
||||
/\brun:\s*openclaw doctor --fix\b/i,
|
||||
];
|
||||
|
||||
function normalizeLogLine(value: string): string {
|
||||
return value.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when text appears to indicate OpenClaw config validation failure.
|
||||
*/
|
||||
export function isInvalidConfigSignal(text: string): boolean {
|
||||
const normalized = normalizeLogLine(text);
|
||||
if (!normalized) return false;
|
||||
return INVALID_CONFIG_PATTERNS.some((pattern) => pattern.test(normalized));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true when either startup stderr lines or startup error message
|
||||
* indicate an OpenClaw config validation failure.
|
||||
*/
|
||||
export function hasInvalidConfigFailureSignal(
|
||||
startupError: unknown,
|
||||
startupStderrLines: string[],
|
||||
): boolean {
|
||||
for (const line of startupStderrLines) {
|
||||
if (isInvalidConfigSignal(line)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
const errorText = startupError instanceof Error
|
||||
? `${startupError.name}: ${startupError.message}`
|
||||
: String(startupError ?? '');
|
||||
|
||||
return isInvalidConfigSignal(errorText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retry guard for one-time config repair during a single startup flow.
|
||||
*/
|
||||
export function shouldAttemptConfigAutoRepair(
|
||||
startupError: unknown,
|
||||
startupStderrLines: string[],
|
||||
alreadyAttempted: boolean,
|
||||
): boolean {
|
||||
if (alreadyAttempted) return false;
|
||||
return hasInvalidConfigFailureSignal(startupError, startupStderrLines);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user