Skip to content

Stabilize master CI: deterministic timing, cancel precedence, and Windows bounds - #328

Merged
seiko-iwasawa merged 12 commits into
masterfrom
stabilize/ci-flakes
Dec 3, 2026
Merged

seiko-iwasawa merged 12 commits into
masterfrom
stabilize/ci-flakes

Conversation

@seiko-iwasawa

Copy link
Copy Markdown
Member

Summary

Master CI failures over the last five weeks were not random. Most were Windows timing flakes and bounds that were too tight; two were macOS arm64 runner acquisition failures on GitHub's side. This PR removes the controllable flakes and documents the remaining rerun path.

What changed

  • Cancel precedence (RM14; AC12; AC19). A requested cancel is recorded before the provider is asked to stop. A provider that consumes the task cancellation and returns late text can no longer turn the run into failed or publish that text. Added a deterministic regression test that consumes CancelledError, advances the clock, and yields late text.
  • Timing test (RM38; AC29). test_event_fetch_timeout... now uses the injected FakeClock; the assertion no longer depends on Windows timer granularity.
  • OpenClaw Windows lifecycle (RM33; AC24). The lifecycle step passes --timeout 600 on windows-latest (300 elsewhere), writes timeout_seconds to the export, and has a 20-minute step bound. Windows install has been 203.8 / 217.4 / 222.0 s in passing runs, against ~28-33 s on Linux/macOS; the old 300 s default was too tight.
  • Slow-step bounds: test step 45 min, Vitest plugin tests 15 min, transport tiers 25 min.
  • Vitest: 30 s test/hook timeout for the real filesystem lock/ledger tests, instead of the 5 s default.
  • Docs: timing-sensitive tests must use injected clocks; a cancelled job with The job was not acquired by Runner of type hosted is GitHub capacity and should be rerun; failed tests must not be retried.

What is not fixed

macOS arm64 runner acquisition is GitHub capacity, not repository behavior. The two 30 Nov cancellations happened after ~15 minutes without a runner (The job was not acquired...). This PR keeps the arm64 matrix and documents the honest fallback: rerun those jobs. It does not auto-rerun or hide test failures.

Verification

  • pytest -n auto --dist loadfile: 10866 passed, 38 skipped
  • npm --prefix integrations/openclaw test: 1013 passed, 1 skipped
  • npm --prefix integrations/openclaw run typecheck
  • ruff check .
  • ruff format --check .
  • pytest tests/test_ci_workflows.py tests/test_documentation_links.py
  • The new cancel regression test fails before the fix (failed / external_failed) and passes after.

Requirements

RM14, RM33, RM38; AC12, AC19, AC24, AC29. No specification revision: the cancel precedence implements the existing section 7.4 rule; the rest is test/CI only.

@seiko-iwasawa
seiko-iwasawa requested a review from a team as a code owner December 1, 2026 05:52
@devnullexile-deepseek-review

devnullexile-deepseek-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit b26e45a)

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
✅ Merge recommendation: No concerns found
🧪 PR contains tests
🔒 No security concerns identified
⚡ No major issues detected
✅ Resolved findings

tests/test_openclaw_install_check.py:765-770

Question: killpg/SIGKILL on Windows

The new test_a_timed_out_host_command_stops_the_process_tree case for
platform == "linux" monkeypatches os.killpg and relies on
signal.SIGKILL. Both are Unix-only stdlib members. On a windows-latest
runner (the full suite runs this file there), monkeypatch.setattr(install_check.os, "killpg", ...) raises AttributeError because os.killpg is absent on
Windows, so the test errors in the Windows job; even if that patch used
raising=False, _stop_tree would then fail evaluating signal.SIGKILL.
That would make Windows CI red on the very test added to stabilize it.
Suggested correction: skip the linux parametrization on Windows, or patch
both os.killpg and signal.SIGKILL with raising=False (or route the
signal through a small module-level indirection) so the simulated branch can
run cross-platform. Worth confirming on a real Windows runner.

@devnullexile-deepseek-review

devnullexile-deepseek-review Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

DeepSeek review: Not approved (b26e45a)

To get the bot's approval:

  • changes to .github/workflows/ci.yml need a human approval

This is review 7 of this pull request. After 3 reviews the model's findings no longer block approval (max-blocking-reviews); security concerns, files not fully reviewed, open threads of the bot and paths a person approves still do.

This comment is updated on every review. The review comment and its threads have the details.

@devnullexile devnullexile left a comment

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.

The revised timing test misses a response-latency regression, and the Windows lifecycle deadline can discard the timeout evidence it is meant to capture.

Comment thread .github/workflows/ci.yml
# 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.
# A real hang still fails here instead of at the 60-minute job limit.
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.

Comment thread tests/test_asset_operations.py Outdated
await asyncio.sleep(0.05)
return httpx.Response(200, json={})

clock = FakeClock()

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. This clock never advances, so client_elapsed_ms stays at zero even if request_sample records the evidence timeout as the response completion time. I verified that the test still passes with that regression. Advance the clock when the POST completes and again when evidence collection times out, then assert the POST duration.

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. FakeClock advances 10 ms on the POST and 5 s on the evidence timeout, and the assertion is client_elapsed_ms == 10; recording the timeout as the response completion would fail the test.

Add a lifecycle budget to the OpenClaw install check and pass 1140 s from the CI step, so a stalled cleanup cannot let the 20-minute step deadline kill the process before the JSON export is written. Record the budget and the effective per-step timeout in the export.

Make the asset timing test advance FakeClock at the POST completion and at the evidence timeout, then assert the POST duration, so it fails when a timeout is recorded as the response completion.

RM33; RM38; AC24; AC29.

@devnullexile devnullexile left a comment

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.

The earlier response-latency comment is resolved. The test now distinguishes POST completion from the evidence timeout. The earlier comment about stacking full command timeouts is also resolved by capping each command to the remaining lifecycle budget. The inline comments cover separate issues with Windows process shutdown, cleanup test coverage, and budget input.

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.

Comment thread tests/test_openclaw_install_check.py Outdated
monkeypatch.setenv("STUB_STALL", "plugins inspect,plugins uninstall")
monkeypatch.setenv("STUB_STALL_SECONDS", "10")
monkeypatch.setattr(install_check, "EXPORT_RESERVE_SECONDS", 0.1)
export = run(stub_host, tarball, tmp_path, timeout=10, budget=3)

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] Exercise the cleanup deadline with an injected clock

The stalled inspect consumes the budget before uninstall starts. I verified that the test still passes when cleanup ignores the deadline and uninstall waits the full 10 seconds. The test also fails if runner delays consume the 2.9-second command window before inspect starts. Have inspect fail promptly, simulate an uninstall stall using an injected clock, and assert that uninstall gets only the remaining budget and the export is written.

Comment thread scripts/openclaw_install_check.py Outdated
parser.add_argument("--timeout", type=float, default=300, help="seconds per host command")
parser.add_argument(
"--budget",
type=float,

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.

[P3] Reject non-finite lifecycle budgets

--budget nan is accepted, leaves the full per-command timeout in effect, and writes "budget_seconds": NaN, which strict JSON readers reject. I reproduced this with a successful stub-host run. Reject non-finite values at argument parsing before starting the lifecycle.

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. --budget and --timeout now use a finite-float parser and reject nan/inf/-inf before the lifecycle starts; run_install_check also rejects non-finite values. A test covers the parser and the direct call.

…33; AC24)

Run host commands in their own process group, stop the whole tree on timeout, and read stdout/stderr from temporary files so a Windows respawn cannot hold inherited pipes past the budget.

