Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions lib/session-watcher.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";

test("session watcher watches the lister's sessions directory, not ~/.omp/agent/sessions", () => {
const source = readFileSync(new URL("./session-watcher.ts", import.meta.url), "utf8");
// Every other session consumer uses getSessionsDir(), which honors the
// XDG layout ($XDG_DATA_HOME/omp/sessions when that opt-in exists). The
// watcher previously derived the path from getAgentDir(), so under XDG it
// watched a directory the lister never reads and external session changes
// never reached the sidebar.
assert.match(source, /const sessionsDir = getSessionsDir\(\);/);
assert.doesNotMatch(source, /join\(getAgentDir\(\), "sessions"\)/);
});
9 changes: 7 additions & 2 deletions lib/session-watcher.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { watch, type FSWatcher } from "fs";
import { join } from "path";
import {
getAgentDir,
invalidateSessionEntriesCache,
invalidateSessionListCache,
invalidateSessionListMeta,
listAllSessions,
resolveSessionIdByPath,
} from "./session-reader";
import { getSessionsDir } from "./omp/paths";

// omp owns the writes to a session's JSONL. ompweb streams RPC events only for
// the sessions it spawned itself, so a session started outside the web UI — by
Expand Down Expand Up @@ -94,7 +94,12 @@ function scheduleRetry(): void {

function ensureWatcher(): void {
if (watcher || retryTimer) return;
const sessionsDir = join(getAgentDir(), "sessions");
// Watch the directory the session lister actually reads. Deriving this
// from getAgentDir() broke the XDG layout ($XDG_DATA_HOME/omp/sessions):
// the watcher then watched ~/.omp/agent/sessions, so external session
// changes never reached the sidebar for XDG users (or it retried a
// nonexistent directory forever).
const sessionsDir = getSessionsDir();
try {
watcher = watch(sessionsDir, { recursive: true, persistent: false }, (_event, filename) => {
if (!filename) {
Expand Down
Loading