From 52720554be83e7c08bb8f2439c135b59eaa5676f Mon Sep 17 00:00:00 2001 From: Sebastian Gieseler Date: Wed, 21 Oct 2026 14:18:00 +0200 Subject: [PATCH] fix: from the pool's telemetry: a sync past a vanished file, tunnel ends, writes in progress, a rebuild's errors - A sync no longer fails when a file goes between listing and reading it (a package manager rewriting node_modules): it is left out, the next sync sends what is there. - A tunnel connection the browser or dev server closed (reset, aborted, Windows 10053) is a normal end, not a warning. - The watcher ignores files of a write in progress: write-atomic temp names (`x.tmp..`), sed -i's `sedXXXXXX`, vim's 4913 and swap files, Emacs' `.#` and `~` files. - A dev server's failed rebuild is logged with its error lines: the line waits up to 2 s after the last one (Angular on Windows prints them after its marker). Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 15 +++++ crates/devstack-daemon/src/rebuild.rs | 21 +++++++ crates/devstack-daemon/src/remote.rs | 39 ++++++++++-- .../src/supervisor/rebuilds.rs | 59 +++++++++++++++++- crates/devstack-daemon/src/watch.rs | 61 ++++++++++++++++++- crates/devstack-node/src/nodeclient.rs | 16 ++++- 6 files changed, 204 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1575fca8..2c492676 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,6 +40,21 @@ and listed with their assets on the ### Fixed +- A lane on a node no longer stops syncing when a file goes while it is + sent (a package manager rewriting `node_modules`): the file is left out + and the next sync sends what is there then. +- A browser or dev server closing a connection through a lane's tunnel is + no longer a warning in the diagnostic log (Windows reports it as + "aborted", 10053). +- Files of a write in progress no longer show among the paths that made a + candidate: atomic writes of editors and agents' tools + (`db.rs.tmp..`), `sed -i`'s `sedXXXXXX`, vim's `4913` and swap + files, Emacs' `.#` and `~` files. +- A dev server's failed rebuild goes to the diagnostic log with its error + lines, not only with its tool's last line: Angular on Windows prints them + after that line, and the log line now waits for them (2 s at most after + the last). + - The daemon log says why a lane whose worktree went is not removed at once: `lane_forget_deferred` said "it is being started" also when a removal of the same lane was under way already, or a move. diff --git a/crates/devstack-daemon/src/rebuild.rs b/crates/devstack-daemon/src/rebuild.rs index e48f148d..8e4dd1ab 100644 --- a/crates/devstack-daemon/src/rebuild.rs +++ b/crates/devstack-daemon/src/rebuild.rs @@ -281,6 +281,12 @@ impl Tracker { /// The last rebuild, as the view shows it at `now`: a finished one for /// [`SHOWN_MS`], a failed one until the next. + /// Does the rebuild that failed last show only its marker so far, its + /// error lines still to come? + pub fn waits_for_errors(&self) -> bool { + self.marker_only + } + pub fn view(&self, now: u128) -> Option { self.current.clone().filter(|c| { c.state != "ok" || now.saturating_sub(c.since) < SHOWN_MS + c.ms.unwrap_or(0) as u128 @@ -378,6 +384,21 @@ X [ERROR] TS2729: Property 'flags' is used before its initialization. [plugin an assert_eq!(v.iter().filter(|r| r.state == "rebuilding").count(), 1); } + #[test] + fn a_failure_waits_for_its_error_lines() { + // What the diagnostic line waits for (`supervisor::rebuilds`): the + // marker alone, then its first error line. + let mut t = Tracker::new(None).unwrap(); + t.feed("> Changes detected. Rebuilding...", 1); + t.feed("Application bundle generation failed. [9.016 seconds]", 2); + assert!(t.waits_for_errors()); + t.feed( + "X [ERROR] TS7008: Member 'flags' implicitly has an 'any' type.", + 3, + ); + assert!(!t.waits_for_errors()); + } + #[test] fn angular_warnings_are_no_failure() { // A warning (NG8113, a budget) is no error. diff --git a/crates/devstack-daemon/src/remote.rs b/crates/devstack-daemon/src/remote.rs index 9ff72458..a307a630 100644 --- a/crates/devstack-daemon/src/remote.rs +++ b/crates/devstack-daemon/src/remote.rs @@ -1156,10 +1156,16 @@ impl RemoteLane { .map_err(|e| e.to_string())?; let mut up = hyper_util::rt::TokioIo::new(up); let open = crate::telemetry::Tunnel::open(&self.name, &self.node.name); - tokio::io::copy_bidirectional(&mut up, &mut tcp) - .await - .map(|(a, b)| open.closed(a + b)) - .map_err(|e| e.to_string()) + match tokio::io::copy_bidirectional(&mut up, &mut tcp).await { + Ok((a, b)) => { + open.closed(a + b); + Ok(()) + } + // One end hung up without a goodbye (a browser closing a tab or + // a dev server's WebSocket): how connections end, not a fault. + Err(e) if closed_by_a_peer(&e) => Ok(()), + Err(e) => Err(e.to_string()), + } } /// Why the node cannot do what `method` on the lane daemon's `path` @@ -1282,6 +1288,17 @@ fn release_warning( Ok((!notes.is_empty()).then(|| notes.join("; "))) } +/// Did a connection of a tunnel end because one end hung up (reset, aborted, +/// a write to a closed socket)? Windows says "aborted" (10053) where a +/// browser closes a connection it kept alive. +fn closed_by_a_peer(e: &std::io::Error) -> bool { + use std::io::ErrorKind::*; + matches!( + e.kind(), + ConnectionReset | ConnectionAborted | BrokenPipe | UnexpectedEof + ) +} + /// A tunnel the node or the lane did not open: what it said, and the /// releases when they differ (an older lane daemon may serve other ports). pub fn tunnel_error(what: &str, body: &str, node: &NodeRef) -> String { @@ -1341,6 +1358,20 @@ pub fn readiness(view: &serde_json::Value, expected: &[String]) -> Option, + /// A failed rebuild whose error lines have not come yet (Angular prints + /// them after its marker on Windows): its start, when it last changed and + /// its diagnostic fields, logged [`HOLD`] after its last error line came, + /// or when the next rebuild starts. + held: Option, } +type Held = (u128, u128, serde_json::Map); + +/// How long a failed rebuild's diagnostic line waits for more error lines. +const HOLD: u128 = 2_000; + impl Supervisor { /// Follow every dev server's log for its rebuilds, as long as this /// supervisor lives (the main tree's, a lane's). @@ -102,6 +112,7 @@ impl Supervisor { tracker: Tracker::new(svc.rebuild.as_ref()), live: false, logged: None, + held: None, }, ); runs.get_mut(name).expect("inserted") @@ -119,11 +130,18 @@ impl Supervisor { if let Some(v) = tracker.feed(&line, now) && was_live { + if run + .held + .as_ref() + .is_some_and(|(since, _, _)| *since != v.since) + { + self.log_held(name, &mut run.held); + } let finished = v.state != "rebuilding" && run.logged != Some(v.since); if finished { run.logged = Some(v.since); } - let done = finished.then(|| { + let mut done = finished.then(|| { let mut extra = serde_json::Map::new(); if let Some(ms) = v.ms { extra.insert("ms".into(), ms.into()); @@ -134,9 +152,27 @@ impl Supervisor { ); extra }); + if tracker.waits_for_errors() { + // Its error lines follow: the log waits for them. + if let Some(extra) = done.take() { + run.held = Some((v.since, now, extra)); + } + } else if let Some((since, at, _)) = run.held.as_mut() + && *since == v.since + { + // One more of its error lines: the next may follow. + *at = now; + } self.set_rebuild(name, Some(v), done); } } + if run + .held + .as_ref() + .is_some_and(|(_, at, _)| now_ms().saturating_sub(*at) >= HOLD) + { + self.log_held(name, &mut run.held); + } if !was_live { continue; } @@ -154,6 +190,27 @@ impl Supervisor { } } + /// A held failed rebuild to the diagnostic log, as the view has it now + /// (with what error lines came). + fn log_held(&self, name: &str, held: &mut Option) { + let Some((_, _, extra)) = held.take() else { + return; + }; + let rebuild = self + .slots + .lock() + .unwrap() + .get(name) + .and_then(|s| s.view.rebuild.clone()); + self.emit_with( + EventBody::DevserverRebuild { + service: name.into(), + rebuild, + }, + Some(extra), + ); + } + /// The service's rebuild on its view and to the dashboard; `extra` (the /// time, the result) goes to the diagnostic line of a finished one. fn set_rebuild( diff --git a/crates/devstack-daemon/src/watch.rs b/crates/devstack-daemon/src/watch.rs index 3899d7f1..6aabe64d 100644 --- a/crates/devstack-daemon/src/watch.rs +++ b/crates/devstack-daemon/src/watch.rs @@ -77,10 +77,42 @@ fn cache(name: &str) -> bool { ) } +/// Is `name` the file name of a write in progress, renamed onto the real +/// file a moment later? Atomic writes of editors and agents' tools +/// (`db.rs.tmp.33128.2dcc67a056d2`: name, `.tmp.`, process id, random hex), +/// GNU `sed -i` (`sedGr1VFQ`), vim's probe file `4913` and its swap files, +/// Emacs' lock and backup files. The real file's change follows; these +/// would only put names in a candidate's paths that never were the user's. +fn transient(name: &str) -> bool { + let mut parts = name.rsplitn(3, '.'); + let write_atomic = matches!( + (parts.next(), parts.next(), parts.next()), + (Some(hex), Some(pid), Some(rest)) + if !hex.is_empty() && hex.bytes().all(|b| b.is_ascii_hexdigit()) + && !pid.is_empty() && pid.bytes().all(|b| b.is_ascii_digit()) + && rest.ends_with(".tmp") + ); + // Six random letters and digits; a real name of that shape (`sedimentd`) + // is lower case throughout. + let sed = name.len() == 9 + && name.starts_with("sed") + && name[3..].bytes().all(|b| b.is_ascii_alphanumeric()) + && name[3..] + .bytes() + .any(|b| b.is_ascii_uppercase() || b.is_ascii_digit()); + write_atomic + || sed + || name == "4913" + || name.ends_with('~') + || name.starts_with(".#") + || (name.starts_with('.') && (name.ends_with(".swp") || name.ends_with(".swx"))) +} + /// Is `rel` (repository-relative, `/`-separated) in a directory that never -/// counts: a generated one or a tool's cache? +/// counts (a generated one or a tool's cache), or a write in progress? pub fn ignored(rel: &str) -> bool { rel.split('/').any(|n| generated(n) || cache(n)) + || rel.rsplit('/').next().is_some_and(transient) } /// Is `rel` in a generated directory (not a cache)? What tells a remote @@ -376,6 +408,33 @@ mod tests { } } + #[test] + fn writes_in_progress_do_not_count() { + for p in [ + "server/src/db.rs.tmp.33128.2dcc67a056d2", + "schema/migrations/0045_icon.sql.tmp.33128.3fd2b0a603be", + "tools/mock/sedGr1VFQ", + "src/4913", + "src/main.rs~", + "src/.#main.rs", + "src/.main.rs.swp", + ] { + assert!(super::ignored(p), "{p}"); + } + for p in [ + "src/db.rs", + "src/data.tmp", + "src/v1.tmp.x.y", + "src/sedan.rs", + "src/seducers", + "bin2/sedimentd", + "docs/4913.md", + "src/swap.swp", + ] { + assert!(!super::ignored(p), "{p}"); + } + } + #[test] fn frontend_caches_do_not_count_but_are_synced_to_a_remote_lane() { for p in [ diff --git a/crates/devstack-node/src/nodeclient.rs b/crates/devstack-node/src/nodeclient.rs index 7f82c697..5de62899 100644 --- a/crates/devstack-node/src/nodeclient.rs +++ b/crates/devstack-node/src/nodeclient.rs @@ -474,6 +474,14 @@ impl NodeClient { let read = reader .await .map_err(|e| ClientError::Other(e.to_string()))?; + // Gone since it was hashed: like a file that changed, the next sync + // sends what is there then. + if read + .as_ref() + .is_err_and(|e| e.kind() == std::io::ErrorKind::NotFound) + { + return Ok(false); + } let (status, text) = answer.map_err(|_| { ClientError::Other(format!( "{}: not sent within {} min", @@ -609,7 +617,13 @@ fn hash_all( .filter(|k| k.len == meta.len() && Some(k.modified) == modified); let hash = match cached { Some(k) => k.hash, - None => hash_file(&path).map_err(|e| ClientError::Io(path.display().to_string(), e))?, + // Gone since it was listed (a package manager rewriting + // `node_modules`): not sent now; the next sync sees what is there. + None => match hash_file(&path) { + Ok(h) => h, + Err(e) if e.kind() == std::io::ErrorKind::NotFound => continue, + Err(e) => return Err(ClientError::Io(path.display().to_string(), e)), + }, }; if let Some(modified) = modified && now.duration_since(modified).is_ok_and(|age| age >= SETTLED)