From ec80c312b80ba51271fff0548c6d1e293d373455 Mon Sep 17 00:00:00 2001 From: aur-build Date: Thu, 19 Nov 2026 15:32:44 +0000 Subject: sandbox: the agent listener belongs to the process, not to a build MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `Ctx::new` constructed a backend for every build, and constructing a remote backend bound the agent listener. With a fixed `listen` — which is what any real deployment configures, since the operator has to tell the agents where to dial — the second concurrent build died of EADDRINUSE. A build failing for a reason that had nothing to do with its package is the worst kind of flake: it looks like the package's fault. `RemoteBackend::bind` now shares one bound listener per `(address, token)` for the life of the process, and hands each backend a clone of the dial-in queue. That is also what `remote` already meant: an agent dials in when the operator boots one and whichever build is waiting takes it. The token is part of the key deliberately — two tokens cannot share a listener, and quietly reusing the first one's would be a fail-open surprise, so the second bind is attempted and fails loudly instead. Backend construction moved out of `Ctx` into `sandbox::backend_for`, so "which backend" has exactly one answer and the validation guard travels with it. Tests cover the shared listener, the shared queue (the *second* backend takes the dial-in), the two-token refusal, and two concurrent `Ctx`es on one address — with an assertion that a raw second bind still fails, so the test cannot rot into proving nothing. --- src/pipeline/mod.rs | 28 +--------------------------- 1 file changed, 1 insertion(+), 27 deletions(-) (limited to 'src/pipeline') diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs index 350df0c..6729605 100644 --- a/src/pipeline/mod.rs +++ b/src/pipeline/mod.rs @@ -171,36 +171,10 @@ impl Ctx { log: cfg.build_log_path(build_id), profile, attempt, - backend: Self::backend_for(cfg)?, + backend: crate::sandbox::backend_for(cfg)?, }) } - /// Which backend a build runs on is configuration, not code: the step - /// machine cannot tell loopback from remote, which is the seam's whole - /// point. `remote` binds the agent listener for the lifetime of this - /// run's context. - fn backend_for(cfg: &Config) -> Result> { - // The startup guard in the CLI catches this first; repeating it here is - // what makes "the config was never validated" impossible for anything - // that constructs a backend — a test, a future daemon, a tool. - cfg.validate()?; - match &cfg.sandbox { - crate::config::Sandbox::Loopback => { - Ok(Arc::new(crate::sandbox::loopback::LoopbackBackend::new(cfg))) - } - crate::config::Sandbox::Remote { listen, token, .. } => Ok(Arc::new( - crate::sandbox::remote::RemoteBackend::bind(cfg, listen, token)?, - )), - // A valid kind that is not wired up yet is an error, never a - // fallthrough: a build configured for a Kata VM that silently ran - // as the hub's own user is the failure this enum was added to stop. - crate::config::Sandbox::AgentSandbox { .. } => Err(Error::invalid(concat!( - "sandbox kind \"agent-sandbox\" is not wired up yet; refusing to run this build ", - "on a backend it was not configured for", - ))), - } - } - /// Lease a sandbox for this build's profile. Today every step acquires and /// releases around itself; a remote backend will hold one sandbox across /// the sandbox-bearing steps of a build, and steps stay idempotent either -- cgit v1.2.3