Skip to content

fix: intermittent MCP question fixture cleanup failures - #150690

Merged
steipete merged 1 commit into
mainfrom
steipete/fix-flake-mcp-question-authority-20260917
Sep 17, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/fix-flake-mcp-question-authority-20260917

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Related: #150399

What Problem This Solves

Fixes intermittent CI failures in the MCP question fixture when transport cleanup outlasts the test's default 1,000 ms polling deadline.

User Impact

No user-visible runtime change. Unrelated pull requests can complete this fixture without a false cleanup failure.

Why This Change Was Made

The failing assertion checked disposed, not registration. withQuestionGateway.holdNextHello() signals receipt of connect while withholding hello-ok; the test deliberately throws after that signal, before question.request can register. withCliQuestionLoopback() aborts the HTTP request and joins its response, the MCP listener/work scope, tool cancellation, and the question Gateway before closing fixture state. The ask_user registration failure also awaits its Gateway cancellation RPCs. Only then did run.finally() set disposed, while vi.waitFor() sampled every 50 ms and failed after 1,000 ms.

The test now awaits that same run owner while hello remains held. It verifies request settlement and pending-question cleanup, and covers fixture failure both before and after registration. onTestFinished retains recovery on assertion failure or test timeout; a cancellation check prevents slow setup from starting a late request. Unexpected cleanup errors still propagate. Normal test deadlines are unchanged.

#138214 added the registration barrier and ordered cleanup, but this disposal poll remained. #149154 changed prepared CLI capture activation; this regression uses an attach grant and does not call prepare().

Evidence

Observed occurrence: checks-node-compact-large-18, run 35178148472 / job 105064503656, PR #150399 at 584a7517b: expected false to be true, old test line 545, case duration 1,666 ms.

Proof Before After
Full-file runs with four CPU-load processes 0 failures / 30 runs 0 failures / 30 runs
Controlled cancellation-handshake delay of 1,100 ms Before-registration case failed with the same boolean assertion; after-registration case passed Both cases passed

The local baseline did not reproduce spontaneously. The controlled probe held the cancellation connection using the existing hello barrier and introduced an event-loop stall before releasing it; that temporary fault injection is absent from the final diff.

Both stress samples use Node 24.21.0 on macOS arm64, CI=1, NODE_OPTIONS=--max-old-space-size=8192, OPENCLAW_VITEST_MAX_WORKERS=2, OPENCLAW_TEST_PROJECTS_PARALLEL=1, and test/vitest/vitest.gateway-core.config.ts (threads, isolate: true), matching the target CI group's worker/isolation settings.

  • All seven src/gateway/mcp-http*.test.ts files: 197 tests passed.
  • node scripts/check-changed.mjs: passed, including gateway-root test types, formatting, guards, dead-export scans, and lint.
  • git diff --check: passed.
  • Independent Codex autoreview with complete fixture context: no actionable P0–P2 findings.
  • A separate forced 1 ms test-timeout probe produced only the intended timeout and completed cleanup without an unhandled rejection, hook timeout, or retained-worker warning.

The change is limited to test sequencing and recovery. No documentation update is needed for runtime behavior.

Join the fixture owner before releasing its held handshake so loaded
runners cannot fail on a 1,000 ms polling deadline. Cover failures before
and after question registration and retain cleanup on test cancellation.

Related: #150399
@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
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.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Sep 17, 2026
@steipete
steipete marked this pull request as ready for review September 17, 2026 06:54
@steipete
steipete requested a review from a team as a code owner September 17, 2026 06:54
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Sep 17, 2026
@clawsweeper

clawsweeper Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 17, 2026, 3:19 AM ET / 07:19 UTC (Revision 2).

ClawSweeper review

What this changes

The PR makes MCP question tests await fixture cleanup directly, covers failure before and after question registration, and preserves recovery after test timeout.

Merge readiness

✅ Ready for maintainer review

This remains a useful, focused repair: current main retains the disposal poll, and no actionable patch defect was found. The previous review’s draft blocker is resolved.

Priority: P3
Reviewed head: d5641f01ed76e4f3efb10a45914fd50036bb3a22

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with relevant controlled-fault evidence, stronger lifecycle assertions, and no actionable findings.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied before/after delay results exercise the changed fixture through real MCP HTTP and Gateway WebSocket clients, the production question tool, and the real question manager; both registration stages recover after the fix, with a separate timeout-cleanup probe.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The supplied before/after delay results exercise the changed fixture through real MCP HTTP and Gateway WebSocket clients, the production question tool, and the real question manager; both registration stages recover after the fix, with a separate timeout-cleanup probe.
Evidence reviewed 6 items Introduced change and assertions: The complete introduced patch changes only the question-authority test. The replacement keeps the handshake held while awaiting the fixture owner, checks request settlement and empty pending state, and registers timeout recovery before awaiting completion.
Cleanup ownership: The fixture aborts HTTP requests, cancels pending questions, joins requests, closes the MCP listener, and joins tool execution before releasing contexts and state. The shared cleanup helper attempts every phase and preserves unexpected errors.
Current main still needs the repair: Fetched main retains the disposed flag and vi.waitFor assertion. The supplied related merged PRs cover earlier registration cleanup, CLI authority, and maintainer tooling; none establishes that this remaining poll was removed. Inspection of the latest release’s source blob failed, so release inclusion is not claimed.
Findings None None.
Security None None.

