Skip to content

fix: recover progress from a last-known-good state backup #45

Description

@abhiksark

Motivation

Progress is valuable to a learner. The current recovery path renames a corrupt primary state file onto state.json.bak, which can overwrite the only valid recovery point and then starts fresh instead of attempting recovery.

Current evidence

  • pythonlings/core/state.py::load() renames an unreadable state.json to state.json.bak and returns fresh state.
  • That behavior can overwrite an existing valid backup.
  • docs-site/faq.md describes where progress lives and needs to match the recovery contract.

Exact scope

Maintain a valid last-known-good .pythonlings/state.json.bak, recover it when the primary state is corrupt, and quarantine bad primary data without overwriting the backup. Align FAQ wording and tests with the final behavior.

Acceptance checklist

  • A successful state save preserves a valid last-known-good backup.
  • If the primary state is corrupt and the backup is valid, loading recovers the backup state and tells the user what happened.
  • Corrupt primary data is quarantined with a distinct, non-destructive name; it never replaces a valid backup.
  • If both files are unusable or no backup exists, recovery starts fresh with a friendly warning and preserves available forensic data.
  • State save/recovery remains atomic enough that normal progress is never silently lost.
  • Unit tests cover valid backup creation, successful recovery, corrupt backup, and absent backup; the FAQ describes the same behavior.

Explicit exclusions

Do not add cloud sync, change the state format version, delete corrupt data automatically, or alter unrelated workspace migration behavior.

Likely files

  • pythonlings/core/state.py
  • tests/unit/test_state.py
  • docs-site/faq.md

Verification

python -m pytest tests/unit/test_state.py -q
python -m pytest -q
mkdocs build --strict

Manually corrupt a primary state after creating valid progress and confirm the recovered progress is visible without overwriting state.json.bak.

Sprint coordination

See the sprint Discussion. This issue is unassigned and is not a reservation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreCore workspace, manifest, state, and runner behaviorbugSomething isn't workingdev sprintPythonlings Community Dev Sprint August 2026help wantedExtra attention is neededsize: MMedium, self-contained contribution

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions