Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ jobs:

- name: Test
# Parallel workers, one test file per worker at a time; on Windows the
# single-process run took about 29 minutes.
# single-process run took about 29 minutes. The bound turns a hung
# test into a fast failure instead of the 60-minute job timeout.
timeout-minutes: 45
run: pytest -n auto --dist loadfile --durations=30 --junitxml=ci-evidence/core-tests.xml

- uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -179,6 +181,7 @@ jobs:

- name: Plugin tests
working-directory: integrations/openclaw
timeout-minutes: 15
run: npm test

- name: Release artifact
Expand Down Expand Up @@ -225,6 +228,7 @@ jobs:
# blocked capture (exit 0); harness/fixture errors must fail the job.
# Typical 50–100 s; tier deadline 180 s, plus 60 s for cleanup/export.
- name: Transport, plugin, and artifact tiers
timeout-minutes: 25
run: >
pytest tests/test_asset_whole_task_host_config.py tests/test_asset_whole_task_inputs.py
tests/test_openclaw_host_transport.py tests/test_openclaw_plugin.py
Expand Down Expand Up @@ -254,10 +258,19 @@ jobs:
--durations=30 --junitxml=ci-evidence/openclaw-tests.xml

- name: Pinned host lifecycle (install, inspect, round trips, removal)
# The Windows runner spends 200-220 s in the host's npm install alone
# (about 30 s on Linux and macOS), so its per-command bound is wider.
# The 19-minute lifecycle budget keeps a minute under this 20-minute
# step for Python startup and the export, even if cleanup stalls.
timeout-minutes: 20

Copy link
Copy Markdown
Member

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 inspect times out after installation and plugins uninstall also 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 the timed_out record. Reserve time for the export within the step deadline or write the failure record before cleanup.

Copy link
Copy Markdown
Member Author

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 inspect timeout plus a 600 s uninstall stall is already about 1400 s, and run_steps keeps running the cleanup steps after a timeout. run_install_check writes the JSON only after run_steps returns (scripts/openclaw_install_check.py), so the runner kills the process before the timed_out record exists. I will reserve time for the export in the step deadline, or write the failure record before cleanup.

Copy link
Copy Markdown
Member Author

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 1140 under the 1200 s cap; run_install_check reserves EXPORT_RESERVE_SECONDS = 30 and gives each command min(timeout, remaining), so a 600 s inspect plus a stalled uninstall cannot consume the export window. test_openclaw_lifecycle_has_a_wider_windows_command_timeout and test_a_lifecycle_budget_stops_a_stalled_cleanup_before_the_export cover it.

env:
HOST_TIMEOUT: ${{ matrix.os == 'windows-latest' && '600' || '300' }}
run: |
tarball="release/openclaw/$(node -p "require('./release/openclaw/release.json').filename")"
python scripts/openclaw_install_check.py --tarball "$tarball" \
--out "ci-evidence/openclaw-install-check-${{ matrix.os }}.json" \
--timeout "$HOST_TIMEOUT" \
--budget 1140 \
--label "GitHub Actions ${{ matrix.os }} runner, Node $(node --version)" \
-- node integrations/openclaw/node_modules/openclaw/openclaw.mjs

Expand Down
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2812,6 +2812,18 @@ pre-release development.

### Fixed

- CI stability (RM14; RM33; RM38; AC12; AC19; AC24; AC29): a requested cancel now
outranks a later failure even when a provider consumes the task cancellation, the
Windows OpenClaw lifecycle gets a wider per-command timeout and an overall
lifecycle budget that keeps the export inside the CI step deadline and stops the
host process tree on timeout, non-finite budget values are rejected, the OpenClaw
lock tests no longer inherit Vitest's 5 s default, and the timing test advances an
injected clock and asserts the POST duration, the POSIX process-tree test is
skipped on Windows, and a `PermissionError` from `os.killpg` is treated as an
already-gone process so a timed-out macOS step keeps its timeout status and
captured output. The cancel precedence follows the existing section 7.4 rule; the
other changes harden the OpenClaw lifecycle and its CI coverage.

