Skip to content

fix(infra): ssh tunnel listener timeout no longer affected by clock skew - #135281

Merged
steipete merged 3 commits into
openclaw:mainfrom
xialonglee:fix/gap-ssh-tunnel-monotonic-deadline
Sep 2, 2026
Merged

steipete merged 3 commits into
openclaw:mainfrom
xialonglee:fix/gap-ssh-tunnel-monotonic-deadline

Conversation

@xialonglee

@xialonglee xialonglee commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where operators opening an SSH tunnel to a remote Gateway could receive an immediate listener timeout or wait indefinitely when the system clock changed during startup.

Why This Change Was Made

The listener-polling owner now measures elapsed time with performance.now(). It keeps the existing polling cadence and the current cancellation, readiness-join, child-reaping, and shared-stop behavior. The fix changes the clock used by the existing loop instead of adding another timeout path.

The regression cases exercise the public startSshPortForward boundary with real listener probes and timers. They move wall time forward or backward only after the first probe begins, reuse the existing synthetic-child fixture, and retain the current abort/join coverage. The private listener helper remains private.

Production delta against integrated main: +2/-2, net 0. Tests: +50/-13, net +37.

Thanks to Peter Lee (@xialonglee) for identifying and repairing the clock-skew failure and supplying the original SSH proof.

User Impact

Clock adjustments no longer determine whether SSH tunnel startup ends too early or continues beyond its polling budget. Startup cancellation and tunnel cleanup still wait for the owned work to finish.

This preserves the existing polling granularity and socket-probe timeout; it does not introduce a strict end-to-end startup deadline.

Evidence

Independent reproduction on current main

At 6426cb310d6e8be691785621ea6f0f244819facc, a maintainer-authored driver used the real public startup function, real loopback socket probes and timers, and isolated synthetic Node child processes. No SSH credentials or external host were used for this baseline.

Scenario Observed current-main result
Normal 250 ms listener budget Timeout at 267 ms
Forward 10-second wall-clock step after first probe Premature timeout at 54 ms
Backward 10-second wall-clock step after first probe Still polling until the safety abort at 904 ms
Startup owner abort Aborted and joined at 82 ms
Child exits before readiness Exit error and joined at 76 ms
Listener ready, then owner aborts Ready followed by joined shutdown at 55 ms

Every case returned only after child exit and closure of its readiness sockets. The established-tunnel case also checked that concurrent stop callers share the same promise. These observations reproduce the defect and protect the newer lifetime behavior; they are baseline results, not execution of the final revision.

Exact published revision: observed startup and cleanup tests

CI run 33616128322 completed successfully for e8c60ff3365c341580531311ce7fdf095dfc512f. The runner checked out merge 3a6d41e6db476eaeec37df60081cf0358d0f5538; both SSH source and test files are byte-identical to the reviewed published revision.

All 23 SSH tests passed, including these two new public-boundary cases:

keeps the startup budget through a 10000 ms wall-clock step  254ms
keeps the startup budget through a -10000 ms wall-clock step 254ms

Each case calls the real startSshPortForward, makes real net.connect loopback probes, and uses real timers. The clock changes only after the initial probe begins. With a 250 ms configured budget, both cases require the listener-timeout error and assert at least 200 ms of measured monotonic startup time. The 254 ms values above are Vitest's complete case durations, not separately printed startup measurements. A backward-clock hang would reach the 1,000 ms safety abort and fail the required timeout-error assertion.

The same run also passed the existing shared-stop TERM/KILL join tests, established-tunnel cancellation, startup-abort child-exit ordering, all six pending socket/retry failure/exit/abort joins, port fallback, and stderr-error controls.

The SSH child in these tests is synthetic. This is exact-revision observed proof at the changed public startup boundary with real sockets and timers; it is not an exact-revision real OpenSSH connection or authenticated Gateway-forwarding run. The earlier real-SSH evidence below remains labeled with its original revision. This addresses the latest review's request for observed forward/backward clock-step behavior without conflating these proof types.

Verified historical original-head CI

Upstream CI run 33526979240 ran the original 20fa5557cb1c7dc10feb3c9a5ee26de18abf8da4 change through merge 4651df2aae67335d0d599a9cb9d703992b7985a9. All 14 SSH tests passed, including both wall-clock regression cases at 255 ms. The tested owner and test blobs match the original PR change.

Retrieved original real-SSH proof

The contributor's proof run and artifact were downloaded and inspected, resolving the artifact-access limitation in an earlier ClawSweeper review. Its workflow has empty GitHub permissions, anonymously fetches the immutable source revisions, and runs the real OpenSSH client, real listener probes, and real timers with isolated state.

Source Forward clock scenario Backward/frozen-clock scenario
Before: f1fb06eef9b46b55359f27451c10f0ba0996b534 Rejected at 23 ms Still waiting at the 1,500 ms safety window
Original PR: 20fa5557cb1c7dc10feb3c9a5ee26de18abf8da4 Rejected at 264 ms Rejected at 256 ms

The original workflow's backward scenario holds Date.now() constant; the independent baseline above additionally performs an actual backward step. The retrieved workflow tests a stalled TEST-NET SSH connection, so this evidence proves startup-timeout behavior rather than successful authenticated Gateway forwarding.

Additional validation recorded by the contributor on the original revision

The contributor recorded 14 passing SSH boundary tests, successful core/test type checks, Oxlint and formatting, and one real SSH/Gateway forwarding QA case:

pnpm test src/infra/ssh-tunnel.test.ts --run
pnpm tsgo:core
node scripts/run-tsgo.mts -b test/tsconfig/tsconfig.core.test.infra.json --builders 1
node scripts/run-oxlint.mjs --tsconfig config/tsconfig/oxlint.core.json src/infra/ssh-tunnel.test.ts src/infra/ssh-tunnel.ts
pnpm format:check --no-error-on-unmatched-pattern -- src/infra/ssh-tunnel.test.ts src/infra/ssh-tunnel.ts
OPENCLAW_TESTBOX=1 pnpm test test/e2e/qa-lab/runtime/gateway-ssh-tunnels.test.ts --run -t "proves real forwarding"

The upstream CI and retrieved startup proof were independently inspected. The separate successful-forwarding QA command above was reported by the contributor and has not been independently rerun for the revised candidate.

Final revision validation

The final revision retains the current main's abortable readiness loop, joined socket cleanup, shared stop promise, and port allocator. A fresh independent P0 review of the complete two-file candidate passed with no findings. Exact-head CI is successful, and the final 23-test SSH boundary run is recorded above. Historical original-head evidence remains separate. A final-revision real OpenSSH/Gateway forwarding run has not been performed.

@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.

@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 1, 2026
@clawsweeper

clawsweeper Bot commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed September 2, 2026, 5:58 AM ET / 09:58 UTC.

ClawSweeper review

What this changes

This PR changes SSH tunnel readiness polling to use a monotonic clock and adds public-boundary regression tests for forward and backward wall-clock changes.

Merge readiness

⛔ Blocked until stronger real behavior proof is added - 3 items remain

The monotonic-clock repair is the correct owner-boundary change and current main still uses the wall clock, but the supplied real-SSH proof covers an earlier revision while the exact current head explicitly has final execution evidence pending. Keep this PR open for exact-head behavior proof.

