chenhg5/cc-connect · error
bridge: marshal reconstruct reply ctx: %w
Error message
bridge: marshal reconstruct reply ctx: %w
What it means
buildBridgeReconstructReplyCtx assembles a payload struct (sender project, transport chat ID, transport session key) and serializes it with json.Marshal. If marshalling fails — which for a struct of string fields should practically never happen — the error is wrapped with this message and returned from ReconstructReplyCtx.
Source
Thrown at core/bridge.go:456
}
return value, true
}
func buildBridgeReconstructReplyCtx(project, sessionKey string) (string, error) {
chatID, err := bridgeTransportChatID(sessionKey)
if err != nil {
return "", err
}
payload := bridgeReconstructReplyCtxPayload{
Kind: bridgeReconstructReplyCtxKind,
Version: 1,
SenderProject: project,
TransportChatID: chatID,
TransportSessionKey: sessionKey,
}
data, err := json.Marshal(payload)
if err != nil {
return "", fmt.Errorf("bridge: marshal reconstruct reply ctx: %w", err)
}
return string(data), nil
}
func bridgeTransportChatID(sessionKey string) (string, error) {
parts := strings.SplitN(sessionKey, ":", 3)
if len(parts) < 2 || parts[1] == "" {
return "", fmt.Errorf("bridge: invalid session key %q", sessionKey)
}
return parts[1], nil
}
func (bp *BridgePlatform) SendCard(ctx context.Context, replyCtx any, card *Card) error {
rc, ok := replyCtx.(*bridgeReplyCtx)
if !ok {
return fmt.Errorf("bridge: invalid reply context")
}
a := bp.server.getAdapter(rc.Platform)View on GitHub (pinned to 4000b2338a)
Solutions
- Inspect the wrapped %w error to identify the unsupported type reported by encoding/json.
- Ensure all fields of the reconstruct payload struct are JSON-serializable (strings, ints, etc.).
- Rebuild from a clean checkout of the pinned version to rule out local modifications.
Example fix
// before
type payload struct{ Extra chan struct{} `json:"extra"` } // not marshalable
// after
type payload struct{ Extra string `json:"extra"` } Defensive patterns
Strategy: try-catch
Try / catch
rc, err := bp.ReconstructReplyCtx(key)
if err != nil {
var me *json.MarshalTypeError
if errors.As(err, &me) { slog.Error("non-serializable payload field", "field", me.Field) }
return err
} Prevention
- Keep reconstruct payload structs limited to JSON-serializable field types.
- Add a unit test that marshals the payload struct.
- Avoid local forks adding exotic fields to bridge payloads.
When it happens
Trigger: json.Marshal returns an error while serializing the reconstruct payload; only realistic if a field carries an unsupported type (e.g. a channel/func value introduced by a custom build) or JSON marshalling is globally broken.
Common situations: Custom forks that added non-serializable fields to the payload struct; corrupted builds; extremely rare in stock usage.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- marshal Agy permission hook: %w
- marshal Agy hooks overlay: %w
- minimax tts: marshal request: %w
- parse existing Agy hooks %s: %w
- marshal stdin: %w
AI-assisted analysis of chenhg5/cc-connect@4000b2338a (2026-09-06).
Data as JSON: /api/errors/eff63d04566c2013.
Report an issue: GitHub.