fix: preserve session createdAt/lastActivityAt across a daemon restart - #306
Merged
Conversation
Both timestamps were stamped unconditionally in the Session constructor, so every restart re-dated every resumed session to the restart moment: this.createdAt = new Date().toISOString(); this.#lastActivityAt = this.createdAt; Two consequences. A weeks-old session reported as brand new. And because the session list's recency key is `lastActivityAt ?? createdAt`, every session tied on the same instant — so the attention ordering added in #300 collapsed back to insertion order on the first restart, which is exactly what it was built to replace. The values were already persisted in TranscriptMeta (createdAt, lastActivityAt) and already read: SessionManager's `resumeSortKey` sorts the resume pass by `meta.lastActivityAt`. So the manager iterated in the right order and each Session then overwrote the timestamps a moment later — the correct data was on disk, read, and discarded. SessionCreateOptions now carries both as optional fields, the constructor prefers them over `now`, and the resume call site passes the meta values. A new session is unaffected (no opts -> stamped fresh, activity falls back to creation), and meta written before `lastActivityAt` existed degrades to `createdAt` rather than to `now` — an ancient session must not sort as the most recently active one. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
rsharath
approved these changes
Aug 29, 2026
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.
Session ordering was not surviving restarts. Root cause is two unconditional lines in the
Sessionconstructor:They run on resume too, so every restart re-dates every session to the restart moment.
Two consequences
lastActivityAt ?? createdAt, so after a restart every session ties on the same instant — and the attention ordering from feat: order the session list by attention, not by when you created it #300 falls back to insertion order, which is precisely what it was built to replace.The data was already there
TranscriptMetapersists both fields, and they were already being read:SessionManager.resumeSortKeysorts the resume pass bymeta.lastActivityAt.So the manager iterated resume in the correct order, and each
Sessionconstructor then overwrote the timestamps a moment later. The right values were on disk, read, and discarded.The fix
SessionCreateOptionsgains optionalcreatedAt/lastActivityAtopts.createdAt ?? new Date().toISOString()meta.createdAt/meta.lastActivityAtNew sessions are unaffected — no opts means stamped fresh, with activity falling back to creation.
One deliberate edge case: meta written before
lastActivityAtexisted degrades tocreatedAt, not tonow. Falling back tonowwould sort the most ancient session as the most recently active one — the inverse of the intent, and worse than the bug being fixed.Verification
lint+typecheckclean, 2386 pass / 0 fail. Four new tests: both timestamps preserved on resume, both stamped fresh for a new session, the partial-meta fallback, and a simulated restart confirming two sessions stay distinguishable by recency (the actual regression).🤖 Generated with Claude Code