This commit is contained in:
selfboot 2026-01-30 13:34:25 +02:00 committed by GitHub
commit cee3d65827
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 0 deletions

View File

@ -108,6 +108,27 @@ describe("initSessionState thread forking", () => {
});
describe("initSessionState RawBody", () => {
it("canonicalizes main session aliases for explicit SessionKey", async () => {
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-session-alias-"));
const storePath = path.join(root, "sessions.json");
const cfg = {
session: { store: storePath, mainKey: "work" },
agents: { list: [{ id: "ops", default: true }] },
} as OpenClawConfig;
const result = await initSessionState({
ctx: {
Body: "Hello",
SessionKey: "main",
},
cfg,
commandAuthorized: true,
});
expect(result.sessionKey).toBe("agent:ops:work");
expect(result.sessionCtx.SessionKey).toBe("agent:ops:work");
});
it("triggerBodyNormalized correctly extracts commands when Body contains context but RawBody is clean", async () => {
const root = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-rawbody-"));
const storePath = path.join(root, "sessions.json");

View File

@ -8,6 +8,7 @@ import type { OpenClawConfig } from "../../config/config.js";
import type { TtsAutoMode } from "../../config/types.tts.js";
import {
DEFAULT_RESET_TRIGGERS,
canonicalizeMainSessionAlias,
deriveSessionMetaPatch,
evaluateSessionFreshness,
type GroupKeyResolution,
@ -187,6 +188,7 @@ export async function initSessionState(params: {
}
sessionKey = resolveSessionKey(sessionScope, sessionCtxForState, mainKey);
sessionKey = canonicalizeMainSessionAlias({ cfg, agentId, sessionKey });
const entry = sessionStore[sessionKey];
const previousSessionEntry = resetTriggered && entry ? { ...entry } : undefined;
const now = Date.now();
@ -337,6 +339,7 @@ export async function initSessionState(params: {
const sessionCtx: TemplateContext = {
...ctx,
SessionKey: sessionKey,
// Keep BodyStripped aligned with Body (best default for agent prompts).
// RawBody is reserved for command/directive parsing and may omit context.
BodyStripped: formatInboundBodyWithSenderMeta({