Repository navigation
fix(gateway): make doctor dreaming timestamp comparators NaN-safe - #118749
Conversation
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.
|
Codex review: needs maintainer review before merge. Reviewed August 6, 2026, 8:37 PM ET / August 7, 2026, 00:37 UTC. ClawSweeper reviewWhat this changesThe branch makes malformed dreaming timestamps rank as oldest in capped Memory Core statistics and gateway doctor output, with regression tests. Merge readinessThis PR remains necessary: current main can return NaN from timestamp comparators at both the Memory Core cap and gateway merge boundaries. The patch uses the existing canonical comparator upstream and downstream; no code finding was identified, but required exact-head checks are failing and must be resolved before merge. Priority: P2 Review scores
Verification
How this fits togetherMemory Core turns persisted recall entries into capped dreaming diagnostics, and the gateway doctor method merges those diagnostics for operators. Ordering at either boundary controls whether valid entries survive and appear in memory-status output. flowchart LR
A[Persisted recall entries] --> B[Memory Core statistics]
B --> C[Eight-entry cap]
C --> D[Gateway doctor method]
D --> E[Cross-workspace ordering]
E --> F[Operator memory status]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource -10, Tests +101. Total +91 across 6 files. View PR surface stats
Review metrics
Stored data modelPersistent data-model change detected: Merge-risk options
Maintainer options:
Technical reviewBest possible solution: Keep the canonical producer-and-consumer comparator repair, then resolve the failing required checks and rerun them on the current head before landing. Do we have a high-confidence way to reproduce the issue? Yes, source-reproducible: one valid and one malformed timestamp makes current-main subtraction return NaN at both sorting boundaries; the added fixtures encode that path, though no local execution was performed in this read-only review. Is this the best way to solve the issue? Yes. Reusing the existing Memory Core timestamp comparator at the capped producer boundary and making the gateway merge finite fixes the complete observable path without adding competing policy. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ec023a433614. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
|
Added real behavior proof per ClawSweeper review:
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
…ator 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 openclaw#118749 self-contained: both gateway doctor.ts AND memory-core stats.ts comparators are NaN-safe. The companion openclaw#118750 now only needs to cover the recency ranking fix (ageDays/recency calculation).
|
Resolved both `merge-risk: 🚨 other` and `status: 📣 needs proof`: merge-risk: 🚨 other → resolvedIncorporated the producer-side NaN-safe timestamp comparator from #118750 into this PR, making it self-contained:
Both boundaries now use NaN-safe comparators. A valid entry can no longer be discarded by Memory Core's 8-entry cap before the gateway sees it. #118750 now only covers the separate recency ranking fix. status: 📣 needs proof → resolvedAdded real gateway doctor response proof: https://gist.github.com/tzy-17/b8e0d53f7f3644a90720fa57f2814769 Captured from actual `invokeDoctorMemory("doctor.memory.status")` call (not a mocked comparator script). Shows the full response payload with valid entry ranking ahead of malformed entry. Tests
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
Patrick-Erichsen
left a comment
There was a problem hiding this comment.
Approved for landing at exact head ddeb30d30ba5d9153a2a19686a4b1e930450b239.
The mixed-NaN defect exists at both the Memory Core top-eight producer cap and the gateway merge boundary; this patch fixes both at their owners and preserves the existing signal/path tie-breakers. Exact-head CI is green and the real doctor.memory.status regression covers the malformed/valid ordering.
ClawSweeper's optional refresh move is intentionally skipped: all four touched current-main blobs remain byte-identical to the reviewed base, GitHub reports a clean merge, exact-head CI is green, and the repository-native merge gate will verify the current merge result. After landing, #118750 needs to rebase/drop its duplicate comparator hunks before separate consideration.
…overlap Revert ageDays from `number | null` back to `number` to preserve the Gateway doctor payload contract. The actual bug (max recency boost for malformed timestamps) is fixed in the recency calculation, not in the ageDays representation: invalid timestamps get `ageDays = 0` (same as main) but `recency = 0` instead of `calculateRecencyComponent(0, ...)` which returns the maximum. This resolves three ClawSweeper merge-risk labels: - compatibility: ageDays stays numeric across the Gateway boundary - session-state: malformed-timestamp candidates are no longer excluded from the maxAgeDays gate (they pass with ageDays=0, same as main) - other: drop comparator + helper-export changes owned by PR openclaw#118749
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
@clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
Patrick-Erichsen
left a comment
There was a problem hiding this comment.
Approved for landing at exact head 4881823894aed1c8727b74ec8bba93d4b7a2b035.
- Exact-head CI is green: https://github.com/openclaw/openclaw/actions/runs/31136332649
- Fresh autoreview is clean (0.99 confidence); the final tree preserves the reviewed six-file patch exactly.
- The prior ClawSweeper rank-up move to diagnose/rerun required checks is satisfied.
Remaining mechanical gate: the queued ClawSweeper refresh must finish on this exact head, then the repository-native prepare/merge guards will run.
|
@clawsweeper re-review |
|
🦞👀 Command router queued. I will update this comment with the next step. |
|
Merged via squash.
|
* origin/main: (58 commits) fix(test): restart shared gateway after migration convergence (openclaw#120089) fix(ui): make active-run steering reliable (openclaw#120083) fix(telegram): preserve voice fallback text test(swift): preserve queued websocket frames (openclaw#120106) fix: reject missing oxlint shard selectors (openclaw#120096) test(channels): align prerelease fallback catalog spec (openclaw#120092) fix(node-cli): warn when systemd user lingering is disabled after install (openclaw#118430) fix(diagnostics): preserve CLI turn usage totals (openclaw#120100) fix(gateway): derive lock and coordinator paths from the resolved state dir (openclaw#120110) fix(release): isolate private Telegram QA harness (openclaw#120088) test(agents): exercise execution attribution ingress guard fix(gateway): defer attribution until admission succeeds refactor(agents): centralize exact execution attribution fix(google): accept base64url provider media (openclaw#116204) fix(plugins): warn when registerHook uses a typed hook event name (openclaw#118601) fix(canvas): serve Content-Length on A2UI HEAD responses (openclaw#117961) fix(gateway): make doctor dreaming timestamp comparators NaN-safe (openclaw#118749) fix(heartbeat): explain target-none skips (openclaw#119689) fix(security): stop recommending retired install-policy bypasses (openclaw#120011) fix(plugins): preserve startup release during repair (openclaw#120085) ... # Conflicts: # CHANGELOG.md # src/config/sessions/session-accessor.sqlite-transcript-write.ts
…enclaw#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 openclaw#118749 self-contained: both gateway doctor.ts AND memory-core stats.ts comparators are NaN-safe. The companion openclaw#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 <[email protected]>
What Problem This Solves
The gateway doctor's dreaming statistics comparators (
compareDreamingEntryByRecencyandcompareDreamingEntryByPromotionindoctor.ts) useDate.parse+bMs - aMssubtraction. When one entry has a valid timestamp and the other has a malformedlastRecalledAt(e.g.,"not-a-valid-date"),Date.parsereturnsNaN, andbMs - aMsreturnsNaN.Array.sortwith a NaN comparator produces undefined ordering, so the operator may see malformed entries ranked ahead of valid recent ones.The same mixed-NaN comparator exists in Memory Core's
short-term-promotion-stats.ts(compareDreamingStatsEntryByRecencyandcompareDreamingStatsEntryByPromotion). Memory Core caps each workspace list at 8 entries BEFORE the gateway merges them, so a NaN-discarded valid entry cannot be recovered at the gateway boundary.Why This Change Was Made
This PR now fixes both boundaries to be self-contained:
doctor.ts): newparseDreamingTimestampMscoerces invalid timestamps to-Infinity, comparators return finite-1/0/1short-term-promotion-stats.ts): replaces the buggy rawDate.parsepattern with the existingcompareStoreTimestampDeschelper (already NaN-safe inshort-term-promotion-utils.ts)The companion PR #118750 now only covers the recency ranking fix (
ageDays/recencycalculation inshort-term-promotion.ts), which is a separate concern from the comparators.User Impact
Operators running
openclaw doctor memory statuswith malformed persisted timestamps see deterministic ordering: valid recent entries always rank ahead of entries with invalid timestamps. Previously, NaN comparators could place malformed entries (with more signals) ahead of valid recent entries, or cause Memory Core to discard valid entries during its 8-entry cap before the gateway ever saw them.Evidence
Real gateway doctor response proof
Actual
doctor.memory.statusresponse with malformed timestamps: https://gist.github.com/tzy-17/b8e0d53f7f3644a90720fa57f2814769The response payload is captured from the actual
invokeDoctorMemory("doctor.memory.status")call, not a mocked comparator script. Both boundaries (gateway + memory-core) use the NaN-safe comparator.Before/after comparator behavior
Tests
doctor.test.ts: 46 tests pass (includes regression test for malformed ordering)short-term-promotion.test.ts: 85 tests passdreaming-phases.test.ts: 56 tests passCompanion PR
#118750 covers the separate recency ranking fix (
ageDays/recencyinshort-term-promotion.ts). It is no longer a merge dependency since the comparator fix is now self-contained in this PR.