Make the cleanup-deadline test inject the lifecycle clock, time out inspect promptly, stall uninstall, and assert the remaining budget and the export. Reject non-finite timeout and budget values before the lifecycle starts.
Comment on lines +765 to +770
else:

def fake_killpg(pid, sig):
calls.append(("killpg", pid, sig))

monkeypatch.setattr(install_check.os, "killpg", fake_killpg)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Question: killpg/SIGKILL on Windows

The new test_a_timed_out_host_command_stops_the_process_tree case for
platform == "linux" monkeypatches os.killpg and relies on
signal.SIGKILL. Both are Unix-only stdlib members. On a windows-latest
runner (the full suite runs this file there), monkeypatch.setattr(install_check.os, "killpg", ...) raises AttributeError because os.killpg is absent on
Windows, so the test errors in the Windows job; even if that patch used
raising=False, _stop_tree would then fail evaluating signal.SIGKILL.
That would make Windows CI red on the very test added to stabilize it.
Suggested correction: skip the linux parametrization on Windows, or patch
both os.killpg and signal.SIGKILL with raising=False (or route the
signal through a small module-level indirection) so the simulated branch can
run cross-platform. Worth confirming on a real Windows runner.

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 at 188af77. The linux parametrization is skipped on win32 (tests/test_openclaw_install_check.py:771), and the PermissionError test is also skipped there (:837), so os.killpg and signal.SIGKILL are not evaluated on Windows.

@devnullexile devnullexile left a comment

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.

All three comments from the earlier review are resolved: _run now stops the process tree on timeout and reads stdout/stderr from temporary files instead of pipes, the cleanup-deadline test uses an injected clock and verifies the remaining budget and export, and non-finite --budget/--timeout values are rejected before the lifecycle starts. One inline note on a macOS os.killpg race in _stop_tree.

Comment thread scripts/openclaw_install_check.py Outdated
else:
try:
os.killpg(process.pid, signal.SIGKILL)
except ProcessLookupError:

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.

[P3] Catch PermissionError from os.killpg on macOS

On macOS, os.killpg(process.pid, signal.SIGKILL) raises PermissionError (EPERM) if the host exits between process.wait() timing out and killpg running (while the process group leader is an unreaped zombie). Unlike os.kill, that error escapes _stop_tree without reaping the child and falls into run_steps's except OSError handler, which misrecords the timed-out step as not_run and drops its captured output.

Suggested change
except ProcessLookupError:
except (ProcessLookupError, PermissionError):

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 188af77. _stop_tree catches (ProcessLookupError, PermissionError) around os.killpg, so a macOS EPERM no longer escapes to run_steps; test_a_permission_error_from_killpg_keeps_the_timeout_evidence checks the timed_out status and the captured output.

@ArcsinX ArcsinX left a comment

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.

Found a few issues to address before merging:

  1. Windows CI is currently red: test_a_timed_out_host_command_stops_the_process_tree[linux] in tests/test_openclaw_install_check.py fails on windows-latest in both check and openclaw-plugin with AttributeError: <module 'os' (frozen)> has no attribute 'killpg' (and signal.SIGKILL is also absent on Windows).
  2. Cancel precedence gaps in orchestrator: _publish in src/relaymind/orchestrator/publish.py does not check self.cancel_requested (unlike _publication_ready), so buffered/draft answers can persist answer.delta before _run_local/_run_external cancels the run. In addition, _clarify, _escalate (local_loop.py), and _escalate_client (client_loop.py) do not check self.cancel_requested before transitioning to WAITING_INPUT/EXTERNAL_RUNNING or calling external health()/measure_request().
  3. Non-positive lifecycle timeout/budget: scripts/openclaw_install_check.py rejects nan/inf but still accepts <= 0 (or budget <= EXPORT_RESERVE_SECONDS), which silently skips all steps or immediately times out.

(Note: platform-run (ubuntu-latest) failed on an Ubuntu apt mirror network error during Playwright browser install, unrelated to this PR.)

