fix(pipeline): keep the run futures Send so the binaries compile again

Neither binary has compiled since traffic recording landed. The release
binary on disk was three weeks older than the source, which is why.

At the end of run(), traffic_record::store() returns a std::sync::MutexGuard
that stayed alive across the tx.send(...).await two lines below. A MutexGuard
is not Send, so the enclosing future is not Send, and both app/src/main.rs
and app/src/tui.rs hand these futures to tokio::spawn, which requires it.

The library kept building clean throughout: nothing in it spawns a run, so
cargo check -p neurosploit-harness never saw the problem. That is the whole
reason this went unnoticed — every check I ran this session was scoped to the
library.

Scope the guard so it drops before the await.

Add a Send assertion over all six run futures. Reverting the scope fix makes
it fail with "future cannot be sent between threads safely", so it catches
the real thing rather than restating it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Joas A SantosandClaude Opus 5 committed 2026-12-04 14:18:42 -03:00
1 parent 73857f7866
commit 90bd20f143
2 files changed
+42 -6

No files matched your search

+13 -6
View File
@@ -6178,12 +6178,19 @@ async fn finish(cfg: RunConfig, _lib: &Library, pool: &ModelPool, recon: String,
// Persist traffic recording if enabled.
if crate::traffic_record::enabled() {
if let Some(ref wd) = cfg.workdir {
let log = crate::traffic_record::store();
let json_path = std::path::Path::new(wd).join("traffic.json");
let _ = crate::traffic_record::save_json(&log, &json_path.to_string_lossy());
let har_path = std::path::Path::new(wd).join("traffic.har");
let _ = std::fs::write(&har_path, crate::traffic_record::export_har(&log));
let summary = log.stats();
// The guard must not survive into the await below. std::sync's
// MutexGuard is not Send, and holding one across a suspension
// point makes the whole run future non-Send — which tokio::spawn
// requires, so both binaries stop compiling while the library
// still builds clean on its own.
let summary = {
let log = crate::traffic_record::store();
let json_path = std::path::Path::new(wd).join("traffic.json");
let _ = crate::traffic_record::save_json(&log, &json_path.to_string_lossy());
let har_path = std::path::Path::new(wd).join("traffic.har");
let _ = std::fs::write(&har_path, crate::traffic_record::export_har(&log));
log.stats()
};
let _ = tx.send(format!("📡 traffic: {} request(s), {} error(s), {} WAF block(s) → traffic.json + traffic.har",
summary.total, summary.errors, summary.blocked)).await;
}
@@ -453,3 +453,32 @@ mod tests {
assert!(formatted.contains("2024"));
}
}
#[cfg(test)]
mod send_tests {
/// The run futures must stay `Send`, because both binaries hand them to
/// `tokio::spawn`, which requires it.
///
/// This is easy to break from inside the library and impossible to notice
/// there: holding a `std::sync::MutexGuard` — `traffic_record::store()`
/// returns one — across an `.await` makes the enclosing future non-Send,
/// and `cargo check -p neurosploit-harness` still passes because nothing
/// in the library spawns them. Only the binaries fail, which is how the
/// release binary came to be three weeks older than the source.
#[test]
fn the_run_futures_are_send() {
fn assert_send<T: Send>(_: &T) {}
let cfg = crate::types::RunConfig::new("example.test");
let lib = crate::agents::Library::default();
let pool = crate::pool::ModelPool::new(Vec::new(), 1);
let (tx, _rx) = tokio::sync::mpsc::channel::<String>(1);
assert_send(&crate::pipeline::run(cfg.clone(), &lib, &pool, tx.clone()));
assert_send(&crate::pipeline::run_whitebox(cfg.clone(), &lib, &pool, tx.clone()));
assert_send(&crate::pipeline::run_greybox(cfg.clone(), &lib, &pool, tx.clone()));
assert_send(&crate::pipeline::run_host(cfg.clone(), &lib, &pool, tx.clone()));
assert_send(&crate::pipeline::run_container(cfg.clone(), &lib, &pool, tx.clone()));
assert_send(&crate::pipeline::run_mobile(cfg, &lib, &pool, tx));
}
}