Repository navigation
fix(rpc): stop resubscribing subscription IDs as queries after reconnect - #1623
Conversation
wsEvents stored each event's subscription ID as an extra key in its subscription map, and resubscribed every key on reconnect except one equal to the subscription's latest ID. Tenderdash sends events without a subscription ID, so the empty key was resubscribed as a query: the node rejected it, and each rejection made the event loop resubscribe again a second later, stalling event delivery. Upstreams sending fresh IDs per session leaked one key per reconnect, resubscribed the same way. Nothing looks subscriptions up by ID, so drop the ID keys; the alias write was also the event loop's only map write under a read lock. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Opus 5.5 <[email protected]>
<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
|
✅ Final review complete — no blockers (commit 31434e0) |
Remove the unused subscription query field and avoid FailNow in the reconnect test's cleanup goroutine. <sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub> Co-Authored-By: Codex GPT-6 <[email protected]>
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
There was a problem hiding this comment.
Final validation — Phase 1 + Phase 2
Updated after discussion: 1 finding(s) of this review were settled in the inline threads; no blocking finding remains.
- ✅ Withdrawn: 🔴 Unsubscribe by event ID leaves the query registered locally
The query-only reconnect tracking fixes the reported empty and upstream subscription-ID replay loop, and the added reconnect test covers the real WebSocket path. However, removing the local subscription-ID alias introduces a cancellation regression: when an upstream accepts an event ID for unsubscription, the remote subscription is removed but the canonical query remains locally and is resubscribed after reconnect. CI code checks are successful; the pending review and PR Hygiene checks do not indicate a code failure.
🔴 1 0 blocking
Review provenance
Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.2-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.2-sol (agent: phase2-reviewer, role: general); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)
- Triage:
normalbygpt-6.2-sol(effort low) — This changes reconnect and subscription-tracking behavior in the HTTP RPC client and adds a substantial regression test, so it is more than a trivial contained fix but does not alter a critical surface. - Phase 1 reviewers:
muse-spark-1.3-contributor— general (completed, effort xhigh); agentphase1-reviewer - Phase 1 model:
muse-spark-1.3-contributor— not quota-gated; passed overgemini-3.8-flash-high(antigravity quota lookup failed),glm-5.3-flash(not used above high effort; tier asks max) - Second Phase-2 pass: on this first full review every Phase-2 reviewer also ran a second, independent time, and the verifier weighed both sets
- Fresh verifier:
gpt-6.2-sol— final-verifier; agentsol-verifier - Phase 2 reviewers:
gpt-6.2-sol— general (completed, effort high); agentphase2-reviewer,gpt-6.2-sol— general (completed, effort high); agentphase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review (PastaClaw). How to work through them:
- Verify each finding against the code; fix only what is real, as narrowly as the finding.
- If a finding is wrong, decline it on its thread in one or two sentences; the bot answers once and stops.
- To defer one, link a tracking issue on its thread (or reply asking the bot to file one).
- Suggestions don't block the merge, but most are worth fixing in this PR; judge each on its merits.
- Keep the PR's scope; don't grow it to satisfy hardening suggestions.
- Carried items were raised in an earlier round: read the thread first, and don't re-fix what you already fixed, declined or deferred there. Disputed and deferred items are already handled and are not listed.
In `rpc/client/http/ws.go`:
- [BLOCKING → WITHDRAWN in discussion; do not fix] rpc/client/http/ws.go:103-110: Unsubscribe by event ID leaves the query registered locally
The previous implementation recorded the nonempty ResultEvent.SubscriptionID as an alias and removed both the alias and canonical query when Unsubscribe was called with that ID. This change deletes only w.subscriptions[query]. Therefore, if a compatible upstream assigns an ID and successfully accepts ws.Unsubscribe(ctx, subscriptionID), the server-side subscription is canceled while the client's canonical query remains in w.subscriptions. The next reconnect iterates that stale query in redoSubscriptionsAfter and silently recreates the subscription, undoing the caller's cancellation. The SubscriptionClient documentation names the argument query, but the existing implementation supported ID-based cancellation and the PR explicitly targets interoperability with upstreams that provide IDs. Retain a separate ID-to-query index used only to resolve unsubscription cleanup, or otherwise resolve the supplied ID to its canonical query before deleting it, and add a regression test for unsubscribe followed by reconnect.
thepastaclaw
left a comment
There was a problem hiding this comment.
Re-review after discussion — commit 31434e0
Standing review was CHANGES_REQUESTED; this re-review is APPROVE: no blocking findings remain.
Approved: the discussion withdrew or deferred every finding the full review of 31434e05 (run 11720) raised, and the approval rests on that review.
No longer blocking:
- Unsubscribe by event ID leaves the query registered locally
Same commit as the standing review; the inline threads above carry the per-finding outcome. This follow-up exists only to correct the verdict.
Review provenance
Source: conversation lane gpt-6.2-sol (agent: conversation); no reviewer or verifier lanes ran for this follow-up
- Verdict moved because the inline discussion withdrew or deferred findings of the standing review of this commit; the code was not re-reviewed
|
Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post |
|
@thepastaclaw review No review for |
|
Policy satisfied — this can merge. |
TL;DR: Restore event subscriptions after a dropped connection without repeated errors or stalled event delivery.
User story
As a developer using
rpc/client/httpto subscribe to node events, directly or through the light client proxy, I want my subscriptions restored cleanly when the connection to the node drops and comes back, so events keep flowing without errors.Scenario
Base flow
An application subscribes to node events (for example new blocks) through the HTTP RPC client. The node restarts or the network blips, and the client reconnects.
Actual behavior
Besides each query, the client stored the subscription ID from incoming events as an extra subscription key. Tenderdash sends events with an empty subscription ID, so after the first event the client tracked an extra key
"". On every reconnect it sentsubscribe "", which the node rejects (failed to parse query: offset 0: EOF). Each rejection makes the client wait a second and resubscribe everything again, so the loop never ends: events are delayed andWS erroris logged every second. Upstreams that do send subscription IDs leaked one entry per reconnect and later resubscribed those IDs as queries.Expected behavior
After a reconnect, the client resubscribes exactly the queries it was asked to subscribe to, and events keep arriving with no errors.
Detailed discussion
What was done
rpc/client/http/ws.go: subscriptions are tracked by query only. Removed theidand unusedqueryfields, the ID alias written byeventListener(also its only map write underRLock), the alias delete inUnsubscribe, and the alias skip inredoSubscriptionsAfter. Event delivery remains keyed byresult.Query, and subscribers still receive theSubscriptionIDdata field unchanged. The undocumented ID-based cancellation path is intentionally removed; the supported cancellation argument is the original query.rpc/client/http/ws_reconnect_test.go: regression test against the node's real subscribe handler (realEventBusandrpccoreroutes behindrpcserver.NewWebsocketManager, with the node'sOnDisconnectcleanup). Across three sessions with two forced reconnects it requires that each session still delivers events and that noWS erroris logged.Testing
dev(loggedfailed to parse query: offset 0: EOF, or no resubscription on the new session) and passes repeatedly with the fix under-race, including a separate check against an upstream that assigns a new ID per session../rpc/client/http/,./rpc/client/,./light/proxy/and./light/rpc/pass with-race;gofmt,go vetandgolangci-lint --new-from-rev=origin/devare clean.dev(f2097db82),go test -mod=readonly -race -p 1 -count=1 -timeout=5m ./rpc/client/http ./rpc/client ./light/proxy ./light/rpcpasses;gofmtand the CI-pinnedgolangci-lint v2.15.0report no issues in./rpc/client/http/....TestReactorValidatorSetChangesafter its 120-second deadline. The same failure occurs ondevafter #1625; the nextdevrun also failsTestStateLock_POLSafety2. The refreshed head (31434e054) reproduces only the same 120-secondTestReactorValidatorSetChangestimeout. These are consensus failures outside this RPC diff. Historical flake tracking: Flaky tests: TestReactorValidatorSetChanges and TestRouter_EvictPeers time out intermittently on v1.6-dev #1405. The latest greendevworkflow skipped its test steps and does not establish a fix.UnsubscribeAPI accepts a query. ID aliases and the undocumented ID-based cancellation path are intentionally removed: no known subscriber uses that path. Verified Platformv5.1-dev(9ce1de7d) andv5.0-dev(a8a2e7e5): rs-dapi does not readsubscription_idor send Tenderdashunsubscribe, and legacy DAPI cancels by query. The Go interface, OpenAPI, and ADR specify query-based cancellation. Callers should use the original query; unknown third-party consumers cannot be exhaustively ruled out. The event data field and JSON-RPC request IDs are unchanged.Breaking changes
No changes to the documented API. Undocumented cancellation by an upstream event ID in the HTTP client is intentionally removed; callers must pass the original query.
Prior work
rpc/client/http/ws.goand still contains the alias logic. The two will conflict; whichever merges second must drop the aliases rather than restore them. The new test lives in its own file and will catch a regression.🤖 Co-authored by Claudius the Magnificent AI Agent
🤖 Generated with Claude Code
PR Hygiene ·
31434e0rpc/client/http/ws.go,rpc/client/http/ws_reconnect_test.go) — approved by lklimekWhen every merge requirement is met, the
PR Hygienecheck passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.