hive-agent: tests for the unknown-window paths, and the two vale errors
This commit is contained in:
parent
1bfee54414
commit
c45615a555
3 changed files with 65 additions and 3 deletions
|
|
@ -63,7 +63,7 @@ The context window is whatever the model reports once a turn completes
|
||||||
(`modelUsage.*.contextWindow`, `Bus::api_context_window`). The harness keeps no
|
(`modelUsage.*.contextWindow`, `Bus::api_context_window`). The harness keeps no
|
||||||
per-model table of window sizes: until the first turn of a process completes the
|
per-model table of window sizes: until the first turn of a process completes the
|
||||||
window is unknown, and what depends on it waits (the compaction watermarks, the
|
window is unknown, and what depends on it waits (the compaction watermarks, the
|
||||||
auto-reset, the `compact` tool, the context fill the swarm shows).
|
autoreset, the `compact` tool, the context fill the swarm shows).
|
||||||
|
|
||||||
The window drives watermarks; no web endpoint serves it.
|
The window drives watermarks; no web endpoint serves it.
|
||||||
|
|
||||||
|
|
@ -188,7 +188,7 @@ still applies.
|
||||||
- **Auto session-reset** — a third path (`turn::maybe_auto_reset`,
|
- **Auto session-reset** — a third path (`turn::maybe_auto_reset`,
|
||||||
pre-turn) that fires when both conditions hold: context is ≥ a watermark
|
pre-turn) that fires when both conditions hold: context is ≥ a watermark
|
||||||
(`HIVE_AUTO_RESET_WATERMARK_TOKENS`, default **50% of the reported
|
(`HIVE_AUTO_RESET_WATERMARK_TOKENS`, default **50% of the reported
|
||||||
window**, none before one is reported) AND the time since the last turn
|
window**, none until the API reports one) AND the time since the last turn
|
||||||
exceeds the assumed prompt-cache TTL (`HIVE_CACHE_TTL_SECS`, default
|
exceeds the assumed prompt-cache TTL (`HIVE_CACHE_TTL_SECS`, default
|
||||||
`3600`). Claude's prompt cache goes cold after a while; once it's cold,
|
`3600`). Claude's prompt cache goes cold after a while; once it's cold,
|
||||||
`--resume`-ing a large session pays the full re-upload cost with no
|
`--resume`-ing a large session pays the full re-upload cost with no
|
||||||
|
|
|
||||||
|
|
@ -981,6 +981,34 @@ mod tests {
|
||||||
assert!(low.take_compact().is_none(), "a refusal queues nothing");
|
assert!(low.take_compact().is_none(), "a refusal queues nothing");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Without a window to divide by, the tool refuses and says why; once a turn
|
||||||
|
/// reports one, the same usage is judged against it.
|
||||||
|
#[test]
|
||||||
|
fn compact_is_refused_while_the_context_window_is_unknown() {
|
||||||
|
let (_dir, todos, _) = stores();
|
||||||
|
let wake = Notify::new();
|
||||||
|
let bus = Bus::new();
|
||||||
|
let usage: hive_claude::TokenUsage = serde_json::from_value(serde_json::json!({
|
||||||
|
"input_tokens": 50,
|
||||||
|
"output_tokens": 0,
|
||||||
|
"cache_read_input_tokens": 0,
|
||||||
|
"cache_creation_input_tokens": 0,
|
||||||
|
}))
|
||||||
|
.expect("a usage block");
|
||||||
|
bus.record_turn_usage(usage, usage);
|
||||||
|
|
||||||
|
let resp = dispatch(compact_req(None), &todos, &wake, None, &bus);
|
||||||
|
assert!(
|
||||||
|
matches!(&resp, Response::Err { message } if message.contains("window is unknown")),
|
||||||
|
"{resp:?}"
|
||||||
|
);
|
||||||
|
assert!(bus.take_compact().is_none(), "a refusal queues nothing");
|
||||||
|
|
||||||
|
bus.set_api_context_window(100);
|
||||||
|
let resp = dispatch(compact_req(None), &todos, &wake, None, &bus);
|
||||||
|
assert!(matches!(resp, Response::Ok), "{resp:?}");
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn the_compact_floor_is_forty_percent_of_the_window() {
|
fn the_compact_floor_is_forty_percent_of_the_window() {
|
||||||
let (_dir, todos, _) = stores();
|
let (_dir, todos, _) = stores();
|
||||||
|
|
|
||||||
|
|
@ -875,7 +875,7 @@ fn archive_session(bus: &Bus, session: &AgentSession) {
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::{PercentPolicy, SoftLimitPolicy};
|
use super::{PercentPolicy, SoftLimitPolicy, auto_reset_watermark_tokens};
|
||||||
use super::{
|
use super::{
|
||||||
PermissionAsk, TurnError, TurnOutcome, acp_permits, apply_telemetry, emit_turn_end,
|
PermissionAsk, TurnError, TurnOutcome, acp_permits, apply_telemetry, emit_turn_end,
|
||||||
error_to_turn, nonzero_or, parse_u64, report_compact, runtime_error_to_turn,
|
error_to_turn, nonzero_or, parse_u64, report_compact, runtime_error_to_turn,
|
||||||
|
|
@ -922,6 +922,40 @@ mod tests {
|
||||||
assert!(policy(75).should_compact(high));
|
assert!(policy(75).should_compact(high));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// The auto-reset watermark is half the window the API reported, and none
|
||||||
|
/// (`0`, off) before one is, instead of half a guessed size.
|
||||||
|
#[test]
|
||||||
|
fn the_auto_reset_watermark_waits_for_a_reported_window() {
|
||||||
|
let bus = Bus::new();
|
||||||
|
assert_eq!(auto_reset_watermark_tokens(&bus), 0);
|
||||||
|
bus.set_api_context_window(1_000_000);
|
||||||
|
assert_eq!(auto_reset_watermark_tokens(&bus), 500_000);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A turn that reports no window never triggers the proactive compaction,
|
||||||
|
/// however full the context: there is nothing to take a percent of.
|
||||||
|
#[test]
|
||||||
|
fn no_reported_window_means_no_proactive_compaction() {
|
||||||
|
let policy = SoftLimitPolicy {
|
||||||
|
percent: PercentPolicy {
|
||||||
|
percent: 75,
|
||||||
|
default_window: None,
|
||||||
|
checkpoint_prompt: None,
|
||||||
|
},
|
||||||
|
bus: Bus::new(),
|
||||||
|
};
|
||||||
|
let unreported = Usage {
|
||||||
|
context_tokens: 900_000,
|
||||||
|
context_window: None,
|
||||||
|
};
|
||||||
|
assert!(!policy.should_compact(unreported));
|
||||||
|
let reported = Usage {
|
||||||
|
context_window: Some(1_000_000),
|
||||||
|
..unreported
|
||||||
|
};
|
||||||
|
assert!(policy.should_compact(reported));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn a_turn_that_parsed_nothing_does_not_keep_the_previous_resolved_model() {
|
fn a_turn_that_parsed_nothing_does_not_keep_the_previous_resolved_model() {
|
||||||
let resolved = crate::paths::with_harness_dir(|| {
|
let resolved = crate::paths::with_harness_dir(|| {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue