The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
fix(memory): evict shut-down drivers, run exit hooks side by side, scope the depth lookup\n\nReview follow-ups on the exit path and the sync pass.\n\nThe shell restarts the embedded server in place (permission refresh, app\nupdate). Exit shut every cached driver down but left it in the binding\ncache, so the next server was handed drivers whose workers had already\nstopped. Exit now evicts what it shut down (by identity, under the cache\nlock); a server starting again binds anew. A test walks the restart.\n\n`core::shutdown::run_hooks` awaits hooks in registration order, and the\nexit path runs it under a deadline: one hook that never answered would\nkeep every hook behind it, the memory lease release included, from\nstarting. `run_hooks_now` runs the drained hooks concurrently; the signal\npath keeps its order.\n\n`run_sync_pass` resolved the per-source sync depth through the process\nenvironment. A pass is bound to one workspace, and the global registry\npath can answer a caller bound to workspace B with workspace A's rows,\nwhich the registry's `_in` variants exist to prevent. The lookup now\nreads `list_sources_in(config)`.\n\nThe completed toast appended the "more to sync" note beside a nonzero\ncount but not the spent-budget note, so a pass that filed some mail and\nthen ran out for the day read as finished. Both notes ride beside the\ncount now.\n\nThe repair button carries an analytics id and a confirmed run reports\n`memory_repair_succeeded` with a count only, per the analytics rule.\n\nThe Tauri workspace lock still named tinyconnectors-bus 0.7.1; refreshed\nto 0.8.0 alongside the root lock.\n
Shanubc131d628b45
diff --git a/app/src-tauri/Cargo.lock b/app/src-tauri/Cargo.lockindex 76f3f90e57..7344c24ce9 100644--- a/app/src-tauri/Cargo.lock+++ b/app/src-tauri/Cargo.lock@@ -7180,7 +7180,7 @@ dependencies = [[[package]]name = "tinyconnectors-bus"-version = "0.7.1"+version = "0.8.0"dependencies = ["serde","serde_json",diff --git a/app/src/components/intelligence/MemorySourcesRegistry.tsx b/app/src/components/intelligence/MemorySourcesRegistry.tsxindex c07cd830a6..0bd76163ff 100644--- a/app/src/components/intelligence/MemorySourcesRegistry.tsx+++ b/app/src/components/intelligence/MemorySourcesRegistry.tsx@@ -34,6 +34,7 @@ import {memoryTreePipelineStatus,type MemoryTreePipelineStatus,} from '../../utils/tauriCommands/memoryTree';+import { trackAnalyticsEvent } from '../analytics';import { Card } from '../ui';import Button from '../ui/Button';import { AddMemorySourceDialog } from './AddMemorySourceDialog';@@ -221,13 +222,20 @@ export function MemorySourcesRegistry({: note === 'more_pending'? tt('memorySources.sync.morePending'): tt('memorySources.sync.upToDate');+ // Beside a count, the note says why the run stopped short — the+ // budget as much as the cap. A pass that filed some mail and then+ // ran out for the day is the common partial case this exists to+ // explain; "N items synced" alone would read as a finished sync.+ const noteKey =+ note === 'budget_spent'+ ? 'memorySources.sync.budgetSpent'+ : note === 'more_pending'+ ? 'memorySources.sync.morePending'+ : null;onToastRef.current?.({type: note === 'budget_spent' ? 'warning' : 'success',title: `${tt('memorySources.sync.completeTitle')} ${label}`,- message:- hasItems && note === 'more_pending'- ? `${counted} — ${tt('memorySources.sync.morePending')}`- : counted,+ message: hasItems && noteKey ? `${counted} — ${tt(noteKey)}` : counted,});} else {// Failure: surface the reason on the row + a toast. The core already@@ -546,6 +554,9 @@ export function MemorySourcesRegistry({setRepairModalOpen(false);try {const result = await memoryTreeBackfillConnectorTrees({ dryRun: false });+ // The successful domain outcome, not the click: a privacy-safe count+ // only — no ids, no user text.+ trackAnalyticsEvent('memory_repair_succeeded', { count: result.ingested });const summary = t('memorySources.repair.success').replace('{ingested}', String(result.ingested)).replace('{already}', String(result.already_present))@@ -628,6 +639,7 @@ export function MemorySourcesRegistry({size="sm"onClick={() => void handleRepairClick()}disabled={repairing}+ analyticsId="memory-sources-repair"data-testid="repair-memories-button"title={t('memorySources.repair.title')}>{t('memorySources.repair.button')}diff --git a/app/src/components/intelligence/__tests__/MemorySourcesRegistry.sync.test.tsx b/app/src/components/intelligence/__tests__/MemorySourcesRegistry.sync.test.tsxindex 79dfbbc914..9fc6dd4e6a 100644--- a/app/src/components/intelligence/__tests__/MemorySourcesRegistry.sync.test.tsx+++ b/app/src/components/intelligence/__tests__/MemorySourcesRegistry.sync.test.tsx@@ -53,6 +53,11 @@ vi.mock('../../../services/memorySourcesService', () => ({// ── tauriCommands mock ────────────────────────────────────────────────────────// memoryTreePipelineStatus is polled for downstream pipeline health (GH-4690);// default to a healthy running snapshot so rows keep their clean synced state.+const mockTrackAnalyticsEvent = vi.fn();+vi.mock('../../analytics', () => ({+ trackAnalyticsEvent: (...args: unknown[]) => mockTrackAnalyticsEvent(...args),+}));+vi.mock('../../../utils/tauriCommands/memoryTree', () => ({memoryTreeBackfillConnectorTrees: vi.fn(),memoryTreeFlushSource: vi.fn().mockResolvedValue({ seals_fired: 0 }),@@ -546,6 +551,37 @@ describe('MemorySourcesRegistry', () => {);});+ it('keeps the budget note beside a nonzero count in the toast', async () => {+ // A pass that filed some mail and then ran out for the day is the common+ // partial case; "N items synced" alone read as a finished sync.+ const sources = [makeSource('src-partial')];+ listMemorySources.mockResolvedValue(sources);+ memorySourcesStatusList.mockResolvedValue([]);+ const onToast = vi.fn();++ renderWithProviders(<MemorySourcesRegistry pollIntervalMs={0} onToast={onToast} />);+ await waitFor(() => expect(screen.getByText('Source src-partial')).toBeInTheDocument());++ act(() => {+ window.dispatchEvent(+ makeSyncStageEvent({+ stage: 'completed',+ source_id: 'src-partial',+ detail: "ingested 3 item(s); today's provider request budget is spent",+ })+ );+ });++ await waitFor(() =>+ expect(onToast).toHaveBeenCalledWith(+ expect.objectContaining({+ type: 'warning',+ message: '3 memorySources.sync.itemsSynced — memorySources.sync.budgetSpent',+ })+ )+ );+ });+it('shows the "more to sync" note beside a count when the run stopped at its cap', async () => {const sources = [makeSource('src-more')];listMemorySources.mockResolvedValue(sources);@@ -616,6 +652,10 @@ describe('MemorySourcesRegistry', () => {fireEvent.click(screen.getByText('memorySources.repair.confirm'));await waitFor(() => expect(backfill).toHaveBeenCalledWith({ dryRun: false }));+ // The successful domain outcome is tracked with the privacy-safe count only.+ await waitFor(() =>+ expect(mockTrackAnalyticsEvent).toHaveBeenCalledWith('memory_repair_succeeded', { count: 40 })+ );// The i18n mock returns keys, so the placeholders in the summary are// not substituted here; the counts are covered by the wrapper's tests.await waitFor(() =>diff --git a/app/src/services/analytics.ts b/app/src/services/analytics.tsindex c675a07ca5..b00c9b1c0d 100644--- a/app/src/services/analytics.ts+++ b/app/src/services/analytics.ts@@ -104,6 +104,7 @@ const ALLOWED_EVENT_NAMES = ['automation_run_started','automation_run_resumed','automation_run_cancelled',+ 'memory_repair_succeeded','memory_tree_retry_succeeded','skill_install','skill_uninstall',diff --git a/src/core/shutdown.rs b/src/core/shutdown.rsindex 337054c587..aa1e14a438 100644--- a/src/core/shutdown.rs+++ b/src/core/shutdown.rs@@ -59,8 +59,18 @@ async fn run_hooks() {/// run — the memory engine releasing its queue leases, above all — never ran/// on a normal quit. Drains the registry, so a later call, or a signal landing/// mid-teardown, finds nothing to run twice.+///+/// Side by side, unlike the signal path. The caller runs this under a+/// deadline, and in sequence one hook that never answers would keep every hook+/// registered after it — the lease release among them — from so much as+/// starting before the deadline dropped the lot. Run together, a hanging hook+/// costs only itself.pub async fn run_hooks_now() {- run_hooks().await;+ let hooks: Vec<ShutdownHook> = {+ let mut guard = HOOKS.lock().expect("shutdown hooks poisoned");+ std::mem::take(&mut *guard)+ };+ futures::future::join_all(hooks.iter().map(|hook| hook())).await;}/// Returns a future that resolves when the process receives a terminationdiff --git a/src/openhuman/integrations/composio/ops/providers_ops.rs b/src/openhuman/integrations/composio/ops/providers_ops.rsindex 05872b10af..fa38c0d5fe 100644--- a/src/openhuman/integrations/composio/ops/providers_ops.rs+++ b/src/openhuman/integrations/composio/ops/providers_ops.rs@@ -489,7 +489,7 @@ pub(crate) async fn run_sync_pass(// the module now turns it into Gmail's own `after:` search term, so a// bounded first sync costs one page of recent mail rather than a walk// through the years. `None` reads unbounded, as every earlier release did.- let depth_days = source_sync_depth_days(toolkit, connection_id).await;+ let depth_days = source_sync_depth_days(config, toolkit, connection_id);let response = connectors::call_slow::<_, ConnectorSyncResponse>(config,@@ -641,22 +641,22 @@ pub(crate) async fn run_sync_pass(}/// The per-source "Sync depth (days)" cap for one connection, from the-/// memory-sources registry.+/// memory-sources registry the pass's own `config` names.////// Resolved here rather than threaded through every caller because there are/// five of them (the row button, All In, the periodic loop, the connection/// bootstrap, Slack's own RPC), and `max_items` already showed what happens/// when each open-codes the same rule: two of the five disagreed-/// (openhuman#6007). `None` when the row is missing, carries no cap, or the-/// registry cannot be read — each means "no lower bound", which is what every-/// release before the field existed did, so a registry hiccup degrades to the-/// old behaviour rather than to a failed sync.-async fn source_sync_depth_days(toolkit: &str, connection_id: &str) -> Option<u32> {- let sources = match crate::openhuman::memory::sources::registry::list_enabled_by_kind(- crate::openhuman::memory::sources::SourceKind::Composio,- )- .await- {+/// (openhuman#6007). Read through `config`, not the process environment: a+/// pass is bound to one workspace, and the global registry path would answer a+/// caller bound to workspace B with workspace A's rows — the cross-workspace+/// leak the registry's `_in` variants exist to prevent. `None` when the row is+/// missing, carries no cap, or the registry cannot be read — each means "no+/// lower bound", which is what every release before the field existed did, so+/// a registry hiccup degrades to the old behaviour rather than to a failed+/// sync.+fn source_sync_depth_days(config: &Config, toolkit: &str, connection_id: &str) -> Option<u32> {+ let sources = match crate::openhuman::memory::sources::registry::list_sources_in(config) {Ok(sources) => sources,Err(error) => {tracing::warn!(@@ -670,13 +670,16 @@ async fn source_sync_depth_days(toolkit: &str, connection_id: &str) -> Option<u3}};pick_source_sync_depth_days(- sources.iter().map(|source| {- (- source.toolkit.as_deref(),- source.connection_id.as_deref(),- source.sync_depth_days,- )- }),+ sources+ .iter()+ .filter(|source| source.kind == crate::openhuman::memory::sources::SourceKind::Composio)+ .map(|source| {+ (+ source.toolkit.as_deref(),+ source.connection_id.as_deref(),+ source.sync_depth_days,+ )+ }),toolkit,connection_id,)diff --git a/src/openhuman/memory/binding.rs b/src/openhuman/memory/binding.rsindex 3aa0f772e5..1601763ddd 100644--- a/src/openhuman/memory/binding.rs+++ b/src/openhuman/memory/binding.rs@@ -482,6 +482,31 @@ pub(crate) fn cached_bindings() -> Vec<Arc<MemoryBinding>> {}}+/// Drop `shut_down` from the cache, so a server that starts again in this+/// process binds fresh drivers instead of the ones exit has already torn down.+///+/// The shell restarts the embedded server in place (a permission refresh, an+/// app update), and exit runs every cached driver's `shutdown` on the way out.+/// Left in the cache, those drivers would be handed straight back to the next+/// server — their workers stopped and their hooks already drained — and memory+/// would stay dark until the whole desktop process restarted. Matched by+/// identity, not by key: only what exit actually asked to shut down leaves.+/// With the exit gate up nothing else can be in the cache by then; without it+/// (a bare call, in tests) a binding built beside the exit stays.+pub(crate) fn evict_bindings(shut_down: &[Arc<MemoryBinding>]) {+ if shut_down.is_empty() {+ return;+ }+ let Some(cache) = BINDINGS.get() else {+ return;+ };+ let mut map = match cache.write() {+ Ok(map) => map,+ Err(poisoned) => poisoned.into_inner(),+ };+ map.retain(|_, binding| !shut_down.iter().any(|gone| Arc::ptr_eq(gone, binding)));+}+/// The bound memory driver for `workspace_dir`, constructing it on first use.////// The same workspace always resolves to the same cached `Arc` (sodiff --git a/src/openhuman/memory/exit.rs b/src/openhuman/memory/exit.rsindex b626fbb56a..d2de4622b6 100644--- a/src/openhuman/memory/exit.rs+++ b/src/openhuman/memory/exit.rs@@ -83,7 +83,9 @@ pub(crate) fn reset_gate_for_tests() {/// appear after the snapshot. Both halves are idempotent — a provider's second/// `shutdown` is a no-op and the registry drains — so a signal landing/// mid-teardown, or the app-update restart path calling this twice, repeats-/// nothing.+/// nothing. The drivers it shut down leave the cache afterwards, so the+/// server the shell starts next in this same process binds anew instead of+/// reusing a driver whose workers are stopped.pub async fn shutdown_for_exit() {if SERVING.load(Ordering::SeqCst) {EXITING.store(true, Ordering::SeqCst);@@ -107,6 +109,12 @@ pub async fn shutdown_for_exit() {proceeding with exit");}+ // Out of the cache either way — answered or timed out, these drivers+ // have been told to stop. The shell restarts the embedded server in+ // place; a server starting again in this process must bind fresh+ // drivers, never be handed back ones whose workers exit already+ // stopped.+ crate::openhuman::memory::binding::evict_bindings(&bindings);}let hooks_deadline = deadline.max(Instant::now() + HOOKS_FLOOR);diff --git a/src/openhuman/memory/exit_tests.rs b/src/openhuman/memory/exit_tests.rsindex 96dec35d50..74172637d9 100644--- a/src/openhuman/memory/exit_tests.rs+++ b/src/openhuman/memory/exit_tests.rs@@ -4,7 +4,9 @@ use std::sync::atomic::{AtomicUsize, Ordering};use std::sync::Arc;use std::time::Duration;+use super::binding::{cached_bindings, for_subtree};use super::exit::{exiting, reset_gate_for_tests, server_starting, shutdown_for_exit, EXIT_BUDGET};+use crate::openhuman::config::schema::MemorySubsystemConfig;/// The hook registry is process-global, so the two tests below must not see/// each other's hooks: each registers and drains under this lock.@@ -77,3 +79,42 @@ async fn exit_is_bounded_even_when_a_hook_hangs() {started.elapsed());}++/// The shell restarts the embedded server in place (a permission refresh, an+/// app update). Exit shuts every cached driver down, so the server that starts+/// next must not be handed those drivers back: exit evicts them, and the next+/// bind builds anew.+#[tokio::test]+async fn exit_evicts_the_drivers_it_shut_down() {+ let _serial = REGISTRY.lock().await;+ reset_gate_for_tests();+ let workspace = tempfile::tempdir().expect("tempdir");+ let cfg = MemorySubsystemConfig {+ driver: "null".into(),+ ..Default::default()+ };+ let before = for_subtree(workspace.path(), "memory", &cfg).expect("binds the null driver");+ assert!(+ cached_bindings()+ .iter()+ .any(|cached| Arc::ptr_eq(cached, &before)),+ "the binding is cached before exit"+ );++ server_starting();+ shutdown_for_exit().await;+ assert!(+ !cached_bindings()+ .iter()+ .any(|cached| Arc::ptr_eq(cached, &before)),+ "exit must drop the driver it shut down"+ );++ server_starting();+ let after = for_subtree(workspace.path(), "memory", &cfg).expect("binds again after a restart");+ assert!(+ !Arc::ptr_eq(&before, &after),+ "a restarted server must not be handed back a driver exit already stopped"+ );+ reset_gate_for_tests();+}