mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 17:18:25 +00:00
fix(agent): search all agent stores when resolving --session-id (#13579)
* fix(agent): search all agent stores when resolving --session-id When `--session-id` was provided without `--to` or `--agent`, the reverse lookup only searched the default agent's session store. Sessions created under a specific agent (e.g. `--agent mybot`) live in that agent's store file, so the lookup silently failed and the session was not reused. Now `resolveSessionKeyForRequest` iterates all configured agent stores when the primary store doesn't contain the requested sessionId. Fixes #12881 * fix: search other agent stores when --to key does not match --session-id When --to derives a session key whose stored sessionId doesn't match the requested --session-id, the cross-store search now also runs. This handles the case where a user provides both --to and --session-id targeting a session in a different agent's store.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import crypto from "node:crypto";
|
||||
import type { MsgContext } from "../../auto-reply/templating.js";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { listAgentIds } from "../../agents/agent-scope.js";
|
||||
import {
|
||||
normalizeThinkLevel,
|
||||
normalizeVerboseLevel,
|
||||
@@ -78,6 +79,31 @@ export function resolveSessionKeyForRequest(opts: {
|
||||
}
|
||||
}
|
||||
|
||||
// When sessionId was provided but not found in the primary store, search all agent stores.
|
||||
// Sessions created under a specific agent live in that agent's store file; the primary
|
||||
// store (derived from the default agent) won't contain them.
|
||||
// Also covers the case where --to derived a sessionKey that doesn't match the requested sessionId.
|
||||
if (
|
||||
opts.sessionId &&
|
||||
!explicitSessionKey &&
|
||||
(!sessionKey || sessionStore[sessionKey]?.sessionId !== opts.sessionId)
|
||||
) {
|
||||
const allAgentIds = listAgentIds(opts.cfg);
|
||||
for (const agentId of allAgentIds) {
|
||||
if (agentId === storeAgentId) {
|
||||
continue;
|
||||
}
|
||||
const altStorePath = resolveStorePath(sessionCfg?.store, { agentId });
|
||||
const altStore = loadSessionStore(altStorePath);
|
||||
const foundKey = Object.keys(altStore).find(
|
||||
(key) => altStore[key]?.sessionId === opts.sessionId,
|
||||
);
|
||||
if (foundKey) {
|
||||
return { sessionKey: foundKey, sessionStore: altStore, storePath: altStorePath };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { sessionKey, sessionStore, storePath };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user