Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
fbe342a
fix(minimald): proxy runtime-published ports like a direct connection…
minimal-foundry[bot] Oct 28, 2026
950f384
fix(minimald): name the range and refuse --public in min net expose (…
minimal-foundry[bot] Oct 28, 2026
47df1d6
fix(minimald): record VM refusals on the host and admit RPC only from…
minimal-foundry[bot] Oct 28, 2026
403d8e8
fix(minimald): fail activation when a declared host port is already t…
gominimal-aw-bot[bot] Oct 28, 2026
e289e5f
fix(minimald): refuse an activation whose declared port something els…
minimal-foundry[bot] Oct 29, 2026
c7087f0
fix(minimald): retry the finalize port probe so a parallel probe is n…
norrietaylor Oct 30, 2026
027dfe6
test(minimald): give each own-address test box its own host port (#2752)
norrietaylor Oct 30, 2026
7981f0e
fix(net): hand boxes the loopback interim when the host cannot bind t…
gominimal-aw-bot[bot] Oct 28, 2026
947b955
fix(minimald): answer a macOS box's ports at the address its name res…
minimal-foundry[bot] Oct 29, 2026
c36cd6e
fix(minimald): move a box's forward to its range address when the ran…
norrietaylor Oct 30, 2026
8acbf4d
fix(minimald): satisfy fmt and clippy on the publish-move backport (#…
norrietaylor Nov 4, 2026
8746a3c
fix(minimald): refuse unmatched names for partial allow lists and gat…
minimal-foundry[bot] Oct 30, 2026
7302e78
fix(minvmd): bound the in-force baseline's host-alias reach to its fe…
gominimal-aw-bot[bot] Oct 28, 2026
7299c15
fix(net): scope the host alias by the host-exposure port list (#2331)
gominimal-aw-bot[bot] Oct 28, 2026
55163d6
fix(minvmd): decide the node plane's own traffic by its baseline set …
minimal-foundry[bot] Oct 31, 2026
5dddc5e
fix(minvmd): refuse flows to host.min.internal outside the design's o…
minimal-foundry[bot] Nov 4, 2026
ec7524a
fix(minimald): run a box's package builds under that box's egress ver…
minimal-foundry[bot] Oct 30, 2026
b568f8d
fix(op): give the sandbox a private copy of non-extracted sources (#2…
bryan-minimal Oct 22, 2026
fd35986
fix(mctx): keep task args from running as shell code (#2296)
gominimal-aw-bot[bot] Oct 18, 2026
cb85e78
fix(deps): bump pulldown-cmark to 0.13.6 for RUSTSEC-2026-0433 (#2846)
mitodrummer Nov 2, 2026
82c8fe7
fix(cargo): remove the committed buf registry token (#2204)
norrietaylor Oct 16, 2026
0ce56e4
fix(minimal): show each box's address and egress posture in min ls (#…
minimal-foundry[bot] Oct 31, 2026
93dd243
fix(minimal): resolve a box's VM from its name for exec, task run and…
bryan-minimal Oct 29, 2026
91d492a
fix(minimal): find a box on any VM, a stopped VM included (#2811)
minimal-foundry[bot] Nov 1, 2026
14c0e8a
fix(minimald): bound wedged transport writes with an inactivity deadl…
gominimal-aw-bot[bot] Oct 18, 2026
3d4e6ee
fix(common): write file cache downloads atomically via temp file and …
norrietaylor Oct 18, 2026
1697044
fix(minimald): leave HEAD alone when a push targets another branch (#…
gominimal-aw-bot[bot] Oct 18, 2026
94eb0eb
fix(minimald): fork a task run's container on the sandbox fork thread…
bryan-minimal Oct 25, 2026
e347984
fix(installer,dash): stop the daemon across uninstall and reinstall (…
gominimal-aw-bot[bot] Oct 19, 2026
aeaf53c
fix(installer): stop a daemon left on an older build after the swaps …
gominimal-aw-bot[bot] Oct 21, 2026
2b8ead9
fix(net): keep restored own-ip boxes' rows and ingress across a VM re…
gominimal-aw-bot[bot] Oct 18, 2026
89a676d
fix: send the lease ARP as the relay's first frame (#2333)
gominimal-aw-bot[bot] Oct 19, 2026
8c4bcd6
build: declare 0.7.3-rc1 as the first release candidate
norrietaylor Nov 4, 2026
38c0801
test(e2e): read the macOS DNS SERVICE port without the word listening
norrietaylor Nov 5, 2026
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
4 changes: 0 additions & 4 deletions .cargo/config.toml

This file was deleted.

21 changes: 11 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ package.rust-version = "1.95"
# (scripts/next-version.sh). `scripts/next-version.sh --check` (the
# workspace `package_version` test, `just check-version`) fails the PR that
# leaves it stale or not strictly greater than the newest v* tag.
package.version = "0.7.3"
package.version = "0.7.3-rc1"
Comment thread
norrietaylor marked this conversation as resolved.
Resolved

# Workspace lint policy. A crate opts in with `[lints] workspace = true`.
#
Expand Down
226 changes: 217 additions & 9 deletions crates/common/src/file_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,23 @@ impl FileCache {

/// Drives the given response to read bytes and write them into the cache with the given filename
/// and hash.
///
/// The bytes go to a uniquely named temp file in the same directory, which is renamed onto the
/// content-addressed path only after its SHA-256 matches. A failed or mismatched download
/// therefore never appears under the hash, and concurrent readers see either nothing or the
/// whole verified file.
///
/// Returns the cached path, replacing any existing entry on success. `sha256` must match the
/// lowercase hexadecimal digest of the response bytes. Updates `op` with bytes received, using
/// the response's content length, when available, as the progress total only.
///
/// # Errors
///
/// Returns `Either::Right` for response stream errors. Returns `Either::Left` for
/// [FileCacheError::BadSha] if `sha256` contains `/`, [FileCacheError::HashMismatch] if the
/// digest differs, or [FileCacheError::IO] if accessing or creating the cache directory,
/// creating the temporary file, writing or syncing it, or persisting it fails. Failure to sync
/// the directory after publication does not prevent a successful return.
pub async fn write_through<R>(
&self,
filename: &str,
Expand All @@ -168,12 +185,24 @@ impl FileCache {
where
R: fetchers::FetchResponse,
{
let cached_path = self.sha_dir(sha256).map_err(Either::Left)?.join(filename);
use std::os::unix::fs::PermissionsExt;

let dir = self.sha_dir(sha256).map_err(Either::Left)?;
let cached_path = dir.join(filename);

// Dropping `tmp` on any early return removes the temp file. The prefix is fixed rather than
// derived from `filename`, so a filename near NAME_MAX still fits.
let mut tmp = tempfile::Builder::new()
.prefix(".dl.")
.suffix(".part")
.permissions(fs::Permissions::from_mode(0o666))
.tempfile_in(&dir)
.map_err(|e| Either::Left(e.into()))?;

let mut hasher = super::HashWriter(Sha256::new());
{
let mut f = fs::File::create(&cached_path).map_err(|e| Either::Left(e.into()))?;
let mut w = Tee::new(&mut f, &mut hasher);
let f = tmp.as_file_mut();
let mut w = Tee::new(&mut *f, &mut hasher);

if let Some(size) = response.content_length() {
op.set_length(size);
Expand All @@ -182,7 +211,7 @@ impl FileCache {
match response.chunk().await {
Ok(Some(chunk)) => {
op.increment(chunk.len() as u64);
w.write_all(&chunk).unwrap();
w.write_all(&chunk).map_err(|e| Either::Left(e.into()))?;
}
Ok(None) => {
break;
Expand All @@ -200,14 +229,22 @@ impl FileCache {
let computed_hex = hex::encode(computed_hash);

if computed_hex != sha256 {
fs::remove_file(&cached_path).ok(); // ignore error, best effort
Err(Either::Left(FileCacheError::HashMismatch {
return Err(Either::Left(FileCacheError::HashMismatch {
want: sha256.to_string(),
got: computed_hex,
}))
} else {
Ok(cached_path)
}));
}

// Renaming over an existing entry is fine: it holds the same verified bytes.
tmp.persist(&cached_path)
.map_err(|e| Either::Left(e.error.into()))?;
// Fsync the directory so the rename itself survives a crash. This buys durability, not
// integrity (`read_cached` re-hashes every read), so a failure only warns: some
// filesystems refuse a directory fsync.
if let Err(e) = fs::File::open(&dir).and_then(|d| d.sync_all()) {
tracing::warn!("could not fsync cache directory {}: {e}", dir.display());
}
Ok(cached_path)
}
}

Expand Down Expand Up @@ -350,6 +387,177 @@ mod tests {
);
}

fn sha256_hex(data: &[u8]) -> String {
let mut h = sha2::Sha256::new();
sha2::Digest::update(&mut h, data);
hex::encode(h.finalize())
}

/// A [FetchResponse] that yields one chunk, waits for `resume` to be
/// notified, then yields `tail` (or fails if `tail` is `Err`).
#[derive(Debug)]
struct PausingResponse {
head: Option<Bytes>,
tail: Option<Result<Bytes, String>>,
paused: std::sync::Arc<tokio::sync::Notify>,
resume: std::sync::Arc<tokio::sync::Notify>,
}

impl fetchers::FetchResponse for PausingResponse {
type Error = String;

fn error_for_status(self) -> Result<Self, Self::Error> {
Ok(self)
}
fn is_success(&self) -> bool {
true
}
fn status_code(&self) -> usize {
200
}
fn content_length(&self) -> Option<u64> {
None
}
async fn bytes(self) -> Result<Bytes, Self::Error> {
unimplemented!("write_through streams via chunk()")
}
async fn chunk(&mut self) -> Result<Option<Bytes>, Self::Error> {
if let Some(head) = self.head.take() {
return Ok(Some(head));
}
match self.tail.take() {
Some(tail) => {
self.paused.notify_one();
self.resume.notified().await;
tail.map(Some)
}
None => Ok(None),
}
}
}

/// Lists the entries of a cache sha directory.
fn dir_entries(dir: &std::path::Path) -> Vec<String> {
let mut v: Vec<String> = fs::read_dir(dir)
.unwrap()
.map(|e| e.unwrap().file_name().to_string_lossy().into_owned())
.collect();
v.sort();
v
}

/// A stream that fails part-way through must leave nothing at the
/// content-addressed path, and no temp file behind either.
#[tokio::test]
async fn write_through_stream_error_leaves_no_file() {
let tmp = tempfile::tempdir().unwrap();
let cache = FileCache::new(tmp.path().to_path_buf()).unwrap();
let op = OpTracker::new_with_root(&None);
let sha = sha256_hex(b"partial-and-the-rest");

let resume = std::sync::Arc::new(tokio::sync::Notify::new());
resume.notify_one(); // do not actually pause
let mut resp = PausingResponse {
head: Some(Bytes::from_static(b"partial-")),
tail: Some(Err("connection reset".into())),
paused: std::sync::Arc::new(tokio::sync::Notify::new()),
resume,
};

let err = cache
.write_through("src.tar.gz", &sha, &mut resp, &op)
.await
.unwrap_err();
assert_eq!(err.unwrap_right(), "connection reset");

let dir = cache.sha_dir(&sha).unwrap();
assert!(
!dir.join("src.tar.gz").exists(),
"a failed stream must not leave a file under the pinned hash"
);
assert_eq!(dir_entries(&dir), Vec::<String>::new(), "temp file leaked");
}

/// While a download is in flight, a concurrent reader must never see a
/// partial file at the content-addressed path; once it completes, the
/// whole verified file appears.
#[tokio::test]
async fn write_through_in_flight_is_invisible_to_readers() {
let tmp = tempfile::tempdir().unwrap();
let cache = FileCache::new(tmp.path().to_path_buf()).unwrap();
let op = OpTracker::new_with_root(&None);
let content = b"first-half|second-half";
let sha = sha256_hex(content);

let paused = std::sync::Arc::new(tokio::sync::Notify::new());
let resume = std::sync::Arc::new(tokio::sync::Notify::new());
let mut resp = PausingResponse {
head: Some(Bytes::copy_from_slice(&content[..11])),
tail: Some(Ok(Bytes::copy_from_slice(&content[11..]))),
paused: paused.clone(),
resume: resume.clone(),
};

let writer = {
let cache = cache.clone();
let sha = sha.clone();
tokio::spawn(async move {
cache
.write_through("src.tar.gz", &sha, &mut resp, &op)
.await
.map_err(|e| format!("{e:?}"))
})
};

// The writer has written the first chunk and is blocked mid-stream.
paused.notified().await;
let final_path = cache.sha_dir(&sha).unwrap().join("src.tar.gz");
assert!(
!final_path.exists(),
"a partial download must not be visible under the pinned hash"
);
assert_eq!(cache.read_cached("src.tar.gz", &sha).unwrap(), None);

resume.notify_one();
let path = writer.await.unwrap().expect("download should succeed");
assert_eq!(path, final_path);
assert_eq!(fs::read(&path).unwrap(), content);
assert_eq!(
dir_entries(path.parent().unwrap()),
vec!["src.tar.gz".to_string()],
"only the final file should remain"
);
}

/// A filename close to NAME_MAX (255) must still cache: the temp file
/// name must not grow with the filename.
#[tokio::test]
async fn write_through_accepts_filename_near_name_max() {
let tmp = tempfile::tempdir().unwrap();
let cache = FileCache::new(tmp.path().to_path_buf()).unwrap();
let op = OpTracker::new_with_root(&None);
let content = b"long-name";
let sha = sha256_hex(content);
let filename = format!("{}.tar.gz", "a".repeat(247));
assert_eq!(filename.len(), 254);

let resume = std::sync::Arc::new(tokio::sync::Notify::new());
resume.notify_one();
let mut resp = PausingResponse {
head: Some(Bytes::from_static(content)),
tail: None,
paused: std::sync::Arc::new(tokio::sync::Notify::new()),
resume,
};

let path = cache
.write_through(&filename, &sha, &mut resp, &op)
.await
.map_err(|e| format!("{e:?}"))
.expect("a 254-byte filename should cache");
assert_eq!(fs::read(&path).unwrap(), content);
}

/// A fake URL whose filename is whatever the test sets.
#[derive(Debug, Clone)]
struct FakeUrl {
Expand Down
1 change: 1 addition & 0 deletions crates/mctx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ check.workspace = true
codespan-reporting.workspace = true
google-cloud-auth.workspace = true
google-cloud-storage.workspace = true
shlex.workspace = true
thiserror.workspace = true
toml.workspace = true
toml_edit.workspace = true
Expand Down
Loading
Loading