Skip to content

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

feat(core): flush buffered conversation turns on clean shutdown

Steven Enamakelb1d7014e99ba
diff --git a/crates/openhuman-app/src/core_process.rs b/crates/openhuman-app/src/core_process.rs
index b19b0809bd..70322437ee 100644
--- a/crates/openhuman-app/src/core_process.rs
+++ b/crates/openhuman-app/src/core_process.rs
@@ -686,10 +686,9 @@ impl CoreProcessHandle {
/// drain, then aborts whatever is left so any background tokio tasks the
/// server spawned stop driving I/O before CEF's teardown runs.
///
- /// The moment is what makes the server's post-drain teardown real. The
- /// memory engine releases its job leases there, and an immediate abort
- /// skipped it on every normal quit, so every next launch waited the
- /// leases out (tinymemory#133). The wait is the same shape as the gateway
+ /// The moment is what makes the server's post-drain teardown real. Memory
+ /// stores its buffered conversation turns there, and an immediate abort
+ /// would drop them on every normal quit. The wait is the same shape as the gateway
/// shutdown beside it: short, bounded, and worth the last moment of the
/// UI thread. A server that does not finish in time is aborted as before.
pub async fn send_terminate_signal(&self) {
@@ -703,8 +702,8 @@ impl CoreProcessHandle {
///
/// The moment is sized from what that teardown is allowed to take, so the
/// abort below never lands in the middle of it: the memory exit budget
- /// (`EXIT_BUDGET`, every driver and the hook registry on one deadline)
- /// plus half a second for the drain itself. There is no local-runtime
+ /// (`EXIT_BUDGET`, storing buffered conversation turns) plus half a second
+ /// for the drain itself. There is no local-runtime
/// cleanup after it: OpenHuman never spawns Ollama / LM Studio / MLX.
/// Typical quits finish in milliseconds; the budget is only what a wedged
/// store may cost.
diff --git a/crates/openhuman-core/src/core/runtime/builder.rs b/crates/openhuman-core/src/core/runtime/builder.rs
index eaeb0d105c..3c0459eb4f 100644
--- a/crates/openhuman-core/src/core/runtime/builder.rs
+++ b/crates/openhuman-core/src/core/runtime/builder.rs
@@ -768,11 +768,15 @@ impl CoreRuntime {
}
/// Cleanup to run once a transport has stopped serving, whether it ended
- /// cleanly or with an error. There is no local model runtime to stop: the
- /// user runs Ollama / LM Studio / MLX themselves and OpenHuman never
- /// spawns it.
+ /// cleanly or with an error: memory stores the conversation turns it still
+ /// has buffered, within [`crate::memory::exit::EXIT_BUDGET`]. There is no
+ /// local model runtime to stop: the user runs Ollama / LM Studio / MLX
+ /// themselves and OpenHuman never spawns it.
pub async fn exit_cleanup(&self) {
- log::debug!("[core] shutdown: exit cleanup done (no owned local runtime to stop)");
+ if let Some(config) = self.config.as_ref() {
+ crate::memory::exit::run(config).await;
+ }
+ log::debug!("[core] shutdown: exit cleanup done");
}
/// Spawn each selected background service.
diff --git a/crates/openhuman-core/src/memory/mod.rs b/crates/openhuman-core/src/memory/mod.rs
index 7942577929..c852cba706 100644
--- a/crates/openhuman-core/src/memory/mod.rs
+++ b/crates/openhuman-core/src/memory/mod.rs
@@ -20,6 +20,7 @@ pub mod context;
pub mod conversations;
pub mod engine;
pub mod error;
+pub mod exit;
pub mod import;
pub mod ops;
pub mod schemas;