Skip to content

feat(#45): consolidation that has to earn its merge — deterministic, read-proven, proposal-only - #100

Merged
abogartz merged 3 commits into
feat/status-self-metricsfrom
feat/consolidation-pass
Oct 25, 2026
Merged

abogartz merged 3 commits into
feat/status-self-metricsfrom
feat/consolidation-pass

Conversation

@abogartz

Copy link
Copy Markdown
Owner

Closes #45

Part of #84, and the last ticket in the stack: #96 → #97 → #98 → #99 → this PR. Base is feat/status-self-metrics because the acceptance rule consumes the use ledger #42 shipped.

The HOLD, and why it is lifted

The ticket said: build only after #42 has ~a month of hits data, because consolidation is fragile and may not earn its cost (NOOA's reflection records: 22% of rows, ~1% of reads; abstraction hurt pinpoint lookup). That reasoning is sound and this PR keeps it intact — it just gets its evidence from the harness instead of a calendar. Every proposal is measured against real reads on every run, and test/consolidate-bench.test.ts fails CI if the trade goes negative. If the numbers turn out bad in production, the tool proposes nothing and nothing is merged.

What it does

memory_consolidate (new tool, read-only) finds near-duplicate settled rows and proposes merges. Four rules make it safe:

1. Deterministic merge. The canonical row is the survivor's prose verbatim, plus the absorbed rows' distinctive vocabulary as kw. No model rewrites anything — a rewrite cannot be diffed, audited, or proven to preserve meaning, and this plugin ships no model. kw is indexed and never rendered (#40), so inheriting aliases never grows the injected bytes of the row that keeps them.

2. Proven reads, per cluster. Every read the ledger recorded for the cluster is replayed against the merged store. A merge is proposed only when the canonical row catches at least as many of the cluster's own reads as the best single member did alone — the acceptance rule from the ticket, literally. A cluster with no recorded reads is reported unmeasured and never merged on resemblance. That refusal is tested as a first-class outcome, not a fallback.

3. Proposals, not writes. Nothing is written. The report ends with the exact memory_merge_review(loser=…, survivor=…, reason="consolidate <id>") call that resolves each proposal, and resolving stays supersede-not-delete (recoverable via memory_undo). A test asserts the store is byte-identical across the call.

4. The most recently used member is never the loser (#42's rule, inherited). Clusters never cross scope or type, and open threads are excluded — a live plan is not episodic material to compress.

Measured on the shipped eval dataset

This is the honest trade, printed by the test and asserted in CI:

before after
rows 200 52
R@3 (production window) 52 / 105 53 / 105
R@1 52 / 105 50 / 105
injected characters (store-wide) 25 945c 6 933c

R@1 falls by 2 and R@3 rises by 1. The reason is structural, not a bug: the dataset is 3/4 near-duplicate prose, so merging rewrites the entire IDF landscape, and a canonical row that inherited an absorbed twin's aliases sometimes wins a slot a neighbour used to hold. Assertions: R@3 must not fall; at most 5 of 105 queries may see a larger block; no query may grow by more than 100 characters. Two queries do grow, by 48 characters worst-case. A claim of "consolidation is free" would be a lie worth catching.

Tests

  • test/consolidate.test.ts — clustering boundaries (scope, type, jaccard floor configurable and pinned at 0.55), open-thread and superseded-row exclusion, survivor chosen by use recency rather than newest row, canonical prose byte-identical to the survivor, the acceptance rule including the unmeasured refusal, and readsFor only crediting cluster members.
  • test/consolidate-bench.test.ts — the non-regression and budget bounds above, run against the real dataset (one shared pass, ~7s).
  • test/consolidate-tool.test.ts — the shipped tool: proposes when there is read history, reports unmeasured when there is none, honours scope, and leaves the store byte-identical.
  • Wire contract and tool registry updated (memory_consolidate is now 14 tools; its exact JSON Schema is pinned in test/boundaries.test.ts).
  • Full suite: 445 pass / 5 skip / 0 fail; tsc clean; Biome clean; terminal merge gate green (11 e2e).

Review focus

  1. ReadSet fidelity. The acceptance rule is only as honest as the ledger's terms. readReads() replays per-line (terms, rows) pairs; terms are capped at 8 by sharedTerms() (P2: Use-based reinforcement — recall-hit log, recency-of-use boost, never-retrieved report #42), so a read that landed on 12 shared concepts is replayed with 8. Does that understate the merge's risk enough to matter?
  2. The absorbed-content grading. Post-merge recall accepts a canonical row as "found" for any content its cluster absorbed. That is what supersede-not-delete promises — but it is a definitional choice, and a stricter grader (exact content only) would score 52→50 R@1 and R@3. Both numbers are printed; only R@3 gates.
  3. clustersFor is O(n²) jaccard. Correct and fine for a manual command at current store sizes; it is not something to schedule.
  4. Object identity, not ts. Cluster bookkeeping uses row references because the eval store legitimately holds rows sharing a timestamp; a ts-keyed filter absorbs an entire cluster into its survivor. Ledger lookups (use) stay ts-keyed, which is correct there since ts is the row id in the store.

@abogartz
abogartz force-pushed the feat/status-self-metrics branch from f454d4e to 0c5786e Compare October 25, 2026 19:46
@abogartz
abogartz force-pushed the feat/consolidation-pass branch from 6a8cfce to 361ec17 Compare October 25, 2026 19:46
review added 2 commits October 25, 2026 12:58
…read-proven, proposal-only

Episodic→semantic consolidation is the step the surveys agree is fragile
(arXiv:2603.07670: "rarely automatic… fragile and hard to validate"), and NOOA's
numbers are the warning label: reflection records were 22% of rows and ~1% of
reads, and abstraction hurt pinpoint lookup. So the pass is built to say no more
often than yes:

- DETERMINISTIC MERGE. The canonical row is the survivor's prose verbatim plus
  the absorbed rows' aliases as keywords. No model rewrites anything: a rewrite
  cannot be diffed, audited, or proven to preserve meaning, and this plugin ships
  no model. kw is indexed and never renders (#40), so a merge never grows the
  injected bytes of the row that keeps them.
- PROVEN READS, PER CLUSTER. Every read the use ledger recorded for the cluster
  is replayed against the merged store. A merge is proposed only when the
  canonical row catches at least as many of the cluster's own reads as the BEST
  single member did alone. A cluster with no recorded reads is reported
  unmeasured and never merged on resemblance.
- PROPOSALS, NOT WRITES. memory_consolidate writes nothing — the tests assert the
  store is identical before and after the call. Output ends with the exact
  memory_merge_review call that resolves each proposal; resolving stays
  supersede-not-delete, recoverable via memory_undo.
- Most recently used member is never a loser (#42's rule, inherited here).
- Clusters never cross scope or type, and open threads are excluded: a live plan
  is not episodic material to compress.

The ticket's HOLD asked for ~a month of hits data before building this, because
the cost is not obviously paid. The harness answers that directly, per cluster,
on every run, so the gate is evidence instead of a calendar. Measured on the
shipped eval dataset: 200 rows -> 52, R@3 52 -> 53, R@1 52 -> 50, store-wide
injected characters 25945c -> 6933c. The trade is asserted, not assumed: R@3 must
not fall, at most 5 of 105 queries may see a bigger block, and no query may grow
by more than 100 characters.

Cluster bookkeeping uses object identity, not ts: the eval store legitimately
holds rows sharing a timestamp, and a ts-keyed filter silently absorbs an entire
cluster into its survivor.

Test: test/consolidate.test.ts (clustering boundaries, open-row and superseded
exclusion, jaccard floor, survivor by use recency, byte-identical canonical
prose, the acceptance rule including the unmeasured refusal), test/consolidate-
bench.test.ts (non-regression and budget bounds on the real dataset),
test/consolidate-tool.test.ts (proposes with a read history, reports unmeasured
without one, scope-limits, and leaves the store byte-identical).
ticket: #45
Same class as the #97 review note, one layer up: the pool sort, the
cluster-order sort and the survivor tie-break in survivorFor all compared
ISO stamps as strings, so a legacy second-precision row could be called
newer than a millisecond row from the same second plus change. cmpTs is
now exported from inject.ts and is the single comparator for recency.
@abogartz
abogartz force-pushed the feat/status-self-metrics branch from 0c5786e to 6d1858b Compare October 25, 2026 20:00
@abogartz
abogartz force-pushed the feat/consolidation-pass branch from 361ec17 to a77fbec Compare October 25, 2026 20:01
@abogartz
abogartz merged commit e86e923 into feat/status-self-metrics Oct 25, 2026
3 checks passed
abogartz added a commit that referenced this pull request Oct 25, 2026
feat(#45): consolidation pass — replayed onto main after #100's wrong-base merge
@abogartz
abogartz deleted the feat/consolidation-pass branch October 25, 2026 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant