From 7eb1bc6615db83e0d833dff511233d352a0c7980 Mon Sep 17 00:00:00 2001 From: Sebastian Gieseler Date: Wed, 21 Oct 2026 13:41:34 +0200 Subject: [PATCH 1/3] fix(pool): the share switch on Windows is off and says why A lane is a Linux container with a Linux devstack in it (ADR-0028), which a Windows machine cannot run yet: its share switch only reported capacity that nobody could use, and the pool showed it as shared. On Windows the hub now offers nothing and reports `sharing: false`, refuses to switch sharing on (409 with the reason), and tells the dashboard why (`unavailable` in /hub/pool/share), which disables the switch and links #168. The machine still starts its own lanes in the pool. Refs #168 Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 8 ++++++ crates/devstack-hub/src/share.rs | 43 +++++++++++++++++++++++++++---- crates/devstack/tests/hub.rs | 32 +++++++++++++++++++++++ docs/dashboard-api.md | 2 +- docs/pool.md | 4 +++ ui/src/api/types.ts | 2 ++ ui/src/components/ShareSwitch.vue | 15 ++++++++--- 7 files changed, 96 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1575fca8..ced05748 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,14 @@ and listed with their assets on the ## [Unreleased] +### Fixed + +- **The share switch on Windows is off and says why**: a Windows machine + cannot run the pool's lanes yet (a lane is a Linux container), so it + offered capacity nobody could use. The hub reports nothing as shared from + Windows and refuses to switch sharing on (`409`); its own lanes still start + in the pool. Running lanes of others on Windows is #168. + ### Changed - **A lane started on a node opens its pages as soon as its daemon runs diff --git a/crates/devstack-hub/src/share.rs b/crates/devstack-hub/src/share.rs index 617819b0..3246656d 100644 --- a/crates/devstack-hub/src/share.rs +++ b/crates/devstack-hub/src/share.rs @@ -26,6 +26,18 @@ use std::time::Duration; const EVERY: Duration = Duration::from_secs(15); +/// Why this machine cannot run the pool's lanes, whatever the switch says. +/// A lane is a Linux container with a Linux `devstack` in it (ADR-0028), +/// which a node agent on Windows cannot provide; until #168 a Windows +/// machine offers nothing, so the pool shows no capacity nobody can use. +const UNAVAILABLE: Option<&str> = if cfg!(windows) { + Some( + "Windows does not run the pool's lanes yet: they are Linux containers, which an agent on Windows cannot provide (#168). This machine can still start its lanes in the pool.", + ) +} else { + None +}; + #[derive(Debug, Clone, Default, Serialize)] pub struct Status { pub settings: Settings, @@ -46,6 +58,9 @@ pub struct Status { /// report; `None` before one, or from an older coordinator. #[serde(skip_serializing_if = "Option::is_none")] pub coordinator: Option, + /// Why this machine shares nothing whatever the switch says (Windows). + #[serde(skip_serializing_if = "Option::is_none")] + pub unavailable: Option, } struct Sharing { @@ -89,6 +104,7 @@ fn dir(pool: &str) -> std::path::PathBuf { fn entry<'a>(map: &'a mut BTreeMap, pool: &str) -> &'a mut Status { map.entry(pool.to_string()).or_insert_with(|| Status { settings: Settings::load(&dir(pool)), + unavailable: UNAVAILABLE.map(str::to_string), ..Status::default() }) } @@ -143,7 +159,11 @@ fn run(poked: &mpsc::Receiver<()>) { let gpus = devstack_node::share::gpus(); for (pool, _) in devstack_node::member::pools(&state()) { let settings = entry(&mut s.status.lock().unwrap(), &pool).settings.clone(); - let offer = settings.offer(free); + let offer = if UNAVAILABLE.is_some() { + Amount::default() + } else { + settings.offer(free) + }; let result = report(&pool, &settings, offer, total, &gpus); let mut map = s.status.lock().unwrap(); let st = entry(&mut map, &pool); @@ -182,7 +202,7 @@ fn report( } local .report(&Report { - sharing: settings.enabled, + sharing: settings.enabled && UNAVAILABLE.is_none(), cpus: offer.cpus, memory: offer.memory, api: None, @@ -199,7 +219,7 @@ fn report( gpus: gpus .iter() .map(|g| devstack_node::share::Gpu { - offered: settings.enabled, + offered: settings.enabled && UNAVAILABLE.is_none(), ..g.clone() }) .collect(), @@ -225,7 +245,9 @@ pub async fn get(Query(q): Query) -> Response { if let Some(a) = any.filter(|_| st.reported_at.is_none() && st.total.cpus == 0.0) { st.total = a.total; st.free = a.free; - st.offer = st.settings.offer(a.free); + if UNAVAILABLE.is_none() { + st.offer = st.settings.offer(a.free); + } } Json(st.clone()).into_response() } @@ -254,6 +276,13 @@ pub async fn put(Query(q): Query, Json(new): Json) -> Respo let Some(s) = SHARING.get() else { return bad("sharing has not started"); }; + if let Some(why) = UNAVAILABLE.filter(|_| new.enabled) { + return ( + StatusCode::CONFLICT, + Json(serde_json::json!({ "error": why })), + ) + .into_response(); + } if let Err(e) = new.save(&dir(&pool)) { return ( StatusCode::INTERNAL_SERVER_ERROR, @@ -265,7 +294,11 @@ pub async fn put(Query(q): Query, Json(new): Json) -> Respo let mut map = s.status.lock().unwrap(); let st = entry(&mut map, &pool); st.settings = new; - st.offer = st.settings.offer(st.free); + st.offer = if UNAVAILABLE.is_some() { + Amount::default() + } else { + st.settings.offer(st.free) + }; st.clone() }; let _ = s.poke.lock().unwrap().send(()); diff --git a/crates/devstack/tests/hub.rs b/crates/devstack/tests/hub.rs index 70c39bfe..13c64ab6 100644 --- a/crates/devstack/tests/hub.rs +++ b/crates/devstack/tests/hub.rs @@ -846,3 +846,35 @@ fn down_then_up_at_once_runs_again() { std::thread::sleep(Duration::from_millis(200)); } } + +/// #168: a Windows machine cannot run the pool's lanes, so its switch stays +/// off and says why; elsewhere nothing changes. +#[test] +fn sharing_is_refused_on_windows_with_the_reason() { + let h = start(); + let p = h.port; + let bearer = format!("Authorization: Bearer {}\r\n", token(&h)); + let (s, _, body) = get(p, "/hub/pool/share", &bearer); + assert_eq!(s, 200, "{body}"); + let v: serde_json::Value = serde_json::from_str(&body).unwrap(); + assert_eq!(v["unavailable"].is_string(), cfg!(windows), "{v}"); + let put = |body: &str| { + http( + p, + &format!( + "PUT /hub/pool/share HTTP/1.1\r\nHost: 127.0.0.1:{p}\r\n{bearer}Content-Type: application/json\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}", + body.len() + ), + ) + }; + let (s, _, body) = put(r#"{"enabled":true}"#); + if cfg!(windows) { + assert_eq!(s, 409, "{body}"); + assert!(body.contains("#168"), "{body}"); + } else { + assert_eq!(s, 200, "{body}"); + } + // Switching it off (or setting caps) is always fine. + let (s, _, body) = put(r#"{"enabled":false,"max_cpus":2}"#); + assert_eq!(s, 200, "{body}"); +} diff --git a/docs/dashboard-api.md b/docs/dashboard-api.md index 0c484f1b..21ada02a 100644 --- a/docs/dashboard-api.md +++ b/docs/dashboard-api.md @@ -82,7 +82,7 @@ and `Referrer-Policy: no-referrer`. The dashboard has no inline script. | `POST /hub/pool/nodes/{id}/policy` (a `NodePolicy` or `null`) | cookie + Origin | admins only: what the node lets run on it, `{allow, repos, memory_headroom?, max_cpus?, network: "lan"\|"internet"\|"none"}`; `null` lifts it | | `POST /hub/pool/join {"coordinator", "fingerprint", "name"?}` | cookie + Origin | ask a pool to admit this machine (`devstack join` without waiting); `GET /hub/pool` shows it pending until an admin approves. `coordinator` is `https://[:]` and nothing more (`400` otherwise). Errors of every `/hub/pool...` route pass on the coordinator's own `{"error"}` only, never the body of whatever else answered | | `POST /hub/pool/members/{id}/role {"role"}` | cookie + Origin | admins only: `member` or `admin`; `409 {"error"}` for the last admin. A member who is no admin gets `403` from all three | -| `GET /hub/pool/share`, `PUT /hub/pool/share {enabled, max_cpus?, max_memory?}` | cookie (+ Origin for `PUT`) | this machine's share of the pool (ADR-0031 point 3), per pool: the switch, the caps, what is free and offered now, the last report (`ShareStatus`, with `coordinator?`: the `PoolRelease` the coordinator answered the last report with, absent from an older one); `PUT` changes them and reports at once | +| `GET /hub/pool/share`, `PUT /hub/pool/share {enabled, max_cpus?, max_memory?}` | cookie (+ Origin for `PUT`) | this machine's share of the pool (ADR-0031 point 3), per pool: the switch, the caps, what is free and offered now, the last report (`ShareStatus`, with `coordinator?`: the `PoolRelease` the coordinator answered the last report with, absent from an older one; `unavailable?`: why this machine shares nothing whatever the switch says, on Windows until [#168](https://github.com/nuetzliches/devstack/issues/168)); `PUT` changes them and reports at once, `409` with that reason for `enabled: true` where it is set | | `POST /hub/shutdown` | `Authorization: Bearer ` | `202`; the hub exits (`devstack hub stop`) | | `POST /hub/pair` | `Authorization: Bearer ` | `{"code": "...", "url": "http://127.0.0.1:4250/auth?code=..."}` (CLI only) | diff --git a/docs/pool.md b/docs/pool.md index bd45f377..bb342175 100644 --- a/docs/pool.md +++ b/docs/pool.md @@ -67,6 +67,10 @@ lanes run where. A member that only asks for lanes needs nothing else. The **share switch** (sidebar, pool area) lets the pool run other members' lanes on your machine: half of what is free, never more than the caps you set; off by default. +On Windows the switch stays off and says why: a lane is a Linux container +that a Windows machine cannot run yet +([#168](https://github.com/nuetzliches/devstack/issues/168)); it still starts +its own lanes in the pool. ## Run a node diff --git a/ui/src/api/types.ts b/ui/src/api/types.ts index 2006eecb..559e186a 100644 --- a/ui/src/api/types.ts +++ b/ui/src/api/types.ts @@ -384,6 +384,8 @@ export type ShareStatus = { error: string | null; /** The devstack the coordinator runs, from its answer to the last report; absent from an older one. */ coordinator?: PoolRelease; + /** Why this machine shares nothing whatever the switch says (Windows, #168); absent where it can. */ + unavailable?: string; }; /** A pool this machine belongs to or asked to join (ADR-0034), `GET /hub/pools`. */ diff --git a/ui/src/components/ShareSwitch.vue b/ui/src/components/ShareSwitch.vue index 1f5f8d7b..376f26e9 100644 --- a/ui/src/components/ShareSwitch.vue +++ b/ui/src/components/ShareSwitch.vue @@ -10,7 +10,9 @@ import { usePool } from '@/stores/pool'; const props = defineProps<{ compact?: boolean }>(); const pool = usePool(); const s = computed(() => pool.share); -const on = computed(() => !!s.value?.settings.enabled); +/** This machine cannot run the pool's lanes (Windows, #168): the switch stays off. */ +const unavailable = computed(() => s.value?.unavailable ?? null); +const on = computed(() => !!s.value?.settings.enabled && !unavailable.value); const busy = ref(false); const GIB = 2 ** 30; @@ -69,8 +71,8 @@ const reported = computed(() => { role="switch" class="switch" :aria-checked="on" - :disabled="busy || !s.member" - :title="s.member ? (on ? 'Stop sharing this machine' : 'Share this machine with the pool') : 'Join a pool first'" + :disabled="busy || !s.member || !!unavailable" + :title="unavailable ?? (s.member ? (on ? 'Stop sharing this machine' : 'Share this machine with the pool') : 'Join a pool first')" data-testid="share-switch" @click="toggle" > @@ -78,11 +80,16 @@ const reported = computed(() => { {{ on ? 'Sharing' : 'Not sharing' }} + not on Windows yet {{ pool.current }} {{ offerText }} -