Skip to content

fix: pass agentId to resolveSessionFilePath for multi-agent path validation#15103

Closed
jalehman wants to merge 1 commit into
openclaw:mainfrom
jalehman:fix/session-file-path-agent-id
Closed

fix: pass agentId to resolveSessionFilePath for multi-agent path validation#15103
jalehman wants to merge 1 commit into
openclaw:mainfrom
jalehman:fix/session-file-path-agent-id

Conversation

@jalehman

@jalehman jalehman commented Feb 13, 2026

Copy link
Copy Markdown
Contributor

Problem

Non-main agents crash when running /compact or hitting other session file resolution paths:

Error: Session file path must be within sessions directory

Root Cause

resolveSessionFilePath() takes an optional opts.agentId to determine which agent's sessions directory to validate against. Multiple callers omit this parameter, so it defaults to the main agent's sessions dir.

When a non-main agent has an absolute sessionFile path in its session store (e.g. ~/.openclaw/agents/other-agent/sessions/xxx.jsonl), the path validation in resolvePathWithinSessionsDir() computes a relative path from the main agent's dir — which starts with ../.. — and rejects it as directory traversal.

Introduced by

Commit 4199f9889 (fix: harden session transcript path resolution) added resolvePathWithinSessionsDir as a security hardening measure for path traversal prevention. It updated resolveSessionFilePath to validate the sessionFile candidate against the sessions directory, but only updated some callers (gateway, subagent-announce, transcript) to pass agentId — missing the auto-reply paths (commands-compact, get-reply-run, status, session-cost-usage, etc.).

Before that commit, resolveSessionFilePath returned entry.sessionFile as-is with no validation, so the missing agentId was harmless.

Fix

Pass agentId to all call sites of resolveSessionFilePath() that were missing it:

  • commands-compact.ts — the immediate crash site (/compact command)
  • get-reply-run.ts — main reply path
  • session.ts — session fork/init
  • status.ts/status transcript usage reading
  • commands-status.ts — status command
  • commands-session.ts/usage command
  • session-status-tool.ts — agent session status tool
  • session-cost-usage.ts — cost summary, time series, and log loading (3 call sites)
  • usage.ts (gateway) — usage API handlers (3 call sites)

All patched callers already had agentId available in their scope/params.

Testing

  • Verified pnpm build succeeds
  • The fix is a strict superset: main-agent behavior is unchanged (agentId defaults to main), non-main agents now resolve paths against their own sessions directory

Greptile Overview

Greptile Summary

This PR fixes multi-agent session transcript path validation by consistently passing agentId to resolveSessionFilePath() at call sites that resolve/validate a session’s transcript path.

The underlying issue is that resolveSessionFilePath() validates entry.sessionFile against an agent-scoped sessions directory; if callers omit opts.agentId, it defaults to the main agent’s sessions dir and rejects non-main agents’ absolute stored paths as traversal. The updates in:

  • auto-reply command handlers (/compact, /status, /usage)
  • the main reply run path
  • session forking/init
  • the session status tool
  • gateway usage handlers
  • session cost/usage loading helpers

ensure that non-main agents validate and resolve against their own sessions directory while leaving main-agent behavior unchanged (default remains main).

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk.
  • Changes are narrowly scoped to threading an existing agentId through to resolveSessionFilePath() and related usage loaders. Verified that resolveSessionFilePath uses agentId to select the correct agent sessions directory for validation, and that gateway session keys are canonicalized with agent:<agentId>: so the new agentId derivation is stable.
  • No files require special attention

Last reviewed commit: ee26f95

Context used:

  • Context from dashboard - CLAUDE.md (source)
  • Context from dashboard - AGENTS.md (source)

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: XS labels Feb 13, 2026
@steipete

Copy link
Copy Markdown
Contributor

Closing per maintainer direction.

What was completed locally:

  • Rebased PR branch onto latest main.
  • Resolved conflicts.
  • Added regression-heavy tests for multi-agent session-path handling:
    • src/auto-reply/status.test.ts
    • src/infra/session-cost-usage.test.ts
    • src/gateway/server-methods/usage.sessions-usage.test.ts
  • Added changelog line with credit.

Local commits (not pushed from this environment):

Credit: thanks @jalehman for the original contribution and fix direction.

@steipete

Copy link
Copy Markdown
Contributor

Closing per maintainer direction after documenting local rebase+test work and credit.

@steipete steipete closed this Feb 13, 2026
steipete added a commit that referenced this pull request Feb 13, 2026
steipete added a commit that referenced this pull request Feb 13, 2026
skyhawk14 pushed a commit to skyhawk14/openclaw that referenced this pull request Feb 13, 2026
GwonHyeok pushed a commit to learners-superpumped/openclaw that referenced this pull request Feb 15, 2026
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 1, 2026
…openclaw#15448)

Co-authored-by: Josh Lehman <[email protected]>
(cherry picked from commit 9904135)

# Conflicts:
#	CHANGELOG.md
#	src/auto-reply/status.test.ts
#	src/auto-reply/status.ts
hughdidit pushed a commit to hughdidit/DAISy-Agency that referenced this pull request Mar 3, 2026
…openclaw#15448)

Co-authored-by: Josh Lehman <[email protected]>
(cherry picked from commit 9904135)

# Conflicts:
#	CHANGELOG.md
#	src/auto-reply/status.ts
#	src/infra/session-cost-usage.test.ts
#	src/infra/session-cost-usage.ts
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling gateway Gateway runtime size: XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants