Skip to content

feat: restore job history from saved files on startup#440

Merged
CybotTM merged 2 commits intomainfrom
feat/restore-history-on-startup
Dec 26, 2025
Merged

feat: restore job history from saved files on startup#440
CybotTM merged 2 commits intomainfrom
feat/restore-history-on-startup

Conversation

@CybotTM
Copy link
Member

@CybotTM CybotTM commented Dec 26, 2025

Summary

  • Adds automatic job history restoration from saved JSON files on startup
  • New config options: restore-history (default: true) and restore-history-max-age (default: 24h)
  • Respects per-job history-limit settings

Problem

When Ofelia restarts (container recreation, host reboot, etc.), job history displayed in the web UI is lost because it's stored only in memory. However, if save-folder is configured, execution data is already persisted to disk as JSON files but never read back.

Solution

On startup, if save-folder is configured:

  1. Scan the save folder for *.json files
  2. Parse JSON to extract job name and execution data
  3. Filter by age (files older than restore-history-max-age are skipped)
  4. Match executions to configured jobs by name
  5. Populate job's in-memory history (respecting history-limit)

New Configuration

[global]
restore-history = true           # default: true (when save-folder is set)
restore-history-max-age = 24h    # default: 24h

Test plan

  • Unit tests for restoration logic
  • Tests for edge cases (invalid JSON, missing jobs, max age filtering)
  • Tests for config option defaults
  • All existing tests pass
  • Linter passes

Closes #439
Relates to discussion #437

When Ofelia restarts, job history is now restored from saved JSON files
in the save folder. This addresses the issue where job history displayed
in the web UI was lost on container restarts.

New configuration options:
- restore-history: Enable/disable history restoration (default: true when
  save-folder is configured)
- restore-history-max-age: Maximum age of history files to restore
  (default: 24h)

The feature:
- Scans the save folder for *.json files on startup
- Parses and matches executions to configured jobs by name
- Respects the per-job history-limit setting
- Only restores files within the configured max age
- Never marks restored executions as "running"

Closes #439
Copilot AI review requested due to automatic review settings December 26, 2025 22:12
@github-actions
Copy link

github-actions bot commented Dec 26, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@github-actions
Copy link

github-actions bot commented Dec 26, 2025

✅ Mutation Testing Results

Mutation Score: 80.95% (threshold: 60%)

✨ Good job! Mutation score meets the threshold.

What is mutation testing?

Mutation testing measures test quality by introducing small changes (mutations) to the code and checking if tests detect them. A higher score means better test effectiveness.

  • Killed mutants: Tests caught the mutation (good!)
  • Survived mutants: Tests missed the mutation (needs improvement)

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements automatic restoration of job execution history from saved JSON files on Ofelia startup. When save-folder is configured, previously saved execution records are now read back and populated into the in-memory job history, making the web UI display persistent across restarts.

Key changes:

  • Adds two new configuration options: restore-history (default: true when save-folder is set) and restore-history-max-age (default: 24h)
  • Implements history restoration logic that respects per-job history-limit settings and filters by file age
  • Comprehensive test coverage for edge cases including invalid JSON, missing jobs, and max-age filtering

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
middlewares/save.go Adds new configuration fields for history restoration with helper methods for defaults
middlewares/restore.go New file implementing the core history restoration logic from saved JSON files
middlewares/restore_test.go Comprehensive unit tests covering restoration logic and configuration behavior
cli/daemon.go Integrates history restoration into the daemon startup sequence
config/validator.go Marks new configuration options as optional fields in validation

- Fix gosec G304 by adding path containment validation and #nosec directive
- Fix log message accuracy by tracking actual count of restored jobs
- Add documentation comments to SaveConfig fields
@CybotTM CybotTM added this pull request to the merge queue Dec 26, 2025
Merged via the queue into main with commit 889105f Dec 26, 2025
27 checks passed
@CybotTM CybotTM deleted the feat/restore-history-on-startup branch December 26, 2025 23:05
@CybotTM CybotTM added the released:v0.18.0 Released in v0.18.0 label Dec 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released:v0.18.0 Released in v0.18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Restore job history from saved files on startup

2 participants