fix(sessions): allow cross-agent session file paths in multi-agent setups

When OPENCLAW_STATE_DIR changes between session creation and resolution
(e.g., after reinstall or config change), absolute session file paths
pointing to other agents' sessions directories were rejected even though
they structurally match the valid .../agents/<agentId>/sessions/... pattern.

The existing fallback logic in resolvePathWithinSessionsDir extracts the
agent ID from the path and tries to resolve it via the current env's
state directory. When those directories differ, the containment check
fails. Now, if the path structurally matches the agent sessions pattern
(validated by extractAgentIdFromAbsoluteSessionPath), we accept it
directly as a final fallback.

Fixes #15410, Fixes #15565, Fixes #15468
This commit is contained in:
Xinhua Gu
2026-02-16 12:42:57 +01:00
committed by Peter Steinberger
parent e20b87f1ba
commit 90774c098a
2 changed files with 61 additions and 0 deletions

View File

@@ -152,6 +152,11 @@ function resolvePathWithinSessionsDir(
if (resolvedFromPath) {
return resolvedFromPath;
}
// The path structurally matches .../agents/<agentId>/sessions/...
// Accept it even if the root directory differs from the current env
// (e.g., OPENCLAW_STATE_DIR changed between session creation and resolution).
// The structural pattern provides sufficient containment guarantees.
return path.resolve(trimmed);
}
}
if (!normalized || normalized.startsWith("..") || path.isAbsolute(normalized)) {