You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e7a5d7b
Browse filesBrowse the repository at this point in the historyBrowse files
Eva
committed
fix(agent): retry LLM completion on malformed 2xx JSON body
A provider that returns HTTP 200 with a truncated JSON document (cleanly
closed, framing intact, content cut off mid-value) previously died on the
first attempt with a terminal AgentError::Llm("json: EOF while parsing a
value"), killing the agent turn before it produced anything. Observed
live: deepseek via OpenRouter returned a truncated body in a tb21 bench
trial and the agent exited with 0 turns (code -32000 at the ACP surface).
Treat an unparseable success body like a 5xx in both HTTP loops (shared
post() and openrouter_post()): retry under the existing MAX_RETRIES bound
with the same backoff_with_jitter, and surface terminal_llm_error with
the json parse detail when retries are exhausted.
Tool-safety: the retry lives entirely inside the HTTP POST helpers,
before any parsed response value exists. Tool calls are only ever
extracted from a successfully parsed response; a malformed body produced
none, so nothing downstream of it could have dispatched. The retry
re-sends the identical request bytes captured at function entry — an LLM
completion request, which executes no tools. No tool call can be
re-run by this change.
Co-authored-by: Eva <011987e296fd5006292d2f930b574be47c7801048d1983c46c425d3c95f0cffd@buzz.block.builderlab.xyz>
Signed-off-by: Eva <011987e296fd5006292d2f930b574be47c7801048d1983c46c425d3c95f0cffd@buzz.block.builderlab.xyz>
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
4859
+
let url = format!("http://{}/v1/x", listener.local_addr().unwrap());
4860
+
let accepts = Arc::new(AtomicU32::new(0));
4861
+
let accepts_srv = accepts.clone();
4862
+
4863
+
tokio::spawn(asyncmove{
4864
+
loop{
4865
+
let(mut sock, _) = match listener.accept().await{
4866
+
Ok(p) => p,
4867
+
Err(_) => return,
4868
+
};
4869
+
let n = accepts_srv.fetch_add(1,Ordering::SeqCst);
4870
+
letmut buf = Vec::new();
4871
+
letmut tmp = [0u8;4096];
4872
+
while !buf.windows(4).any(|w| w == b"\r\n\r\n"){
4873
+
match sock.read(&mut tmp).await{
4874
+
Ok(0) | Err(_) => return,
4875
+
Ok(k) => buf.extend_from_slice(&tmp[..k]),
4876
+
}
4877
+
}
4878
+
if n == 0{
4879
+
// First attempt: 200 OK with a truncated JSON document.
4880
+
// Content-Length matches the bytes actually sent, so the
4881
+
// body read completes cleanly — the fault is purely that
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
4940
+
let url = format!("http://{}/v1/x", listener.local_addr().unwrap());
let listener = TcpListener::bind("127.0.0.1:0").await.unwrap();
5016
+
let url = format!("http://{}/v1/x", listener.local_addr().unwrap());
5017
+
let accepts = Arc::new(AtomicU32::new(0));
5018
+
let accepts_srv = accepts.clone();
5019
+
5020
+
tokio::spawn(asyncmove{
5021
+
loop{
5022
+
let(mut sock, _) = match listener.accept().await{
5023
+
Ok(p) => p,
5024
+
Err(_) => return,
5025
+
};
5026
+
let n = accepts_srv.fetch_add(1,Ordering::SeqCst);
0 commit comments