The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
test: distinguish worker scheduling from protocol completion
ethernet52b5ea4e7f29
diff --git a/tests/agent/test_compression_worker_isolation_76354.py b/tests/agent/test_compression_worker_isolation_76354.pyindex fe976e5e5bc..53f3d5d0188 100644--- a/tests/agent/test_compression_worker_isolation_76354.py+++ b/tests/agent/test_compression_worker_isolation_76354.py@@ -66,6 +66,24 @@ def _build_agent_with_db(db: SessionDB, session_id: str, **compressor_kwargs):return agent+def _timeout_after_entry(monkeypatch, started):+ """Start the real timeout wait after the engine reached its blocking point."""+ from agent import conversation_compression as cc++ wait = cc._await_worker_within_budget+ futures = []++ def after_entry(future, fence, **_kwargs):+ futures.append(future)+ assert started.wait(timeout=10)+ fence.touch_progress()+ return wait(future, fence, idle=0.1, ceiling=1.0, wait_started=time.monotonic())++ monkeypatch.setattr(cc, "resolve_context_compression_timeouts", lambda cfg=None: (30, 60))+ monkeypatch.setattr(cc, "_await_worker_within_budget", after_entry)+ return futures++def test_f3_mutating_engine_cannot_touch_live_transcript_after_timeout(tmp_path: Path, monkeypatch) -> None:@@ -80,15 +98,10 @@ def test_f3_mutating_engine_cannot_touch_live_transcript_after_timeout(agent = _build_agent_with_db(db, session_id)agent._cached_system_prompt = "sys"- # Fast host timeout for the owned wrapper.- monkeypatch.setattr(- "agent.conversation_compression.resolve_context_compression_timeouts",- lambda cfg=None: (0.6, 1.2),- )-engine_started = threading.Event()release_engine = threading.Event()mutated_lists = []+ futures = _timeout_after_entry(monkeypatch, engine_started)def _mutating_engine(msgs, **_kwargs):# Legacy/plugin-engine contract: mutate the input list IN PLACE.@@ -122,6 +135,8 @@ def test_f3_mutating_engine_cannot_touch_live_transcript_after_timeout(assert live == baselinefinally:release_engine.set()+ for future in futures:+ future.result(timeout=10)# After the late worker finishes, the live transcript must STILL be# untouched (publication only on admitted commit — which was cancelled).deadline = time.time() + 5@@ -157,13 +172,9 @@ def test_host_timeout_releases_pool_slot_while_protected_provider_is_still_blockdb.create_session(session_id, source="cli")agent = _build_agent_with_db(db, session_id)agent._cached_system_prompt = "sys"- monkeypatch.setattr(- "agent.conversation_compression.resolve_context_compression_timeouts",- lambda cfg=None: (0.05, 0.1),- )-provider_started = threading.Event()release_provider = threading.Event()+ futures = _timeout_after_entry(monkeypatch, provider_started)def _blocked_provider(_kwargs):provider_started.set()@@ -182,10 +193,10 @@ def test_host_timeout_releases_pool_slot_while_protected_provider_is_still_blocklive, "sys", approx_tokens=120_000)assert returned is live- assert provider_started.wait(timeout=1)+ assert provider_started.wait(timeout=10)assert not release_provider.is_set()- deadline = time.time() + 1+ deadline = time.time() + 10while time.time() < deadline:with cc._compress_admission_lock:if cc._compress_admitted_count == 0:@@ -198,6 +209,8 @@ def test_host_timeout_releases_pool_slot_while_protected_provider_is_still_block)finally:release_provider.set()+ for future in futures:+ future.result(timeout=10)deadline = time.time() + 5while time.time() < deadline:with cc._compress_admission_lock:diff --git a/tests/tui_gateway/test_compute_host_turn_protocol.py b/tests/tui_gateway/test_compute_host_turn_protocol.pyindex fb3b034b3a0..0e421aae353 100644--- a/tests/tui_gateway/test_compute_host_turn_protocol.py+++ b/tests/tui_gateway/test_compute_host_turn_protocol.py@@ -25,7 +25,7 @@ def _frames(out: io.StringIO) -> list[dict]:return [json.loads(line) for line in out.getvalue().splitlines() if line.strip()]-def _wait(out: io.StringIO, predicate, timeout: float = 5.0) -> dict:+def _wait(out: io.StringIO, predicate, timeout: float = 20.0) -> dict:deadline = time.monotonic() + timeoutwhile time.monotonic() < deadline:for frame in _frames(out):diff --git a/tests/tui_gateway/test_hosted_room_driver_runtime.py b/tests/tui_gateway/test_hosted_room_driver_runtime.pyindex 9b226701515..69a78787b8a 100644--- a/tests/tui_gateway/test_hosted_room_driver_runtime.py+++ b/tests/tui_gateway/test_hosted_room_driver_runtime.py@@ -421,7 +421,8 @@ def _runtime()-def _wait_for(predicate, *, timeout: float = 2.0) -> None:+def _wait_for(predicate, *, timeout: float = 10.0) -> None:+ # Allow worker scheduling without repeating the operation under test.deadline = time.monotonic() + timeoutwhile time.monotonic() < deadline:if predicate():@@ -763,7 +764,7 @@ def test_waiting_room_does_not_block_an_independent_room(tmp_path: Path):)runtime.start()- assert waiting.submitted.wait(1.0)+ assert waiting.submitted.wait(10.0)_wait_for(lambda: state.get_task(db, identities[1])["status"] == "settled")assert state.get_task(db, identities[0])["status"] == "running"assert runtime.stop(timeout=5.0)@@ -1188,7 +1189,7 @@ def test_retry_ignores_late_receipt_from_prior_execution_generation(db: Path):runtime = _runtime(db, rpc, clock=clock)runtime.start()- assert rpc.submitted.wait(1.0)+ assert rpc.submitted.wait(10.0)time.sleep(0.04)assert runtime.stop(timeout=5.0)@@ -1559,7 +1560,7 @@ def test_post_submit_observation_failure_preserves_recoverable_outcome(db: Path)runtime = _runtime(db, rpc)runtime.start()- assert rpc.submitted.wait(1.0)+ assert rpc.submitted.wait(10.0)_wait_for(lambda: ("observation failed after submit"@@ -1590,7 +1591,7 @@ def test_cancellation_is_persisted_before_interrupt_and_fences_late_result()runtime.start()- assert rpc.submitted.wait(1.0)+ assert rpc.submitted.wait(10.0)cancelled = runtime.cancel(identity, cancel_id="cancel-user")rpc.complete(identity.task_id, content="Too late.")runtime.wakeup()@@ -1620,7 +1621,7 @@ def test_transient_remote_stop_failure_stays_pending_and_retries(db: Path):rpc.interrupt = flaky_interruptruntime.start()- assert rpc.submitted.wait(1.0)+ assert rpc.submitted.wait(10.0)stopping = runtime.cancel(identity, cancel_id="cancel-retry")assert stopping["status"] == "stopping"assert state.get_task(db, identity)["status"] == "stopping"@@ -1766,7 +1767,7 @@ def test_completion_wins_a_race_with_unacknowledged_stop(db: Path):runtime = _runtime(db, rpc)runtime.start()- assert rpc.submitted.wait(1.0)+ assert rpc.submitted.wait(10.0)def finish_only_after_stop_intent():if state.get_task(db, identity)["status"] == "stopping":@@ -1775,7 +1776,10 @@ def test_completion_wins_a_race_with_unacknowledged_stop(db: Path):rpc.on_info = finish_only_after_stop_intentresult = runtime.cancel(identity, cancel_id="cancel-raced")- assert result["status"] == "settled"+ assert result["status"] in {"stopping", "settled"}+ # cancel returns a routing snapshot; the worker owns durable settlement.+ _wait_for(lambda: state.get_task(db, identity)["status"] == "settled")+ result = state.get_task(db, identity)assert result["result"]["text"] == "Already done."assert runtime.stop(timeout=5.0)@@ -1959,7 +1963,7 @@ def test_pending_local_approval_is_reported_with_safe_choices(db: Path):)runtime.start()- assert rpc.submitted.wait(1.0)+ assert rpc.submitted.wait(10.0)session_id = next(iter(rpc.states))with rpc._lock:rpc.states[session_id]["pending_approval"] = {@@ -1984,7 +1988,7 @@ def test_cancel_never_interrupts_a_newer_task_in_the_same_session(db: Path):runtime = _runtime(db, rpc)runtime.start()- assert rpc.submitted.wait(1.0)+ assert rpc.submitted.wait(10.0)session_id = next(iter(rpc.states))def switch_to_newer_task() -> None:@@ -2047,7 +2051,7 @@ def test_authority_loss_stops_terminal_commit(db: Path):runtime = _runtime(db, rpc, lease_ttl_seconds=30.0)runtime.start()- assert rpc.submitted.wait(1.0)+ assert rpc.submitted.wait(10.0)hosted_rooms.claim_authority(db,room_id=ROOM_ID,@@ -2091,7 +2095,7 @@ def test_stop_is_bounded_and_does_not_interrupt_active_turn(db: Path):runtime = _runtime(db, rpc, poll_interval_seconds=0.01)runtime.start()- assert rpc.submitted.wait(1.0)+ assert rpc.submitted.wait(10.0)started = time.monotonic()stopped = runtime.stop(timeout=0.5)diff --git a/tests/tui_gateway/test_hosted_room_two_gateway_scoped.py b/tests/tui_gateway/test_hosted_room_two_gateway_scoped.pyindex 72d47507259..8b0f146860e 100644--- a/tests/tui_gateway/test_hosted_room_two_gateway_scoped.py+++ b/tests/tui_gateway/test_hosted_room_two_gateway_scoped.py@@ -153,7 +153,7 @@ async def test_in_process_scoped_transport_contract_finishes_headlessly(event_id="user-1",payload={"text": "@reviewer inspect", "thread_id": "thread-1"},)- deadline = asyncio.get_running_loop().time() + 5+ deadline = asyncio.get_running_loop().time() + 20while asyncio.get_running_loop().time() < deadline:if any(event["kind"] == "message.member"