fix(session): scope resolver to per-project transcript dir, drop /tmp self-debris scan#25
Merged
Merged
Conversation
… self-debris scan The previous resolveSessionId() scanned /tmp for nerf-<sid>.json and claude-session-<sid>* markers — files the resolver itself wrote. On first run it fell through to a md5(pid-ppid) fallback, persisted the fake ID into /tmp/nerf-<fake>.json, then re-found that file forever. Result: nerf_status reported "Context: unavailable", and every nerf_darts/nerf_budget write went to a phantom session config that no real-session call could ever read. Replace strategy 3 with a transcript-mtime scan over ~/.claude/projects/<slug>/*.jsonl, where <slug> is process.cwd() with '/' replaced by '-'. Claude Code writes those transcripts itself, the basename IS the session UUID, and scoping to the calling project's slug disambiguates correctly when the user has multiple concurrent CC sessions in different projects (an early version that scanned across all projects globally was wrong on multi-session machines). Fallback md5(pid-ppid) is kept as last resort but now logs a warn event so a stuck session resolution surfaces in fleet logs instead of producing the silent "Context: unavailable" symptom. Closes #24 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
Closes #24. The previous
resolveSessionId()scanned/tmpfor marker files the resolver itself wrote in prior runs, perpetuating a fakemd5(pid-ppid)fallback ID forever. Symptom:nerf_statusreported "Context: unavailable" indefinitely; everynerf_darts/nerf_budgetcall wrote to a phantom session config that real-session calls couldn't read.Changes
session.ts— replace/tmp-scan strategy with a per-project transcript-mtime resolver. Walks~/.claude/projects/<slug>/*.jsonlwhere<slug>isprocess.cwd()with/→-. The newest UUID-shaped basename IS the session UUID written by Claude Code. Multi-session-safe: scoped to the calling project, not global across the fleet.session.ts— fallback md5(pid-ppid) kept as last resort, now logs awarnevent so a stuck resolution surfaces in fleet logs instead of producing the silent symptom.session.ts— UUID regex case-insensitive (iflag, latent uppercase robustness); debug log onreaddirSyncouter-catch (operator visibility on permissions failure).tests/session.test.ts(new, 16 tests) — coversprojectSlug,resolveFromTranscripts(incl. multi-session-isolation regression),resolveSessionId(incl. real fallback path forced via emptyprojectsDir).Linked Issues
Closes #24
Test Plan
bun test— 126 pass, 0 fail./scripts/ci/validate.sh— greentrivy fs --severity HIGH,CRITICAL— 0 findings/home/bakerb/sandbox/github/claudecode-workflowcwd → returns the right session UUID (991053c7-…); ran against/home/bakerb/sandbox/gitlab/blueshift-devkit/blueshift-berniecwd → returns0eda03a4-…(multi-session isolation works)feature-dev:code-revieweragent — 3 Important findings, all addressed before commit🤖 Generated with Claude Code