K24: the usage totals count every call of a reading wake: each continuation and each earlier Interpreter call carries its usage

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-21 00:05:29 +01:00
commit 9eae3af581
3 changed files with 25 additions and 4 deletions

View file

@ -413,7 +413,8 @@ fn narrate_one(model: &dyn Model, instance: &str, packet: &Packet, tuning: &tuni
}
};
let mut prose = cap_words(&first.answer.text, tuning.persona.words);
let mut usage = vec![json!(first.answer.usage)];
// Each continuation's call, its usage under `usage` so the report's totals count it (Soul: 72 of 76 calls counted).
let mut continuations: Vec<Value> = Vec::new();
render["persona"] = json!({ "words": words(&prose), "cut_at_budget": words(&first.answer.text) > tuning.persona.words, "usage": first.answer.usage, "prose": prose });
if through != Through::Interpreter {
return render;
@ -465,7 +466,7 @@ fn narrate_one(model: &dyn Model, instance: &str, packet: &Packet, tuning: &tuni
};
let segment = cap_words(&continued.answer.text, tuning.persona.words);
cut = words(&continued.answer.text) > tuning.persona.words;
usage.push(json!(continued.answer.usage));
continuations.push(json!({ "usage": continued.answer.usage, "words": words(&segment), "cut_at_budget": cut }));
turns.push(Turn::Assistant { text: segment.clone(), states: continued.states });
before = format!("{before}{}\n\n{bridge}\n\n", &prose[from..]);
prose = format!("{prose}\n\n{segment}");
@ -501,8 +502,8 @@ fn narrate_one(model: &dyn Model, instance: &str, packet: &Packet, tuning: &tuni
}
render["persona"]["prose"] = json!(prose);
render["persona"]["words"] = json!(words(&prose));
render["persona"]["segments"] = json!(usage.len());
render["persona"]["usage_by_segment"] = json!(usage);
render["persona"]["segments"] = json!(1 + continuations.len());
render["persona"]["continuations"] = json!(continuations);
render["interpreter"] = decision;
render
}

View file

@ -507,3 +507,17 @@ fn k24_the_reply_after_a_read_gets_her_whole_budget_and_a_cut_draft_is_not_hers(
let told = crate::projection::outcome::outcome_of(&json!({ "interpreter": decision, "posted": [] })).unwrap().lines(crate::projection::select::forms(&control()));
assert!(!told.iter().any(|line| line.contains("finished writing")), "{told:?}");
}
/// Soul at F.1 (72 calls reported, 76 made): every call of a reading wake is in the usage totals, the continuations and
/// the earlier Interpreter calls too.
#[test]
fn k24_every_call_of_a_reading_wake_is_counted() {
let fixture = reading_room("quiet-beat.toml");
let model = Scripted::new(|prompt| if prompt.contains("LOOP-READ") { "So the knee goes first.".into() } else { "I want to see what changed in GameCult/Lodur#12.".into() }).interpreting(|prompt| {
let read = if prompt.contains("Earlier in his moment") { Value::Null } else { json!({ "kind": "repo", "target": "GameCult/Lodur#12", "quote": "I want to see what changed" }) };
json!({ "say": [], "gaps": [], "read": read }).to_string()
});
let report = wake_of(&fixture, &model);
let counted: u64 = usage_total(std::slice::from_ref(&report)).values().map(|row| row["calls"]).sum();
assert_eq!((counted, model.calls.borrow().len()), (5, 5), "projector, persona, interpreter, continuation, interpreter");
}

View file

@ -534,6 +534,12 @@ pub(crate) fn decide_in(model: &dyn Model, request_id: &str, packet: &Packet, na
if let Some(reads) = wake.earlier.map(|earlier| earlier["reads"].clone()).filter(Value::is_array) {
decision["reads"] = reads;
}
// The earlier calls of this wake, each with its usage, so the report's totals count every call (Soul: 72 of 76).
if let Some(before) = wake.earlier {
let mut calls = before["earlier_calls"].as_array().cloned().unwrap_or_default();
calls.push(json!({ "usage": before["usage"] }));
decision["earlier_calls"] = json!(calls);
}
if let Some(open) = found.unfinished {
decision["unfinished"] = json!(prose[open + DRAFT_OPEN.len()..].trim());
}