chenhg5/cc-connect · error

webex: invalid reply context %T

Error message

webex: invalid reply context %T

What it means

asReplyContext recovers the platform-specific replyContext from the engine's any-typed reply context value. If the value was not produced by this Webex platform (wrong concrete type), it returns this error naming the actual Go type received. It is an internal invariant violation across the platform boundary.

Source

Thrown at platform/webex/webex_reply.go:19

package webex

import (
	"context"
	"fmt"
	"strings"
	"unicode/utf8"

	"github.com/chenhg5/cc-connect/core"
)

// webexMaxBytes is Webex's per-message body cap.
const webexMaxBytes = 7439

// asReplyContext recovers a replyContext from the engine's any-typed value.
func asReplyContext(replyCtx any) (replyContext, error) {
	rc, ok := replyCtx.(replyContext)
	if !ok {
		return replyContext{}, fmt.Errorf("webex: invalid reply context %T", replyCtx)
	}
	return rc, nil
}

// Reply posts a threaded response to the originating message.
func (p *Platform) Reply(ctx context.Context, replyCtx any, content string) error {
	rc, err := asReplyContext(replyCtx)
	if err != nil {
		return err
	}
	return p.post(ctx, rc.roomID, rc.messageID, content)
}

// Send posts a non-threaded (proactive) message to the room.
func (p *Platform) Send(ctx context.Context, replyCtx any, content string) error {
	rc, err := asReplyContext(replyCtx)
	if err != nil {
		return err

View on GitHub (pinned to 4000b2338a)

Solutions

  1. Always pass the replyCtx value received from the engine's message event back verbatim — never reconstruct it
  2. Ensure messages from other platforms are not routed to the Webex platform's Reply/Send
  3. Check engine routing logic for mixing reply contexts across platforms
  4. In tests, use the actual replyContext returned by the Webex platform rather than a hand-made value

Example fix

// before
p.Reply(ctx, someOtherPlatformCtx, "hi")
// after
if msg.Platform == "webex" {
    p.Reply(ctx, msg.ReplyContext, "hi")
}
Defensive patterns

Strategy: type-guard

Validate before calling

if _, ok := replyCtx.(webex.ReplyContext); !ok {
    return errors.New("reply context does not belong to webex platform")
}

Type guard

func isValidWebexReplyContext(v any) bool {
    _, ok := v.(webex.ReplyContext)
    return ok
}

Try / catch

if err := p.Reply(ctx, replyCtx, text); err != nil {
    if strings.Contains(err.Error(), "invalid reply context") {
        return fmt.Errorf("reply ctx not from webex; check routing: %w", err)
    }
    return err
}

Prevention

When it happens

Trigger: Calling Reply/Send/SendImage/SendFile with a replyCtx value captured from a different platform's message, a nil value, or an altered/reconstructed value that is not of type replyContext.

Common situations: Routing engine bug forwarding another platform's reply context to the Webex platform; storing a reply context, restarting with a different platform type, then replying; tests passing a raw string/struct instead of the value obtained from ReceiveMessage.

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/6245c840d1e64356. Report an issue: GitHub.