Skip to content

Add self-healing cache validation for DeepFace weight files#3

Draft
Claude wants to merge 1 commit intomainfrom
claude/fix-weight-file-cache-validation
Draft

Add self-healing cache validation for DeepFace weight files#3
Claude wants to merge 1 commit intomainfrom
claude/fix-weight-file-cache-validation

Conversation

@Claude
Copy link
Copy Markdown

@Claude Claude AI commented Mar 27, 2026

Tickets

N/A - Fixing CI test failures caused by corrupted cached model weight files.

What has been done

With this PR, the CI workflow now validates cached DeepFace weight files before tests run. Corrupted .h5 files that pass the size check (>100KB) but have invalid HDF5 structure now get detected and removed, allowing DeepFace to re-download clean weights.

Changes:

  • Added GitHub Actions cache for ~/.deepface/weights with dynamic key based on requirements.txt hash
  • Implemented H5 integrity validation using h5py.File() to detect corrupted weights
  • Validation removes both suspiciously small files (<100KB) and files that fail HDF5 structure checks
  • Cache key invalidates when dependencies change to prevent stale cache reuse

Root cause: Truncated/corrupted weight files in CI cache were causing ValueError in model.load_weights(), cascading into API test failures (400 vs 200 status codes).

Fix approach: Validate all *.h5 files before tests by attempting to open with h5py. Invalid files are removed and logged with diagnostic output.

How to test

# Run CI workflow - corrupted cached weights will be detected and removed
# DeepFace will re-download valid weights automatically

- Add GitHub Actions cache for ~/.deepface/weights with dynamic key based on requirements.txt hash
- Implement H5 file integrity validation using h5py to detect corrupted weight files
- Remove both suspiciously small (<100KB) and corrupted H5 files before tests
- Gracefully fall back to size-based cleanup if h5py is unavailable
- Cache key invalidates when dependencies change to prevent stale cache reuse

Fixes issue where corrupted/truncated model weight files in CI cache cause ValueError during model.load_weights() and cascade into API test failures.

Agent-Logs-Url: https://github.com/JayNightmare/Deepface-Mirror/sessions/a5d961cd-5f82-40c9-8b22-1c3bac0cfc54

Co-authored-by: JayNightmare <34739807+JayNightmare@users.noreply.github.com>
@JayNightmare JayNightmare self-requested a review March 27, 2026 16:07
@JayNightmare JayNightmare linked an issue Mar 27, 2026 that may be closed by this pull request
2 tasks
@JayNightmare JayNightmare added bug Something isn't working invalid This doesn't seem right labels Mar 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working invalid This doesn't seem right

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: Failed Tests

2 participants