diff --git a/robot-docs/kernel.md b/robot-docs/kernel.md index de0c1b5e6..46156f015 100644 --- a/robot-docs/kernel.md +++ b/robot-docs/kernel.md @@ -741,7 +741,9 @@ Kernels stay resident while their session uses them. A resting session releases kernel came back running a job that is not a service is started at once, idle, so its cache warming resumes (robot-docs/cache-warming.md). a session that asks for its kernel meanwhile waits for that attach, and gets a fresh boot if there - was nothing to attach to. an attached kernel's `runtime.origin` is + was nothing to attach to. it gets what an open would: an attached kernel + that turned out stale (its protocol or bundle is only known from its hello) + and that no live job keeps is swapped before the waiter has it. an attached kernel's `runtime.origin` is `Resumed`, and the session keeps its namespace without the disk restore. a recorded kernel whose module set no longer fits is kept and marked stale; one in another workspace is stopped and replaced. when jobs or background cells diff --git a/src/albedo/harness/runtime/preparation.gleam b/src/albedo/harness/runtime/preparation.gleam index baafbd39b..509778638 100644 --- a/src/albedo/harness/runtime/preparation.gleam +++ b/src/albedo/harness/runtime/preparation.gleam @@ -416,7 +416,9 @@ pub fn booted( /// The composition is in place and `session` is what came with it. A kernel /// is handed out like a boot; without one, a waiting opener gets a boot and -/// nobody waiting ends the generation. +/// nobody waiting ends the generation. Openers that waited for a reattach +/// get what an open would: a stale kernel nothing keeps is swapped first, +/// since its staleness was only known once it answered. pub fn settled( state: runtime_state.State, id: String, @@ -426,7 +428,18 @@ pub fn settled( waiters: List(fn(Result(runtime_state.Session, python.Error)) -> Nil), ) -> runtime_state.State { case session, waiters { - Some(session), _ -> booted(state, id, generation, Ok(session)) + Some(session), [_, ..] -> + case runtime_state.upgradable(session) { + True -> + runtime_state.State( + ..state, + waiting: list.append(state.waiting, [ + runtime_state.SwapStale(id, generation, cached, session), + ]), + ) + False -> booted(state, id, generation, Ok(session)) + } + Some(session), [] -> booted(state, id, generation, Ok(session)) None, [] -> runtime_state.generation_over(state, id) None, _ -> runtime_state.State(