From e0b12f90250cafcec0f4a234e60bc9c20dd7df07 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 23 Aug 2026 06:29:05 +0200 Subject: [PATCH] Keep strategic verifier diagnostics private --- crates/ghostlight-dungeon/src/main.rs | 43 ++++++++++++++++-------- crates/ghostlight-dungeon/src/outcome.rs | 18 +++++++--- crates/ghostlight-dungeon/src/persona.rs | 18 ++++++++-- 3 files changed, 58 insertions(+), 21 deletions(-) diff --git a/crates/ghostlight-dungeon/src/main.rs b/crates/ghostlight-dungeon/src/main.rs index ed7e343..c849967 100644 --- a/crates/ghostlight-dungeon/src/main.rs +++ b/crates/ghostlight-dungeon/src/main.rs @@ -4242,13 +4242,8 @@ async fn command( ) .await { - return ( - StatusCode::CONFLICT, - Json(ErrorBody { - error: error.to_string(), - }), - ) - .into_response(); + let body = player_safe_strategic_failure(&error); + return (StatusCode::CONFLICT, Json(body)).into_response(); } if let WorldCommand::Wait { expected_revision, @@ -4314,13 +4309,10 @@ async fn command( }), ) .into_response(), - Err(error) => ( - StatusCode::UNPROCESSABLE_ENTITY, - Json(ErrorBody { - error: error.to_string(), - }), - ) - .into_response(), + Err(error) => { + let body = player_safe_strategic_failure(&error); + (StatusCode::UNPROCESSABLE_ENTITY, Json(body)).into_response() + } }; } } @@ -5784,6 +5776,14 @@ struct ErrorBody { error: String, } +fn player_safe_strategic_failure(error: &anyhow::Error) -> ErrorBody { + tracing::warn!(%error, "private strategic simulation failed without mutation"); + ErrorBody { + error: "The strategic world simulation could not produce a valid atomic wave. No world state changed; retry when ready." + .into(), + } +} + #[cfg(test)] mod tests { use super::*; @@ -5791,6 +5791,21 @@ mod tests { use ghostlight_dungeon::domain::{ActorState, BranchOrigin, Location}; use tower::ServiceExt; + #[test] + fn strategic_failure_projection_never_contains_private_model_diagnostics() { + let private = anyhow::anyhow!( + "the hidden convoy chooses a route at dawn; verifier returned private output" + ); + let projected = player_safe_strategic_failure(&private); + + assert_eq!( + projected.error, + "The strategic world simulation could not produce a valid atomic wave. No world state changed; retry when ready." + ); + assert!(!projected.error.contains("convoy")); + assert!(!projected.error.contains("verifier")); + } + fn seed(name: &str) -> Campaign { let actor = ActorState { id: "player".into(), diff --git a/crates/ghostlight-dungeon/src/outcome.rs b/crates/ghostlight-dungeon/src/outcome.rs index d1174f8..c88a03f 100644 --- a/crates/ghostlight-dungeon/src/outcome.rs +++ b/crates/ghostlight-dungeon/src/outcome.rs @@ -313,8 +313,12 @@ async fn verify_outcomes( } match (verdict.result, verdict.repair_guidance) { (OutcomeVerifierResult::Match, None) => {} - (OutcomeVerifierResult::Mismatch, Some(guidance)) if bounded_text(&guidance, 240) => { - mismatches.push(format!("{}: {guidance}", verdict.action_digest)); + (OutcomeVerifierResult::Mismatch, Some(guidance)) if !guidance.trim().is_empty() => { + mismatches.push(format!( + "{}: {}", + verdict.action_digest, + guidance.chars().take(240).collect::() + )); } _ => { return Err(anyhow!( @@ -1514,8 +1518,7 @@ fn constrain_verifier_schema(schema: &mut serde_json::Value, digests: &[String]) "result":{"const":"mismatch"}, "repair_guidance":{ "type":"string", - "minLength":1, - "maxLength":240 + "minLength":1 } } } @@ -1698,6 +1701,13 @@ mod tests { "repair_guidance":null }] }))); + assert!(validator.is_valid(&serde_json::json!({ + "verdicts":[{ + "action_digest":digest, + "result":"mismatch", + "repair_guidance":"The proposed transfer is not causally supported by the exact attempt. Preserve the source subject, exact resource custody, and recipient boundary; if no supplied outcome can express the actual result, replace it with no_material_change instead of inventing an exchange or acceptance that never occurred." + }] + }))); assert!(!validator.is_valid(&serde_json::json!({ "verdicts":[{ "action_digest":digest, diff --git a/crates/ghostlight-dungeon/src/persona.rs b/crates/ghostlight-dungeon/src/persona.rs index f4b74aa..bd01b71 100644 --- a/crates/ghostlight-dungeon/src/persona.rs +++ b/crates/ghostlight-dungeon/src/persona.rs @@ -999,6 +999,9 @@ impl CellProjectionEngine { .repair_guidance .as_deref() .expect("validated mismatch guidance") + .chars() + .take(240) + .collect::() ) .into() }) @@ -1131,7 +1134,7 @@ fn validate_effect_verification( ) { (CellEffectMatchResult::Match, None, None) => {} (CellEffectMatchResult::Mismatch, Some(_), Some(guidance)) - if !guidance.trim().is_empty() && guidance.chars().count() <= 240 => + if !guidance.trim().is_empty() => { rejected.push(expected_index) } @@ -1201,8 +1204,7 @@ fn cell_effect_verifier_schema(action_count: usize) -> Result }, "repair_guidance":{ "type":"string", - "minLength":1, - "maxLength":240 + "minLength":1 } } } @@ -2323,6 +2325,16 @@ mod tests { }); assert!(validator.is_valid(&faithful)); + let long_but_semantically_coherent_guidance = serde_json::json!({ + "verdicts":[ + {"action_index":0,"result":"mismatch","mismatch_kind":"wrong_effect_kind","repair_guidance":"The Persona chose a concrete journey, so preserve that exact decision with the supplied migration effect rather than downgrading it to coordination; if no supplied effect can represent the destination, remove this action and let the world retain the attributed choice without committing an invented route."}, + {"action_index":1,"result":"match","mismatch_kind":null,"repair_guidance":null}, + {"action_index":2,"result":"match","mismatch_kind":null,"repair_guidance":null}, + {"action_index":3,"result":"match","mismatch_kind":null,"repair_guidance":null} + ] + }); + assert!(validator.is_valid(&long_but_semantically_coherent_guidance)); + let incoherent = serde_json::json!({ "verdicts":[ {"action_index":0,"result":"match","mismatch_kind":"invented_outcome","repair_guidance":null},