chenhg5/cc-connect · error

yuanbao: parse varint tag failed at

Error message

yuanbao: parse varint tag failed at %d

What it means

This error is thrown by parseFields in the yuanbao protocol codec when the protobuf wire-format tag at the current byte offset cannot be decoded as a varint. decodeVarint returns n==0 when the buffer ends mid-varint (continuation bit set on the last byte) or the varint exceeds 10 bytes, meaning the framed payload is not valid protobuf data.

Solutions

  1. Verify the bytes passed to parseFields are the complete, uncompressed protobuf message for the frame (check framing/splitting logic upstream of decodeConnMsg).
  2. Log the raw bytes at the failure offset and compare against an expected encoded message to detect protocol drift after a server update.
  3. Update the yuanbao adapter to match any changed server protocol version.
  4. Add a length/consistency check before decoding: ensure the frame payload length matches the header-declared length.
  5. If transient network truncation is suspected, reconnect and re-request the frame rather than retrying the parse.

Example fix

// before
raw := wsFrame.Payload
cmp, _ := parseFields(raw)
// after
if len(raw) == 0 || raw[len(raw)-1]&0x80 != 0 {
    return fmt.Errorf("frame truncated, refusing to parse")
}
cmp, err := parseFields(raw)
if err != nil {
    return fmt.Errorf("yuanbao: decode frame: %w", err)
}
Defensive patterns

Strategy: validation

Validate before calling

func isDecodableFrame(b []byte) bool {
    return len(b) > 0 && b[len(b)-1]&0x80 == 0
}

Type guard

func validVarintStart(b []byte) bool {
    // tag varint must terminate within 10 bytes
    n := 0
    for n < len(b) && n < 10 {
        if b[n]&0x80 == 0 { return true }
        n++
    }
    return false
}

Try / catch

cm, err := decodeConnMsg(raw)
if err != nil {
    slog.Warn("yuanbao: drop frame", "err", err)
    return // or resync/reconnect
}

Prevention

When it happens

Trigger: decodeVarint(data[pos:]) returns 0 while parsing the tag of a message frame: input shorter than the tag's varint length, byte 0x80+ as the final byte, or a 10+ byte malformed varint. Reached via decodeConnMsg, decodeAuthBindRsp, decodeInboundPush, or decodeMsgBodyElement on any inbound frame.

Common situations: Yuanbao server protocol changed (new framing/wire format), a truncated or corrupted WebSocket frame is fed to the decoder, a caller accidentally passes plaintext or compressed data instead of the protobuf body, or a proxy splits/merges frames incorrectly.

Understand the failure class

Background: "cannot parse invalid wire-format data", "cannot unmarshal", "failed unmarshalling": protobuf unmarshal errors explained — this error's family across 10 libraries.

Related errors


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

Appendix: source

Thrown at platform/yuanbao/proto.go:140

	return b.bytes()
}

type field struct {
	fieldNum int
	wireType int
	value    interface{}
}

func parseFields(data []byte) ([]field, error) {
	if len(data) == 0 {
		return nil, fmt.Errorf("yuanbao: empty data")
	}
	var fields []field
	pos := 0
	for pos < len(data) {
		tag, n := decodeVarint(data[pos:])
		if n == 0 {
			return nil, fmt.Errorf("yuanbao: parse varint tag failed at %d", pos)
		}
		pos += n
		fieldNum := int(tag >> 3)
		wt := int(tag & 0x07)
		switch wt {
		case wtVarint:
			val, n := decodeVarint(data[pos:])
			if n == 0 {
				return nil, fmt.Errorf("yuanbao: parse varint at %d", pos)
			}
			fields = append(fields, field{fieldNum, wt, val})
			pos += n
		case wtLen:
			ln, n := decodeVarint(data[pos:])
			if n == 0 {
				return nil, fmt.Errorf("yuanbao: parse length at %d", pos)
			}
			pos += n

View on GitHub (pinned to 4000b2338a)