Files
openclaw/extensions/memory-core
tzy-17 e0ec136108 fix(gateway): make doctor dreaming timestamp comparators NaN-safe (#118749)
* fix(gateway): make doctor dreaming timestamp comparators NaN-safe

compareDreamingEntryByRecency and compareDreamingEntryByPromotion used
`Number.isFinite(aMs) || Number.isFinite(bMs)` then `return bMs - aMs`.
When exactly one side parsed to NaN (non-empty malformed timestamp), the
guard still entered the branch and returned NaN - bMs, producing NaN and
leaving Array.sort order undefined for the doctor.memory.status dreaming
entry list. Coerce unparseable timestamps to -Infinity via a shared
parseDreamingTimestampMs helper and return a finite -1/0/1 from the
timestamp branch so the sort stays deterministic.

* fix(memory-core): incorporate producer-side NaN-safe timestamp comparator

ClawSweeper [P1] finding: gateway-only fix is incomplete because Memory Core
has the same mixed-NaN comparator BEFORE the gateway merges lists. A valid
entry discarded upstream cannot be recovered at the gateway boundary.

Incorporate the producer-side fix:
- Export compareStoreTimestampDesc from short-term-promotion-utils.ts
- Replace the buggy raw Date.parse + bMs-aMs pattern in
  short-term-promotion-stats.ts with the NaN-safe compareStoreTimestampDesc

This makes #118749 self-contained: both gateway doctor.ts AND memory-core
stats.ts comparators are NaN-safe. The companion #118750 now only needs to
cover the recency ranking fix (ageDays/recency calculation).

* fix(memory): preserve valid dreaming diagnostics

* style(memory): format dreaming imports

---------

Co-authored-by: Patrick Erichsen <patrick.a.erichsen@gmail.com>
2026-08-06 18:56:50 -07:00
..
2026-06-04 21:40:44 -04:00