feat(retry): B24 冷却扩围到「不回包/解密失败成片」两形
连接层冷却只认「会话没建立」,而现网 B26 的成片失败是连接已建立的两种形状: 对端在给出响应前收连接、HTTP 200 里行级结论带解密失败。给冷却表加第二条 证据道(同 host 分格、同窗长、同阈值 2),品牌客户端把两形都记进这条道: 不回包按异常即时记证;解密形状先批内开票,批终态只在零可结算结论时按票 记证——一枚干净结论就整票作废,脏品牌名的行级差异证据面保持不变。 冷却期快失败沿用既有整批分支,归因文案单独一条以便交付侧与取证区分。
This commit is contained in:
@@ -23,6 +23,14 @@ import java.util.concurrent.atomic.AtomicLong;
|
||||
* {@link #recordConnectFailure}(返回 true 的那方打一条进入冷却的 warn);
|
||||
* 连接成功或"连上了没答好"(读超时/5xx/解析失败)记 {@link #recordConnected} 清零证据。
|
||||
* 窗长 {@code <= 0} 表示关闭冷却,全部方法退化为无操作——调用方退回各自的调用内短路行为。
|
||||
*
|
||||
* <p>第二条证据道(B24 扩围,2026-10-26 拍板):{@link #recordNoAnswerFailure} 收的是
|
||||
* 「连接已建立、但对端没给出可结算的响应」——现网两个形状(BACKLOG B26):16890 卡死后
|
||||
* 在给出响应前收连接({@code header parser received no bytes}),以及 HTTP 200 里
|
||||
* {@code query_faild_data} 成片带解密失败。两形都按次即时记证:任何一次可结算结论
|
||||
* (干净返回/命中侵权/余额不足)都把证据清零,脏品牌名混在好品牌里永远攒不满两条。
|
||||
* no-answer 道与 connect 道分账:{@link #recordConnected} 只清 connect 证据,
|
||||
* no-answer 证据由 {@link #clearNoAnswerEvidence} 在调用方自己的批次语义里清。
|
||||
*/
|
||||
@Component
|
||||
public class UnreachableCooldown {
|
||||
@@ -38,6 +46,8 @@ public class UnreachableCooldown {
|
||||
private static final class State {
|
||||
final AtomicInteger evidence = new AtomicInteger();
|
||||
final AtomicLong cooldownUntilMillis = new AtomicLong();
|
||||
final AtomicInteger noAnswerEvidence = new AtomicInteger();
|
||||
final AtomicLong noAnswerCooldownUntilMillis = new AtomicLong();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -56,13 +66,31 @@ public class UnreachableCooldown {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** 该 host 是否正处冷却窗内:true 时调用方不发请求,直接按既有不可达归因文案快速失败。 */
|
||||
/** 该 host 是否正处冷却窗内(connect 道或 no-answer 道任一):true 时调用方不发请求,直接按既有不可达归因文案快速失败。 */
|
||||
public boolean isCoolingDown(String host, long windowMillis) {
|
||||
return connectLaneCooling(host, windowMillis) || noAnswerLaneCooling(host, windowMillis);
|
||||
}
|
||||
|
||||
/** 只问 connect 道:品牌客户端据此在两条快失败分支里选归因文案;两道的窗口径一致。 */
|
||||
public boolean connectLaneCooling(String host, long windowMillis) {
|
||||
return laneCooling(host, windowMillis, true);
|
||||
}
|
||||
|
||||
/** 只问 no-answer 道(B24 扩围):品牌客户端据此选用「不回包/解密成片」的归因文案。 */
|
||||
public boolean noAnswerLaneCooling(String host, long windowMillis) {
|
||||
return laneCooling(host, windowMillis, false);
|
||||
}
|
||||
|
||||
private boolean laneCooling(String host, long windowMillis, boolean connectLane) {
|
||||
if (windowMillis <= 0) {
|
||||
return false;
|
||||
}
|
||||
State state = states.get(normalizeHost(host));
|
||||
return state != null && state.cooldownUntilMillis.get() > System.currentTimeMillis();
|
||||
if (state == null) {
|
||||
return false;
|
||||
}
|
||||
AtomicLong until = connectLane ? state.cooldownUntilMillis : state.noAnswerCooldownUntilMillis;
|
||||
return until.get() > System.currentTimeMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,22 +100,37 @@ public class UnreachableCooldown {
|
||||
* 调用方据此打一条进入冷却的 warn,期中快失败不刷屏
|
||||
*/
|
||||
public boolean recordConnectFailure(String host, long windowMillis) {
|
||||
return openWindow(host, windowMillis, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* no-answer 道证据 +1(B24 扩围):形状由调用方判定——异常侧认「对端在给出响应前
|
||||
* 关闭连接」,响应侧认「行级结论带解密失败」。窗长/阈值/到期语义与 connect 道同款
|
||||
* (同格到期一次失败即重进)。
|
||||
*/
|
||||
public boolean recordNoAnswerFailure(String host, long windowMillis) {
|
||||
return openWindow(host, windowMillis, false);
|
||||
}
|
||||
|
||||
private boolean openWindow(String host, long windowMillis, boolean connectLane) {
|
||||
if (windowMillis <= 0) {
|
||||
return false;
|
||||
}
|
||||
State state = states.computeIfAbsent(normalizeHost(host), key -> new State());
|
||||
if (state.evidence.incrementAndGet() < EVIDENCE_THRESHOLD) {
|
||||
AtomicInteger evidence = connectLane ? state.evidence : state.noAnswerEvidence;
|
||||
if (evidence.incrementAndGet() < EVIDENCE_THRESHOLD) {
|
||||
return false;
|
||||
}
|
||||
long now = System.currentTimeMillis();
|
||||
long previous = state.cooldownUntilMillis.get();
|
||||
AtomicLong until = connectLane ? state.cooldownUntilMillis : state.noAnswerCooldownUntilMillis;
|
||||
long previous = until.get();
|
||||
if (previous > now) {
|
||||
return false;
|
||||
}
|
||||
return state.cooldownUntilMillis.compareAndSet(previous, now + windowMillis);
|
||||
return until.compareAndSet(previous, now + windowMillis);
|
||||
}
|
||||
|
||||
/** 连接成功或"连上了没答好":证据清零(已开的冷却窗不受影响,等它自然到期)。 */
|
||||
/** 连接成功或"连上了没答好":connect 道证据清零(已开的冷却窗不受影响,等它自然到期)。 */
|
||||
public void recordConnected(String host) {
|
||||
State state = states.get(normalizeHost(host));
|
||||
if (state != null) {
|
||||
@@ -95,6 +138,14 @@ public class UnreachableCooldown {
|
||||
}
|
||||
}
|
||||
|
||||
/** no-answer 道证据清零:批次里出现任何一次可结算结论即「服务活着」,重新攒两次证据。 */
|
||||
public void clearNoAnswerEvidence(String host) {
|
||||
State state = states.get(normalizeHost(host));
|
||||
if (state != null) {
|
||||
state.noAnswerEvidence.set(0);
|
||||
}
|
||||
}
|
||||
|
||||
/** host 归一:两个 LLM 客户端配的同一网关必须落进同一格,别因尾斜杠/大小写裂成两份。 */
|
||||
static String normalizeHost(String host) {
|
||||
String normalized = host == null ? "" : host.trim().toLowerCase();
|
||||
|
||||
Reference in New Issue
Block a user