Skip to content

chore(tests): block new timing-sensitive test patterns and warn near CI step timeouts - #2141

Merged
bkudiess merged 2 commits into
openclaw:mainfrom
bkudiess:bkudiess-flake-prevention-guardrails
Nov 13, 2026
Merged

bkudiess merged 2 commits into
openclaw:mainfrom
bkudiess:bkudiess-flake-prevention-guardrails

Conversation

@bkudiess

@bkudiess bkudiess commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

What Problem This Solves

Fixes: new flaky test patterns keep landing on main after each flake is fixed, and a CI step can drift toward its timeout without anyone noticing until passing runs start timing out.

User Impact

No user-visible change. Contributors get an immediate CI failure that names the safe helper when a pull request adds a literal short hang guard, a fixed delay, or a one-shot UI Automation lookup to test code. CI also shows a warning annotation when a test step uses 80% or more of its timeout.

Why This Change Was Made

The November 2026 flake investigation found the same few root patterns behind most intermittent failures. Fixing individual tests did not stop new ones: while this branch was open, #2137 added 15 new one-shot lookups. This change makes the patterns visible and ratcheted, without breaking existing code:

  • Ratchet guard. A dependency-free C# scanner, tests/OpenClaw.Tray.Tests/TestTimingPatternGuard.cs, masks comments and strings, then counts three rules per test file:

    • literal hang guards under 10 s;
    • Task.Delay, Thread.Sleep, and SettleAsync used as readiness;
    • Find*(...)! and throwing Find(root, id) lookups in Tray UI Automation tests.

    Current counts are recorded in TestTimingPatternBaseline.json. Growth fails. A shrunk count only emits a warning annotation with the command that lowers the baseline (-LowerBaseline or OPENCLAW_UPDATE_TEST_TIMING_BASELINE=1, which never raise a count), so in-flight PRs that remove patterns stay green. A deliberate case can use // test-timing-exception: <reason>. The guard runs in Tray tests and, through scripts/validate-test-timing-patterns.ps1 (Add-Type), in always-on fast validation. That matters because the change classifier sends UI-test-only PRs only to the UI lane.

  • Step budget. scripts/CiStepBudget.ps1 adds -StepTimeoutMinutes to Invoke-CiTest.ps1, Invoke-CiE2e.ps1, and test-gateway-fixture.ps1. The 12 timed single-runner steps in ci.yml pass their timeout-minutes, including the new Tray UI shard. Each runner prints the share of its budget it used, warns at 80% or more, and also reports on failure. test-ci-workflow-contract.ps1 rejects drift from timeout-minutes, and a multi-command runner step must be listed as an explicit exception.

  • Docs. New "Deterministic native and timing-sensitive tests" rules in docs/TEST_COVERAGE.md, pointing at real helpers, and a matching checklist in the test-audit skill. The misplaced FileWorker coverage block moves verbatim from "Writing a regression test" to "Coverage highlights".

Baseline at introduction (current main)
Rule Occurrences Files
short-literal-hang-guard 542 95
fixed-delay-readiness 624 112
one-shot-uia-lookup 710 20

If another PR adds occurrences before this merges, this PR's ratchet will fail on rebase. Update only the named entries to match main.

