fix(core): preserve unknown outcomes when room bindings retire

A room writer may already have accepted a request when its binding retires or the requester changes. Return the existing Unknown result for dispatched work instead of treating the operation as rejected. Admission refusals still report errors.

The room writer and request-correlation contract require confirmed outcomes before retry. Verified the WatchReady-then-retirement sequence and all 348 SQLite Core tests on the frozen candidate.
This commit is contained in:
AAA committed 2026-11-27 22:29:18 -05:00
1 parent a11c7318d5
commit ebb370950e
4 files changed
+36 -9

No files matched your search

+1 -3
View File
@@ -2143,9 +2143,7 @@ impl Channel {
result: if current {
completion.unwrap()
} else {
RoomResult::Error {
code: "room_context_changed".into(),
}
RoomResult::Unknown
},
}
})
+1 -3
View File
@@ -225,9 +225,7 @@ impl RemoteRoom {
self.summary.id.clone(),
RoomReply {
context,
result: RoomResult::Error {
code: "room_context_changed".into(),
},
result: RoomResult::Unknown,
},
)),
_ => None,
+2 -3
View File
@@ -480,8 +480,7 @@ fn pending_room_request_finishes_when_its_host_binding_retires() {
} else {
assert_eq!(replies.len(), 1, "{case} left its room request pending");
assert!(
matches!(replies[0], (target, Event::Reply { room_id: Some(id), result: ReplyResult::Error { code }, .. })
if *target == reader && id == room_id && code == "room_context_changed")
matches!(replies[0], (target, Event::Reply { room_id: Some(id), result: ReplyResult::Unknown, .. }) if *target == reader && id == room_id)
);
}
let late = review_host_turn(&mut core, owner, room_id, delayed);
@@ -668,7 +667,7 @@ fn room_entry_waits_for_commit_without_blocking_site_identity() {
);
assert!(!stopped.close.contains(&c));
assert!(stopped.events.iter().any(|(target,e)| *target==c && matches!(e,
Event::Reply { room_id: Some(_), request_id: id, result: ReplyResult::Error { code } } if id=="entry" && code=="room_context_changed")));
Event::Reply { room_id: Some(_), request_id: id, result: ReplyResult::Unknown } if id=="entry")));
}
#[test]
+32
View File
@@ -1045,3 +1045,35 @@ fn leaving_retired_screen_cancels_only_the_callers_pending_handoff() {
assert_eq!(net.state(viewer).watch_activities[0].predecessor, None);
assert_eq!(net.state(other).watch_activities[0].predecessor, Some(ViewSource::Screen(screen)));
}
#[test]
fn retiring_host_after_watch_commit_reports_unknown_to_requester() {
use piik_channel_core::{host::RoomResult, wire::{Command, Request}};
let (mut net, owner, viewer, room) = setup();
let request = Request::parse(&start(&room, Uuid::new_v4()).to_string()).unwrap();
let dispatched = net.authority.handle(viewer, request, 2000);
let input = dispatched.events.into_iter().find_map(|(_, event)| match event {
Event::HostInput { input, .. } => Some(input),
_ => None,
}).unwrap();
let output = net.host_turn(&room, input);
assert!(matches!(output.reply.as_ref().unwrap().result, RoomResult::WatchReady { .. }));
let update = Request::parse(&json!({"type":"update_room","roomId":room,"name":"Renamed","requestId":"manage"}).to_string()).unwrap();
let management = net.authority.handle(owner, update, 2000);
assert!(management.events.iter().any(|(_, event)| matches!(event, Event::HostInput { .. })));
let stopped = net.authority.handle(owner, Request {
request_id: None,
command: Command::HostStop { room_id: room.clone(), binding_id: output.binding_id },
}, 2001);
assert!(stopped.events.iter().any(|(target, event)| *target == viewer && matches!(event,
Event::Reply { request_id, result: ReplyResult::Unknown, .. } if request_id == "start")));
assert!(stopped.events.iter().any(|(target, event)| *target == owner && matches!(event,
Event::Reply { request_id, result: ReplyResult::Unknown, .. } if request_id == "manage")));
let late = net.authority.handle(owner, Request {
request_id: None, command: Command::HostOutput { room_id: room.clone(), output },
}, 2002);
assert!(!late.events.iter().any(|(target, event)| *target == viewer && matches!(event, Event::Reply { .. })));
let retry = net.command_at(viewer, start(&room, Uuid::new_v4()), 2003);
assert!(retry.events.iter().any(|(target, event)| *target == viewer && matches!(event,
Event::Reply { request_id, result: ReplyResult::Error { .. }, .. } if request_id == "start")));
}