From 6003acac56ab7733066327fbe53b18aa5da1f29a Mon Sep 17 00:00:00 2001 From: DrSmoothl <1787882683@qq.com> Date: Mon, 15 Jun 2026 22:07:50 +0800 Subject: [PATCH] chore(msg-push): log body of empty-decoded messages (#102 diagnostic) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A group invite surfaces a content-less "[空消息]" friend message (#102). Before deciding whether to drop or decode it, we need to know what its body actually carries — SnowLuma's decoder covers fewer element types than Lagrange, so an empty decode may be a missing decoder (real content) rather than a genuinely empty control push. parseMsgPush now warns, on any message that decodes to zero elements, with a summary of the body: each element's field names, every commonElem's serviceType/businessType + payload hex, and any msgContent. One log line is enough to identify the culprit element offline. No behavior change — the message still dispatches as before. Temporary; remove once the #102 culprit is identified and handled. --- packages/protocol/src/msg-push/index.ts | 53 ++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/packages/protocol/src/msg-push/index.ts b/packages/protocol/src/msg-push/index.ts index 711a16a9..3f7b015d 100644 --- a/packages/protocol/src/msg-push/index.ts +++ b/packages/protocol/src/msg-push/index.ts @@ -1,7 +1,10 @@ +import { hexPreview } from '@snowluma/common/hex'; +import { createLogger } from '@snowluma/common/logger'; import type { PacketInfo } from '@snowluma/common/protocol-types'; +import type { Elem } from '@snowluma/proto-defs/element'; import type { QQEventVariant } from '../events'; import type { IdentityService } from '../identity-service'; -import { buildContext } from './context'; +import { buildContext, type PushMsgBody } from './context'; import { decodeEvent0x210 } from './decoders/event-0x210'; import { decodeEvent0x2DC } from './decoders/event-0x2dc'; import { decodeFriendMessage } from './decoders/friend-message'; @@ -42,8 +45,54 @@ registry.register([ PkgType.PrivateFileMessage, ], decodeFriendMessage); +const log = createLogger('MsgPush'); + +// Kinds that carry decoded `elements`; an empty list surfaces to clients as the +// confusing "[空消息]". +const MESSAGE_KINDS = new Set([ + 'friend_message', 'group_message', 'temp_message', +]); + +/** + * Diagnostic for issue #102 (group invite → "[空消息]"). When a message decodes + * to zero elements, dump what its body actually carried — each element's field + * names, every `commonElem`'s serviceType/businessType + payload hex, and any + * `msgContent` — so we can tell a genuinely content-less control push from an + * element type we simply don't decode yet (and then decode it, rather than + * blindly dropping the message). TODO(#102): remove once the culprit element is + * identified and handled. + */ +function describeUndecodedBody(body: PushMsgBody | undefined): string { + const elems = (body?.richText?.elems ?? []) as Elem[]; + const parts = elems.map((e) => { + if (e.commonElem) { + const ce = e.commonElem; + const pb = ce.pbElem && ce.pbElem.length > 0 ? ` pbElem=${hexPreview(ce.pbElem, 256)}` : ''; + return `commonElem(svc=${ce.serviceType ?? 0},biz=${ce.businessType ?? 0})${pb}`; + } + const keys = Object.keys(e).filter((k) => (e as Record)[k] != null); + return keys.join('+') || '(empty)'; + }); + const extras: string[] = []; + if (body?.richText?.ptt) extras.push('ptt'); + if (body?.richText?.notOnlineFile) extras.push('notOnlineFile'); + if (body?.msgContent && body.msgContent.length > 0) { + extras.push(`msgContent=${hexPreview(body.msgContent, 256)}`); + } + return `elems=[${parts.join('; ')}]${extras.length ? ` ${extras.join(' ')}` : ''}`; +} + export function parseMsgPush(pkt: PacketInfo, identity: IdentityService): QQEventVariant[] { const ctx = buildContext(pkt, identity); if (!ctx) return []; - return registry.decode(ctx); + const events = registry.decode(ctx); + // #102 diagnostic — surface what an empty-decoded message actually contained. + for (const ev of events) { + if (MESSAGE_KINDS.has(ev.kind) && (ev as { elements?: unknown[] }).elements?.length === 0) { + log.warn('[#102] empty message (kind=%s seq=%d from=%d msgType=%d/%d): %s', + ev.kind, ctx.head.sequence, ctx.fromUin, ctx.head.msgType, ctx.head.subType, + describeUndecodedBody(ctx.body)); + } + } + return events; }