Evidence

  • The clean tree passes both entry points. A deliberate new violation (one of each rule in NativeUiOwnership.cs, and a t.Wait(3000) in a Shared test) fails with file, line, and helper. Removing one Task.Delay passes with a "baseline can be lowered" warning annotation.

  • 38 focused detector tests cover:

    • each rule;
    • comments, verbatim, interpolated, and raw (including $$""") strings;
    • _/_5000 identifiers;
    • ValueTask SettleAsync declarations;
    • an exception marker inside a string (not honored);
    • growth-only failure, and lowering that never raises a count.
  • Changing a step's -StepTimeoutMinutes 25 to 24 fails the workflow contract with the step name.

  • An adversarial dual-model review (Claude Opus 5.5 + GPT-6 Astra, high effort) found no critical or high issues. Fixed:

    • stopwatch-dependent harness assertion;
    • _ crash;
    • marker in string literals;
    • ValueTask false positive;
    • raw interpolation holes;
    • budget reporting on throw;
    • multi-command step escape;
    • rename/move guidance with per-rule totals;
    • baseline line endings;
    • doc mismatches.

    Deferred, documented as limits: interpolation format-specifier text, extra equivalent forms (target-typed CancellationTokenSource, Task.WaitAll), and remove-one/add-one in the same file.

Change Type

  • Bug fix
  • Feature
  • Refactor
  • Docs or instructions
  • Tests or validation
  • Security hardening
  • Chore or infrastructure

Scope

  • Tray or WinUI UX
  • Windows node capability
  • Local MCP or winnode
  • Gateway, connection, or pairing
  • Setup or onboarding
  • Permissions, privacy, or security
  • Tests, CI, or docs

Required proof pools

  • none: test-code static analysis, CI runner reporting, and docs only. No product behavior, UI, Gateway, installer, or native capability changes.

Validation

Run on the final rebased head with an isolated tray profile (OPENCLAW_TRAY_DATA_DIR, OPENCLAW_TRAY_APPDATA_DIR, OPENCLAW_TRAY_LOCALAPPDATA_DIR set to a temporary directory):

  • ./build.ps1: passed (all builds succeeded)
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj --no-restore: passed 5,849, skipped 29 (environment-gated), failed 0
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj --no-restore: passed 6,402, failed 0 (includes 38 TestDeterminismGuardTests; rerun on 9a6822633: 6,402 passed)
  • ./scripts/validate-test-timing-patterns.ps1: passed (about 5 s)
  • ./scripts/test-ci-workflow-contract.ps1: passed (12 budgeted steps; 7 E2E harness cases including budget on success and failure)
  • ./scripts/test-ci-gate-results.ps1, test-ci-change-classifier.ps1, test-alpha-promotion.ps1, test-ci-native-failure-metadata.ps1, test-proof-evidence.ps1, test-native-animation-preference.ps1, test-ci-test-host-exit.ps1: passed
  • ./scripts/validate-docs.ps1, validate-agent-skills.ps1, test-agent-skills-validator.ps1, git diff --check: passed

Real Behavior Proof

  • Environment tested: local Windows 11 dev box, PowerShell 7.6, .NET 10 SDK.
  • PR head or commit tested: 9a68226334c875b012e63730881d663ea66027ad (based on origin/main 8d5e27bd8); full build and Shared suite ran on its parent 3d138e97, which differs only in the guard, its tests and docs.
  • Exact steps or command run: inserted deliberate violations, then ran pwsh -File scripts/validate-test-timing-patterns.ps1 and the TestCode_DoesNotAddTimingSensitivePatterns test; changed a step budget, then ran scripts/test-ci-workflow-contract.ps1.
  • Evidence after fix: ::error title=Timing-sensitive test pattern::tests/OpenClaw.Shared.Tests/SingleFlightDownloadTests.cs: short-literal-hang-guard has 1 occurrence(s), baseline 0. Lines: 138. Use a named, environment-overridable timeout ...; CI step 'Run Tray UI Tests' must pass -StepTimeoutMinutes 25 to match its timeout-minutes.
  • Observed result: violations fail with the helper to use; the clean tree passes.
  • Screenshot or artifact links verified? N/A
  • CI run on this head (43361266063, first attempt, all required checks green): fast-validation printed Test timing pattern ratchet passed. Every budgeted step printed its share, for example CI step budget: OpenClaw.Tray.UITests.Shard.trx used 9.6 of 25 minutes (38%), OpenClaw.Tray.UITests.trx used 3.5 of 25 minutes (13%), Gateway fixture checks used 19.9 of 30 minutes (66%), and E2E shard 'setup-connect' used 7.4 of 20 minutes (37%). No step reached the 80% warning.
  • Not verified or blocked: the 80% ::warning annotation was not triggered in CI (no step was near its budget); its format is covered by the workflow contract tests.

Security Impact

  • New permissions or capabilities? No
  • Secrets or tokens handling changed? No
  • New or changed network calls? No
  • Command or tool execution surface changed? No
  • Data access scope changed? No
  • If any answer is Yes, explain the risk and mitigation: N/A

Compatibility and Migration

  • Backward compatible? Yes. -StepTimeoutMinutes defaults to 0, which skips the report.
  • Config or environment changes? No (optional OPENCLAW_UPDATE_TEST_TIMING_BASELINE=1 for local baseline lowering)
  • Migration needed? No
  • If yes, list the exact upgrade steps: N/A

Review Conversations

  • I replied to or resolved every bot review conversation addressed by this PR.
  • I left unresolved only conversations that still need maintainer judgment.

…CI step timeouts

Adds a ratchet over literal short hang guards, fixed delays and one-shot UI
Automation lookups in test code, run in Tray tests and always-on fast
validation; a CI step budget report that warns at 80% of timeout-minutes;
and deterministic-test rules in TEST_COVERAGE.md and the test-audit skill.
Moves misplaced FileWorker coverage out of 'Writing a regression test'.

Co-authored-by: Copilot App <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

…n be lowered

Pull requests that remove timing-sensitive patterns stay green; the validator
emits a warning annotation with the -LowerBaseline command instead.

Co-authored-by: Copilot App <[email protected]>
@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. labels Nov 13, 2026
@clawsweeper

clawsweeper Bot commented Nov 13, 2026

Copy link
Copy Markdown

Codex review: needs changes before merge.

What this changes

This PR adds a timing-pattern baseline guard and warnings when CI test steps consume most of their timeout.

Example: A contributor adds Task.Delay(250) to a test file whose fixed-delay baseline is zero.

  • Before: CI has no timing-pattern guard for the addition.
  • After: Fast validation fails with the file, line, and suggested replacement.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused maintenance with detector and runner coverage, passing completed checks, and a narrow instruction-provenance blocker.
Proof confidence 🦐 gold shrimp (3/6) The change is test validation, CI reporting, and guidance; supplied detector and runner harness results support those boundaries without requiring Companion runtime proof.
Patch quality 🦐 gold shrimp (3/6) 2 actionable review findings remain.

Product

Kind: Maintenance · Worth it: Yes · Fix scope: Complete
User problem: Contributors repeatedly encounter flaky timing patterns and CI steps that outgrow their timeout.
Reason: Recorded incidents support the maintenance value, and collaborator authorship establishes direction without another product approval.

Merge readiness

⛔ Needs changes before merge - 1 item remains

Keep open: this collaborator-authored PR adds useful CI safeguards absent from main and needs a narrow documentation repair.

Priority: P3
Reviewed head: 9a68226334c875b012e63730881d663ea66027ad

Before merge

Findings

  • [P2] [P2] Cite the incidents behind the new instruction rules — .agents/skills/test-audit/SKILL.md:86-90
  • [P3] [P3] Document the two timeout defaults separately — docs/TEST_COVERAGE.md:762
Agent review details

How this fits together

Repository test source enters a shared scanner used by fast validation and Tray tests; existing CI runners separately report elapsed time against workflow step budgets.

flowchart LR
  A[Test source] --> B[Shared scanner]
  C[Checked in baseline] --> B
  B --> D[Fast validation and Tray tests]
  E[CI test runners] --> F[Step budget reporter]
  F --> G[Console and warning annotations]
Loading

Technical review

Best possible solution:

Retain the shared scanner and existing runner owners, with incident-linked guidance and accurate timeout defaults.

Do we have a high-confidence way to reproduce the issue?

This is preventive CI work supported by recorded timing failures; this read-only review executed no target code.

Is this the best way to solve the issue?

The problem is recurring timing-sensitive additions and unnoticed budget growth; the invariant is to preserve existing test execution and failure handling, and the shared scanner plus additive runner reporting is a focused solution.

Full review comments:

  • [P2] [P2] Cite the incidents behind the new instruction rules — .agents/skills/test-audit/SKILL.md:86-90
    The new checklist imposes readiness, geometry, ownership, and timeout rules without citing an issue, PR, or commit. Its linked guide only names a general November investigation. Add the concrete incident references beside the relevant rules or in the linked section, including the applicable cases from fix(tests): intermittent CI failures when hosted runners are under load #2129 and fix(ci): Tray UI tests fail intermittently and the step times out on passing runs #2130, so future agents can verify the constraints and their scope.
    Confidence: 0.98
  • [P3] [P3] Document the two timeout defaults separately — docs/TEST_COVERAGE.md:762
    This row says both named timeout variables default to 30 seconds, but OpenClawGatewayClientTests.StepTimeout defaults to 15 seconds; only McpFileTransportTests uses 30 seconds. State the defaults separately so contributors diagnosing a Gateway test timeout do not expect twice the actual headroom.
    Confidence: 1

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 8d5e27bd8d3a.

Provenance checked

  • CI test execution and exit handling keeps the original intent (3a71e5f: Run PR tests directly while preserving coverage on pushes and tags and retaining TRX output.)
  • E2E inactivity deadline keeps the original intent (6647e54: Fixture output must count as progress while silent process trees remain bounded and native exit status is preserved.)
  • Test-audit guidance keeps the original intent (ed1444b: Provide Windows-specific owner selection, meaningful regression coverage, and proportional test cost.)
  • File-worker coverage documentation keeps the original intent (932bc0e: Document native file-worker coverage and its distinct runtime proof boundaries; the PR moves the block without changing its content.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

Acceptance criteria:

  • pwsh -File ./scripts/validate-docs.ps1
  • pwsh -File ./scripts/validate-agent-skills.ps1
  • pwsh -File ./scripts/test-agent-skills-validator.ps1
  • git diff --check

What I checked:

Likely related people:

  • Barbara Kudiess: Raw commit ed1444b adds .agents/skills/test-audit/SKILL.md:74 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ed1444b0de69; files: .agents/skills/test-audit/SKILL.md)
  • Scott Hanselman: Raw commit 969fe6d adds scripts/Invoke-CiE2e.ps1:13 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 969fe6dad230; files: scripts/Invoke-CiE2e.ps1)
  • Dallin Romney: Raw commit 6647e54 adds scripts/Invoke-CiE2e.ps1:19 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 6647e5497dd0; files: scripts/Invoke-CiE2e.ps1)

Preflight source

Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

Labels

Label changes:

  • add P3: Preventive contributor tooling and documentation maintenance do not change shipped application behavior.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P3: Preventive contributor tooling and documentation maintenance do not change shipped application behavior.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed November 12, 2026, 11:03 PM ET / November 13, 2026, 04:03 UTC.

@bkudiess
bkudiess merged commit ee8edbc into openclaw:main Nov 13, 2026
33 checks passed
paulcam206 added a commit to paulcam206/openclaw-windows-node that referenced this pull request Nov 13, 2026
Use the ui-tests job's desktop-step guard for the native disclosure proof step, as main's Automations, animation, Axe and Local AI proof steps do, so an unrelated Tray UI failure no longer hides it, and pin the guard in the workflow contract. Mark the screenshot-only chevron settle for the timing-pattern ratchet from openclaw#2141; assertions wait for native expansion state.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P3 Low-risk cleanup, docs, polish, ergonomics, or speculative feature. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant