00a1b4528f25
keep incoming event IDs so a strip is applied once, not on every steal (3.0.3)
- time
- 2026-09-23 21:16 UTC · 2 weeks ago
- machine
- koh2
- agent
- claude-opus-5-5
- session
- koh 3 review fixes
- parent
- 4149f626ab4a
↓ koh-00a1b452.tar.gzatlas at this save
files changed5 files
VERSION+1 −1src/events/events.v+8 −0src/sync/sync.v+3 −1src/sync/sync_test.v+13 −0v.mod+1 −1src/events/events.v+8 −0
@@ -85,6 +85,14 @@8585 return record8686 }8787 88+// receive stores an event exactly as another machine recorded it, ID and all.89+// Re-deriving the ID here would disagree with `write_once` for strips, and the90+// event would come back as new on every steal. Reports whether it was new.91+pub fn receive(store &storage.Store, event Event) !bool {92+ insert(store, event)!93+ return store.db.changes() > 094+}95+8896 fn next_timestamp(store &storage.Store) !i64 {8997 now := time.now().unix()9098 mut stmt := store.db.prepare('SELECT MAX(created_at) FROM events')!src/sync/sync.v+3 −1
@@ -209,7 +209,9 @@209209 history.import_save(store, to_save(record), to_files(record))!210210 }211211 for event in fetched.events_out {212- events.write(store, event)!212+ if !events.receive(store, event)! {213+ continue214+ }213215 if event.kind == events.kind_strip {214216 // Somebody stripped a path: remove it here too, so the two215217 // histories agree from now on.src/sync/sync_test.v+13 −0
@@ -576,4 +576,17 @@576576 }577577 assert 'secrets.env' !in paths578578 assert 'keep.txt' in paths579+580+ // The event arrives under its own ID, so it is applied once: B's offer adds581+ // no second copy, and a file B saves again after the strip stays saved582+ // through B's next steal.583+ assert events.strip_events(b)!.map(it.id) == events.strip_events(a)!.map(it.id)584+ put(b.root, 'secrets.env', 'rotated\n')!585+ readded := commit(b, 'add the rotated key back')!586+ offer_now(b, mut backend)!587+ assert backend.list('proj/events')!.len == 1588+ b.begin()!589+ write_fetched(b, fetch_back_to_known(b, mut backend, 'proj')!)!590+ b.commit()!591+ assert 'secrets.env' in history.files_of(b, readded.id)!.map(it.path)579592 }v.mod+1 −1
@@ -1,6 +1,6 @@11 Module {22 name: 'koh3'3- version: '3.0.2'3+ version: '3.0.3'44 description: 'One SQLite file per repo, one line of history.'55 license: 'MIT'66 }