Skip to content
Draft
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
35 changes: 33 additions & 2 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
resolver = "3"
members = ["crates/*", "crates/gateway/app", "crates/gateway/config", "crates/gateway/config-ui", "crates/gateway/local", "crates/gateway/logging", "crates/gateway/progress", "crates/gateway/protocol", "crates/gateway/routing", "crates/gateway/web-search", "crates/gateway/stt/api", "crates/gateway/stt/engine", "crates/gateway/stt/backend-whisper", "crates/gateway/stt/whisper-ffi"]
members = ["crates/*", "crates/gateway/app", "crates/gateway/config", "crates/gateway/config-ui", "crates/gateway/local", "crates/gateway/logging", "crates/gateway/progress", "crates/gateway/protocol", "crates/gateway/routing", "crates/gateway/web-search", "crates/gateway/chatgpt-plan", "crates/gateway/stt/api", "crates/gateway/stt/engine", "crates/gateway/stt/backend-whisper", "crates/gateway/stt/whisper-ffi"]
# crates/shared-ui is not a Rust crate: it is the TypeScript and CSS package
# the config UI consumes, so the crates/* glob skips it.
# crates/gateway and crates/gateway/stt are manifestless containers holding
Expand All @@ -23,6 +23,7 @@ repository = "https://github.com/cppalliance/runvil-gateway"
[workspace.dependencies]
anyhow = "1"
async-trait = "0.1"
aws-lc-rs = { version = "1.18", default-features = false, features = ["aws-lc-sys"] }
axum = { version = "0.8", features = ["multipart", "ws"] }
base64 = "0.22"
block2 = "0.6"
Expand All @@ -36,6 +37,7 @@ embed-resource = "3"
flate2 = "1"
futures-util = "0.3"
gateway-api-discovery = { path = "crates/gateway-api-discovery" }
gateway-chatgpt-plan = { path = "crates/gateway/chatgpt-plan" }
gateway-api-types = { path = "crates/gateway-api-types" }
gateway-config = { path = "crates/gateway/config" }
gateway-config-ui = { path = "crates/gateway/config-ui" }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Runvil Gateway is one process that serves an OpenAI-shaped API for chat, embeddi
| `POST /v1/tools/web_search` | A Gateway extension, backed by Brave Search |
| `GET /v1/audio/voices` | A Gateway extension, the voice catalog |
| `/v1/cache` | A Gateway extension, a local blob cache that downloads and keeps files by sha256 |
| `/config/`, `/admin/*`, `/health` | The Gateway's own settings page, admin surface, and liveness probe |
| `/config/`, `/admin/*`, `/health` | The Gateway's own settings page, admin surface, and liveness probe ([the ChatGPT plan](crates/gateway/README.md#the-chatgpt-plan) covers `/admin/chatgpt/*`, and [a config save names a revision](crates/gateway/README.md#saving-the-configuration)) |

Requests are answered by a local model through a managed `llama-server` child, or forwarded to a cloud provider you configured. Chat, embeddings, and reranking work either way. Transcription runs on the Gateway's own speech pipeline, which decodes with whisper.cpp, and speech synthesis forwards to a speech endpoint you configure.

Expand Down
8 changes: 5 additions & 3 deletions crates/gateway-api-discovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ mod file;
mod health;
mod lock;
mod paths;
mod private;
mod shutdown;
mod stale;
mod sys;
Expand All @@ -52,10 +53,11 @@ pub use crate::file::{GatewayDiscoveryFile, remove_if_mine};
pub use crate::health::{HealthError, ProbeError, wait_for_health, wait_for_health_cancellable};
pub use crate::lock::{GatewayInstanceLease, LaunchDecision, LaunchLock};
pub use crate::paths::{
GATEWAY_DISCOVERY_FILE_NAME, GATEWAY_LOG_FILE_NAME, INSTANCE_LOCK_FILE_NAME, LOCK_FILE_NAME,
default_run_dir, gateway_discovery_file_path, gateway_log_path, instance_lock_file_path,
lock_file_path, run_dir,
GATEWAY_DISCOVERY_FILE_NAME, GATEWAY_LOG_FILE_NAME, GATEWAY_PRIVATE_FILE_NAME,
INSTANCE_LOCK_FILE_NAME, LOCK_FILE_NAME, default_run_dir, gateway_discovery_file_path,
gateway_log_path, gateway_private_file_path, instance_lock_file_path, lock_file_path, run_dir,
};
pub use crate::private::{GatewayPrivateFile, remove_private_if_mine};
pub use crate::shutdown::{ShutdownError, request_shutdown, request_shutdown_before};
pub use crate::stale::resolve_cancellable;
#[cfg(feature = "test-fixtures")]
Expand Down
10 changes: 10 additions & 0 deletions crates/gateway-api-discovery/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ use std::path::{Path, PathBuf};
/// The gateway discovery file's name inside the run directory.
pub const GATEWAY_DISCOVERY_FILE_NAME: &str = "gateway.json";

