Skip to content

test(daemon): make managerless port fixture hermetic - #137692

Merged
vincentkoc merged 1 commit into
mainfrom
test/daemon-hermetic-port-probe-20260903
Sep 4, 2026
Merged

vincentkoc merged 1 commit into
mainfrom
test/daemon-hermetic-port-probe-20260903

Conversation

@vincentkoc

@vincentkoc vincentkoc commented Sep 4, 2026 •

Copy link
Copy Markdown
Member

Related: #137634

What Problem This Solves

Resolves a nondeterministic daemon update fixture where the managerless Linux preflight test released an ephemeral TCP port and then assumed the same port remained free. On busy hosted runners, another socket could claim the port before production inspected all four local interfaces, causing the test to observe the correct fail-closed "inspection unavailable" result instead of the expected absent-service result.

This exact failure occurred in CI jobs 100855049862 and 100857628036 at src/daemon/service.test.ts:250. The unchanged fixture also passed locally 65/65, which is consistent with a port-rebind race rather than evidence that the fixture was deterministic. The same rebind hazard is documented in src/infra/ports-probe.test.ts.

Why This Change Was Made

The existing table now controls probePortUsage through a typed partial module mock that preserves every other export. Each planned case declares an exact synthetic port and free, busy, or unknown result; every unplanned probe rejects. Installed-definition and service-manager cases also prove that no port probe occurs.

Busy and unknown cases assert the semantic fail-closed contract without coupling the fixture to production diagnostic prose. Production port probing and its strict fail-closed update policy are unchanged. No real sockets, retries, timeout changes, production seams, or relaxed assertions were added.

User Impact

No runtime behavior changes. The daemon update contract test no longer depends on host port allocation timing, so unrelated PR CI can distinguish real updater regressions from runner-local socket races.

Evidence

  • node scripts/run-vitest.mjs src/daemon/service.test.ts --reporter=dot - 66 passed
  • node scripts/run-vitest.mjs src/infra/ports-probe.test.ts src/cli/update-cli/update-command-service-maintenance.test.ts --reporter=dot - 5 passed and 13 passed
  • node_modules/.bin/oxfmt --check src/daemon/service.test.ts - passed
  • node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/daemon/service.test.ts - passed
  • node scripts/check-changed.mjs --dry-run -- src/daemon/service.test.ts - classified coreTests
  • git diff --check - passed
  • Diff-scoped autoreview through P2 - scoped clean
  • Production LOC: +0/-0; tests: +67/-42

Test audit: this extends the existing owner-boundary table, adds the missing unknown fail-closed case, removes socket lifecycle cleanup, and does not duplicate coverage or weaken production policy.

@vincentkoc vincentkoc self-assigned this Sep 4, 2026
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: S maintainer Maintainer-authored PR labels Sep 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@vincentkoc
vincentkoc force-pushed the test/daemon-hermetic-port-probe-20260903 branch from 010004e to 610de93 Compare September 4, 2026 00:05
@vincentkoc
vincentkoc marked this pull request as ready for review September 4, 2026 00:06
@vincentkoc

Copy link
Copy Markdown
Member Author

@clawsweeper review

Please run the durable correctness review for exact head 610de938126d7fce75f89d1367a77a423bf6a378. Exact-head CI has 50 branch-owned successes; the sole primary failure is the known external 60-second production advisory timeout in security-fast.

@clawsweeper

clawsweeper Bot commented Sep 4, 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:

@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 4, 2026
@clawsweeper

clawsweeper Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 3, 2026, 8:32 PM ET / September 4, 2026, 00:32 UTC.

ClawSweeper review

What this changes

The PR replaces real TCP listener setup in the managerless daemon-update test with deterministic mocked free, busy, and unknown port-usage results.

Merge readiness

⛔ Blocked before merge - 1 item remains

Keep this maintainer-authored PR open for normal handling. The exact-head diff removes a real-socket rebind race from the managerless preflight fixture while retaining and extending the fail-closed port-result coverage; no blocking correctness or security defect was found.

Priority: P3
Reviewed head: 610de938126d7fce75f89d1367a77a423bf6a378

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving test repair with an evidence-backed production boundary and no supported correctness finding.
Proof confidence 🌊 off-meta tidepool Not applicable: This MEMBER-authored, test-only change does not alter user-visible runtime behavior; the PR body supplies focused after-change test results, which are supplemental validation rather than a live-proof requirement.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: This MEMBER-authored, test-only change does not alter user-visible runtime behavior; the PR body supplies focused after-change test results, which are supplemental validation rather than a live-proof requirement.
Evidence reviewed 6 items Exact introduced fixture control: The exact-head change replaces listener allocation and close timing with a typed partial port-probe mock. Planned cases supply free, busy, or unknown results; unplanned probes reject, and the test asserts both expected probes and no-probe branches.
Production owner contract: The managerless preflight reports absent only after no effective command, no installed/running service, no active lock, and a free configured port; busy or unknown port inspection resolves to unavailable and blocks mutation.
Port-probe semantics: The real probe checks the local interfaces and returns busy immediately, retains unknown observations, and returns free only when no interface is busy or unknown. The new fixture values therefore exercise the owner boundary rather than reimplementing its behavior.
Findings None None.
Security None None.

How this fits together

