Skip to content

Promote fallback-latest to live inside the matching orchestrator - #9

Merged
inchwormz merged 1 commit into
mainfrom
fix/claude-live-session-detection
Apr 20, 2026
Merged

inchwormz merged 1 commit into
mainfrom
fix/claude-live-session-detection

Conversation

@inchwormz

Copy link
Copy Markdown
Owner

Summary

  • Claude Code never exports CLAUDE_SESSION_ID to subshells, so resolve_transcript_target's env-var path was unreachable on the native shell — every munin brain build was downgraded to fallback-latest and the brain skill correctly refused to trust the result.
  • Codex exposes CODEX_THREAD_ID so its live detection works; the asymmetry made munin brain look broken on Claude Code.
  • When CLAUDECODE=1 (or CODEX_HOME/CODEX_THREAD_ID for Codex) is set AND the chosen transcript was modified within 120s, treat it as live. Older idle transcripts stay fallback-latest; >24h still goes stale.
  • Decision logic extracted into a pure decide_source_status() so behaviour is unit-testable without env mocking. Four regression tests cover the matrix.

Verification

  • cargo test --lib: 317 passed (4 new regression tests for decide_source_status).
  • Live binary on Windows MSYS2: munin brain --format prompt from the project root now reports source_status="live" with the correct active session id.

Test plan

  • cargo test --lib session_brain::messages::tests — 11 passed
  • cargo test --lib full suite — 317 passed
  • Manual reproduction inside live Claude Code session: status flips from fallback-latest → live
  • CI: cross-platform tests (Linux/macOS/Windows) green

🤖 Generated with Claude Code

Claude Code never exports CLAUDE_SESSION_ID to subshells, so the env-var path in resolve_transcript_target is unreachable on the native shell and every brain build was downgraded to fallback-latest. Codex exposes CODEX_THREAD_ID so its live detection works, but the asymmetry made munin brain look broken to Claude Code users.

When CLAUDECODE=1 (or CODEX_HOME/CODEX_THREAD_ID for Codex) is set AND the latest matching transcript was modified within the last 120s, treat it as live. Older idle transcripts stay fallback-latest; >24h still goes stale.

Decision logic extracted into a pure function (decide_source_status) so the behaviour is unit-testable without env mocking. Four regression tests cover the matrix.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@inchwormz
inchwormz force-pushed the fix/claude-live-session-detection branch from 4afaa01 to 2ba69a1 Compare April 20, 2026 20:47
@inchwormz
inchwormz merged commit e8378d1 into main Apr 20, 2026
4 checks passed
@inchwormz
inchwormz deleted the fix/claude-live-session-detection branch April 20, 2026 20:50
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.

1 participant