Skip to content

fix(tlon): stop SSE reconnects after client close - #108168

Merged
steipete merged 5 commits into
openclaw:mainfrom
wahaha1223:fix/tlon-cancel-sse-reconnect-backoff
Jul 29, 2026
Merged

steipete merged 5 commits into
openclaw:mainfrom
wahaha1223:fix/tlon-cancel-sse-reconnect-backoff

Conversation

@wahaha1223

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes an issue where operators stopping a Tlon channel monitor during an SSE reconnect delay could still see the closed client re-authenticate and reconnect after the delay expired. The pending retry could outlive shutdown for up to 30 seconds, or 10 seconds in the max-attempt reset path.

Why This Change Was Made

Both reconnect waits now share a client-owned abort controller that terminal close() cancels before channel cleanup. The change is limited to the Tlon SSE client's reconnect lifecycle; it does not change connection setup, retry timing, configuration, or the separate openStream timeout path.

User Impact

Stopping a Tlon monitor now cancels pending SSE reconnect work immediately, so a closed client no longer invokes re-authentication callbacks or opens another channel after shutdown. Reconnects still occur normally when the client remains open.

Evidence

AI-assisted.

Real production-path proof was run on the contributor machine with Node 24.18.0. The regression test starts a real loopback HTTP server and drives the production UrbitSSEClient through SSRF validation, channel create/wake requests, an SSE GET that ends, the production reconnect scheduler, and public close() cleanup.

Before the fix, on latest main at fc56b554, this exact command reproduced the terminal reconnect:

node scripts/run-vitest.mjs extensions/tlon/src/urbit/sse-client.reconnect-close.test.ts

Test Files  1 failed (1)
Tests       1 failed | 1 passed (2)
AssertionError: expected 1 to be +0

The failed assertion records one real onReconnect callback after close(). The second test was the negative control and passed, confirming that an uninterrupted 100 ms backoff still reconnects normally.

Premise checks:

  • The production stream path entered the logged 1000ms reconnect delay before close() ran.
  • packages/retry/src/index.ts confirms sleepWithAbort clears its timer and abort listener when its signal aborts.
  • The max-attempt sibling uses a separate 10,000 ms wait; a focused test verifies that close() cancels it before onReconnect or the normal retry delay can run.

After the fix, rebased onto 63aafd003, the same real-server path plus the extended-backoff regression and the existing SSE client suite passed:

node scripts/run-vitest.mjs extensions/tlon/src/urbit/sse-client.reconnect-close.test.ts extensions/tlon/src/urbit/sse-client.reconnect-close.unit.test.ts extensions/tlon/src/urbit/sse-client.test.ts

Test Files  3 passed (3)
Tests       25 passed (25)

Additional validation:

node scripts/run-oxlint.mjs extensions/tlon/src/urbit/sse-client.ts extensions/tlon/src/urbit/sse-client.reconnect-close.test.ts extensions/tlon/src/urbit/sse-client.reconnect-close.unit.test.ts
git diff --check upstream/main...HEAD
.agents/skills/autoreview/scripts/autoreview --mode uncommitted --stream-engine-output

Targeted lint and diff checks passed. Autoreview reported no accepted/actionable findings and judged the patch correct with 0.96 confidence.

Not tested: a credentialed remote Tlon ship. The exercised network, SSE, retry, and shutdown code is production code; the local server substitutes only the remote Urbit endpoint.

@openclaw-barnacle openclaw-barnacle Bot added channel: tlon Channel integration: tlon size: S labels Jul 15, 2026
@wahaha1223
wahaha1223 force-pushed the fix/tlon-cancel-sse-reconnect-backoff branch from 546088a to 7c58bc4 Compare July 15, 2026 08:47
@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 Jul 16, 2026
@clawsweeper

clawsweeper Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed July 29, 2026, 12:37 PM ET / 16:37 UTC.

ClawSweeper review

What this changes

The PR makes Tlon’s Urbit SSE client abort pending ordinary and max-attempt reconnect delays when monitoring stops, with loopback-server and timer regression tests.

Merge readiness

⚠️ Ready for maintainer review - 1 item remains

This remains a useful, narrowly scoped Tlon shutdown fix. The final branch cancels both delayed reconnect paths at the monitor-owned stop boundary, preserves normal active-client reconnects, and has real loopback SSE proof plus focused regression coverage; no discrete correctness or security defect is evident from the supplied final-head diff and review context.

Priority: P2
Reviewed head: 40cf85e97f9cd4ba1e3d59cb3e565c06b0e5f127

Review scores

