From 39ecc85bf731fb3d49e7383657e5f2a69119d184 Mon Sep 17 00:00:00 2001 From: JeffreyChen Date: Thu, 19 Nov 2026 14:26:02 +0800 Subject: [PATCH] test: publish helper "entered" markers whole Path.write_text creates the marker before writing it, and the tests stopped polling once the file existed, so on Windows one read an empty marker and failed while the helper was still blocked. The fixtures now write a temporary file and os.replace it into place, and the tests wait for the expected content. --- docs/updates/2026-11-c.md | 6 ++++++ docs/updates/README.md | 1 + test/fixtures/semantic_helper.py | 10 +++++++++- test/fixtures/service_helper.py | 9 ++++++++- test/unit_test/headless/test_agent_semantic_helper.py | 4 ++-- test/unit_test/headless/test_agent_service_helper.py | 4 ++-- 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/docs/updates/2026-11-c.md b/docs/updates/2026-11-c.md index cbf25e31d..6ce94fb32 100644 --- a/docs/updates/2026-11-c.md +++ b/docs/updates/2026-11-c.md @@ -265,3 +265,9 @@ - **What**: Halving the UIA checkpoints (U-20261119-01) was not enough: `test_agent_uia_target` still hit the 120 s timeout on a Windows 3.12 runner, because a capture makes thousands of COM calls and each full runtime checkpoint is a durable budget write plus authority queries. `UiaObservationTarget` now hands the source a capture checkpoint that re-validates the pinned task and owner on every call but runs the full runtime checkpoint at most every 50 ms; the unthrottled checkpoint after the capture still runs before publication, so revocation is observed before anything is published. The same CI rounds also showed two clock/latency follow-ups to U-20261119-02, committed separately: `test/fixtures/semantic_helper.py` still stamped captures with `time.monotonic` (a different clock than `perf_counter` on Windows before 3.13), and `test_agent_memory_target`'s managed read used the probe's 1 s default under per-step durable checkpoints. - **Evidence**: `uia_target.py` `_capture_checkpoint`; `test_agent_uia_target.py::test_revocation_during_capture_prevents_publication` (both cadences), `::test_throttled_capture_still_validates_scope_on_every_call` (3 full checkpoints per observe, scope checked on every call). The two runtime cases went from 32-139 s to under 1 s locally; 145 UIA tests passed. Job 135058967209 (windows-2022, 3.12) shows the timeout; jobs 135019756708 / 135019756850 / 135019757298 show the memory budget and helper clock failures. - **Open items**: none. + +## U-20261119-04 · 2026-11-19 · Publish helper "entered" markers whole · #incident #ci #agent + +- **What**: After #556 merged, `main`'s Code Quality run failed one test on `windows-2022, 3.11`: `test_agent_semantic_helper.py::test_cancel_retires_a_helper_after_it_entered_a_blocked_command` read `''` from the marker its helper writes on entering a blocked command. `Path.write_text` creates the file before it writes the text, and the test stopped polling as soon as the file existed. The follow-on `runtime still has active input or cleanup` came from the helper still being blocked when the assertion failed. The semantic and service helper fixtures now write the marker to a temporary file and `os.replace` it into place, and both tests wait for the expected content, not just the file. +- **Evidence**: job 135178189984 (run 44410830939, `a6fe6ae8`); `test/fixtures/semantic_helper.py`, `test/fixtures/service_helper.py` `mark_entered`; `test_agent_semantic_helper.py`, `test_agent_service_helper.py`. 100 helper tests passed locally. The same test passed in the PR's earlier rounds, so this was intermittent. +- **Open items**: none. diff --git a/docs/updates/README.md b/docs/updates/README.md index d29fb4cf7..f7021d4fc 100644 --- a/docs/updates/README.md +++ b/docs/updates/README.md @@ -58,6 +58,7 @@ In the same commit: delete the item from `Progress.md`, add a `#done` entry here | ID | Date | Title | Tags | Batch | |---|---|---|---|---| +| U-20261119-04 | 2026-11-19 | Publish helper "entered" markers whole | #incident #ci #agent | [2026-11-c](2026-11-c.md) | | U-20261119-03 | 2026-11-19 | Throttle full checkpoints inside read-only UIA captures | #incident #ci #agent #uia | [2026-11-c](2026-11-c.md) | | U-20261119-02 | 2026-11-19 | Order captures with a fine clock; keep Docker helpers on the full package | #incident #ci #agent | [2026-11-c](2026-11-c.md) | | U-20261119-01 | 2026-11-19 | Repair PR #556 CI: read-only guard, UIA checkpoint cost, Docker helper imports | #incident #ci #agent | [2026-11-c](2026-11-c.md) | diff --git a/test/fixtures/semantic_helper.py b/test/fixtures/semantic_helper.py index c9f7211b1..f7727d05b 100644 --- a/test/fixtures/semantic_helper.py +++ b/test/fixtures/semantic_helper.py @@ -1,6 +1,7 @@ """Run a repository-owned semantic IPC target without any desktop or memory access.""" from dataclasses import replace import hashlib +import os from pathlib import Path import sys import threading @@ -15,6 +16,13 @@ from je_auto_control.utils.process_memory.models import FailureReason, MemoryObservationError +def mark_entered(marker: Path) -> None: + """Publish the marker whole: a reader polling for the file never sees it empty.""" + staged = marker.with_name(marker.name + ".tmp") + staged.write_text("entered", encoding="utf-8") + os.replace(staged, marker) + + class FixtureTarget(SemanticTarget): """Only this helper changes its counter; no application or desktop resources are opened.""" @@ -42,7 +50,7 @@ def perform_grounded(self, name, arguments, *, expected, operation_id): self.worker._input({"kind": "key_press", "keycode": 65, "is_shift": False}) if arguments.get("hang"): if self.started_marker is not None: - self.started_marker.write_text("entered", encoding="utf-8") + mark_entered(self.started_marker) threading.Event().wait(30) if not arguments.get("no_effect"): self.state = replace(self.state, fields=(("value", 1),), revision=self.state.revision + 2) diff --git a/test/fixtures/service_helper.py b/test/fixtures/service_helper.py index 41b04c430..00385ecf0 100644 --- a/test/fixtures/service_helper.py +++ b/test/fixtures/service_helper.py @@ -16,6 +16,13 @@ from je_auto_control.wrapper._input_observer import input_event +def mark_entered(marker: Path) -> None: + """Publish the marker whole: a reader polling for the file never sees it empty.""" + staged = marker.with_name(marker.name + ".tmp") + staged.write_text("entered", encoding="utf-8") + os.replace(staged, marker) + + class Function: def __init__(self, callback): self.callback = callback @@ -43,7 +50,7 @@ def query(self, _handle, _level, output, _size, _needed): def change(self, state): if self.marker is not None: - self.marker.write_text("entered", encoding="utf-8") + mark_entered(self.marker) if self.fault == "hang": threading.Event().wait(30) if self.fault == "input": diff --git a/test/unit_test/headless/test_agent_semantic_helper.py b/test/unit_test/headless/test_agent_semantic_helper.py index ba838fd1d..c05a12ccd 100644 --- a/test/unit_test/headless/test_agent_semantic_helper.py +++ b/test/unit_test/headless/test_agent_semantic_helper.py @@ -133,9 +133,9 @@ def blocked(): worker = threading.Thread(target=blocked) worker.start() deadline = time.monotonic() + 5 - while not marker.exists() and time.monotonic() < deadline: + while not (marker.exists() and marker.read_text(encoding="utf-8") == "entered"): + assert time.monotonic() < deadline, "the helper never entered the blocked command" threading.Event().wait(0.01) - assert marker.read_text(encoding="utf-8") == "entered" runtime.cancel(task.task_id) worker.join(timeout=5) assert not worker.is_alive() and len(failures) == 1 diff --git a/test/unit_test/headless/test_agent_service_helper.py b/test/unit_test/headless/test_agent_service_helper.py index 10e7de537..982dbc4ee 100644 --- a/test/unit_test/headless/test_agent_service_helper.py +++ b/test/unit_test/headless/test_agent_service_helper.py @@ -357,9 +357,9 @@ def blocked(): thread = threading.Thread(target=blocked) thread.start() deadline = time.monotonic() + 5 - while not marker.exists() and time.monotonic() < deadline: + while not (marker.exists() and marker.read_text(encoding="utf-8") == "entered"): + assert time.monotonic() < deadline, "the helper never entered the blocked command" threading.Event().wait(0.01) - assert marker.read_text() == "entered" runtime.cancel(task) thread.join(5) assert not thread.is_alive() and errors