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
3 changes: 3 additions & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,9 @@ A save whose answer was lost to a timeout or a dropped connection is `unknown`:

An Explorer change (`file_create`, `dir_create`, `path_rename`, `path_move`, `path_trash`) is one `hide_host` request too (`hide-host/src/mutate.rs`, `files::apply_explorer_operation`), made by the host of the checkout in front on a worker: this machine's in process, a device's by its helper.
The event names the device whose tree asked, and a change for another device than the one in front is refused (B34); hided lets a device's change past this machine's checkout roots and the helper confines every path to the opened root.
Changes run one at a time, in the order they were asked, because the page sends a change without waiting for the one before it (a drop, then the key that trashes the folder it landed in).
The core holds the running change in `explorer_operation` and up to four asked meanwhile in its own queue (`request_explorer_change` in `runtime/session.rs`), which never reaches the snapshot; the settle of one change starts the next under the same lock, planned against the checkout in front at that moment.
A change that fails or is refused drops the waiting ones with one `explorer.queue_dropped` diagnostic, because they may rely on it and the operator has not seen the failure; so does a waiting change whose checkout is no longer in front when its turn comes, and a fifth waiting change is refused with `explorer.busy`.
Trash stages the item in the device's temporary directory before handing it to the Trash, so on a Linux device whose `/tmp` is another filesystem the move is refused and the item stays; Linux devices are outside this stage's supported platforms.
Nothing is replaced: a creation opens exclusively and a rename or move uses the kernel's exclusive rename, so a name that appears meanwhile is refused and both items stay (B16).
A trash names the item by the inode the tree listed (`directory_list` entries carry it as decimal text, because a JSON number reaches the browser as a double and rounds a 64-bit id past 2^53, as an NTFS id is once its sequence number reaches 32) and is refused if another item took that path; the item moves through its opened parent into a private staging folder outside the checkout, is checked again there, and only then goes to that machine's Trash, and a Trash that refuses it puts it back, so nothing is ever deleted permanently (B17).
Expand Down
4 changes: 4 additions & 0 deletions docs/UI_BEHAVIOR.md
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,10 @@ The field draws on an elevated surface so it reads as an input among labels; not

The filesystem change is the core's: one event carries the request, the core refuses paths outside the focused checkout and any overwrite, runs the exclusive call off the runtime mutex, and settles one operation slot.
The tree reads a finished slot to re-read only the folders it touched, keeping every loaded folder and its expansion, and a failed slot to place the reason under the row the change started from.
Changes run one at a time in the order they were asked: a change asked while another runs, such as a trash pressed right after a drop, waits and starts when the one before it settles.
At most four wait, and a fifth is refused into the diagnostic log; a failed or refused change drops the ones waiting behind it into the log too, so nothing runs past a failure the operator has not seen.
The slot shows only the running change, and the next one starts in the same step that settles the one before it, so the tree can see a change working and then the next working without the first ever finished.
The tree then skips that change's own re-read, and its folders are refreshed the way a change made outside hide is, by the folder watch and device stamping; the selection still lands on the last change's item, because the core sets it on every success.
A folder being re-read, after a settled change, a change the watcher saw, or the refresh button, keeps its rows drawn until the new listing lands; it never empties for the round trip.
A device folder whose re-read is refused keeps those rows under its could-not-be-listed reason until Retry, or until the helper is ready again; a local subfolder whose re-read is refused keeps them until the next change reads it again.
The selection moves to the new or moved item because the core sets it explicitly; expanded folders and open file tabs inside a renamed folder follow it.
Expand Down
85 changes: 85 additions & 0 deletions herdr-core/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,89 @@ pub(crate) struct ExplorerTarget {
pub(crate) root: String,
}

/// An Explorer change as the page asked for it. One asked while another runs
/// waits in `explorer_queue` and is planned when its turn comes, against the
/// checkout in front then; changes run one at a time in the order they were
/// asked, so one that relies on the change before it (a rename, then a move
/// of the renamed item) reaches the host after that change landed.
#[derive(Clone, Debug)]
pub(crate) struct ExplorerRequest {
pub(crate) root: String,
pub(crate) device: Option<String>,
pub(crate) change: ExplorerChange,
}

#[derive(Clone, Debug)]
pub(crate) enum ExplorerChange {
Create {
kind: files::ExplorerOperationKind,
parent: String,
name: String,
},
Rename {
path: String,
name: String,
},
Move {
path: String,
destination: String,
},
Trash {
path: String,
select_after: String,
inode: Option<u64>,
},
}

