xai-org/x-algorithm · error
Not implemented: to_thrift for KeywordMatch
Error message
Not implemented: to_thrift for KeywordMatch
What it means
The MValCodec trait requires both from_thrift and to_thrift, but KeywordMatch only implements Thrift decoding (reading). Serialization was intentionally left unimplemented, so calling to_thrift on a KeywordMatch panics immediately. This is a developer-facing assertion that the type is decode-only in the visibility-filtering client.
Source
Thrown at visibility-filtering-client/models.rs:121
if field.field_type == TType::Stop {
break;
}
match field.id {
Some(1) => {
keyword = proto.read_string().unwrap();
}
_ => {
proto.skip(field.field_type).unwrap();
}
}
proto.read_field_end().unwrap();
}
proto.read_struct_end().unwrap();
KeywordMatch { keyword }
}
fn to_thrift(&self, _proto: &mut dyn TOutputProtocol) {
panic!("Not implemented: to_thrift for KeywordMatch")
}
}
impl MValCodec for SafetyResult {
fn thrift_type() -> TType {
TType::Struct
}
fn from_thrift(proto: &mut dyn TInputProtocol) -> Self {
proto.read_struct_begin().unwrap();
let mut reason: Option<SafetyResultReason> = None;
let mut action = Action::default();
loop {
let field = proto.read_field_begin().unwrap();
if field.field_type == TType::Stop {
break;
}
match field.id {View on GitHub (pinned to 24c60942c5)
Solutions
- Stop calling to_thrift on KeywordMatch; this type is decode-only by design.
- If you own the model, implement to_thrift (mirror the field writes of the matching from_thrift reader, writing the 'keyword' string field).
- Convert to the protobuf type vf_pb::KeywordMatch (a From impl exists) and serialize that instead.
- If serialization is genuinely never needed, add a compile-time guard or code comment so generic encoders exclude decode-only types.
Example fix
// before
fn to_thrift(&self, _proto: &mut dyn TOutputProtocol) {
panic!("Not implemented: to_thrift for KeywordMatch")
}
// after
fn to_thrift(&self, proto: &mut dyn TOutputProtocol) {
let ident = TStructIdentifier::new("KeywordMatch");
proto.write_struct_begin(&ident).unwrap();
proto.write_field_begin(&TFieldIdentifier::new("keyword", TType::String, 1)).unwrap();
proto.write_string(&self.keyword).unwrap();
proto.write_field_end().unwrap();
proto.write_field_stop().unwrap();
proto.write_struct_end().unwrap();
} Defensive patterns
Strategy: type-guard
Type guard
// Trait-level capability split: only encode types that implement WriteCodec
trait WriteCodec { fn to_thrift(&self, p: &mut dyn TOutputProtocol); }
fn encode<T: WriteCodec>(v: &T, p: &mut dyn TOutputProtocol) { v.to_thrift(p); }
// KeywordMatch simply does not implement WriteCodec, so this call won't compile Try / catch
let r = std::panic::catch_unwind(|| m.to_thrift(proto));
if r.is_err() { /* fall back to vf_pb::KeywordMatch serialization */ } Prevention
- Split codec traits into read-only and write-only capabilities so encode-only/decode-only types are compile-time enforced.
- Keep round-trip codec tests parameterized by direction so they skip one-sided impls.
- Document decode-only types with rustdoc warnings.
When it happens
Trigger: Any code path that serializes a KeywordMatch to Thrift — e.g. writing it into an MVal (manhattan value) column, forwarding it over a Thrift RPC, or a generic codec function that calls to_thrift on MValCodec types. Also hit in tests that round-trip encode/decode.
Common situations: A new caller starts persisting KeywordMatch structs, a generic serializer iterates all MValCodec impls, or someone writes a round-trip unit test without noticing the encode side is unimplemented.
Related errors
- Not implemented: to_thrift for SafetyResult
- Not implemented: to_thrift for Action
- Not implemented: to_thrift for DropReason
- Not implemented: to_thrift for FilteredReason
- LookupContext should not be decoded from Thrift
AI-assisted analysis of xai-org/x-algorithm@24c60942c5 (2026-08-28).
Data as JSON: /api/errors/ff3cb6fdaa9986fb.
Report an issue: GitHub.