Skip to content

fix(source): derive Claude session time from JSONL timestamp#60

Merged
gadflysu merged 2 commits into
masterfrom
fix/36-claude-session-jsonl-timestamp
Jun 16, 2026
Merged

fix(source): derive Claude session time from JSONL timestamp#60
gadflysu merged 2 commits into
masterfrom
fix/36-claude-session-jsonl-timestamp

Conversation

@gadflysu

Copy link
Copy Markdown
Owner

Summary

  • parseJSONL now returns a jsonlMeta struct instead of multiple values — future fields require no call-site changes
  • Parse the last valid RFC3339 timestamp across all JSONL records as session time; fall back to file mtime when no timestamp found
  • Add SessionTime to MetaEntry for cache persistence; zero value preserves backward compatibility with old cache entries
  • parseOne and ReloadSession both use the JSONL-derived time

Test plan

  • TestParseJSONL_TimestampLastWins — last timestamp in file wins
  • TestParseJSONL_TimestampNoTimestampIsZero — zero returned when no timestamp present
  • TestParseJSONL_TimestampInvalidIgnored — invalid strings skipped, last valid wins
  • TestParseJSONL_TimestampMetadataRowAfterConversation — metadata row timestamp counts
  • TestMetaCache_SessionTimeRoundTrip — SessionTime survives gob round-trip
  • TestMetaCache_SessionTimeZeroBackcompat — old cache entries (zero SessionTime) still hit
  • TestLoadClaude_UsesJSONLTimestamp — Session.Time comes from JSONL, not mtime
  • TestLoadClaude_FallsBackToMtimeWhenNoTimestamp — mtime fallback works
  • TestLoadClaude_CacheHitUsesSessionTime — cached SessionTime used on hit
  • TestLoadClaude_CacheHitZeroSessionTimeFallsBackToMtime — legacy cache entry falls back to mtime
  • TestReloadSession_UsesJSONLTimestamp — ReloadSession uses JSONL time
  • TestReloadSession_FallsBackToMtimeWhenNoTimestamp — ReloadSession mtime fallback
  • go test ./... passes

Closes #36

gadflysu added 2 commits June 16, 2026 16:10
- Add jsonlMeta struct to parseJSONL, eliminating brittle multi-return
  signatures; future fields require no call-site changes
- Parse last valid RFC3339 timestamp across all JSONL records as
  session time; fall back to file mtime when none found
- Add SessionTime to MetaEntry for cache persistence; zero value
  preserves backward compatibility with old cache entries
- Update parseOne and ReloadSession to use JSONL-derived time

Closes #36
Claude emits "2006-01-02T15:04:05.000Z" (3-digit millis, trailing zeros
preserved). RFC3339Nano uses the '9' placeholder which requires trailing
zeros stripped — so ".800Z" would silently fail. Replace the two-step
RFC3339 / RFC3339Nano parse with a single fixed-width millisecond layout
that matches Claude's actual output. Update test fixtures from whole-second
"…:00Z" to millisecond "…:00.000Z" to reflect real data.
@gadflysu gadflysu merged commit c6974a5 into master Jun 16, 2026
4 checks passed
@gadflysu gadflysu deleted the fix/36-claude-session-jsonl-timestamp branch June 16, 2026 08:29
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.

Claude session timestamps from JSONL records

1 participant