Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -708,8 +708,10 @@ fn occupancy_of(shape: TurnShape, prefill_tps: f64, decode_tps: f64) -> Option<s
Some(std::time::Duration::from_secs_f64(secs))
}

/// Append one request's exact message list to `<dir>/<persona>.wire.jsonl` (the wire capture,
/// sink 4 of PRIVACY-OF-THOUGHT.md). A turn in her mind room writes nothing.
/// Append one request's message list, whole, to `<dir>/<persona>.wire.jsonl` (the wire capture,
/// sink 4 of PRIVACY-OF-THOUGHT.md). A turn in her mind room writes nothing. The boundary is the
/// ADAPTER'S INPUT (`TextGenerationRequest::messages`), not the HTTP body an adapter serializes
/// from it; a write failure is silent here, so a missing row is never evidence no request ran.
fn append_wire_capture(dir: &std::path::Path, persona_id: Uuid, persona_name: &str, room_id: Uuid, request: &TextGenerationRequest) {
if crate::cognition::mind_room::is_private_room(persona_id, room_id) {
crate::cognition::mind_room::note_withheld(persona_id, "wire_capture");
Expand All @@ -718,11 +720,10 @@ fn append_wire_capture(dir: &std::path::Path, persona_id: Uuid, persona_name: &s
let row = serde_json::json!({
"ts_ms": continuum_base::time::EpochMs::now().millis(),
"persona": persona_name,
"messages": request
.messages
.iter()
.map(|m| serde_json::json!({"role": m.role, "text": m.content_text()}))
.collect::<Vec<_>>(),
// Whole messages, every part: a text-only projection dropped native tool calls and
// results, so her newest result read as a bare label in the one input of record
// (Aiko, the M5, 2026-10-29: a result counted as lost was on the wire).
"messages": request.messages,
});
let _ = std::fs::create_dir_all(dir);
use std::io::Write as _;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,41 @@ fn a_turn_in_her_mind_room_writes_zero_wire_capture_bytes() {
assert!(std::fs::metadata(&file).expect("row written").len() > 0, "an ordinary room still captures");
}

// what this catches (the M5, 2026-10-29): the wire capture keeping only Text parts, so a
// native tool call or result (her newest result rides as one) was recorded as its label alone
// and read as a lost body. Every message must round-trip whole: role, name, and its typed parts
// in order with their ids and error flag.
#[test]
fn the_wire_capture_records_every_message_whole() {
use crate::ai::types::{ChatMessage, ContentPart, MessageContent};
let dir = tempfile::tempdir().expect("wire capture dir");
let persona = uuid::Uuid::new_v4();
let messages = vec![
ChatMessage {
role: "assistant".into(),
content: MessageContent::Parts(vec![
ContentPart::Text { text: "checking the tree".into() },
ContentPart::ToolUse { id: "call-1".into(), name: "code/shell".into(), input: serde_json::json!({"cmd": "git status"}) },
]),
name: Some("Aiko".into()),
},
ChatMessage {
role: "tool".into(),
content: MessageContent::Parts(vec![ContentPart::ToolResult {
tool_use_id: "call-1".into(),
content: "nothing to commit, working tree clean".into(),
is_error: Some(false),
}]),
name: None,
},
];
let request = crate::ai::types::TextGenerationRequest { messages: messages.clone(), ..Default::default() };
super::append_wire_capture(dir.path(), persona, "Aiko", uuid::Uuid::new_v4(), &request);
let row: serde_json::Value = serde_json::from_str(std::fs::read_to_string(dir.path().join("Aiko.wire.jsonl")).expect("row written").trim()).expect("row is json");
let recorded: Vec<ChatMessage> = serde_json::from_value(row["messages"].clone()).expect("messages deserialize");
assert_eq!(serde_json::to_value(&recorded).expect("recorded"), serde_json::to_value(&messages).expect("sent"));
}

// what this catches (Kimi, 2026-09-25): a cut act must leave her a record of what
// she was composing and that it did not land; a long payload is trimmed to its two
// edges so the record cannot crowd the retry the way the payload did.
Expand Down
Loading