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
2 changes: 2 additions & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ Herdr moves that memory silently: a close that removes a workspace's active tab
The replica therefore asks `workspace.get` for the replacement the moment such a close is applied and on each operation tick while the answer names a tab the stream has not delivered yet; a workspace still waiting after a bounded number of reads is a replica that cannot converge, and it is rebuilt from a fresh snapshot.
Waiting for the focus event alone froze the whole workspace's projection, so a closed pane stayed drawn as `closing…` for three to five seconds, until the operator's next tab focus or the close deadline's status check.
The focused checkout always draws the tab that holds the selected pane: a tab action moves the pane into the tab, and a pane action, a restore, or a retirement moves the tab to the pane (`align_visible_tab_with_selected_pane`).
A retired selection lands, in order, in the tab it was in, in the tab the same session pass has the checkout showing, and only then where Herdr's keyboard is, because Herdr's keyboard can sit in another Agent area.
A reopen's seed tab shows why: its events arrive after the reopen answered, so its focus can be followed after the restored tab was placed, and when the seed went the selection took the other area's tab Herdr named and the restored tab lost the screen (#425).
The pending model covers the visible tab and the focused pane: zoom, splits, closes and resizes still wait for Herdr, because their geometry decides the PTY size (commit 9570a2a), and they keep their own operation records below rather than the lane; a close that removes a whole tab waits as well but is drawn gone at once (Reopening locally closed work).
Every Herdr-owned mutation has one core-owned operation record with a host connection generation, target and conflict-scope IDs, phase, stage, start time, absolute deadline, caller-visible message, and retry policy; the records are exported as `status.async_operations`.
Transport success is not topology truth: split, zoom, resize, move, and close remain pending until an authoritative session event or fresh snapshot identifies the exact created, changed, or absent topology.
Expand Down
26 changes: 26 additions & 0 deletions herdr-core/src/runtime/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2341,6 +2341,32 @@ impl Runtime {
.map(|layout| layout.focused_pane_id.as_str())
})
.filter(|pane_id| focused_checkout_pane_set.contains(*pane_id))
.or_else(|| {
// The tab this pass has the checkout
// showing is where the operator looks.
// Herdr's keyboard can be on another Agent
// area's tab, and landing there moves the
// screen with it: a reopen's seed tab,
// followed, went as its restored tab came
// (#425).
self.snapshot
.ui_state
.focused_checkout_id
.as_deref()
.and_then(|checkout_id| {
self.visible_tab_ids.get(checkout_id)
})
.and_then(|tab_id| {
payload
.layouts
.iter()
.find(|layout| &layout.tab_id == tab_id)
})
.map(|layout| layout.focused_pane_id.as_str())
.filter(|pane_id| {
focused_checkout_pane_set.contains(*pane_id)
})
})
.or_else(|| {
payload.focused_pane_id.as_deref().filter(|pane_id| {
focused_checkout_pane_set.contains(*pane_id)
Expand Down
97 changes: 97 additions & 0 deletions herdr-core/src/runtime/tests/agent_areas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1248,3 +1248,100 @@ fn a_reopen_waiting_for_a_refused_close_is_dropped_and_never_reopens_an_older_cl
assert!(!runtime.snapshot().recent_closed.restoring);
assert_eq!(runtime.snapshot().recent_closed.count, 1);
}

/// Herdr makes a reopened tab inside a seed tab it then replaces
/// (`workspace.create`, then `layout.apply`), and the seed's focus can reach
/// the core after the reopen's own answer, when it is followed like any move
/// of Herdr's. When the seed goes, the keyboard stays on the restored tab the
/// checkout shows, never on the other area's tab Herdr's keyboard names
/// (#425, `agent-tab-groups.spec.ts` "New tab and Reopen use the
/// requested area").
#[test]
fn a_followed_reopen_seed_that_goes_leaves_the_operator_on_the_restored_tab() {
let (mut runtime, checkout) = two_areas_on_t1();
close_tab(&mut runtime, "w-order:t3");
answer_close(&mut runtime, Ok(()));
let after_close = ["w-order:t1", "w-order:t2"];
runtime.ingest_session(Ok(tab_order_payload(
"/agent-groups",
&after_close,
&after_close,
"w-order:t1",
)));
action(
&mut runtime,
serde_json::json!({"action":"focus","tab_id":"w-order:t2"}),
);
// Herdr confirms the click on the right area's tab.
runtime.ingest_session(Ok(tab_order_payload(
"/agent-groups",
&after_close,
&after_close,
"w-order:t2",
)));
let item = runtime.recent_closed.back().cloned().expect("t3 to reopen");
reopen(&mut runtime);
assert!(runtime.reopen_in_flight.is_some(), "the reopen started");
runtime.ingest_reopen_result(
&live::ReopenRequest {
codex_daemon: Default::default(),
item,
workspace_exists: true,
tab_exists: false,
fallback_pane_id: None,
owner: None,
},
Ok(live::FileReopenResultOrHerdr::Herdr(live::ReopenOutcome {
tab_id: Some("w-order:t4".into()),
consumed: true,
focused_pane_id: Some("w-order:t4:p".into()),
notices: vec![],
})),
);

// The seed's creation and its focus reach the core after that answer.
let seeded = ["w-order:t1", "w-order:t2", "w-order:t8"];
let mut seed = tab_order_payload("/agent-groups", &seeded, &seeded, "w-order:t8");
seed.tab_focus = Some(crate::sidebar::SessionTabFocus {
generation: 1,
workspace_id: "w-order".into(),
tab_id: "w-order:t8".into(),
revision: 1,
creation: true,
});
runtime.ingest_session(Ok(seed.clone()));
let focus = seed.tab_focus.as_mut().unwrap();
focus.creation = false;
focus.revision = 2;
runtime.ingest_session(Ok(seed));
assert_eq!(
runtime.snapshot().terminal.pane_id.as_deref(),
Some("w-order:t8:p"),
"the seed's focus was followed"
);

// The seed goes and the restored tab arrives, with Herdr's keyboard back
// on the right area's tab.
let restored = ["w-order:t1", "w-order:t2", "w-order:t4"];
runtime.ingest_session(Ok(tab_order_payload(
"/agent-groups",
&restored,
&restored,
"w-order:t2",
)));
assert_eq!(
drawn(&mut runtime),
[
area("w-order:t4", &["w-order:t1", "w-order:t4"]),
area("w-order:t2", &["w-order:t2"])
]
);
assert_eq!(
checkout_active_tab_id(&runtime, &checkout).as_deref(),
Some("w-order:t4")
);
assert_eq!(
runtime.snapshot().terminal.pane_id.as_deref(),
Some("w-order:t4:p")
);
}
Loading