-
-
Notifications
You must be signed in to change notification settings - Fork 69.4k
[Bug]: /new / before_reset resolves the wrong agent identity, causing session-memory to write into workspace-main instead of the bound agent workspace #39816
Description
Bug type
Behavior bug
Summary
In a multi-agent setup, native /new / before_reset hook handling derives agent identity incorrectly and can cause the bundled session-memory hook to write reset/session memory into workspace-main even when the live bound agent is a different agent (for example, Navi with workspace-navi).
Steps to reproduce
- Configure a non-main agent bound to a channel/DM, for example:
agentId: naviagents.list[navi].workspace = ~/.openclaw/workspace-navi
- Ensure bundled internal hooks include:
session-memory
- Use the bound non-main agent in a real chat surface (Discord DM in my case).
- Trigger
/newor/reset. - Inspect the resulting session-memory artifacts under
~/.openclaw/.
Expected behavior
Reset/session-memory flow should resolve to the bound active agent and write memory/session bridge files into that agent's workspace.
Example:
- bound agent
navi→ writes to~/.openclaw/workspace-navi/memory/
Actual behavior
Session-start/reset memory artifacts are being written into ~/.openclaw/workspace-main/memory/ instead of the bound agent workspace.
Observed files:
~/.openclaw/workspace-main/memory/2026-03-07-2106.md~/.openclaw/workspace-main/memory/2026-03-07-session-greeting.md~/.openclaw/workspace-main/memory/2026-03-08-session-start.md
These are session-start style summaries and reference:
Session Key: agent:main:main
Meanwhile the actual bound agent continuity files live in:
~/.openclaw/workspace-navi/memory/
So the system ends up in a workspace split-brain state.
OpenClaw version
2026.3.7
Also checked on current main source as of 2026-03-08; the relevant code path still appears unchanged there.
Operating system
Linux (WSL2 / Ubuntu-style environment)
Install method
Git/source install (main) and stable release both inspected.
Logs, screenshots, and evidence
Current stable tag inspected:
- v2026.3.7
- commit: 42a1394c5c0fb86706f61598e68e0db30e8c99c1
Current upstream main still contains this in src/auto-reply/reply/commands-core.ts:
await hookRunner.runBeforeReset(
{ sessionFile, messages, reason: params.action },
{
agentId: params.sessionKey?.split(":")[0] ?? "main",
sessionKey: params.sessionKey,
sessionId: prevEntry?.sessionId,
workspaceDir: params.workspaceDir,
},
);
For a session key like:
- agent:navi:main
split(":")[0] returns:
- "agent"
not:
- "navi"
Bundled session-memory handler resolves workspace from session identity:
src/hooks/bundled/session-memory/handler.ts
const agentId = resolveAgentIdFromSessionKey(event.sessionKey);
const workspaceDir = cfg
? resolveAgentWorkspaceDir(cfg, agentId)
: path.join(resolveStateDir(process.env, os.homedir), "workspace");
Observed split on disk:
- Navi configured workspace: ~/.openclaw/workspace-navi
- stray session-memory files created in: ~/.openclaw/workspace-main/memory/
Example files created there:
- 2026-03-07-2106.md
- 2026-03-07-session-greeting.md
- 2026-03-08-session-start.mdImpact and severity
Affected:
- multi-agent setups using non-main agents
- bundled
session-memoryon/new//reset - likely any workflow that assumes reset/session-memory writes land in the active bound agent workspace
Severity:
- High behavior bug
Frequency:
- Reproducible in my setup
Consequence:
- session/reset memory written into the wrong workspace
- split-brain continuity (
workspace-navifor real agent files,workspace-mainfor reset/session-memory artifacts) - likely contributes to stale continuity, wrong memory reads, and reset weirdness in multi-agent setups
Additional information
Regression timing
This appears to have been introduced when native reset hooks were backfilled in:
- commit
aec41a588b - message:
fix(hooks): backfill reset command hooks for native /new path - date: 2026-02-24
That commit is contained in releases including:
- v2026.3.2
- v2026.3.7
Related issues
Potentially related, but not the same exact bug:
- Bug: session-memory hook (and command-logger) do not fire on /new or /reset commands #23027 —
session-memory/command-loggerdo not fire on/newor/reset - Internal hooks not triggered in auto-reply path due to missing sessionKey parameter #29203 — internal hooks not triggered in auto-reply path due to missing
sessionKey - agent_end hook passes wrong agentId (always 'agent' instead of actual agent ID) #39521 —
agent_endhook passes wrongagentIdusing the samesplit(":")[0]pattern
Suggested fix direction
At minimum:
- stop using
params.sessionKey?.split(":")[0] - use proper session-key parsing such as
resolveAgentIdFromSessionKey(params.sessionKey)
But ideally:
- reset hooks should prefer the bound/active agent identity (or explicit hook context agent/workspace) rather than relying on a legacy-looking session key that can be
agent:main:main
Why I think this is runtime, not config
The relevant config values remained stable across backups and live config:
agents.defaults.workspace = ~/.openclaw/workspaceagents.list[navi].workspace = ~/.openclaw/workspace-navi
So this does not look like a plain config-path mistake. It looks like a hook/runtime identity-resolution bug.