/// The private proofs file's name inside the run directory. It is not part
/// of the discovery contract.
pub const GATEWAY_PRIVATE_FILE_NAME: &str = "gateway-private.json";

/// The gateway log's name inside the state directory's `logs` directory.
pub const GATEWAY_LOG_FILE_NAME: &str = "gateway.log";

Expand Down Expand Up @@ -37,6 +41,12 @@ pub fn gateway_discovery_file_path(run_dir: &Path) -> PathBuf {
run_dir.join(GATEWAY_DISCOVERY_FILE_NAME)
}

/// The private proofs file inside `run_dir`.
#[must_use]
pub fn gateway_private_file_path(run_dir: &Path) -> PathBuf {
run_dir.join(GATEWAY_PRIVATE_FILE_NAME)
}

/// The launch lock inside `run_dir`.
#[must_use]
pub fn lock_file_path(run_dir: &Path) -> PathBuf {
Expand Down
120 changes: 120 additions & 0 deletions crates/gateway-api-discovery/src/private-tests.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
//! Tests for the private proofs file.

use super::*;

fn valid() -> GatewayPrivateFile {
GatewayPrivateFile {
pid: 4242,
epoch: 1_763_000_000,
plan_proof: "plan-proof-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa".to_owned(),
owner_proof: "owner-proof-bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb".to_owned(),
}
}

fn discovery(pid: u32, epoch: u64) -> GatewayDiscoveryFile {
GatewayDiscoveryFile {
port: 8081,
api_key: "key".to_owned(),
pid,
epoch,
version: "0.3.1".to_owned(),
started_at: "2026-11-13T12:00:00Z".to_owned(),
}
}

#[test]
fn it_round_trips_and_is_absent_until_written() {
let dir = tempfile::TempDir::new().expect("tempdir");
assert_eq!(GatewayPrivateFile::read(dir.path()).expect("reads"), None);
valid().write_to(dir.path()).expect("writes");
assert_eq!(
GatewayPrivateFile::read(dir.path()).expect("reads"),
Some(valid())
);
}

#[cfg(unix)]
#[test]
fn it_lands_owner_only() {
use std::os::unix::fs::PermissionsExt as _;

let dir = tempfile::TempDir::new().expect("tempdir");
valid().write_to(dir.path()).expect("writes");
let mode = std::fs::metadata(gateway_private_file_path(dir.path()))
.expect("meta")
.permissions()
.mode();
assert_eq!(mode & 0o777, 0o600);
}

#[test]
fn proofs_pair_only_with_the_boot_that_minted_them() {
let file = valid();
assert!(file.names_boot_of(&discovery(4242, 1_763_000_000)));
assert!(
!file.names_boot_of(&discovery(4243, 1_763_000_000)),
"another process"
);
assert!(
!file.names_boot_of(&discovery(4242, 1_763_000_001)),
"a later boot"
);
}

#[test]
fn an_invalid_file_is_neither_written_nor_read() {
let dir = tempfile::TempDir::new().expect("tempdir");
let cases = [
GatewayPrivateFile { pid: 0, ..valid() },
GatewayPrivateFile {
plan_proof: String::new(),
..valid()
},
GatewayPrivateFile {
owner_proof: "has a space".to_owned(),
..valid()
},
GatewayPrivateFile {
owner_proof: valid().plan_proof,
..valid()
},
];
for case in cases {
assert!(case.validation_error().is_some(), "{case:?}");
assert!(matches!(
case.write_to(dir.path()),
Err(SidecarError::Invalid { .. })
));
}
assert_eq!(GatewayPrivateFile::read(dir.path()).expect("reads"), None);

std::fs::write(gateway_private_file_path(dir.path()), b"{ not json").expect("write");
assert!(matches!(
GatewayPrivateFile::read(dir.path()),
Err(SidecarError::Parse { .. })
));
}

#[test]
fn only_the_owning_process_removes_it() {
let dir = tempfile::TempDir::new().expect("tempdir");
remove_private_if_mine(dir.path(), 4242).expect("a missing file is fine");
valid().write_to(dir.path()).expect("writes");
remove_private_if_mine(dir.path(), 9999).expect("a foreign pid leaves it");
assert!(
GatewayPrivateFile::read(dir.path())
.expect("reads")
.is_some()
);
remove_private_if_mine(dir.path(), 4242).expect("removes its own");
assert_eq!(GatewayPrivateFile::read(dir.path()).expect("reads"), None);
}

#[test]
fn debug_output_never_shows_a_proof() {
let shown = format!("{:?}", valid());
assert!(
!shown.contains("plan-proof-a") && !shown.contains("owner-proof-b"),
"{shown}"
);
}
Loading