Before updating code, the daemon updater determines whether a Gateway service or listener is active and blocks unsafe mutations when inspection is uncertain. This test covers the managerless Linux path that turns service and port observations into an update-safety verdict.

flowchart LR
  A[Daemon update request] --> B[Managerless preflight]
  B --> C[Inspect service state]
  C --> D[Probe configured Gateway port]
  D --> E[Safety verdict]
  E --> F[Allow or block code mutation]
  G[Deterministic test fixture] --> D
Loading

Before merge

  • Resolve merge risk (P1) - Direct Vitest source/type inspection was unavailable in this node_modules-less read-only checkout; rely on the reported exact-head focused test run and normal branch checks for final framework compatibility.
Agent review details

Security

None.

PR surface

Tests +25. Total +25 across 1 file.

View PR surface stats
Area Files Added Removed Net
Source 0 0 0 0
Tests 1 67 42 +25
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 1 67 42 +25

Review metrics

Metric Value Why it matters
Production versus test delta production +0/-0; tests +67/-42 The added table cases and mock assertions improve deterministic coverage without changing runtime behavior.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the port outcome controlled at the imported probe boundary, preserving the production fail-closed behavior while making the fixture independent of host socket allocation timing.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Keep the port outcome controlled at the imported probe boundary, preserving the production fail-closed behavior while making the fixture independent of host socket allocation timing.

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

Yes, from source: the old fixture allocated then released an ephemeral port before the production four-interface probe, creating a rebind window. No local test execution was performed because this review must keep the checkout byte-for-byte clean.

Is this the best way to solve the issue?

Yes. Mocking the imported port-probe owner preserves the tested update-policy branch while removing the unrelated host socket-timing dependency; the unexpected-call default also detects accidental probe-path drift.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a focused test-fixture reliability improvement with no intended user-visible runtime change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This MEMBER-authored, test-only change does not alter user-visible runtime behavior; the PR body supplies focused after-change test results, which are supplemental validation rather than a live-proof requirement.

Label justifications:

  • P3: This is a focused test-fixture reliability improvement with no intended user-visible runtime change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: This MEMBER-authored, test-only change does not alter user-visible runtime behavior; the PR body supplies focused after-change test results, which are supplemental validation rather than a live-proof requirement.

Evidence

What I checked:

  • Exact introduced fixture control: The exact-head change replaces listener allocation and close timing with a typed partial port-probe mock. Planned cases supply free, busy, or unknown results; unplanned probes reject, and the test asserts both expected probes and no-probe branches. (src/daemon/service.test.ts:19, 610de938126d)
  • Production owner contract: The managerless preflight reports absent only after no effective command, no installed/running service, no active lock, and a free configured port; busy or unknown port inspection resolves to unavailable and blocks mutation. (src/cli/update-cli/update-command-service-maintenance.ts:102, 610de938126d)
  • Port-probe semantics: The real probe checks the local interfaces and returns busy immediately, retains unknown observations, and returns free only when no interface is busy or unknown. The new fixture values therefore exercise the owner boundary rather than reimplementing its behavior. (src/infra/ports-probe.ts:85, 610de938126d)
  • Current-main necessity: No change to this test exists between the PR base and fetched current main, so current main still contains the listener-backed fixture that this PR replaces. (src/daemon/service.test.ts:188, cd8c74889d21)
  • Area history: Recent merged update work touched both this fixture and the managerless update owner, making Peter Steinberger a relevant routing candidate; the available history does not prove an exact source-line introduction. (src/daemon/service.test.ts:188, b026948c8faa)
  • Dependency inspection limitation: The test directly uses Vitest mock APIs, but this read-only worktree has no Vitest package sources and network access was unavailable. The PR body’s exact-head focused-test results are the available compatibility evidence; no unverified Vitest-contract claim was used for a finding.

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Jason O'Neal: 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.

@vincentkoc
vincentkoc force-pushed the test/daemon-hermetic-port-probe-20260903 branch from 610de93 to db2301c Compare September 4, 2026 01:03
@vincentkoc

Copy link
Copy Markdown
Member Author

Maintainer disposition for the sole ClawSweeper before-merge item:

Exact-head native Vitest proof passed 66/66, 5/5, and 13/13. The exact-head hosted type, changed-check, lint, dependency, and aggregate CI lanes are also green, resolving the review's node_modules-less framework-proof limitation. The mechanical rebase preserved the exact test blob and stable patch ID. ClawSweeper reported no correctness or security findings and no Rank-up moves.

@vincentkoc
vincentkoc merged commit 3c0eb9f into main Sep 4, 2026
101 checks passed
@vincentkoc
vincentkoc deleted the test/daemon-hermetic-port-probe-20260903 branch September 4, 2026 01:10
@vincentkoc

Copy link
Copy Markdown
Member Author

Merged via squash.

vincentkoc added a commit that referenced this pull request Sep 4, 2026
* origin/main:
  fix(git-hooks): keep unstaged bytes out of pre-commit formatting (#137723)
  test(gateway): drain session tool fixture cleanup (#137743)
  fix: avoid duplicate errors when a desktop disconnects (#137724)
  refactor: streamline temporary mention retention (#137714)
  fix(gateway): prevent hosted lifecycle crashes and self-waits (#137456)
  test(daemon): make managerless port fixture hermetic (#137692)
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 4, 2026
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. 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