How this fits together

The MCP question fixture sends local HTTP tool requests through OpenClaw’s question tool to a synthetic Gateway backed by the real question manager. Its teardown must finish requests and tool cancellation before releasing servers and isolated state.

flowchart TD
  A[Test starts question request] --> B[Local MCP HTTP server]
  B --> C[Question tool and Gateway client]
  C --> D[Question registration barrier]
  D --> E[Injected fixture failure]
  E --> F[Abort requests and join cleanup]
  F --> G[Assert settlement and no pending questions]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Tests +21. Total +21 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 65 44 +21
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 65 44 +21

Review metrics

None.

Technical review

Best possible solution:

Keep cleanup synchronized with its existing fixture owner while preserving registration-stage assertions and finite timeout recovery.

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

Yes: current main still polls disposal under an independent deadline, and the PR records a controlled 1,100 ms handshake-delay reproduction. This read-only review verified the source path without executing that probe.

Is this the best way to solve the issue?

Yes: awaiting the existing cleanup owner removes the premature polling deadline without increasing test timeouts, weakening assertions, or adding another cleanup implementation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 68b4251368c1.

Labels

Label justifications:

  • P3: This is a focused test-reliability repair with no user-visible runtime change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The supplied before/after delay results exercise the changed fixture through real MCP HTTP and Gateway WebSocket clients, the production question tool, and the real question manager; both registration stages recover after the fix, with a separate timeout-cleanup probe.
  • proof: sufficient: Contributor real behavior proof is sufficient. The supplied before/after delay results exercise the changed fixture through real MCP HTTP and Gateway WebSocket clients, the production question tool, and the real question manager; both registration stages recover after the fix, with a separate timeout-cleanup probe.

Evidence

What I checked:

  • Introduced change and assertions: The complete introduced patch changes only the question-authority test. The replacement keeps the handshake held while awaiting the fixture owner, checks request settlement and empty pending state, and registers timeout recovery before awaiting completion. (src/gateway/mcp-http.question-authority.test.ts:516, d5641f01ed76)
  • Cleanup ownership: The fixture aborts HTTP requests, cancels pending questions, joins requests, closes the MCP listener, and joins tool execution before releasing contexts and state. The shared cleanup helper attempts every phase and preserves unexpected errors. (src/gateway/mcp-http.question-authority.test.ts:294, d5641f01ed76)
  • Current main still needs the repair: Fetched main retains the disposed flag and vi.waitFor assertion. The supplied related merged PRs cover earlier registration cleanup, CLI authority, and maintainer tooling; none establishes that this remaining poll was removed. Inspection of the latest release’s source blob failed, so release inclusion is not claimed. (src/gateway/mcp-http.question-authority.test.ts:545, 68b4251368c1)
  • Behavior-specific proof: The supplied complete PR body records a controlled 1,100 ms cancellation-handshake delay reproducing the old boolean failure and passing both repaired cases, 30 before/after stress runs, 197 passing MCP tests, and a forced-timeout probe completing without unhandled rejection or retained-worker warnings. The inspected fixture uses actual HTTP and WebSocket transport with the production question tool and question manager. These are contributor-reported results; this review executed no tests. (src/gateway/mcp-http.question-authority.test.ts:188, d5641f01ed76)
  • Review continuity: The previous review covered this same head and recorded no findings. Its sole published next step was leaving draft status; the supplied timeline records ready_for_review at 2026-09-17T06:54:41Z and the PR snapshot has draft=false. (d5641f01ed76)
  • Area history and routing: Current-main file history includes Peter Steinberger’s earlier fixture work in test(mcp): await question registration and join cleanup #138214 and Shakker’s adjacent CLI cancellation work in fix: revoke CLI tool access when a run is canceled #149154. Exact source-line introduction could not be verified because historical blobs were unavailable; routing candidates therefore have no introduction pointer. (src/gateway/mcp-http.question-authority.test.ts, 68b4251368c1)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • shakkernerd: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-17T06:53:57.785Z sha d5641f0 :: needs changes before merge. :: none

@steipete
steipete merged commit 34f548c into main Sep 17, 2026
171 checks passed
@steipete
steipete deleted the steipete/fix-flake-mcp-question-authority-20260917 branch September 17, 2026 08:11
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 18, 2026
Join the fixture owner before releasing its held handshake so loaded
runners cannot fail on a 1,000 ms polling deadline. Cover failures before
and after question registration and retain cleanup on test cancellation.

Related: openclaw#150399
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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