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 @@ -780,6 +780,7 @@ The last look is stamped when a visit commits and once a minute while a pane is
The hours count from the later of the agent's last conversation line and its last look (`PaneStamps::idle_since`).
The last conversation line is the newest request or reply the session read proves (`last_conversation_at_unix_ms`), because a relaunch or an engine restart reports a state for a moment and moves the change stamp without adding a line to the conversation; on 2026-10-22 one app update restarted every idle agent's 24 hours that way.
Until a session read proves a line, the change stamp stands in, so a restart only ever delays a sleep.
A pane's stamp, and the last look in it, is dropped only when the engine's topology no longer holds the pane, never because the agent list holds no agent for it: a restarted engine lists an agent only once its program shows again, and a stamp lost in that gap sleeps an agent the operator just read the moment the session read proves its old conversation (`AgentSleepStore::stamp`; the read records follow the same rule, `prune_read_records`).
A wake stamps a last look, as a visit does, because the conversation it resumes is as old as the sleep and would make the agent due again at the next minute.
A relaunch forgets an end that was in flight, because it cannot know whether it landed, and reads a wake that was in flight as still asleep until an agent appears in the pane.
An in-pane sleep keeps the read axis's engine mark beside the ended agent's state sequence: the sequence identifies the ended agent only on that engine, because an engine restart starts its counter again.
Expand Down Expand Up @@ -2532,6 +2533,7 @@ Schema 2 clients that request `snapshot_format: "semantic-rest-v1"` receive `res
Omission retains a value, `null` clears an optional value and an empty array or map clears a collection; `workspace_view` is explicitly null when absent in this format.
Without the capability, schema 2 keeps the supported complete-rest delta, including the omitted absent `workspace_view`; an unknown format is refused with `schema_mismatch` before snapshot delivery.
A mismatched token, Origin, or schema version, or a ninth concurrent client, is closed with a reason code (`invalid_token`, `origin_not_allowed`, `schema_mismatch`, `client_limit`) and a diagnostic log line.
The web shell follows a new token in its address by retiring the previous socket's pending file reads with `socket_closed` and clearing its browser-comment state before opening the successor; the previous socket's late close cannot reject the successor's reads.
After a valid handshake the daemon reads from the revision the client sent (`have_revision`, the cursor `Core::snapshot_delta_payload` takes), and then one delta frame per core notification burst.
A client with cursor 0 gets a self-contained `snapshot`; a reconnecting client resumes with a `delta` that carries only what changed while it was away.
When the core cannot serve the cursor, because the client's revision is ahead of the core's after a daemon restart, the daemon re-reads from zero and sends a `snapshot` (`server::classify_frame` owns that rule).
Expand Down
6 changes: 5 additions & 1 deletion docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,15 @@ A piece that another open change is still building is marked as pending with the
7. **Restart through `daemon.restart()`, and leave the old page first.**
`daemon.restart()` in `web/e2e/hided-fixture.ts` stops `hided` and starts it again on the same state folder and port, as a real restart does, and takes an optional callback to edit the state folder before the start; `web/e2e/sidebar-pr-start.spec.ts` restarts three times in one test.
It uses `hide stop` on every system and preserves the own engine's holders for adoption; only final fixture cleanup sweeps their process trees.
A navigation that only changes the hash does not remount the connection, so the old page keeps its old token and socket and races the new one.
It returns only after its own WebSocket reads the core's connected engine and, when a saved checkout is selected, its restored Workspace view.
`/health` alone proves only that the listener is back; this shared snapshot boundary keeps restart callers from acting on an unresolved saved selection.
A navigation that only changes the hash does not remount the page: its connection follows the new token (`followToken` in `web/src/ws.ts`), but the page it keeps has the old page's state and may already have been refused with the old token, so a test that reopens the product goes through a fresh page.
Go through `about:blank` before opening the new origin and token, as `openSettings` in `web/e2e/interface-language.spec.ts` does, and keep that step in one helper per spec.
Why: the old page and the new token reconnect at the same time and either can win.
`hide-e2e/reopen-after-restart-through-blank` fails a `goto` of `#token=` after `restart()` in the same function; a helper defined elsewhere and called after the restart is not seen, so keep the step in the helper.
A test whose subject is a surviving page reconnecting to the restarted daemon (`web/e2e/s3.spec.ts`, the two draft recovery tests) must not reload it, and says so in a line allow.
A restored editable draft needs an editable file: the View-tab draft test makes the parent folder unwritable to refuse atomic saves while keeping the file editable when the restarted node opens it.
Making that file itself read-only would correctly prevent the draft from being restored into it.
8. **Put a system difference in one fixture helper.**
See [Operating-system differences belong to one fixture helper](#operating-system-differences-belong-to-one-fixture-helper); native home variables, executable names, the tool path and the no-op opener live in `web/e2e/platform-fixture.ts`, not in a `process.platform` branch in a spec.
9. **A retry is a label, not a fix.**
Expand Down
43 changes: 38 additions & 5 deletions hide-core/src/agent_sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,11 +562,19 @@ impl AgentSleepStore {

/// Moves each awake agent's change stamp on one machine when its state
/// changed or it appeared, and drops the stamps of that machine's panes
/// that hold no agent now. Returns whether anything moved.
/// the engine's topology says are gone. Returns whether anything moved.
///
/// A pane that holds no agent now keeps its stamp, and with it its last
/// look: a restarted engine lists an agent only once its program shows
/// again, so the agent list is empty or incomplete for a while and is
/// never an eviction source (as for the read records,
/// `agent_state::prune_read_records`). `live_pane_ids` is the topology
/// of the same read; none keeps every stamp.
pub fn stamp(
&mut self,
agents: &[SidebarAgentSnapshot],
scope: SleepScope<'_>,
live_pane_ids: Option<&HashSet<String>>,
now_unix_ms: u64,
) -> bool {
let mut changed = false;
Expand Down Expand Up @@ -605,6 +613,7 @@ impl AgentSleepStore {
!scope.holds(pane_id)
|| present.contains(pane_id.as_str())
|| self.records.contains_key(pane_id)
|| live_pane_ids.is_none_or(|live| live.contains(pane_id))
});
changed | (self.stamps.len() != before)
}
Expand Down Expand Up @@ -839,7 +848,7 @@ mod tests {
/// A store that first saw `agents` at time zero.
fn stamped(agents: &[SidebarAgentSnapshot]) -> AgentSleepStore {
let mut store = AgentSleepStore::default();
store.stamp(agents, SleepScope::Core, 0);
store.stamp(agents, SleepScope::Core, None, 0);
store
}

Expand Down Expand Up @@ -904,9 +913,9 @@ mod tests {
let mut store = stamped(&agents);
// A relaunch reports a state for a moment.
agents[0].activity = "unknown".to_owned();
assert!(store.stamp(&agents, SleepScope::Core, 20 * HOUR));
assert!(store.stamp(&agents, SleepScope::Core, None, 20 * HOUR));
agents[0].activity = "stopped".to_owned();
assert!(store.stamp(&agents, SleepScope::Core, 20 * HOUR));
assert!(store.stamp(&agents, SleepScope::Core, None, 20 * HOUR));
assert!(due_at(&store, &agents, 25 * HOUR - 1).is_empty());
assert_eq!(due_at(&store, &agents, 25 * HOUR), ["w1:p1"]);

Expand All @@ -918,12 +927,36 @@ mod tests {
assert_eq!(due_at(&store, &agents, 64 * HOUR), ["w1:p1"]);
}

#[test]
fn a_pane_without_an_agent_keeps_its_last_look_until_the_pane_itself_is_gone() {
let mut agents = [agent("w1:p1")];
agents[0].last_conversation_at_unix_ms = Some(HOUR);
let mut store = stamped(&agents);
store.mark_seen(["w1:p1"], 10 * HOUR);
let live = HashSet::from(["w1:p1".to_owned()]);

// A restarted engine lists an agent only once its program shows again.
assert!(!store.stamp(&[], SleepScope::Core, Some(&live), 11 * HOUR));
agents[0].activity = "unknown".to_owned();
assert!(store.stamp(&agents, SleepScope::Core, Some(&live), 12 * HOUR));
agents[0].activity = "stopped".to_owned();
assert!(store.stamp(&agents, SleepScope::Core, Some(&live), 13 * HOUR));
assert!(due_at(&store, &agents, 34 * HOUR - 1).is_empty());
assert_eq!(due_at(&store, &agents, 34 * HOUR), ["w1:p1"]);

// No topology to judge by evicts nothing; one that lacks the pane does.
assert!(!store.stamp(&[], SleepScope::Core, None, 14 * HOUR));
assert!(store.stamps.contains_key("w1:p1"));
assert!(store.stamp(&[], SleepScope::Core, Some(&HashSet::new()), 15 * HOUR));
assert!(store.stamps.is_empty());
}

#[test]
fn without_a_conversation_read_a_state_change_restarts_the_clock() {
let mut agents = [agent("w1:p1")];
let mut store = stamped(&agents);
agents[0].completed = true;
assert!(store.stamp(&agents, SleepScope::Core, 20 * HOUR));
assert!(store.stamp(&agents, SleepScope::Core, None, 20 * HOUR));
assert!(due_at(&store, &agents, 24 * HOUR).is_empty());
assert_eq!(due_at(&store, &agents, 44 * HOUR), ["w1:p1"]);
}
Expand Down
21 changes: 13 additions & 8 deletions hide-core/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,18 @@ fn prune_pane_text_scales(
scales.len() != before
}

/// Every pane the remote topology holds, independent of agent detection or focus.
fn remote_live_pane_ids(session: &RemoteSessionSnapshot) -> HashSet<String> {
session
.workspaces
.iter()
.flat_map(|workspace| workspace.checkouts.iter())
.flat_map(|checkout| checkout.tabs.iter())
.flat_map(|tab| tab.panes.iter())
.map(|pane| pane.id.clone())
.collect()
}

/// Every pane `session` lists, and the panes on screen: while its machine
/// is in front, exactly the tabs its selected group shows. Without a core
/// layout, the legacy engine-focused tab supplies the initial canvas.
Expand All @@ -1036,14 +1048,7 @@ fn remote_terminal_pane_sets(
target_is_active: bool,
shown_tabs: Option<&[String]>,
) -> (HashSet<String>, HashSet<String>) {
let live_pane_ids = session
.workspaces
.iter()
.flat_map(|workspace| workspace.checkouts.iter())
.flat_map(|checkout| checkout.tabs.iter())
.flat_map(|tab| tab.panes.iter())
.map(|pane| pane.id.clone())
.collect::<HashSet<_>>();
let live_pane_ids = remote_live_pane_ids(session);
if !target_is_active {
return (live_pane_ids, HashSet::new());
}
Expand Down
20 changes: 15 additions & 5 deletions hide-core/src/runtime/agent_sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,24 +266,34 @@ impl Runtime {

/// Marks the projected rows that sleep and moves each awake agent's
/// change stamp. The stamps are persisted, never published.
pub(super) fn stamp_agent_sleep(&mut self, agents: &mut [SidebarAgentSnapshot]) {
pub(super) fn stamp_agent_sleep(
&mut self,
agents: &mut [SidebarAgentSnapshot],
live_pane_ids: Option<&HashSet<String>>,
) {
self.confirm_dormant_wake(agents);
self.stamp_agent_sleep_in(agents, SleepScope::Core);
self.stamp_agent_sleep_in(agents, SleepScope::Core, live_pane_ids);
}

/// The same for the rows of another machine.
pub(super) fn stamp_node_agent_sleep(
&mut self,
device: &str,
agents: &mut [SidebarAgentSnapshot],
live_pane_ids: &HashSet<String>,
) {
self.stamp_agent_sleep_in(agents, SleepScope::Device(device));
self.stamp_agent_sleep_in(agents, SleepScope::Device(device), Some(live_pane_ids));
}

fn stamp_agent_sleep_in(&mut self, agents: &mut [SidebarAgentSnapshot], scope: SleepScope<'_>) {
fn stamp_agent_sleep_in(
&mut self,
agents: &mut [SidebarAgentSnapshot],
scope: SleepScope<'_>,
live_pane_ids: Option<&HashSet<String>>,
) {
let store = &mut self.snapshot.ui_state.agent_sleep;
store.annotate(agents);
if store.stamp(agents, scope, unix_milliseconds()) {
if store.stamp(agents, scope, live_pane_ids, unix_milliseconds()) {
self.persist_ui_state();
}
}
Expand Down
17 changes: 5 additions & 12 deletions hide-core/src/runtime/agents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1711,16 +1711,9 @@ impl Runtime {
&mut self,
target_id: &str,
session: &mut RemoteSessionSnapshot,
live_pane_ids: &HashSet<String>,
) -> bool {
let look = self.reading_device_look(target_id, session);
let live_pane_ids = session
.workspaces
.iter()
.flat_map(|workspace| workspace.checkouts.iter())
.flat_map(|checkout| checkout.tabs.iter())
.flat_map(|tab| tab.panes.iter())
.map(|pane| pane.id.clone())
.collect::<HashSet<_>>();
// The lineage comes first because the read fingerprint carries what
// each row's descendants are doing, and that is only known once the
// tree is built (PRD B5).
Expand All @@ -1737,17 +1730,17 @@ impl Runtime {
&mut session.agents,
Some(target_id),
ReadRecordScope::Remote(target_id),
Some(&live_pane_ids),
Some(live_pane_ids),
);
self.apply_pane_launches(
&mut session.agents,
ReadRecordScope::Remote(target_id),
Some(&live_pane_ids),
Some(live_pane_ids),
);
self.lay_start_prompts(
&mut session.agents,
ReadRecordScope::Remote(target_id),
Some(&live_pane_ids),
Some(live_pane_ids),
);
self.lay_unseen_views(&mut session.agents);
self.lay_human_turns(&mut session.agents);
Expand All @@ -1759,7 +1752,7 @@ impl Runtime {
let mut records = std::mem::take(&mut self.snapshot.ui_state.pane_read_records);
let mut changes = crate::agent_state::prune_read_records(
&mut records,
&live_pane_ids,
live_pane_ids,
ReadRecordScope::Remote(target_id),
);
let connection = self.read_connection(Some(target_id));
Expand Down
7 changes: 4 additions & 3 deletions hide-core/src/runtime/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2063,9 +2063,10 @@ impl Runtime {
self.overlay_remote_pane_moves(target_id, session);
// A node that dials this core sleeps as the core's own machine
// does (PRD core-host-node-remote-core B13).
self.stamp_node_agent_sleep(target_id, &mut session.agents);
let live_pane_ids = remote_live_pane_ids(session);
self.stamp_node_agent_sleep(target_id, &mut session.agents, &live_pane_ids);
self.lay_plan_reviews(target_id, &mut session.agents);
read_changed = self.apply_remote_read_state(target_id, session);
read_changed = self.apply_remote_read_state(target_id, session, &live_pane_ids);
for workspace in &mut session.workspaces {
for checkout in &mut workspace.checkouts {
for tab in &mut checkout.tabs {
Expand Down Expand Up @@ -3195,7 +3196,7 @@ impl Runtime {
if let Some(mut agents) = agents {
let held = Arc::clone(&self.herdr_held);
let local = ReadRecordScope::Local(&held);
self.stamp_agent_sleep(&mut agents);
self.stamp_agent_sleep(&mut agents, live_pane_ids.as_ref());
self.place_agents_in_navigator(&mut agents);
// The lineage is built before the read axis is applied, because
// the read fingerprint carries what each row's descendants are
Expand Down
35 changes: 35 additions & 0 deletions hide-core/src/runtime/tests/agent_sleep.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1931,6 +1931,41 @@ fn the_input_gate_follows_the_sleep_records_from_the_first_moment_of_the_end() {
);
}

/// A restarted engine lists an agent only once its program shows again, so
/// the first reads after a daemon start hold none for a pane that has one: the
/// pane's last look, which keeps an old conversation from sleeping an agent the
/// operator just read, must outlive them (with-hide/hide-private#682).
#[test]
fn a_read_that_lists_no_agent_for_a_pane_keeps_the_panes_last_look() {
let (mut runtime, checkout_id) = live_tab_order_runtime(CHECKOUT);
runtime.ingest_session(Ok(session(Some(4))));
assert!(runtime.dispatch_json(&focus_tab_event(&checkout_id, "w-order:t2")));
let seen = |runtime: &Runtime| {
runtime
.snapshot()
.ui_state
.agent_sleep
.stamps
.get(SLEEPER)
.map(|stamps| stamps.seen_at_unix_ms)
};
let looked = seen(&runtime).expect("the visit stamped the pane");
assert!(looked > 0);

runtime.ingest_session(Ok(session(None)));
assert_eq!(seen(&runtime), Some(looked), "the pane is still there");
runtime.ingest_session(Ok(session(Some(1))));
assert_eq!(seen(&runtime), Some(looked), "the agent is back");

let gone = tab_order_payload(CHECKOUT, &["w-order:t1"], &["w-order:t1"], "w-order:t1");
runtime.ingest_session(Ok(gone));
assert_eq!(
seen(&runtime),
None,
"a pane the topology lost takes its stamp"
);
}

/// B12, D-12: a committed visit to the tab wakes the agent; another event
/// in the same tab is not a visit, and a second wake starts nothing.
#[test]
Expand Down
Loading
Loading