智慧模式實測:真迴圈整合測試 4 條+模型同步
- smart_mode_runs_a_work_step_nobody_answered: 沒回的卡片逾時自動放行,步驟結果寫明 - smart_mode_scope_grant_asks_once_per_turn: 「這輪都准」一輪一決定,第二張卡不出现 - smart_mode_never_answers_a_must_ask_card: 一律詢問規則的卡再短的逾時也不会被自动回答 - the_reviewer_answers_the_same_step_once_per_turn: 重复步骤只付一次审核模型调用 - verify-approval-routing: 对过 brain.answer/desk.approval_body 改动,模型假设成立,rehash (AllSurfaces 通过、CanAnswer 如预期、replay 10 条全过) 已驗證: cargo test 全綠 720;verify-approval-routing run.sh 全绿(同步 commit)
This commit is contained in:
parent
20580e5255
commit
9ca5434747
|
|
@ -1,12 +1,12 @@
|
||||||
# 模型對照的程式碼段落(drift.py 讀這個檔)。欄位用 tab 分開:id 檔案 種類 開始 結束 sha256
|
# 模型對照的程式碼段落(drift.py 讀這個檔)。欄位用 tab 分開:id 檔案 種類 開始 結束 sha256
|
||||||
# sha256 是上次確認「模型還描述這段程式」時的內容。只有對過 SKILL.md 的對照表之後,才用 drift.py --rehash 更新。
|
# sha256 是上次確認「模型還描述這段程式」時的內容。只有對過 SKILL.md 的對照表之後,才用 drift.py --rehash 更新。
|
||||||
desk.approval_body src/app.rs block ^ fn approval_body\( } 42809de459f19bfa7abbb0b080144c8d04ae98242a5c93d4b721be19671b9830
|
desk.approval_body src/app.rs block ^ fn approval_body\( } dedd78f24a6a923ebee819f17cbde8d2d91ce9803e5e4dfad81b52c01d316c51
|
||||||
desk.approval_dock src/app.rs block ^ fn approval_dock\( } cda918bb255c4533d2d116736aaeb10aa2b9477b6c2858f1698b81b6dcef8794
|
desk.approval_dock src/app.rs block ^ fn approval_dock\( } cda918bb255c4533d2d116736aaeb10aa2b9477b6c2858f1698b81b6dcef8794
|
||||||
brain.need_approval src/app.rs block ^ if let StreamEvent::NeedApproval\(a\) = ev \{ } 5d62c439986d0e2ee6d0f28b3cbaf28fca8688c0c60395d86e77a77a35bd55ec
|
brain.need_approval src/app.rs block ^ if let StreamEvent::NeedApproval\(a\) = ev \{ } 5d62c439986d0e2ee6d0f28b3cbaf28fca8688c0c60395d86e77a77a35bd55ec
|
||||||
brain.on_new_approval src/app.rs block ^ fn on_new_approval\( } c110c0341ae1b8cbcc59d0b4dc1dba7a2b8006885837e515ea6c0ef23a195205
|
brain.on_new_approval src/app.rs block ^ fn on_new_approval\( } c110c0341ae1b8cbcc59d0b4dc1dba7a2b8006885837e515ea6c0ef23a195205
|
||||||
brain.new_approval_keyed src/app.rs block ^ fn new_approval_keyed\( } cfba6b7d4b08bc0a2d46363f5ff27205cf0c49c3a80f0cf4673c9546ab99f34d
|
brain.new_approval_keyed src/app.rs block ^ fn new_approval_keyed\( } cfba6b7d4b08bc0a2d46363f5ff27205cf0c49c3a80f0cf4673c9546ab99f34d
|
||||||
brain.notice_answers src/app.rs block ^fn notice_answers\( } a846a5e243978060ff4810ced82a064820da0966634bb9e730a14e6a5b303400
|
brain.notice_answers src/app.rs block ^fn notice_answers\( } a846a5e243978060ff4810ced82a064820da0966634bb9e730a14e6a5b303400
|
||||||
brain.answer src/app.rs block ^ fn answer\(&mut self, ctx: &egui::Context, bot_id: u64, answer: ApprovalAnswer\) } 192102f8e18c5859f58b3fb89acf5faffcd5339603f7e7ec3ab47aaf94c52cfd
|
brain.answer src/app.rs block ^ fn answer\(&mut self, ctx: &egui::Context, bot_id: u64, answer: ApprovalAnswer\) } 8e3ecb15b9d63de8c344165becc611fe8aa5ba1b843b8579922112eb8e1fade2
|
||||||
brain.stop src/app.rs block ^ fn stop\(&mut self, bot_id: u64\) } c7b8144a99b5cd03d37dd34ca1745dca693d4f2f0197a51d29dfb71b3e770f4f
|
brain.stop src/app.rs block ^ fn stop\(&mut self, bot_id: u64\) } c7b8144a99b5cd03d37dd34ca1745dca693d4f2f0197a51d29dfb71b3e770f4f
|
||||||
brain.watchdog src/app.rs block ^ fn watchdog\(&mut self\) } 50af66bd5a7f254e4400edb2f0fedc550465a43ac0d9fce155e5353c8d4ae336
|
brain.watchdog src/app.rs block ^ fn watchdog\(&mut self\) } 50af66bd5a7f254e4400edb2f0fedc550465a43ac0d9fce155e5353c8d4ae336
|
||||||
brain.cmd_answer src/app/remote_ui.rs block ^ Cmd::Answer \{ bot, answer, text, call, notice, screen \} => \{ } 8100f28ea03fedbd4cd58f988c5d32be2761151349110b134dcfb54d61a4e482
|
brain.cmd_answer src/app/remote_ui.rs block ^ Cmd::Answer \{ bot, answer, text, call, notice, screen \} => \{ } 8100f28ea03fedbd4cd58f988c5d32be2761151349110b134dcfb54d61a4e482
|
||||||
|
|
|
||||||
|
Can't render this file because it has a wrong number of fields in line 2.
|
122
src/agent.rs
122
src/agent.rs
|
|
@ -5559,6 +5559,128 @@ echo '<meta charset=utf-8><title>done</title>送出了' > done.html; (setsid pyt
|
||||||
assert_eq!(seen.lock().unwrap().len(), 3);
|
assert_eq!(seen.lock().unwrap().len(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn smart_job(port: u16, history: Vec<Message>, review: Option<Review>, timeout: Duration, smart_on: bool) -> Job {
|
||||||
|
let w = std::env::temp_dir().join(format!("anybot-smart-{}-{}", std::process::id(), port));
|
||||||
|
let _ = std::fs::remove_dir_all(&w);
|
||||||
|
std::fs::create_dir_all(&w).unwrap();
|
||||||
|
Job {
|
||||||
|
req: ChatRequest { kind: ProviderKind::Custom, base_url: format!("http://127.0.0.1:{port}/v1"), api_key: String::new(), model: "m".into(), system: String::new(), history, tools: tools::specs(), session: String::new(), effort: String::new() },
|
||||||
|
computers: vec![tools::Target { name: crate::model::THIS_COMPUTER_NAME.into(), place: tools::Place::Local { workdir: w } }],
|
||||||
|
default_computer: crate::model::THIS_COMPUTER_NAME.into(),
|
||||||
|
roles: tools::Roles { own: crate::model::BOT_COMPUTER_NAME.into(), person: Some(crate::model::THIS_COMPUTER_NAME.into()), server: false },
|
||||||
|
local_execution: true,
|
||||||
|
smart: if smart_on { crate::smart::Smart::on(timeout) } else { crate::smart::Smart::off() },
|
||||||
|
review,
|
||||||
|
op: "smart-test".into(),
|
||||||
|
..test_job()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Smart mode (autonomy-smart): a work-tier step nobody answers goes ahead after the
|
||||||
|
/// timeout, and the step's result says so in words.
|
||||||
|
#[test]
|
||||||
|
fn smart_mode_runs_a_work_step_nobody_answered() {
|
||||||
|
let (port, _) = fake_http(vec![sse_call("c1", "shell", serde_json::json!({"command": "sleep 1 && echo hi"})), sse_text("做好了")]);
|
||||||
|
let job = smart_job(port, vec![Message::user("做 s1.txt")], None, Duration::from_secs(1), true);
|
||||||
|
let (tx, rx) = channel();
|
||||||
|
spawn(job, 1, tx, Arc::new(AtomicBool::new(false)), eframe::egui::Context::default());
|
||||||
|
let (mut asked, mut results, mut held) = (0, vec![], vec![]);
|
||||||
|
loop {
|
||||||
|
match rx.recv_timeout(Duration::from_secs(20)).expect("loop stalled") {
|
||||||
|
(_, StreamEvent::NeedApproval(a)) => { asked += 1; held.push(a.reply); /* the card stays open, nobody answers */ }
|
||||||
|
(_, StreamEvent::ToolResult(m)) => results.push(m.text.clone()),
|
||||||
|
(_, StreamEvent::Done) => break,
|
||||||
|
(_, StreamEvent::Error(e)) => panic!("{e}"),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert_eq!(asked, 1, "the step did ask once");
|
||||||
|
assert!(results.iter().any(|r| r.contains("hi") && r.contains("沒有人回應") && r.contains("先做了")), "{results:?}");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Smart mode's 「這輪都准」: answering the first card with a scope grant runs that step
|
||||||
|
/// and stops asking for the same grant for the rest of the turn — no second card.
|
||||||
|
#[test]
|
||||||
|
fn smart_mode_scope_grant_asks_once_per_turn() {
|
||||||
|
let (port, _) = fake_http(vec![
|
||||||
|
sse_call("c1", "shell", serde_json::json!({"command": "sleep 1 && echo one"})),
|
||||||
|
sse_call("c2", "shell", serde_json::json!({"command": "sleep 1 && echo two"})),
|
||||||
|
sse_text("做好了"),
|
||||||
|
]);
|
||||||
|
let job = smart_job(port, vec![Message::user("做兩個檔案")], None, Duration::from_secs(300), true);
|
||||||
|
let (tx, rx) = channel();
|
||||||
|
spawn(job, 1, tx, Arc::new(AtomicBool::new(false)), eframe::egui::Context::default());
|
||||||
|
let (mut asked, mut results) = (0, vec![]);
|
||||||
|
loop {
|
||||||
|
match rx.recv_timeout(Duration::from_secs(20)).expect("loop stalled") {
|
||||||
|
(_, StreamEvent::NeedApproval(a)) => { asked += 1; eprintln!("CARD {} reason={:?} grant={:?}", asked, a.reason, a.grant); assert_eq!(a.grant, "shell:sleep"); let _ = a.reply.send(ApprovalAnswer::Scope(a.grant.clone())); }
|
||||||
|
(_, StreamEvent::ToolResult(m)) => results.push(m.text.clone()),
|
||||||
|
(_, StreamEvent::Done) => break,
|
||||||
|
(_, StreamEvent::Error(e)) => panic!("{e}"),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert_eq!(asked, 1, "one decision per turn, not one per step: {asked}");
|
||||||
|
assert_eq!(results.len(), 2, "{results:?}");
|
||||||
|
assert!(results.iter().all(|r| !r.contains("逾時")), "answering is not timing out: {results:?}");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Smart mode never answers a card that must ask (autonomy-still-asks): a 「一律詢問」
|
||||||
|
/// rule's card waits for the person however short the smart timeout is — and when the
|
||||||
|
/// person finally answers, it runs with no auto-run note.
|
||||||
|
#[test]
|
||||||
|
fn smart_mode_never_answers_a_must_ask_card() {
|
||||||
|
let (port, _) = fake_http(vec![sse_call("c1", "shell", serde_json::json!({"command": "sleep 1 && echo xyz"})), sse_text("做好了")]);
|
||||||
|
let review = Review { allow: vec![], ask: vec!["tool(shell*)".into()] };
|
||||||
|
let job = smart_job(port, vec![Message::user("做 s3.txt")], Some(review), Duration::from_millis(300), true);
|
||||||
|
let (tx, rx) = channel();
|
||||||
|
spawn(job, 1, tx, Arc::new(AtomicBool::new(false)), eframe::egui::Context::default());
|
||||||
|
let (mut asked, mut results) = (0, vec![]);
|
||||||
|
loop {
|
||||||
|
match rx.recv_timeout(Duration::from_secs(20)).expect("loop stalled") {
|
||||||
|
(_, StreamEvent::NeedApproval(a)) => {
|
||||||
|
asked += 1;
|
||||||
|
std::thread::sleep(Duration::from_millis(900)); // longer than the smart timeout
|
||||||
|
let _ = a.reply.send(ApprovalAnswer::Once);
|
||||||
|
}
|
||||||
|
(_, StreamEvent::ToolResult(m)) => results.push(m.text.clone()),
|
||||||
|
(_, StreamEvent::Done) => break,
|
||||||
|
(_, StreamEvent::Error(e)) => panic!("{e}"),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert_eq!(asked, 1);
|
||||||
|
assert!(results.iter().any(|r| r.contains("xyz")), "{results:?}");
|
||||||
|
assert!(results.iter().all(|r| !r.contains("逾時") && !r.contains("自動放行") && !r.contains("自動拒絕")), "the card waited for the person: {results:?}");
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The reviewer's verdict is asked once per turn for the same step: repeated steps pay
|
||||||
|
/// one model call, not one per step (the hot path's per-step stall, cut).
|
||||||
|
#[test]
|
||||||
|
fn the_reviewer_answers_the_same_step_once_per_turn() {
|
||||||
|
let (port, seen) = fake_http(vec![
|
||||||
|
sse_call("c1", "shell", serde_json::json!({"command": "sleep 1 && echo r"})),
|
||||||
|
sse_text(r#"{"verdict":"ask","rule":"用我的帳號做事前先問我"}"#),
|
||||||
|
sse_call("c2", "shell", serde_json::json!({"command": "sleep 1 && echo r"})),
|
||||||
|
sse_text("做好了"),
|
||||||
|
]);
|
||||||
|
let review = Review { allow: vec![], ask: vec!["用我的帳號做事前先問我".into()] };
|
||||||
|
let job = smart_job(port, vec![Message::user("做 s4.txt 兩次")], Some(review), Duration::from_secs(300), false);
|
||||||
|
let job = Job { direct: Arc::new(AtomicBool::new(true)), ..job };
|
||||||
|
let (tx, rx) = channel();
|
||||||
|
spawn(job, 1, tx, Arc::new(AtomicBool::new(false)), eframe::egui::Context::default());
|
||||||
|
loop {
|
||||||
|
match rx.recv_timeout(Duration::from_secs(20)).expect("loop stalled") {
|
||||||
|
(_, StreamEvent::NeedApproval(a)) => { let _ = a.reply.send(ApprovalAnswer::Once); }
|
||||||
|
(_, StreamEvent::Done) => break,
|
||||||
|
(_, StreamEvent::Error(e)) => panic!("{e}"),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let calls = seen.lock().unwrap().len();
|
||||||
|
assert_eq!(calls, 4, "3 turn calls + ONE review call for the repeated step, not two: {calls}");
|
||||||
|
}
|
||||||
|
|
||||||
/// The work log while a turn runs: the turn and its model call are written first; a step
|
/// The work log while a turn runs: the turn and its model call are written first; a step
|
||||||
/// waiting for the person isn't "started"; once allowed it is (with the arguments it runs
|
/// waiting for the person isn't "started"; once allowed it is (with the arguments it runs
|
||||||
/// with), then finished; a finished turn leaves no file. A stopped turn ends as stopped.
|
/// with), then finished; a finished turn leaves no file. A stopped turn ends as stopped.
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,11 @@ pub struct Smart {
|
||||||
|
|
||||||
impl Smart {
|
impl Smart {
|
||||||
/// Off, and never turns on (tests, untrusted turns).
|
/// Off, and never turns on (tests, untrusted turns).
|
||||||
|
/// 開著,用預設逾時。
|
||||||
|
pub fn on(timeout: Duration) -> Smart {
|
||||||
|
Self { on: Arc::new(AtomicBool::new(true)), timeout, scopes: std::cell::RefCell::new(vec![]), reviews: std::cell::RefCell::new(std::collections::HashMap::new()) }
|
||||||
|
}
|
||||||
|
|
||||||
pub fn off() -> Smart {
|
pub fn off() -> Smart {
|
||||||
Smart::default()
|
Smart::default()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue