Make compaction transitions recoverable

This commit is contained in:
Georg Bauer
2026-07-26 10:56:19 +02:00
parent 6aa45b2cf0
commit 2a14b93335
13 changed files with 329 additions and 26 deletions

View File

@@ -276,6 +276,32 @@ impl Tools {
(self.context_tokens.max(4096) as usize * 2).min(512 * 1024)
}
pub(crate) fn compaction_observation(&mut self) -> Option<String> {
let mut running = self
.jobs
.values_mut()
.filter_map(|job| {
job.child.try_wait().ok().flatten().is_none().then(|| {
format!(
"bash job={} pid={} status=running command={}\noutput_path={}\n",
job.id,
job.child.id(),
job.command,
job.output.display()
)
})
})
.collect::<Vec<_>>();
if running.is_empty() {
return None;
}
running.sort();
Some(format!(
"Bash job update after context compaction. Running jobs still need explicit bash_status or bash_stop if relevant.\n{}",
running.concat()
))
}
fn existing_path(&self, value: &str) -> Result<PathBuf, String> {
let path = if Path::new(value).is_absolute() {
PathBuf::from(value)
@@ -1288,6 +1314,9 @@ mod tests {
],
);
assert!(tools.execute(&running, &cancel).contains("status=running"));
let observation = tools.compaction_observation().unwrap();
assert!(observation.contains("bash job=2"));
assert!(observation.contains("status=running"));
let stopped = tools.execute(&call("bash_stop", [("job", "2")]), &cancel);
assert!(!stopped.contains("status=running"));
assert_eq!(