From 9dc4a358d334659b49f8903dae9d400a2ed1aeab Mon Sep 17 00:00:00 2001 From: joshavant <830519+joshavant@users.noreply.github.com> Date: Fri, 7 Aug 2026 13:52:02 -0500 Subject: [PATCH] Revert "fix(audit): keep source adoption schema first-use" This reverts commit 4244630ccf618c7b9e71a16c95d8d1f47a5c3396. --- src/audit/audit-event-source-adoption.test.ts | 31 ++++++++++--------- src/state/openclaw-state-db-contract.ts | 6 ++-- src/state/openclaw-state-db.test.ts | 18 +++-------- 3 files changed, 24 insertions(+), 31 deletions(-) diff --git a/src/audit/audit-event-source-adoption.test.ts b/src/audit/audit-event-source-adoption.test.ts index 19a3d3c452b0..a5ef46de08a1 100644 --- a/src/audit/audit-event-source-adoption.test.ts +++ b/src/audit/audit-event-source-adoption.test.ts @@ -9,20 +9,11 @@ import type { AuditEventInput } from "./audit-event-types.js"; const tempDirs = useAutoCleanupTempDirTracker(afterEach); const AUDIT_EVENT_RETENTION_MS_CONTRACT = 30 * 24 * 60 * 60_000; -const ADOPTION_TABLE_QUERY = - "SELECT 1 AS ok FROM sqlite_master WHERE type = 'table' AND name = 'audit_event_source_adoptions'"; function createDatabaseOptions() { return { env: { OPENCLAW_STATE_DIR: tempDirs.make("openclaw-audit-adoption-") } }; } -function expectAdoptionTableAbsent(database: ReturnType): void { - expect( - openOpenClawStateDatabase(database).db.prepare(ADOPTION_TABLE_QUERY).get(), - ).toBeUndefined(); - closeOpenClawStateDatabaseForTest(); -} - function auditInput(overrides: Partial = {}): AuditEventInput { const input = { sourceSequence: 1, @@ -61,7 +52,9 @@ describe("audit event source adoption", () => { database, ), ).toBeDefined(); - expectAdoptionTableAbsent(database); + const { db: legacyDb } = openOpenClawStateDatabase(database); + legacyDb.exec("DROP TABLE audit_event_source_adoptions"); + closeOpenClawStateDatabaseForTest(); expect( recordAuditEvent( @@ -130,7 +123,9 @@ describe("audit event source adoption", () => { toolCallId: "call-1", }); expect(recordAuditEvent(legacyInput, database)).toBeDefined(); - expectAdoptionTableAbsent(database); + const { db: legacyDb } = openOpenClawStateDatabase(database); + legacyDb.exec("DROP TABLE audit_event_source_adoptions"); + closeOpenClawStateDatabaseForTest(); const replayInput = { ...legacyInput, @@ -156,7 +151,9 @@ describe("audit event source adoption", () => { database, ), ).toBeDefined(); - expectAdoptionTableAbsent(database); + const { db: legacyDb } = openOpenClawStateDatabase(database); + legacyDb.exec("DROP TABLE audit_event_source_adoptions"); + closeOpenClawStateDatabaseForTest(); const firstVersionedSourceId = `lifecycle:generation-1:${legacySourceId}`; expect( @@ -235,10 +232,16 @@ describe("audit event source adoption", () => { it("does not materialize the lazy adoption table during cleanup", () => { const database = createDatabaseOptions(); - expectAdoptionTableAbsent(database); + const tableQuery = + "SELECT 1 AS ok FROM sqlite_master WHERE type = 'table' AND name = 'audit_event_source_adoptions'"; + const { db } = openOpenClawStateDatabase(database); + db.exec("DROP TABLE audit_event_source_adoptions"); + closeOpenClawStateDatabaseForTest(); + expect(openOpenClawStateDatabase(database).db.prepare(tableQuery).get()).toBeUndefined(); + closeOpenClawStateDatabaseForTest(); pruneExpiredAuditEvents({ database }); - expectAdoptionTableAbsent(database); + expect(openOpenClawStateDatabase(database).db.prepare(tableQuery).get()).toBeUndefined(); }); }); diff --git a/src/state/openclaw-state-db-contract.ts b/src/state/openclaw-state-db-contract.ts index e4fbbe834d48..6ca8a14b8a5e 100644 --- a/src/state/openclaw-state-db-contract.ts +++ b/src/state/openclaw-state-db-contract.ts @@ -7,15 +7,13 @@ export const OPENCLAW_STATE_SCHEMA_VERSION = 6; export const OPENCLAW_STATE_STRICT_SCHEMA_VERSION = 3; // Privacy-sensitive feature tables remain absent even in fresh databases until // their feature-local first write. The canonical SQL still owns their shape. -export const FIRST_USE_STATE_TABLES = [ - "audit_event_source_adoptions", - "execution_identity_contexts", -] as const; +export const FIRST_USE_STATE_TABLES = ["execution_identity_contexts"] as const; export const FIRST_USE_STATE_INDEXES = ["execution_identity_contexts_run_created_idx"] as const; // Added after v6 shipped. These tables stay optional until their feature-local // lazy ensures run; fold them into the next natural schema-version bump. export const LAZY_ADDITIVE_STATE_TABLES = [ ...FIRST_USE_STATE_TABLES, + "audit_event_source_adoptions", "model_catalog_remote", "sidebar_sections", "skill_workshop_proposal_events", diff --git a/src/state/openclaw-state-db.test.ts b/src/state/openclaw-state-db.test.ts index dba42debce5a..2b0fa2fa9830 100644 --- a/src/state/openclaw-state-db.test.ts +++ b/src/state/openclaw-state-db.test.ts @@ -68,16 +68,6 @@ function createInitialStateSchemaShape() { return shape; } -function expectFirstUseStateTablesAbsent(database: DatabaseSync): void { - for (const tableName of FIRST_USE_STATE_TABLES) { - expect( - database - .prepare("SELECT name FROM sqlite_schema WHERE type = 'table' AND name = ?") - .get(tableName), - ).toBeUndefined(); - } -} - function expectStateSchemaMigrationRequired( run: () => unknown, expected: { @@ -1101,7 +1091,11 @@ describe("openclaw state database", () => { }); expect(collectSqliteSchemaShape(database.db)).toEqual(createInitialStateSchemaShape()); - expectFirstUseStateTablesAbsent(database.db); + expect( + database.db + .prepare("SELECT name FROM sqlite_schema WHERE type = 'table' AND name = ?") + .get("execution_identity_contexts"), + ).toBeUndefined(); expect(database.path).toBe(path.join(stateDir, "state", "openclaw.sqlite")); expect( database.db @@ -3431,7 +3425,6 @@ INSERT INTO macos_port_guardian_records VALUES (4242, 18789, '/usr/bin/ssh', 're requester_agent_id: "main", }); expect(collectSqliteSchemaShape(db)).toEqual(expectedShape); - expectFirstUseStateTablesAbsent(db); } finally { db.close(); } @@ -3457,7 +3450,6 @@ INSERT INTO macos_port_guardian_records VALUES (4242, 18789, '/usr/bin/ssh', 're db.prepare("SELECT schema_version FROM schema_meta WHERE meta_key = 'primary'").get(), ).toEqual({ schema_version: OPENCLAW_STATE_SCHEMA_VERSION }); expect(collectSqliteSchemaShape(db)).toEqual(expectedShape); - expectFirstUseStateTablesAbsent(db); } finally { db.close(); }