diff --git a/src/browser/mod.rs b/src/browser/mod.rs index d921d316f2..66e1c66393 100644 --- a/src/browser/mod.rs +++ b/src/browser/mod.rs @@ -154,9 +154,10 @@ impl Db { )); } - /// Reserve the durability boundary synchronously, before a commit's JS - /// promise body is deferred. Barriers always resolve: each operation - /// reports its own error, with no unhandled predecessor rejection. + /// Reserve the flush's place in the IndexedDB sequence synchronously, + /// before returning the JavaScript promise that does the work. Internal + /// barriers resolve even on failure, so an earlier flush cannot cause an + /// unhandled promise rejection. Each operation reports its own error. fn flush(self: &Rc, work: FlushWork) -> js_sys::Promise { let idb = self .borrow() @@ -477,7 +478,7 @@ impl BrowserDb { /// transact/retract calls reject with `[STG-046]` without changing memory. /// Queries and rules remain available; close and reopen to recover. /// - /// Returns a `Promise` in JavaScript. The JSON shape is: + /// Returns a `Promise` in JavaScript. The string contains one of these JSON results: /// - Query: `{"variables": [...], "results": [[...], ...]}` /// - Transact: `{"transacted": }` /// - Retract: `{"retracted": }` @@ -572,9 +573,10 @@ impl BrowserDb { /// Flush all dirty pages to IndexedDB. /// - /// Waits for every IndexedDB write applied before this call, even if it - /// has no pages of its own. Later writes are outside this boundary. Its - /// own flush failure is `[STG-048]`; an earlier failed flush is `[STG-046]`. + /// Waits for every IndexedDB write applied before this call, even if this + /// checkpoint has no pages to flush. It does not wait for later writes. + /// If this call's flush fails, it returns + /// `[STG-048]`. If an earlier flush failed, it returns `[STG-046]`. /// Close and reopen to recover. With no earlier work or dirty pages it /// resolves immediately. In memory and OPFS every commit is already stored. pub async fn checkpoint(&self) -> Result<(), JsValue> { @@ -677,8 +679,8 @@ impl BrowserDb { .filter(|id| !new_ids.contains(id)) .collect() }); - // Preserve the existing memory contract: an import becomes - // visible before its flush. Failure belongs to Db, not this pfs. + // Make the imported data visible in memory before flushing it. + // Record a flush failure on Db, not on the replacement storage. inner.fact_storage = new_pfs.storage().clone(); inner.pfs = new_pfs; inner.withheld.clear(); @@ -979,12 +981,14 @@ fn commit_stamped( /// while open, discards them. After either, the transaction is finished: /// `execute`, `incomingRefs` and `commit` fail with `[API-018]`, and `rollback` /// does nothing. Calls back into this transaction from a user function of its -/// own statement fail with `[INT-001]` before lifecycle or argument checks. +/// own statement fail with `[INT-001]` before checking whether the transaction +/// has finished or validating arguments. /// -/// `incomingRefs(target, maxLinks, maxRecords)` synchronously returns a plain -/// object discriminated by `status`: complete links or an exhausted budget, -/// never a partial list. It reads earlier statements without staging writes, -/// taking a `tx_count` or starting a flush, even after a failed IndexedDB flush. +/// `incomingRefs(target, maxLinks, maxRecords)` returns a plain object, not a +/// promise. Check its `status` to tell whether it contains the complete list or +/// a limit was reached. It never returns a partial list. It reads earlier +/// statements without staging writes, taking a `tx_count`, or starting a flush, +/// even after a failed IndexedDB flush. #[wasm_bindgen] pub struct BrowserWriteTransaction { db: Rc, @@ -1227,7 +1231,8 @@ fn tx_execute( } } -/// Validate before applying. Empty staging still has a durability boundary. +/// Validate staged facts before applying them. With no facts, return empty +/// flush work so the caller can still wait for earlier IndexedDB writes. fn tx_commit(inner: &mut BrowserDbInner, staged: crate::db::Staged) -> Result { let facts = staged.pending_facts; if facts.is_empty() { diff --git a/src/error.rs b/src/error.rs index 9fa59c9b2d..bd01b7ca2b 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,4 +1,4 @@ -//! Structured runtime error codes surfaced through `MinigrafError`. +//! Runtime error codes returned in `MinigrafError`. //! //! See `docs/superpowers/specs/2026-08-25-structured-error-codes-design.md` //! and `docs/ERROR_REFERENCE.md` for the design and the full code registry. @@ -346,7 +346,7 @@ pub(crate) enum ErrorCode { Int056, } -/// Single source of truth: (code, code string, message template, category). +/// The canonical list of error codes, display strings, message templates, and categories. /// /// The message template is verified against `docs/ERROR_REFERENCE.md`'s /// "Error text" lines by the sync test in this module. @@ -2079,26 +2079,19 @@ pub(crate) fn format_template(template: &str, args: &[&dyn fmt::Display]) -> Str /// An `anyhow`-compatible error carrying a compile-time-checked [`ErrorCode`]. /// -/// Built exclusively through [`bail_coded!`]/[`err_coded!`] and wrapped as an -/// `anyhow::Error`, so it rides through the crate's existing `anyhow::Result` -/// plumbing (`?`, `.context()`) unchanged. Recovered at the public API -/// boundary by [`MinigrafError::from`]`(anyhow::Error)` walking the error -/// chain for the first `CodedError` via `downcast_ref`. +/// Only [`bail_coded!`] and [`err_coded!`] build this error. They wrap it in +/// `anyhow::Error`, so `?` and `.context()` still work. At the public API, +/// [`MinigrafError::from`] uses `downcast_ref` to find the first `CodedError` +/// in the error chain. pub(crate) struct CodedError { code: ErrorCode, message: String, } impl CodedError { - /// `#[cold]`/`#[inline(never)]`: `bail_coded!`/`err_coded!` expand to a - /// call to this at every one of the (roughly 300, now that #277's six - /// category PRs have all landed) error call sites across the crate. - /// Error construction is by definition the cold path, so forcing - /// it out of line keeps the lookup + `format_template` call from being - /// duplicated inline at each one — pure binary-size cost for a path - /// that, unlike the argument-array construction immediately at the call - /// site (which still inlines, and is cheap), has no per-call-site - /// specialization to gain from inlining. + /// Keep the registry lookup and message formatting out of line so all + /// error sites share the same code. Each site still builds its own small + /// argument array. #[cold] #[inline(never)] pub(crate) fn new(code: ErrorCode, args: &[&dyn fmt::Display]) -> Self { diff --git a/src/lib.rs b/src/lib.rs index a2f0fdc4fd..98da7e10d1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -161,10 +161,10 @@ pub fn __input_order(on: bool) -> InputOrderGuard { query::engine::set_input_order(on) } -/// This thread's path events since the last call, which clears them: how -/// often queries took the paths the nightly acceptance tests guard (#863), -/// such as `ancestor_alternative_selected` and `bound_value_avet_range`. -/// Only for tests; built with the `test-hooks` feature only. +/// Return and reset this thread's query event counts. Nightly tests use them +/// to check which execution strategies ran (#863), such as +/// `ancestor_alternative_selected` and `bound_value_avet_range`. +/// For tests only. Requires the `test-hooks` feature. #[cfg(feature = "test-hooks")] #[doc(hidden)] pub fn __path_events() -> std::collections::BTreeMap<&'static str, u64> {