Priority: P2
Reviewed head: e8c60ff3365c341580531311ce7fdf095dfc512f

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The patch is a clean, focused repair with meaningful boundary coverage, but exact-head real-behavior evidence remains a merge gate.
Proof confidence 🦪 silver shellfish (2/6) Needs stronger real behavior proof before merge: The changed production owner is the local-listener readiness loop in src/infra/ssh-tunnel.ts, reached by Gateway-status SSH probing. The supplied artifact description reports real OpenSSH behavior for original revision 20fa555, but the current head has different source/test blobs and its body says final execution evidence is pending; no exact-head observed recovery is available. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Needs proof Needs stronger real behavior proof before merge: The changed production owner is the local-listener readiness loop in src/infra/ssh-tunnel.ts, reached by Gateway-status SSH probing. The supplied artifact description reports real OpenSSH behavior for original revision 20fa555, but the current head has different source/test blobs and its body says final execution evidence is pending; no exact-head observed recovery is available. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed 6 items Current-head repair: The readiness-loop owner records and compares elapsed time with performance.now(), so Date.now() wall-clock steps no longer alter its polling budget.
Current main remains affected: The fetched current-main revision still records and compares the listener budget with Date.now(), so the PR’s central behavior is not already implemented on main.
Boundary regression coverage: The new test drives startSshPortForward with a stalled local listener, changes Date.now() only after the initial probe, and requires the real monotonic elapsed time to retain the startup budget for both clock directions.
Findings None None.
Security None None.

How this fits together

Gateway status can create an SSH local port forward to reach a remote Gateway, then waits for the local listener before probing it. Startup must either return a usable tunnel or cleanly time out or cancel while reaping the SSH child.

flowchart LR
  A[Gateway status command] --> B[Start SSH tunnel]
  B --> C[Poll local listener]
  C --> D{Listener ready in budget?}
  D -->|Yes| E[Probe remote Gateway]
  D -->|No or cancelled| F[Stop and reap SSH child]
Loading

Before merge

  • Add real behavior proof - Needs stronger real behavior proof before merge: The changed production owner is the local-listener readiness loop in src/infra/ssh-tunnel.ts, reached by Gateway-status SSH probing. The supplied artifact description reports real OpenSSH behavior for original revision 20fa555, but the current head has different source/test blobs and its body says final execution evidence is pending; no exact-head observed recovery is available. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • Resolve merge risk (P1) - The only supplied real-SSH after-fix evidence is for an earlier revision; the PR body explicitly leaves exact-head execution evidence pending, so merging would rely on source review rather than observed current-head recovery.
  • Complete next step (P2) - Publish redacted real-behavior proof for the exact current head covering forward and backward wall-clock steps through the SSH tunnel startup boundary.
Agent review details

Security

None.

PR surface

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

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

Review metrics

Metric Value Why it matters
Production versus test LOC production +0 net (2 added, 2 removed); tests +37 net (50 added, 13 removed) The fix replaces the time source in the existing owner and adds focused boundary coverage without production growth.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Keep the single monotonic readiness budget and publish a redacted exact-head trace showing both forward and backward Date.now() steps consume roughly the configured budget while startup cleanup still completes.
  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 single monotonic readiness budget and publish a redacted exact-head trace showing both forward and backward Date.now() steps consume roughly the configured budget while startup cleanup still completes.

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

Yes, at source level: current main’s Date.now()-based loop can terminate early after a forward clock step or continue after a backward one, and the PR’s boundary test models both paths. This read-only review did not execute the contributor branch.

Is this the best way to solve the issue?

Yes. Replacing the time source inside the existing readiness-loop owner preserves the existing cancellation and child-reaping design, unlike adding another timeout around its callers.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The changed production owner is the local-listener readiness loop in src/infra/ssh-tunnel.ts, reached by Gateway-status SSH probing. The supplied artifact description reports real OpenSSH behavior for original revision 20fa555, but the current head has different source/test blobs and its body says final execution evidence is pending; no exact-head observed recovery is available. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
  • remove proof: sufficient: Current real behavior proof status is insufficient, not sufficient.
  • remove rating: 🐚 platinum hermit: Current PR rating is rating: 🦪 silver shellfish, so this older rating label is no longer current.
  • remove status: 👀 ready for maintainer look: Current PR status label is status: 📣 needs proof.

