Skip to content

fix(scripts): stop pruning run-log entries with non-ISO run_id - #519

Merged
cobusgreyling merged 1 commit into
cobusgreyling:mainfrom
KhaiTrang1995:fix/append-run-log-non-iso-run-id
Aug 17, 2026
Merged

fix(scripts): stop pruning run-log entries with non-ISO run_id#519
cobusgreyling merged 1 commit into
cobusgreyling:mainfrom
KhaiTrang1995:fix/append-run-log-non-iso-run-id

Conversation

@KhaiTrang1995

Copy link
Copy Markdown
Contributor

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).

…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 cobusgreyling left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@cobusgreyling
cobusgreyling merged commit c74a99c into cobusgreyling:main Aug 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants