Repository navigation
Description
Problem Statement
We run consolidation weekly on a brain that is never quiet: recall reinforcement, a
background embedding backfill and other brains' writes go on 24/7. On that workload a
semantic_link run that takes tens of minutes rarely reaches completed, and when it
fails the record blocks the next scheduled runs.
On current main (e22ba25) your fenced source session with INCLUDE ORIGINAL diffs
(72ff646, ad87892) already makes recall reinforcement neutral, and the audited source
generations from b6f6954 restart discovery once and then pause instead of failing — thank
you, together they remove most of the failures we saw. What still makes discovery start
over, measured against the classifier with a probe of eleven change kinds:
- a background backfill writing the embedding of a neuron created before the cut-off;
- a neuron created in another brain after the cut-off (pinned by
test_semantic_source_revision.py— intentional, see question 2); - deletion of an old synapse or neuron outside the candidate set.
We also hit two smaller defects on the resume paths and one in lease renewal, each with a
red test on main.
Proposed Solution — four small PRs
Following AGENTS.md ("one logical change per PR"), the work is split into four PRs, opened
together with this issue so the whole picture is in one place. Each one stands on its own,
is based on current main and can be reviewed, merged, reworked or closed independently;
the two features are off by default. (We had a fifth piece — a bounded automatic discovery
restart — and dropped it: b6f6954 covers it.)
- fix: allocate a fresh staged-snapshot state id at an owner epoch's first save (fix: allocate a fresh staged-snapshot state id at an owner epoch's first save #338) —
a resumed discovery epoch re-saves(state_id, N+1)over an orphan revision left by a
crashed epoch and fails with "semantic discovery state revisions are immutable". The
new id is allocated lazily, at the first save; allocating it when the state is loaded
breaks batch continuation (two of your tests catch that). - fix: accept recall reinforcement of semantic edges written before an apply pause (fix: accept recall reinforcement of semantic edges written before an apply pause #339) —
on apply resume, an edge written before the pause and reinforced by recall
(higher weight and count, newlast_activated) is rejected as "changed after its
checkpoint". Only those three fields may move, weight and count only upwards. - feat: let an opt-in run supersede a failed or expired lone
semantic_linkrun (feat: let an opt-in run supersede a failed or expired lone semantic_link run #340) —
today the hint afterConsolidationResumeMismatchErrorpoints to
recover-semantic-discovery --stale-source, which accepts only the all-strategies run
with 19 completed, so a failed lonesemantic_linkrun can only be removed by hand.
Alternative we are happy to implement instead: extendrecover-semantic-discoveryto
lone runs. - fix: keep the consolidation lease alive when SHA-256 falls back to the
portable path (fix: keep the consolidation lease alive when SHA-256 falls back to the portable path #341) — with 4157ea6 the native path costs ~0.07 ms per neuron and the
lease is safe; the portable fallback measured ~80 ms on a 21 KB neuron and the scan
loop does not yield, so the lease can expire on large brains. Only the fallback path
is affected — close it if you do not support that path for large brains.
Two policy questions
- Tolerating changes that cannot change the result. Locally we run a working-set
variant: the run fingerprints its candidates and degree counts and ignores writes that
cannot alter any candidate pair (backfill of a vector outside the set, other brains,
deletes outside the set), with a per-edge guarantee instead of strict equality with a
quiet run. With a continuous backfill every such write costs a new source generation
and a full rediscovery. Would you consider that direction for upstream, or do you
prefer to keep strict equality and pay with generations? - Brain scope of the source fence. Should a write in brain B invalidate discovery in
brain A? Two tests pin the current behaviour, so we would not change it without your
agreement.
Use Case
Scheduled weekly consolidation of a multi-brain store with continuous recall, write and
embedding traffic, without pausing the writers.
Alternatives Considered
- Pausing all writers for the run — works, but the run takes tens of minutes and the
workload is 24/7. - Porting our local working-set change as one PR — rejected: it changes the result
contract and conflicts with the fenced session design, hence question 1.
Additional Context
While measuring we noticed a deployment hazard, not a bug: ALTER TABLE … CHANGEFEED 7d INCLUDE ORIGINAL takes effect immediately and survives a restart on SurrealDB 3.2.3
(surrealkv), but any process of an older version calling ensure_schema re-issues
CHANGEFEED 7d without ORIGINAL and silently drops the flag (the feed records
define_table original:false); the classifier then loses diffs until a newer process
restarts. A note in the upgrade docs might save someone a confusing week.
Activity