fix: an hx error asks the user instead of taking the state's first catch
hx reports its own failures (API, login, ...) as blocked with reason "error" and no catch. orch then fell back to the state's first catch, so with code's ToolDenied = "review" a failed agent looked like "review ready" with no code written. Now the error lands in Needs-you; a reply runs the step again with the reply as hint. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
551e0efd7c
commit
db80d15ba2
2 files changed
+38
-8
No files matched your search
+36
-6
@@ -774,6 +774,18 @@ fn run_agent(cx: &mut Ctx, st: &State, step: &Step) -> Result<StepRes> {
|
|||||||
cx.ctl.stop_for_budget(format!("hx limit: {}", r.summary));
|
cx.ctl.stop_for_budget(format!("hx limit: {}", r.summary));
|
||||||
Err(Stopped.into())
|
Err(Stopped.into())
|
||||||
}
|
}
|
||||||
|
"blocked" if r.catch.is_none() && r.reason.as_deref() == Some("error") => {
|
||||||
|
// hx itself failed (API, login, ...): no catch fits, so ask instead of guessing one
|
||||||
|
let payload = json!({
|
||||||
|
"key": format!("{}/{}/error", st.name, step.name),
|
||||||
|
"state": st.name, "step": step.name, "title": "agent error",
|
||||||
|
"detail": format!("hx failed: {}. Fix the cause, then reply to run the step again (abort to give up)", r.summary),
|
||||||
|
});
|
||||||
|
let answer = ask(&cx.ctl, &cx.s.id, &st.name, "input", payload, true)?;
|
||||||
|
let reply = answer.strip_prefix("reply:").unwrap_or(&answer).trim();
|
||||||
|
hint = (!reply.is_empty()).then(|| reply.to_string());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
"blocked" => Ok(StepRes {
|
"blocked" => Ok(StepRes {
|
||||||
ok: false,
|
ok: false,
|
||||||
exit: None,
|
exit: None,
|
||||||
@@ -2178,17 +2190,35 @@ next = "done"
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn hx_blocked_with_another_reason_is_not_a_budget() {
|
fn hx_error_asks_the_user_and_the_reply_retries_the_step() {
|
||||||
let e = env("hx-error");
|
let e = env("hx-error");
|
||||||
let m = ctl_machine(LIMIT_MACHINE);
|
// the state has a catch: an hx error must not be filed under it
|
||||||
|
let m = ctl_machine(&LIMIT_MACHINE.replace(
|
||||||
|
"next = \"done\"",
|
||||||
|
"next = \"done\"\ncatch = { ToolDenied = \"done\" }",
|
||||||
|
));
|
||||||
create(&e.db, &e.dir.join("wt"), "t", "", "m").unwrap();
|
create(&e.db, &e.dir.join("wt"), "t", "", "m").unwrap();
|
||||||
|
let user = answerer(e.dir.join("orch.db"), &["reply: logged in again"]);
|
||||||
let p = fake("FAKE_MODE=error");
|
let p = fake("FAKE_MODE=error");
|
||||||
assert_eq!(
|
run_session(&e.db, &m, "s1", &e.repo, "", &p).unwrap();
|
||||||
run_session(&e.db, &m, "s1", &e.repo, "", &p).unwrap(),
|
let seen = user.join().unwrap();
|
||||||
"failed"
|
assert_eq!(seen.len(), 1);
|
||||||
|
assert_eq!(seen[0].0, "input");
|
||||||
|
assert!(
|
||||||
|
seen[0].1["detail"]
|
||||||
|
.as_str()
|
||||||
|
.unwrap()
|
||||||
|
.contains("hit the error")
|
||||||
);
|
);
|
||||||
let ev = e.db.events(Some("s1"), 0).unwrap();
|
let ev = e.db.events(Some("s1"), 0).unwrap();
|
||||||
assert!(ev.iter().all(|v| v.kind != "budget" && v.kind != "goto"));
|
assert!(
|
||||||
|
ev.iter()
|
||||||
|
.all(|v| !matches!(v.kind.as_str(), "budget" | "goto" | "catch"))
|
||||||
|
);
|
||||||
|
let ok = ev
|
||||||
|
.iter()
|
||||||
|
.filter(|v| v.kind == "step" && v.payload["ok"] == true);
|
||||||
|
assert_eq!(ok.count(), 1, "the retried step finished");
|
||||||
let _ = std::fs::remove_dir_all(&e.dir);
|
let _ = std::fs::remove_dir_all(&e.dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ Behaviour per `hx/step`, chosen with FAKE_MODE (orch passes FAKE_* through the p
|
|||||||
slow works until hx/interrupt (records hx/message and hx/compact in messages.txt / compact.txt), then
|
slow works until hx/interrupt (records hx/message and hx/compact in messages.txt / compact.txt), then
|
||||||
answers done; a retried step with context.hint finishes at once
|
answers done; a retried step with context.hint finishes at once
|
||||||
limit step_result blocked, no catch, reason "limit" (hx hit a limit from hx/step)
|
limit step_result blocked, no catch, reason "limit" (hx hit a limit from hx/step)
|
||||||
error step_result blocked, no catch, reason "error"
|
error step_result blocked, no catch, reason "error"; finishes when the retried step has a context.hint
|
||||||
crash exits without a step_result
|
crash exits without a step_result
|
||||||
FAKE_UNDERSCORE=1 sends every custom method as `_hx/...`.
|
FAKE_UNDERSCORE=1 sends every custom method as `_hx/...`.
|
||||||
FAKE_USAGE="ctx_used,ctx_limit,cost" makes every step report that usage first.
|
FAKE_USAGE="ctx_used,ctx_limit,cost" makes every step report that usage first.
|
||||||
@@ -90,7 +90,7 @@ def step(params):
|
|||||||
if mode == "needs_input" and not params.get("context", {}).get("hint"):
|
if mode == "needs_input" and not params.get("context", {}).get("hint"):
|
||||||
note("hx/step_result", {"status": "needs_input", "question": "Which provider?"})
|
note("hx/step_result", {"status": "needs_input", "question": "Which provider?"})
|
||||||
return
|
return
|
||||||
if mode in ("limit", "error"): # blocked without a catch, only the reason differs
|
if mode == "limit" or mode == "error" and not params.get("context", {}).get("hint"): # blocked without a catch, only the reason differs
|
||||||
note("hx/step_result", {"status": "blocked", "reason": mode, "summary": f"hit the {mode}"})
|
note("hx/step_result", {"status": "blocked", "reason": mode, "summary": f"hit the {mode}"})
|
||||||
return
|
return
|
||||||
blocked = mode == "blocked"
|
blocked = mode == "blocked"
|
||||||
|
|||||||
Reference in new issue
Block a user