Skip to content

Resume pets after a killed server when no deletion was lost - #44

Merged
Nowkoo merged 1 commit into
mainfrom
fix/unclean-shutdown-recovery
Oct 16, 2026
Merged

Nowkoo merged 1 commit into
mainfrom
fix/unclean-shutdown-recovery

Conversation

@Nowkoo

@Nowkoo Nowkoo commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Problem

On 15 October at 01:25 UTC, TF Main was stopped and the process was killed about six seconds later, before CompanionPets reached onDisable. The pets-recovery-required guard stayed on disk. Every later start (01:25, 06:10 and 06:10 the next day) then logged Previous pet session did not commit a clean shutdown and disabled the plugin, so pets were unavailable until an operator removed the file by hand.

The guard exists for one case: a pet death or release that could not be written to pet-deletions.log. A stale pets.yml could then bring that pet back. A killed process with healthy storage cannot leave that state, because remove() writes and forces the log entry before the body goes away, and read() drops logged IDs from the saved data.

Change

  • beginSession() writes pets-session-intact before it creates the guard.
  • The proof is withdrawn as soon as the session stops being safe to resume: a deletion fails to reach the log, an ownership migration is held, or the shutdown save fails. A delete needs no free space, so it still works after the write that failed.
  • At startup, if both files are present, the store logs a warning, removes both, and loads the last saved pets.yml with the deletion log applied.
  • A guard without the proof still blocks startup, as before. That includes a guard left by an older release. A proof without a guard is discarded.

Changes saved within the five-second flush window before a kill can still be lost, as with any crash. Deaths and releases cannot.

Tests

  • New: a killed healthy session resumes and keeps a death that pets.yml still listed; a legacy guard still blocks; a stale proof is discarded; plugin-level startup after a kill.
  • Existing failure cases (failed deletion log, failed backup, interrupted or failed shutdown save, undeletable guard) still block startup.
  • Full suite on Linux: 1055 tests, 0 failures, 3 skipped. The store tests need Linux because of directory fsync; on Windows, unmodified main also fails 64 of them.

🤖 Generated with Claude Code

A server killed mid-shutdown left pets-recovery-required behind, and every
later start disabled CompanionPets until an operator removed it by hand.

The session now also arms pets-session-intact, which is withdrawn as soon as
a death or release cannot reach pet-deletions.log, a migration is held, or
the shutdown save fails. When both files are found at startup, every
terminal transition is already in the log, so the store logs a warning and
resumes from the last saved pets.yml. A guard without the proof, including
one left by an older release, still requires reconciliation.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 16, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 8746038d-597d-41a8-9f89-34184ec04aff
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added the size:M 30-99 effective changed lines (tests excluded in mixed PRs). label Oct 16, 2026
@Nowkoo
Nowkoo merged commit 0b671d1 into main Oct 16, 2026
3 checks passed
@Nowkoo
Nowkoo deleted the fix/unclean-shutdown-recovery branch October 16, 2026 09:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 effective changed lines (tests excluded in mixed PRs).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant