fix(scripts): stop pruning run-log entries with non-ISO run_id - #519
Merged
cobusgreyling merged 1 commit intoAug 17, 2026
Merged
Conversation
…indows test path
append-run-log.mjs pruned entries with new Date(obj.run_id).getTime()
and dropped any that came back NaN-or-too-old. JS's Date constructor is
lenient: a non-ISO run_id (a numeric GitHub run id, a custom slug like
"run-1") doesn't reliably parse to NaN, it can parse into a spurious
in-range-looking date instead ("run-1" -> 2001-01-01 in local time),
which then reads as 30+ days old and gets silently deleted on the very
next append -- even though the entry was just written. loop-metrics
already handles this same run_id shape correctly (keep on unparseable
rather than drop); this script did the opposite. Now only strings
shaped like an ISO date are parsed as timestamps at all, so a non-ISO
run_id is always kept.
Also fixes append-run-log.test.mjs's own SCRIPT path, which used
new URL(...).pathname -- on Windows that yields a leading-slash path
("/D:/...") that node's CLI mis-resolves relative to the current
drive instead of as absolute, the same class of bug already fixed for
tools/loop/test/files.test.mjs. Switched to fileURLToPath(), which is
what let this fix's own regression test actually run and confirm the
behavior locally.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
cobusgreyling
approved these changes
Aug 17, 2026
cobusgreyling
left a comment
Owner
There was a problem hiding this comment.
Correct fix. JS Date is too lenient on slugs like run-1; gating prune on ISO-shaped run_id matches loop-metrics and the regression test locks it. fileURLToPath() for the test script path is the right Windows fix.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
scripts/append-run-log.mjs prunes entries older than 30 days using
new Date(obj.run_id).getTime(). JS's Date constructor is lenient: a
non-ISO run_id (a numeric GitHub run id, a custom slug like "run-1")
doesn't reliably parse to NaN -- it can parse into a spurious
in-range-looking date instead ("run-1" -> 2001-01-01), which then
reads as 30+ days old and gets silently deleted on the very next
append, even though the entry was just written. tools/loop-metrics
already handles this exact run_id shape correctly (keep on
unparseable rather than drop); this script did the opposite.
Fix
Only strings shaped like an ISO date (^\d{4}-\d{2}-\d{2}) are parsed
as timestamps for pruning at all; anything else is always kept,
matching loop-metrics' handling.
Also fixes append-run-log.test.mjs's own SCRIPT path, which used
new URL(...).pathname -- on Windows that yields a leading-slash path
("/D:/...") that node's CLI mis-resolves relative to the current
drive instead of as absolute (the same class of bug already fixed for
tools/loop/test/files.test.mjs in #502). Switched to fileURLToPath().
Test plan
Added a regression test appending an entry with a non-ISO run_id
("run-1") followed by a second append, asserting the first entry
survives. node --test scripts/append-run-log.test.mjs: 3/3 passing
(this also required the Windows path fix to even run locally).