Repository navigation
Stabilize master CI: deterministic timing, cancel precedence, and Windows bounds #328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
eb399ee
840960d
6b2be60
6252c92
0f6aec6
fac711a
103812e
188af77
540225a
e677497
9574342
b26e45a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,15 +47,19 @@ | |
| Usage: | ||
| python scripts/openclaw_install_check.py --tarball <relaymind-openclaw-provider-*.tgz> \\ | ||
| --out <export.json> [--label "<machine and runtime>"] [--target-platform] \\ | ||
| [--timeout 300] -- <openclaw command, e.g. integrations/openclaw/node_modules/.bin/openclaw> | ||
| [--timeout 300] [--budget 1140] \\ | ||
| -- <openclaw command, e.g. integrations/openclaw/node_modules/.bin/openclaw> | ||
| """ | ||
|
|
||
| import argparse | ||
| import hashlib | ||
| import json | ||
| import math | ||
| import os | ||
| import platform | ||
| import re | ||
| import shutil | ||
| import signal | ||
| import socket | ||
| import sqlite3 | ||
| import subprocess | ||
|
|
@@ -179,6 +183,9 @@ def _redact_default_model(text: str) -> str: | |
| TOOL_CALL_ID = "call_read_1" | ||
| TOOL_ANSWER = "The note says the lantern is on the second shelf." | ||
| OUTPUT_TAIL = 4000 | ||
| # Kept free at the end of the lifecycle budget for the JSON export, so a | ||
| # stalled cleanup step cannot let the step deadline kill the process first. | ||
| EXPORT_RESERVE_SECONDS = 30.0 | ||
|
|
||
| STEPS = ( | ||
| "version", | ||
|
|
@@ -557,27 +564,71 @@ def _path_forms(candidate: PurePath, home: PurePath) -> set[str]: | |
| return forms | ||
|
|
||
|
|
||
| def _stop_tree(process: subprocess.Popen) -> None: | ||
| """Stop the host and its children; Windows can respawn with inherited stdio.""" | ||
| if sys.platform == "win32": | ||
| if process.poll() is None: | ||
| try: | ||
| subprocess.run( | ||
| ["taskkill", "/T", "/F", "/PID", str(process.pid)], | ||
| stdout=subprocess.DEVNULL, | ||
| stderr=subprocess.DEVNULL, | ||
| timeout=10, | ||
| check=False, | ||
| ) | ||
| except (OSError, subprocess.TimeoutExpired): | ||
| pass | ||
| if process.poll() is None: | ||
| process.kill() | ||
| else: | ||
| try: | ||
| os.killpg(process.pid, signal.SIGKILL) | ||
| except (ProcessLookupError, PermissionError): | ||
| pass | ||
| try: | ||
| process.wait(timeout=10) | ||
| except subprocess.TimeoutExpired: | ||
| process.kill() | ||
| process.wait() | ||
|
|
||
|
|
||
| def _run(command: Sequence[str], args: list[str], stdin: str | None, env, timeout: float): | ||
| invocation = host_invocation(command, args) | ||
| started = time.monotonic() | ||
| try: | ||
| completed = subprocess.run( | ||
| windows = sys.platform == "win32" | ||
| with ( | ||
| tempfile.TemporaryFile("w+", encoding="utf-8", errors="replace") as out, | ||
| tempfile.TemporaryFile("w+", encoding="utf-8", errors="replace") as err, | ||
| ): | ||
| process = subprocess.Popen( | ||
| invocation, | ||
| env=env, | ||
| input=stdin, | ||
| capture_output=True, | ||
| stdin=subprocess.PIPE if stdin is not None else subprocess.DEVNULL, | ||
| stdout=out, | ||
| stderr=err, | ||
| text=True, | ||
| timeout=timeout, | ||
| encoding="utf-8", | ||
| errors="replace", | ||
| start_new_session=not windows, | ||
| creationflags=(getattr(subprocess, "CREATE_NEW_PROCESS_GROUP", 0) if windows else 0), | ||
| ) | ||
| result = (completed.returncode, completed.stdout, completed.stderr, None) | ||
| except subprocess.TimeoutExpired as error: | ||
| result = ( | ||
| None, | ||
| qualification._text(error.stdout), | ||
| qualification._text(error.stderr), | ||
| "timed_out", | ||
| ) | ||
| return (*result, round(time.monotonic() - started, 3)) | ||
| if stdin is not None: | ||
| try: | ||
| process.stdin.write(stdin) | ||
| process.stdin.close() | ||
| except (BrokenPipeError, OSError): | ||
| pass | ||
| timed_out = None | ||
| try: | ||
| code = process.wait(timeout=timeout) | ||
| except subprocess.TimeoutExpired: | ||
| timed_out = "timed_out" | ||
| _stop_tree(process) | ||
| code = None | ||
| out.seek(0) | ||
| err.seek(0) | ||
| stdout, stderr = out.read(), err.read() | ||
| return code, stdout, stderr, timed_out, round(time.monotonic() - started, 3) | ||
|
|
||
|
|
||
| CHECKS: dict[str, Callable[[str, Context], tuple[bool, dict]]] = { | ||
|
|
@@ -586,7 +637,15 @@ def _run(command: Sequence[str], args: list[str], stdin: str | None, env, timeou | |
| } | ||
|
|
||
|
|
||
| def run_steps(command: Sequence[str], ctx: Context, timeout: float) -> tuple[list, dict, str]: | ||
| def run_steps( | ||
| command: Sequence[str], | ||
| ctx: Context, | ||
| timeout: float, | ||
| *, | ||
| deadline: float | None = None, | ||
| clock: Callable[[], float] = time.monotonic, | ||
| ) -> tuple[list, dict, str]: | ||
| """Run the host steps; ``deadline`` caps each command and leaves export time.""" | ||
| steps: list[dict] = [] | ||
| exchanges: dict[str, dict] = {} | ||
| found: dict[str, dict] = {} | ||
|
|
@@ -610,10 +669,21 @@ def run_steps(command: Sequence[str], ctx: Context, timeout: float) -> tuple[lis | |
| continue | ||
| if name in ("text-exchange", "tool-exchange"): | ||
| exec_state_dir(ctx, name).mkdir(parents=True, exist_ok=True) | ||
| step_timeout = timeout | ||
| if deadline is not None: | ||
| remaining = deadline - clock() | ||
| if remaining <= 0: | ||
| step["reason"] = "lifecycle_budget_exhausted" | ||
| stopped = True | ||
| continue | ||
| step_timeout = min(timeout, remaining) | ||
| step["timeout_seconds"] = round(step_timeout, 3) | ||
| before = set(qualification._run_ids(ctx.gateway)) | ||
| requests_before = len(ctx.gateway.adapter.requests) | ||
| try: | ||
| code, stdout, stderr, timed_out, seconds = _run(command, args, stdin, ctx.env, timeout) | ||
| code, stdout, stderr, timed_out, seconds = _run( | ||
| command, args, stdin, ctx.env, step_timeout | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [P2] Enforce the lifecycle deadline across Windows child processes The pinned OpenClaw CLI respawns OpenClaw respawn · Inherited stdio · CPython timeout behavior
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in fac711a. |
||
| ) | ||
| except OSError as error: | ||
| # The host command cannot start: this step did not run. The rest | ||
| # stays listed as not_run, and the cleanup still runs if installed. | ||
|
|
@@ -688,11 +758,24 @@ def run_install_check( | |
| out: Path, | ||
| *, | ||
| timeout: float = 300, | ||
| budget: float | None = None, | ||
| clock: Callable[[], float] = time.monotonic, | ||
| label: str | None = None, | ||
| target_platform: bool = False, | ||
| host_home: Path | None = None, | ||
| ) -> dict: | ||
| """Run the lifecycle against one doubles gateway; write and return the export.""" | ||
| """Run the lifecycle against one doubles gateway; write and return the export. | ||
|
|
||
|
ArcsinX marked this conversation as resolved.
Resolved
|
||
| ``budget`` bounds the whole check, including the export. The command | ||
| deadline keeps ``EXPORT_RESERVE_SECONDS`` free, so a stalled cleanup step | ||
| cannot let the CI step deadline kill the process before the export exists. | ||
| ``clock`` is the deadline clock; tests inject one to avoid wall-clock waits. | ||
| """ | ||
| if not math.isfinite(timeout) or timeout <= 0: | ||
| raise ValueError("timeout must be positive and finite") | ||
| if budget is not None and (not math.isfinite(budget) or budget <= EXPORT_RESERVE_SECONDS): | ||
| raise ValueError("budget must be finite and greater than the export reserve") | ||
| started = clock() | ||
| tarball = Path(tarball).resolve() | ||
| # Removed by hand at the end: a file a host child still holds (Windows) | ||
| # must never stop the export from being written. | ||
|
|
@@ -722,7 +805,12 @@ def run_install_check( | |
| gateway=gateway, | ||
| gateway_port=_closed_port(), | ||
| ) | ||
| steps, exchanges, status = run_steps(command, ctx, timeout) | ||
| deadline = None | ||
| if budget is not None: | ||
| deadline = started + budget - EXPORT_RESERVE_SECONDS | ||
| steps, exchanges, status = run_steps( | ||
| command, ctx, timeout, deadline=deadline, clock=clock | ||
| ) | ||
| found = exchanges.pop("_leftovers", {}) | ||
| runs = qualification.run_records(gateway, qualification._run_ids(gateway)) | ||
| version = next( | ||
|
|
@@ -748,6 +836,8 @@ def run_install_check( | |
| }, | ||
| "gateway_port": ctx.gateway_port, | ||
| }, | ||
| "timeout_seconds": timeout, | ||
| "budget_seconds": budget, | ||
| "token": NOT_RECORDED, | ||
| "steps": steps, | ||
| "exchanges": exchanges, | ||
|
|
@@ -771,11 +861,41 @@ def run_install_check( | |
| return json.loads(text) | ||
|
|
||
|
|
||
| def _finite_float(value: str) -> float: | ||
| number = float(value) | ||
| if not math.isfinite(number): | ||
| raise argparse.ArgumentTypeError("must be a finite number") | ||
| return number | ||
|
|
||
|
|
||
| def _positive_float(value: str) -> float: | ||
| number = _finite_float(value) | ||
| if number <= 0: | ||
| raise argparse.ArgumentTypeError("must be positive") | ||
| return number | ||
|
|
||
|
|
||
| def _lifecycle_budget(value: str) -> float: | ||
| number = _finite_float(value) | ||
| if number <= EXPORT_RESERVE_SECONDS: | ||
| raise argparse.ArgumentTypeError( | ||
| f"must be greater than the export reserve ({EXPORT_RESERVE_SECONDS:g} s)" | ||
| ) | ||
| return number | ||
|
|
||
|
|
||
| def main(argv: Sequence[str] | None = None) -> int: | ||
| parser = argparse.ArgumentParser(description=__doc__.split("\n\n")[0]) | ||
| parser.add_argument("--tarball", type=Path, required=True, help="the release artifact") | ||
| parser.add_argument("--out", type=Path, required=True) | ||
| parser.add_argument("--timeout", type=float, default=300, help="seconds per host command") | ||
| parser.add_argument( | ||
| "--timeout", type=_positive_float, default=300, help="seconds per host command" | ||
| ) | ||
| parser.add_argument( | ||
| "--budget", | ||
| type=_lifecycle_budget, | ||
| help="seconds for the whole check, including the export (default: no overall bound)", | ||
| ) | ||
| parser.add_argument("--label", help="the machine and runtime, recorded in the export") | ||
| parser.add_argument( | ||
| "--target-platform", | ||
|
|
@@ -806,6 +926,7 @@ def main(argv: Sequence[str] | None = None) -> int: | |
| args.tarball, | ||
| args.out, | ||
| timeout=args.timeout, | ||
| budget=args.budget, | ||
| label=args.label, | ||
| target_platform=args.target_platform, | ||
| ) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[P2] should fix. If
plugins inspecttimes out after installation andplugins uninstallalso stalls during cleanup, their two 600-second waits plus installation exceed this 20-minute cap. The runner stops the script before it writes the lifecycle JSON, losing thetimed_outrecord. Reserve time for the export within the step deadline or write the failure record before cleanup.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirmed. The 20-minute step cap is 1200 s, while a 200-220 s Windows install plus the 600 s
inspecttimeout plus a 600 suninstallstall is already about 1400 s, andrun_stepskeeps running the cleanup steps after a timeout.run_install_checkwrites the JSON only afterrun_stepsreturns (scripts/openclaw_install_check.py), so the runner kills the process before thetimed_outrecord exists. I will reserve time for the export in the step deadline, or write the failure record before cleanup.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in 0f6aec6. The step passes
--budget 1140under the 1200 s cap;run_install_checkreservesEXPORT_RESERVE_SECONDS = 30and gives each commandmin(timeout, remaining), so a 600 sinspectplus a stalleduninstallcannot consume the export window.test_openclaw_lifecycle_has_a_wider_windows_command_timeoutandtest_a_lifecycle_budget_stops_a_stalled_cleanup_before_the_exportcover it.