persistence: multi-version reads across every store
ProcessJobStore and SubstrateStore already implemented the loader-accepts-any-version-in-[1, kVersion] pattern. The other five stores (ControlJobStore, CarrierStore, LoadPortStore, ExceptionStore, SpoolStore) used strict `header[1] != kVersion` rejection, meaning a future kVersion bump there would silently nuke every persisted record on first replay. That's a footgun the test_persistence_upgrade test already flagged as a tripwire. This commit flips the strict checks to `< 1 || > kVersion`, mirroring PJ + Substrate. No format change (kVersion stays at 1 across the five stores), but: - Future v2 of any store now Just Works: add fields at the end of write_record_, bump kVersion to 2, gate the new reads behind `if (version >= 2)`. Old v1 records on disk continue to replay with the new fields defaulted. - Future versions beyond kVersion still get rejected (downgrade protection — older code can't try to decode trailers it doesn't understand). Comment blocks on each kVersion declaration now describe the upgrade discipline so the next contributor doesn't reinvent it. Test additions: - Positive test that v1 ControlJob records load on current code (will continue to pass when kVersion bumps to 2, proving v1 is still readable) - ExceptionStore rejects a v9 (future) record, matching CJ + Carrier - The existing tripwire tests get retitled from "rejects unknown version" to "rejects a future version" to reflect the new contract README §6 gets honest: every store is now multi-version-aware, not just PJ + Substrate. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -189,14 +189,17 @@ class SpoolStore {
|
||||
std::filesystem::path path; // empty when persistence is disabled
|
||||
};
|
||||
|
||||
// Journal record layout (little-endian-free; all-bytes are explicit):
|
||||
// Journal record (v1) layout (little-endian-free; all bytes explicit):
|
||||
// [u8 magic = 0xE5]
|
||||
// [u8 version = 1]
|
||||
// [u8 version]
|
||||
// [u8 stream]
|
||||
// [u8 function]
|
||||
// [u8 reply_expected]
|
||||
// [u32 body_length, big-endian]
|
||||
// [body_length bytes]
|
||||
//
|
||||
// Upgrade discipline: loader accepts any version in [1, kVersion];
|
||||
// future fields append behind an `if (version >= N)` gate.
|
||||
static constexpr uint8_t kMagic = 0xE5;
|
||||
static constexpr uint8_t kVersion = 0x01;
|
||||
|
||||
@@ -241,7 +244,8 @@ class SpoolStore {
|
||||
if (!in) return std::nullopt;
|
||||
uint8_t hdr[5];
|
||||
in.read(reinterpret_cast<char*>(hdr), sizeof(hdr));
|
||||
if (!in || hdr[0] != kMagic || hdr[1] != kVersion) return std::nullopt;
|
||||
if (!in || hdr[0] != kMagic ||
|
||||
hdr[1] < 1 || hdr[1] > kVersion) return std::nullopt;
|
||||
uint8_t blen_be[4];
|
||||
in.read(reinterpret_cast<char*>(blen_be), sizeof(blen_be));
|
||||
if (!in) return std::nullopt;
|
||||
|
||||
Reference in New Issue
Block a user