xai-org/x-algorithm · error

Not implemented: to_thrift for FilteredReason

Error message

Not implemented: to_thrift for FilteredReason

What it means

FilteredReason's MValCodec impl decodes Thrift but panics on to_thrift, marking it as decode-only. The panic is an explicit design statement, not a runtime failure of external systems.

Source

Thrown at visibility-filtering-client/models.rs:372

                    proto.read_bool().unwrap();
                    result = FilteredReason::TweetIsNullcast;
                }
                Some(16) => {
                    proto.read_bool().unwrap();
                    result = FilteredReason::ExclusiveTweet;
                }
                _ => {
                    proto.skip(field.field_type).unwrap();
                }
            }
            proto.read_field_end().unwrap();
        }
        proto.read_struct_end().unwrap();
        result
    }

    fn to_thrift(&self, _proto: &mut dyn TOutputProtocol) {
        panic!("Not implemented: to_thrift for FilteredReason")
    }
}

impl From<vf_pb::KeywordMatch> for KeywordMatch {
    fn from(value: vf_pb::KeywordMatch) -> Self {
        KeywordMatch {
            keyword: value.keyword,
        }
    }
}

impl From<KeywordMatch> for vf_pb::KeywordMatch {
    fn from(value: KeywordMatch) -> Self {
        vf_pb::KeywordMatch {
            keyword: value.keyword,
        }
    }
}

View on GitHub (pinned to 24c60942c5)

Solutions

  1. Do not encode FilteredReason.
  2. Implement to_thrift mirroring the field ids/order the from_thrift reader uses (the reader builds `result` field by field).
  3. Prefer the vf_pb protobuf conversion for any required serialization.

Example fix

// before
fn to_thrift(&self, _proto: &mut dyn TOutputProtocol) {
    panic!("Not implemented: to_thrift for FilteredReason")
}

// after
fn to_thrift(&self, proto: &mut dyn TOutputProtocol) {
    proto.write_struct_begin(&TStructIdentifier::new("FilteredReason")).unwrap();
    /* write each field with the same ids as the decoder */
    proto.write_field_stop().unwrap();
    proto.write_struct_end().unwrap();
}
Defensive patterns

Strategy: type-guard

Type guard

trait WriteCodec { fn to_thrift(&self, p: &mut dyn TOutputProtocol); }
fn encode<T: WriteCodec>(v: &T, p: &mut dyn TOutputProtocol) { v.to_thrift(p); }
// FilteredReason excluded -> compile-time safety

Try / catch

if std::panic::catch_unwind(|| fr.to_thrift(proto)).is_err() { /* serialize vf_pb equivalent */ }

Prevention

When it happens

Trigger: Serializing FilteredReason via MValCodec::to_thrift — outbound RPC payloads, mval persistence, or symmetric round-trip tests.

Common situations: New producers of FilteredReason; generic encoders that walk all codec impls; codec conformance test suites.

Related errors


AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28). Data as JSON: /api/errors/6b0d9e8f63cc9fa8. Report an issue: GitHub.