Label justifications:

  • P2: This repairs bounded SSH tunnel startup reliability for remote Gateway operators without evidence of a critical outage.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🐚 platinum hermit.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs stronger real behavior proof before merge: The changed production owner is the local-listener readiness loop in src/infra/ssh-tunnel.ts, reached by Gateway-status SSH probing. The supplied artifact description reports real OpenSSH behavior for original revision 20fa555, but the current head has different source/test blobs and its body says final execution evidence is pending; no exact-head observed recovery is available. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Evidence

What I checked:

  • Current-head repair: The readiness-loop owner records and compares elapsed time with performance.now(), so Date.now() wall-clock steps no longer alter its polling budget. (src/infra/ssh-tunnel.ts:125, e8c60ff3365c)
  • Current main remains affected: The fetched current-main revision still records and compares the listener budget with Date.now(), so the PR’s central behavior is not already implemented on main. (src/infra/ssh-tunnel.ts:125, 0f553a2d6075)
  • Boundary regression coverage: The new test drives startSshPortForward with a stalled local listener, changes Date.now() only after the initial probe, and requires the real monotonic elapsed time to retain the startup budget for both clock directions. (src/infra/ssh-tunnel.test.ts:393, e8c60ff3365c)
  • Caller and sibling proof path: Gateway-status probe execution owns the tunnel lifecycle, while the Testbox SSH scenario exercises real forwarding, cleanup, strict host-key failure, and unreachable-server diagnostics through that path. (src/commands/gateway-status/probe-run.ts:76, e8c60ff3365c)
  • Revision and proof gap: The exact head is a merge commit with changed SSH tunnel source and test blobs relative to its first parent; the supplied PR body says final-revision execution and exact-head CI evidence remain pending, so earlier-revision proof cannot certify this head. (e8c60ff3365c)
  • Feature history: Recent history shows the tunnel lifecycle was substantially maintained by the reaping/join repair and that this PR’s monotonic-clock commits are new branch work rather than a current-main implementation. (src/infra/ssh-tunnel.ts:125, 174f1d98eced)

Likely related people:

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

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Publish redacted exact-head after-fix evidence for e8c60ff, showing both forward and backward wall-clock steps preserve the configured listener budget; update the PR body to trigger review, or ask a maintainer to comment @clawsweeper re-review.

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 (3 earlier review cycles)
  • reviewed 2026-09-01T15:07:35.605Z sha 3e9c89b :: needs real behavior proof before merge. :: [P2] Exercise wall-clock skew through tunnel startup
  • reviewed 2026-09-01T15:55:12.488Z sha 20fa555 :: needs real behavior proof before merge. :: none
  • reviewed 2026-09-02T01:33:05.772Z sha 20fa555 :: needs maintainer review before merge. :: none

@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. and removed rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. labels Sep 1, 2026
@xialonglee

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

CI proof has been added at exact heads. The production SSH boundary now shows the expected before/after behavior under simulated wall-clock jumps; see the updated ## Evidence section.

@clawsweeper

clawsweeper Bot commented Sep 2, 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.

@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. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 2, 2026
@steipete steipete self-assigned this Sep 2, 2026
Measure listener readiness with the monotonic clock in the existing polling owner. Preserve cancellation, joined readiness work, shared child reaping, and the canonical port allocator. Exercise forward and backward wall-clock steps through the public startup boundary with shared synthetic-child coverage.

Production net 0; tests net +37. Current-main defect and lifecycle controls reproduced; independent P0 review clean. Final execution/CI proof remains pending publication.

Co-authored-by: xialonglee <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed 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 2, 2026
@steipete
steipete merged commit 1093287 into openclaw:main Sep 2, 2026
299 of 300 checks passed
@steipete

steipete commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 3, 2026
…kew (openclaw#135281)

* fix(infra): use monotonic clock for ssh tunnel listener deadline

* fix(infra): keep ssh tunnel listener helper private and test clock skew at boundary

---------

Co-authored-by: Peter Steinberger <[email protected]>
Co-authored-by: xialonglee <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: S status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants