fix: recover revision conflicts across transports
Recognize stale/mismatched revision messages independently of their I/O error kind, retain bounded resnapshot retries, and render surfaced conflicts with warning severity.\n\nTests: cargo fmt --all -- --check\nTests: cargo test -p tui --all-features\nTests: cargo check --workspace --all-targets --all-features\nTests: cargo clippy -p tui --all-targets --all-features -- -D warnings
This commit is contained in:
parent
7b18fe5030
commit
69975e57dd
|
|
@ -432,7 +432,9 @@ latest-value-per-object; mute presses remain a bounded FIFO. Confirmed snapshots
|
|||
replace the local base and retain optimistic overlays until observation settles
|
||||
them. Poll quickly while writes are pending, slowly while idle, and resnapshot
|
||||
then retry a bounded number of times after stale mutations so consecutive
|
||||
server revisions cannot roll an optimistic edit back. Start immediately with a
|
||||
server revisions cannot roll an optimistic edit back. Revision conflicts are
|
||||
recognized from their protocol message rather than a transport-specific I/O
|
||||
kind and are presented as recoverable warnings. Start immediately with a
|
||||
disconnected placeholder when the socket is absent, retain the last confirmed items across
|
||||
transport failures, surface the connection error inside the terminal, and keep
|
||||
retrying so starting or restarting the server reconnects without restarting the
|
||||
|
|
|
|||
2
task.md
2
task.md
|
|
@ -255,6 +255,8 @@ Dependencies: M3, M2; may proceed after the fake-adapter slice.
|
|||
Each request receives a complete current snapshot; stale edit revisions
|
||||
trigger bounded background resnapshot/retry attempts, covering consecutive
|
||||
server revisions without allowing an unbounded retry loop. The TUI's IPC
|
||||
client recognizes revision conflicts independent of their transport error
|
||||
kind and renders any surfaced conflict as a warning rather than a fatal error.
|
||||
worker exits independently of the server, starts with a disconnected placeholder when the
|
||||
socket is absent, retains the last confirmed view during failures, and retries
|
||||
until a server appears again. Competing edits from one attached revision prove
|
||||
|
|
|
|||
|
|
@ -894,7 +894,7 @@ fn execute_action<C: MixerClient>(
|
|||
Ok(snapshot) => return Ok(snapshot),
|
||||
Err(error)
|
||||
if can_retry_stale
|
||||
&& error.kind() == io::ErrorKind::InvalidData
|
||||
&& is_revision_conflict(&error)
|
||||
&& attempt + 1 < MAX_STALE_ATTEMPTS =>
|
||||
{
|
||||
first_error.get_or_insert_with(|| error.to_string());
|
||||
|
|
@ -913,6 +913,18 @@ fn execute_action<C: MixerClient>(
|
|||
unreachable!("bounded action retry loop always returns")
|
||||
}
|
||||
|
||||
fn is_revision_conflict(error: &io::Error) -> bool {
|
||||
is_revision_conflict_message(&error.to_string())
|
||||
}
|
||||
|
||||
fn is_revision_conflict_message(message: &str) -> bool {
|
||||
let message = message.to_ascii_lowercase();
|
||||
message.contains("revision")
|
||||
&& ["stale", "mismatch", "conflict", "changed"]
|
||||
.iter()
|
||||
.any(|marker| message.contains(marker))
|
||||
}
|
||||
|
||||
fn publish_confirmed(state: &mut BufferedState, confirmed: &MixerSnapshot) {
|
||||
state.snapshot = confirmed.clone();
|
||||
for action in &state.configuration_work {
|
||||
|
|
@ -3143,7 +3155,11 @@ impl<C: MixerClient> Widget for &LiveTui<C> {
|
|||
)
|
||||
.render(header, buf);
|
||||
|
||||
let status_error = self.client_error.is_some()
|
||||
let client_warning = self
|
||||
.client_error
|
||||
.as_deref()
|
||||
.is_some_and(is_revision_conflict_message);
|
||||
let status_error = self.client_error.is_some() && !client_warning
|
||||
|| self
|
||||
.snapshot
|
||||
.devices
|
||||
|
|
@ -3162,7 +3178,9 @@ impl<C: MixerClient> Widget for &LiveTui<C> {
|
|||
.fg(theme.accent)
|
||||
.bold(),
|
||||
)
|
||||
.title_bottom(if status_error {
|
||||
.title_bottom(if client_warning {
|
||||
status.fg(theme.warning)
|
||||
} else if status_error {
|
||||
status.fg(theme.error)
|
||||
} else {
|
||||
status.fg(theme.muted)
|
||||
|
|
@ -5303,6 +5321,32 @@ mod tests {
|
|||
assert!(!rendered.contains("move"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn revision_conflicts_are_shown_as_recoverable_warnings() {
|
||||
let mut app = LiveTui::new(DemoClient::default()).unwrap();
|
||||
app.client_error = Some("stale configuration revision 4; current revision is 5".to_owned());
|
||||
let area = Rect::new(0, 0, 100, 20);
|
||||
let mut buffer = Buffer::empty(area);
|
||||
|
||||
(&app).render(area, &mut buffer);
|
||||
|
||||
let rendered = buffer
|
||||
.content
|
||||
.iter()
|
||||
.map(|cell| cell.symbol())
|
||||
.collect::<String>();
|
||||
assert!(rendered.contains("stale configuration revision"));
|
||||
let warning = app.theme().palette().warning;
|
||||
assert!(
|
||||
buffer
|
||||
.content
|
||||
.iter()
|
||||
.filter(|cell| cell.fg == warning && cell.symbol() != " ")
|
||||
.count()
|
||||
>= "staleconfigurationrevision".len()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_chooses_fader_group_or_separator_and_opens_the_relevant_editor() {
|
||||
let edits = Arc::new(Mutex::new(Vec::new()));
|
||||
|
|
@ -7466,13 +7510,10 @@ mod tests {
|
|||
self.attempts.push(expected_revision);
|
||||
if self.attempts.len() <= 2 {
|
||||
self.snapshot.configuration.revision += 1;
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::InvalidData,
|
||||
format!(
|
||||
"stale configuration revision {expected_revision}; current revision is {}",
|
||||
self.snapshot.configuration.revision
|
||||
),
|
||||
));
|
||||
return Err(io::Error::other(format!(
|
||||
"stale configuration revision {expected_revision}; current revision is {}",
|
||||
self.snapshot.configuration.revision
|
||||
)));
|
||||
}
|
||||
apply_optimistic_configuration_edit(&mut self.snapshot, &edit);
|
||||
self.snapshot.configuration.revision += 1;
|
||||
|
|
|
|||
Loading…
Reference in New Issue