fix(memory): strip null bytes from workspace paths causing ENOTDIR (#24876)

Add stripNullBytes() helper and apply it to all return paths in
resolveAgentWorkspaceDir() including configured, default, and
state-dir-derived paths. Null bytes in paths cause ENOTDIR errors
when Node tries to resolve them as directories.
This commit is contained in:
Omair Afzal
2026-02-24 08:22:42 +05:00
committed by GitHub
parent 177f167eab
commit 19c43eade2

View File

@@ -13,6 +13,12 @@ import { normalizeSkillFilter } from "./skills/filter.js";
import { resolveDefaultAgentWorkspaceDir } from "./workspace.js";
const log = createSubsystemLogger("agent-scope");
/** Strip null bytes from paths to prevent ENOTDIR errors. */
function stripNullBytes(s: string): string {
// eslint-disable-next-line no-control-regex
return s.replace(/\0/g, "");
}
export { resolveAgentIdFromSessionKey } from "../routing/session-key.js";
type AgentEntry = NonNullable<NonNullable<OpenClawConfig["agents"]>["list"]>[number];
@@ -214,18 +220,18 @@ export function resolveAgentWorkspaceDir(cfg: OpenClawConfig, agentId: string) {
const id = normalizeAgentId(agentId);
const configured = resolveAgentConfig(cfg, id)?.workspace?.trim();
if (configured) {
return resolveUserPath(configured);
return stripNullBytes(resolveUserPath(configured));
}
const defaultAgentId = resolveDefaultAgentId(cfg);
if (id === defaultAgentId) {
const fallback = cfg.agents?.defaults?.workspace?.trim();
if (fallback) {
return resolveUserPath(fallback);
return stripNullBytes(resolveUserPath(fallback));
}
return resolveDefaultAgentWorkspaceDir(process.env);
return stripNullBytes(resolveDefaultAgentWorkspaceDir(process.env));
}
const stateDir = resolveStateDir(process.env);
return path.join(stateDir, `workspace-${id}`);
return stripNullBytes(path.join(stateDir, `workspace-${id}`));
}
export function resolveAgentDir(cfg: OpenClawConfig, agentId: string) {