aboutsummaryrefslogtreecommitdiff
path: root/src/integration/assets/omp
diff options
context:
space:
mode:
authorOgulcan Celik <ogulcancelik@gmail.com>2026-06-16 17:57:24 +0300
committerOgulcan Celik <ogulcancelik@gmail.com>2026-06-16 17:57:52 +0300
commitebff34063a55446c7390e12ec84acd2dad04ce43 (patch)
tree0ed8f092d418d245fd69ac0d36e21ee1e3ef1a83 /src/integration/assets/omp
parentcc802c8f9c154ca23e6a1db095b8857c1d5f1fe9 (diff)
fix: restore omp sessions after same-pane restart
refs #614
Diffstat (limited to 'src/integration/assets/omp')
-rw-r--r--src/integration/assets/omp/herdr-agent-state.ts44
1 files changed, 37 insertions, 7 deletions
diff --git a/src/integration/assets/omp/herdr-agent-state.ts b/src/integration/assets/omp/herdr-agent-state.ts
index 9229436b..c2bec682 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=2
+// HERDR_INTEGRATION_VERSION=3
// @ts-nocheck
import { createConnection } from "node:net";
@@ -53,12 +53,41 @@ const retryGraceMs = parseDurationEnv("HERDR_OMP_RETRY_GRACE_MS", 2500);
const retryableErrorPattern =
/overloaded|provider.?returned.?error|rate.?limit|too many requests|429|500|502|503|504|service.?unavailable|server.?error|internal.?error|network.?error|connection.?error|connection.?refused|connection.?lost|websocket.?closed|websocket.?error|other side closed|fetch failed|upstream.?connect|reset before headers|socket hang up|ended without|http2 request did not get a response|timed? out|timeout|terminated|retry delay/i;
let reportSeq = Date.now() * 1000;
+let currentAgentSessionId: string | undefined;
+let currentAgentSessionPath: string | undefined;
function nextReportSeq(): number {
reportSeq += 1;
return reportSeq;
}
+function updateSessionRef(ctx: any): void {
+ try {
+ const file = ctx?.sessionManager?.getSessionFile?.();
+ currentAgentSessionPath =
+ typeof file === "string" && file.startsWith("/") ? file : undefined;
+ } catch {
+ currentAgentSessionPath = undefined;
+ }
+
+ try {
+ const id = ctx?.sessionManager?.getSessionId?.();
+ currentAgentSessionId = typeof id === "string" && id.length > 0 ? id : undefined;
+ } catch {
+ currentAgentSessionId = undefined;
+ }
+}
+
+function withSessionRef(params: Record<string, unknown>): Record<string, unknown> {
+ if (currentAgentSessionPath) {
+ return { ...params, agent_session_path: currentAgentSessionPath };
+ }
+ if (currentAgentSessionId) {
+ return { ...params, agent_session_id: currentAgentSessionId };
+ }
+ return params;
+}
+
function parseDurationEnv(name: string, fallback: number): number {
const raw = process.env[name];
if (!raw) {
@@ -75,14 +104,14 @@ function sendState(state: AgentState, message?: string, seq = nextReportSeq()):
return sendRequest({
id: `${source}:${Date.now()}:${Math.random().toString(36).slice(2)}`,
method: "pane.report_agent",
- params: {
+ params: withSessionRef({
pane_id: paneId,
source,
agent: "omp",
state,
message,
seq,
- },
+ }),
});
}
@@ -201,9 +230,9 @@ export default function (pi) {
return { state: "idle" as const, message: undefined };
}
- function publishState() {
+ function publishState(force = false) {
const next = desiredState();
- if (next.state === lastState && next.message === lastMessage) {
+ if (!force && next.state === lastState && next.message === lastMessage) {
return;
}
lastState = next.state;
@@ -253,8 +282,9 @@ export default function (pi) {
publishState();
});
- pi.on("session_start", () => {
- publishState();
+ pi.on("session_start", (_event, ctx) => {
+ updateSessionRef(ctx);
+ publishState(true);
});
pi.on("agent_start", () => {