fix(gateway): add pre-sanitize + move Python check outside retry loop
Hybrid config repair approach: 1. Pre-sanitize: Add sanitizeOpenClawConfig() using a conservative blocklist approach to remove known-invalid keys (e.g. skills.enabled at root level) BEFORE starting the Gateway. Uses blocklist instead of allowlist for forward-compatibility — new valid keys added by future OpenClaw versions are never stripped. 2. Reactive fallback: The existing doctor auto-repair mechanism catches any OTHER config validation errors, runs openclaw doctor --fix, and retries once. 3. Move Python readiness check outside the while loop since it's fire-and-forget and only needs to run once per start() call. Also adds comprehensive unit tests for the sanitization logic. Co-authored-by: Haze <hazeone@users.noreply.github.com>
This commit is contained in:
@@ -717,4 +717,51 @@ export async function updateAgentModelProvider(
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sanitize ~/.openclaw/openclaw.json before Gateway start.
|
||||
*
|
||||
* Removes known-invalid keys that cause OpenClaw's strict Zod validation
|
||||
* to reject the entire config on startup. Uses a conservative **blocklist**
|
||||
* approach: only strips keys that are KNOWN to be misplaced by older
|
||||
* OpenClaw/ClawX versions or external tools.
|
||||
*
|
||||
* Why blocklist instead of allowlist?
|
||||
* • Allowlist (e.g. `VALID_SKILLS_KEYS`) would strip any NEW valid keys
|
||||
* added by future OpenClaw releases — a forward-compatibility hazard.
|
||||
* • Blocklist only removes keys we positively know are wrong, so new
|
||||
* valid keys are never touched.
|
||||
*
|
||||
* This is a fast, file-based pre-check. For comprehensive repair of
|
||||
* unknown or future config issues, the reactive auto-repair mechanism
|
||||
* (`runOpenClawDoctorRepair`) runs `openclaw doctor --fix` as a fallback.
|
||||
*/
|
||||
export async function sanitizeOpenClawConfig(): Promise<void> {
|
||||
const config = await readOpenClawJson();
|
||||
let modified = false;
|
||||
|
||||
// ── skills section ──────────────────────────────────────────────
|
||||
// OpenClaw's Zod schema uses .strict() on the skills object, accepting
|
||||
// only: allowBundled, load, install, limits, entries.
|
||||
// The key "enabled" belongs inside skills.entries[key].enabled, NOT at
|
||||
// the skills root level. Older versions may have placed it there.
|
||||
const skills = config.skills;
|
||||
if (skills && typeof skills === 'object' && !Array.isArray(skills)) {
|
||||
const skillsObj = skills as Record<string, unknown>;
|
||||
// Keys that are known to be invalid at the skills root level.
|
||||
const KNOWN_INVALID_SKILLS_ROOT_KEYS = ['enabled', 'disabled'];
|
||||
for (const key of KNOWN_INVALID_SKILLS_ROOT_KEYS) {
|
||||
if (key in skillsObj) {
|
||||
console.log(`[sanitize] Removing misplaced key "skills.${key}" from openclaw.json`);
|
||||
delete skillsObj[key];
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
await writeOpenClawJson(config);
|
||||
console.log('[sanitize] openclaw.json sanitized successfully');
|
||||
}
|
||||
}
|
||||
|
||||
export { getProviderEnvVar } from './provider-registry';
|
||||
|
||||
Reference in New Issue
Block a user