PM was loading stale PM_INSTRUCTIONS v0006 instead of current v0007 due to missing version validation.
instruction_loader.py had early return when PM_INSTRUCTIONS_DEPLOYED.md existed, without checking if the deployed version was stale compared to source.
Before Fix:
# Lines 104-113 (OLD CODE)
deployed_path = self.current_dir / ".claude-mpm" / "PM_INSTRUCTIONS_DEPLOYED.md"
if deployed_path.exists():
loaded_content = self.file_loader.try_load_file(
deployed_path, "deployed PM_INSTRUCTIONS_DEPLOYED.md"
)
if loaded_content:
content["framework_instructions"] = loaded_content
content["loaded"] = True
self.logger.info("Loaded PM_INSTRUCTIONS_DEPLOYED.md from .claude-mpm/")
return # ❌ PROBLEM: No version check!- Source file: v0007 (Dec 22 23:59)
- Deployed file: v0006 (Dec 22 16:39)
- PM loaded: v0006 (stale)
- Silent failure (no warning logs)
def _extract_version(self, file_content: str) -> int:
"""Extract version number from PM_INSTRUCTIONS_VERSION comment.
Args:
file_content: Content of the file to extract version from
Returns:
Version number as integer, or 0 if not found
"""
import re
match = re.search(r"PM_INSTRUCTIONS_VERSION:\s*(\d+)", file_content)
if match:
return int(match.group(1))
return 0 # No version = oldest# Lines 128-157 (NEW CODE)
if deployed_path.exists():
# ✓ Validate version before using deployed file
deployed_content = deployed_path.read_text()
deployed_version = self._extract_version(deployed_content)
# Check source version for comparison
if pm_instructions_path.exists():
source_content = pm_instructions_path.read_text()
source_version = self._extract_version(source_content)
if deployed_version < source_version:
# ✓ Reject stale deployed file
self.logger.warning(
f"Deployed PM instructions v{deployed_version:04d} is stale, "
f"source is v{source_version:04d}. Using source instead."
)
# Fall through to source loading - don't return early
else:
# Version OK, use deployed
content["framework_instructions"] = deployed_content
content["loaded"] = True
self.logger.info(
f"Loaded PM_INSTRUCTIONS_DEPLOYED.md v{deployed_version:04d} from .claude-mpm/"
)
return # Stop here - deployed version is currentRemoved stale deployed file to trigger fresh deployment:
rm -f .claude-mpm/PM_INSTRUCTIONS_DEPLOYED.mdAll test cases passed:
Test Case 1: No deployed file
- ✓ Uses source v0007
- ✓ Logs warning about missing deployed file
Test Case 2: Stale deployed file (v0006)
- ✓ Detects version mismatch
- ✓ Rejects stale v0006
- ✓ Falls through to source v0007
- ✓ Logs warning: "Deployed PM instructions v0006 is stale, source is v0007"
Test Case 3: Current deployed file (v0007)
- ✓ Uses deployed v0007
- ✓ Logs success: "Loaded PM_INSTRUCTIONS_DEPLOYED.md v0007"
- Source: v0007 (44,051 chars)
- Deployed: REMOVED (will be regenerated on next deploy)
- PM loads: v0007 ✓
- Added
_extract_version()method (lines 91-105) - Enhanced
_load_filesystem_framework_instructions()with version validation (lines 107-157) - Removed duplicate
pm_instructions_pathdefinition
Lines Changed: ~50 lines modified LOC Delta: +30 lines (version validation logic)
- Prevents Stale Versions: Deployed files are validated against source
- Clear Warnings: Logs explicit version mismatch warnings
- Automatic Fallback: Falls through to source when deployed is stale
- Future-Proof: Any v0008, v0009, etc. will automatically be preferred
- No deployed file: Uses source (existing behavior)
- Stale deployed file: Uses source (NEW - fixed)
- Current deployed file: Uses deployed (existing behavior)
- No version in deployed: Treated as v0000, source preferred
- No version in source: Both v0000, deployed used (backward compat)
- Source doesn't exist: Uses deployed even if no version (production mode)
- PM now loads v0007 correctly ✓
- No breaking changes (backward compatible)
- Existing workflows unaffected
When mpm deploy runs next:
- Will create new
PM_INSTRUCTIONS_DEPLOYED.mdwith v0007 - Version validation will pass
- Deployed file will be used for performance
Check logs for version warnings:
grep "PM instructions.*stale" ~/.claude-mpm/logs/latest.logExpected output if deployed is stale:
WARNING - Deployed PM instructions v0006 is stale, source is v0007. Using source instead.
- Source:
src/claude_mpm/agents/PM_INSTRUCTIONS.md(v0007) - Deployed:
.claude-mpm/PM_INSTRUCTIONS_DEPLOYED.md(removed, will regenerate) - Cache:
.claude-mpm/PM_INSTRUCTIONS.md(v0006, not used by loader)
Status: ✅ FIXED AND VERIFIED Version Now Loaded: v0007 Date: 2025-12-23