Skip to content

armgit / moli

Public Imported from GitHub
0

Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust

refactor(renderer): publish nested prefixes with their retention fences

ldm028e40e52875b
diff --git a/moli-renderer-v8/src/runtime/page_vm/mod.rs b/moli-renderer-v8/src/runtime/page_vm/mod.rs
index aea2654a1..d118f429d 100644
--- a/moli-renderer-v8/src/runtime/page_vm/mod.rs
+++ b/moli-renderer-v8/src/runtime/page_vm/mod.rs
@@ -1797,10 +1797,7 @@ impl PageVm {
self.record_document_title_change_if_needed();
let publication = self.vm_mut().settle_renderer_output_prefix()?;
let journal = self.vm().renderer_command_output_journal();
- let cursor = publication.cursor();
- journal
- .publish_resolved_prefix(publication)
- .then(|| journal.declare_fence(cursor))
+ journal.publish_resolved_prefix_and_declare_fence(publication)
}
fn record_document_title_change_if_needed(&mut self) {
diff --git a/moli-renderer-v8/src/runtime/protocol_output/turn_journal.rs b/moli-renderer-v8/src/runtime/protocol_output/turn_journal.rs
index 7ffd95e83..bdcef157c 100644
--- a/moli-renderer-v8/src/runtime/protocol_output/turn_journal.rs
+++ b/moli-renderer-v8/src/runtime/protocol_output/turn_journal.rs
@@ -205,18 +205,33 @@ impl RendererTurnOutputJournal {
/// Admit a prefix whose cursor was already allocated by
/// `take_pending_for_resolution`. Resolution updates Inspector mirrors
/// outside the journal lock and must not allocate a second cursor.
- pub(crate) fn publish_resolved_prefix(&self, publication: RendererOutputPublication) -> bool {
+ /// Publication and its retention lease share this lock, so retirement
+ /// cannot close the stream between admitting the prefix and its fence.
+ pub(crate) fn publish_resolved_prefix_and_declare_fence(
+ &self,
+ publication: RendererOutputPublication,
+ ) -> Option<RendererOutputFence> {
let mut state = self.state.lock();
- assert_eq!(publication.cursor().stream(), state.stream);
+ let cursor = publication.cursor();
+ assert_eq!(cursor.stream(), state.stream);
if state.closed {
- return false;
+ return None;
}
+ assert!(
+ state
+ .last_published_sequence
+ .is_some_and(|sequence| sequence.get() >= cursor.sequence()),
+ "renderer output fence cannot name an unpublished cursor"
+ );
if let Some(transport) = state.transport.as_ref() {
- publication.publish_to(transport).is_ok()
+ publication.publish_to(transport).ok()?;
} else {
state.deferred_publications.push(publication);
- true
}
+ Some(RendererOutputFence::declare(
+ cursor,
+ state.transport.clone(),
+ ))
}
/// Atomically appends and publishes one already-resolved producer batch.