diff --git a/src/agents/pi-embedded-runner.test.ts b/src/agents/pi-embedded-runner.test.ts index 248869b90..c1a7ffae7 100644 --- a/src/agents/pi-embedded-runner.test.ts +++ b/src/agents/pi-embedded-runner.test.ts @@ -399,6 +399,19 @@ describe("getDmHistoryLimitFromSessionKey", () => { ).toBe(10); }); + it("returns undefined for non-dm session kinds", () => { + const config = { + slack: { dmHistoryLimit: 10 }, + telegram: { dmHistoryLimit: 15 }, + } as ClawdbotConfig; + expect( + getDmHistoryLimitFromSessionKey("agent:beta:slack:channel:C1", config), + ).toBeUndefined(); + expect( + getDmHistoryLimitFromSessionKey("telegram:slash:123", config), + ).toBeUndefined(); + }); + it("returns undefined for unknown provider", () => { const config = { telegram: { dmHistoryLimit: 15 } } as ClawdbotConfig; expect( diff --git a/src/agents/pi-embedded-runner.ts b/src/agents/pi-embedded-runner.ts index a6b845aa4..3932f49fd 100644 --- a/src/agents/pi-embedded-runner.ts +++ b/src/agents/pi-embedded-runner.ts @@ -475,6 +475,7 @@ export function getDmHistoryLimitFromSessionKey( // The userId may contain colons (e.g., email addresses), so join remaining parts const kind = providerParts[1]?.toLowerCase(); const userId = providerParts.slice(2).join(":"); + if (kind !== "dm") return undefined; // Helper to get limit with per-DM override support const getLimit = (