Skip to content

Supersede in batch: decay rewrites and snapshots the store file once per row #61

Closed

Description

@abogartz

Problem

Multi-row supersession is done one row at a time. memory_decay snapshots the affected files and then calls markSuperseded(ts) per row (src/index.ts), and the gate's canonical-neutralization loop (src/gates.ts) does the same. Each call is: read the whole daily file, rewrite one line, snapshot the file, publish it. So N stale rows cost N full reads, N snapshots and N renames, each taking and releasing the store lock in between.

That was tolerable when it was unlocked. Now that #60 put a per-file lock around these paths it is worth fixing rather than merely untidy: one pass over the file under one lock is cheaper, produces one undo point instead of N, and removes the windows where two decay runs interleave and each pays twice for the other's file.

Proposal

  • markManySuperseded(entries: { ts: string; fields: SupersedeFields }[]): Promise<number> in src/memory.ts — one lock, one read, stamp every matching line, one snapshot, one atomic publish. Keep markSuperseded as the single-row wrapper (stampRow already factors the shape).
  • Point memory_decay and the canonical-neutralization loop at it.
  • Test: N rows superseded in one pass → exactly one snapshot, all N stamped, and a concurrent append during that pass survives.

Cost / scope

~30 lines plus a test. No semantic change: per-row idempotence stays (a row already carrying superseded_by is skipped, so a repeat run is still a no-op).

Found while reviewing #60; deliberately kept out of that PR, which was already changing every write path.

Activity

  1. WhollyMindless commented on Oct 25, 2026

    @WhollyMindless
    Contributor

    Happy to take this if it's unclaimed. The acceptance test ("a concurrent append during the batch pass survives") builds directly on the rename-handover semantics in #89, so the clean sequence is: branch off main after #89 lands, markManySuperseded with one lock / one snapshot / one publish, decay + canonical-neutralization pointed at it, red-first scenario for the interleaving. Say the word.

  2. added 2 commits that reference this issue on Oct 25, 2026
  3. abogartz commented on Oct 27, 2026

    @abogartz
    OwnerAuthor

    Closed as completed — the batch path shipped.

    Decay now retires via markManySuperseded in a single batched call (src/index.ts:794 on main), and the gate's drift/canon plans batch through the same primitive (src/gates.ts:411, :453). The per-row rewrite-and-snapshot behavior this issue was filed against is gone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions