Skip to content

fix(tests): main search tests wait for search elements instead of one lookup - #2334

Merged
bkudiess merged 2 commits into
openclaw:mainfrom
bkudiess:bkudiess-main-search-flake-fix
Nov 19, 2026
Merged

bkudiess merged 2 commits into
openclaw:mainfrom
bkudiess:bkudiess-main-search-flake-fix

Conversation

@bkudiess

Copy link
Copy Markdown
Collaborator

Related: #2262

What Problem This Solves

Main CI keeps failing in the Mock Gateway fixture UI shard B. The search test MainSearch_MessageHitOpensItsNativeConversationWithoutSending opens Companion's main search and fails with a NullReferenceException before it types. It failed three times on 2026-11-18: main cf58b639 (run 44418135075), main 996ac69c (run 44425756439) and #2329 (run 44431345467). Contributors then have to rerun CI to get a green result.

User Impact

User impact: none. Companion behavior does not change. Main and PR CI no longer fail when the search box briefly drops out of a single UI Automation lookup.

Why This Change Was Made

Each test waited until the search box appeared and then looked it up again once with SearchEdit. If that second lookup missed the box, the test crashed. In CI the failing line was SearchEdit:205 (element.Current, after FindById(...)!). That line means the second lookup returned null, even though the wait had just seen the box. The failure screenshot shows the search flyout open with the box present. The box is the SearchHost TextBox, so the inner-Edit lookup was not involved.

SearchEditAsync replaces SearchEdit. It uses the existing WaitUiAsync with its normal 20-second limit and looks up the box again on every poll. It returns only an Edit that is enabled and supports ValuePattern. If it times out, the error names the input that was awaited and the last observed state: input missing, no Edit, Edit disabled, Edit has no ValuePattern or ready. All 21 callers use it: the main search tests and the Channels search test in the Dashboard file.

The same tests had other one-shot lookups right after waits. One was the screenshot target FindById(run, "SearchResultsList")! in the failing test. Each FindById(...)!, FindInApp(...)! or FindFirst(...)! that ran right after a wait, before the next input action, now uses a bounded re-lookup: the existing WaitForElementByIdAsync, a new WaitForInAppAsync, or a new SearchScrollAsync for the result list's scroll host, which replaces the one-shot ScrollSearch. Wait conditions that could dereference a missing element (!.Current) now use null-safe pattern checks. ComposerText returns an empty string while the composer is briefly missing, so waits keep polling and draft assertions still fail if the draft is lost. The test-timing ratchet baseline drops from 52 to 5 one-shot UIA lookups in the main search file and from 21 to 20 in the Dashboard file. The 5 that remain follow a foreground-activation action or are catch-block diagnostics.

