Skip to content

Commit 597684c

Browse files
committed
fix(imessage): include from-me drop diagnostics
1 parent 5dbea4e commit 597684c

2 files changed

Lines changed: 42 additions & 2 deletions

File tree

extensions/imessage/src/monitor.watch-subscribe-retry.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vites
44
import type { createIMessageRpcClient, IMessageRpcClient } from "./client.js";
55
import { monitorIMessageProvider } from "./monitor.js";
66
import type { attachIMessageMonitorAbortHandler } from "./monitor/abort-handler.js";
7-
import { describeIMessageInboundDropDiagnostic } from "./monitor/monitor-provider.js";
7+
import {
8+
describeIMessageInboundDropDiagnostic,
9+
shouldThrottleIMessageInboundDropDiagnostic,
10+
} from "./monitor/monitor-provider.js";
811

912
const waitForTransportReadyMock = vi.hoisted(() =>
1013
vi.fn<typeof waitForTransportReady>(async () => {}),
@@ -181,6 +184,27 @@ describe("describeIMessageInboundDropDiagnostic", () => {
181184
expect(diagnostic).not.toContain("+1555");
182185
});
183186

187+
it("describes from-me drops and marks them for throttling", () => {
188+
const diagnostic = describeIMessageInboundDropDiagnostic({
189+
accountId: "default",
190+
reason: "from me",
191+
message: {
192+
id: 43,
193+
chat_id: 456,
194+
guid: "p:0/outbound-guid",
195+
is_group: true,
196+
created_at: "2026-06-09T10:01:00.000Z",
197+
},
198+
});
199+
200+
expect(diagnostic).toBe(
201+
'imessage: dropped inbound message account=default reason="from me" chat_id=456 group=true message_id=43 guid=present created_at=2026-06-09T10:01:00.000Z',
202+
);
203+
expect(diagnostic).not.toContain("outbound-guid");
204+
expect(shouldThrottleIMessageInboundDropDiagnostic("from me")).toBe(true);
205+
expect(shouldThrottleIMessageInboundDropDiagnostic("echo")).toBe(false);
206+
});
207+
184208
it("keeps normal policy drops quiet", () => {
185209
expect(
186210
describeIMessageInboundDropDiagnostic({

extensions/imessage/src/monitor/monitor-provider.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,9 +260,15 @@ function isRetriableWatchSubscribeStartupError(error: unknown): boolean {
260260
const IMESSAGE_DIAGNOSTIC_DROP_REASONS = new Set([
261261
"agent echo in self-chat",
262262
"echo",
263+
"from me",
263264
"reflected assistant content",
264265
"self-chat echo",
265266
]);
267+
const IMESSAGE_THROTTLED_DIAGNOSTIC_DROP_REASONS = new Set(["from me"]);
268+
269+
export function shouldThrottleIMessageInboundDropDiagnostic(reason: string): boolean {
270+
return IMESSAGE_THROTTLED_DIAGNOSTIC_DROP_REASONS.has(reason);
271+
}
266272

267273
export function describeIMessageInboundDropDiagnostic(params: {
268274
accountId: string;
@@ -419,6 +425,7 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P
419425
// replay aggressively without the old catchup cursor/retry bookkeeping.
420426
const inboundReplayGuard = createIMessageInboundReplayGuard();
421427
let staleBacklogSuppressed = 0;
428+
const loggedThrottledDropDiagnostics = new Set<string>();
422429

423430
// Downtime recovery. We pass the persisted recovery cursor (the last
424431
// dispatched rowid) to watch.subscribe as since_rowid so imsg replays the rows
@@ -911,7 +918,16 @@ export async function monitorIMessageProvider(opts: MonitorIMessageOpts = {}): P
911918
message,
912919
});
913920
if (diagnostic) {
914-
runtime.log?.(warn(diagnostic));
921+
const throttleKey = `${rateLimitKey}:${decision.reason}`;
922+
const shouldThrottleDiagnostic = shouldThrottleIMessageInboundDropDiagnostic(
923+
decision.reason,
924+
);
925+
if (!shouldThrottleDiagnostic || !loggedThrottledDropDiagnostics.has(throttleKey)) {
926+
if (shouldThrottleDiagnostic) {
927+
loggedThrottledDropDiagnostics.add(throttleKey);
928+
}
929+
runtime.log?.(warn(diagnostic));
930+
}
915931
}
916932
// Surface the silent-allowlist drop once per chat. Without this, operators
917933
// who set groupPolicy="allowlist" without populating

0 commit comments

Comments
 (0)