Skip to content

fix(gateway): clamp discovery advertise timeout - #117204

Merged
steipete merged 1 commit into
openclaw:mainfrom
zhangguiping-xydt:fix/problem-g5-discovery-advertise-timeout
Aug 1, 2026
Merged

steipete merged 1 commit into
openclaw:mainfrom
zhangguiping-xydt:fix/problem-g5-discovery-advertise-timeout

Conversation

@zhangguiping-xydt

Copy link
Copy Markdown
Contributor
Additional instructions

MUST: Keep Allow edits from maintainers enabled for this PR so maintainers
can help update the branch when needed.

What Problem This Solves

Fixes an issue where Gateway startup could treat a configured discovery advertise timeout above Node's timer ceiling as approximately 1ms. A discovery service that needed only 50ms could therefore be reported as timed out almost immediately.

Why This Change Was Made

The parsed discovery timeout is now passed through the project's existing timer clamp before it reaches setTimeout. Values up to the project timer ceiling keep their configured duration, oversized values are capped consistently with other timers, and invalid values still use the existing default.

User Impact

Operators can use a large positive discovery advertise timeout without triggering TimeoutOverflowWarning or accidentally shortening Gateway startup tolerance to about 1ms.

Evidence

Fresh reproduction on latest main (c50237e37df) with a 50ms discovery advertiser:

DF_LATEST_MAIN trigger configured_timeout_ms=2147483648 advertise_delay_ms=50
TimeoutOverflowWarning: 2147483648 does not fit into a 32-bit signed integer.
Timeout duration was set to 1.
DF_LATEST_MAIN transition warning_log=gateway discovery service timed out after 2147483648ms; continuing startup
DF_LATEST_MAIN transition startup_returned elapsed_ms=4
DF_LATEST_MAIN transition advertise_completed elapsed_ms=50
DF_LATEST_MAIN outcome problem_present premature_timeout=true overflow_warning=true discovery_timeout_log=true advertise_completed=true

After the fix, an isolated real Gateway loaded a manifest-backed discovery plugin with the same timeout and delay:

DF_LIVE trigger plugin=daily-fix-discovery-delay timeout_env=2147483648 configured_delay_ms=50 gateway_port=19051
DF_LIVE transition advertise_completed elapsed_ms=60
[gateway] http server listening (1 plugin: daily-fix-discovery-delay; 118.7s)
[gateway] ready
DF_LIVE_GATEWAY gateway ready listening port=19051
DF_LIVE_PROOF outcome advertise_completed_before_gateway_ready elapsed_ms=60 overflow_warning_count=0 discovery_timeout_log_count=0

Focused verification:

  • node scripts/run-vitest.mjs run src/gateway/server-discovery-runtime.test.ts — 11 tests passed.
  • pnpm exec oxfmt --check src/gateway/server-discovery-runtime.ts src/gateway/server-discovery-runtime.test.ts — both changed files passed.

@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime size: XS labels Aug 1, 2026
@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. labels Aug 1, 2026
@clawsweeper

clawsweeper Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed August 1, 2026, 12:44 AM ET / 04:44 UTC.

ClawSweeper review

What this changes

Clamp the Gateway discovery advertise timeout after parsing so oversized configured values do not overflow Node’s timer and prematurely continue startup.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

This PR remains necessary: current main still sends any parsed positive discovery timeout directly to Node’s timer, which turns 2147483648 ms into an approximately 1 ms timeout. The PR applies the repository’s existing timer-safe clamp at that parsing boundary and includes focused coverage plus a real Gateway before/after transcript. Likely related people: steipete is the high-confidence routing contact as the recent introducer of this Gateway discovery runtime.

