Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

fix: prune retired jobs on workspace activation\n\n

Steven Enamakel4b82d7936906
diff --git a/src/openhuman/cron/seed.rs b/src/openhuman/cron/seed.rs
index aa5c16a7ad..93e06b0a10 100644
--- a/src/openhuman/cron/seed.rs
+++ b/src/openhuman/cron/seed.rs
@@ -33,10 +33,10 @@ const MORNING_BRIEFING_JOB_NAME: &str = "morning_briefing";
/// finds the migration path.
const LEGACY_WELCOME_JOB_NAME: &str = "welcome";
-/// Name used by the retired TinyPlace autopilot schedule. This migration
-/// marker must remain until upgraded workspaces have had the persisted job
-/// removed.
-const RETIRED_TINYPLACE_AUTOPILOT_JOB_NAME: &str = "tinyplace_autopilot";
+/// Agent definition ID used by the retired TinyPlace autopilot schedule. Unlike
+/// its display name, this was not editable, so it identifies only rows created
+/// by the removed feature and still catches rows a user renamed.
+const RETIRED_TINYPLACE_AUTOPILOT_AGENT_ID: &str = "tinyplace_agent";
/// Delivery config for proactive agents. The channels module decides
/// which channel(s) to deliver to based on the user's active channel
@@ -85,21 +85,35 @@ pub fn seed_proactive_agents(config: &Config) -> Result<()> {
/// Remove schedules whose implementation and management UI no longer exist.
///
-/// Runs on every core boot (and is idempotent) so existing installations cannot
-/// keep executing an enabled TinyPlace autopilot row after upgrading.
+/// Runs on every core boot and whenever a user workspace becomes active (and is
+/// idempotent) so existing installations cannot keep executing an enabled
+/// TinyPlace autopilot row after upgrading.
pub fn prune_retired_jobs(config: &Config) -> Result<usize> {
let existing = list_jobs(config)?;
let stale_ids: Vec<String> = existing
.iter()
- .filter(|job| job.name.as_deref() == Some(RETIRED_TINYPLACE_AUTOPILOT_JOB_NAME))
+ .filter(|job| job.agent_id.as_deref() == Some(RETIRED_TINYPLACE_AUTOPILOT_AGENT_ID))
.map(|job| job.id.clone())
.collect();
+ let mut removed = 0;
+ let mut failures = Vec::new();
for id in &stale_ids {
- remove_job(config, id)?;
+ match remove_job(config, id) {
+ Ok(()) => removed += 1,
+ Err(error) => failures.push(format!("{id}: {error}")),
+ }
}
- Ok(stale_ids.len())
+ if failures.is_empty() {
+ Ok(removed)
+ } else {
+ anyhow::bail!(
+ "failed to remove {} retired cron job(s): {}",
+ failures.len(),
+ failures.join("; ")
+ )
+ }
}
/// Remove any persisted cron job named `"welcome"` from a prior build.
@@ -210,7 +224,7 @@ mod tests {
assert!(!MORNING_BRIEFING_JOB_NAME.is_empty());
assert!(!LEGACY_WELCOME_JOB_NAME.is_empty());
assert_ne!(MORNING_BRIEFING_JOB_NAME, LEGACY_WELCOME_JOB_NAME);
- assert!(!RETIRED_TINYPLACE_AUTOPILOT_JOB_NAME.is_empty());
+ assert!(!RETIRED_TINYPLACE_AUTOPILOT_AGENT_ID.is_empty());
}
#[test]
@@ -322,7 +336,7 @@ mod tests {
add_agent_job_with_definition(
&config,
- Some(RETIRED_TINYPLACE_AUTOPILOT_JOB_NAME.to_string()),
+ Some("tinyplace_autopilot".to_string()),
Schedule::Cron {
expr: "*/5 * * * *".to_string(),
tz: None,
@@ -333,7 +347,7 @@ mod tests {
None,
Some(proactive_delivery()),
false,
- Some(RETIRED_TINYPLACE_AUTOPILOT_JOB_NAME.to_string()),
+ Some(RETIRED_TINYPLACE_AUTOPILOT_AGENT_ID.to_string()),
true,
None,
)
@@ -343,4 +357,52 @@ mod tests {
assert_eq!(prune_retired_jobs(&config).unwrap(), 0);
assert!(list_jobs(&config).unwrap().is_empty());
}
+
+ #[test]
+ fn retired_autopilot_prune_uses_immutable_agent_id() {
+ let tmp = TempDir::new().unwrap();
+ let config = test_config(&tmp);
+
+ add_agent_job_with_definition(
+ &config,
+ Some("renamed by user".to_string()),
+ Schedule::Cron {
+ expr: "*/5 * * * *".to_string(),
+ tz: None,
+ active_hours: None,
+ },
+ "retired autopilot prompt",
+ SessionTarget::Isolated,
+ None,
+ Some(proactive_delivery()),
+ false,
+ Some(RETIRED_TINYPLACE_AUTOPILOT_AGENT_ID.to_string()),
+ true,
+ None,
+ )
+ .expect("seed renamed retired autopilot");
+ add_agent_job_with_definition(
+ &config,
+ Some("tinyplace_autopilot".to_string()),
+ Schedule::Cron {
+ expr: "*/5 * * * *".to_string(),
+ tz: None,
+ active_hours: None,
+ },
+ "unrelated prompt",
+ SessionTarget::Isolated,
+ None,
+ Some(proactive_delivery()),
+ false,
+ Some("unrelated_agent".to_string()),
+ true,
+ None,
+ )
+ .expect("seed unrelated same-name job");
+
+ assert_eq!(prune_retired_jobs(&config).unwrap(), 1);
+ let remaining = list_jobs(&config).unwrap();
+ assert_eq!(remaining.len(), 1);
+ assert_eq!(remaining[0].agent_id.as_deref(), Some("unrelated_agent"));
+ }
}
diff --git a/src/openhuman/desktop/app_state/ops.rs b/src/openhuman/desktop/app_state/ops.rs
index 9353f65e30..77c8ad6640 100644
--- a/src/openhuman/desktop/app_state/ops.rs
+++ b/src/openhuman/desktop/app_state/ops.rs
@@ -671,6 +671,10 @@ async fn finish_revalidated_user_activation(
user_id: &str,
service_rebind_source: Option<&Config>,
) {
+ if let Err(error) = crate::openhuman::cron::seed::prune_retired_jobs(target_config) {
+ warn!("{LOG_PREFIX} failed to prune retired cron jobs after pending session revalidation: {error}");
+ }
+
// ── No explicit memory re-point here any more (#5560) ──────────────────
//
// This was `tinymemory_core::global::init(...)`, the in-process engine's
diff --git a/src/openhuman/security/credentials/ops.rs b/src/openhuman/security/credentials/ops.rs
index ec039d8693..3976f7e87c 100644
--- a/src/openhuman/security/credentials/ops.rs
+++ b/src/openhuman/security/credentials/ops.rs
@@ -522,6 +522,13 @@ async fn store_session_inner(
config.clone()
};
+ if let Err(error) = crate::openhuman::cron::seed::prune_retired_jobs(&effective_config) {
+ tracing::warn!(
+ error = %error,
+ "[credentials] failed to prune retired cron jobs after user workspace activation"
+ );
+ }
+
if local_session {
match crate::openhuman::config::ops::set_onboarding_completed(false).await {
Ok(_) => logs.push("onboarding left incomplete for local session setup".to_string()),