fix: prefer persisted parent session in status

This commit is contained in:
Tak Hoffman
2026-04-10 18:19:11 -05:00
parent 71bd9e0df0
commit 68a39c2f82
2 changed files with 35 additions and 1 deletions

View File

@@ -2,6 +2,8 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
import type { OpenClawConfig } from "../../config/config.js";
import type { MsgContext } from "../templating.js";
import { handleContextCommand } from "./commands-context-command.js";
import { handleStatusCommand } from "./commands-info.js";
import { buildStatusReply } from "./commands-status.js";
import type { HandleCommandsParams } from "./commands-types.js";
import { handleWhoamiCommand } from "./commands-whoami.js";
@@ -11,6 +13,10 @@ vi.mock("./commands-context-report.js", () => ({
buildContextReply: buildContextReplyMock,
}));
vi.mock("./commands-status.js", () => ({
buildStatusReply: vi.fn(async () => ({ text: "status reply" })),
}));
function buildInfoParams(
commandBodyNormalized: string,
cfg: OpenClawConfig,
@@ -134,4 +140,32 @@ describe("info command handlers", () => {
}
}
});
it("prefers the persisted session parent when routing /status context", async () => {
const params = buildInfoParams(
"/status",
{
commands: { text: true },
channels: { whatsapp: { allowFrom: ["*"] } },
} as OpenClawConfig,
{
ParentSessionKey: undefined,
},
);
params.sessionEntry = {
sessionId: "session-1",
updatedAt: Date.now(),
parentSessionKey: "discord:group:parent-room",
} as HandleCommandsParams["sessionEntry"];
const statusResult = await handleStatusCommand(params, true);
expect(statusResult?.shouldContinue).toBe(false);
expect(vi.mocked(buildStatusReply)).toHaveBeenCalledWith(
expect.objectContaining({
parentSessionKey: "discord:group:parent-room",
}),
);
});
});

View File

@@ -189,7 +189,7 @@ export const handleStatusCommand: CommandHandler = async (params, allowTextComma
command: params.command,
sessionEntry: params.sessionEntry,
sessionKey: params.sessionKey,
parentSessionKey: params.ctx.ParentSessionKey,
parentSessionKey: params.sessionEntry?.parentSessionKey ?? params.ctx.ParentSessionKey,
sessionScope: params.sessionScope,
provider: params.provider,
model: params.model,