From 4cb83ad8bf854444070ae52ae46fecd56c57f16f Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Thu, 3 Dec 2026 21:23:35 +0100 Subject: [PATCH] Harden play-turn refusal test and align remaining Dungeon doc lines - README.md, AGENTS.md, notes/fresh-workspace-handoff.md: distinguish the live crates/ghostlight-dungeon playtest daemon from the parked Eve surface and historical MVP design record. - play.rs: verify corrupt, inner-mismatch, non-canonical, and missing-field v3 rows remain byte-for-byte untouched on disk when PlayTurnStore::open refuses them. --- AGENTS.md | 3 +- README.md | 9 +-- crates/ghostlight-dungeon/src/play.rs | 88 ++++++++++++++++++++++----- notes/fresh-workspace-handoff.md | 5 +- 4 files changed, 84 insertions(+), 21 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 1a74f58..1016fdb 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -63,7 +63,8 @@ says what exists today and what does not. `parked/ghostlight-eve-surface`). - Persona membrane: `crates/ghostlight-persona-projection/src/lib.rs`. - Claude SDK sidecar: `sidecar/claude-sdk/`. -- Architecture rationale (the parked Dungeon's): `docs/architecture/ghostlight-dungeon-mvp.md`. +- Architecture rationale (earlier Dungeon / parked Eve surface design record): + `docs/architecture/ghostlight-dungeon-mvp.md`. `notes/ghostlight-implementation-plan.md` is the historical plan of the 2026-09 rebuild, not the current plan. diff --git a/README.md b/README.md index 8f36bb8..1bca64d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ **Ghostlight is a world kernel: typed world state that a language model can propose changes to and can never write.** The valuable part is -`crates/ghostlight`. The Dungeon game, one client of it, is parked (below). +`crates/ghostlight`. The live Dungeon playtest daemon (`crates/ghostlight-dungeon`, +below) is one client of it; the earlier Eve surface is parked. **The thesis.** World state is typed documents. Every change to it, and every narrative dependency on it, is an operation in a closed, predefined algebra. @@ -13,9 +14,9 @@ committed. A model-as-game-master holds the world in a context window and drifts; here the world is a digest-chained journal that survives restarts and cannot be talked into contradicting itself. -**Use it as a structured state backend.** Do not judge it by the parked Dungeon's -prose. The kernel is a library; prose comes from whichever model you plug into -its ports. +**Use it as a structured state backend.** Do not judge it by the Dungeon playtest's +or the earlier parked Eve surface's prose. The kernel is a library; prose comes +from whichever model you plug into its ports. - `crates/ghostlight`: the sealed library. A consumer gets create/open (`WorldMailbox::open`, `create`), immutable snapshots (`snapshot`), command diff --git a/crates/ghostlight-dungeon/src/play.rs b/crates/ghostlight-dungeon/src/play.rs index 6dbc90a..54bec84 100644 --- a/crates/ghostlight-dungeon/src/play.rs +++ b/crates/ghostlight-dungeon/src/play.rs @@ -4151,36 +4151,48 @@ pub(crate) mod tests { assert_eq!(rows[0].schema_id.as_deref(), Some(schema)); } - // Corrupt bytes, non-canonical wire order, and inner-schema mismatches under the current - // schema id are also refused cleanly without writing sidecars. + // Corrupt bytes, non-canonical wire order, inner-schema mismatches, and v3 rows + // missing non-defaulted fields (`applied_keys`, `question_token`, `fault`) are also + // refused cleanly without modifying the row or writing sidecars. let directory = tempfile::tempdir().unwrap(); + let assert_row_untouched = |path: &Path, expected_payload: &[u8]| { + let raw_store = OwnedRedbMessagePackBackingStore::new(path).unwrap(); + let rows = raw_store.pull_all().unwrap(); + assert_eq!(rows.len(), 1); + assert_eq!(rows[0].schema_id.as_deref(), Some(STORE_SCHEMA)); + assert_eq!(rows[0].payload.as_slice(), expected_payload); + }; + let corrupt_path = directory.path().join("corrupt.cc"); + let corrupt_payload = vec![0xC1]; { let raw_store = OwnedRedbMessagePackBackingStore::new(&corrupt_path).unwrap(); let row = CultCacheEnvelope { key: STORE_KEY.into(), r#type: STORE_TYPE.into(), - payload: vec![0xC1], + payload: corrupt_payload.clone(), stored_at: Utc::now().to_rfc3339(), schema_id: Some(STORE_SCHEMA.into()), }; assert!(raw_store.compare_and_swap_batch(&[], vec![row]).unwrap()); } assert!(PlayTurnStore::open(&corrupt_path).is_err()); + assert_row_untouched(&corrupt_path, &corrupt_payload); let inner_mismatch_path = directory.path().join("inner-mismatch.cc"); + let inner_mismatch_payload = rmp_serde::to_vec_named(&PlayTurnStoreState { + schema: "ghostlight.play_turn_store.v1".into(), + turn: None, + ledger: KeyLedger::default(), + revision: 7, + }) + .unwrap(); { let raw_store = OwnedRedbMessagePackBackingStore::new(&inner_mismatch_path).unwrap(); - let state = PlayTurnStoreState { - schema: "ghostlight.play_turn_store.v1".into(), - turn: None, - ledger: KeyLedger::default(), - revision: 7, - }; let row = CultCacheEnvelope { key: STORE_KEY.into(), r#type: STORE_TYPE.into(), - payload: rmp_serde::to_vec_named(&state).unwrap(), + payload: inner_mismatch_payload.clone(), stored_at: Utc::now().to_rfc3339(), schema_id: Some(STORE_SCHEMA.into()), }; @@ -4188,23 +4200,26 @@ pub(crate) mod tests { } let error = PlayTurnStore::open(&inner_mismatch_path).err().unwrap(); assert!(format!("{error:#}").contains("schema is invalid"), "{error:#}"); + assert_row_untouched(&inner_mismatch_path, &inner_mismatch_payload); let non_canonical_path = directory.path().join("non-canonical.cc"); - { + let non_canonical_payload = { let mut fields = std::collections::BTreeMap::new(); fields.insert("ledger", serde_json::to_value(KeyLedger::default()).unwrap()); fields.insert("revision", Value::Number(5.into())); fields.insert("schema", Value::String(STORE_SCHEMA.into())); fields.insert("turn", Value::Null); - let payload = rmp_serde::to_vec_named(&Value::Object( + rmp_serde::to_vec_named(&Value::Object( fields.into_iter().map(|(k, v)| (k.to_string(), v)).collect(), )) - .unwrap(); + .unwrap() + }; + { let raw_store = OwnedRedbMessagePackBackingStore::new(&non_canonical_path).unwrap(); let row = CultCacheEnvelope { key: STORE_KEY.into(), r#type: STORE_TYPE.into(), - payload, + payload: non_canonical_payload.clone(), stored_at: Utc::now().to_rfc3339(), schema_id: Some(STORE_SCHEMA.into()), }; @@ -4212,6 +4227,51 @@ pub(crate) mod tests { } let error = PlayTurnStore::open(&non_canonical_path).err().unwrap(); assert!(format!("{error:#}").contains("not canonical"), "{error:#}"); + assert_row_untouched(&non_canonical_path, &non_canonical_payload); + + // Pin `#[serde(default)]` removal: a v3 row whose `turn` omits `applied_keys`, + // `question_token`, and `fault` must be refused on open and left untouched. + let missing_fields_path = directory.path().join("missing-turn-fields.cc"); + let missing_fields_payload = { + let mut turn_fields = std::collections::BTreeMap::new(); + turn_fields.insert("turn_id", Value::String("44444444-4444-4444-4444-444444444444".into())); + turn_fields.insert("opening_prompt", Value::String("You stand at the gate.".into())); + turn_fields.insert("player_prose", Value::Array(vec![Value::String("I knock.".into())])); + turn_fields.insert("rounds", Value::Array(Vec::new())); + turn_fields.insert("calls", Value::Array(Vec::new())); + turn_fields.insert("persona_turns", Value::Array(Vec::new())); + turn_fields.insert("question", Value::Null); + turn_fields.insert("refusal", Value::Null); + turn_fields.insert("narration", Value::Null); + turn_fields.insert("state", Value::String("Running".into())); + let turn_json = Value::Object( + turn_fields.into_iter().map(|(k, v)| (k.to_string(), v)).collect(), + ); + let mut state_fields = std::collections::BTreeMap::new(); + state_fields.insert("schema", Value::String(STORE_SCHEMA.into())); + state_fields.insert("turn", turn_json); + state_fields.insert("ledger", serde_json::to_value(KeyLedger::default()).unwrap()); + state_fields.insert("revision", Value::Number(2.into())); + rmp_serde::to_vec_named(&Value::Object( + state_fields.into_iter().map(|(k, v)| (k.to_string(), v)).collect(), + )) + .unwrap() + }; + { + let raw_store = OwnedRedbMessagePackBackingStore::new(&missing_fields_path).unwrap(); + let row = CultCacheEnvelope { + key: STORE_KEY.into(), + r#type: STORE_TYPE.into(), + payload: missing_fields_payload.clone(), + stored_at: Utc::now().to_rfc3339(), + schema_id: Some(STORE_SCHEMA.into()), + }; + assert!(raw_store.compare_and_swap_batch(&[], vec![row]).unwrap()); + } + let error = PlayTurnStore::open(&missing_fields_path).err().unwrap(); + assert!(format!("{error:#}").contains("corrupt"), "{error:#}"); + assert_row_untouched(&missing_fields_path, &missing_fields_payload); + assert!( std::fs::read_dir(directory.path()) .unwrap() diff --git a/notes/fresh-workspace-handoff.md b/notes/fresh-workspace-handoff.md index 1d93215..9a4000a 100644 --- a/notes/fresh-workspace-handoff.md +++ b/notes/fresh-workspace-handoff.md @@ -34,8 +34,9 @@ target and probed body facts are `notes/ghostlight-verse-target.md` and 2. `AGENTS.md`: invariants and where things are. 3. `docs/architecture/ghostlight-world-ontology.md`: the kernel's vocabulary and current mechanism. -4. `docs/architecture/ghostlight-dungeon-mvp.md`: the parked Dungeon's authority - architecture. History until Thing 2 revives it. +4. `docs/architecture/ghostlight-dungeon-mvp.md`: the earlier Dungeon / parked Eve + surface authority architecture (historical design record; `crates/ghostlight-dungeon` + is the live playtest daemon). 5. `docs/architecture/ghostlight-play-agent-cut.md`: the dated record of the play agent and of the first deploy on 2026-09-23 (findings PA.f198 to PA.f216). It is history; the mind says which findings are still open.