Skip to content

Session scope filtering fails - falls back to all main sessions #371

@Bozhu12

Description

@Bozhu12

Bug Description

When setting EVOLVER_SESSION_SCOPE to a workspace name (e.g. workspace-helperclaw), the evolver falls back to reading ALL sessions from the main agent directory, ignoring the scope.

Expected: Only read sessions whose cwd field contains workspaces/<scope>.

Actual: Logs show [SessionScope] No sessions match scope "workspace-helperclaw". Using all 15 session(s) (fallback). — reading from ~/.openclaw/agents/main/sessions instead of ~/.openclaw/agents/helperclaw/sessions.

Environment

  • evolver: v1.62.1 (tested on origin/main, commit 0bffa8c)
  • Node.js: v24
  • Platform: Linux

Steps to Reproduce

EVOLVER_SESSION_SCOPE=workspace-helperclaw EVOLVE_BRIDGE=false node index.js run

Observe log output:

[SessionScope] No sessions match scope "workspace-helperclaw". Using all 15 session(s) (fallback).

Root Cause Analysis

Two bugs cause this:

Bug 1: AGENT_SESSIONS_DIR is derived from AGENT_NAME env var (defaults to "main" from .env), not from EVOLVER_SESSION_SCOPE. Even when scope is set, the code reads from ~/.openclaw/agents/main/sessions instead of ~/.openclaw/agents/helperclaw/sessions.

Bug 2: The scope matching logic uses f.name.toLowerCase().includes(scopeLower) — but session files are UUIDs (e.g. c982d748-b38e-4b58-bd99-adf064741790.jsonl) which never contain the workspace scope string. Additionally, readRecentLog() reads from the tail of each file, but the session header (containing cwd) is at the head of the file.

Workaround

From bash, set both variables:

AGENT_NAME=helperclaw EVOLVER_SESSION_SCOPE=workspace-helperclaw EVOLVE_BRIDGE=false node index.js run

Result: [SessionScope] Using all 3 session(s) (fallback). — correctly reads 3 sessions from helperclaw instead of 15 from main. The content-based matching still fails (falls back to all 3 sessions) due to Bug 2.

Suggested Fix

  1. Add deriveSessionsDir() that extracts the agent name from EVOLVER_SESSION_SCOPE (e.g. workspace-helperclawhelperclaw) and reads from that agent's sessions directory.

  2. For scope content matching, read the first ~800 bytes of each session file (not the tail) and match the cwd field which contains workspaces/<scopeName>.

A reference implementation for v1.32.4 (readable source) is available at: https://github.com/Bozhu12/evolver/commit/db31a1f

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions