feat: replicate thread membership and record merges #46

Merged
david merged 1 commits from feat/thread-links into main 2026-11-05 09:09:28 +00:00
Owner

Second half of #41. Threads replicate (#45), but arrived without their members — the replica could list a thread and not summarise it. 292 links on the server against 1,764 on the laptop.

Why membership was node-local

Two mechanisms, neither portable:

Store Key Why it can't travel
thread_observations observation_id local autoincrement
provenance_links ThreadFP(int thread id) embeds the local integer id

The replicated fact is therefore the entry-level edge: (thread_uid, entry_fingerprint), because entry fingerprints are already stable across nodes. Both local forms are materialised from it on arrival.

Details

  • LinkDoc{thread_uid, entry_fp, relation, relevance, removed}, fingerprint sha256("thread_link:"+uid|fp|relation).
  • Unlinks replicate as tombstones — without them the next reconcile would resurrect any edge that was deliberately removed.
  • Links project after threads, since they resolve against them; a link for a thread that hasn't arrived yet is skipped and retried on the next reconcile (links are replayed from the log, not consumed).
  • knox thread emit-all now backfills membership as well (1,764 edges on this index).

Merges

MergeThreads sets superseded_by = successor uid and replicates both threads, so a peer resolves the merge instead of restoring the absorbed one. ThreadDoc.superseded_by round-trips through the log.

Deadlock fixed

MergeThreads resolved the successor uid inside its transaction. The pool is pinned to one connection, so that query waited on the transaction holding it — a hang, not an error, which is why the test run timed out rather than failed. Moved before Begin.

Verification

  • go test ./... green: link survives a wipe-and-reproject; merge records the successor pointer and survives a rebuild from the log
  • Existing merge/auto-link tests still pass

Not yet verified live: the post-deploy reprojection on dhg.lol — that needs the backfill pushed after CI lands the binary.

Second half of #41. Threads replicate (#45), but arrived **without their members** — the replica could list a thread and not summarise it. 292 links on the server against 1,764 on the laptop. ## Why membership was node-local Two mechanisms, neither portable: | Store | Key | Why it can't travel | |---|---|---| | `thread_observations` | `observation_id` | local autoincrement | | `provenance_links` | `ThreadFP(int thread id)` | embeds the local integer id | The replicated fact is therefore the **entry-level edge**: `(thread_uid, entry_fingerprint)`, because entry fingerprints are already stable across nodes. Both local forms are materialised from it on arrival. ## Details - `LinkDoc{thread_uid, entry_fp, relation, relevance, removed}`, fingerprint `sha256("thread_link:"+uid|fp|relation)`. - **Unlinks replicate as tombstones** — without them the next reconcile would resurrect any edge that was deliberately removed. - Links project *after* threads, since they resolve against them; a link for a thread that hasn't arrived yet is skipped and retried on the next reconcile (links are replayed from the log, not consumed). - `knox thread emit-all` now backfills membership as well (1,764 edges on this index). ## Merges `MergeThreads` sets `superseded_by = successor uid` and replicates both threads, so a peer resolves the merge instead of restoring the absorbed one. `ThreadDoc.superseded_by` round-trips through the log. ## Deadlock fixed `MergeThreads` resolved the successor uid *inside* its transaction. The pool is pinned to one connection, so that query waited on the transaction holding it — a hang, not an error, which is why the test run timed out rather than failed. Moved before `Begin`. ## Verification - `go test ./...` green: link survives a wipe-and-reproject; merge records the successor pointer and survives a rebuild from the log - Existing merge/auto-link tests still pass **Not yet verified live:** the post-deploy reprojection on dhg.lol — that needs the backfill pushed after CI lands the binary.
david added 1 commit 2026-11-05 09:09:21 +00:00
feat: replicate thread membership and record merges (#41)
build / image (push) Successful in 39s
build / test (push) Successful in 5m9s
9f378946b9
Threads replicated without their members: the replica could list a thread but
not summarise it. Membership was stored two node-local ways — thread_observations
by local observation id, provenance_links by ThreadFP(int id) — so neither could
cross a node boundary.

The replicated fact is the entry-level edge (thread uid, entry fingerprint),
because the fingerprint is already stable across nodes; both local forms are
materialised from it on arrival. Unlinks replicate as tombstones, or the next
reconcile would resurrect the edge.

Merges now record superseded_by = successor uid and replicate both threads, so a
peer resolves the merge instead of restoring the absorbed thread.

One deadlock fixed along the way: MergeThreads resolved the successor uid inside
its transaction, and the pool is pinned to a single connection, so the query
waited on itself.
david merged commit 499cd2be5d into main 2026-11-05 09:09:28 +00:00
Sign in to join this conversation.
No Reviewers
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: david/knox#46