impl ExplorerChange {
fn kind(&self) -> files::ExplorerOperationKind {
match self {
Self::Create { kind, .. } => *kind,
Self::Rename { .. } => files::ExplorerOperationKind::PathRename,
Self::Move { .. } => files::ExplorerOperationKind::PathMove,
Self::Trash { .. } => files::ExplorerOperationKind::PathTrash,
}
}

/// The row the change started from, where a refusal is shown.
fn started_from(&self) -> &str {
match self {
Self::Create { parent, .. } => parent,
Self::Rename { path, .. } | Self::Move { path, .. } | Self::Trash { path, .. } => path,
}
}

fn plan(&self, root: &str) -> Result<files::ExplorerOperation, String> {
match self {
Self::Create { kind, parent, name } => {
files::ExplorerOperation::create(*kind, root, parent, name)
}
Self::Rename { path, name } => files::ExplorerOperation::rename(root, path, name),
Self::Move { path, destination } => {
files::ExplorerOperation::move_into(root, path, destination)
}
Self::Trash {
path,
select_after,
inode,
} => files::ExplorerOperation::trash(root, path, select_after, *inode),
}
}
}

/// A change waiting behind the running one, with the checkout that was in
/// front when it was asked: it runs only if that checkout is still in front
/// when its turn comes.
#[derive(Debug)]
struct WaitingExplorerChange {
owner: Option<(String, String)>,
request: ExplorerRequest,
}

/// How many Explorer changes wait behind the running one. A drag and the
/// keys that follow it queue one or two; past this the newest is refused.
const EXPLORER_QUEUE_LIMIT: usize = 4;

