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): retain the native terminal fence without its covered prefix

ldm064033a0be934
diff --git a/moli-renderer-v8/src/runtime/page_surface.rs b/moli-renderer-v8/src/runtime/page_surface.rs
index 21e045070..8ee7ca72f 100644
--- a/moli-renderer-v8/src/runtime/page_surface.rs
+++ b/moli-renderer-v8/src/runtime/page_surface.rs
@@ -1612,9 +1612,18 @@ impl RendererCommandTurnOutput {
// Settlement has already published this turn's earlier facts.
// Publish the ready reply here, before a later Main command
// can append its output, regardless of adapter waiter polling.
- ready
- .publish(&page_state)?
- .merge_into_same_stream_tail(&mut renderer_output_predecessor);
+ let terminal = ready.publish(&page_state)?;
+ if let Some(prefix) = &renderer_output_predecessor {
+ assert_eq!(
+ terminal.cursor(),
+ terminal.cursor().latest_in_same_stream(prefix.cursor()),
+ "native terminal must cover its settled output prefix",
+ );
+ }
+ // The terminal lease is declared before the covered prefix
+ // is released. Only this final boundary leaves the renderer;
+ // typed/composite replies still retain independent leases.
+ renderer_output_predecessor = Some(terminal);
RendererPageReply::NativeCommandPublished
}
reply => reply,
diff --git a/moli-renderer-v8/src/runtime/tests/extracted/runtime_scripts.rs b/moli-renderer-v8/src/runtime/tests/extracted/runtime_scripts.rs
index 5a7feafd1..7804beea7 100644
--- a/moli-renderer-v8/src/runtime/tests/extracted/runtime_scripts.rs
+++ b/moli-renderer-v8/src/runtime/tests/extracted/runtime_scripts.rs
@@ -2654,6 +2654,11 @@ async fn native_terminals_publish_before_waiters_are_polled() {
renderer_json_value(later.into_reply_and_state().0),
Some(serde_json::json!(42))
);
+ // Retire the stream before polling native waiters or publication receipts.
+ // Already-published replies and their exact fences must survive teardown.
+ page.close_async()
+ .await
+ .expect("close page before consuming native replies");
let terminals = output_rx
.drain()
.into_iter()
@@ -2704,15 +2709,26 @@ async fn native_terminals_publish_before_waiters_are_polled() {
assert!(error.to_string().contains("native response was canceled"));
continue;
}
- let reply = pending
+ let completion = pending
.wait()
.await
- .expect("receive native completion")
- .into_reply_and_state()
+ .expect("receive native completion after page retirement");
+ let terminal_cursor = terminals
+ .iter()
+ .find(|(_, terminal)| terminal.command_id.get() == command_id)
+ .expect("native terminal was published before retirement")
.0;
+ assert_eq!(
+ completion
+ .renderer_output_predecessor()
+ .expect("native terminal fence")
+ .cursor(),
+ terminal_cursor,
+ "retirement must retain the exact committed terminal boundary",
+ );
+ let reply = completion.into_reply_and_state().0;
assert!(matches!(reply, RendererPageReply::NativeCommandPublished));
}
- page.close_async().await.expect("close page");
}
#[tokio::test(flavor = "multi_thread")]