Skip to content

feat: US-003 - Poll and diff the external save file while the game runs (pure watch core + 5s monitor) - #8

Merged
Varonal merged 2 commits into
mainfrom
ralph/external-companion
Nov 19, 2026
Merged

Varonal merged 2 commits into
mainfrom
ralph/external-companion

Conversation

@Varonal

@Varonal Varonal commented Nov 19, 2026

Copy link
Copy Markdown
Owner

Summary (US-003)

Domain (pure decision core, unit-tested) — src/PKForge.Domain/ExternalSaveWatch.cs:

  • SaveFileStamp(Path, Length, LastWriteUtc) + ExternalSaveWatch.Poll(stamp?) → NoChange / PendingStable / ChangedStable / Missing, with a two-identical-reads debounce: a changed file must read identical twice before it is parsed, so a partial flush mid-write is never parsed. Reset() per session.
  • ExternalSavePublish.ShouldPublish(...) — a null candidate (failed parse) never replaces the last good snapshot.

Contract — IGameCompanionStore gains External, UpdateExternal(...), ClearExternal(); GameCompanionStore implements them, Stop() clears External too.

App — ExternalSaveMonitor (new service, registered in MauiProgram): PeriodicTimer every 5 s, running only between Start(romPath, emulator, label) and Stop() (never polls without an external session). Each poll: resolve path (US-002) → FileInfo stat → pure watch decision → ISaveEngine.Validate before OpenSession → ExternalCompanionSnapshotFactory.FromSession (US-001) → UpdateExternal on the UI thread. Every I/O step guarded: failure keeps the last good snapshot, never crashes. ObjectDisposedException from timer disposal is swallowed as a normal stop.

Tests: 11 new xunit tests (debounce sequences, size-only/mtime-only changes, disappear/reappear, reset, publish gate).

prd.json: US-003 passes: true. progress.txt: appended learnings.

Verification

  • CI (this PR): dotnet test tests/PKForge.Domain.Tests -c Release + dotnet build src/PKForge.App -f net10.0-android.
  • Local: no .NET SDK in this sandbox — static checks (interface/store symmetry, Domain purity = no File./Directory. in Domain, DI registration) passed.
  • Manual on device (prd.json notes, US-004 wires Start/Stop): while a DS game runs in melonDS, the second screen refreshes within ~10 s of an in-game save; a mid-flush read never blanks the companion.

mistral-vibe and others added 2 commits November 19, 2026 16:11
Domain (pure, tested): ExternalSaveWatch decides each poll from injected
SaveFileStamp reads - NoChange / PendingStable / ChangedStable / Missing -
with a two-identical-reads debounce so a partial flush mid-write is never
parsed. ExternalSavePublish gates publication: a null candidate (failed
parse) never replaces the last good snapshot. Reset() per session.

Contract: IGameCompanionStore gains External + UpdateExternal + ClearExternal;
GameCompanionStore implements them (Stop clears External too).

App: ExternalSaveMonitor (registered in MauiProgram) polls the resolved save
path (US-002 resolver) with a PeriodicTimer every 5 s, only while a session
runs (Start/Stop - never polls otherwise). Each poll: FileInfo stat -> pure
watch decision -> ISaveEngine.Validate before OpenSession ->
ExternalCompanionSnapshotFactory.FromSession (US-001) -> UpdateExternal on
the UI thread. Every I/O step is guarded: stat/read/parse failure keeps the
last good snapshot, never crashes.

11 new Domain tests (debounce sequences, size-only/mtime-only changes,
disappear/reappear, reset, publish gate). prd.json: US-003 passes=true.
progress.txt: appended learnings (stamp-injection pattern, anti-partial-flush
debounce, PeriodicTimer disposal throws ObjectDisposedException).

Co-authored-by: Varonal <Varonal@users.noreply.github.com>
…o-save mode)

The Missing decision must also forget the published stamp: the companion shows
'no save yet' instead of a stale snapshot when the emulator deletes the file.

Co-authored-by: Varonal <Varonal@users.noreply.github.com>
@Varonal
Varonal merged commit 9b8903e into main Nov 19, 2026
1 check passed
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.

2 participants