diff --git a/crates/ghostlight-dungeon/src/compiler.rs b/crates/ghostlight-dungeon/src/compiler.rs index 0a84d75..75e5a30 100644 --- a/crates/ghostlight-dungeon/src/compiler.rs +++ b/crates/ghostlight-dungeon/src/compiler.rs @@ -777,13 +777,19 @@ enum DestinationReconciliationEdit { } #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] -#[serde(tag = "tool", rename_all = "snake_case", deny_unknown_fields)] -enum DestinationReconciliationToolAction { +#[serde(rename_all = "snake_case")] +enum DestinationReconciliationTool { ValidateCurrent, - ReviseAndValidate { - #[schemars(length(min = 1, max = 12))] - edits: Vec, - }, + ReviseAndValidate, +} + +#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq)] +#[serde(deny_unknown_fields)] +struct DestinationReconciliationToolAction { + tool: DestinationReconciliationTool, + #[serde(default)] + #[schemars(length(min = 1, max = 12))] + edits: Option>, } #[derive(Clone, Debug, Serialize, Deserialize, JsonSchema, PartialEq, Eq)] @@ -3406,11 +3412,13 @@ impl ModelAgentTool for DestinationReconciliationAgentTool<'_> { action: Self::Action, context: &ModelAgentToolContext, ) -> ModelAgentToolOutcome { - match action { - DestinationReconciliationToolAction::ValidateCurrent => { + match (action.tool, action.edits) { + (DestinationReconciliationTool::ValidateCurrent, None) => { self.validate_current(context, Vec::new()).await } - DestinationReconciliationToolAction::ReviseAndValidate { edits } => { + (DestinationReconciliationTool::ReviseAndValidate, Some(edits)) + if (1..=12).contains(&edits.len()) => + { let applied_edits = match apply_destination_reconciliation_edits(&mut self.draft, edits) { Ok(applied_edits) => applied_edits, @@ -3428,6 +3436,19 @@ impl ModelAgentTool for DestinationReconciliationAgentTool<'_> { }; self.validate_current(context, applied_edits).await } + (tool, edits) => ModelAgentToolOutcome::Rejected { + finding: self.observation( + Vec::new(), + DestinationReconciliationFinding::Edit { + message: format!( + "reconciliation tool {:?} received an invalid edit batch of length {}", + tool, + edits.as_ref().map_or(0, Vec::len) + ), + }, + ), + receipts: Vec::new(), + }, } } } @@ -9886,8 +9907,9 @@ mod tests { }) .collect(); let draft = civic_reconciliation_draft(&seed).unwrap(); - let action = DestinationReconciliationToolAction::ReviseAndValidate { - edits: vec![DestinationReconciliationEdit::ReplaceFact { + let action = DestinationReconciliationToolAction { + tool: DestinationReconciliationTool::ReviseAndValidate, + edits: Some(vec![DestinationReconciliationEdit::ReplaceFact { fact_index: 31, fact: WorldFact { id: "fact:large:31".into(), @@ -9896,7 +9918,7 @@ mod tests { evidence_receipt_ids: vec![], discoverable_at_location_ids: BTreeSet::from(["refuge".into()]), }, - }], + }]), }; let draft_bytes = serde_json::to_vec(&draft).unwrap(); let action_bytes = serde_json::to_vec(&action).unwrap(); @@ -9967,6 +9989,7 @@ mod tests { crate::model_connector::project_strict_responses_schema(&mut schema).unwrap(); let schema_text = serde_json::to_string(&schema).unwrap(); + assert_eq!(schema["type"], "object"); assert!(!schema_text.contains("CompiledDestinationReconciliation")); assert!(schema_text.contains("validate_current")); assert!(schema_text.contains("revise_and_validate")); diff --git a/crates/ghostlight-dungeon/src/model_connector.rs b/crates/ghostlight-dungeon/src/model_connector.rs index 8c1caaf..3c64c49 100644 --- a/crates/ghostlight-dungeon/src/model_connector.rs +++ b/crates/ghostlight-dungeon/src/model_connector.rs @@ -281,6 +281,9 @@ fn unix_ms() -> Result { pub(crate) fn project_strict_responses_schema(schema: &mut serde_json::Value) -> Result<()> { lower_schema_for_responses_format(schema); require_closed_responses_objects(schema, "$")?; + if schema.get("type").and_then(serde_json::Value::as_str) != Some("object") { + bail!("Responses output schema root must have type object") + } if !responses_schema_is_strict(schema) { bail!("projected Responses output schema is not strict") } @@ -867,6 +870,32 @@ mod tests { assert!(error.contains("sibling keywords beside $ref")); } + #[test] + fn strict_schema_projection_rejects_root_unions_before_provider_submission() { + let mut schema = serde_json::json!({ + "oneOf":[ + { + "type":"object", + "required":["kind"], + "properties":{"kind":{"type":"string","const":"one"}}, + "additionalProperties":false + }, + { + "type":"object", + "required":["kind"], + "properties":{"kind":{"type":"string","const":"two"}}, + "additionalProperties":false + } + ] + }); + + let error = project_strict_responses_schema(&mut schema) + .unwrap_err() + .to_string(); + + assert!(error.contains("root must have type object")); + } + #[test] fn attempt_deadline_tracks_the_logical_model_class_not_the_stage_name() -> Result<()> { let port = CodexConnectorModelPort::new( diff --git a/notes/ghostlight-current-system-map.md b/notes/ghostlight-current-system-map.md index 011311a..8495dbb 100644 --- a/notes/ghostlight-current-system-map.md +++ b/notes/ghostlight-current-system-map.md @@ -987,7 +987,9 @@ four small typed actions: `validate_current`, or `revise_and_validate` with a bounded transactional edit batch. The edit algebra replaces one stable fact slot, one resident fact-ID set, one frozen institution's operational fields, individual local relations, or the civic-manifest membership and fact lanes. -The action schema contains no complete-candidate type. A failed edit batch +The action wire is one root object with a typed tool discriminant and nullable +edit batch; the connector refuses root-union schemas locally before provider +submission. The action schema contains no complete-candidate type. A failed edit batch changes nothing. An admitted edit persists only in the private workbench and returns `Continue` when the resulting draft still fails validation; its digest, changed slots, and exact typed finding become the next observation without @@ -1130,10 +1132,13 @@ receipts by content hash, restores scheduler state from the consumed schedule, and continues at the first incomplete authority boundary. A committed foundation is checked against its preserved civic apparatus. A titled preview is not completion authority: only a post-kernel completion checkpoint bound to -the before/after revisions, admission digest, semantic verifier, model receipts, -exact `WorldCommitReceipt`, and the kernel-owned mutation authority, batch, and -receipt may skip that commit. The batch's `intended_effect_digest` binds the -complete finalized candidate before deterministic aggregate projection, so the +the before/after revisions, semantic verifier, model receipts, exact +`WorldCommitReceipt`, and the kernel-owned mutation authority, batch, and +receipt may skip that commit. New checkpoints also bind the admission digest; +legacy inference instead binds the finalized candidate through the persisted +mutation proof before minting its checkpoint. The batch's +`intended_effect_digest` binds the complete finalized candidate before +deterministic aggregate projection, so the resume verifier does not duplicate the reducer's set and ordering rules. Run-32's older committed Canopy pass can be admitted once through that persisted mutation proof plus its complete civic candidate, then gains the same durable