Why it started now
  • In the 68 failed main runs from 2026-11-05 to 2026-11-13 and in all failed main runs from 2026-11-13 until cf58b639, no MainSearch test failed. The first failure was on 2026-11-18.
  • The last passing main run before the first failure was 30cfe593. The only commit between that run and the first failure is fix(tests): Systems hero proof reads the issues icon before its button hosts it #2321, which is test-only (SystemsPageProofTests.cs). ci.yml last changed on 2026-11-16.
  • SearchHost last changed on 2026-11-12 (fix: Dashboard loses the selected chat on newer Gateways #2125). No product change in the failure window affects search.
  • So this is a timing race in the test that a busier fixture shard now hits more often. It is not a product regression. The flyout and box are present in the CI failure screenshot.

Evidence

  • RED: before the fix, a temporary change in the test process made the next three WorkspaceSearchBox lookups miss after the wait first saw the box. This change was not committed. The test failed with the CI stack: NullReferenceException at SearchEdit line 205, called from the test lambda at line 181.
  • GREEN: with the fix and the same three injected misses, the test passed with OPENCLAW_GATEWAY_FIXTURE_SCREENSHOTS set to 0 and to 1. SearchEditAsync polled through the misses.
  • Second RED, for the screenshot target: after the "message result" wait returned, three SearchResultsList lookups were made to miss. With the first commit's one-shot line 190, the test failed at :190: OwnedWindowCapture.SaveCore threw ElementNotAvailableException ("control was detached or re-rendered"). With the final head, the test polled through the three misses and passed with screenshots set to 0 and to 1.
  • Without injection, all 18 changed tests (MainSearch_* and ChannelsSearch_OpensDashboardFromWorkspaceAndSettings) passed on this head with screenshots set to 0, as in the CI soak, and set to 1.

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: this changes only fixture UI tests and a timing-ratchet baseline. The CI fixture UI shards already run the changed tests on a Windows desktop runner. No product behavior, visual output or capability changes.

Validation

All checks ran on head 82ff4048264a5bfd866dc999beedf7b602b3653c, based on origin/main 757bb2272d48e499e5ece6ea8e75ddfe87602c42, with a clean tree and isolated OPENCLAW_TRAY_DATA_DIR, OPENCLAW_TRAY_APPDATA_DIR and OPENCLAW_TRAY_LOCALAPPDATA_DIR.

  • ./scripts/validate-test-timing-patterns.ps1: passed after lowering the two touched baseline entries.
  • git diff --check origin/main: passed.
  • ./build.ps1: passed ("All builds succeeded").
  • dotnet test ./tests/OpenClaw.Shared.Tests/OpenClaw.Shared.Tests.csproj: passed, 5961 passed, 29 skipped, 0 failed.
  • dotnet test ./tests/OpenClaw.Tray.Tests/OpenClaw.Tray.Tests.csproj: passed, 6829 passed, 0 failed.
  • dotnet test tests/OpenClaw.Tray.UITests -c Debug -r win-x64 -p:DevBuild=false --filter "FullyQualifiedName~GatewayFixtureUiTests.MainSearch_|FullyQualifiedName~GatewayFixtureUiTests.ChannelsSearch_OpensDashboardFromWorkspaceAndSettings" with OPENCLAW_RUN_GATEWAY_FIXTURE_UI=1: 18 of 18 passed with OPENCLAW_GATEWAY_FIXTURE_SCREENSHOTS=0, and 18 of 18 passed with =1.
  • Dual-model review (Claude Opus 5.5 and GPT-6 Astra, high reasoning) of the first commit (a0f424f6): no CRITICAL or HIGH findings. The second commit has not been reviewed. See Review Conversations.

Real Behavior Proof

  • Environment tested: local Windows 11 desktop in an active interactive session, Debug win-x64 fixture app, isolated tray profile directories, fixture Gateway
  • PR head or commit tested: 82ff4048264a5bfd866dc999beedf7b602b3653c (clean tree)
  • Exact steps or command run: the fixture UI dotnet test command in Validation. RED and GREEN used the same single-test filter on MainSearch_MessageHitOpensItsNativeConversationWithoutSending with temporary, uncommitted lookup-miss changes for WorkspaceSearchBox and SearchResultsList.
  • Evidence after fix: RED failed with NullReferenceException at SearchEdit ... GatewayFixtureMainSearchUiTests.cs:line 205, called from line 181. GREEN passed after three injected misses. Without injection, all 18 changed tests passed with screenshots set to 0 and to 1.
  • Observed result: search tests now wait for a usable search input instead of crashing on one missed lookup.
  • Screenshot or artifact links verified? N/A
  • Not verified or blocked: the original UI Automation drop was not reproduced naturally on this machine, so the race was injected. Not yet observed on CI. Assert.Null and Assert.NotNull lookups after waits were left unchanged. They have no !, so a miss fails the assertion. Tests in other files were not changed.

Security Impact

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

Compatibility and Migration

  • Backward compatible? (Yes/No) Yes
  • Config or environment changes? (Yes/No) No
  • Migration needed? (Yes/No) 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.

Review findings from the first commit (Claude Opus 5.5 and GPT-6 Astra on a0f424f; the second commit has not been reviewed):

  • LOW (both reviewers): if a poll throws ElementNotAvailableException, the timeout's "Last state" text is not updated. Fix: pass onProbeError to WaitUiAsync (99% fix confidence).
  • Fixed in the second commit: MEDIUM (Opus only), the one-shot FindById(run, "SearchResultsList")! at line 190 of the target test, along with the other one-shot lookups after waits in the touched tests.

bkudiess and others added 2 commits November 18, 2026 18:02
…of one lookup

MainSearch_MessageHitOpensItsNativeConversationWithoutSending failed on main with a NullReferenceException in SearchEdit: the search input that the preceding wait had just seen was missing from the next one-shot UIA lookup. SearchEditAsync now re-acquires the input until it is an enabled Edit that supports ValuePattern, and reports the last observed state on timeout. Every SearchEdit caller uses it.

Co-authored-by: Copilot App <[email protected]>
… of one lookup

The message-hit test still captured its screenshot from a one-shot FindById(SearchResultsList)! right after the wait that saw the list, the same failure mode as the search input. Lookups that follow a wait in the touched search tests now use bounded re-lookups (WaitForElementByIdAsync, a FindInApp variant and SearchScrollAsync for the result list scroll host), and wait conditions no longer dereference a missing element. The one-shot UIA lookup baseline drops to 5 for the search tests and 20 for the Dashboard tests.

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

clawsweeper Bot commented Nov 19, 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. P2 Normal priority bug or improvement with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. labels Nov 19, 2026
@clawsweeper

clawsweeper Bot commented Nov 19, 2026

Copy link
Copy Markdown

Codex review: needs maintainer review before merge.

What this changes

This PR replaces one-shot search-test element lookups with bounded waits and lowers the corresponding timing-pattern baselines.

Example: The message-hit test opens search with Ctrl+E and enters “lighthouse” after three transient WorkspaceSearchBox lookup misses.

  • Before: SearchEdit dereferences a missing element and throws NullReferenceException.
  • After: SearchEditAsync polls until an enabled Edit supporting ValuePattern is available, then the test continues.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused test repair with no identified correctness defects; fault-injection results are reported in the body, while hosted UI and soak validation remain unfinished.
Proof confidence 🦐 gold shrimp (3/6) Only fixture acquisition and its ratchet change; the author reports current-head Windows fixture runs and injected lookup-miss recovery, and no shipped product behavior requires separate proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Test only · Worth it: Yes · Fix scope: Complete
User problem: Contributors encounter intermittent CI failures before the search test can type into an already opened flyout.
Reason: The maintainer-authored change addresses a repeatedly recorded fixture failure without changing Companion behavior or weakening the retained assertions.

Merge readiness

✅ Ready for maintainer review

Keep open: this maintainer-authored PR repairs a test race still present on main, and the review found no actionable introduced defects.

Priority: P2
Reviewed head: 82ff4048264a5bfd866dc999beedf7b602b3653c

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway fixture UI tests drive Companion through Windows UI Automation; the changed helpers turn transient element availability into bounded acquisition while retaining navigation, focus, accessibility, and draft assertions.

flowchart LR
  A[Fixture UI tests] --> B[Bounded UIA acquisition]
  B --> C[Native SearchHost]
  C --> D[Shared search controller]
  D --> E[Fixture Gateway]
  C --> F[Navigation and draft assertions]
Loading

Technical review

Best possible solution:

Land the bounded element-acquisition repair with the existing behavioral assertions and tightened timing baseline intact.

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

Main's SearchEdit dereferences a nullable lookup after a separate readiness wait, directly explaining the reported NullReferenceException; the author reports matching injected reproduction, but this review executed no tests.

Is this the best way to solve the issue?

The defect is reacquisition after readiness; the invariant is unchanged behavioral assertions, and the smallest complete repair uses the existing polling owner to return captured usable elements, as this patch does.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 757bb2272d48.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned change and current-main defect: The full introduced diff changes only two UI-test files and their timing baseline. Main still contains SearchEdit's unchecked FindById dereference; the PR replaces that helper and migrates its callers. (tests/OpenClaw.Tray.UITests/GatewayFixtureMainSearchUiTests.cs:211, 82ff4048264a)
  • Existing polling owner reused: WaitForElementByIdAsync returns the successful poll's captured element, and WaitUiAsync retries ElementNotAvailableException through the existing fixture deadline; the added search helpers use this same boundary. (tests/OpenClaw.Tray.UITests/GatewayFixtureUiTests.cs:2380, 82ff4048264a)
  • Repeated failure independently recorded: The failure tracker records MainSearch_MessageHitOpensItsNativeConversationWithoutSending failing in main runs 44418135075 and 44425756439: Tests failing on main (tracking) #2262 (comment) and Tests failing on main (tracking) #2262 (comment).
  • Reported validation and negative controls: The supplied full PR body, sourceRevision 5637963db4609ec9de771d8be226d65058ad9dc9a8dddd557504c24f82642452, reports matching injected failures before repair, recovery afterward, and all 18 affected tests passing with screenshots disabled and enabled on the reviewed head; it also reports successful build, Shared, Tray, and timing-ratchet validation. (82ff4048264a)
  • Hosted validation remains in progress: Exact-head checks show successful fast validation and Tray/setup/integration tests, while fixture UI shard B, changed-test soak, and other UI/security checks remain in progress; no failed check was returned. (82ff4048264a)
  • Policy and simplification review: Read the complete root AGENTS.md, test-audit skill, and pr-simplify skill; no nested test AGENTS.md or maintainer-notes directory exists. The patch follows the documented captured-element polling pattern and tightens the ratchet. No helper review, build, test, or target runtime was executed during this read-only review. (docs/TEST_COVERAGE.md:899, 82ff4048264a)

Likely related people:

  • Barbara Kudiess: Raw commit 4ea07e8 adds tests/OpenClaw.Tray.UITests/GatewayFixtureMainSearchUiTests.cs:172 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 4ea07e858b81; files: tests/OpenClaw.Tray.UITests/GatewayFixtureMainSearchUiTests.cs)

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.

Review metrics

Metric Value Why it matters
Change footprint Production +0/-0; C# tests +148/-99; baseline +2/-2 Growth stays within existing fixture helpers and callers, without production machinery or new test processes.
Timing-ratchet reduction 48 fewer allowed one-shot UIA lookups Main search decreases from 52 to 5 and Dashboard from 21 to 20.

Labels

Label changes:

  • add P2: Repeated native UI test failures consume contributor and maintainer time, with no demonstrated end-user outage.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Repeated native UI test failures consume contributor and maintainer time, with no demonstrated end-user outage.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 18, 2026, 9:39 PM ET / November 19, 2026, 02:39 UTC.

@bkudiess
bkudiess merged commit aa55234 into openclaw:main Nov 19, 2026
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal priority bug or improvement with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant