From 5ffaf4f32b299bd904c9dbfc02e77252cbfb0220 Mon Sep 17 00:00:00 2001 From: Ogulcan Celik Date: Tue, 16 Jun 2026 18:25:02 +0300 Subject: [PATCH] fix: isolate omp hook state to ui sessions refs #614 --- .../assets/omp/herdr-agent-state.ts | 17 ++++++++++++++ src/integration/mod.rs | 23 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/integration/assets/omp/herdr-agent-state.ts b/src/integration/assets/omp/herdr-agent-state.ts index c2bec682..a6428cdd 100644 --- a/src/integration/assets/omp/herdr-agent-state.ts +++ b/src/integration/assets/omp/herdr-agent-state.ts @@ -197,6 +197,7 @@ export default function (pi) { let lastMessage: string | undefined; let idleTimer: ReturnType | undefined; let retryTimer: ReturnType | undefined; + let rootSession = false; function clearTimer(timer: ReturnType | undefined) { if (timer) { @@ -267,6 +268,9 @@ export default function (pi) { } pi.events.on("herdr:blocked", (data) => { + if (!rootSession) { + return; + } if (!data?.active) { blockedCount = Math.max(0, blockedCount - 1); if (blockedCount === 0) { @@ -283,11 +287,18 @@ export default function (pi) { }); pi.on("session_start", (_event, ctx) => { + rootSession = ctx?.hasUI === true; + if (!rootSession) { + return; + } updateSessionRef(ctx); publishState(true); }); pi.on("agent_start", () => { + if (!rootSession) { + return; + } clearPendingTimers(); clearFailureState(); agentActive = true; @@ -295,6 +306,9 @@ export default function (pi) { }); pi.on("agent_end", (event) => { + if (!rootSession) { + return; + } if (!agentActive) { // OMP can emit duplicate/late end events while auto-retry is already // holding the pane in Working. Do not let an unqualified duplicate end @@ -314,6 +328,9 @@ export default function (pi) { }); pi.on("session_shutdown", async () => { + if (!rootSession) { + return; + } clearPendingTimers(); await releaseAgent(); }); diff --git a/src/integration/mod.rs b/src/integration/mod.rs index d4c7265b..59eaebd9 100644 --- a/src/integration/mod.rs +++ b/src/integration/mod.rs @@ -6034,6 +6034,29 @@ mod tests { assert!(!CURSOR_HOOK_ASSET.contains("pane.release_agent")); } + #[test] + fn omp_root_session_guard_is_instance_scoped() { + let export_start = OMP_EXTENSION_ASSET + .find("export default function (pi)") + .expect("omp extension exports a function"); + let root_session_decl = OMP_EXTENSION_ASSET + .find("let rootSession = false") + .expect("omp extension declares root session guard"); + let session_start_handler = OMP_EXTENSION_ASSET + .find("pi.on(\"session_start\"") + .expect("omp extension registers session_start handler"); + + assert_eq!( + OMP_EXTENSION_ASSET + .matches("let rootSession = false") + .count(), + 1 + ); + assert!(OMP_EXTENSION_ASSET.contains("rootSession = ctx?.hasUI === true")); + assert!(export_start < root_session_decl); + assert!(root_session_decl < session_start_handler); + } + #[test] fn install_qodercli_writes_hook_and_updates_settings() { let _lock = integration_env_lock();