diff --git a/docs/cult-runtime-surface.md b/docs/cult-runtime-surface.md index 691481d..1849968 100644 --- a/docs/cult-runtime-surface.md +++ b/docs/cult-runtime-surface.md @@ -12,6 +12,15 @@ it to a `CultCache`. The dev scripts pass: ``` Direct runs can also use `--cache ` or `AQUARIUM_CULTCACHE_PATH`. +If the single-file MessagePack snapshot is unreadable at startup, Aquarium +quarantines it beside the live file with a `.corrupt-` suffix and +boots a fresh typed state. Schema guardrails protect valid persisted documents +whose shape has changed; they cannot rescue a truncated backing file with no +complete MessagePack envelope. + +CultLib's single-file backing store writes snapshots through a same-directory +temporary file and atomic replace. That prevents process death during save from +turning the live cache path into a zero-byte startup trap. ## Live State diff --git a/src/Aquarium.Engine.Live/State/AquariumCultStateStore.cs b/src/Aquarium.Engine.Live/State/AquariumCultStateStore.cs index b51861c..48dbfaa 100644 --- a/src/Aquarium.Engine.Live/State/AquariumCultStateStore.cs +++ b/src/Aquarium.Engine.Live/State/AquariumCultStateStore.cs @@ -2,6 +2,7 @@ using System.Numerics; using GameCult.Caching; using GameCult.Caching.MessagePack; using GameCult.Networking; +using MessagePack; namespace Aquarium.Engine.State; @@ -21,7 +22,15 @@ public sealed class AquariumCultStateStore : IDisposable cache = new CultCache(); backingStore = new SingleFileMessagePackBackingStore(CachePath); cache.AddBackingStore(backingStore); - cache.PullAllBackingStoresAsync().GetAwaiter().GetResult(); + try + { + cache.PullAllBackingStoresAsync().GetAwaiter().GetResult(); + } + catch (Exception error) when (IsRecoverableBackingStoreFailure(error)) + { + QuarantineUnreadableCache(CachePath, error); + } + Hello = CreateHello(cache.Registry); } @@ -87,4 +96,39 @@ public sealed class AquariumCultStateStore : IDisposable ] }; } + + private static bool IsRecoverableBackingStoreFailure(Exception error) + { + return error is EndOfStreamException + or InvalidDataException + or MessagePackSerializationException; + } + + private static void QuarantineUnreadableCache(string cachePath, Exception error) + { + if (!File.Exists(cachePath)) + { + return; + } + + var directory = Path.GetDirectoryName(cachePath)!; + var fileName = Path.GetFileName(cachePath); + var stamp = DateTimeOffset.UtcNow.ToString("yyyyMMdd-HHmmss-fff"); + var quarantinePath = Path.Combine(directory, $"{fileName}.corrupt-{stamp}"); + + try + { + File.Move(cachePath, quarantinePath); + Console.Error.WriteLine( + $"CultCache snapshot was unreadable and has been quarantined: {quarantinePath}. {error.GetType().Name}: {error.Message}"); + } + catch (Exception quarantineError) + { + var fallbackPath = Path.Combine(directory, $"{fileName}.corrupt-{stamp}-{Guid.NewGuid():N}"); + File.Move(cachePath, fallbackPath); + Console.Error.WriteLine( + $"CultCache snapshot was unreadable and quarantine path was busy; moved it to {fallbackPath}. " + + $"{error.GetType().Name}: {error.Message}; quarantine retry after {quarantineError.GetType().Name}: {quarantineError.Message}"); + } + } } diff --git a/state/evidence.jsonl b/state/evidence.jsonl index 09847e1..023e0bd 100644 --- a/state/evidence.jsonl +++ b/state/evidence.jsonl @@ -41,3 +41,4 @@ {"area":"renderer/hdr","lesson":"Modern HDR/PBR presentation should be built as scene-linear lighting, explicit exposure, pre-tonemap bloom/veil, and an explicit display transform. Aquarium should avoid thresholded 2000s bloom; broad low-intensity bloom should spread existing HDR energy and be inspected with luminance/bloom debug views before SDF volumetrics land.","files":["research/rendering/hdr-pbr-presentation.md","state/map.yaml","state/memory.json","state/scratch.md"],"verification":["research pass over ACES, Unreal exposure/bloom docs, Jimenez COD AW post-processing, Hable filmic tonemapping, and Frostbite PBR notes"],"ts":"2026-05-09"} {"area":"renderer/hdr","lesson":"Aquarium now has the first HDR presentation pipe before volumetrics: fixed manual exposure, half/quarter/eighth pre-tonemap bloom targets, firefly-safe downsampling, separable horizontal/vertical blur per level, low-gain bloom/veil composite before the ACES fit, and debug modes for bloom contribution and exposed luminance. This replaces the tempting full-res gather prototype with a proper hierarchical shape.","files":["src/Aquarium.Engine/Render/D3D11Renderer.cs","src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","src/Aquarium.Engine.Contracts/Input/InputState.cs","src/Aquarium.Engine/AquariumHost.cs","src/Aquarium.Engine/Platform/Win32Window.cs","src/Aquarium.Engine/Render/DirectWriteOverlay.cs","docs/hlsl-renderer.md","docs/tsr-inspired-taa-spec.md","research/rendering/hdr-pbr-presentation.md","state/map.yaml","state/memory.json","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4"],"ts":"2026-05-09"} {"area":"renderer/debug-ui","lesson":"Aquarium debug UI now uses a native Direct2D/DirectWrite retained panel inspired by CultLib code-first composition: controls are bound by explicit read/write delegates and styled as flat compact rows rather than importing Unity prefabs or ImGui chrome. The first panel toggles with F2 and drives render debug mode plus HDR exposure, bloom intensity, and bloom veil through shader constants.","files":["src/Aquarium.Engine/Render/Ui/DebugUi.cs","src/Aquarium.Engine/Render/DirectWriteOverlay.cs","src/Aquarium.Engine/Render/D3D11Renderer.cs","src/Aquarium.Engine/Render/Shaders/Aquarium.hlsl","src/Aquarium.Engine.Contracts/Input/InputState.cs","src/Aquarium.Engine/Platform/Win32Window.cs","docs/hlsl-renderer.md","state/map.yaml","state/memory.json","state/scratch.md"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4"],"ts":"2026-05-09"} +{"area":"runtime/cultcache","lesson":"A startup EndOfStreamException from CultCache means the backing MessagePack snapshot itself is truncated, not that schema guardrails failed. Aquarium now quarantines unreadable snapshots beside the live cache and boots fresh typed state; CultLib single-file stores now write via same-directory temp file plus atomic replace so process death cannot leave a zero-byte live cache.","files":["src/Aquarium.Engine.Live/State/AquariumCultStateStore.cs","docs/cult-runtime-surface.md","state/memory.json","state/scratch.md","E:\\Projects\\CultLib\\src\\GameCult.Caching\\CultCache.cs"],"verification":["dotnet build Aquarium.Engine.slnx",".\\scripts\\dev-reload.ps1 -Headless -RetainSlots 4","zero-byte artifacts/dev-reload/cultcache/aquarium-client.msgpack quarantined and fresh 1773-byte cache created"],"ts":"2026-05-09"} diff --git a/state/memory.json b/state/memory.json index 66186c0..c650447 100644 --- a/state/memory.json +++ b/state/memory.json @@ -80,6 +80,7 @@ "state_and_reload": [ "CultCache is the client memory organ. Runtime state, camera, renderer knobs, body state, UI state, and future Epiphany connection state should be typed Cult documents.", "The current live document is epiphany.aquarium.live_state, stored through CultLib MessagePack backing. Direct runs can use --cache or AQUARIUM_CULTCACHE_PATH.", + "A truncated or unreadable single-file CultCache backing store is not a schema migration failure. Aquarium should quarantine the corrupt snapshot and boot fresh typed state, while CultLib must write snapshots atomically so process death cannot leave a zero-byte cache.", "dev-reload builds disposable apphost slots so a running window does not lock normal build output. dev-watch hot reloads shaders and live runtime DLLs while preserving the last good process. Host/core/content changes, scripts, and src/Aquarium.Engine/Assets must rebuild and restart the apphost on demand. dev-watch must also relaunch if its recorded script-owned process is no longer running. For visible windows, dev-watch -ReopenWhenClosed reopens the last good visible slot without rebuilding.", "Live runtime reload is not successful just because dev-watch wrote live-current.txt. The watcher must see the host acknowledge the exact live DLL path in stdout, or treat the update as failed and keep the previous runtime/process alive.", "dev-watch must not use Start-Process -Wait to run dev-reload while dev-reload launches the long-lived Aquarium app. On Windows that can leave the watcher stuck after initial launch, never reaching the poll loop. Invoke the reload script synchronously and let dev-reload own the detached app process.", diff --git a/state/scratch.md b/state/scratch.md index 4c0d290..e15eaec 100644 --- a/state/scratch.md +++ b/state/scratch.md @@ -126,3 +126,9 @@ prototype integrated along the camera ray before surface composition. `dev-reload.ps1` could block after the app launched, leaving the watcher stuck at initial launch and never polling. The watcher now invokes dev-reload synchronously and leaves long-lived process ownership inside dev-reload. +- CultCache startup failure found: dev cache + `artifacts/dev-reload/cultcache/aquarium-client.msgpack` was zero bytes, so + MessagePack threw `EndOfStreamException` before schema guardrails could run. + Aquarium now quarantines unreadable snapshots with a `.corrupt-` + suffix and boots fresh state; CultLib single-file stores now write through a + temp file and atomic replace to avoid future zero-byte live snapshots.