fn retarget_path(path: &str, source: &str, destination: &str) -> Option<String> {
if path == source {
return Some(destination.to_owned());
Expand Down Expand Up @@ -1517,6 +1600,7 @@ pub struct Runtime {
/// row shows its fallback until the user tries Set purpose again.
unconfirmed_created_purposes: HashMap<String, String>,
next_explorer_operation_id: u64,
explorer_queue: VecDeque<WaitingExplorerChange>,
delta: snapshot_delta::DeltaState,
/// Each Workspace's presentation; present only in a shell that draws
/// separate Agent and View areas (`CoreOptions::workspace_views_path`).
Expand Down Expand Up @@ -1894,6 +1978,7 @@ impl Runtime {
created_purpose_writes_in_flight: HashMap::new(),
unconfirmed_created_purposes: HashMap::new(),
next_explorer_operation_id: 0,
explorer_queue: VecDeque::new(),
delta: snapshot_delta::DeltaState::default(),
workspace_views,
workspace_actions: VecDeque::new(),
Expand Down
88 changes: 39 additions & 49 deletions herdr-core/src/runtime/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2883,60 +2883,50 @@ impl Runtime {
{
return true;
}
self.start_explorer_operation(
|root| {
files::ExplorerOperation::create(
files::ExplorerOperationKind::FileCreate,
root,
&payload.parent,
&payload.name,
)
self.request_explorer_change(ExplorerRequest {
root: payload.root,
device: payload.device_id,
change: ExplorerChange::Create {
kind: files::ExplorerOperationKind::FileCreate,
parent: payload.parent,
name: payload.name,
},
&payload.root,
&payload.parent,
payload.device_id.as_deref(),
)
})
}
Event::DirCreate(payload) => self.start_explorer_operation(
|root| {
files::ExplorerOperation::create(
files::ExplorerOperationKind::DirCreate,
root,
&payload.parent,
&payload.name,
)
Event::DirCreate(payload) => self.request_explorer_change(ExplorerRequest {
root: payload.root,
device: payload.device_id,
change: ExplorerChange::Create {
kind: files::ExplorerOperationKind::DirCreate,
parent: payload.parent,
name: payload.name,
},
&payload.root,
&payload.parent,
payload.device_id.as_deref(),
),
Event::PathRename(payload) => self.start_explorer_operation(
|root| files::ExplorerOperation::rename(root, &payload.path, &payload.name),
&payload.root,
&payload.path,
payload.device_id.as_deref(),
),
Event::PathMove(payload) => self.start_explorer_operation(
|root| {
files::ExplorerOperation::move_into(root, &payload.path, &payload.destination)
}),
Event::PathRename(payload) => self.request_explorer_change(ExplorerRequest {
root: payload.root,
device: payload.device_id,
change: ExplorerChange::Rename {
path: payload.path,
name: payload.name,
},
&payload.root,
&payload.path,
payload.device_id.as_deref(),
),
Event::PathTrash(payload) => self.start_explorer_operation(
|root| {
files::ExplorerOperation::trash(
root,
&payload.path,
&payload.select_after,
payload.inode,
)
}),
Event::PathMove(payload) => self.request_explorer_change(ExplorerRequest {
root: payload.root,
device: payload.device_id,
change: ExplorerChange::Move {
path: payload.path,
destination: payload.destination,
},
&payload.root,
&payload.path,
payload.device_id.as_deref(),
),
}),
Event::PathTrash(payload) => self.request_explorer_change(ExplorerRequest {
root: payload.root,
device: payload.device_id,
change: ExplorerChange::Trash {
path: payload.path,
select_after: payload.select_after,
inode: payload.inode,
},
}),
Event::TerminalClick(payload) => {
// D8 explicitly chooses Herdr's detected agent as the policy
// boundary until its frame protocol carries mouse mode.
Expand Down
123 changes: 99 additions & 24 deletions herdr-core/src/runtime/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3865,6 +3865,91 @@ impl Runtime {
self.push_diagnostic(diagnostic_kind, message);
true
}
/// Starts an Explorer change, or keeps it behind the one still running.
/// The page sends a drop and the key that follows it without waiting for
/// the drop to land, and a change refused because another one ran was
/// lost with nothing logged and nothing on screen (#630); now they run one
/// at a time in the order they were asked. At most
/// `EXPLORER_QUEUE_LIMIT` wait, and the newest past that is refused and
/// logged. The queue is core state only: the snapshot shows the running
/// change, never the waiting ones.
pub(super) fn request_explorer_change(&mut self, request: ExplorerRequest) -> bool {
let running = self
.snapshot
.explorer_operation
.as_ref()
.is_some_and(|operation| operation.phase == "working");
if !running {
return self.start_explorer_operation(&request);
}
if self.explorer_queue.len() >= EXPLORER_QUEUE_LIMIT {
self.push_diagnostic(
"explorer.busy",
format!(
"{}: {EXPLORER_QUEUE_LIMIT} file operations are already waiting; this one was not run",
request.change.started_from()
),
);
return true;
}
crate::diagnostic!(serde_json::json!({
"component": "explorer", "kind": "explorer.change_waiting",
"operation": request.change.kind().as_str(),
"waiting": self.explorer_queue.len() + 1,
}));
let owner = self.front_checkout_owned();
self.explorer_queue
.push_back(WaitingExplorerChange { owner, request });
false
}
/// Starts the next waiting change once the running one has settled, planned
/// against the checkout as it is now. A change that failed or was refused
/// stops the queue: the changes behind it may rely on it, and the operator
/// has not seen the failure they would run past. Changes asked in a
/// checkout that is no longer in front are dropped as well, since the tree
/// they came from is not the one on screen.
fn continue_explorer_queue(&mut self) {
let failed = self
.snapshot
.explorer_operation
.as_ref()
.is_some_and(|operation| operation.phase == "failed");
if failed {
self.drop_explorer_queue("the change before them did not happen");
return;
}
let Some(next) = self.explorer_queue.pop_front() else {
return;
};
if next.owner != self.front_checkout_owned() {
self.explorer_queue.push_front(next);
self.drop_explorer_queue("the checkout they were asked in is no longer in front");
return;
}
self.start_explorer_operation(&next.request);
let running = self
.snapshot
.explorer_operation
.as_ref()
.is_some_and(|operation| operation.phase == "working");
if !running {
// Refused at its turn, or settled in place without a worker; a
// settle already continued the queue, so what is left here
// follows a refusal.
self.drop_explorer_queue("the change before them was refused");
}
}
fn drop_explorer_queue(&mut self, reason: &str) {
if self.explorer_queue.is_empty() {
return;
}
let count = self.explorer_queue.len();
self.explorer_queue.clear();
self.push_diagnostic(
"explorer.queue_dropped",
format!("{count} waiting file operation(s) were not run: {reason}"),
);
}
/// Decides an explorer change under the lock and runs it off the lock.
///
/// The decision reads nothing from disk: `plan` refuses a path outside
Expand All @@ -3879,26 +3964,13 @@ impl Runtime {
/// `device` is the device the tree that asked was showing. A change for
/// another device than the checkout in front is refused: the tree it came
/// from is no longer the one on screen (PRD S5.5 B34).
pub(super) fn start_explorer_operation(
&mut self,
plan: impl FnOnce(&str) -> Result<files::ExplorerOperation, String>,
root: &str,
started_from: &str,
device: Option<&str>,
) -> bool {
if self
.snapshot
.explorer_operation
.as_ref()
.is_some_and(|operation| operation.phase == "working")
{
self.set_error(
"explorer.busy",
"Another file operation is still running",
true,
);
return true;
}
///
/// The slot holds one change at a time; `request_explorer_change` keeps
/// the ones asked meanwhile, and this starts one only on an empty slot.
fn start_explorer_operation(&mut self, request: &ExplorerRequest) -> bool {
let root = request.root.as_str();
let started_from = request.change.started_from();
let device = request.device.as_deref();
self.next_explorer_operation_id = self.next_explorer_operation_id.wrapping_add(1).max(1);
let id = self.next_explorer_operation_id;
let device = device.unwrap_or(workspace::LOCAL_DEVICE_ID);
Expand All @@ -3917,10 +3989,12 @@ impl Runtime {
Some(target) if target.device_id != device => Err(format!(
"{root} is not on the device in front; nothing was changed"
)),
Some(target) if target.root == root => plan(root).and_then(|operation| {
self.document_source(&target.workspace_id, &target.checkout_id)
.map(|source| (operation, target, source))
}),
Some(target) if target.root == root => {
request.change.plan(root).and_then(|operation| {
self.document_source(&target.workspace_id, &target.checkout_id)
.map(|source| (operation, target, source))
})
}
Some(target) => Err(format!(
"{root} is not the focused checkout {}",
target.root
Expand Down Expand Up @@ -4151,6 +4225,7 @@ impl Runtime {
);
}
}
self.continue_explorer_queue();
true
}
/// Keeps the first prompt and the CLI arguments for the agent a task
Expand Down
Loading
Loading