Luxe 0.1.2: Windows fixes, working compaction, and compaction progress in the dock

This commit is contained in:
Evan Whittaker
2026-10-18 15:04:51 -05:00
parent 4ed87ee4e4
commit 33b87c78a8
69 changed files with 1470 additions and 424 deletions

View File

@@ -300,17 +300,23 @@ async fn compacting_on_request_ignores_the_threshold_and_says_what_it_freed() {
);
action_tx.send(Action::CompactNow { focus: Some("the API decisions".into()) }).await.unwrap();
let mut freed = None;
let (mut started, mut freed) = (None, None);
while let Ok(Some(event)) =
tokio::time::timeout(std::time::Duration::from_secs(10), event_rx.recv()).await
{
if let Event::CompactionDone { tokens_before, tokens_after } = event {
freed = Some((tokens_before, tokens_after));
break;
match event {
Event::CompactionStarted { tokens_before } => started = Some(tokens_before),
Event::CompactionDone { tokens_before, tokens_after } => {
freed = Some((tokens_before, tokens_after));
break;
}
_ => {}
}
}
let (before, after) = freed.expect("a compaction_done event");
assert!(before > after, "it reports what it freed: {before} -> {after}");
// The summary call can take a minute, and without the start a client shows nothing meanwhile
assert_eq!(started, Some(before), "a compaction_started came first, naming what it replaces");
let calls = calls.lock().await;
let summarization =

View File

@@ -141,6 +141,80 @@ impl Provider for CutOffSummaryProvider {
}
}
/// A session on a summarizer that always stops short, `turns` turns in.
async fn cut_off_session(
turns: usize,
tmp: &tempfile::TempDir,
) -> (tokio::sync::mpsc::Sender<Action>, tokio::sync::mpsc::Receiver<Event>, Vec<Event>) {
let mut store = JsonlSessionStore::new(tmp.path().join("sessions"));
let session_id = store.create("/tmp/test").unwrap();
let calls = Arc::new(Mutex::new(Vec::new()));
let provider = Arc::new(CutOffSummaryProvider { calls, cut_off: CutOff::Length });
let (action_tx, mut event_rx) = Engine::spawn(config(store, session_id, provider, tmp.path()));
let mut seen = Vec::new();
for turn in 0..turns {
let prompt = bulky(&format!("TURN-{turn}"));
let submit =
Action::SubmitUserMessage { content: prompt, images: vec![], remediation: None };
action_tx.send(submit).await.unwrap();
seen.extend(crate::fixtures::events_until_turn_end(&mut event_rx).await);
}
(action_tx, event_rx, seen)
}
/// `/compact` says why the summary it ran was refused.
///
/// The break this catches: a summarizer that ran out of output room failed every time, and
/// `/compact` reported it as "Nothing to compact — the conversation already fits", at 100% of a
/// million-token window, so the reader had no way to tell what was wrong.
#[tokio::test]
async fn compacting_on_request_reports_why_the_summary_was_refused() {
let tmp = tempfile::tempdir().unwrap();
let (action_tx, mut event_rx, _) = cut_off_session(6, &tmp).await;
action_tx.send(Action::CompactNow { focus: None }).await.unwrap();
let seen = crate::fixtures::events_until(&mut event_rx, "the compaction's outcome", |e| {
matches!(e, Event::Error(_) | Event::CompactionDone { .. })
})
.await;
let Some(Event::Error(message)) = seen.last() else { panic!("no error: {seen:?}") };
assert!(message.contains("stopped short"), "the real reason is given: {message}");
assert!(!message.contains("Nothing to compact"), "not a no-op: {message}");
// A client showing the compaction as under way needs its end, failure included
let position = |wanted: fn(&Event) -> bool| seen.iter().position(wanted);
let started = position(|e| matches!(e, Event::CompactionStarted { .. }));
let stopped = position(|e| matches!(e, Event::CompactionStopped));
assert!(started.is_some() && started < stopped, "started, then stopped: {seen:?}");
action_tx.send(Action::Close).await.unwrap();
}
/// A failed automatic compaction is announced, and so is the breaker turning it off.
///
/// The break this catches: every summary failed for a whole session and only the log said so;
/// the reader found out when the window was full and the model could no longer answer at all.
#[tokio::test]
async fn a_failing_automatic_compaction_tells_the_reader_and_says_when_it_stops() {
let tmp = tempfile::tempdir().unwrap();
let (action_tx, _event_rx, seen) = cut_off_session(TURNS + 5, &tmp).await;
let notices: Vec<&String> = seen
.iter()
.filter_map(|event| match event {
Event::Notice(message) => Some(message),
_ => None,
})
.collect();
let breaker = luxe_core::compaction::MAX_COMPACTION_FAILURES as usize;
let failures = notices.iter().filter(|notice| notice.contains("stopped short")).count();
assert_eq!(failures, breaker, "one notice per failure, until it stops: {notices:?}");
assert!(
notices.iter().any(|notice| notice.contains("/compact")),
"the last one says it is off and how to retry: {notices:?}"
);
action_tx.send(Action::Close).await.unwrap();
}
/// A summary the summarizer did not finish must not replace the conversation it summarizes.
///
/// The break this catches: the reply loop took an error, a length stop or a dropped stream as

View File

@@ -113,6 +113,11 @@ fn the_frames_a_client_cannot_work_without_are_pinned() {
Event::ActionRejected { kind: None, reason: "line is not JSON".into() },
r#"{"kind":"action_rejected","content":{"reason":"line is not JSON"}}"#,
),
(
Event::CompactionStarted { tokens_before: 180_000 },
r#"{"kind":"compaction_started","content":{"tokens_before":180000}}"#,
),
(Event::CompactionStopped, r#"{"kind":"compaction_stopped"}"#),
(
Event::PermissionRequested {
id: request_id("perm:1"),
@@ -558,7 +563,9 @@ fn every_known_event_roundtrips() {
Event::StateChanged(EngineState::default()),
Event::TurnEnded { reason: StopReason::EndTurn },
Event::LastTurnAvailable { session_id: "session-1".into(), turn_id: "turn-1".into() },
Event::CompactionStarted { tokens_before: 2_000 },
Event::CompactionDone { tokens_before: 2_000, tokens_after: 1_000 },
Event::CompactionStopped,
Event::ContextUsage { used_tokens: 1_000, context_window: 8_000 },
Event::TurnUsage {
prompt_tokens: 800,