Skip to content

Commit 31bbe02

Browse files
committed
fix(parser): use real content digest for Shelley skip
Replace the additive/byte-length Shelley change signal with two per-conversation signals so the sync skip cannot miss a rewrite: - file_mtime stays the conversation's real updated_at timestamp. It must remain a true timestamp because ListSessionsModifiedBetween filters file_mtime <= now for PG/DuckDB push; a synthetic future value dropped a just-synced Shelley row from a same-second push until a later run. - file_hash holds a content digest over the conversation's messages, computed identically by the meta skip query and the parse loop. It is length-framed, so it detects appends, in-place rewrites, and length-preserving same-second edits that a byte-length signal misses. The bulk skip now compares the stored file_hash via GetFileHashByPath alongside file_mtime. Computing the digest reads message payloads, which the sub-second-timestamped siblings (Zed, Kiro) avoid; Shelley's second-precision updated_at makes the read the price of not silently skipping a rewrite. ShelleySourceMtime keeps a watcher-only change signal (updated_at plus a sub-second digest term), compared for inequality and never range-filtered.
1 parent 9a52b29 commit 31bbe02

5 files changed

Lines changed: 268 additions & 157 deletions

File tree

internal/db/sessions.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,6 +1517,25 @@ func (db *DB) GetFileInfoByPath(
15171517
return s.Int64, m.Int64, true
15181518
}
15191519

1520+
// GetFileHashByPath returns the stored file_hash for the session
1521+
// matching file_path, preferring the most recently modified row.
1522+
// The bool is false when no row exists or the column is NULL. Used
1523+
// by the Shelley skip to compare a per-conversation content
1524+
// fingerprint alongside file_mtime.
1525+
func (db *DB) GetFileHashByPath(path string) (hash string, ok bool) {
1526+
var h sql.NullString
1527+
err := db.getReader().QueryRow(
1528+
"SELECT file_hash FROM sessions"+
1529+
" WHERE file_path = ?"+
1530+
" ORDER BY file_mtime DESC LIMIT 1",
1531+
path,
1532+
).Scan(&h)
1533+
if err != nil {
1534+
return "", false
1535+
}
1536+
return h.String, h.Valid
1537+
}
1538+
15201539
// GetDataVersionByPath returns the minimum data_version for
15211540
// sessions matching a file_path. Returns 0 when no session
15221541
// exists for the path.

0 commit comments

Comments
 (0)