Preserve valid Claude hook sessions after decode drift

Merged
TE
2mo ago
+197-35

Fixes #15654.

A single malformed persisted hook record currently makes the strict Codable decode fail, so cmux quarantines the entire shared Claude hook store and loses every session-to-workspace mapping. This change decodes each persisted dictionary entry independently, keeps valid records when a sibling is malformed, and logs a bounded recovery breadcrumb with the dropped paths count. Scalar state fields fall back to their existing defaults when their persisted type is invalid.

Truly unparseable roots still quarantine. Quarantine backups now include a millisecond timestamp and UUID, so repeated recoveries preserve every prior backup instead of deleting the previous one.

Validation:

  • swiftc -frontend -parse CLI/ClaudeHookSessionStoreFile.swift CLI/cmux.swift
  • git diff --check
  • scripts/sync-test-wiring --check
  • scripts/lint-pbxproj-test-wiring.sh
  • python3 scripts/verify-local.py --affected upstream/main --swift CLI/ClaudeHookSessionStoreFile.swift CLI/cmux.swift cmuxCLITests/ClaudeHookSessionStoreRecoveryTests.swift (Swift syntax, project, wiring, and static checks passed; localization reported two pre-existing English-identical French entries)
  • Native app tests were not run on the MacBook Air.

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Fixes #15654. A single malformed persisted hook record previously made the strict decode fail, forcing cmux to quarantine the entire shared Claude hook store and lose every session-to-workspace mapping. The store now decodes each dictionary entry independently, keeps valid sibling records, falls back to defaults for invalid scalar fields, and logs a bounded recovery breadcrumb with the dropped paths count.

Truly unparseable roots still quarantine. Quarantine backups now include a millisecond timestamp and UUID, so repeated recoveries retain every prior backup instead of deleting the previous one.

  • Adds ClaudeHookSessionStoreRecoveryTests covering per-entry salvage and repeated backup retention.