fix: use previousSessionEntry for pre-reset learning and preserve session file path

This commit is contained in:
lubolin0925 2026-03-07 11:24:40 +08:00
parent d000dcad94
commit 672728a692
3 changed files with 12 additions and 27 deletions

View File

@ -80,14 +80,7 @@ export const handleCompactCommand: CommandHandler = async (params) => {
groupChannel: params.sessionEntry.groupChannel,
groupSpace: params.sessionEntry.space,
spawnedBy: params.sessionEntry.spawnedBy,
sessionFile: resolveSessionFilePath(
sessionId,
params.sessionEntry,
resolveSessionFilePathOptions({
agentId: params.agentId,
storePath: params.storePath,
}),
),
sessionFile: params.sessionEntry.sessionFile,
workspaceDir: params.workspaceDir,
agentDir: params.agentDir,
config: params.cfg,

View File

@ -223,10 +223,16 @@ export async function handleCommands(params: HandleCommandsParams): Promise<Comm
: undefined;
// Determine which session to learn from (after ACP resolution)
// For non-ACP resets, use previousSessionEntry because initSessionState already rotated to fresh session
const targetSessionKey = boundAcpKey ?? params.sessionKey;
const targetSessionEntry = boundAcpKey
? resolveSessionEntryForHookSessionKey(params.sessionStore, boundAcpKey)
: params.sessionEntry;
let targetSessionEntry: typeof params.sessionEntry;
if (boundAcpKey) {
targetSessionEntry = resolveSessionEntryForHookSessionKey(params.sessionStore, boundAcpKey);
} else if (params.previousSessionEntry?.sessionId) {
targetSessionEntry = params.previousSessionEntry;
} else {
targetSessionEntry = params.sessionEntry;
}
// Trigger learning before reset/new commands (after ACP target resolution)
if (targetSessionEntry?.sessionId) {
@ -238,14 +244,7 @@ export async function handleCommands(params: HandleCommandsParams): Promise<Comm
groupChannel: targetSessionEntry.groupChannel,
groupSpace: targetSessionEntry.space,
spawnedBy: targetSessionEntry.spawnedBy,
sessionFile: resolveSessionFilePath(
targetSessionEntry.sessionId,
targetSessionEntry,
resolveSessionFilePathOptions({
agentId: params.agentId,
storePath: params.storePath,
}),
),
sessionFile: targetSessionEntry.sessionFile,
workspaceDir: params.workspaceDir,
agentDir: params.agentDir,
config: params.cfg,

View File

@ -1,6 +1,5 @@
import { runEmbeddedPiAgent } from "../../agents/pi-embedded.js";
import type { OpenClawConfig } from "../../config/config.js";
import { resolveSessionFilePath, resolveSessionFilePathOptions } from "../../config/sessions.js";
import { logVerbose } from "../../globals.js";
const LEARN_SYSTEM_PROMPT = [
@ -54,17 +53,11 @@ export async function runLearnForSession(params: {
? `Focus area: ${params.customFocus}. ${LEARN_DEFAULT_PROMPT}`
: LEARN_DEFAULT_PROMPT;
const sessionFilePath = resolveSessionFilePath(
params.sessionId,
{ sessionId: params.sessionId, sessionFile: params.sessionFile },
resolveSessionFilePathOptions({ agentId: undefined, storePath: undefined }),
);
try {
await runEmbeddedPiAgent({
sessionId: params.sessionId,
sessionKey: params.sessionKey,
sessionFile: sessionFilePath,
sessionFile: params.sessionFile,
messageChannel: params.messageChannel,
groupId: params.groupId,
groupChannel: params.groupChannel,