JuliusBrussee/caveman · error · Error
KILO_DB contains an invalid path character
Error message
KILO_DB contains an invalid path character
What it means
When the KILO_DB environment variable is set (and not ':memory:'), it is used to build the Kilo database path. The value is rejected if it contains NUL, CR, or LF characters, since these make filesystem paths invalid or exploitable. This prevents path injection through the environment.
Solutions
- Remove control characters from the KILO_DB value, e.g. KILO_DB="$(printf '%s' "$KILO_DB" | tr -d '\r\n\0')"
- Set KILO_DB to a plain path like /home/user/.local/share/kilo/kilo.db
- Unset KILO_DB to fall back to the default database location
Example fix
// before export KILO_DB="/tmp/kilo$(printf '\n').db" // after export KILO_DB="/tmp/kilo.db"
Defensive patterns
Strategy: validation
Validate before calling
const db = process.env.KILO_DB;
if (db && db !== ':memory:' && /[\0\r\n]/.test(db)) {
process.env.KILO_DB = db.replace(/[\0\r\n]/g, '');
} Type guard
function isValidKiloDbPath(v: string | undefined): v is string {
return v === undefined || v === ':memory:' || !/[\0\r\n]/.test(v);
} Try / catch
try {
resolveKiloDatabase();
} catch (e) {
if (e instanceof Error && e.message.includes('invalid path character')) {
process.env.KILO_DB = process.env.KILO_DB!.replace(/[\0\r\n]/g, '');
return resolveKiloDatabase();
}
throw e;
} Prevention
- Strip trailing newlines when loading KILO_DB from files or secret stores
- Avoid echoing KILO_DB from command substitution that appends newlines
- Validate secret-injected env vars for control characters at container startup
- Keep KILO_DB as a simple absolute path without embedded whitespace
When it happens
Trigger: Exporting KILO_DB with embedded newlines or a NUL byte, e.g. KILO_DB=$'foo\nbar' or a value read from a file/secret store that includes a trailing newline or \0.
Common situations: Reading the env var from a Docker secret or CI variable that appends a newline; scripted env injection with unescaped control characters; copy-paste errors into shell profiles.
Understand the failure class
Background: "is not a valid" / "Invalid ... value" environment variable errors: how libraries validate env vars and what to do when they reject yours — this error's family across 48 libraries.
Related errors
- Kilo data root resolves to an empty path
- azure legacy inference path
- bedrock request path
- bounded_response_unavailable
- cave_sandbox_conformance_failed
AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20).
Data as JSON: /api/errors/f4131caafd3e130e.
Report an issue: GitHub.
Appendix: source
Thrown at packages/cli/src/index.ts:12036
try {
preferenceFiles.unshift(join("/Library/Managed Preferences", userInfo().username, "ai.opencode.managed.plist"));
} catch {
// System-level preference remains covered; an unreadable username is itself
// unusual, but no user path can be resolved safely enough to claim absence.
return true;
}
return preferenceFiles.some((path) => existsSync(path));
}
function kiloDatabasePath(): string | null {
const rawDataRoot = process.env.XDG_DATA_HOME || join(homedir(), ".local", "share");
const cleanedDataRoot = rawDataRoot.replace(/[\r\n]+/g, "");
if (!cleanedDataRoot) throw new Error("Kilo data root resolves to an empty path");
const dataRoot = normalize(isAbsolute(cleanedDataRoot) ? cleanedDataRoot : resolve(cleanedDataRoot));
const configured = process.env.KILO_DB;
if (configured === ":memory:") return null;
if (configured) {
if (/[\0\r\n]/.test(configured)) throw new Error("KILO_DB contains an invalid path character");
return normalize(isAbsolute(configured) ? configured : join(dataRoot, "kilo", configured));
}
return join(dataRoot, "kilo", "kilo.db");
}
function kiloActiveOrganizationState(): "none" | "active" | "unknown" {
let path: string | null;
try {
path = kiloDatabasePath();
if (path === null) return "none";
const stat = statSync(path);
if (!stat.isFile()) return "unknown";
} catch (error) {
if ((error as NodeJS.ErrnoException).code === "ENOENT") return "none";
return "unknown";
}
const script = [
'const { DatabaseSync } = require("node:sqlite");',View on GitHub (pinned to 3ee70a1026)