Measure Result What it means
Overall readiness 🦞 diamond lobster (5/6) Strong real-path proof and tightly scoped lifecycle coverage support a high-confidence normal maintainer review.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The PR body provides before-and-after real loopback SSE evidence through the production client path, including public shutdown and both reconnect-delay branches; the reported successful Real behavior proof check corroborates it. Any future evidence should redact cookies, addresses, and other private endpoint details.
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 provides before-and-after real loopback SSE evidence through the production client path, including public shutdown and both reconnect-delay branches; the reported successful Real behavior proof check corroborates it. Any future evidence should redact cookies, addresses, and other private endpoint details.
Evidence reviewed 4 items Reconnect-delay ownership: The proposed client-owned abort controller is created with the SSE client and the reconnect scheduler now uses an abort-aware wait for both the 10-second exhausted-attempt cooldown and the ordinary reconnect delay, preventing either continuation from proceeding after monitoring stops.
Focused behavior coverage: The final branch adds a real loopback HTTP/SSE regression path for shutdown during reconnect and a focused timer test covering both the 1-second ordinary retry and 10-second exhausted-attempt cooldown; the PR body reports the production client path and existing SSE suite passing after the fix.
Adjacent shutdown work is separate: Merged Tlon shutdown cleanup work in commit 5bb969f concerns response-body cancellation failures, while this PR changes delayed reconnect ownership; the supplied related-item discussion identifies the paths as separate.
Findings None None.
Security None None.

How this fits together

Tlon’s channel monitor owns an Urbit SSE client that authenticates, opens an event stream, and schedules reconnects when the stream ends. Monitor shutdown stops ingress and the client, so delayed reconnect work must observe that shutdown before it can re-authenticate or open another stream.

flowchart LR
  A[Tlon channel monitor] --> B[Urbit SSE client]
  B --> C[SSE stream ends]
  C --> D[Reconnect scheduler]
  D --> E[Reconnect delay]
  A --> F[Monitoring stops]
  F --> G[Abort pending delay]
  G --> H[No post-stop reconnect]
  E --> I[Reconnect while monitor stays active]
Loading

Before merge

  • Resolve merge risk (P1) - The PR is behind current main, so maintainers should refresh exact-head merge and required-check status before landing; the supplied GitHub state reports it as cleanly mergeable, not a demonstrated three-way regression.
Agent review details

Security

None.

PR surface

Source +13, Tests +277. Total +290 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 1 21 8 +13
Tests 2 277 0 +277
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 298 8 +290

Review metrics

None.

Stored data model

Persistent data-model change detected: persistent cache schema: extensions/tlon/src/urbit/sse-client.reconnect-close.test.ts. Confirm migration or upgrade compatibility proof before merge.

Merge-risk options

Maintainer options:

  1. Decide the mitigation before merge
    Land the focused abort-aware reconnect-delay change after exact-head CI/mergeability refresh, retaining the production-path regression tests that prove stop behavior and uninterrupted active reconnect behavior.
  2. Pause or close
    Do not merge this PR until maintainers decide whether the risk is worth taking.

Technical review

Best possible solution:

Land the focused abort-aware reconnect-delay change after exact-head CI/mergeability refresh, retaining the production-path regression tests that prove stop behavior and uninterrupted active reconnect behavior.

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

Yes, source-reproducible with high confidence: the supplied loopback test drives the production SSE disconnect and delayed-reconnect path, calls the public shutdown path during the delay, and observes whether reconnect callbacks or requests occur afterward. The contributor reports that this failed before the fix and passes on the repaired path.

Is this the best way to solve the issue?

Yes: aborting the client-owned pending waits at the monitor shutdown boundary is narrower and safer than changing retry timing or adding a separate shutdown flag. It covers both retry delays while retaining the normal reconnect path for an active monitor.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides before-and-after real loopback SSE evidence through the production client path, including public shutdown and both reconnect-delay branches; the reported successful Real behavior proof check corroborates it. Any future evidence should redact cookies, addresses, and other private endpoint details.
  • add rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (live_output): The PR body provides before-and-after real loopback SSE evidence through the production client path, including public shutdown and both reconnect-delay branches; the reported successful Real behavior proof check corroborates it. Any future evidence should redact cookies, addresses, and other private endpoint details.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🦞 diamond lobster, so this older rating label is no longer current.

Label justifications:

  • P2: This fixes a bounded channel-monitor shutdown regression that can cause post-stop reconnect work, without evidence of broad runtime unavailability or data loss.
  • 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 provides before-and-after real loopback SSE evidence through the production client path, including public shutdown and both reconnect-delay branches; the reported successful Real behavior proof check corroborates it. Any future evidence should redact cookies, addresses, and other private endpoint details.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body provides before-and-after real loopback SSE evidence through the production client path, including public shutdown and both reconnect-delay branches; the reported successful Real behavior proof check corroborates it. Any future evidence should redact cookies, addresses, and other private endpoint details.

Evidence

