From a9f63b76998b47c626e3e81ac02148f3d146e735 Mon Sep 17 00:00:00 2001 From: npub17jjz49l9jjmhhk7cac63j8yt9z555n9cw8vk7v5jz4vzw4ppld5qgj57cc Date: Wed, 8 Jul 2026 10:15:49 -0400 Subject: [PATCH] perf(desktop): defer archive-seed hooks behind startupReady MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Finding [L5] AppShell.tsx:161-164 — 4 archive/ingestion hooks mounted unconditionally at first render competed with first paint. Gate the two archive *seed* hooks (useObserverArchiveSeed, useAgentMetricArchiveSeed) behind startupReady by passing deferredPubkey instead of the eager identityQuery pubkey, matching the existing presence/user-status deferral pattern. useArchiveSync (the eager live-save path) stays unchanged — it owns live event ingestion and must not be deferred. Only the one-shot first-run seeds (mergeSaveSubscriptionKinds) move off the boot critical path. The seeds' explicit-choice guard is untouched: each hook already early-returns on `if (!pubkey) return`, so a deferred (undefined) pubkey is a no-op until startup completes, then the seed fires exactly once with identical semantics. Confirmed by useObserverArchiveSeed/ useAgentMetricArchiveSeed test suites (18/18), incl. test_undefined_pubkey_does_nothing and test_explicit_choice_set_does_not_reseed. Co-authored-by: Tyler Longwell Signed-off-by: Tyler Longwell --- desktop/src/app/AppShell.tsx | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/desktop/src/app/AppShell.tsx b/desktop/src/app/AppShell.tsx index e35c41c0d2..062f815ff3 100644 --- a/desktop/src/app/AppShell.tsx +++ b/desktop/src/app/AppShell.tsx @@ -160,10 +160,16 @@ export function AppShell() { // guard here would drop managed-agent coverage during startup. useAgentObserverIngestion(); useArchiveSync(); - useObserverArchiveSeed(identityQuery.data?.pubkey); - useAgentMetricArchiveSeed(identityQuery.data?.pubkey); - const profileQuery = useProfileQuery(); + // Defer the archive *seeds* until startup is idle: they're first-run catch-up + // config (a one-shot mergeSaveSubscriptionKinds), not live-ingest — that's + // useArchiveSync's job, which stays eager above. Passing deferredPubkey makes + // each seed hook wait on its own `if (!pubkey) return` guard until the shell + // is interactive, so their IPC + sqlite archive open doesn't compete with + // first paint. The explicit-choice guard inside each hook is unchanged. const deferredPubkey = startupReady ? identityQuery.data?.pubkey : undefined; + useObserverArchiveSeed(deferredPubkey); + useAgentMetricArchiveSeed(deferredPubkey); + const profileQuery = useProfileQuery(); useRelayAutoHeal(); usePresenceSubscription(); useUserStatusSubscription();