vectordotdev/vector · error
stream must exist
Error message
stream must exist
What it means
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.
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.
Defensive patterns
Strategy: fallback
Try / catch
// auto-restart on the rare internal panic [Service] Restart=on-failure
Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Understand the failure class
Background: "This is a bug, please report it": internal invariant violations, unreachable panics, and SNH errors explained — this error's family across 47 libraries.
Related errors
- static
- a record with a next ID must have an event count
- a validated HTTP endpoint is a valid `http 1` URI
- building HTTP request failed unexpectedly
- Building request never fails.
AI-assisted analysis of vectordotdev/vector@bdb87aeaa4 (2026-09-16).
Data as JSON: /api/errors/010a7aedd5b53548.
Report an issue: GitHub.
Appendix: source
Thrown at src/sinks/loki/event.rs:121
})
.collect();
escaped.push(',');
escaped
})
.collect();
if !res.stream_by_labels.contains_key(&labels) {
res.stream_by_labels.insert(
labels.clone(),
LokiStream {
stream: item.labels.into_iter().collect(),
values: Vec::new(),
},
);
}
let stream = res
.stream_by_labels
.get_mut(&labels)
.expect("stream must exist");
stream.values.push(item.event);
res
});
for (_k, stream) in result.stream_by_labels.iter_mut() {
stream.values.sort_by_key(|e| e.timestamp);
}
result
}
}
#[derive(Clone, Debug)]
pub struct LokiEvent {
pub timestamp: i64,
pub event: Bytes,
pub structured_metadata: StructuredMetadata,
}
impl ByteSizeOf for LokiEvent {View on GitHub (pinned to bdb87aeaa4)