Skip to content

armgit / mso

Public Imported from GitHub
0

Browser-based graphical shell and control plane for a Linux server you own — real terminal, file manager, live metrics and BYOK AI in one mobile-first workspace. Next.js 16 · React 19 · node-pty · Tailwind v4 · shadcn/ui. Public alpha, self-hosted.

perf(mcp): bound active session refresh to live leases

Rahman7e0ee4965fb6
diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 03d2c268..409fa896 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -24,6 +24,10 @@ this is the *what*, and it is what Settings → About shows as “What's new”.
- keep the session mode badge clear of mobile navigation
- harden audited execution, integrations and release journeys
+**Faster**
+
+- `mcp` bound active session refresh to live leases
+
**Changed**
- `gateway` keep provisional readiness with pending lifecycle
diff --git a/docs/PROGRESS.md b/docs/PROGRESS.md
index 832d15cb..71caa096 100644
--- a/docs/PROGRESS.md
+++ b/docs/PROGRESS.md
@@ -4,6 +4,7 @@
Added the third MCP tab for six-card session pagination, exact-session readable event logs,
active versus stored filters, receiver observability, and a copyable structured handover guide.
+Active refreshes read only records with a valid presence lease, avoiding full transcript-store scans.
The Owner dashboard reuses durable session/presence records; model-facing same-principal
messaging remains unchanged. Only allowlisted redacted metadata/events leave the monitor.
Keyboard tabs, mobile reflow, pagination, error recovery, scope refusal and redaction receive
diff --git a/lib/agent/session-monitor.test.ts b/lib/agent/session-monitor.test.ts
index 3a8eae4a..7cba7395 100644
--- a/lib/agent/session-monitor.test.ts
+++ b/lib/agent/session-monitor.test.ts
@@ -25,17 +25,18 @@ beforeEach(() => { vi.clearAllMocks(); mocks.connected.mockReturnValue(false); }
describe("owner session monitor", () => {
it("paginates mixed MCP/CLI active sessions six at a time without leaking private records", async () => {
const rows = Array.from({ length: 9 }, (_, i) => record(i));
- mocks.records.mockResolvedValue(rows); mocks.presence.mockResolvedValue(rows.map(row => presence(row)));
+ mocks.records.mockResolvedValue(rows); mocks.read.mockImplementation(async id => rows.find(row => row.id === id) || null); mocks.presence.mockResolvedValue(rows.map(row => presence(row)));
const first = await ownerSessionPage(1), second = await ownerSessionPage(2);
expect(first.sessions).toHaveLength(6); expect(second.sessions).toHaveLength(3);
expect(first.total).toBe(9); expect(first.pages).toBe(2);
+ expect(mocks.records).not.toHaveBeenCalled();
expect(new Set([...first.sessions, ...second.sessions].map(row => row.id)).size).toBe(9);
expect(first.sessions.map(row => row.source)).toContain("cli"); expect(first.sessions.map(row => row.source)).toContain("mcp");
expect(JSON.stringify(first)).not.toMatch(/principalHash|private transcript|private-memory|history/);
});
it("separates expired/ended leases and mismatched principals from active receivers", async () => {
const rows = Array.from({ length: 5 }, (_, i) => record(i));
- mocks.records.mockResolvedValue(rows); mocks.presence.mockResolvedValue([
+ mocks.records.mockResolvedValue(rows); mocks.read.mockImplementation(async id => rows.find(row => row.id === id) || null); mocks.presence.mockResolvedValue([
presence(rows[0]), presence(rows[1], { leaseUntil: new Date(0).toISOString() }),
presence(rows[2], { state: "ended" }), presence(rows[3], { principalHash: "b".repeat(64) }),
]);
diff --git a/lib/agent/session-monitor.ts b/lib/agent/session-monitor.ts
index 2d1fd457..c7811047 100644
--- a/lib/agent/session-monitor.ts
+++ b/lib/agent/session-monitor.ts
@@ -29,8 +29,17 @@ function pagination(total: number, requested: number, pageSize: number) {
}
/** Owner dashboard only. Model-facing directory remains strictly principal-scoped. */
export async function ownerSessionPage(requested = 1, includeOffline = false): Promise<SessionPage> {
- const [records, presence] = await Promise.all([listSessionRecords(), listLocalAgentPresenceOwner()]);
+ const presence = await listLocalAgentPresenceOwner();
const now = Date.now(), byId = new Map(presence.map(row => [row.sessionId, row]));
+ // Active refreshes must not load thousands of inactive transcripts from disk.
+ const records: AgentSession[] = includeOffline ? await listSessionRecords() : [];
+ if (!includeOffline) {
+ for (const entry of presence) {
+ if (["offline", "ended"].includes(localAgentStatus(entry, now))) continue;
+ const record = await readSessionFile(entry.sessionId).catch(() => null);
+ if (record) records.push(record);
+ }
+ }
const all = records.map(row => card(row, byId.get(row.id), now));
const active = all.filter(row => row.status !== "offline" && row.status !== "ended");
const rows = (includeOffline ? all : active).sort((a, b) => b.lastSeenAt.localeCompare(a.lastSeenAt) || a.id.localeCompare(b.id));
diff --git a/package.json b/package.json
index 9e3f735e..9bd839f3 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "mso",
- "version": "0.2.8",
+ "version": "0.2.9",
"private": true,
"engines": {
"node": ">=20.9",