diff options
| author | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-21 02:38:14 +0300 |
|---|---|---|
| committer | Ogulcan Celik <ogulcancelik@gmail.com> | 2026-06-21 02:42:39 +0300 |
| commit | 92a10fc044d42b216317696a4e8e6f70d7cc7a7d (patch) | |
| tree | a45fb881c85e66ff8641fa84bb2a1bf0ead584ed /src/integration/assets/omp | |
| parent | 73b137a4ae75cb1465e8d4ddfc293ff7366d8133 (diff) | |
fix: protect root agent restore sessions
refs #712
Diffstat (limited to 'src/integration/assets/omp')
| -rw-r--r-- | src/integration/assets/omp/herdr-agent-state.ts | 55 |
1 files changed, 32 insertions, 23 deletions
diff --git a/src/integration/assets/omp/herdr-agent-state.ts b/src/integration/assets/omp/herdr-agent-state.ts index a6428cdd..a933e867 100644 --- a/src/integration/assets/omp/herdr-agent-state.ts +++ b/src/integration/assets/omp/herdr-agent-state.ts @@ -100,6 +100,35 @@ function parseDurationEnv(name: string, fallback: number): number { return parsed; } +function currentSessionRef(): Record<string, unknown> | undefined { + if (currentAgentSessionPath) { + return { agent_session_path: currentAgentSessionPath }; + } + if (currentAgentSessionId) { + return { agent_session_id: currentAgentSessionId }; + } + return undefined; +} + +function reportSession(): Promise<void> { + const sessionRef = currentSessionRef(); + if (!sessionRef) { + return Promise.resolve(); + } + + return sendRequest({ + id: `${source}:session:${Date.now()}:${Math.random().toString(36).slice(2)}`, + method: "pane.report_agent_session", + params: { + pane_id: paneId, + source, + agent: "omp", + seq: nextReportSeq(), + ...sessionRef, + }, + }); +} + function sendState(state: AgentState, message?: string, seq = nextReportSeq()): Promise<void> { return sendRequest({ id: `${source}:${Date.now()}:${Math.random().toString(36).slice(2)}`, @@ -169,19 +198,6 @@ function retryableErrorMessage(event: any): string | undefined { return errorMessage || "retryable provider error"; } -function releaseAgent(): Promise<void> { - return sendRequest({ - id: `${source}:release:${Date.now()}:${Math.random().toString(36).slice(2)}`, - method: "pane.release_agent", - params: { - pane_id: paneId, - source, - agent: "omp", - seq: nextReportSeq(), - }, - }); -} - export default function (pi) { if (!enabled()) { return; @@ -287,11 +303,12 @@ export default function (pi) { }); pi.on("session_start", (_event, ctx) => { - rootSession = ctx?.hasUI === true; - if (!rootSession) { + if (ctx?.hasUI !== true) { return; } + rootSession = true; updateSessionRef(ctx); + void reportSession(); publishState(true); }); @@ -326,12 +343,4 @@ export default function (pi) { scheduleIdle(); }); - - pi.on("session_shutdown", async () => { - if (!rootSession) { - return; - } - clearPendingTimers(); - await releaseAgent(); - }); } |
