Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
77e32bbc78 | ||
|
|
79cf5fcda1 | ||
|
|
05dbb8e63f | ||
|
|
e119dc2f0d | ||
|
|
0184627f27 |
No files matched your search
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"version": "0.1.10",
|
||||
"version": "0.1.11",
|
||||
"sha256": {
|
||||
"aarch64-apple-darwin": "b0192269b031068f5799ac61b70d85f9e5364b17d1634701084f76b3707bf063",
|
||||
"x86_64-unknown-linux-musl": "e42f35a2df69ceeed24004ec1ab5cb7c043133fda2f7acd52a5b7fe62ce04109"
|
||||
"aarch64-apple-darwin": "a363071712b8a0df2fce74a671b5ee1c7ee3bb384fc2989d71c3bd6654c62874",
|
||||
"x86_64-unknown-linux-musl": "f4d0c71869d25b06be19c2da9be48f4ae0ea71acf413bc5460706b4e0d0a87a4"
|
||||
}
|
||||
}
|
||||
@@ -433,7 +433,12 @@ impl Agent {
|
||||
) -> Result<futures::stream::BoxStream<'static, hx_ai::Result<StreamEvent>>, Error> {
|
||||
let mut wait = self.retry_ms;
|
||||
for attempt in 1..=4 {
|
||||
match self.provider.stream(req.clone()).await {
|
||||
let mut ab = self.abort.clone();
|
||||
let r = tokio::select! {
|
||||
r = self.provider.stream(req.clone()) => r,
|
||||
_ = async { ab.wait_for(|a| *a).await.is_ok() } => return Err(Error::Aborted),
|
||||
};
|
||||
match r {
|
||||
Err(hx_ai::Error::Api { status, .. }) if attempt < 4 && transient(status) => {
|
||||
self.emit(Event::Info(format!(
|
||||
"api error {status}; retry {attempt}/3 in {wait}ms"
|
||||
@@ -477,8 +482,12 @@ impl Agent {
|
||||
if self.aborted() {
|
||||
return Err(Error::Aborted);
|
||||
}
|
||||
let mut ab = self.abort.clone();
|
||||
if self.window.should_compact(&self.session.messages())
|
||||
&& self.compact(KEEP_MESSAGES).await?
|
||||
&& tokio::select! {
|
||||
r = self.compact(KEEP_MESSAGES) => r?,
|
||||
_ = async { ab.wait_for(|a| *a).await.is_ok() } => return Err(Error::Aborted),
|
||||
}
|
||||
{
|
||||
self.emit(Event::Info("context compacted".into())).await;
|
||||
}
|
||||
@@ -919,6 +928,39 @@ mod tests {
|
||||
(r, n)
|
||||
}
|
||||
|
||||
struct Hang;
|
||||
#[async_trait]
|
||||
impl Provider for Hang {
|
||||
async fn stream(
|
||||
&self,
|
||||
_: Request,
|
||||
) -> hx_ai::Result<BoxStream<'static, hx_ai::Result<StreamEvent>>> {
|
||||
std::future::pending().await
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn abort_ends_a_request_that_never_answers() {
|
||||
let dir = tempfile::tempdir().unwrap();
|
||||
let cx = ToolCtx {
|
||||
cwd: dir.path().into(),
|
||||
state: Default::default(),
|
||||
};
|
||||
let (mut a, h) = Agent::new(
|
||||
Arc::new(Hang),
|
||||
Registry::default(),
|
||||
Session::open(dir.path().join("s.jsonl")).unwrap(),
|
||||
cx,
|
||||
);
|
||||
let t = tokio::spawn(async move {
|
||||
tokio::time::sleep(std::time::Duration::from_millis(50)).await;
|
||||
h.abort();
|
||||
});
|
||||
let r = tokio::time::timeout(std::time::Duration::from_secs(5), a.run("go")).await;
|
||||
t.await.unwrap();
|
||||
assert!(matches!(r, Ok(Err(Error::Aborted))));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn transient_api_errors_are_retried() {
|
||||
let (r, n) = flaky_run(1, 529).await;
|
||||
|
||||
@@ -371,7 +371,20 @@ impl Router {
|
||||
}
|
||||
};
|
||||
let prefer = self.cur.map_or(start, |(k, _)| k);
|
||||
let (kind, model) = pick_for(tier, prefer, avoid, models, &self.cfg)?;
|
||||
let (mut kind, mut model) = pick_for(tier, prefer, avoid, models, &self.cfg)?;
|
||||
// the history must fit the window (a 1M session cannot go down to a 200k Haiku)
|
||||
let mut tier = tier;
|
||||
while (hx_ai::models::window(models, &model) as usize) * 9 / 10 < sig.ctx {
|
||||
let up = match tier {
|
||||
Tier::Fast => Tier::Balanced,
|
||||
Tier::Balanced => Tier::Deep,
|
||||
_ => break,
|
||||
};
|
||||
let Some((k, m)) = pick_for(up, kind, avoid, models, &self.cfg) else {
|
||||
break;
|
||||
};
|
||||
(tier, kind, model) = (up, k, m);
|
||||
}
|
||||
// no Fable in the catalog: it ran as Deep
|
||||
let tier = if tier == Tier::Max && Tier::of(&model) != Some(Tier::Max) {
|
||||
Tier::Deep
|
||||
@@ -485,7 +498,7 @@ mod tests {
|
||||
ModelInfo {
|
||||
id: id.into(),
|
||||
kind,
|
||||
context_window: 1,
|
||||
context_window: 1_000_000,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -635,6 +648,19 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn history_too_big_for_the_window_skips_the_small_tier() {
|
||||
let mut r = Router::new(Cfg::default());
|
||||
let mut light = signals("commit", &[]);
|
||||
assert_eq!(light.tier, Tier::Fast);
|
||||
light.ctx = 250_000;
|
||||
let mut c = cat();
|
||||
c[2].context_window = 200_000;
|
||||
c[1].context_window = 1_000_000;
|
||||
let p = r.route(&light, Kind::Claude, None, &c).unwrap();
|
||||
assert_eq!(p.model, "claude-sonnet-5-5");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn effort_follows_score_and_provider() {
|
||||
assert_eq!(effort_for(-2, Kind::Claude), Effort::Off);
|
||||
|
||||
Reference in new issue
Block a user