Repository navigation
fix: keep session state per transcript so parallel sessions don't collide - #5
Open
michel-slm wants to merge 1 commit into
Open
michel-slm wants to merge 1 commit into
michel-slm wants to merge 1 commit into
Conversation
…lide With two Claude Code sessions open, each statusline render from one session overwrote the other's entry in the shared state.json. Every switch re-rolled the pet's species and palette, cleared events.json, and counted a new session in memory.json, so pets changed mid-session and totalSessions and the relationship tier grew far faster than real use. state.json now keeps a `sessions` map keyed by transcript path. Only an unseen transcript path counts a session, rolls a pet and clears events; known sessions keep their identity and rewrite the file at most once a minute. Uptime is credited per session, and sessions unseen for a day (or beyond the newest 50) are pruned and credited. The top-level fields still mirror the latest session and the schema version stays 1, so older codachi and `codachi stats` read the file unchanged, and a 0.3.0 file is adopted rather than reset. Fixes vincent-k2026#4 Assisted-by: Claude Code:claude-opus-5-5
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 #4.
Problem
With two Claude Code sessions open, every statusline render from one session overwrote the other's entry in the shared
~/.claude/plugins/codachi/state.json. Each switch re-rolled the pet's species and palette, clearedevents.json, and counted a new session inmemory.json, so pets changed mid-session andtotalSessions(and with it the relationship tier) grew far faster than real use.Fix
state.jsonkeeps asessionsmap keyed by transcript path:state.ts, so older codachi andcodachi statsread the file unchanged. A file written by 0.3.0 is adopted rather than reset: its session keeps its pet and its uptime is still credited.Before and after
The same reproduction run against the npm 0.3.0 package and against a tarball packed from this branch (
npm pack, installed withnpm install --prefix): two sessions, A and B, render alternately for five rounds in an isolatedHOME. Each line shows the pet each session sees.Reproduction script
Usage:
./compare.sh <path to dist/index.js> <label>Tests
src/state.test.tssimulate separate render processes sharing onestate.json. Run against the unmodifiedstate.ts, the 5 that cover this bug fail (pets stay stable, sessions counted once, no event clearing on a switch, the top-level mirror, malformed entries); the other 3 pass on both, as they cover behaviour 0.3.0 already had.tscclean,npm run benchp95 0.03ms.Not in this PR
A genuinely new session still clears
events.json, which is shared by all sessions, so starting a session can drop another's recent events. Fixing that means the hook writing events per session as well; happy to follow up separately.