Priority: P2
Reviewed head: 5f19b320e8631256bff1420e90ec7b11b2cc8712

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) A small owner-local repair with focused regression coverage and convincing real Gateway behavior proof.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body contains a redacted before/after real Gateway run using a manifest-backed discovery plugin, demonstrating that the overflowing configuration no longer causes a premature timeout or overflow warning.
Patch quality 🦞 diamond lobster (5/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (live_output): The PR body contains a redacted before/after real Gateway run using a manifest-backed discovery plugin, demonstrating that the overflowing configuration no longer causes a premature timeout or overflow warning.
Evidence reviewed 7 items Current-main defect: Current main parses a positive environment value and returns it unchanged; that value becomes the delay passed to the discovery advertisement timer.
Node timer contract: The local Node 24.13.0 runtime reports delay=1 and emits TimeoutOverflowWarning for setTimeout(..., 2147483648), matching the reported premature-timeout mechanism.
Existing canonical clamp: The shared normalization helper clamps finite millisecond values into the repository’s Node-safe timer range, including values above MAX_TIMER_TIMEOUT_MS.
Findings None None.
Security None None.

How this fits together

Gateway startup invokes registered discovery plugins to advertise the local Gateway before reporting readiness. The configured advertise timeout bounds each plugin’s startup wait, then either retains its shutdown hook or logs a timeout and continues.

flowchart LR
  Config[Gateway timeout environment value] --> Parse[Strict positive timeout parsing]
  Parse --> Clamp[Timer-safe duration]
  Plugin[Discovery plugin advertise call] --> Wait[Startup wait race]
  Clamp --> Wait
  Wait --> Ready[Gateway ready or timeout warning]
  Wait --> Cleanup[Publisher shutdown hook]
Loading

Before merge

  • Complete next step (P2) - This open, cleanly mergeable PR already owns the bounded repair; it needs ordinary maintainer review and completion of the in-progress checks rather than a second repair branch.
Agent review details

Security

None.

PR surface

Source 0, Tests +35. Total +35 across 2 files.

View PR surface stats
Area Files Added Removed Net
Source 1 2 2 0
Tests 1 35 0 +35
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 2 37 2 +35

Review metrics

None.

Technical review

Best possible solution:

Merge the owner-local clamp and regression test after the current checks complete, so every parsed discovery advertise timeout is timer-safe before Gateway startup races the publisher.

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

Yes. Current main’s resolver forwards the overflowing value to the discovery timer, and a direct Node probe confirms the 1 ms overflow behavior; the PR body additionally provides a real Gateway before/after run.

Is this the best way to solve the issue?

Yes. Clamping at the timeout-resolution boundary is the narrowest maintainable repair: it preserves the existing invalid-value default while protecting every discovery publisher from the unsafe timer value.

AGENTS.md: found and applied where relevant.

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

Labels

Label justifications:

  • P2: Oversized discovery timeout values can prematurely end a Gateway startup advertisement, while ordinary and default timeout settings remain unaffected.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body contains a redacted before/after real Gateway run using a manifest-backed discovery plugin, demonstrating that the overflowing configuration no longer causes a premature timeout or overflow warning.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body contains a redacted before/after real Gateway run using a manifest-backed discovery plugin, demonstrating that the overflowing configuration no longer causes a premature timeout or overflow warning.

Evidence

What I checked:

  • Current-main defect: Current main parses a positive environment value and returns it unchanged; that value becomes the delay passed to the discovery advertisement timer. (src/gateway/server-discovery-runtime.ts:17, 618f3298c7dc)
  • Node timer contract: The local Node 24.13.0 runtime reports delay=1 and emits TimeoutOverflowWarning for setTimeout(..., 2147483648), matching the reported premature-timeout mechanism.
  • Existing canonical clamp: The shared normalization helper clamps finite millisecond values into the repository’s Node-safe timer range, including values above MAX_TIMER_TIMEOUT_MS. (packages/normalization-core/src/number-coercion.ts:163, a1b41d5ddb05)
  • Proposed owner-boundary repair: The PR applies that canonical clamp in the timeout resolver before the value reaches the setTimeout race, while retaining the existing default for unparseable values. (src/gateway/server-discovery-runtime.ts:26, 5f19b320e863)
  • Regression coverage: The added test configures 2147483648, delays the discovery publisher for 50 ms, and verifies startup waits for it without a warning before shutdown calls the returned stop hook. (src/gateway/server-discovery-runtime.test.ts:226, 5f19b320e863)
  • Feature provenance: The current discovery runtime and its test file were introduced together by Peter Steinberger in commit a1b41d5ddb; blame attributes the timeout resolver on current main to that introduction. (src/gateway/server-discovery-runtime.ts:17, a1b41d5ddb05)

Likely related people:

  • steipete: Commit a1b41d5ddb introduced the current Gateway discovery runtime and its adjacent tests, and current blame attributes the timeout resolver to that work. (role: feature introducer and recent area contributor; confidence: high; commits: a1b41d5ddb05; files: src/gateway/server-discovery-runtime.ts, src/gateway/server-discovery-runtime.test.ts)

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-08-01T04:24:12.998Z sha 1e09c561b8382a65ed7c478d4807f10f1be76db0 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the fix/problem-g5-discovery-advertise-timeout branch from 1e09c56 to 5f19b32 Compare August 1, 2026 04:39
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Aug 1, 2026
@steipete

steipete commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Land-ready verification for original contributor head 5f19b32: actual Node setTimeout(2147483648) emits TimeoutOverflowWarning and silently schedules in 1ms, making Gateway plugin discovery falsely time out immediately. The contributor fixes the canonical Gateway timeout owner with the existing clampTimerTimeoutMs helper; actual Node preserves the correct maximum 2147483647ms. The full real Gateway discovery owner suite passed 11/11, including a delayed asynchronous advertisement and its shutdown hook. Only contributor-branch repair was converting the regression Promise executor to its equivalent lint-safe block; original author and exact production fix are preserved. Proof: OPENCLAW_VITEST_MAX_WORKERS=1 node /Users/steipete/Projects/openclaw/scripts/run-vitest.mjs src/gateway/server-discovery-runtime.test.ts; actual oxlint and oxfmt both passed; fresh complete-branch Codex xhigh autoreview passed (0.99). Exact-head full hosted CI run 30684363996 attempt 2 is green, including Gateway, lint, types, QA, and openclaw/ci-gate; first attempt hit the independently diagnosed unrelated private-QA integration flake and was retried without source changes.

@steipete
steipete merged commit 4fb19fb into openclaw:main Aug 1, 2026
195 of 199 checks passed
@steipete

steipete commented Aug 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

gateway Gateway runtime P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. size: XS 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