Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ The update is ingested at once, with the layout, the panes and every other part
Exactly one read is outstanding (`pane_focus_readback`, a slot the runtime takes under the lock as it ingests and the worker frees on every way out, including a panic), so a slow Herdr delays only that focus: an earlier version read before ingesting, and a pane close or zoom behind a slow answer reached the screen up to ten seconds late (#424).
A confirmed answer applies the layout the session already stored, with its focus and zoom, after the identity is rechecked under the lock against the current pane-request serial and connection generation; an answer whose identity is stale, or whose move the stored layout no longer shows, moves nothing and hands the worker the read the stored layout does call for.
An unconfirmed answer keeps Hide's keyboard focus and is asked again with the next session update, never in a loop.
An update that called for a read while the slot was taken is that next update: the answer may have been read before Herdr made the move it shows, so the worker reads again for it, where it used to be dropped and an external move landing during a read of a stale layout was never followed.
A refusal or timeout keeps the core-owned context at the requested target, records a diagnostic and resolves the correlated shell request as a retryable failure; the shell presents Retry and Dismiss, and Dismiss clears only that notice.
A non-focused workspace's active tab is that workspace's memory, never a focus to follow: folding every workspace's active tab into one value per checkout let the last one overwrite the rest, and every tab focus on the other workspace timed out and snapped back.
Herdr moves that memory silently: a close that removes a workspace's active tab is followed by `tab_focused` only when the workspace holds Herdr's keyboard focus, and by nothing at all otherwise.
Expand Down
5 changes: 5 additions & 0 deletions herdr-core/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,10 @@ pub struct Runtime {
/// the session itself is already ingested, so a slow Herdr delays only
/// the focus, never the topology that arrived with it.
pane_focus_readback: Option<PendingPaneFocusControl>,
/// A session update called for a readback while the one slot was taken.
/// The outstanding answer may have been read before that update, so an
/// unconfirmed answer is asked again rather than losing the move.
pane_focus_readback_again: bool,
next_pane_focus_serial: u64,
/// The one ordered lane the local tab and pane focus controls travel on.
control_lane: ControlLane,
Expand Down Expand Up @@ -1779,6 +1783,7 @@ impl Runtime {
pending_pane_focus: None,
pane_focus_in_flight: None,
pane_focus_readback: None,
pane_focus_readback_again: false,
control_lane: ControlLane::default(),
last_view_intent_serial: 0,
next_pane_focus_serial: 0,
Expand Down
14 changes: 10 additions & 4 deletions herdr-core/src/runtime/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1981,12 +1981,15 @@ impl Runtime {
})
}

/// Takes the one readback slot for the move the stored layouts show.
/// Takes the one readback slot for the move the stored layouts show. A
/// move that finds the slot taken is remembered for the answer to settle.
fn begin_pane_focus_readback(&mut self) -> Option<PendingPaneFocusControl> {
let identity = self.pane_focus_readback_target()?;
if self.pane_focus_readback.is_some() {
self.pane_focus_readback_again = true;
return None;
}
let identity = self.pane_focus_readback_target()?;
self.pane_focus_readback_again = false;
self.pane_focus_readback = Some(identity.clone());
Some(identity)
}
Expand All @@ -1999,6 +2002,7 @@ impl Runtime {
/// Frees the readback slot for a worker that ended without an answer.
pub(crate) fn abandon_pane_focus_readback(&mut self) {
self.pane_focus_readback = None;
self.pane_focus_readback_again = false;
}

/// Settles the readback for `identity` and returns whether the snapshot
Expand All @@ -2009,13 +2013,15 @@ impl Runtime {
/// now with its focus and zoom. The identity is checked again there:
/// a newer selection, a pending focus request or another connection
/// leaves the answer without authority. An unconfirmed answer changes
/// nothing and is not asked again until the next session update.
/// nothing and is not asked again until the next session update; an
/// update that arrived while the read was out is that next update.
pub(crate) fn finish_pane_focus_readback(
&mut self,
identity: PendingPaneFocusControl,
confirmed: bool,
) -> (bool, Option<PendingPaneFocusControl>) {
self.pane_focus_readback = None;
let again = std::mem::take(&mut self.pane_focus_readback_again);
let stored = self
.snapshot
.pane_layouts
Expand All @@ -2038,7 +2044,7 @@ impl Runtime {
changed |= self.settle_selection_projection();
changed |= self.refresh_browser_inventory_scope();
}
let next = if confirmed || stored.is_none() {
let next = if confirmed || stored.is_none() || again {
self.begin_pane_focus_readback()
} else {
None
Expand Down
28 changes: 28 additions & 0 deletions herdr-core/src/runtime/tests/session_navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,34 @@ fn only_one_pane_focus_readback_is_outstanding_and_a_superseded_one_hands_on() {
assert!(runtime.pane_focus_readback.is_none());
}

#[test]
fn a_move_that_arrives_during_an_unconfirmed_readback_is_read_again() {
let mut runtime = live_runtime();
let panes = [("w1:p1", 6018_u64), ("w1:p2", 6019), ("w1:p3", 6020)];
runtime.ingest_session(Ok(finished_tab_payload(&panes, "w1:p1")));

// A late layout from an earlier burst shows p2 and starts a read.
let (_, stale) = runtime
.ingest_session_awaiting_focus_readback(Ok(finished_tab_payload(&panes, "w1:p2")), None);
let stale = stale.unwrap();
// Herdr really moves to p2 while that read is out: the layout looks the
// same, and the one slot is taken.
let (_, moved) = runtime
.ingest_session_awaiting_focus_readback(Ok(finished_tab_payload(&panes, "w1:p2")), None);
assert!(moved.is_none());

// The read was answered before the move, so it does not confirm. The
// move came after the read began, so it is read again rather than lost.
let (_, next) = runtime.finish_pane_focus_readback(stale, false);
assert_eq!(runtime.snapshot().focused.pane_id.as_deref(), Some("w1:p1"));
let next = next.expect("the move that arrived during the read is read again");
assert_eq!(next.target_id, "w1:p2");
runtime.finish_pane_focus_readback(next, true);
assert_eq!(runtime.snapshot().focused.pane_id.as_deref(), Some("w1:p2"));
assert_eq!(diagnostic_count(&runtime, "pane.focus.followed"), 1);
assert!(runtime.pane_focus_readback.is_none());
}

#[test]
fn superseded_same_pane_focus_failure_cannot_fail_a_newer_correlated_request() {
let mut runtime = live_runtime();
Expand Down
Loading