fix(summon): evict stale completed tasks to prevent unbounded memory growth (#9514)
Signed-off-by: Douwe M Osinga <douwe@sidewalklabs.com> Co-authored-by: Douwe M Osinga <douwe@sidewalklabs.com>
This commit is contained in:
@@ -80,6 +80,7 @@ pub struct CompletedTask {
|
||||
pub result: Result<String, String>,
|
||||
pub turns_taken: u32,
|
||||
pub duration: Duration,
|
||||
pub completed_at: Instant,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
@@ -402,6 +403,13 @@ fn max_background_tasks() -> usize {
|
||||
.unwrap_or(5)
|
||||
}
|
||||
|
||||
fn completed_task_ttl() -> Duration {
|
||||
let secs = Config::global()
|
||||
.get_param::<u64>("GOOSE_COMPLETED_TASK_TTL_SECS")
|
||||
.unwrap_or(600);
|
||||
Duration::from_secs(secs)
|
||||
}
|
||||
|
||||
fn is_session_id(s: &str) -> bool {
|
||||
let parts: Vec<&str> = s.split('_').collect();
|
||||
parts.len() == 2 && parts[0].len() == 8 && parts[0].chars().all(|c| c.is_ascii_digit())
|
||||
@@ -1560,9 +1568,13 @@ impl SummonClient {
|
||||
result,
|
||||
turns_taken,
|
||||
duration,
|
||||
completed_at: Instant::now(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
let ttl = completed_task_ttl();
|
||||
completed.retain(|_id, task| task.completed_at.elapsed() <= ttl);
|
||||
}
|
||||
|
||||
fn get_task_description(params: &DelegateParams) -> String {
|
||||
@@ -2491,6 +2503,7 @@ You review code."#;
|
||||
result: Ok("Task completed successfully with output".to_string()),
|
||||
turns_taken: 5,
|
||||
duration: Duration::from_secs(60),
|
||||
completed_at: Instant::now(),
|
||||
},
|
||||
);
|
||||
completed.insert(
|
||||
@@ -2501,6 +2514,7 @@ You review code."#;
|
||||
result: Err("Something went wrong".to_string()),
|
||||
turns_taken: 3,
|
||||
duration: Duration::from_secs(30),
|
||||
completed_at: Instant::now(),
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user