Comment thread tests/test_openclaw_install_check.py Resolved
Comment thread scripts/openclaw_install_check.py Resolved
The linux parameter patches os.killpg and asserts signal.SIGKILL, both POSIX-only, so it cannot run on Windows. The win32 parameter still covers the Windows branch, and the POSIX branch remains covered on Linux and macOS.
…or (RM33; AC24)

Treat a PermissionError from os.killpg like a missing process. The timeout path still reaps the child, reads the captured stdout/stderr, and reports timed_out instead of falling through to run_steps' OSError path, which recorded the step as not_run.

@ArcsinX ArcsinX left a comment

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.

Re-reviewed at 188af77966aa0591e3393dd3c1394a102251dc9a:

  • Resolved: test_a_timed_out_host_command_stops_the_process_tree[linux] is now skipped on win32 (and test_a_permission_error_from_killpg_keeps_the_timeout_evidence is also skipped on win32).
  • Still open from previous review:
    1. _publish in src/relaymind/orchestrator/publish.py still lacks a self.cancel_requested guard.
    2. _escalate_client (client_loop.py) and _escalate / _clarify (local_loop.py) still lack self.cancel_requested checks.
    3. scripts/openclaw_install_check.py still accepts timeout <= 0 and budget <= EXPORT_RESERVE_SECONDS (or <= 0).
  • New findings (inline): additional cancel-precedence gaps in src/relaymind/orchestrator/generation.py (except BudgetExceededError / post-finally error paths) and _await_confirmation (src/relaymind/orchestrator/confirmation.py, called at local_loop.py:1608).

@ArcsinX ArcsinX left a comment

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.

Re-reviewed at e67749747cdbea12173c5ebf4d7b19ab617c5cd6 and resolved the previously addressed ArcsinX threads. Found two remaining cancel_requested windows across awaits in _escalate_client, _hand_off, and _run_parallel.

@ArcsinX ArcsinX left a comment

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.

LGTM. Re-reviewed at 95743426b085c9fd90786887f69418fada10cd12: both remaining cancel_requested windows across awaits in _escalate_client, _hand_off, and _run_parallel are fixed with targeted regression tests, and both ArcsinX threads have been resolved. Note: CI checks on 95743426b085c9fd90786887f69418fada10cd12 were still pending at review time.

@devnullexile devnullexile left a comment

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.

My earlier macOS killpg comment is resolved. The PermissionError path now preserves the timed_out status and captured output. The earlier POST timing, lifecycle deadline, Windows process-tree shutdown, cleanup deadline coverage, and non-finite input comments are also resolved.

monkeypatch.setattr(run, "_checklist_branch", branch)
outcome = asyncio.run(run._run_parallel(None))
assert outcome.state is RunState.CANCELLED
assert gateway.store.get_run(run.run_id).state == "cancelled"

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] Assert that cancellation prevents the parallel workflow from starting

I verified that this test still passes with the post-measurement cancel check removed. The run enters PARALLEL_RUNNING and both branch doubles run, then the post-join check returns CANCELLED and both assertions pass. Check that the workflow never started so the test catches a regression in the RM14/AC12 dispatch guarantee.

Suggested change
assert gateway.store.get_run(run.run_id).state == "cancelled"
assert gateway.store.get_run(run.run_id).state == "cancelled"
assert run.workflow is None

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 b26e45a. test_parallel_cancel_during_measure_returns_cancelled now asserts run.workflow is None, so it fails if the run enters PARALLEL_RUNNING and starts the branches; the post-join cancel remains covered by test_parallel_cancel_after_branches_returns_cancelled.

@seiko-iwasawa
seiko-iwasawa merged commit 1cebf87 into master Dec 3, 2026
8 checks passed
@seiko-iwasawa
seiko-iwasawa deleted the stabilize/ci-flakes branch December 3, 2026 08:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants