Skip to content

fix: keep state-dir Gateway CI proof reliable under load - #135495

Merged
steipete merged 1 commit into
openclaw:mainfrom
LeizhenZhang:fix/state-dir-gateway-check-flake
Sep 1, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
LeizhenZhang:fix/state-dir-gateway-check-flake

Conversation

@LeizhenZhang

Copy link
Copy Markdown
Contributor

Related: #134403

What Problem This Solves

Fixes an issue where the state-directory Gateway integration proof could fail under CI load even though the intended production behavior was correct. A real authenticated Gateway hello can take longer than the guard's intentional 3-second offline-allow window, so the old test could observe allow and falsely expect refuse.

Why This Change Was Made

The test now separates the two contracts it was conflating:

  • one bounded real-Gateway call proves an authenticated hello publishes stateDir and configPath;
  • the state-directory comparison owner proves matching and mismatched outcomes from that same captured snapshot;
  • a focused unit case proves the successful onHelloOk path refuses without falling back to installed-service inspection.

The live test reuses one Gateway process and one authenticated hello. Its request deadline is 60 seconds and its Vitest deadline is 120 seconds, both owned only by the test. The production 3-second offline-allow policy is unchanged.

Rejected alternatives were increasing the production timeout, retrying the owner call, weakening the expected refusal, or keeping redundant live tokenless coverage. Those approaches would change or mask the production contract; the existing deterministic credential-error/protocol-probe test already owns the tokenless fallback.

User Impact

No shipped runtime behavior changes. Contributors and maintainers get a deterministic state-directory Gateway proof that remains meaningful under loaded CI runners instead of racing the production offline timeout.

Root cause and owner: src/cli/state-dir-gateway-check.server.test.ts timed a real authenticated hello through the production checkCliGatewayStateDir guard, while src/cli/state-dir-gateway-check.ts intentionally treats an ordinary transport timeout as offline and allows the command. The repair stays in the test owner; no production seam was added.

Scope: test-only, 2 files, +69/-40. Production LOC: 0. No API, config, protocol, dependency, retry, production timeout, SQLite, or persistence change. No exact active duplicate was found; #134403 introduced the original test and is linked only as provenance.

Exact head: 7a3996a1945a7289fab940d1e95d4edfb80e31e5.

Evidence

Authoritative failing-before evidence:

  • OpenClaw CI job checks-node-compact-small-50: refuses mismatched authenticated hello paths expected { kind: "refuse" } but received { kind: "allow" }. The matching and mismatched authenticated cases took about 3.26s and 3.33s, straddling the 3-second offline-allow deadline.

Corroborating pre-rebase local run on trusted main 01ea77ec3dae416a3c43cced10e7ae45e4147983:

  • 2 failed / 9 passed; matching passed in 3.291s, mismatch returned allow in 3.385s, and tokenless returned allow in 3.245s.

Post-fix evidence on the exact head:

  • focused author run: 2 files / 10 tests passed; real authenticated hello case 23.979s;
  • independent exact-head run under Node 24 with an isolated Vitest cache: 2 files / 10 tests passed; real hello case 24.516s; clean process and temporary-directory cleanup;
  • pnpm check:changed: exit 0, including formatting, typecheck, dead-export scans, and changed-file lint;
  • diff-scoped cleanup: clean;
  • final branch autoreview: no actionable P0-P2 findings;
  • independent exact-head verification: accepted.

Test-audit judgment: the real call proves the external Gateway hello boundary once; the pure comparison reuses its captured evidence for both outcomes; deterministic unit coverage protects callback wiring and fallback ownership. This avoids redundant live cases while preserving the observable invariant.

@openclaw-barnacle openclaw-barnacle Bot added cli CLI command changes size: S labels Sep 1, 2026
@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@LeizhenZhang
LeizhenZhang marked this pull request as ready for review September 1, 2026 19:20
@LeizhenZhang

Copy link
Copy Markdown
Contributor Author

@clawsweeper review

@clawsweeper

clawsweeper Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event exact_review_queue).
Result: when the review finishes, ClawSweeper will create the durable review comment if needed or update the existing comment in place.

Re-review progress:

@steipete

steipete commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

This is also the state-directory failure blocking the native Mermaid rollout in #135342 and #135470. The same mismatch case fails on Android's exact-head fallback run and the iOS run.

I reproduced the original three-case file locally without changing the timeout. In the diagnostic run, the first connection received an authenticated hello, then its status request hit the three-second deadline; the next case received no hello before its deadline. The mismatch case also lost the beforeAll environment stubs between tests. This corroborates the fixture-lifetime problem, while distinguishing slow follow-up status work from slow authentication itself.

We will use this canonical repair once it lands. Avoiding the unused status request after receiving the hello is a separate owner-level latency follow-up; callGateway already supports cancellation from its hello observer.

Ready to land at 7a3996a1945a7289fab940d1e95d4edfb80e31e5: exact-head CI is green, fresh Codex review at the repository's P0 threshold is clean, and independent source review found no correctness gap. I checked the hello producer, callback/error ordering, Vitest's per-test environment restoration, retained fallback tests, and macOS path handling. Local git diff --check passed. The existing exact-head execution evidence reports both focused files passing (10 tests); I did not execute fork code on the credentialed maintainer host.

Production delta is zero; tests are +69/-40. The latest ClawSweeper review has no before-merge moves. This removes the CI fixture race while preserving the production three-second offline policy. Thanks @lzhan011.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 1, 2026
@clawsweeper

clawsweeper Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 3:55 PM ET / 19:55 UTC.

ClawSweeper review

What this changes

The PR captures one authenticated Gateway hello with a test-only deadline and reuses its paths to test matching and mismatched CLI/Gateway state-directory outcomes.

Regression provenance

Possible regression — probable (failure trace; reviewed change). No predecessor PR is attributed.

Merge readiness

✅ Ready for maintainer review

Keep open. The introduced test-only refactor directly addresses the recorded CI race while current main still contains the timing-sensitive three-case integration test; no blocking correctness or security concern was found.

Priority: P2
Reviewed head: 7a3996a1945a7289fab940d1e95d4edfb80e31e5

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, production-neutral test repair with recorded pre-fix CI evidence and exact-head real-Gateway validation.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (terminal): The changed production-facing test harness starts a real token-authenticated Gateway and uses the real Gateway client to obtain its hello snapshot; the supplied exact-head terminal evidence reports all 10 focused tests passing with the authenticated hello case observed after the refactor.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The changed production-facing test harness starts a real token-authenticated Gateway and uses the real Gateway client to obtain its hello snapshot; the supplied exact-head terminal evidence reports all 10 focused tests passing with the authenticated hello case observed after the refactor.
Evidence reviewed 5 items Introduced test boundary: The PR replaces the race-prone calls through the production three-second guard with one real authenticated hello and pure comparisons derived from its returned snapshot.
Production policy remains unchanged: Current main retains the intentional 3,000 ms guard deadline, records an authenticated hello, and compares it before considering installed-service or credential-probe fallback.
Current-main necessity: Current main still has the original three-case real-Gateway test that routes each case through the production guard, while the PR is the only local commit changing this surface.
Findings None None.
Security None None.

How this fits together

CLI setup commands use the state-directory guard to avoid writing credentials or configuration into a tree the running Gateway will not use. This test starts a real token-authenticated Gateway, obtains its hello snapshot, and checks the comparison owner’s allow/refuse results.

flowchart LR
  A[CLI state paths] --> D[Path comparison]
  B[Token-authenticated Gateway] --> C[Gateway hello snapshot]
  C --> D
  D --> E[Allow matching paths]
  D --> F[Refuse mismatched paths]
  G[Integration test] --> B
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Tests +29. Total +29 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 2 69 40 +29
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 69 40 +29

Review metrics

Metric Value Why it matters
Production versus test LOC production +0/-0; tests +69/-40 The change is confined to test coverage and does not alter the shipped state-directory safety guard or its timeout.

Technical review

Best possible solution:

Land the focused test-owner refactor after the normal exact-head merge checks complete, preserving the production guard’s offline-allow policy unchanged.

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

Yes. The supplied CI trace shows the failure when the authenticated Gateway call crosses the three-second guard deadline, and current main still routes this test through that unchanged deadline.

Is this the best way to solve the issue?

Yes. Separating the real hello contract from deterministic path comparison removes the timing race without increasing the production timeout, retrying production behavior, or weakening the refusal invariant.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against e4100aca8ee9.

Labels

Label changes:

  • add P2: This repairs a repeatable CI reliability problem that blocks validation of otherwise unrelated work, without changing runtime behavior for operators.
  • add proof: sufficient: Contributor real behavior proof is sufficient. The changed production-facing test harness starts a real token-authenticated Gateway and uses the real Gateway client to obtain its hello snapshot; the supplied exact-head terminal evidence reports all 10 focused tests passing with the authenticated hello case observed after the refactor.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The changed production-facing test harness starts a real token-authenticated Gateway and uses the real Gateway client to obtain its hello snapshot; the supplied exact-head terminal evidence reports all 10 focused tests passing with the authenticated hello case observed after the refactor.

Label justifications:

  • P2: This repairs a repeatable CI reliability problem that blocks validation of otherwise unrelated work, without changing runtime behavior for operators.
  • 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 (terminal): The changed production-facing test harness starts a real token-authenticated Gateway and uses the real Gateway client to obtain its hello snapshot; the supplied exact-head terminal evidence reports all 10 focused tests passing with the authenticated hello case observed after the refactor.
  • proof: sufficient: Contributor real behavior proof is sufficient. The changed production-facing test harness starts a real token-authenticated Gateway and uses the real Gateway client to obtain its hello snapshot; the supplied exact-head terminal evidence reports all 10 focused tests passing with the authenticated hello case observed after the refactor.

Evidence

What I checked:

Likely related people:

  • Ayaan Zaidi: Raw commit ef44eab adds src/cli/state-dir-gateway-check.ts:82 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: ef44eab5ed83; files: src/cli/state-dir-gateway-check.ts)
  • steipete: 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.

@steipete steipete self-assigned this Sep 1, 2026
@steipete
steipete merged commit 5131048 into openclaw:main Sep 1, 2026
182 checks passed
@steipete

steipete commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes P2 Normal backlog priority with limited blast radius. 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.

2 participants