K27/K28 fix-up: promise_block reads her commitments without creating the field; a reaffirmation of a closed promise is refused as closed before any outside-put check

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-11-21 01:45:25 +01:00
commit 714c2c8701

View file

@ -286,7 +286,7 @@ pub(crate) fn apply(state: &Value, record: &Value, prose: &str, key: &str, now:
fn block_on_failed_reads(state: &mut Value, record: &Value, applied: &mut Applied) {
let repo_of = |target: &str| target.split(['#', '?', '/', '@']).take(2).collect::<Vec<_>>().join("/");
let failed: Vec<&Value> = record["interpreter"]["reads"].as_array().into_iter().flatten().filter(|read| read["ok"] == false && read["failure"] == "not_found").collect();
for entry in state["commitments"].as_array_mut().into_iter().flatten().filter(|entry| entry["status"] == "open") {
for entry in state.get_mut("commitments").and_then(Value::as_array_mut).into_iter().flatten().filter(|entry| entry["status"] == "open") {
let Some(needs) = entry["needs"].as_str().map(str::to_owned) else { continue };
let Some(read) = failed.iter().find(|read| {
let target = read["request"]["target"].as_str().unwrap_or_default();
@ -325,12 +325,12 @@ fn apply_one(state: &mut Value, proposal: &Proposal, record: &Value, prose: &str
let listed = record["interpreter"]["promises"].as_array().into_iter().flatten().find(|shown| shown["id"].as_str() == Some(id.trim())).ok_or(Refusal::NoSuchPromise)?;
let entries = state["commitments"].as_array_mut().expect("commitments is an array");
let entry = entries.iter_mut().find(|entry| entry["id"] == listed["entry"]).ok_or(Refusal::OutsidePutRemovedTarget)?;
if listed["held"] != *entry {
return Err(Refusal::OutsidePutChanged);
}
if !matches!(entry["status"].as_str(), Some("open" | "blocked")) {
return Err(Refusal::ReaffirmsClosed);
}
if listed["held"] != *entry {
return Err(Refusal::OutsidePutChanged);
}
if entry["to"] != json!(to) {
return Err(Refusal::ReaffirmsAnother);
}