mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 00:31:24 +00:00
fix(agents): skip bootstrap files with undefined path (#22698)
* fix(agents): skip bootstrap files with undefined path buildBootstrapContextFiles() called file.path.replace() without checking that path was defined. If a hook pushed a bootstrap file using 'filePath' instead of 'path', the function threw TypeError and crashed every agent session — not just the misconfigured hook. Fix: add a null-guard before the path.replace() call. Files with undefined path are skipped with a warning so one bad hook can't take down all agents. Also adds a test covering the undefined-path case. Fixes #22693 * fix: harden bootstrap path validation and report guards (#22698) (thanks @arosstale) --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
This commit is contained in:
@@ -22,12 +22,31 @@ export function makeBootstrapWarn(params: {
|
||||
return (message: string) => params.warn?.(`${message} (sessionKey=${params.sessionLabel})`);
|
||||
}
|
||||
|
||||
function sanitizeBootstrapFiles(
|
||||
files: WorkspaceBootstrapFile[],
|
||||
warn?: (message: string) => void,
|
||||
): WorkspaceBootstrapFile[] {
|
||||
const sanitized: WorkspaceBootstrapFile[] = [];
|
||||
for (const file of files) {
|
||||
const pathValue = typeof file.path === "string" ? file.path.trim() : "";
|
||||
if (!pathValue) {
|
||||
warn?.(
|
||||
`skipping bootstrap file "${file.name}" — missing or invalid "path" field (hook may have used "filePath" instead)`,
|
||||
);
|
||||
continue;
|
||||
}
|
||||
sanitized.push({ ...file, path: pathValue });
|
||||
}
|
||||
return sanitized;
|
||||
}
|
||||
|
||||
export async function resolveBootstrapFilesForRun(params: {
|
||||
workspaceDir: string;
|
||||
config?: OpenClawConfig;
|
||||
sessionKey?: string;
|
||||
sessionId?: string;
|
||||
agentId?: string;
|
||||
warn?: (message: string) => void;
|
||||
}): Promise<WorkspaceBootstrapFile[]> {
|
||||
const sessionKey = params.sessionKey ?? params.sessionId;
|
||||
const bootstrapFiles = filterBootstrapFilesForSession(
|
||||
@@ -35,7 +54,7 @@ export async function resolveBootstrapFilesForRun(params: {
|
||||
sessionKey,
|
||||
);
|
||||
|
||||
return applyBootstrapHookOverrides({
|
||||
const updated = await applyBootstrapHookOverrides({
|
||||
files: bootstrapFiles,
|
||||
workspaceDir: params.workspaceDir,
|
||||
config: params.config,
|
||||
@@ -43,6 +62,7 @@ export async function resolveBootstrapFilesForRun(params: {
|
||||
sessionId: params.sessionId,
|
||||
agentId: params.agentId,
|
||||
});
|
||||
return sanitizeBootstrapFiles(updated, params.warn);
|
||||
}
|
||||
|
||||
export async function resolveBootstrapContextForRun(params: {
|
||||
|
||||
Reference in New Issue
Block a user