From 324ca9b137bc7edb0db93b2ced1fcae27873c91c Mon Sep 17 00:00:00 2001 From: MicroBlock <66859419+std-microblock@users.noreply.github.com> Date: Tue, 17 Nov 2026 20:45:14 +0800 Subject: [PATCH] fix(im): scope interaction message lookup by chat in ImOutputRegistry --- packages/experimental/im/src/outputs.ts | 3 ++- packages/experimental/im/tests/outputs.spec.ts | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/packages/experimental/im/src/outputs.ts b/packages/experimental/im/src/outputs.ts index fee4d38e5e..9d27a97694 100644 --- a/packages/experimental/im/src/outputs.ts +++ b/packages/experimental/im/src/outputs.ts @@ -213,9 +213,10 @@ export class ImOutputRegistry implements ImOutputs { // next inbound frame is re-admitted against the current rules, so the controls have to be as well. if (!admitsChat(source, interaction.bot.id, interaction.chat)) return if (!allows(source.users, interaction.user.id)) return - const message = interaction.message === undefined + const candidate = interaction.message === undefined ? undefined : this.deps.im.history.get(ImMessageKey(interaction.bot.id, interaction.message.id)) + const message = candidate?.chat.key === chat.key ? candidate : undefined const owner = message === undefined ? undefined : this.deps.sender.sessionOf(message.key) return { chat, ...message === undefined ? {} : { message }, ...owner === undefined ? {} : { session: owner } } } diff --git a/packages/experimental/im/tests/outputs.spec.ts b/packages/experimental/im/tests/outputs.spec.ts index 63819a9da0..4a300a393f 100644 --- a/packages/experimental/im/tests/outputs.spec.ts +++ b/packages/experimental/im/tests/outputs.spec.ts @@ -380,6 +380,21 @@ describe('ImOutputRegistry buttons', () => { expect(harness.buttons).toHaveLength(1) }) + it('ignores a stored message belonging to another chat when attributing an interaction', async () => { + const harness = booted() + harness.host({ output: 'probe' }) + const foreign = harness.host({ key: 'foreign', output: 'probe', bindings: [{ chat: ImChatKey('fake:bot', 'elsewhere'), writable: true, home: true }] }) + const foreignMsg = { ...inbound(), key: ImMessageKey('fake:bot', 'm-foreign'), chat: chatOf('elsewhere') } + // Simulate an alias collision where history.get(aliasKey) returns a message from another chat. + harness.messages.set(ImMessageKey('fake:bot', 'REFIDX_shared'), foreignMsg) + harness.sender.owners.set(foreignMsg.key, foreign.sessionId) + + await harness.registry.button(click('dsh:plain', { message: 'REFIDX_shared' })) + expect(harness.buttons).toHaveLength(1) + expect(harness.buttons[0]?.message).toBeUndefined() + expect(harness.buttons[0]?.session).toBeUndefined() + }) + it('routes the stop button of a bound session to sessions.stop', async () => { const harness = booted() const hosted = harness.host({ output: 'probe' })