fix: isolate omp hook state to ui sessions

refs #614
This commit is contained in:
Ogulcan Celik 2026-06-16 18:25:02 +03:00
parent ebff34063a
commit 5ffaf4f32b
2 changed files with 40 additions and 0 deletions

View File

@ -197,6 +197,7 @@ export default function (pi) {
let lastMessage: string | undefined;
let idleTimer: ReturnType<typeof setTimeout> | undefined;
let retryTimer: ReturnType<typeof setTimeout> | undefined;
let rootSession = false;
function clearTimer(timer: ReturnType<typeof setTimeout> | 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();
});

View File

@ -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();