fix: route direct thread event wakes to main DMs

This commit is contained in:
Peter Steinberger
2026-05-22 10:23:32 +01:00
parent 4ee8a2ac2e
commit 0acfb7ba13
2 changed files with 19 additions and 2 deletions

View File

@@ -25,6 +25,14 @@ describe("event session routing", () => {
accountId: "work",
peerId: "123",
});
expect(
parseDirectAgentSessionTarget("agent:main:telegram:work:direct:123:thread:1712345678.123"),
).toEqual({
agentId: "main",
channel: "telegram",
accountId: "work",
peerId: "123",
});
});
it("routes single-owner dmScope=main direct event keys to the agent main session", () => {
@@ -53,6 +61,12 @@ describe("event session routing", () => {
policy,
),
).toEqual({ reason: "exec-event", sessionKey: "agent:main:main" });
expect(
resolveEventSessionKeyForPolicy(
"agent:main:telegram:work:direct:123:thread:1712345678.123",
policy,
),
).toBe("agent:main:main");
});
it("does not route multi-owner or wildcard direct sessions to main", () => {

View File

@@ -5,6 +5,7 @@ import {
buildAgentMainSessionKey,
normalizeAgentId,
parseAgentSessionKey,
parseThreadSessionSuffix,
} from "../routing/session-key.js";
import { resolveEventSessionKey, scopedHeartbeatWakeOptions } from "../routing/session-key.js";
import { resolvePinnedMainDmOwnerFromAllowlist } from "../security/dm-policy-shared.js";
@@ -66,8 +67,10 @@ function normalizeEntry(value: string): string | undefined {
export function parseDirectAgentSessionTarget(
sessionKey: string | undefined | null,
): DirectSessionTarget | null {
const parsed = parseAgentSessionKey(sessionKey);
if (!parsed || deriveSessionChatTypeFromKey(sessionKey) !== "direct") {
const { baseSessionKey } = parseThreadSessionSuffix(sessionKey);
const directSessionKey = baseSessionKey ?? sessionKey;
const parsed = parseAgentSessionKey(directSessionKey);
if (!parsed || deriveSessionChatTypeFromKey(directSessionKey) !== "direct") {
return null;
}
const parts = parsed.rest.split(":");