perf(hive-claude): match rate-limit markers on raw line, drop re-serialize
This commit is contained in:
parent
487e62a9ca
commit
f6977a961a
2 changed files with 7 additions and 6 deletions
|
|
@ -65,12 +65,13 @@ impl Sentinels {
|
|||
}
|
||||
}
|
||||
|
||||
/// Trust a rate-limit hit on a JSON `error` event's serialized form.
|
||||
pub(crate) fn scan_stdout_json(&self, event: &serde_json::Value) {
|
||||
/// Trust a rate-limit hit only on a JSON `error` event (so a model
|
||||
/// *discussing* a rate limit in prose can't trigger it). The `type` gate
|
||||
/// needs the parsed `event`; the marker match runs on `raw`, the original
|
||||
/// line — the same bytes, so we don't re-serialize the value.
|
||||
pub(crate) fn scan_stdout_json(&self, event: &serde_json::Value, raw: &str) {
|
||||
if event.get("type").and_then(|t| t.as_str()) == Some("error")
|
||||
&& RATE_LIMIT_MARKERS
|
||||
.iter()
|
||||
.any(|m| event.to_string().contains(m))
|
||||
&& RATE_LIMIT_MARKERS.iter().any(|m| raw.contains(m))
|
||||
{
|
||||
self.rate_limited.store(true, Ordering::Relaxed);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ async fn pump_stdout(stdout: ChildStdout, sink: &impl Sink, sentinels: &Sentinel
|
|||
while let Ok(Some(line)) = lines.next_line().await {
|
||||
sentinels.scan_line(&line);
|
||||
if let Ok(event) = serde_json::from_str::<serde_json::Value>(&line) {
|
||||
sentinels.scan_stdout_json(&event);
|
||||
sentinels.scan_stdout_json(&event, &line);
|
||||
sink.on_event(&event);
|
||||
} else {
|
||||
sentinels.scan_rate_limit_text(&line);
|
||||
|
|
|
|||
Loading…
Reference in a new issue