You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(logs): show emission time for replayed log lines, not render time
Log lines were timestamped at RENDER time (new Date() in the client),
so replayed buffer lines — the init replay and the /live backlog seed —
all showed page-open time instead of when each line was actually
produced. Root cause: emission time was captured NOWHERE in the log
path. The audit log file (pipeline logLine) and the in-memory logBuffer
both stored bare strings, and the client invented a timestamp at paint.
Thread a real emission timestamp end-to-end:
- server.js broadcast('log'): stamp data.ts = Date.now() once, at
emission. logBuffer changes from string[] to {ts,msg}[]; the ts rides
the live SSE event, the buffer, and (via pipeline) the on-disk log.
- server.js publicLogBuffer(): filter on .msg, return {ts,msg}[].
- server.js parseLogLine() + hydrateLogBufferFromFile(): recover ts from
the on-disk '[<ISO>] <msg>' format; legacy bare lines → ts:null.
- server.js sanitizeForPublic(): forward ts on public 'log' events.
- audit/pipeline.js logLine(): prefix each persisted line with [<ISO>]
so emission time survives a server restart / reloaded saved run.
- admin.html: _logEntryFields() normalizes string|{ts,msg};
_buildLogEntry(msg,cat,tsMs) renders the emission time (null → BLANK,
never a misleading now); appendLog uses Date.now() only for direct
live string calls; appendLogBatch + SSE 'log' use the stored ts.
- live.html: appendLog shape-sniffs {ts,msg} buffer/SSE entries (object
with msg but no tag/cat/status), unwraps to the string-classify path,
and renders the stored emission ts (null → blank); structured live
lifecycle objects still stamp now. SSE 'log' case forwards ts.
Lines whose emission time is genuinely unknown (older on-disk runs
written before this change) render a BLANK time rather than a fake one.
Test: admin-log-batch.test.js extended (15) — replayed {ts,msg} renders
its emission time, bare string → blank, live string → current time, live
{ts,msg} SSE → server ts. Adversarial review: SHIP (8/8 risks verified
safe — buffer-shape readers, public API consumers, live shape-sniff,
disk-format parse, no double-prefix, XSS intact, ms-epoch formatting).
0 commit comments