From 3c7327c267a352023797c8a13fd0b7f4a7a40591 Mon Sep 17 00:00:00 2001 From: Dillon Mulroy Date: Thu, 25 Jun 2026 10:59:17 -0400 Subject: fix: avoid pi release on internal session reloads (#800) * fix: avoid pi release on internal session reloads * fix: align omp session shutdown release with pi --------- Co-authored-by: Can Celik --- src/integration/assets/omp/herdr-agent-state.ts | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) (limited to 'src/integration/assets/omp') diff --git a/src/integration/assets/omp/herdr-agent-state.ts b/src/integration/assets/omp/herdr-agent-state.ts index ba97b1c7..e0cfab5e 100644 --- a/src/integration/assets/omp/herdr-agent-state.ts +++ b/src/integration/assets/omp/herdr-agent-state.ts @@ -2,7 +2,7 @@ // managed by herdr; reinstalling or updating the integration overwrites this file. // add custom hooks/plugins beside this file instead of editing it. // HERDR_INTEGRATION_ID=omp -// HERDR_INTEGRATION_VERSION=3 +// HERDR_INTEGRATION_VERSION=4 // @ts-nocheck import { createConnection } from "node:net"; @@ -157,6 +157,16 @@ function releaseAgent(): Promise { }); } +function shouldReleaseOnSessionShutdown(event: any): boolean { + // OMP tears down and rebinds extension runtimes for internal lifecycle actions + // such as /reload, /new, /resume, and /fork. Those do not mean the pane's + // agent process has exited, and releasing hook authority there can suppress + // legitimate reports from the replacement runtime. Only a user/process quit + // should release Herdr's full-lifecycle authority. + const reason = event?.reason; + return reason === "quit"; +} + let sendInFlight = false; let queuedState: QueuedState | undefined; @@ -325,10 +335,12 @@ export default function (pi) { publishState(true); }); - pi.on("agent_start", () => { + pi.on("agent_start", (_event, ctx) => { if (!rootSession) { return; } + updateSessionRef(ctx); + void reportSession(); clearPendingTimers(); clearFailureState(); agentActive = true; @@ -357,11 +369,13 @@ export default function (pi) { scheduleIdle(); }); - pi.on("session_shutdown", async () => { + pi.on("session_shutdown", async (event) => { if (!rootSession) { return; } clearPendingTimers(); - await releaseAgent(); + if (shouldReleaseOnSessionShutdown(event)) { + await releaseAgent(); + } }); } -- cgit v1.2.3