{"record":{"id":"010a7aedd5b53548","repo":"vectordotdev/vector","slug":"stream-must-exist","errorCode":null,"errorMessage":"stream must exist","messagePattern":"stream must exist","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/sinks/loki/event.rs","lineNumber":121,"sourceCode":"                            })\n                            .collect();\n                        escaped.push(',');\n                        escaped\n                    })\n                    .collect();\n                if !res.stream_by_labels.contains_key(&labels) {\n                    res.stream_by_labels.insert(\n                        labels.clone(),\n                        LokiStream {\n                            stream: item.labels.into_iter().collect(),\n                            values: Vec::new(),\n                        },\n                    );\n                }\n                let stream = res\n                    .stream_by_labels\n                    .get_mut(&labels)\n                    .expect(\"stream must exist\");\n                stream.values.push(item.event);\n                res\n            });\n        for (_k, stream) in result.stream_by_labels.iter_mut() {\n            stream.values.sort_by_key(|e| e.timestamp);\n        }\n        result\n    }\n}\n\n#[derive(Clone, Debug)]\npub struct LokiEvent {\n    pub timestamp: i64,\n    pub event: Bytes,\n    pub structured_metadata: StructuredMetadata,\n}\n\nimpl ByteSizeOf for LokiEvent {","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/vectordotdev/vector/blob/bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013/src/sinks/loki/event.rs#L103-L139","documentation":"While building a Loki push request, events are grouped into streams keyed by their label set. The code inserts each new label set into stream_by_labels before mutating it, so a lookup miss at expect(\"stream must exist\") is an internal bookkeeping bug: the code that should have inserted the stream did not. It is not caused by user event data shapes.","triggerScenarios":"Building a Loki request where an event's computed labels key is not present in stream_by_labels even though the same pass inserted it — i.e., the labels value used for lookup differs from the one used for insertion (hashing/normalization mismatch between insert and get_mut).","commonSituations":"Effectively unreachable in stock Vector; would surface after code changes to label normalization or event partitioning in src/sinks/loki/event.rs, or with exotic label values exposing a hash/equality inconsistency.","solutions":["Rebuild Vector from an unmodified source tree to rule out local patches to Loki event handling.","Check for abnormal label characters in events (use label drop/structured metadata settings) and sanitize event labels via VRL.","Upgrade Vector; if reproducible on stock builds, file a bug with the offending events."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"// auto-restart on the rare internal panic\n[Service]\nRestart=on-failure","preventionTips":["Sanitize label values with VRL before the loki sink.","Use stock Vector builds (avoid patching loki event partitioning).","Report reproducible cases upstream with sample events."],"tags":["rust","panic","loki","sink","invariant"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bdb87aeaa4c4ff27c0ba643c1c77b21bf2ef4013","analyzedAt":"2026-09-16T02:53:35.741Z","contentChangedAt":"2026-09-16T02:53:35.741Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}