Skip to content

Commit e7e7a4e

Browse files
committed
fix(scope): listScopeChanges 排序 tiebreaker 改 rowid——同毫秒 decided_at 打平时 UUID 序随机(CI windows/node24 实抓 flake)
审计回放要求『最新一条』确定:decided_at 只有毫秒精度,连续两次修正落在同一 毫秒时 ORDER BY id DESC(随机 UUID)使两条审计行顺序不定。改 rowid DESC (追加写入的单调序),语义不变、顺序确定。
1 parent 711a1df commit e7e7a4e

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

‎dsh-mneme/lib/store.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1777,8 +1777,11 @@ export function createStore(path) {
17771777
/** Scope 修正审计(单条记忆,新→旧)。审计回放与候选复核用。 */
17781778
function listScopeChanges(memoryId, { limit = 50 } = {}) {
17791779
const lim = Number.isInteger(limit) && limit > 0 ? Math.min(limit, 200) : 50;
1780+
// tiebreaker 用 rowid(追加写入的单调序)而非 id:decided_at 只有毫秒精度,
1781+
// 连续两次修正落在同一毫秒时 UUID 排序是随机的(CI windows/node24 抓到的
1782+
// 真实 flake)——审计回放要求「最新一条」确定。
17801783
const rows = db.prepare(
1781-
"SELECT * FROM scope_changes WHERE memory_id = ? ORDER BY decided_at DESC, id DESC LIMIT ?"
1784+
"SELECT * FROM scope_changes WHERE memory_id = ? ORDER BY decided_at DESC, rowid DESC LIMIT ?"
17821785
).all(memoryId, lim);
17831786
return rows.map(toScopeChange);
17841787
}

‎dsh-mneme/src/store.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1777,8 +1777,11 @@ export function createStore(path) {
17771777
/** Scope 修正审计(单条记忆,新→旧)。审计回放与候选复核用。 */
17781778
function listScopeChanges(memoryId, { limit = 50 } = {}) {
17791779
const lim = Number.isInteger(limit) && limit > 0 ? Math.min(limit, 200) : 50;
1780+
// tiebreaker 用 rowid(追加写入的单调序)而非 id:decided_at 只有毫秒精度,
1781+
// 连续两次修正落在同一毫秒时 UUID 排序是随机的(CI windows/node24 抓到的
1782+
// 真实 flake)——审计回放要求「最新一条」确定。
17801783
const rows = db.prepare(
1781-
"SELECT * FROM scope_changes WHERE memory_id = ? ORDER BY decided_at DESC, id DESC LIMIT ?"
1784+
"SELECT * FROM scope_changes WHERE memory_id = ? ORDER BY decided_at DESC, rowid DESC LIMIT ?"
17821785
).all(memoryId, lim);
17831786
return rows.map(toScopeChange);
17841787
}

0 commit comments

Comments
 (0)