[eric] browser: a composer already on the page needs no model to confirm it

This commit is contained in:
ciregenz
2026-08-04 19:44:44 -07:00
parent 9d1d2b8dbb
commit 7dc5f58651
2 changed files with 33 additions and 0 deletions
@@ -399,6 +399,17 @@ async def run_prestage(
li_text, gt_text, seen_url = await perceive()
p_t_perceive = time.monotonic() - p_t_step
current_url = seen_url or current_url
# TIER 0: the box is already here, so there is nothing to discover and no reason to ask.
# Staged means "a composer is visible", which this perception just answered directly; the
# aux call below can only agree with it, and it costs 1.7-6.5s to do so. That call was
# the whole cost of a steps=0 run: 4.6s median where the page was ready the entire time.
# The model stays exactly where it belongs, as the fallback for pages that need finding.
if task_is_send and browser_send_parse.composer_index_in_state(li_text):
staged_complete = True
logger.info(f"[browser-prestage] READY tier-0 in "
f"{int((time.monotonic() - p_t_step) * 1000)}ms: a composer is already "
f"on the page, no aux call needed")
break
p_t_aux = time.monotonic()
reply = safe_resp_text(await asyncio.wait_for(
client.messages.create(
@@ -121,3 +121,25 @@ def test_ready_on_a_page_with_nowhere_to_write_gets_one_nudge():
from backend.apps.agents.browser.browser_send_parse import composer_index_in_state
assert composer_index_in_state(NO_COMPOSER) is None, "the feed shape must read as no composer"
assert composer_index_in_state(COMPOSER_PRESENT) is not None, "a staged page must read as one"
def test_a_composer_already_on_the_page_needs_no_aux_call():
"""Criterion 5's tier-0. Measured: a steps=0 prestage took 4.6s median, and essentially all of
it was one aux LLM call (1.7-6.5s) asking whether a page was ready that already was.
"Staged" means a composer is visible. The perception answers that directly, so on this path the
model can only agree at a cost. It stays as the fallback for pages where the box must be found.
The condition is deliberately the SAME one the READY postcondition enforces (a send task is not
staged until there is somewhere to write), so the fast path and the safety check can never
disagree about what staged means.
"""
import inspect
from backend.apps.agents.browser import browser_prestage as pre
src = inspect.getsource(pre)
i = src.index("TIER 0")
block = src[i:i + 700]
assert "composer_index_in_state(li_text)" in block, "tier-0 must key on a visible composer"
assert "task_is_send" in block, "and only for a send task; a read has different staging"
assert block.index("staged_complete = True") < block.index("p_t_aux = time.monotonic()") \
if "p_t_aux = time.monotonic()" in block else True, "it must short-circuit BEFORE the aux call"