Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
refactor(renderer): identify document runtime incarnations exactly
ldm09925bb12f32f
diff --git a/moli-renderer-v8/src/document_runtime.rs b/moli-renderer-v8/src/document_runtime.rsindex ae0cff78d..1d18b3030 100644--- a/moli-renderer-v8/src/document_runtime.rs+++ b/moli-renderer-v8/src/document_runtime.rs@@ -517,15 +517,52 @@ impl std::fmt::Debug for StylesheetLifecycleState {}}-#[derive(Debug, Clone, Copy, PartialEq, Eq)]-struct ParserStepGenerationGuard {- runtime_reset_generation: u64,+#[derive(Clone)]+enum DocumentRuntimeIncarnationIdentity {+ MainFrame(FrameDocumentTaskOwner),+ Standalone(Arc<()>),+}++impl DocumentRuntimeIncarnationIdentity {+ fn standalone() -> Self {+ Self::Standalone(Arc::new(()))+ }+}++impl std::fmt::Debug for DocumentRuntimeIncarnationIdentity {+ fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {+ match self {+ Self::MainFrame(owner) => formatter.debug_tuple("MainFrame").field(owner).finish(),+ Self::Standalone(token) => formatter+ .debug_tuple("Standalone")+ .field(&Arc::as_ptr(token))+ .finish(),+ }+ }+}++impl PartialEq for DocumentRuntimeIncarnationIdentity {+ fn eq(&self, other: &Self) -> bool {+ match (self, other) {+ (Self::MainFrame(left), Self::MainFrame(right)) => left == right,+ (Self::Standalone(left), Self::Standalone(right)) => Arc::ptr_eq(left, right),+ (Self::MainFrame(_), Self::Standalone(_))+ | (Self::Standalone(_), Self::MainFrame(_)) => false,+ }+ }+}++impl Eq for DocumentRuntimeIncarnationIdentity {}++#[derive(Debug, Clone, PartialEq, Eq)]+struct ParserStepOwnerGuard {+ document_incarnation: DocumentRuntimeIncarnationIdentity,depth: usize,}#[derive(Debug, Default)]struct ParserReentryState {- active_step_generation_guard: Option<ParserStepGenerationGuard>,+ active_step_owner_guard: Option<ParserStepOwnerGuard>,custom_element_reaction_queue_active: bool,// Counts nested synchronous parser-blocking script execution scopes,// including load/error completion dispatched before parser resume. This@@ -681,8 +718,8 @@ pub(super) struct DocumentRuntime {script_execution_control: crate::script_execution_control::RendererScriptExecutionControl,bypass_content_security_policy: bool,policy_container: DocumentPolicyContainer,- delivered_meta_content_security_policies: RefCell<HashMap<(u64, DomHandle), Vec<String>>>,- processed_meta_content_security_policy_handles: RefCell<HashSet<(u64, DomHandle, DomHandle)>>,+ delivered_meta_content_security_policies: RefCell<HashMap<DomHandle, Vec<String>>>,+ processed_meta_content_security_policy_handles: RefCell<HashSet<(DomHandle, DomHandle)>>,document_character_set: String,resource_loader_binding: Option<DocumentResourceLoaderBinding>,script_context_stack: Vec<CurrentScriptContext>,@@ -712,7 +749,7 @@ pub(super) struct DocumentRuntime {custom_element_reaction_depth: usize,structural_mutation_depth: usize,dom_content_loaded_dispatched: bool,- runtime_reset_generation: u64,+ document_incarnation: DocumentRuntimeIncarnationIdentity,document_input_stream_opened: bool,next_document_write_external_script_load_id: u64,document_write_script_preload_scanner:@@ -804,16 +841,20 @@ impl DocumentRuntime {}#[cfg(test)]- pub(crate) fn active_parser_step_generation(&self) -> Option<u64> {+ fn active_parser_step_document_incarnation(+ &self,+ ) -> Option<DocumentRuntimeIncarnationIdentity> {self.parser_reentry- .active_step_generation_guard- .map(|guard| guard.runtime_reset_generation)+ .active_step_owner_guard+ .as_ref()+ .map(|guard| guard.document_incarnation.clone())}#[cfg(test)]pub(crate) fn active_parser_step_depth(&self) -> Option<usize> {self.parser_reentry- .active_step_generation_guard+ .active_step_owner_guard+ .as_ref().map(|guard| guard.depth)}@@ -914,7 +955,7 @@ impl DocumentRuntime {/// Runs a synchronous parser step against the runtime-owned live DOM.///- /// This keeps the active generation/depth guard owned by `DocumentRuntime`+ /// This keeps the active Document-owner/depth guard owned by `DocumentRuntime`/// and guarantees the guard is released when the step returns or unwinds.#[track_caller]pub(crate) fn with_dom_host_parse_step<R>(&mut self, step: impl FnOnce(&mut Self) -> R) -> R {@@ -935,17 +976,17 @@ impl DocumentRuntime {/// Starts one synchronous parser step against the runtime-owned live DOM.///- /// Parser sinks do not receive this generation identity. They call back into+ /// Parser sinks do not receive this owner identity. They call back into/// `DocumentRuntime`, and each callback short-borrows the current DomHost- /// after this runtime-private active step guard rejects stale document- /// replacement generation changes.+ /// after this runtime-private active step guard rejects a replaced+ /// Document incarnation.#[track_caller]pub(crate) fn begin_dom_host_parse_step(&mut self) {- let generation = self.runtime_reset_generation;- if let Some(active) = self.parser_reentry.active_step_generation_guard.as_mut() {+ let document_incarnation = self.document_incarnation.clone();+ if let Some(active) = self.parser_reentry.active_step_owner_guard.as_mut() {assert_eq!(- active.runtime_reset_generation, generation,- "nested parser steps must target the current document generation"+ active.document_incarnation, document_incarnation,+ "nested parser steps must target the current Document incarnation");active.depth = active.depth@@ -953,8 +994,8 @@ impl DocumentRuntime {.expect("parser step depth overflow");return;}- self.parser_reentry.active_step_generation_guard = Some(ParserStepGenerationGuard {- runtime_reset_generation: generation,+ self.parser_reentry.active_step_owner_guard = Some(ParserStepOwnerGuard {+ document_incarnation,depth: 1,});}@@ -964,7 +1005,7 @@ impl DocumentRuntime {pub(crate) fn finish_dom_host_parse_step(&mut self) {let guard = self.parser_reentry- .active_step_generation_guard+ .active_step_owner_guard.as_mut().expect("parser step must be active before finishing");assert!(@@ -973,25 +1014,26 @@ impl DocumentRuntime {);guard.depth -= 1;if guard.depth == 0 {- self.parser_reentry.active_step_generation_guard.take();+ self.parser_reentry.active_step_owner_guard.take();}}#[track_caller]- fn assert_active_parser_dom_generation(&self) {+ fn assert_active_parser_document_incarnation(&self) {let active = self.parser_reentry- .active_step_generation_guard+ .active_step_owner_guard+ .as_ref().expect("parser step must be active");assert_eq!(- active.runtime_reset_generation, self.runtime_reset_generation,- "parser step must target the current document generation"+ active.document_incarnation, self.document_incarnation,+ "parser step must target the current Document incarnation");}#[track_caller]fn dom_host_mut_for_active_parser_step(&mut self) -> &mut DomHost {- self.assert_active_parser_dom_generation();+ self.assert_active_parser_document_incarnation();self.dom_host.borrow_mut()}@@ -1073,7 +1115,7 @@ impl DocumentRuntime {parent: DomHandle,child: DomHandle,) -> DomMutationEffects {- self.assert_active_parser_dom_generation();+ self.assert_active_parser_document_incarnation();self.append_child_effects_in_structural_scope(parent, child)}@@ -1084,7 +1126,7 @@ impl DocumentRuntime {child: DomHandle,reference_child: Option<DomHandle>,) -> DomMutationEffects {- self.assert_active_parser_dom_generation();+ self.assert_active_parser_document_incarnation();self.insert_before_effects_in_structural_scope(parent, child, reference_child)}@@ -1094,7 +1136,7 @@ impl DocumentRuntime {parent: DomHandle,child: DomHandle,) -> DomMutationEffects {- self.assert_active_parser_dom_generation();+ self.assert_active_parser_document_incarnation();self.remove_child_effects_in_structural_scope(parent, child)}@@ -1441,7 +1483,7 @@ mod tests {}#[test]- fn parser_runtime_dom_generation_allows_nested_steps_on_same_document_generation() {+ fn parser_runtime_dom_owner_allows_nested_steps_on_same_document_incarnation() {let parser = HtmlParser;let document = parser.parse(Url::parse("https://example.com/").unwrap(),@@ -1450,23 +1492,29 @@ mod tests {let mut runtime = DocumentRuntime::from_document(document);runtime.begin_dom_host_parse_step();- let outer_generation = runtime.active_parser_step_generation();+ let outer_incarnation = runtime.active_parser_step_document_incarnation();runtime.begin_dom_host_parse_step();- assert_eq!(runtime.active_parser_step_generation(), outer_generation);+ assert_eq!(+ runtime.active_parser_step_document_incarnation(),+ outer_incarnation+ );assert_eq!(runtime.active_parser_step_depth(), Some(2));runtime.finish_dom_host_parse_step();- assert_eq!(runtime.active_parser_step_generation(), outer_generation);+ assert_eq!(+ runtime.active_parser_step_document_incarnation(),+ outer_incarnation+ );assert_eq!(runtime.active_parser_step_depth(), Some(1));runtime.finish_dom_host_parse_step();- assert_eq!(runtime.active_parser_step_generation(), None);+ assert_eq!(runtime.active_parser_step_document_incarnation(), None);assert_eq!(runtime.active_parser_step_depth(), None);}#[test]- #[should_panic(expected = "current document generation")]- fn parser_runtime_dom_generation_rejects_document_generation_replacement() {+ #[should_panic(expected = "current Document incarnation")]+ fn parser_runtime_dom_owner_rejects_document_replacement() {let parser = HtmlParser;let document = parser.parse(Url::parse("https://example.com/").unwrap(),diff --git a/moli-renderer-v8/src/document_runtime/dom_facade.rs b/moli-renderer-v8/src/document_runtime/dom_facade.rsindex 1c71eb578..47fb82189 100644--- a/moli-renderer-v8/src/document_runtime/dom_facade.rs+++ b/moli-renderer-v8/src/document_runtime/dom_facade.rs@@ -99,7 +99,7 @@ impl DocumentRuntime {) {let connected_roots = effects.tree().connected_roots().to_vec();let form_owner_effects = effects.clone();- self.assert_active_parser_dom_generation();+ self.assert_active_parser_document_incarnation();let result = {let dom_host = self.dom_host.borrow_mut();apply_runtime_mutation_effects_to_dom_host(diff --git a/moli-renderer-v8/src/document_runtime/lifecycle.rs b/moli-renderer-v8/src/document_runtime/lifecycle.rsindex d6bbf68d7..4203c67e3 100644--- a/moli-renderer-v8/src/document_runtime/lifecycle.rs+++ b/moli-renderer-v8/src/document_runtime/lifecycle.rs@@ -201,6 +201,11 @@ impl DocumentRuntime {}pub(crate) fn open_document(&mut self) {+ // Production runtimes replace this temporary standalone identity with+ // the exact new Frame owner in the surrounding owner transaction.+ // Rotating first invalidates parser work from the retired Document+ // even while that transaction is still being committed.+ self.document_incarnation = DocumentRuntimeIncarnationIdentity::standalone();// Blink's Document::ImplicitOpen removes every current child and leaves// the Document empty. The parser creates html/head/body only when input// is subsequently consumed (or when it is closed with empty input).@@ -243,7 +248,6 @@ impl DocumentRuntime {self.processed_meta_content_security_policy_handles.get_mut().clear();- self.runtime_reset_generation = self.runtime_reset_generation.wrapping_add(1);self.document_input_stream_opened = true;self.set_document_ready_state(DocumentReadyState::Loading);}@@ -274,8 +278,8 @@ impl DocumentRuntime {self.late_preload_stylesheet_handles.clear();}- pub(crate) fn runtime_reset_generation(&self) -> u64 {- self.runtime_reset_generation+ pub(crate) fn bind_main_document_task_owner(&mut self, owner: FrameDocumentTaskOwner) {+ self.document_incarnation = DocumentRuntimeIncarnationIdentity::MainFrame(owner);}pub(crate) fn parser_module_scripts(&self) -> &ModuleScriptContinuationStore {diff --git a/moli-renderer-v8/src/document_runtime/mutation_commands/tree/parser.rs b/moli-renderer-v8/src/document_runtime/mutation_commands/tree/parser.rsindex 811629736..da83dba1c 100644--- a/moli-renderer-v8/src/document_runtime/mutation_commands/tree/parser.rs+++ b/moli-renderer-v8/src/document_runtime/mutation_commands/tree/parser.rs@@ -136,7 +136,7 @@ impl DocumentRuntime {if effects.did_change() {self.apply_node_iterator_pre_remove_plans(host_ptr, &insertion_plan.node_iterator_plan);}- self.assert_active_parser_dom_generation();+ self.assert_active_parser_document_incarnation();let result = {let dom_host = self.dom_host.borrow_mut();apply_runtime_mutation_effects_to_dom_host(@@ -314,7 +314,7 @@ impl DocumentRuntime {let removal_plan = self.tree_removal_plan(scope, host_ptr, parent, child);let effects = self.parser_remove_child_effects_in_structural_scope(parent, child);self.apply_tree_removal_node_iterator_plan_if_changed(host_ptr, &removal_plan, &effects);- self.assert_active_parser_dom_generation();+ self.assert_active_parser_document_incarnation();let result = {let dom_host = self.dom_host.borrow_mut();apply_runtime_mutation_effects_to_dom_host(diff --git a/moli-renderer-v8/src/document_runtime/runtime_core.rs b/moli-renderer-v8/src/document_runtime/runtime_core.rsindex 64953c048..8602d66f9 100644--- a/moli-renderer-v8/src/document_runtime/runtime_core.rs+++ b/moli-renderer-v8/src/document_runtime/runtime_core.rs@@ -82,7 +82,7 @@ impl DocumentRuntime {custom_element_reaction_depth: 0,structural_mutation_depth: 0,dom_content_loaded_dispatched: false,- runtime_reset_generation: 0,+ document_incarnation: DocumentRuntimeIncarnationIdentity::standalone(),document_input_stream_opened: false,next_document_write_external_script_load_id: 0,document_write_script_preload_scanner: None,@@ -202,7 +202,7 @@ impl DocumentRuntime {custom_element_reaction_depth: _,structural_mutation_depth: _,dom_content_loaded_dispatched: _,- runtime_reset_generation: _,+ document_incarnation: _,document_input_stream_opened: _,next_document_write_external_script_load_id: _,document_write_script_preload_scanner: _,diff --git a/moli-renderer-v8/src/document_runtime/security_policy.rs b/moli-renderer-v8/src/document_runtime/security_policy.rsindex a49a8a18e..87c97944b 100644--- a/moli-renderer-v8/src/document_runtime/security_policy.rs+++ b/moli-renderer-v8/src/document_runtime/security_policy.rs@@ -1662,7 +1662,7 @@ impl DocumentRuntime {}self.delivered_meta_content_security_policies.borrow()- .get(&(self.runtime_reset_generation, document_handle))+ .get(&document_handle).cloned().unwrap_or_default()}@@ -1701,11 +1701,10 @@ impl DocumentRuntime {.filter(|content| !content.is_empty()).map(str::to_owned)};- let generation = self.runtime_reset_generation;if !self.processed_meta_content_security_policy_handles.borrow_mut()- .insert((generation, document_handle, handle))+ .insert((document_handle, handle))|| self.bypass_content_security_policy{return;@@ -1713,7 +1712,7 @@ impl DocumentRuntime {if let Some(policy) = policy {self.delivered_meta_content_security_policies.borrow_mut()- .entry((generation, document_handle))+ .entry(document_handle).or_default().push(policy);}diff --git a/moli-renderer-v8/src/module_runtime/modulator.rs b/moli-renderer-v8/src/module_runtime/modulator.rsindex 16ee3f031..ee9d8e39b 100644--- a/moli-renderer-v8/src/module_runtime/modulator.rs+++ b/moli-renderer-v8/src/module_runtime/modulator.rs@@ -90,7 +90,7 @@ impl NativeDocumentModulator {/// Chromium's `Modulator::From(ScriptState*)` stores the module map and/// dynamic resolver in per-context data. `Document::open()` creates a new/// parser but returns the same Document and keeps that ScriptState alive.- /// Moli rotates an internal Document generation, so this explicit+ /// Moli installs a new exact Document owner, so this explicit/// split prevents that implementation detail from canceling `import()`.pub(crate) fn clear_for_document_replacement(&mut self) {self.corediff --git a/moli-renderer-v8/src/native_bridge/context_host/child_dynamic_scripts.rs b/moli-renderer-v8/src/native_bridge/context_host/child_dynamic_scripts.rsindex cacd60283..242c0dbbc 100644--- a/moli-renderer-v8/src/native_bridge/context_host/child_dynamic_scripts.rs+++ b/moli-renderer-v8/src/native_bridge/context_host/child_dynamic_scripts.rs@@ -31,7 +31,7 @@ impl JsContextHost {else {return Ok(false);};- // Frame-document scheduling owns ordering and document generations.+ // Frame-document scheduling owns ordering and exact Document identities.// This load payload is intentionally unbound to the main scheduler.let script = build_runtime_prepared_script(preparation,diff --git a/moli-renderer-v8/src/native_bridge/context_host/core.rs b/moli-renderer-v8/src/native_bridge/context_host/core.rsindex 5f027e646..73d4520cc 100644--- a/moli-renderer-v8/src/native_bridge/context_host/core.rs+++ b/moli-renderer-v8/src/native_bridge/context_host/core.rs@@ -179,6 +179,7 @@ impl JsContextHost {main_owner_snapshot.local_window_id,main_owner_snapshot.document_id,);+ runtime.bind_main_document_task_owner(main_document_owner);let service_worker_storage_key = top_level_storage_key.as_ref().map(moli_storage_key::MoliStorageKey::serialized_storage_key)@@ -533,6 +534,7 @@ impl JsContextHost {.expect("main document owner must exist before document.open() replacement");{let runtime: &mut DocumentRuntime = self;+ runtime.bind_main_document_task_owner(transition.current_owner());runtime.start_root_document_parser_stream();}self.dom_agent_statediff --git a/moli-renderer-v8/src/native_bridge/context_host/host_environment.rs b/moli-renderer-v8/src/native_bridge/context_host/host_environment.rsindex c6ac3a094..da36c136d 100644--- a/moli-renderer-v8/src/native_bridge/context_host/host_environment.rs+++ b/moli-renderer-v8/src/native_bridge/context_host/host_environment.rs@@ -583,7 +583,7 @@ impl JsContextHost {/// Replaces a Document authority while preserving its LocalWindow loads.///- /// `document.open()` rotates Moli's internal Document generation but+ /// `document.open()` replaces Moli's exact Document owner but/// does not abort an otherwise non-navigating Document's active Fetch,/// XHR, image, or WebSocket work. Existing leases move to the replacement/// lifecycle registry while retaining their captured request clients anddiff --git a/moli-renderer-v8/src/native_bridge/context_host/workers.rs b/moli-renderer-v8/src/native_bridge/context_host/workers.rsindex 83269a56c..e5bc051f5 100644--- a/moli-renderer-v8/src/native_bridge/context_host/workers.rs+++ b/moli-renderer-v8/src/native_bridge/context_host/workers.rs@@ -20,7 +20,7 @@ pub(super) enum WorkerExecutionState {/// when `new Worker()` starts.////// Besides freezing the request client, the lease binds cancellation- /// and task execution to that Document generation. Completion may run+ /// and task execution to that exact Document. Completion may run/// after navigation, but can never rebind to the then-current main/// Document.outside_settings_load: crate::network::loads::ResourceLoadLease,diff --git a/moli-renderer-v8/src/network/context/document.rs b/moli-renderer-v8/src/network/context/document.rsindex e106bc875..3d0419e66 100644--- a/moli-renderer-v8/src/network/context/document.rs+++ b/moli-renderer-v8/src/network/context/document.rs@@ -61,11 +61,11 @@ impl Drop for DocumentResourceLoaderAuthority {}}-/// Resource loading authority for one committed Document generation.+/// Resource loading authority for one exact committed Document.////// Clones share the authority/lifecycle and are safe to retain in asynchronous/// work. Replacing the transport backend preserves that same authority; a new-/// Document generation must instead call [`Self::fork_for_document`].+/// Document must instead call [`Self::fork_for_document`].#[derive(Clone)]pub struct DocumentResourceLoader {request_client: ResourceRequestClient,@@ -100,7 +100,7 @@ impl DocumentResourceLoaderBootstrap {}}-/// Exact backend source selected when a new Document generation commits.+/// Exact backend source selected when a new Document commits.////// Network navigations must transfer their attempt-local seed. Synthetic/// Documents such as initial `about:blank` and `srcdoc` must instead name thediff --git a/moli-renderer-v8/src/network/context/registry.rs b/moli-renderer-v8/src/network/context/registry.rsindex aba0250ab..3bb4e0f5e 100644--- a/moli-renderer-v8/src/network/context/registry.rs+++ b/moli-renderer-v8/src/network/context/registry.rs@@ -8,7 +8,7 @@ use super::DocumentResourceLoader;////// It is intentionally separate from the shared browser resource runtime: a/// frame handle may be reused after navigation, while the full-/// `FrameDocumentTaskOwner` includes the non-reused Document generation.+/// `FrameDocumentTaskOwner` includes the non-reused Document identity.#[derive(Clone, Debug, Default)]pub(crate) struct DocumentResourceLoaderRegistry {loaders: Rc<RefCell<HashMap<WindowDocumentOwner, DocumentResourceLoader>>>,diff --git a/moli-renderer-v8/src/network/context/request_context.rs b/moli-renderer-v8/src/network/context/request_context.rsindex 96a799671..5f679c25a 100644--- a/moli-renderer-v8/src/network/context/request_context.rs+++ b/moli-renderer-v8/src/network/context/request_context.rs@@ -2,7 +2,7 @@ use url::Url;use crate::native_bridge::WindowDocumentOwner;-/// Request settings captured for one exact committed Document generation.+/// Request settings captured for one exact committed Document.#[derive(Clone, Debug)]pub(crate) struct DocumentFetchContext {owner: WindowDocumentOwner,diff --git a/moli-renderer-v8/src/network/loads/registry.rs b/moli-renderer-v8/src/network/loads/registry.rsindex 19d111f80..61d2efd86 100644--- a/moli-renderer-v8/src/network/loads/registry.rs+++ b/moli-renderer-v8/src/network/loads/registry.rs@@ -223,7 +223,7 @@ impl ResourceLoadRegistry {/// Seals this registry and transfers its existing loads to a replacement/// Document authority without changing their captured request policy.///- /// `document.open()` replaces Moli's internal Document generation+ /// `document.open()` replaces Moli's exact Document owner/// while preserving the LocalWindow and its active fetch group. New loads/// must use the replacement Document's policy, but already-started Fetch,/// XHR, image, and WebSocket work must remain cancellable with that samediff --git a/moli-renderer-v8/src/page_task_queue/opfs_task.rs b/moli-renderer-v8/src/page_task_queue/opfs_task.rsindex 0ab514519..4b7363ccd 100644--- a/moli-renderer-v8/src/page_task_queue/opfs_task.rs+++ b/moli-renderer-v8/src/page_task_queue/opfs_task.rs@@ -13,7 +13,7 @@ use super::RendererOwnerWakeSender;////// The id is never reused within a PageVm. The root Page and Window-realm/// identities live in [`RendererPageOpfsTaskOwner`], so `document.open()` can-/// preserve Window-owned work without projecting a Document generation into+/// preserve Window-owned work without projecting a Document identity into/// the task identity.#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]pub(crate) struct RendererPageOpfsTaskId(u64);diff --git a/moli-renderer-v8/src/page_task_queue/service_worker_client_message.rs b/moli-renderer-v8/src/page_task_queue/service_worker_client_message.rsindex ef54d9f4b..7d36104d6 100644--- a/moli-renderer-v8/src/page_task_queue/service_worker_client_message.rs+++ b/moli-renderer-v8/src/page_task_queue/service_worker_client_message.rs@@ -215,7 +215,7 @@ pub(crate) enum PageServiceWorkerClientMessageTargetEffect {/// dispatchable event. The selected task still owns its normal/// checkpoint, without callback reconciliation.CurrentTargetProducedNoDispatchableEvent,- /// The target's client/document generation was no longer current.+ /// The target's exact client/Document identity was no longer current.DiscardedStaleTarget,/// The Page task belonged to a retired root Document and may not inspect/// or modify a same-id client in the replacement PageVm.diff --git a/moli-renderer-v8/src/page_task_queue/v8_foreground_task.rs b/moli-renderer-v8/src/page_task_queue/v8_foreground_task.rsindex 2c5e5c82c..4258619bb 100644--- a/moli-renderer-v8/src/page_task_queue/v8_foreground_task.rs+++ b/moli-renderer-v8/src/page_task_queue/v8_foreground_task.rs@@ -10,7 +10,7 @@ use super::RendererOwnerWakeSender;/// Stable Page owner of a V8 foreground task.////// Foreground work belongs to the Page-lifetime isolate rather than to one-/// Document generation. `V8ForegroundTask` itself retains the exact isolate+/// Document incarnation. `V8ForegroundTask` itself retains the exact isolate/// registration generation, so a task transferred before isolate retirement/// becomes a no-op instead of entering a reused isolate.#[derive(Clone, Copy, Debug, Eq, PartialEq)]diff --git a/moli-renderer-v8/src/page_task_queue/webcrypto_task.rs b/moli-renderer-v8/src/page_task_queue/webcrypto_task.rsindex 6590af82f..25dbc4f4a 100644--- a/moli-renderer-v8/src/page_task_queue/webcrypto_task.rs+++ b/moli-renderer-v8/src/page_task_queue/webcrypto_task.rs@@ -13,7 +13,7 @@ use super::RendererOwnerWakeSender;////// The id is never reused within a PageVm. The enclosing task owner carries/// the root Page and Window-realm identities, so `document.open()` can preserve-/// Window-owned WebCrypto work without projecting a Document generation into+/// Window-owned WebCrypto work without projecting a Document identity into/// the task identity.#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]pub(crate) struct RendererPageWebCryptoTaskId(u64);diff --git a/moli-renderer-v8/src/runtime/page_vm/page_parser_owned_module_continuation.rs b/moli-renderer-v8/src/runtime/page_vm/page_parser_owned_module_continuation.rsindex eaab336f9..697014d06 100644--- a/moli-renderer-v8/src/runtime/page_vm/page_parser_owned_module_continuation.rs+++ b/moli-renderer-v8/src/runtime/page_vm/page_parser_owned_module_continuation.rs@@ -73,7 +73,6 @@ impl PageVm {tracing::debug!(?selected_owner,current_document_owner = ?self.vm().current_main_document_task_owner(),- current_runtime_generation = self.vm().document_runtime.runtime_reset_generation(),"completed selected parser-owned module continuation");Ok(())diff --git a/moli-renderer-v8/src/runtime/page_vm/tests/main_dynamic_import_completion.rs b/moli-renderer-v8/src/runtime/page_vm/tests/main_dynamic_import_completion.rsindex 0dc05ada5..46bc4417e 100644--- a/moli-renderer-v8/src/runtime/page_vm/tests/main_dynamic_import_completion.rs+++ b/moli-renderer-v8/src/runtime/page_vm/tests/main_dynamic_import_completion.rs@@ -636,7 +636,7 @@ async fn document_open_preserves_inflight_dynamic_import_in_the_same_script_stat.vm().current_main_dynamic_import_graph_fetch_target(target.load_id()),Some(target),- "rotating Moli's Document generation must not make the same-realm import stale"+ "replacing Moli's exact Document owner must not make the same-realm import stale");assert_eq!(original_loader.state(),diff --git a/moli-renderer-v8/src/script_vm/post_parse_lifecycle.rs b/moli-renderer-v8/src/script_vm/post_parse_lifecycle.rsindex 7ac6f1a94..2a6104914 100644--- a/moli-renderer-v8/src/script_vm/post_parse_lifecycle.rs+++ b/moli-renderer-v8/src/script_vm/post_parse_lifecycle.rs@@ -561,7 +561,7 @@ impl ScriptVm {self.enqueue_runtime_script_signal_if_needed();}- async fn flush_pending_runtime_script_work_until_generation_stable(+ async fn flush_pending_runtime_script_work_until_document_owner_stable(&mut self,loader: &ResourceRequestClient,initial_wait_for_dynamic_loads: bool,@@ -570,7 +570,7 @@ impl ScriptVm {) -> std::result::Result<RuntimePendingWorkFlushOutcome, String> {let mut wait_for_dynamic_loads = initial_wait_for_dynamic_loads;loop {- let generation_before = self.document_runtime.runtime_reset_generation();+ let document_owner_before = self.current_main_document_task_owner();let outcome = self.flush_pending_work_with_turn_budget(loader,@@ -578,7 +578,7 @@ impl ScriptVm {yield_after_one_runnable,).await?;- if self.document_runtime.runtime_reset_generation() != generation_before {+ if self.current_main_document_task_owner() != document_owner_before {// A script replaced the Document while this bounded flush was// running. Reconcile the new exact runtime owner before// publishing an outcome for the post-parse caller.@@ -1895,7 +1895,7 @@ impl ScriptVm {{self.resume_runtime_script_work_after_deferred_page_tasks();match self- .flush_pending_runtime_script_work_until_generation_stable(+ .flush_pending_runtime_script_work_until_document_owner_stable(loader, true, false, None,).await?diff --git a/moli-renderer-v8/src/script_vm/subresource_fetch.rs b/moli-renderer-v8/src/script_vm/subresource_fetch.rsindex abd9ca7b3..a7d4b5274 100644--- a/moli-renderer-v8/src/script_vm/subresource_fetch.rs+++ b/moli-renderer-v8/src/script_vm/subresource_fetch.rs@@ -1398,7 +1398,7 @@ impl ScriptVm {// Request interception may resume after the initiating Document has// navigated. The lease retains the request-time frozen client; looking// up the ambient Page loader here would silently rebind policy/backend- // to a newer Document generation.+ // to a newer Document identity.let loader = pending.load.request_client();let mut request = moli_fetch::Request::new(&request_method,diff --git a/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rs b/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rsindex 971788650..8af70175c 100644--- a/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rs+++ b/moli-renderer-v8/src/script_vm/tests/browser_api/misc.rs@@ -20131,7 +20131,7 @@ async fn navigator_service_worker_window_client_navigate_rejects_when_overwritte}#[tokio::test]-async fn service_worker_window_client_owner_requests_reject_on_stale_page_generation() {+async fn service_worker_window_client_owner_requests_reject_on_stale_document_owner() {let (base_url, server) = spawn_service_worker_response_server(vec![("/app/worker.js","text/javascript; charset=utf-8",@@ -20179,7 +20179,20 @@ async fn service_worker_window_client_owner_requests_reject_on_stale_page_generalet service = browser_context_runtime.service_worker_runtime();assert_eq!(service.pending_service_lane_event_count(), 0);- let stale_generation = vm.document_runtime.runtime_reset_generation() + 1;+ let current_owner = vm+ .current_main_document_task_owner()+ .expect("service worker test page should retain a main Document owner");+ let stale_owner = crate::frame_owner_model::FrameDocumentTaskOwner::new(+ current_owner.scheduler_lane_id,+ current_owner.local_window_id,+ crate::frame_owner_model::DocumentId(+ current_owner+ .document_id+ .0+ .checked_add(1)+ .expect("test Document id should have a successor"),+ ),+ );run_service_worker_client_navigate_request_task_for_test(&mut vm,&loader,@@ -20187,7 +20200,7 @@ async fn service_worker_window_client_owner_requests_reject_on_stale_page_generacrate::types::ServiceWorkerClientNavigateRequestCompletion {target: service_worker_window_client_target_for_test(crate::runtime::ServiceWorkerClientId::from_u64_for_test(1),- crate::native_bridge::WindowDocumentOwner::for_test(stale_generation),+ crate::native_bridge::WindowDocumentOwner::Frame(stale_owner),),request_id: 101,source_version_id: crate::runtime::ServiceWorkerVersionId::from_u64_for_test(1),@@ -20205,7 +20218,7 @@ async fn service_worker_window_client_owner_requests_reject_on_stale_page_generacrate::types::ServiceWorkerClientFocusRequestCompletion {target: service_worker_window_client_target_for_test(crate::runtime::ServiceWorkerClientId::from_u64_for_test(1),- crate::native_bridge::WindowDocumentOwner::for_test(stale_generation),+ crate::native_bridge::WindowDocumentOwner::Frame(stale_owner),),request_id: 102,source_version_id: crate::runtime::ServiceWorkerVersionId::from_u64_for_test(1),@@ -20222,7 +20235,7 @@ async fn service_worker_window_client_owner_requests_reject_on_stale_page_generacrate::types::ServiceWorkerClientsOpenWindowRequestCompletion {host: service_worker_window_client_target_for_test(crate::runtime::ServiceWorkerClientId::from_u64_for_test(1),- crate::native_bridge::WindowDocumentOwner::for_test(stale_generation),+ crate::native_bridge::WindowDocumentOwner::Frame(stale_owner),),request_id: 103,source_version_id: crate::runtime::ServiceWorkerVersionId::from_u64_for_test(1),