Skip to content
Open
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
7 changes: 5 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -1473,9 +1473,12 @@ during the wait.
- **Connection tab** (right panel, both layouts, shown while Settings → Interface & Behavior → "Show connection
diagnostics" is on, `omp-web:connection-diagnostics`, per browser). It polls the worker (`diag` op,
`requestConnectionDiagnostics`) once a second while visible: the mode in effect, fallback, status (`idle` when
no connection is needed, `down` after `SEND_DEADLINE_MS` without a connection), the last reconnect, and
no connection is needed, `down` after `SEND_DEADLINE_MS` without a connection), the last reconnect,
per-transport stats (mean, p50, p95, p99.9 from 1000 values, max) of the worker's last 30 min of samples (at most
20 000, kept beside the POST buffer). Command rows include confirmed successful replies only; app ↔ omp and round-trip rows skip commands whose reply does not confirm omp got them (`NO_OMP_REPLY_COMMANDS`: the `NO_SPAWN_REPLIES` the web app answers itself, a test keeps them included, plus the results `dispatchCommand` forwards without awaiting omp). A new command of either kind belongs there. Shared durations
20 000, kept beside the POST buffer), and the browser outbox: IndexedDB and read state, pending count, oldest age,
in-flight sends, retries, last HTTP status and error, plus the last 20 stage events (`stored`, `read`, `dispatch`,
`response`, `accepted`, `retry`, `failed`). Events carry ids and modes only, never message text, attachments or proofs.
Command rows include confirmed successful replies only; app ↔ omp and round-trip rows skip commands whose reply does not confirm omp got them (`NO_OMP_REPLY_COMMANDS`: the `NO_SPAWN_REPLIES` the web app answers itself, a test keeps them included, plus the results `dispatchCommand` forwards without awaiting omp). A new command of either kind belongs there. Shared durations
come from `lib/transport-stats.ts`; one-way estimates use clock correction and assume symmetric latency.
Without a SharedWorker (Chrome for Android) each tab has its own worker, so the numbers are that tab's.
- **Worker rules.** Browser code: no `AbortSignal.timeout`/`any` or `Promise.withResolvers` (a test checks
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ All notable changes to **omp-web** (`@kahme247/ompweb`) are documented in this f

## [Unreleased]

### Added

- **Connection diagnostics show the browser outbox.** The Connection tab now shows IndexedDB and read state, pending messages, retries, the last HTTP status and error, and the last 20 stage events. Events include ids and modes only, never message text.

### Fixed

- **GitHub workflow watches no longer regress to stale run states.** Workflow updates retain GitHub's run timestamp and ignore older snapshots for the same or an earlier attempt, so a delayed `queued` response cannot follow a newer `in_progress` delivery.
Expand Down
27 changes: 27 additions & 0 deletions components/ConnectionDiagnostics.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const wsDiagnostics = {
effectiveType: "4g",
windowMs: 1800000,
stats: [{ transport: "ws", metric: "transportMs", count: 10, mean: 20.4, p50: 18, p95: 30, p999: null, max: 41 }],
outbox: { db: "open", read: "idle", pending: 0, oldestAgeMs: null, inFlight: 0, retries: 0, lastHttpStatus: null, lastError: null, events: [] },
};

function rightPanelProps(overrides) {
Expand Down Expand Up @@ -183,6 +184,32 @@ test("an active visible panel replaces its displayed snapshot on the next poll",
assert.equal(valueOf("Clock RTT").textContent, "3 ms");
});

test("the Connection tab shows outbox stage diagnostics without message text", async () => {
diagnostics = {
...wsDiagnostics,
outbox: {
db: "open",
read: "failed",
pending: 1,
oldestAgeMs: 12500,
inFlight: 0,
retries: 2,
lastHttpStatus: 503,
lastError: "IndexedDB read failed",
events: [{ at: 1_700_000_000_000, stage: "retry", id: "m1", sessionId: "session-1", mode: "followUp", status: 503 }],
},
};
await act(async () => render(createElement(ConnectionDiagnosticsPanel, { active: true })));
assert.equal(valueOf("Outbox database").textContent, "open");
assert.equal(valueOf("Outbox read").textContent, "failed");
assert.equal(valueOf("Pending messages").textContent, "1");
assert.equal(valueOf("Oldest pending").textContent, "13 s");
assert.equal(valueOf("Retries").textContent, "2");
assert.equal(valueOf("Last HTTP status").textContent, "503");
assert.ok(screen.getByText("retry · followUp · m1 · session-1 · HTTP 503"));
assert.equal(document.body.textContent.includes("secret prompt"), false);
});

test("inactive diagnostics retain the old snapshot, ignore a late response, and refresh on activation", async (t) => {
t.mock.timers.enable({ apis: ["setTimeout"] });
diagnostics = wsDiagnostics;
Expand Down
19 changes: 19 additions & 0 deletions components/ConnectionDiagnostics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,25 @@ function DiagnosticsBody({ diagnostics: d, now }: { diagnostics: ConnectionDiagn
<Row label={t("connectionDiagnostics.rowNetwork")}>{d.effectiveType ?? "—"}</Row>
</dl>

<div style={{ fontSize: 13, fontWeight: 600, color: "var(--text)" }}>{t("connectionDiagnostics.outboxTitle")}</div>
<dl style={{ margin: 0, display: "flex", flexDirection: "column" }}>
<Row label={t("connectionDiagnostics.rowOutboxDb")}>{d.outbox.db}</Row>
<Row label={t("connectionDiagnostics.rowOutboxRead")}>{d.outbox.read}</Row>
<Row label={t("connectionDiagnostics.rowOutboxPending")}>{d.outbox.pending}</Row>
<Row label={t("connectionDiagnostics.rowOutboxOldest")}>{d.outbox.oldestAgeMs === null ? "—" : t("connectionDiagnostics.outboxAgeSeconds", { seconds: Math.round(d.outbox.oldestAgeMs / 1000) })}</Row>
<Row label={t("connectionDiagnostics.rowOutboxInFlight")}>{d.outbox.inFlight}</Row>
<Row label={t("connectionDiagnostics.rowOutboxRetries")}>{d.outbox.retries}</Row>
<Row label={t("connectionDiagnostics.rowOutboxStatus")}>{d.outbox.lastHttpStatus ?? "—"}</Row>
<Row label={t("connectionDiagnostics.rowOutboxError")}>{d.outbox.lastError ?? "—"}</Row>
</dl>
<div style={{ display: "flex", flexDirection: "column", gap: 4, color: "var(--text-muted)" }}>
{d.outbox.events.length === 0 ? <div>{t("connectionDiagnostics.outboxNoEvents")}</div> : d.outbox.events.map((event, index) => (
<div key={`${event.at}-${event.stage}-${event.id}-${index}`}>
{t("connectionDiagnostics.outboxEvent", { stage: event.stage, mode: event.mode, id: event.id || "—", session: event.sessionId || "—", status: event.status ?? "—" })}
</div>
))}
</div>

<div style={{ display: "flex", flexDirection: "column", gap: 12 }}>
{groups.length === 0 && <div style={{ color: "var(--text-dim)" }}>{t("connectionDiagnostics.noSamples")}</div>}
{groups.map((group) => (
Expand Down
2 changes: 1 addition & 1 deletion graphify-out/graph.json

Large diffs are not rendered by default.

27 changes: 27 additions & 0 deletions lib/event-stream-protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,32 @@ export interface BrowserTransportState {
/** Why the worker fell back to SSE: proxies refused the upgrade, or the server speaks another link version. */
export type FallbackReason = "refused" | "version";

export type OutboxDiagnosticStage = "stored" | "read" | "dispatch" | "response" | "accepted" | "retry" | "failed";

/** One outbox transition. Never includes message text, attachments, proofs, or credentials. */
export interface OutboxDiagnosticEvent {
at: number;
stage: OutboxDiagnosticStage;
id: string;
sessionId: string;
mode: "prompt" | "followUp" | "steer";
status?: number;
error?: string;
}

export interface OutboxDiagnostics {
db: "opening" | "open" | "unavailable";
read: "idle" | "reading" | "failed";
pending: number;
oldestAgeMs: number | null;
inFlight: number;
retries: number;
lastHttpStatus: number | null;
lastError: string | null;
/** Newest first, at most 20. */
events: OutboxDiagnosticEvent[];
}

export interface ConnectionDiagnostics {
/** The server's setting. */
setting: BrowserTransport;
Expand All @@ -73,6 +99,7 @@ export interface ConnectionDiagnostics {
effectiveType: string | null;
windowMs: number;
stats: DiagnosticStat[];
outbox: OutboxDiagnostics;
}

export const BROWSER_LINK_PATH = "/api/events/link";
Expand Down
99 changes: 99 additions & 0 deletions lib/event-stream-worker.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2982,6 +2982,105 @@ test("outbox: over SSE the worker POSTs outbox_add itself", async () => {
assert.equal(idb.entries.size, 0);
});

test("diag: SSE outbox stages show storage, dispatch, retry and acceptance without message text", async (t) => {
t.mock.timers.enable(TIMERS);
const idb = fakeIndexedDB();
let status = 503;
const worker = loadWorker({
indexedDB: idb,
respond: () => ({ status, body: status === 200 ? acceptedM1 : { error: "host refused the private prompt" } }),
});
const tab = worker.connectTab();
tab.send({ op: "outbox_add", n: 1, entry: { ...outboxEntry("m1"), message: "secret prompt", mode: "followUp" } });
await flush();

const stalled = diag(tab, 1).outbox;
assert.equal(stalled.db, "open");
assert.equal(stalled.read, "idle");
assert.equal(stalled.pending, 1);
assert.equal(stalled.inFlight, 0);
assert.equal(stalled.retries, 1);
assert.equal(stalled.lastHttpStatus, 503);
assert.equal(stalled.lastError, "host refused the private prompt");
assert.deepEqual(stalled.events.map((event) => event.stage), ["retry", "response", "dispatch", "stored"]);
assert.deepEqual(stalled.events.map((event) => event.mode), ["followUp", "followUp", "followUp", "followUp"]);
assert.equal(JSON.stringify(stalled).includes("secret prompt"), false);

status = 200;
t.mock.timers.tick(1_000);
await flush();
const delivered = diag(tab, 2).outbox;
assert.equal(delivered.pending, 0);
assert.equal(delivered.lastHttpStatus, 200);
assert.equal(delivered.lastError, null);
assert.equal(delivered.events[0].stage, "accepted");
});

test("diag: a failed initial IndexedDB read stays failed until a later read succeeds", async (t) => {
t.mock.timers.enable(TIMERS);
const idb = fakeIndexedDB();
idb.failReads = true;
const worker = loadWorker({ indexedDB: idb, respond: () => ({ status: 503, body: {} }) });
const tab = worker.connectTab();
await flush();
assert.equal(diag(tab, 1).outbox.read, "failed");
assert.equal(diag(tab, 1).outbox.events.some((event) => event.stage === "read"), true);

idb.failReads = false;
tab.send({ op: "outbox_add", n: 1, entry: outboxEntry("m1") });
await flush();
assert.equal(diag(tab, 2).outbox.read, "idle");
});

test("diag: an empty recovery read clears a failed initial read", async () => {
const idb = fakeIndexedDB();
idb.failReads = true;
const worker = loadWorker({ indexedDB: idb });
worker.connectTab();
await flush();
idb.failReads = false;
const tab = worker.connectTab();
await flush();
assert.equal(diag(tab, 1).outbox.read, "idle");
assert.equal(tab.received.some((message) => message.partial === true), false);
});

test("diag: an IndexedDB deletion failure keeps HTTP 200 and still retries", async (t) => {
t.mock.timers.enable(TIMERS);
const idb = fakeIndexedDB();
let status = 503;
const worker = loadWorker({ indexedDB: idb, respond: () => ({ status, body: status === 200 ? acceptedM1 : {} }) });
const tab = worker.connectTab();
tab.send({ op: "outbox_add", n: 1, entry: outboxEntry("m1") });
await flush();
status = 200;
idb.failWrites = true;
t.mock.timers.tick(1_000);
await flush();
const stalled = diag(tab, 1).outbox;
assert.equal(stalled.lastHttpStatus, 200);
assert.equal(stalled.events[0].error, "IndexedDB write failed");
assert.equal(stalled.events[0].status, 200);
assert.equal(idb.entries.has("m1"), true);
idb.failWrites = false;
t.mock.timers.tick(2_000);
await flush();
assert.equal(idb.entries.has("m1"), false);
});

test("diag: an invalid 200 receipt keeps HTTP 200 and names the receipt", async () => {
const idb = fakeIndexedDB();
const worker = loadWorker({ indexedDB: idb, respond: () => ({ status: 200, body: { success: true } }) });
const tab = worker.connectTab();
tab.send({ op: "outbox_add", n: 1, entry: outboxEntry("m1") });
await flush();
const retry = diag(tab, 1).outbox.events[0];
assert.equal(diag(tab, 1).outbox.lastHttpStatus, 200);
assert.equal(retry.stage, "retry");
assert.equal(retry.status, 200);
assert.equal(retry.error, "Invalid acceptance receipt");
});

test("outbox: a 503 or no answer keeps it sending and retries after 1 s doubling; a wake sends it at once", async (t) => {
t.mock.timers.enable(TIMERS);
const idb = fakeIndexedDB();
Expand Down
Loading