fix(xiaoyi): reuse the verified route at output handoff

This commit is contained in:
WuYongJie 2026-11-26 04:58:49 +08:00
parent a891310b54
commit 5216332cbf
3 changed files with 56 additions and 3 deletions

View File

@ -119,7 +119,8 @@ export async function runSession(config, call, sharedBroker, recovery, signal) {
broker=sharedBroker??new Native98kBroker(bindingConfig);
broker.bind(bindingConfig);
const brokerStartedAt = performance.now();
const info = await broker.info(config.mode==='recover'?{original:true,id:config.productionOriginals?.[0]}:undefined);
const info = await broker.info(config.mode==='recover'?{original:true,id:config.productionOriginals?.[0]}
:productionGoal&&!config.goalUserEntry?{reuseDetailSelection:true}:undefined);
const brokerReadyAt = performance.now();
if (info.accountScope !== config.scope) throw Error('账户已切换,未发送请求');
let binding;

View File

@ -694,6 +694,15 @@ fn verified_detail_model(record: &Value, input: &Value, settings: &Value, scope:
.then(|| model.clone())
}
fn continue_detail_selection(current: Option<&Selection>, record: &Value, settings: &Value, scope: &str) -> Option<(Value, Value, String)> {
let (selected_scope, role, selected_settings, model, invocation) = current?;
if selected_scope != scope || role != "detail" || selected_settings != settings
|| record["scope"] != scope || record["model"] != *model || record["headers"] != invocation["headers"] {
return None;
}
Some((model.clone(), invocation.clone(), uuid(record, "id").ok()?))
}
fn dispatch(input: Value, shared_http: &mut Option<NetworkClient>, selection: &mut Option<Selection>, new_request_preflight: &mut bool) -> R<()> {
let project = uuid(&input, "project")?;
let root = crate::services::config_dir().ok_or("本机配置目录不可用")?.join("jiansun");
@ -730,10 +739,23 @@ fn dispatch(input: Value, shared_http: &mut Option<NetworkClient>, selection: &m
"origin":backend.origin,"model":original["model"],"pending":pending}}));
}
let role = input["modelRole"].as_str().unwrap_or("chat");
let (settings, mut model, invocation, selection_timings) = selected(&mut backend, role)?;
let continuation = if role == "detail" && input["reuseDetailSelection"] == true {
let settings = backend.settings()?;
read_task(&selection_file).ok()
.and_then(|record| continue_detail_selection(selection.as_ref(), &record, &settings, &backend.scope()))
.map(|(model, invocation, id)| (settings, model, invocation, json!({"source":"run"}), Some(id)))
} else { None };
let (settings, mut model, invocation, selection_timings, continuing_id) = if let Some(continuation) = continuation {
continuation
} else {
let (settings, model, invocation, timings) = selected(&mut backend, role)?;
(settings, model, invocation, timings, None)
};
pi_runtime::apply_invocation_capacity(&mut model, &invocation)?;
let thinking = crate::jiansun_models::thinking_preference(&settings, &model).map(str::to_owned);
let selection_id = if role == "detail" {
let selection_id = if continuing_id.is_some() {
continuing_id
} else if role == "detail" {
settings["key"].as_str().and_then(|key| {
let id = Uuid::new_v4().to_string();
let record = json!({"id":id,"scope":backend.scope(),"choice":settings["model"],"keyFingerprint":hash(key),
@ -1077,6 +1099,27 @@ mod tests {
}
}
#[test]
fn next_output_can_reuse_previous_selection_only_while_the_same_route_is_valid() {
let id = Uuid::new_v4().to_string();
let settings = json!({"key":"fixture-key","model":"test-vision"});
let model = json!({"id":"test-vision","path":"/v1/responses","maxTokens":16384});
let route = json!({"X-Relay-Route-Option":Uuid::new_v4().to_string()});
let invocation = json!({"headers":route});
let record = json!({"id":id,"scope":"account","model":model,"headers":route});
let current = ("account".into(), "detail".into(), settings.clone(), model.clone(), invocation.clone());
assert_eq!(continue_detail_selection(Some(&current), &record, &settings, "account"),
Some((model, invocation, id)));
assert!(continue_detail_selection(None, &record, &settings, "account").is_none());
assert!(continue_detail_selection(Some(&current), &Value::Null, &settings, "account").is_none());
assert!(continue_detail_selection(Some(&current), &record, &settings, "other-account").is_none());
assert!(continue_detail_selection(Some(&current), &record,
&json!({"key":"rotated-key","model":"test-vision"}), "account").is_none());
let mut moved_route = record.clone();
moved_route["headers"] = json!({});
assert!(continue_detail_selection(Some(&current), &moved_route, &settings, "account").is_none());
}
#[test]
fn rpc_error_frame_preserves_safe_categories_without_leaking_raw_errors() {
use super::*;

View File

@ -593,3 +593,12 @@ R9 详情页原请求 `6c9f6c53-334e-4164-aa19-7d510d45e734` 返回 HTTP 503 和
纯推理的未知回执交由调用方保留原记录及 Pi 的原始错误类型,使用 Pi SDK 已有设置决定是否重试。进程内待核查集合只追踪须保留的副作用类调用。付费生图、确认原操作及写画布的原编号处理保持现有契约。
从小壹的生产入口用 Responses 合成 HTTP 503,验证 Pi 在同一目标上按默认退避重试,拿到完整函数回执后执行一次工具;隔离的未知非推理调用保持不可重发。三项定向、263 项 Node 回归通过,见 `batch-09/native-503-pi-retry-targeted.log`、`native-503-pi-retry-npm.log`。当前 R9 仍使用启动前的构建。
### 主图和 SKU 沿用本轮已验证的模型线路
R8 在 SKU 交接时重新请求账户与目录,在原生 TLS 握手失败后留下草稿。此前详情和主图模型使用同一已验证线路。实机原始证据见 `batch-09/desk-verified-route-r8/network-termination-evidence.json`。
同一个生产守护进程交接下一输出时,继续使用此前验证的设置、模型线路和选择编号。选择记录与当前账户、项目目录、设置和请求头一致时,跳过重复的联网核对。首次进入、设置或路由变化、401/403 使原选择失效、进程重启时,按正常联网核对路径继续。读原请求的处理独立。
定向覆盖继续交接成功、记录不存在、账户不同、更换 Key 和线路变更。34 项原生 Pi 桥回归通过,1 项目录夹具按原配置忽略。Windows 构建、263 项 Node 回归通过。证据为 `batch-09/stage-selection-reuse-targeted.log`、`stage-selection-native.log`、`stage-selection-build.log`、`stage-selection-npm.log`。下一实机读取每次交接的启动回执,核对选路来源及实际耗时。