Skip to content

fix(session): scope resolver to per-project transcript dir, drop /tmp self-debris scan#25

Merged
bakeb7j0 merged 1 commit into
mainfrom
fix/24-session-resolver
Apr 28, 2026
Merged

fix(session): scope resolver to per-project transcript dir, drop /tmp self-debris scan#25
bakeb7j0 merged 1 commit into
mainfrom
fix/24-session-resolver

Conversation

@bakeb7j0
Copy link
Copy Markdown
Contributor

Summary

Closes #24. The previous resolveSessionId() scanned /tmp for marker files the resolver itself wrote in prior runs, perpetuating a fake md5(pid-ppid) fallback ID forever. Symptom: nerf_status reported "Context: unavailable" indefinitely; every nerf_darts/nerf_budget call 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>/*.jsonl where <slug> is process.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 a warn event so a stuck resolution surfaces in fleet logs instead of producing the silent symptom.
  • session.ts — UUID regex case-insensitive (i flag, latent uppercase robustness); debug log on readdirSync outer-catch (operator visibility on permissions failure).
  • tests/session.test.ts (new, 16 tests) — covers projectSlug, resolveFromTranscripts (incl. multi-session-isolation regression), resolveSessionId (incl. real fallback path forced via empty projectsDir).

Linked Issues

Closes #24

Test Plan

  • bun test — 126 pass, 0 fail
  • ./scripts/ci/validate.sh — green
  • trivy fs --severity HIGH,CRITICAL — 0 findings
  • Live verification: ran resolver against current /home/bakerb/sandbox/github/claudecode-workflow cwd → returns the right session UUID (991053c7-…); ran against /home/bakerb/sandbox/gitlab/blueshift-devkit/blueshift-bernie cwd → returns 0eda03a4-… (multi-session isolation works)
  • feature-dev:code-reviewer agent — 3 Important findings, all addressed before commit

🤖 Generated with Claude Code

… 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>
@bakeb7j0 bakeb7j0 added this pull request to the merge queue Apr 28, 2026
Merged via the queue into main with commit 3dc7899 Apr 28, 2026
4 checks passed
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.

bug(session): nerf bootstraps fake session ID from self-written /tmp debris

1 participant