From 9a1d8dbbf7537688197b5423a62f196901e3db43 Mon Sep 17 00:00:00 2001 From: martbost Date: Fri, 21 Aug 2026 16:41:12 -0500 Subject: [PATCH] Translate: accept batch items individually so one malformed item cannot poison the rest; log partial parses --- server.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/server.js b/server.js index 9fffbad..7323d04 100644 --- a/server.js +++ b/server.js @@ -404,10 +404,14 @@ async function handleTranslate(req,res){ // parts: [lead, "1", text1, "2", text2, ...] const arr=[]; for(let k=1;k+1typeof x==='string'&&x.length)){ - miss.forEach((idx,j)=>{ const tr=String(arr[j]).slice(0,600); out[idx]=tr; cache[keyOf(texts[idx])]=tr; }); - trDirty=true; done=true; - } + // per-item acceptance: one malformed item must never poison its batch + let got=0; + miss.forEach((idx,j)=>{ + const tr=typeof arr[j]==='string'&&arr[j].length?String(arr[j]).slice(0,600):null; + if(tr){ out[idx]=tr; cache[keyOf(texts[idx])]=tr; got++; } + }); + if(got){ trDirty=true; done=true; } + if(got