Skip to content

test/hits.test.ts re-ingested-row scenario is wall-clock flaky (fails ~1 run in 6 on main) #144

Closed

Description

@abogartz

test/hits.test.ts > "a re-ingested row cannot inherit the reinforcement of the row that held its words" fails intermittently on an otherwise-green main. Found while pushing #24-area work: the pre-push gate failed on it, the same suite then passed 6× in a row, and unmodified main (61e01b0) failed the same test in 2 of 12 full-suite runs — so it is not caused by that change.

Evidence

tree runs failures
main @ 61e01b0 12 (full bun test ./test/) 2 — always this one test
PR branch (path containment) 10 2 — always this one test

Nothing else flakes. The run reports 520 pass / 1 fail (or 548/1 on the branch), and the failing test is always:

(fail) use signals and the honest window > a re-ingested row cannot inherit the reinforcement of the row that held its words

Why it is timing-sensitive

The test derives row identity twice, back to back, and asserts they differ:

await appendMemory({ type: "learning", scope: "rev", content: "the vault rotates on the first monday" });
const [original] = await loadAll();
…
rmSync(memoryRoot(), { recursive: true, force: true });
mkdirSync(memoryRoot(), { recursive: true });
resetLedgerCache();
await appendMemory({ type: "learning", scope: "rev", content: "the vault rotates on the first monday" });
const [fresh] = await loadAll();
expect(fresh!.ts).not.toBe(original!.ts);   // ← the flaky edge

Row identity is ts, and ts is a wall-clock ISO instant. The claim under test ("a re-ingested row is a new identity") is only observable when the two writes land in different milliseconds — on a warm cache they can land in the same one, and then the assertion that proves the invariant is the thing that fails. The expect(ledger.byRow.get(original!.ts)?.count).toBe(1) above it depends on the same clock.

What to decide

  1. Make the test deterministic. Inject the clock at the seam the test already reaches for (resetLedgerCache() shows the seam exists), or advance a controllable clock between the two appendMemory calls, instead of hoping the millisecond rolls over.
  2. Or make identity collision-proof at the source. If two rows in the same millisecond is a real possibility in production, ts alone is not a safe row key and the collision needs handling there — which is a much bigger statement than a flaky test, so it should be a deliberate ruling rather than something a green suite hides.

Either way the suite should not depend on wall-clock luck: a gate that fails 1 run in 6 stops being trusted, and "rerun it, it's the hits test" is exactly the failure mode #68 exists to prevent.

Notes

Activity

  1. added
    test-integrity
    verified-on-main
    on Oct 27, 2026
  2. abogartz commented on Oct 30, 2026

    @abogartz
    OwnerAuthor

    Fixed — the identity check no longer depends on the millisecond rolling over

    test/hits.test.ts:151-164 advances the clock deterministically between the two writes instead of hoping:

    resetLedgerCache();
    const stampMs = Date.now();
    while (Date.now() === stampMs) { /* spin to the next millisecond */ }
    ...
    expect(fresh!.ts).not.toBe(original!.ts);

    Landed in 6bcd6a8 ("test: make the re-ingested-row identity check deterministic"). The suite is green end-to-end at 525ed89.

    One thing to note about which option was taken. You offered two: make the test deterministic, or make identity collision-proof at the source, with the caveat that the second is "a much bigger statement than a flaky test, so it should be a deliberate ruling". The fix took option 1, which means the same-millisecond collision is still possible in principle — ts is still the sole row key — and the test now works around it rather than the source handling it.

    That's a fine outcome, but it leaves "two rows in one millisecond is out of scope" as an unstated invariant. Since ts is also the blocklist key and the superseded_by pointer, it is worth one line recording the ruling, or a ticket if you actually disagree with it. Flagging it because the green suite now hides the question that #144 originally surfaced.


    Severity triage 2026-10-30 — reviewed against main @ 525ed89 (v0.14.24). Labeled verified-on-main: the behavior this ticket describes no longer exists, so there is nothing to build. Full-suite baseline at that commit: 722 pass / 12 skip / 0 fail. Closing is your call; the evidence is here so the claim is checkable rather than asserted.

  3. abogartz commented on Nov 4, 2026

    @abogartz
    OwnerAuthor

    Carried verified-on-main since the 2026-11-01 sweep; the last leftover of that batch (#137 #141 #146 already closed). Closing on the verified label.

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

    test-integrityverified-on-main

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions