From d32e35d2b2bcaf597ae498c4291fbf74f0045cb4 Mon Sep 17 00:00:00 2001 From: huangruiteng <14976749+huangruiteng@users.noreply.github.com> Date: Mon, 28 Sep 2026 01:47:09 +0800 Subject: [PATCH] fix(authority): use streaming verifier for SQLite operation replay Signed-off-by: huangruiteng <14976749+huangruiteng@users.noreply.github.com> --- .../coordination/sqlite_authority_store.ts | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/loopx/control_plane/coordination/sqlite_authority_store.ts b/loopx/control_plane/coordination/sqlite_authority_store.ts index 845af4753..024222d73 100644 --- a/loopx/control_plane/coordination/sqlite_authority_store.ts +++ b/loopx/control_plane/coordination/sqlite_authority_store.ts @@ -454,16 +454,22 @@ export class SqliteAuthorityStore implements AuthorityStore { .get(normalized.operation_id); if (existingRow) { const retained = this.decodeCommitRow(existingRow); - const window = this.verifiedRange(db, retained.cursor, retained.cursor); - const original = window.transactions[0]; - if (!original || original.operation_id !== normalized.operation_id) { - protocol("SQLite replay is not part of its retained window"); - } - const digest = commitDigest(window.identity, retained.cursor, normalized.operation_id, - normalized.next_projection, normalized.events, normalized.receipts); - if (digest === retained.commit_digest) { + let verified = false; + let replayResult: AuthorityStoreCommitResult | null = null; + this.verifiedRange(db, retained.cursor, retained.cursor, (row, _replay, identity) => { + if (row.operation_id !== normalized.operation_id) { + protocol("SQLite replay is not part of its retained window"); + } + verified = true; + const digest = commitDigest(identity, row.cursor, normalized.operation_id, + normalized.next_projection, normalized.events, normalized.receipts); + if (digest === row.commit_digest) replayResult = {status: "applied", + provider_revision: `${identity}:${row.cursor}`, cursor: row.cursor.toString()}; + }); + if (!verified) protocol("SQLite replay is not part of its retained window"); + if (replayResult) { db.exec("ROLLBACK"); transactionOpen = false; - return {status: "applied", provider_revision: original.provider_revision, cursor: original.cursor}; + return replayResult; } conflict = "operation_id_exists"; }