fix: prevent duplicate sessions, audits, and stuck audit logs#40
Merged
George-iam merged 2 commits intomainfrom Apr 7, 2026
Merged
fix: prevent duplicate sessions, audits, and stuck audit logs#40George-iam merged 2 commits intomainfrom
George-iam merged 2 commits intomainfrom
Conversation
Fix 1: Filesystem lock (O_EXCL) in ensureAxmeSessionForClaude prevents parallel hooks from creating multiple AXME sessions per Claude session. Lock winner creates session, others re-read the mapping. Fix 2: cleanupAndExit deduplicates by Claude session ID before spawning audit workers (one per Claude session, not per AXME session). Plus cross-session concurrent-audit check in runSessionCleanup as defense. Fix 3: finally block in LLM audit section ensures audit log is finalized even on unexpected termination. SIGTERM/SIGINT handlers in audit-session CLI set auditStatus=failed before exit. SIGKILL handled by existing 15-minute stale timeout.
- 11 new tests: lock mechanism (7), sequential calls (3), parallel E2E (1) - E2E test: 5 parallel processes -> exactly 1 session (verified) - Fix: re-check inside lock trusts mapping unconditionally (winner's session may have dead pid if worker exited, but it's fresh by definition) - Export lock functions for testing
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
Three fixes for related audit reliability issues.
Fix 1: Session creation lock (
sessions.ts)Fix 2: Audit spawn dedup (
server.ts+session-cleanup.ts)Fix 3: Stuck audit cleanup (
session-cleanup.ts+cli.ts)Evidence (from this session)
Test plan