fix(tui): retry composer history atomic writes#2277
Conversation
There was a problem hiding this comment.
Hmbown has reached the 50-review limit for trial accounts. To continue receiving code reviews, upgrade your plan.
There was a problem hiding this comment.
Code Review
This pull request introduces a retry mechanism with backoff delays (write_history_atomic) when persisting composer history to disk. The reviewer suggested simplifying the retry loop to make it more idiomatic and readable by removing the complex iterator chain and unreachable! macro, handling the final write attempt outside the loop instead.
| for (attempt, delay) in RETRY_DELAYS | ||
| .iter() | ||
| .map(Some) | ||
| .chain(std::iter::once(None)) | ||
| .enumerate() | ||
| { | ||
| match crate::utils::write_atomic(path, payload) { | ||
| Ok(()) => return Ok(()), | ||
| Err(err) if delay.is_some() => { | ||
| tracing::debug!( | ||
| "Retrying composer history write to {} after attempt {} failed: {err}", | ||
| path.display(), | ||
| attempt + 1 | ||
| ); | ||
| std::thread::sleep(*delay.expect("delay checked")); | ||
| } | ||
| Err(err) => return Err(err), | ||
| } | ||
| } | ||
|
|
||
| unreachable!("retry iterator always ends with a final write attempt") |
There was a problem hiding this comment.
The current retry loop uses a complex iterator chain (.map(Some).chain(std::iter::once(None))) and an unreachable! macro to handle the final write attempt. We can simplify this significantly and make it more idiomatic by looping over the retry delays and performing the final write attempt outside the loop. This avoids the need for option wrapping, unwrapping, and the unreachable! assertion.
for (attempt, &delay) in RETRY_DELAYS.iter().enumerate() {
match crate::utils::write_atomic(path, payload) {
Ok(()) => return Ok(()),
Err(err) => {
tracing::debug!(
"Retrying composer history write to {} after attempt {} failed: {err}",
path.display(),
attempt + 1
);
std::thread::sleep(delay);
}
}
}
crate::utils::write_atomic(path, payload)|
Independent review:
|
Summary
composer_history::tests::append_history_dispatched_does_not_block_the_callerseen on docs: add provider registry drift check #2274 and earlier on fix(tui): make update hint transient (#2254) #2275Refs #2274.
Verification