chenhg5/cc-connect · error

yuanbao: invalid reply context type %T

Error message

yuanbao: invalid reply context type %T

What it means

Reply expects the rctx parameter to be the platform's internal replyContext struct; if a caller passes any other type it returns this error including the actual type. Reply contexts must originate from this platform's message handling or ReconstructReplyCtx.

Source

Thrown at platform/yuanbao/platform.go:399

		if content, ok := item["msg_content"].(map[string]interface{}); ok {
			elem.msgContent = content
		} else if mc, ok := item["MsgContent"]; ok {
			switch v := mc.(type) {
			case map[string]interface{}:
				elem.msgContent = v
			case string:
				_ = json.Unmarshal([]byte(v), &elem.msgContent)
			}
		}
		result = append(result, elem)
	}
	return result
}

func (p *Platform) Reply(ctx context.Context, rctx any, content string) error {
	rc, ok := rctx.(replyContext)
	if !ok {
		return fmt.Errorf("yuanbao: invalid reply context type %T", rctx)
	}
	if content == "" {
		return nil
	}
	content = core.StripMarkdown(content)
	p.startReplyHeartbeat(rc.chatID)
	defer p.stopReplyHeartbeat(rc.chatID, true)
	msgBody := [][]byte{encodeTextBody(content)}
	var frame []byte
	if rc.chatType == "group" {
		frame = encodeSendGroupMessage(rc.targetID, msgBody, p.getBotID(), "", "", "")
	} else {
		frame = encodeSendC2CMessage(rc.targetID, msgBody, p.getBotID(), "", 0, "", "")
	}
	ws := p.getWS()
	if ws == nil {
		return fmt.Errorf("yuanbao: not connected")
	}

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Ensure the rctx passed to Reply was produced by yuanbao's own message handling or ReconstructReplyCtx
  2. Check that persisted reply contexts are keyed/stored per platform and restored for the matching adapter
  3. Use ReconstructReplyCtx with a valid "yuanbao:..." session key to rebuild the context
Defensive patterns

Strategy: type-guard

Validate before calling

if rc, ok := rctx.(replyContext); !ok { return fmt.Errorf("not a yuanbao reply context") }

Type guard

func isYuanbaoReplyCtx(rctx any) bool { _, ok := rctx.(replyContext); return ok }

Try / catch

if err := p.Reply(ctx, rctx, text); err != nil { if strings.Contains(err.Error(), "invalid reply context type") { slog.Error("wrong reply context for platform", "type", fmt.Sprintf("%T", rctx)) } }

Prevention

When it happens

Trigger: Calling Reply with a reply context built by a different platform adapter, a nil value, or a hand-constructed map/struct; typically caused by mixing reply contexts across platforms in a bridge.

Common situations: Multi-platform setups where reply contexts are persisted globally and replayed against the wrong adapter; a session restore path returning the wrong context type.

Understand the failure class

Background: Type mismatch errors: IllegalArgumentException, TypeError and type guards across 150 open-source libraries — this error's family across 150 libraries.

Related errors


AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06). Data as JSON: /api/errors/dcee022368cf7636. Report an issue: GitHub.