From d816689c9b04b81ff2352591b5ddfd7c9f5b39d3 Mon Sep 17 00:00:00 2001 From: hotragn Date: Mon, 14 Sep 2026 18:45:03 -0400 Subject: [PATCH] Say only the audit events this deployment can actually record MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The audit taxonomy is the trail's vocabulary, and a name in it reads as a promise that this deployment can produce that row. Four of them could not. `connector.sync_succeeded`, `connector.sync_failed`, `knowledge.searched` and `agent.invoked` are declared in `auditEventTypes` and written by nothing in `server/src`. They outlived the code that wrote them — `server/src/knowledge` and `server/src/connectors` are both empty directories now, and `git log -S` shows `knowledge.searched` arriving in #113 and its only writer leaving in #118. They stayed because the taxonomy test named them explicitly, so the list kept agreeing with itself. That is not cosmetic for an operator. The Audit screen filters by type, so filtering for `knowledge.searched` returns an empty page, and an empty page in an audit trail reads as "this did not happen" rather than "this cannot happen". A record that can say nothing is worse than a record that says nothing, because the reader cannot tell which one they are looking at. Removing them is safe to read back: the Audit UI does not enumerate `auditEventTypes` — it uses the curated `REFUSED_EVENT_TYPES` and `DID_NOT_HAPPEN_EVENT_TYPES` groups, and neither names these — and `AuditEvent.eventType` is a plain `string`, so any historical row still loads and renders. This narrows what the type is allowed to claim, not what the table is allowed to hold. The guard is the point of the change. `declares nothing this deployment cannot write` reads the event types off `server/src` rather than off a hand-kept list, because a hand-kept list is exactly what just failed. It matches literal strings only: every writer today passes the type as a literal, and a writer that computed one would fail here and should — an event type a reader cannot grep for is worse than this test being strict. Co-Authored-By: Claude Opus 5 --- server/src/audit.ts | 4 ---- server/tests/audit.test.ts | 46 +++++++++++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/server/src/audit.ts b/server/src/audit.ts index 48d181246..814a2fd23 100644 --- a/server/src/audit.ts +++ b/server/src/audit.ts @@ -49,9 +49,6 @@ export const auditEventTypes = [ */ "credential.rotation_refused", "credential.revoked", - "connector.sync_succeeded", - "connector.sync_failed", - "knowledge.searched", /** * Which coworker an untagged message was routed to, and why. * @@ -71,7 +68,6 @@ export const auditEventTypes = [ * `payload.mechanism` names how, so a later hard delete is distinguishable from this one. */ "channel.deleted", - "agent.invoked", /** * An address this deployment declined to dial for a Bot, and why. * diff --git a/server/tests/audit.test.ts b/server/tests/audit.test.ts index d55c01ad9..70d2597f6 100644 --- a/server/tests/audit.test.ts +++ b/server/tests/audit.test.ts @@ -1,5 +1,7 @@ import { describe, expect, test } from "bun:test"; +import { readdirSync, readFileSync } from "node:fs"; import { readdir, readFile } from "node:fs/promises"; +import { join } from "node:path"; import { createApp } from "../src/app"; import { auditEventTypes, @@ -32,18 +34,52 @@ const memberAuth = { }, }; +/** + * Every event type this deployment declares, it can actually write. + * + * The taxonomy is the trail's vocabulary, and a name in it is a promise that this deployment can + * produce that row. Four of them could not: `connector.sync_succeeded`, `connector.sync_failed`, + * `knowledge.searched` and `agent.invoked` outlived the document-index and connector-sync code that + * wrote them, and stayed in the list for months because the test above named them explicitly and + * nothing else asked. An operator filtering for one got an empty page that reads as "nothing + * happened" rather than "nothing can". + * + * Read off the source rather than maintained by hand, because a hand-kept list is the thing that + * just failed. Literal strings only: every writer today passes the type as a literal, and one that + * computed it would fail here and should — a row type a reader cannot grep for is worse than this + * test being strict. + */ +describe("the audit event taxonomy", () => { + test("declares nothing this deployment cannot write", () => { + const root = join(import.meta.dir, "..", "src"); + const sources: string[] = []; + const walk = (directory: string) => { + for (const entry of readdirSync(directory, { withFileTypes: true })) { + const path = join(directory, entry.name); + if (entry.isDirectory()) walk(path); + else if (entry.name.endsWith(".ts") && entry.name !== "audit.ts") { + sources.push(readFileSync(path, "utf8")); + } + } + }; + walk(root); + const everywhereElse = sources.join("\n"); + + const unwritable = auditEventTypes.filter( + (type) => !everywhereElse.includes(JSON.stringify(type)), + ); + expect(unwritable).toEqual([]); + }); +}); + describe("audit payload redaction", () => { - test("defines the v1 audit event taxonomy", () => { + test("defines the audit event taxonomy", () => { expect(auditEventTypes).toEqual( expect.arrayContaining([ "configuration.changed", "credential.created", "credential.rotated", "credential.revoked", - "connector.sync_succeeded", - "connector.sync_failed", - "knowledge.searched", - "agent.invoked", "mcp.call_succeeded", "mcp.call_rejected", ]),