feat(chat): self-heal the session list from chat logs when the cache is lost#102
Closed
viniciussouzax wants to merge 1 commit into
Closed
Conversation
…is lost
sessions.json (under ~/.claude-code-web) is only a fast-access cache; the JSONL
logs under workspace/ADWs/logs/chat are the durable source of truth. When the
cache directory is not persisted (e.g. a container redeploy where it wasn't on
a volume), the conversation list came back empty even though the history was
intact on disk.
Rebuild the in-memory index from the logs when the loaded cache is empty:
- ChatLogger.listSessions() enumerates sessions from the log filenames
({agentName}_{shortId}.jsonl), splitting on the last underscore so agent
names containing underscores still parse correctly.
- TerminalServer.rebuildSessionsFromLogs() reads each log back into a session
entry and is invoked from loadPersistedSessions() only when the cache is
empty, then persists the rebuilt index. It is idempotent and never
duplicates cached sessions; timestamps come from the logs so the normal TTL
policy still drops stale sessions.
Adds tests for listSessions() parsing and the empty-cache rebuild.
Refs #101
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
There was a problem hiding this comment.
Sorry @viniciussouzax, you have reached your weekly rate limit of 500000 diff characters.
Please try again later or upgrade to continue using Sourcery
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.
Fixes #101.
Problem
sessions.json(under~/.claude-code-web, i.e./root/.claude-code-webinthe container) is only a fast-access cache; the JSONL logs under
workspace/ADWs/logs/chatare the durable source of truth. When the cachedirectory isn't persisted (e.g. a container redeploy where it wasn't mounted on
a volume), the conversation list comes back empty even though the history is
intact on disk, because the list is built from the in-memory Map (seeded from
the cache), not from the logs. See #101 for the full root-cause analysis.
Change
Rebuild the in-memory index from the logs when the loaded cache is empty:
ChatLogger.listSessions()enumerates sessions from the log filenames(
{agentName}_{shortId}.jsonl), splitting on the last underscore so agentnames that contain underscores still parse correctly.
TerminalServer.rebuildSessionsFromLogs()reads each log back into asession entry. It is invoked from
loadPersistedSessions()only when thecache is empty, then persists the rebuilt index.
Properties:
ids not already present).
dropped by the existing save / GC policy. No behavior change when the cache is
present.
sessions.jsona true cache (no longer a single point of failure forthe conversation list).
This is option (4) from #101. It composes with the deployment-side mitigation
(mounting a volume at the cache dir) but removes the need for it to avoid data
becoming unreachable.
Tests
Added to
dashboard/terminal-server/test/server.test.js(node --test):ChatLogger.listSessionsparses agent and session id, including agent nameswith underscores, and ignores non-
.jsonlfiles.TerminalServerrebuilds the index from chat logs when the cache is empty,and a second pass is a no-op (idempotent).
Notes
Recovered session ids use the 8-char short id from the log filename (the same
id
ChatLoggerkeys on), so continuing a recovered conversation appends to thesame log. Full chat history is restored into the entry; the existing 50-message
cap in
SessionStore.saveSessionsis unchanged and out of scope here.