What I checked:

  • Reconnect-delay ownership: The proposed client-owned abort controller is created with the SSE client and the reconnect scheduler now uses an abort-aware wait for both the 10-second exhausted-attempt cooldown and the ordinary reconnect delay, preventing either continuation from proceeding after monitoring stops. (extensions/tlon/src/urbit/sse-client.ts:93, 40cf85e97f9c)
  • Focused behavior coverage: The final branch adds a real loopback HTTP/SSE regression path for shutdown during reconnect and a focused timer test covering both the 1-second ordinary retry and 10-second exhausted-attempt cooldown; the PR body reports the production client path and existing SSE suite passing after the fix. (extensions/tlon/src/urbit/sse-client.reconnect-close.test.ts:1, 40cf85e97f9c)
  • Adjacent shutdown work is separate: Merged Tlon shutdown cleanup work in commit 5bb969f concerns response-body cancellation failures, while this PR changes delayed reconnect ownership; the supplied related-item discussion identifies the paths as separate. (extensions/tlon/src/urbit/sse-client.ts:476, 5bb969f7de6c)
  • Real behavior proof: The PR body records an authenticated loopback server exercising production SSRF validation, channel requests, SSE termination, reconnect scheduling, and public cleanup; the latest review context also reports a successful Real behavior proof check. (extensions/tlon/src/urbit/sse-client.reconnect-close.test.ts:1, 40cf85e97f9c)

Likely related people:

  • steipete: Authored the final two reconnect-shutdown commits on this branch, including the current head that explicitly moves cancellation to the monitor-owned stop boundary. (role: recent area contributor; confidence: high; commits: 1dfd20661991, 40cf85e97f9c; files: extensions/tlon/src/urbit/sse-client.ts, extensions/tlon/src/urbit/sse-client.reconnect-close.unit.test.ts)
  • ZengWen-DT: Authored the merged Tlon SSE shutdown cleanup change that touches the same client lifecycle but a distinct response-cancellation failure mode. (role: adjacent shutdown contributor; confidence: medium; commits: 5bb969f7de6c; files: extensions/tlon/src/urbit/sse-client.ts, extensions/tlon/src/urbit/sse-client.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-07-16T02:59:53.136Z sha 7c58bc4 :: needs maintainer review before merge. :: none

Preserve the original Tlon SSE reconnect fix while canceling both retry timers at stopReceiving(), the real monitor shutdown boundary.

Verified against an authenticated, SSRF-guarded loopback SSE server; both reconnect waits settle immediately without changing replay, close cleanup, or uninterrupted reconnection.

Co-authored-by: wahaha1223 <[email protected]>
@clawsweeper clawsweeper Bot added rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. 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 Jul 29, 2026
Prepare a conflict-free refresh of the original Tlon SSE shutdown correction without changing its ownership or losing the contributor commit.

Co-authored-by: wahaha1223 <[email protected]>
Cancel both Tlon SSE reconnect waits at stopReceiving(), the monitor-owned shutdown boundary, while preserving guarded HTTP, durable same-channel replay, and the original contributor's fix.

Verified with authenticated loopback SSE, both real retry delays, normal reconnection, all 252 Tlon tests, extension type checks, lint, and focused owner regressions.

Co-authored-by: wahaha1223 <[email protected]>
@clawsweeper clawsweeper Bot added proof: sufficient ClawSweeper judged the real behavior proof convincing. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Jul 29, 2026
@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. labels Jul 29, 2026
@steipete
steipete merged commit 030dbe9 into openclaw:main Jul 29, 2026
94 of 101 checks passed
@steipete

Copy link
Copy Markdown
Contributor

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 30, 2026
* fix(tlon): stop reconnecting after SSE client close

* fix(tlon): cancel SSE reconnect timers when monitoring stops

Preserve the original Tlon SSE reconnect fix while canceling both retry timers at stopReceiving(), the real monitor shutdown boundary.

Verified against an authenticated, SSRF-guarded loopback SSE server; both reconnect waits settle immediately without changing replay, close cleanup, or uninterrupted reconnection.

Co-authored-by: wahaha1223 <[email protected]>

* fix(tlon): prepare conflict-free reconnect refresh

Prepare a conflict-free refresh of the original Tlon SSE shutdown correction without changing its ownership or losing the contributor commit.

Co-authored-by: wahaha1223 <[email protected]>

* fix(tlon): cancel reconnect timers when monitoring stops

Cancel both Tlon SSE reconnect waits at stopReceiving(), the monitor-owned shutdown boundary, while preserving guarded HTTP, durable same-channel replay, and the original contributor's fix.

Verified with authenticated loopback SSE, both real retry delays, normal reconnection, all 252 Tlon tests, extension type checks, lint, and focused owner regressions.

Co-authored-by: wahaha1223 <[email protected]>

---------

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

Labels

channel: tlon Channel integration: tlon 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: M 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