Matrix: tighten fallback resolution and ACP lookup

This commit is contained in:
Gustavo Madeira Santana
2026-03-12 10:01:38 +00:00
parent a7edb677b0
commit ee0568c62e
9 changed files with 183 additions and 21 deletions

View File

@@ -83,11 +83,6 @@ function normalizeMatrixThreadTarget(raw: string): string | undefined {
return normalized || undefined;
}
function normalizeMatrixDirectUserTarget(raw: string): string | undefined {
const normalized = normalizeMatrixThreadTarget(raw);
return normalized?.startsWith("@") ? normalized : undefined;
}
export function resolveMatrixAutoThreadId(params: {
to: string;
toolContext?: ChannelThreadingToolContext;
@@ -101,15 +96,11 @@ export function resolveMatrixAutoThreadId(params: {
if (!target || !currentChannel) {
return undefined;
}
// Matrix user:@ targets resolve to a DM room at send time, which can differ
// from the current room after DM recreation or stale m.direct ordering.
// Only auto-thread when the explicit room target already matches.
if (target.toLowerCase() !== currentChannel.toLowerCase()) {
const directTarget = normalizeMatrixDirectUserTarget(params.to);
const currentDirectUserId = normalizeMatrixDirectUserTarget(context.currentDirectUserId ?? "");
if (!directTarget || !currentDirectUserId) {
return undefined;
}
if (directTarget.toLowerCase() !== currentDirectUserId.toLowerCase()) {
return undefined;
}
return undefined;
}
return context.currentThreadTs;
}

View File

@@ -309,7 +309,7 @@ describe("runMessageAction threading auto-injection", () => {
expect(call?.ctx?.params?.threadId).toBe("$explicit");
});
it("injects threadId for matching Matrix dm user target", async () => {
it("skips threadId for Matrix dm user targets until the resolved room matches", async () => {
mockHandledSendAction();
const call = await runThreadingAction({
@@ -322,8 +322,8 @@ describe("runMessageAction threading auto-injection", () => {
toolContext: defaultMatrixDmToolContext,
});
expect(call?.threadId).toBe("$thread");
expect(call?.ctx?.params?.threadId).toBe("$thread");
expect(call?.threadId).toBeUndefined();
expect(call?.ctx?.params?.threadId).toBeUndefined();
});
it("skips threadId for different Matrix dm user target", async () => {

View File

@@ -115,6 +115,10 @@ export {
resolveMatrixLegacyFlatStoragePaths,
sanitizeMatrixPathSegment,
} from "../infra/matrix-storage-paths.js";
export {
requiresExplicitMatrixDefaultAccount,
resolveMatrixDefaultOrOnlyAccountId,
} from "../infra/matrix-account-selection.js";
export {
hasActionableMatrixMigration,
hasPendingMatrixMigration,