diff --git a/crates/runvil-engine/src/lib.rs b/crates/runvil-engine/src/lib.rs index 599a63368..abc153cc0 100644 --- a/crates/runvil-engine/src/lib.rs +++ b/crates/runvil-engine/src/lib.rs @@ -9,6 +9,10 @@ //! A tool whose call is open asks the caller for each file operation it //! needs, and the caller reports the request with [`Run::request_file`], //! so the run issues that operation as an effect too. +//! A [`Step::Pending`] with no effects and `waiting_for_input` set means only +//! [`Run::deliver`] or a cancel can move the run: the main chain is waiting on +//! a `tasks.receive()`. Every other pending step returns the effects the run +//! waits on. //! The run ends at [`Step::Done`] with its result: the final text, or the //! [`Error`] that ended it. A cancel is the error whose code //! is [`ErrorCode::Canceled`]. @@ -22,7 +26,8 @@ //! [`RequirementsUnmet`](ErrorCode::RequirementsUnmet) failure that names //! every gap. //! -//! The crate's `greeter` example is that whole loop in one program. +//! The crate's `greeter` example is the loop for a prompt that never waits on +//! a message, so it takes no `waiting_for_input` arm. pub use runvil_prompt::Prompt; pub use runvil_prompt::PromptFinder; diff --git a/crates/runvil-internal/lua/src/dispatch.rs b/crates/runvil-internal/lua/src/dispatch.rs index 89fd56729..2b25fa65a 100644 --- a/crates/runvil-internal/lua/src/dispatch.rs +++ b/crates/runvil-internal/lua/src/dispatch.rs @@ -29,7 +29,8 @@ use crate::protocol::ModelCall; /// event belongs to. #[derive(Debug, Clone, Copy)] pub struct ScriptReport { - /// The section's completed model-turn count at dispatch. + /// The turn the call reports under: the requesting round's turn for a + /// call a model issued, or the task's model-turn counter at dispatch. pub turn: u32, } diff --git a/crates/runvil-internal/lua/src/globals.rs b/crates/runvil-internal/lua/src/globals.rs index 20b3d331c..873b55b17 100644 --- a/crates/runvil-internal/lua/src/globals.rs +++ b/crates/runvil-internal/lua/src/globals.rs @@ -21,7 +21,9 @@ //! guard, copying its other fields onto the guard, and `getmetatable(_G)` //! returns the author's metatable (or its `__metatable` field), never the //! guard. For every other value both behave as the base functions, -//! argument errors and `__metatable` protection included. With no debug +//! argument errors and `__metatable` protection included, except that +//! `setmetatable` refuses, on every target, a metatable with a `__gc` +//! field: finalizers are not available in the sandbox. With no debug //! library, `rawset`, or code loading in the sandbox, author code has no //! route to the guard or to a raw `args`, `prose`, or `messages` global. //! diff --git a/crates/runvil-internal/lua/src/lib.rs b/crates/runvil-internal/lua/src/lib.rs index 30666a25e..b3566492e 100644 --- a/crates/runvil-internal/lua/src/lib.rs +++ b/crates/runvil-internal/lua/src/lib.rs @@ -11,7 +11,9 @@ //! Four standard functions are replaced so that a run with the same seed //! repeats: `math.randomseed` seeds from the VM's own generator, //! `table.sort` is a stable merge sort, and `tostring` and `string.format` -//! print a table, function, thread, or userdata by its name. The executor +//! print a table, function, thread, or userdata by its name. `pairs` and +//! `next` are replaced too, for a different reason: each walks a table's keys +//! in the fixed order above. The executor //! seeds each VM's `math.random` generator. //! Direct `print` and `warn` are unavailable. A persistent `log(message)` //! callback accepts one bounded, single-line UTF-8 string and reports it diff --git a/crates/runvil-internal/lua/src/models_loop/machine.rs b/crates/runvil-internal/lua/src/models_loop/machine.rs index 4e8ac5bca..b93814b88 100644 --- a/crates/runvil-internal/lua/src/models_loop/machine.rs +++ b/crates/runvil-internal/lua/src/models_loop/machine.rs @@ -218,8 +218,8 @@ impl Machine { } /// Applies one input, pushes the records it settles, and returns what - /// runs next. A reply is read as the renderer reads it, an empty - /// string as no reply. An input other than the one + /// runs next. An empty reply string is read as no reply. An input other + /// than the one /// [`Machine::phase`] names is a crate bug and raises an `internal` /// error. pub(super) fn step(&mut self, input: Input) -> Then { diff --git a/crates/runvil-internal/lua/src/order.rs b/crates/runvil-internal/lua/src/order.rs index d5cee7b3c..42df6c4a8 100644 --- a/crates/runvil-internal/lua/src/order.rs +++ b/crates/runvil-internal/lua/src/order.rs @@ -1,13 +1,14 @@ //! The shared ordering of a Lua table's hash keys. //! -//! Lua leaves a table's hash traversal order unspecified, so every path that -//! turns a table into an ordered sequence imposes the same order: booleans -//! first (`false` before `true`), then numbers by value, then strings +//! Lua leaves a table's hash traversal order unspecified, so this module +//! orders the keys a reader sorts, and each reader chooses what comes before +//! them: fanout puts the list first, and `pairs` and `next` put every integer +//! from 1 up first (see `iteration::WalkPlace`). The key order itself: +//! booleans first (`false` before `true`), then numbers by value, then strings //! bytewise. [`sort_key`] classifies one Lua key into its [`SortKey`]; -//! [`SortKey::compare`] orders two of them. Fanout's member enumeration, the -//! deterministic `pairs`/`next` installer, and `json.encode`'s key order -//! share both, so a table's order is a function of its contents wherever it -//! is read. [`FirstRefusal`] gives the same order to a check that refuses a +//! [`SortKey::compare`] orders two of them, and `json.encode` uses both for +//! its own key order. [`FirstRefusal`] gives the same order to a check that +//! refuses a //! table for one of its entries, and [`sort_list`] to a Lua list of a //! table's entries. [`is_weak`] tells a table that no such list is made //! of, and [`listed`] counts the items that come before the keys. diff --git a/crates/runvil-internal/lua/src/prelude.rs b/crates/runvil-internal/lua/src/prelude.rs index 1e5d966df..5ab3c7ee8 100644 --- a/crates/runvil-internal/lua/src/prelude.rs +++ b/crates/runvil-internal/lua/src/prelude.rs @@ -76,8 +76,10 @@ const VISIBLE_GLOBALS: [&str; 21] = [ /// /// # Errors /// Returns a `LuaRuntime` failure naming the Pack when a prelude fails to -/// load, or naming the Pack, the global, and what it collides with when a -/// global collides or is not named by a string. +/// load, when the prelude made its environment weak, or when a global it +/// defines collides with a reserved name, a name already bound in `_G`, or an +/// earlier prelude's global. A global whose key is not a string is refused +/// with the Pack and the key's type named. pub fn install_preludes(lua: &Lua, preludes: &[Prelude]) -> Result<()> { let globals = lua.globals(); let mut installed: BTreeMap = BTreeMap::new(); diff --git a/crates/runvil-internal/lua/src/projection.rs b/crates/runvil-internal/lua/src/projection.rs index de0314572..75b5a3ff3 100644 --- a/crates/runvil-internal/lua/src/projection.rs +++ b/crates/runvil-internal/lua/src/projection.rs @@ -26,8 +26,8 @@ //! //! The output is the OpenAI wire shape the gateway speaks: replayed //! assistant `tool_calls` render as the function-call -//! `{id, type, function: {name, arguments}}` object, the exact inverse of the -//! Engine's own inbound parser, so records stay neutral while the wire +//! `{id, type, function: {name, arguments}}` object, the same shape a +//! reply's tool calls arrive in, so records stay neutral while the wire //! dogfoods the gateway's ingress contract. The projection is recomputed per //! dispatch and is the same for every model. diff --git a/crates/runvil-internal/lua/src/protocol/render.rs b/crates/runvil-internal/lua/src/protocol/render.rs index cf871e4d9..768ba424a 100644 --- a/crates/runvil-internal/lua/src/protocol/render.rs +++ b/crates/runvil-internal/lua/src/protocol/render.rs @@ -164,9 +164,9 @@ pub(crate) fn render_envelope( // return, so the call's value is nil and never the empty string, // which a chain can return on purpose. Answer::Call(None) | Answer::Note | Answer::Cancel => vec![Value::Nil], - // The one serde-boundary conversion: the parsed JSON output - // becomes the resumed Lua value, so the shim hands the script a - // table with no codec in author reach. + // The parsed JSON output resumes through `lua.to_value`, the same + // conversion `json.decode` uses, so a structured result and a + // decoded text have the same shape. Answer::ToolCallResult(ToolCallOutcome::Structured(json)) => { vec![lua.to_value(&json)?] } diff --git a/crates/runvil-internal/lua/src/protocol/request.rs b/crates/runvil-internal/lua/src/protocol/request.rs index b9ac12919..e0276a375 100644 --- a/crates/runvil-internal/lua/src/protocol/request.rs +++ b/crates/runvil-internal/lua/src/protocol/request.rs @@ -233,7 +233,8 @@ pub enum Request { /// resolves the section's current model. binding: Option, }, - /// `store.*(...)`: one run-scoped store operation as a leaf yield. + /// `store.*(...)`: one operation on the calling chain's store, as a leaf + /// yield. /// Every operation takes this path, with no inline fast path. Store { /// The validated operation and its author-supplied arguments: one diff --git a/crates/runvil-internal/lua/src/tools/tests.rs b/crates/runvil-internal/lua/src/tools/tests.rs index 1257886b6..e86021b46 100644 --- a/crates/runvil-internal/lua/src/tools/tests.rs +++ b/crates/runvil-internal/lua/src/tools/tests.rs @@ -292,7 +292,7 @@ fn adhoc_params_schema_rejects_an_unsupported_type_under_the_adhoc_prefix() { #[test] fn the_tools_namespace_exposes_its_verbs_without_call() { // `call` is absent here on purpose: it suspends, so the coroutine shim - // prelude installs it - this table exposes exactly the non-suspending + // chunk installs it - this table exposes exactly the non-suspending // operations. let vm = TestVm::new().build(); let shapes: (bool, bool, bool, bool, bool) = vm.eval( @@ -306,7 +306,7 @@ fn the_tools_namespace_exposes_its_verbs_without_call() { } #[test] -fn the_shim_prelude_installs_tools_call() { +fn the_shim_chunk_installs_tools_call() { let vm = TestVm::new().shims().build(); let call_is_function: bool = vm.eval("return type(tools.call) == 'function'"); assert!(call_is_function, "tools.call installs on the tools table"); diff --git a/crates/runvil-internal/lua/src/tools/userdata.rs b/crates/runvil-internal/lua/src/tools/userdata.rs index f7dfd1ba7..e7af43d7b 100644 --- a/crates/runvil-internal/lua/src/tools/userdata.rs +++ b/crates/runvil-internal/lua/src/tools/userdata.rs @@ -8,8 +8,8 @@ //! methodless, so `description` is always the text the Pack or the //! `tools.adhoc` attrs declared, and each `parameters` read is a fresh //! table of the schema as declared. Neither is ever in the untrusted -//! envelope. Unlike a model handle, which carries `infer` and `loop`, it -//! is invoked only through `tools.call(tool, arguments)`. +//! envelope. Like a model handle, it is a value with fields: +//! `tools.call(tool, arguments)` is the one way to invoke it. use mlua::{LuaSerdeExt, UserData, UserDataFields, UserDataMethods}; use runvil_types::tools::{ToolId, ToolInfo}; diff --git a/crates/runvil-internal/model-client/src/client/wire.rs b/crates/runvil-internal/model-client/src/client/wire.rs index 15a695a3a..02a9160bf 100644 --- a/crates/runvil-internal/model-client/src/client/wire.rs +++ b/crates/runvil-internal/model-client/src/client/wire.rs @@ -37,10 +37,10 @@ pub struct Message { /// For a `tool` message, the id of the tool call this result answers. #[serde(skip_serializing_if = "Option::is_none")] pub(crate) tool_call_id: Option, - /// For an `assistant` turn that requested tools, the raw `tool_calls` array - /// as received from the backend, echoed back verbatim on the live path. The - /// projection path instead re-renders each call from its neutral - /// `ToolCallRecord` into the OpenAI function-call shape, so key order and + /// For an `assistant` turn that requested tools, the `tool_calls` array + /// as received from the backend, echoed verbatim on the live path. A + /// projected record renders each call from its neutral `ToolCallRecord` + /// into the OpenAI function-call shape instead, so key order and /// whitespace can differ from the provider's original. #[serde(skip_serializing_if = "Option::is_none")] pub(crate) tool_calls: Option>, diff --git a/crates/runvil-internal/model-client/src/lib.rs b/crates/runvil-internal/model-client/src/lib.rs index 30d344d78..cc3d66d0c 100644 --- a/crates/runvil-internal/model-client/src/lib.rs +++ b/crates/runvil-internal/model-client/src/lib.rs @@ -5,26 +5,20 @@ //! types that go out of the Engine in a `Chat` effect and come back in its //! answer ([`client::Message`], [`client::ToolSchema`], //! [`client::Completion`]), with the validating constructors that run the -//! neutral reply checks on every completion. [`model`] holds the catalog -//! and prompt-local binding vocabulary: the -//! [`ModelCatalog`](runvil_types::models::ModelCatalog) the -//! caller supplies, the validated [`ModelId`](runvil_types::models::ModelId) -//! identity, and the -//! [`model::ModelBinding`]/[`model::ModelSet`] types -//! model selections resolve and freeze through, with the universal -//! [`Error`](runvil_types::error::Error) under a model code, built through -//! [`model::make_completion_error`], as the failure a round reports. +//! neutral reply checks on every completion. [`model`] holds the binding +//! vocabulary: [`model::ModelBinding`] with its request settings, +//! [`model::ModelSet`], one prompt's filled roles, and the builders of a +//! round's failure, [`model::make_completion_error`] among them. //! -//! The metrics vocabulary in [`runvil_types::metrics`] (`Usage`, -//! `LlamaTimings`, `VllmMetrics`, `ClientTiming`, `CallMetrics`) is -//! canonical in `runvil-types`, and this crate uses it from there: -//! [`client::Completion`] holds a round's metrics. The -//! model identity/catalog vocabulary +//! The model identity and catalog vocabulary //! ([`ModelId`](runvil_types::models::ModelId), //! [`ModelCatalog`](runvil_types::models::ModelCatalog), //! [`ModelInfo`](runvil_types::models::ModelInfo), -//! [`ThinkingMode`](runvil_types::models::ThinkingMode)) is canonical there -//! too, and `runvil-lua` reaches only the id through the `model` path. +//! [`ThinkingMode`](runvil_types::models::ThinkingMode)) lives in +//! `runvil-types`, and a caller builds its catalog there. The metrics +//! vocabulary ([`runvil_types::metrics`], which holds `Usage`, +//! `LlamaTimings`, `VllmMetrics`, `ClientTiming`, and `CallMetrics`) lives +//! there too: [`client::Completion`] holds a round's metrics. //! //! This crate contains no HTTP, no wire parsing, no prompt parser, no Lua //! runtime, and no executor. diff --git a/crates/runvil-internal/model-client/src/model.rs b/crates/runvil-internal/model-client/src/model.rs index fd36c5947..b673b37a0 100644 --- a/crates/runvil-internal/model-client/src/model.rs +++ b/crates/runvil-internal/model-client/src/model.rs @@ -1,14 +1,13 @@ -//! Prompt-local model bindings: catalog, role bindings, and invocation. +//! Prompt-local model bindings: a binding's request settings, the set a +//! prompt fills, and the builders of a round's failure. //! -//! The caller supplies the -//! [`ModelCatalog`](runvil_types::models::ModelCatalog); building it happens -//! outside this crate. Building a run fills each of the five model roles -//! from the caller's role map into its [`ModelSet`], once, before any Lua -//! runs, and the run's first step checks the prompt's declared requirements -//! against the model that fills each role. `models.use` selects one binding for -//! a section, and a section that never calls it runs on the `default` role. -//! A model-facing section with no model fails with a model-binding failure -//! surfaced through the run error the caller receives. +//! The caller supplies its role map; +//! [`ModelSet`] holds the five roles filled from it for one prompt, and the +//! prompt's first step checks the requirements it declares against the model +//! that fills each role. `models.use` selects one binding for a section, and +//! a section that never calls it runs on the `default` role. A model-facing +//! section with no model fails with a model-binding failure surfaced through +//! the run error the caller receives. pub(crate) mod error; mod options; diff --git a/crates/runvil-internal/model-client/src/model/error.rs b/crates/runvil-internal/model-client/src/model/error.rs index d6cd57b3e..e705b606c 100644 --- a/crates/runvil-internal/model-client/src/model/error.rs +++ b/crates/runvil-internal/model-client/src/model/error.rs @@ -40,8 +40,12 @@ pub fn phrase(code: ErrorCode) -> &'static str { } /// Builds the failure of a model round or a catalog fetch, with `message` as -/// both its message and its prose. `code` is one of the model codes, and -/// `message` is its phrase, extended as the module page says. +/// both its message and its prose. +/// +/// `code` is one of the model codes. The prose a model reads is the code's own +/// phrase from [`ErrorCode::prose`], extended with `message` when the failure +/// carries a specific fact, such as the provider's text or the field that was +/// refused. #[must_use] pub fn make_completion_error(code: ErrorCode, message: impl Into) -> Error { let message = message.into(); diff --git a/crates/runvil-internal/model-client/src/model/options.rs b/crates/runvil-internal/model-client/src/model/options.rs index 9134b2fbd..f0504989b 100644 --- a/crates/runvil-internal/model-client/src/model/options.rs +++ b/crates/runvil-internal/model-client/src/model/options.rs @@ -1,5 +1,6 @@ -//! Model value types: validated temperature, bind/invocation options, -//! prompt-local bindings, and completion options. +//! Model value types: the validated temperature, a binding's request +//! settings, the binding, per-round completion options, and a prompt's +//! model set. use std::num::NonZeroU32; @@ -358,8 +359,8 @@ impl CompletionOptions { } } -/// The run's model set: the five role bindings the run builds once, -/// shared unchanged by every section VM. +/// One prompt's model set: the five role bindings that prompt builds, shared +/// unchanged by its section VMs. #[derive(Debug, Clone, Default, PartialEq, Eq)] pub struct ModelSet { /// The bindings in the order they were pushed. diff --git a/crates/runvil-internal/prompt/src/contract/args_check.rs b/crates/runvil-internal/prompt/src/contract/args_check.rs index 942987c03..f3d437392 100644 --- a/crates/runvil-internal/prompt/src/contract/args_check.rs +++ b/crates/runvil-internal/prompt/src/contract/args_check.rs @@ -54,7 +54,7 @@ impl Mismatch { } } - /// The failure of a run whose arguments hold this mismatch. + /// The failure of a caller or a chain whose arguments hold this mismatch. fn into_error(self) -> Error { make_args_error( self.reason, @@ -106,7 +106,8 @@ pub(crate) fn accept_value(schema: &ArgsSchema, mut args: Json) -> Result String { let names: Vec = object @@ -312,7 +314,8 @@ fn json_kind(value: &Json) -> &'static str { } } -/// Builds the failure of a run's arguments: `message` under `ArgsInvalid`, +/// Builds the failure of a caller or a chain whose arguments do not match: +/// `message` under `ArgsInvalid`, /// with the `Reason` fact `reason` and, for one argument, its path as the /// `Name` fact. The prose is the message and then the code's default. fn make_args_error(reason: &str, name: Option<&str>, message: impl Into) -> Error { diff --git a/crates/runvil-internal/prompt/src/detail.rs b/crates/runvil-internal/prompt/src/detail.rs index 27b7e86fa..245c0aaf3 100644 --- a/crates/runvil-internal/prompt/src/detail.rs +++ b/crates/runvil-internal/prompt/src/detail.rs @@ -16,7 +16,8 @@ pub const TEXT_FIELD: &str = crate::contract::TEXT_FIELD; /// Reads `text`, the arguments a caller passes a run of `prompt`, against /// the prompt's `args` declaration, and returns the object the run holds: -/// the caller's fields, with the declared default of each field left out. +/// the caller's fields, plus the declared default of each field the caller +/// left out. /// /// # Errors /// Returns an `ArgsInvalid` failure with no location when `text` is not @@ -30,8 +31,8 @@ pub fn accept_args(prompt: &Prompt, text: &str) -> Result Option<(Lifecycle, Lifecycle)> { } /// Classifies one store operation's failure for the answer channel. A -/// claims-model conflict becomes the fatal make_determinism_error violation: the +/// claims-model conflict becomes the fatal determinism violation: the /// driver intercepts it at the answer boundary and ends the run on the /// spot rather than resuming it into Lua, so no author `pcall` can catch /// it. Every other failure returns as the call's answer as a store diff --git a/crates/runvil-internal/runtime/src/execute/scheduler/chain.rs b/crates/runvil-internal/runtime/src/execute/scheduler/chain.rs index c7feb08d4..59607bfb5 100644 --- a/crates/runvil-internal/runtime/src/execute/scheduler/chain.rs +++ b/crates/runvil-internal/runtime/src/execute/scheduler/chain.rs @@ -123,7 +123,7 @@ impl Scheduler { /// Finishes one chain: the frame's teardown boundary when the chain /// ends mid-section, the chain-end rules for the tasks it owns (a live - /// task makes the outcome `make_tasks_live_error` and is abandoned), then the + /// task makes the outcome the `tasks_live` code and is abandoned), then the /// chain-end joins - every owned task's final clock merges into this /// chain's own, so a waiting owner sees the whole subtree /// transitively - and finally the outcome's delivery: the run's result @@ -174,7 +174,7 @@ impl Scheduler { // The frame drops here: the single teardown boundary. drop(entered); // The chain's tasks end with it: a live task turns a success into - // `make_tasks_live_error` and is abandoned. + // the `tasks_live` code and is abandoned. let outcome = self.settle_owned_tasks(id, outcome); // The chain-end joins run after the settle - the abandoned tasks' // identities ended there, so their final clocks are recorded - @@ -192,7 +192,7 @@ impl Scheduler { // its end, before its owner is woken: the owner's re-acquire and // any queued sibling need the freed capacity. self.admission.release(id); - // A make_determinism_error violation is fatal to the run on the spot and + // A determinism violation is fatal to the run on the spot and // never resumes into Lua as a catchable member failure: a shim // that re-raises it after its own cleanup yields would flatten // the typed error, so the outcome ends the run here, exactly as diff --git a/crates/runvil-internal/runtime/src/execute/scheduler/task_end.rs b/crates/runvil-internal/runtime/src/execute/scheduler/task_end.rs index 2e79af68b..defce82d1 100644 --- a/crates/runvil-internal/runtime/src/execute/scheduler/task_end.rs +++ b/crates/runvil-internal/runtime/src/execute/scheduler/task_end.rs @@ -5,7 +5,7 @@ //! every live task it owns is abandoned - its entry moves to `Abandoned`, //! its terminal observation names how the owner ended, and its backing //! chain aborts with everything it owns in turn. A task left running is -//! the author's bug, so the owner's own outcome becomes `make_tasks_live_error` naming +//! the author's bug, so the owner's own outcome becomes the `tasks_live` code naming //! the leaked ids; an idle task already handed its owner a reply, so it //! ends without counting as leaked. Tasks survive a section's fall-through //! and a `jump` - those move the walk within one chain - and end with the @@ -208,7 +208,7 @@ impl Scheduler { /// the wait's detail, not a task the author started, and an idle task /// ends the same way but never counts as leaked either: it already /// replied. Returns the abandoned running ids in spawn order, for the - /// owner's `make_tasks_live_error` outcome; the caller discards them for an owner + /// owner's the `tasks_live` code outcome; the caller discards them for an owner /// that is itself being aborted, whose outcome no one receives. pub(super) fn abandon_owned_tasks( &mut self, diff --git a/crates/runvil-internal/runtime/src/execute/scheduler/tasks.rs b/crates/runvil-internal/runtime/src/execute/scheduler/tasks.rs index 602fe7966..b9dc5871c 100644 --- a/crates/runvil-internal/runtime/src/execute/scheduler/tasks.rs +++ b/crates/runvil-internal/runtime/src/execute/scheduler/tasks.rs @@ -152,7 +152,7 @@ pub(super) struct TaskEntry { /// the task, reported by `tasks.status`. pub(super) note: Option, /// The prompt line of the author's call that spawned the task, which a - /// `make_tasks_live_error` failure that names it first is placed on: `None` for + /// the `tasks_live` code failure that names it first is placed on: `None` for /// an internal timer, and for a spawn whose yield found no author /// frame. pub(super) spawn_line: Option, diff --git a/crates/runvil-internal/runtime/src/execute/scheduler/waits.rs b/crates/runvil-internal/runtime/src/execute/scheduler/waits.rs index b981c8948..aad62fc4f 100644 --- a/crates/runvil-internal/runtime/src/execute/scheduler/waits.rs +++ b/crates/runvil-internal/runtime/src/execute/scheduler/waits.rs @@ -6,7 +6,7 @@ //! end or reply delivers it. Delivery takes the member's waiting outcome //! (each result is taken by exactly one wait; a wait on a task whose //! latest result was taken, and that has ended or idles with no message -//! since, raises `make_task_consumed_error`), and it joins the task: +//! since, raises the `task_consumed` code), and it joins the task: //! everything the task did happens before the owner's next step, so its //! store writes are visible from the very next operation. A `Canceled` //! entry delivers `ok = false` with the `canceled` error value and stays diff --git a/crates/runvil-internal/runtime/src/execute/section_vm.rs b/crates/runvil-internal/runtime/src/execute/section_vm.rs index 3f3d0c4fc..545c4ce53 100644 --- a/crates/runvil-internal/runtime/src/execute/section_vm.rs +++ b/crates/runvil-internal/runtime/src/execute/section_vm.rs @@ -12,8 +12,12 @@ //! templates. //! //! VM construction and the Lua limits install stay with the frame -//! constructor. A construction or limits failure propagates as a bare -//! `?` - routing it through teardown would emit +//! constructor. A `SectionVm::new` failure after the struct exists - the +//! hardening, the untrusted install, or the cancel hook - reports the +//! teardown pair through `construction_failed`. The heap-limit step runs +//! before the struct exists and returns bare, as does a failure of the +//! seeding or the limits install, so none of those reports teardown: routing +//! them through it would emit //! `LUA_TEARDOWN_STARTED`/`SUCCEEDED` events the walk never emitted. Setup //! consumes the uninjected VM, so a setup failure tears it down here, the //! one place a VM that never reached its frame is torn down. diff --git a/crates/runvil-internal/runtime/src/execute/tests/scheduler/failures.rs b/crates/runvil-internal/runtime/src/execute/tests/scheduler/failures.rs index 197d2f1de..9849fe5db 100644 --- a/crates/runvil-internal/runtime/src/execute/tests/scheduler/failures.rs +++ b/crates/runvil-internal/runtime/src/execute/tests/scheduler/failures.rs @@ -140,7 +140,7 @@ fn fatal_arm_aborts_an_in_flight_sibling() { // cancels the live sibling before it re-raises, so the cancel orphans // the sibling's effect, drops its round, and fires the // sibling's TaskCanceled BEFORE the parent's chunk failure - a shim - // that raised first would leak the sibling into `make_tasks_live_error`. The + // that raised first would leak the sibling into the `tasks_live` code. The // sibling's round is never answered, so the run cannot have waited // on it. let gateway = ScriptedChat::new(vec![text("boom-answer")]); diff --git a/crates/runvil-internal/runtime/src/execute/tests/tasks-chain-end.rs b/crates/runvil-internal/runtime/src/execute/tests/tasks-chain-end.rs index ab1d60bb0..0fef3af92 100644 --- a/crates/runvil-internal/runtime/src/execute/tests/tasks-chain-end.rs +++ b/crates/runvil-internal/runtime/src/execute/tests/tasks-chain-end.rs @@ -1,5 +1,5 @@ //! The chain-end rules: a chain ending with live tasks fails as -//! `make_tasks_live_error` naming the leaked ids (as the run's error at the root, as +//! the `tasks_live` code naming the leaked ids (as the run's error at the root, as //! the call's answer for a `call` chain), the leaked tasks are abandoned; //! a running task's terminal names how its owner ended (returned, failed, //! or exhausted its tool loop); a task spawned in the preamble belongs to @@ -37,7 +37,7 @@ fn no_task_reports(records: &[(String, Observation)]) -> bool { fn a_chain_ending_with_live_author_tasks_fails_as_tasks_live_naming_the_ids() { // The spawner ends while both children are live - neither was ever // admitted, since the spawner returned without suspending - so the - // run fails with `make_tasks_live_error` naming both ids in spawn order, and + // run fails with the `tasks_live` code naming both ids in spawn order, and // both tasks are abandoned because their owner returned. A task that // never ran reports no start and no terminal, though its entry still // reaches Abandoned. @@ -80,7 +80,7 @@ fn a_chain_ending_with_live_author_tasks_fails_as_tasks_live_naming_the_ids() { #[test] fn a_chain_failing_with_a_live_task_keeps_its_own_error_and_abandons_the_task() { // The spawner errors after spawning: the leak is the lesser fault, so - // the run's error is the spawner's own, not `make_tasks_live_error`; the task + // the run's error is the spawner's own, not the `tasks_live` code; the task // still ends with its owner, its entry Abandoned. The task was never // admitted - the spawner failed without suspending - so it reports no // start and no terminal. @@ -251,7 +251,7 @@ fn moving_spawner_prompt(movement: &str) -> String { ) } -/// Drives `md` and asserts that the run fails `make_tasks_live_error` naming `0.0` +/// Drives `md` and asserts that the run fails the `tasks_live` code naming `0.0` /// alone, with the task's entry Abandoned because its owner returned. The /// task never ran - neither chain suspended between the spawn and the /// end - so it reports no start and no terminal. @@ -296,7 +296,7 @@ fn a_task_survives_its_spawning_sections_jump() { #[test] fn a_call_chain_ending_with_a_live_task_answers_tasks_live_to_its_caller() { // The leak is the call's answer, not the run's error: the caller's - // `pcall` sees the `make_tasks_live_error` kind with the leaked ids in `tasks`, + // `pcall` sees the the `tasks_live` code kind with the leaked ids in `tasks`, // and the task ended with the call chain that owned it. let md = "---\nname: t\ndescription: d\nrunvil: 0\n---\n\n\ ## Main\n\n\ @@ -335,7 +335,7 @@ fn a_call_chain_ending_with_a_live_task_answers_tasks_live_to_its_caller() { #[test] fn a_fanout_arm_leaking_a_task_fails_on_the_arms_own_spawn_line() { - // The arm's `make_tasks_live_error` is placed in the arm, on its spawn's line, + // The arm's the `tasks_live` code is placed in the arm, on its spawn's line, // before the fanout delivers it, so the parent's re-raise and the run // keep that line rather than the parent's `tasks.fanout` line. let md = "---\nname: t\ndescription: d\nrunvil: 0\n---\n\n\ diff --git a/crates/runvil-internal/runtime/src/execute/tests/tasks.rs b/crates/runvil-internal/runtime/src/execute/tests/tasks.rs index 4b4052ae3..8a2c8b6cb 100644 --- a/crates/runvil-internal/runtime/src/execute/tests/tasks.rs +++ b/crates/runvil-internal/runtime/src/execute/tests/tasks.rs @@ -306,7 +306,7 @@ fn spawn_shares_calls_depth_cap() { ```\n"; // Every spawner parks on a store write after spawning, so whether a // spawner resumes before or after its child ends depends on the order - // the writes are answered in: the run ends `done` or `make_tasks_live_error`. + // the writes are answered in: the run ends `done` or the `tasks_live` code. // Either way the whole spawn cascade and the one refusal ran before // any answer arrived, which is what this test measures. let rig = Rig::run(scheduler_scenario(md)); diff --git a/crates/runvil-internal/runtime/src/execute/tests/timeouts.rs b/crates/runvil-internal/runtime/src/execute/tests/timeouts.rs index 4a2b15c2b..7d53beb49 100644 --- a/crates/runvil-internal/runtime/src/execute/tests/timeouts.rs +++ b/crates/runvil-internal/runtime/src/execute/tests/timeouts.rs @@ -1,6 +1,6 @@ //! Timeouts on the wait shims: `opts.timeout` on `tasks.join_any` returns //! `nil` when the internal timer wins and the members keep running (no -//! `make_tasks_live_error` at chain end); on `tasks.join` it returns `results, +//! the `tasks_live` code at chain end); on `tasks.join` it returns `results, //! timed_out` with the unfinished members absent. When a member wins the //! shim cancels the timer and its leaf work is dropped. The timer is an //! effect-backed entry the author never sees: `tasks.pending` and a status diff --git a/crates/runvil-internal/runtime/src/execute/tests/waits.rs b/crates/runvil-internal/runtime/src/execute/tests/waits.rs index cde0895d6..047780a4f 100644 --- a/crates/runvil-internal/runtime/src/execute/tests/waits.rs +++ b/crates/runvil-internal/runtime/src/execute/tests/waits.rs @@ -4,7 +4,7 @@ //! finished task; `tasks.ready`, `tasks.pending`, `tasks.note`, and //! `tasks.cancel` round-trip; ownership is enforced (`make_task_not_owned_error`, //! with the self exception for `status` and `note`); a delivered task's -//! second wait raises `make_task_consumed_error`; cancel is idempotent and reports +//! second wait raises the `task_consumed` code; cancel is idempotent and reports //! `TaskCanceled` exactly once. use runvil_types::event::Event; @@ -67,7 +67,7 @@ fn join_fills_every_position_of_a_member_named_twice() { // A set naming one task twice: the task is waited on once and its // outcome lands at both positions, so the result sequence has no hole // and `#results` is the input's length; the second wait would have - // raised `make_task_consumed_error` had the shim waited twice. + // raised the `task_consumed` code had the shim waited twice. let md = tasks_prompt( "local a = tasks.spawn('../Alpha')\n\ local b = tasks.spawn('../Beta')\n\ @@ -324,7 +324,7 @@ fn cancel_ends_a_parked_task_idempotently_and_reports_task_canceled_once() { // The child spawns a task of its own and parks on a store write, and // the grandchild parks on one too; the owner cancels the child twice // (the second is a no-op), reads the terminal state, and ends with no - // live task - so no `make_tasks_live_error`. A wait on the canceled entry + // live task - so no the `tasks_live` code. A wait on the canceled entry // delivers `ok = false` with a `canceled` error value. The cancel // takes the grandchild with the child: the grandchild started, so it // reports one terminal, which names the abort of its owner and comes diff --git a/crates/runvil-internal/runtime/src/lib.rs b/crates/runvil-internal/runtime/src/lib.rs index f995a7b7a..3ea098c3f 100644 --- a/crates/runvil-internal/runtime/src/lib.rs +++ b/crates/runvil-internal/runtime/src/lib.rs @@ -5,7 +5,8 @@ //! first when the prompt has one. It issues each model round, Pack render, Pack tool call, //! file operation, and timer as an [`Effect`] the //! Harness performs and answers, and reports every boundary as an event -//! returned from `step`. A file operation is a `store` call of the +//! returned from `step` and from `deliver`. A file operation is a `store` +//! call of the //! prompt's Lua, or a request of an open tool call that the caller //! reports with [`Run::request_file`]. A tool call's file request has no //! event: its effect and the answer are its whole report. Other crates diff --git a/crates/runvil-internal/runtime/src/subst.rs b/crates/runvil-internal/runtime/src/subst.rs index 2c89ba457..3a105d706 100644 --- a/crates/runvil-internal/runtime/src/subst.rs +++ b/crates/runvil-internal/runtime/src/subst.rs @@ -115,8 +115,8 @@ pub(crate) struct Sources<'a> { /// /// # Errors /// Returns a `Substitution` failure whose `Reason` fact is one of the -/// reasons `failure` lists, which is the complete list of what a -/// placeholder can fail with. Its message names the reason and the byte +/// reasons `make_failure_error` accepts, which is the complete list of what +/// a placeholder can fail with. Its message names the reason and the byte /// offset of the offending placeholder after a detail with its bounded, /// control-escaped path preview, and a `serialize` message then holds the /// lookup failure. It is placed in the sources' file on the offending diff --git a/crates/runvil-internal/types/src/packs.rs b/crates/runvil-internal/types/src/packs.rs index 46796cb84..013db407a 100644 --- a/crates/runvil-internal/types/src/packs.rs +++ b/crates/runvil-internal/types/src/packs.rs @@ -62,10 +62,10 @@ impl PackId { Ok(PackId(name)) } - /// Builds an identity from the first segment of a validated tool id. + /// Builds an identity from one segment of an already validated name. /// - /// The source tool id was validated at parse, so its first segment is - /// already a valid Pack id. + /// The segment came from a name that passed validation, so it is already + /// a valid Pack id. pub(crate) fn from_segment(segment: &str) -> PackId { PackId(GlobalName::from_validated_segment(segment)) } diff --git a/crates/runvil-internal/vfs/src/handle/access.rs b/crates/runvil-internal/vfs/src/handle/access.rs index 95c9f5ca1..b406ce321 100644 --- a/crates/runvil-internal/vfs/src/handle/access.rs +++ b/crates/runvil-internal/vfs/src/handle/access.rs @@ -1,4 +1,4 @@ -//! The capability's machinery: spawning, joining, and the gate, the +//! The capability's machinery: spawning and the gate, the //! admission, and the event every operation passes through. use std::sync::{Arc, Mutex, MutexGuard, PoisonError}; diff --git a/crates/runvil-internal/vfs/src/handle/scope.rs b/crates/runvil-internal/vfs/src/handle/scope.rs index 6f04abfbd..ef9844052 100644 --- a/crates/runvil-internal/vfs/src/handle/scope.rs +++ b/crates/runvil-internal/vfs/src/handle/scope.rs @@ -287,9 +287,9 @@ impl Scope { } /// Merges `child`'s final clock into `owner`'s: everything the child - /// did is ordered before the owner's next step. A missing identity is - /// a join after the scope purged it, when no live access could still - /// join, so it merges nothing. + /// did is ordered before the owner's next step. An identity this scope + /// never registered, such as a timer's or another scope's, merges + /// nothing, and a live child contributes the clock it has reached so far. pub(super) fn join(&self, owner: ExecId, child: ExecId) { self.lock().merge(owner, child); } diff --git a/crates/runvil-internal/vfs/src/traits.rs b/crates/runvil-internal/vfs/src/traits.rs index 88cd57130..fd8e6d312 100644 --- a/crates/runvil-internal/vfs/src/traits.rs +++ b/crates/runvil-internal/vfs/src/traits.rs @@ -2,7 +2,8 @@ //! //! `Vfs` is one backend behind the virtual namespace; `VfsAccess` is one //! identity's session with it and declares every filesystem operation. -//! `Policy` is the per-handle hook consulted before the claims check, and +//! `Policy` is the per-handle hook consulted before an operation is +//! admitted, and //! `ExecId` is the identity every operation is attributed to. mod backend; diff --git a/crates/runvil-internal/vfs/src/traits/backend.rs b/crates/runvil-internal/vfs/src/traits/backend.rs index fde39ce9f..362e52c7b 100644 --- a/crates/runvil-internal/vfs/src/traits/backend.rs +++ b/crates/runvil-internal/vfs/src/traits/backend.rs @@ -52,8 +52,7 @@ pub trait Vfs: Send { /// /// Every operation on a session is attributed to the identity it was /// acquired for. Storage is reachable only through a session. Paths -/// arrive validated, canonicalized, and interned, so a backend uses -/// them as given. +/// arrive validated and canonicalized, so a backend uses them as given. pub trait VfsAccess: Send { /// Reads the file at `path` as stored. /// @@ -129,7 +128,15 @@ pub trait VfsAccess: Send { /// Returns stored paths matching `pattern`, sorted. /// - /// The root is not a stored path, so no pattern matches it. + /// Every result is an absolute canonical virtual path. The root is not a + /// stored path, so no pattern matches it. + /// + /// The grammar is one that a hostile pattern cannot be used to exhaust: + /// the pattern is at most 1024 bytes, backslashes and control characters + /// are refused, and the wildcards are `*`, which matches within one path + /// segment, and `**`, which must occupy a whole segment (`**`, `**/...`, + /// `.../**`, or `.../**/...`). Each refusal names the rule the pattern + /// broke. /// /// # Errors /// diff --git a/crates/runvil-internal/vfs/src/traits/identity.rs b/crates/runvil-internal/vfs/src/traits/identity.rs index 232a11ff8..78d20dabb 100644 --- a/crates/runvil-internal/vfs/src/traits/identity.rs +++ b/crates/runvil-internal/vfs/src/traits/identity.rs @@ -27,7 +27,8 @@ impl ExecId { /// The context that [`Vfs::acquire`](crate::Vfs::acquire) receives: the /// identity being acquired and the scope it belongs to. /// -/// A `VfsRef` or one of its `Access` capabilities builds each context. +/// A `VfsRef`, one of its `Access` capabilities, or a `Store` making a view +/// builds each context. /// A backend that wraps another [`Vfs`](crate::Vfs) must pass it the /// context exactly as received. A wrapped `VfsRef` then joins the outer /// session's scope, so one scope orders the identities of both.