- Hardened automated-host control polling and provider-response failures. Future executions require explicit v2 control budgets and fresh preregistration; historical inputs and outcomes remain unchanged. Timeout paths retain the last recommendation state, and functional transport tests allow cold worker startup (RM03, RM05, RM16, RM44).

- Addressed #277/#280 review findings: portable transport tests, clear blind-CLI input errors, consistent stored row evidence, fenced JSON proposals, private-file read bounds, and redacted public home paths with retained original bindings. Historical benchmark results and qualification claims are unchanged.
Expand Down
21 changes: 21 additions & 0 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ marker when the test drops below 10 seconds; the gap keeps a run near the line
from churning the marker. The Windows job runs the same tests slower, so the
Ubuntu job is the reference. The fast local subset leaves those tests out.

### Timing-sensitive tests

A loaded runner, a parallel worker, or a slow file system must never change a
test's verdict. Inject `FakeClock` (or the production clock parameter) and
assert the recorded duration, not the wall-clock duration of the test process;
do not use `asyncio.sleep` as synchronization. A real sleep may remain where
the test proves an external timeout, but the assertion reads the injected
clock. File-system stress tests that need real operations keep a generous
per-test timeout instead of a tight one.

### A failed master run

Read the failed job and its annotations before rerunning. A cancelled job with
`The job was not acquired by Runner of type hosted` is GitHub capacity, not a
test failure: rerun that job. A failed step is a real failure until its test or
harness is fixed; do not add a retry that hides it. The OpenClaw host lifecycle
keeps its per-command timeout and the overall lifecycle budget in the JSON
export, so a `timed_out` step names the bound that was hit; the budget also
keeps time to write the export before the step deadline, and a timed-out host
process tree is stopped before the export.

### Optional coverage

Coverage is a diagnostic, not a quality gate. It is not part of the default
Expand Down
4 changes: 4 additions & 0 deletions integrations/openclaw/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ import { defineConfig } from "vitest/config";
export default defineConfig({
test: {
include: ["test/**/*.test.ts"],
// The lock/ledger tests drive real file-system interleavings; a busy
// Windows runner can exceed Vitest's 5 s default without a test bug.
testTimeout: 30_000,
hookTimeout: 30_000,
},
});
161 changes: 141 additions & 20 deletions scripts/openclaw_install_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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]]] = {
Expand All @@ -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] = {}
Expand All @@ -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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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 plugins uninstall on Windows with inherited stdout and stderr, even when launched directly through node. When the timeout expires, CPython kills the immediate process and drains the pipes without a timeout. A stalled OpenClaw child can hold those pipes open until Actions kills the step, so this command can exceed its remaining budget and prevent the JSON export. Terminate the process tree on timeout and bound the final output read. The install helper’s _stop already handles both.

OpenClaw respawn · Inherited stdio · CPython timeout behavior

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in fac711a. _run now starts the host in its own process group, stops the tree on timeout (taskkill /T /F on Windows, killpg on POSIX), and writes stdout/stderr to temporary files, so a respawned child cannot hold inherited pipes past the budget. A unit test covers both timeout paths.

)
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.
Expand Down Expand Up @@ -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.

Comment thread
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.
Expand Down Expand Up @@ -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(
Expand All @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -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,
)
Expand Down
2 changes: 2 additions & 0 deletions src/relaymind/orchestrator/_run_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ class _RunHost(Protocol):
model_calls: list[dict[str, str]]
generating: dict[str, ModelAdapter]
cancel_asked: set[str]
cancel_requested: bool
workflow: _Workflow | None
tool_branch: str | None
decision: RouteDecision | None
Expand Down Expand Up @@ -622,6 +623,7 @@ def _answer_options(
self, defaults: GenerationOptions, *, tools_offered: bool = False
) -> GenerationOptions: ...
def _local_unavailable(self, detail: str) -> Escalation: ...
def _cancel(self) -> RunOutcome: ...
def _fail(self, error_code: str, *, detail: str, **extra: Any) -> RunOutcome: ...
async def _protected(self, work: Callable[[], Awaitable[RunOutcome]]) -> RunOutcome: ...
async def _run_local(
Expand Down
Loading
Loading