Skip to content

fix: restore the desk on the next start after a session that never ended - #178

Merged
lippdev merged 4 commits into
mainfrom
feat/durable-restore
Oct 29, 2026
Merged

lippdev merged 4 commits into
mainfrom
feat/durable-restore

Conversation

@lippdev

@lippdev lippdev commented Oct 29, 2026

Copy link
Copy Markdown
Owner

What

PRD CORE-012 / D-22. Today, if Console Mode closes or the PC shuts down in the middle of a session, nothing is restored afterwards. The display, audio and RTSS backups stay on disk, but Engine.Stop() returns early without an active session, so "Restore now" does nothing and the desk stays as the session left it (TV as the only screen, desk monitors off).

Now:

  • When the desk starts changing, the session writes a journal (session.json in the data folder): the launcher, the audio output before the session, the desktop icons (feat: put desktop icons back in place after a console session #167) and the pointer position (feat: move the mouse pointer out of the way during a session #177). Displays and RTSS already have their own backup files.
  • Once the restore went through, the journal is deleted. A restore that threw keeps it, so it's tried again.
  • When the app opens and the journal is still there, the session is rebuilt from it and from the backups and restored like a normal one, before anything else (also before an auto-start, and at Windows sign-in when it starts with Windows). A warning says the last session didn't end properly. Steam is left alone; only Big Picture is closed if it is still open.
  • An unreadable journal (cut short by a power loss) is dropped, so it doesn't come back on every start.

Tests

  • dotnet test: 576 passing. New SessionJournalTests: round trip, missing parts, broken or half-written files, and no file.
  • Debug x64 build: 0 errors.
  • On Windows, a real crash: JoyChromium session with the PC's only screen as the game screen, pointer at 500,350 and parked in the corner. I killed ConsoleMode.exe mid-session: JoyChromium stayed full screen and session.json was on disk. Reopening the app logged Recuperação: a sessão … não terminou, restored the layout, sent JoyChromium back to a window, moved the pointer back to 500,350, deleted the journal and showed the warning (read through UI Automation).
  • Not tested: a real TV with the desk monitors turned off, or a power cut. Checklist in docs/TESTING.md → "Restauração depois de uma queda".

Changelog (Fixes) in both files, a paragraph in every guide, and the PRD: CORE-012 checked, D-22 and CA-03 corrected (the PRD wrongly said displays and audio were already restored after a crash).

🤖 Generated with Claude Code

A session journal (session.json) is written when the desk starts changing and deleted once the restore went through. If it is still there when the app opens, the session is rebuilt from it and from the display, audio and RTSS backups, restored like a normal one, and the user is told. Before, a crash left the screens as the session had them, and Restore now did nothing without an active session.

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

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

The crash-recovery path can discard the journal after an incomplete display restore, and startup can proceed without a journal when writing it fails.

Reviewed changes This review covers durable session journaling and startup recovery, along with its documentation and tests.

  • Session journal persists pre-session audio, desktop icon, and pointer state before applying the main display changes.
  • Interrupted-session recovery rebuilds the restore state at startup, restores it before auto-start, and reports recovery to the user.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6-luna | 𝕏

…hout it

The journal is written before the desk changes; if it can't be written the session doesn't start. A restore that leaves the screens wrong keeps the journal for the next start, up to two attempts, so a screen gone for good doesn't restore the desk on every start.

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

lippdev commented Oct 29, 2026

Copy link
Copy Markdown
Owner Author

Both points fixed in the latest commit:

  • Incomplete restore: the journal is now kept when RestoreBackup reports Success = false, so the next start tries again. It's capped at 2 attempts (RecoveryAttempts in the journal), so a screen that's gone for good (a TV unplugged) doesn't restore the desk on every start.
  • Journal write failure: the journal is written before anything on the desk changes, and if writing it fails the session doesn't start (localized error, nothing changed).

Tested on Windows: a session.json that can't be written (a folder with that name) → start fails with nothing changed; a journal at 2 attempts → dropped without restoring; killing the app mid-session → restored on the next start (attempt 1), pointer back where it was, journal deleted. 577 tests pass.

🤖 Generated with Claude Code

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Important

The retry-counter update can destroy the only recovery journal before restoration completes.

Reviewed changes Reviewed the follow-up commit that hardened journal writes and retries after unsuccessful display restoration.

  • Aborted sessions without a journal Prevented a session from starting when its initial recovery journal cannot be written.
  • Retried incomplete restores Retained the journal when display restoration fails and limited recovery to two startup attempts.

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using gpt-6-luna | 𝕏

Written to a .tmp file and swapped in, so a crash while updating the retry count can't leave a cut-short journal that would be dropped as unreadable.

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

lippdev commented Oct 29, 2026

Copy link
Copy Markdown
Owner Author

Fixed: SessionJournal.Write now writes session.json.tmp and swaps it in with File.Move(..., overwrite: true), so a crash while bumping the attempt count leaves the previous journal whole. Tests check the swap and that no .tmp is left; the real crash test on Windows still recovers on the next start. 578 tests pass.

🤖 Generated with Claude Code

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues; one minor durability-contract clarification inline.

Reviewed changes Reviewed the follow-up that writes the session journal through a sibling temporary file before replacing it.

  • Replaced journal writes safely Wrote updates to a temporary sibling file before moving it over the journal, and added a rewrite test.

Note: 1 inline comment(s) dropped because they did not anchor to lines inside the PR diff:

  • src/ConsoleMode/Services/SessionJournal.cs:445 (RIGHT) — line 445 (RIGHT) is not inside a diff hunk

Pullfrog  | Fix it ➔ | View workflow run | Using gpt-6-luna | 𝕏

{
var temp = path + ".tmp";
File.WriteAllText(temp, Serialize(journal));
File.Move(temp, path, overwrite: true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Writing beside the journal avoids truncating the destination while the temporary contents are produced, but File.Move(..., overwrite: true) does not document a power-loss durability guarantee for the replacement itself. The XML comment therefore promises more than the API contract establishes; see .NET File.Move and Windows MoveFileExW.

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

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — one minor durability-contract clarification inline.

Reviewed changes Reviewed the follow-up that flushes the temporary session journal before replacing the existing file.

  • Flushed journal contents Persisted the temporary file's data before moving it over the journal.

Note: 1 inline comment(s) dropped because they did not anchor to lines inside the PR diff:

  • src/ConsoleMode/Services/SessionJournal.cs:440 (RIGHT) — line 440 (RIGHT) is not inside a diff hunk

Pullfrog  | Fix it ➔ | View workflow run | Using gpt-6-luna | 𝕏

@lippdev
lippdev merged commit 4a604e1 into main Oct 29, 2026
5 checks passed
@lippdev lippdev mentioned this pull request Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant