Skip to content

fix(service)!: join remaining service workers before shutdown completes - #1515

Merged
lklimek merged 34 commits into
devfrom
fix/base-service-stop
Dec 3, 2026
Merged

lklimek merged 34 commits into
devfrom
fix/base-service-stop

Conversation

@lklimek

@lklimek lklimek commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

TL;DR: A stopping node joins (waits for) its remaining service workers before shutdown completes, so no goroutines, WebSocket forwarders, or in-flight receive queues keep running past Stop.

What was done

Service.Stop and the components built on it wait for their workers to finish before returning, instead of returning while workers are still draining. This closes shutdown races and worker/subscription leaks across the service tree:

  • libs/service — stop joins the service's remaining workers before it completes.
  • P2P (internal/p2p) — the simple priority queue signals completion on its own close channel so shutdown can join it (the queue capacity bound introduced by the merged P2P queue work is unchanged); Router.OpenChannel rejects a channel open once the router is no longer running, so a late open during shutdown fails cleanly instead of racing a half-stopped router. The MConn transport joins its accept/connection workers.
  • RPC / WebSocket (rpc/jsonrpc/server, rpc/jsonrpc/client, rpc/client/http) — the WebSocket server, handler, and client join their read/write workers and release subscriptions on stop; the event loop stays correct during an error-triggered resubscribe and shutdown.
  • Node (node) — node and seed lifecycles, the HTTP server, and the RPC core env join their workers on stop.
  • Light client (light/rpc, light/proxy) — WebSocket forwarders retire with their subscriptions; subscription ownership is tracked so stop releases the upstream subscriptions it owns.
  • Supporting lifecycle fixes — internal/rpc/core, internal/proxy, internal/pubsub, internal/state/indexer, internal/statesync.

Scope note

This branch was previously stacked on the P2P priority-queue work and also adjusted the socket/gRPC remote-signer shutdown. The socket and gRPC remote signer were removed from dev by #1647, so those changes are dropped here: this PR now carries only the service-shutdown-join behaviour and is rebased onto dev after #1647.

Testing

Touched packages build and pass the race detector. New lifecycle/shutdown tests cover node (node, seed, HTTP server, rollback), light/rpc (shutdown, ownership, subscribe/unsubscribe admission), light/proxy (shutdown), rpc/jsonrpc/{client,server} (ws client, http server, ws handler), rpc/client/http (ws, join/leave, join/leave stress), internal/rpc/core, and internal/state/indexer.

Breaking changes

Service stop semantics now block until the service's workers have joined; components embedding it inherit the stricter shutdown ordering.

PR Hygiene · 448a86c

  • Bots — thepastaclaw ✓
  • Self-review — posted; again after any push
  • Build green
  • Approvals — you own every area touched; none needed

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

@coderabbitai

coderabbitai Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@thepastaclaw

thepastaclaw commented Sep 24, 2026 •

Copy link
Copy Markdown

✅ Final review complete — no blockers (commit 448a86c) · triage: normal

@lklimek lklimek added the claudius-review Trigger Claudius AI code review on this PR label Sep 25, 2026
lklimek added a commit that referenced this pull request Sep 25, 2026
Port the focused lifecycle core from #1515, replacing the local State wait workaround while retaining other service ownership mechanisms.

Co-Authored-By: OpenAI GPT-6 <[email protected]>
lklimek added a commit that referenced this pull request Oct 23, 2026
* fix(consensus): wait for receive routine during shutdown

Join the receive routine before State.Wait returns and cancel its context
on explicit Stop. This prevents node cleanup racing in-flight consensus
file writes. Add a regression test for the shutdown contract.

Co-Authored-By: OpenAI Codex GPT-6 <[email protected]>

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

* fix(service)!: share worker lifecycle for consensus shutdown

Port the focused lifecycle core from #1515, replacing the local State wait workaround while retaining other service ownership mechanisms.

Co-Authored-By: OpenAI GPT-6 <[email protected]>

* fix(consensus): preserve in-flight work during manual shutdown

Keep processing on the State parent's lifetime while canceling intake, and
let handoff callers cancel their wait without abandoning reactor-owned work.
Document the global cancellation contract, cleanup ownership and migration
boundaries; harden context lookup and close logjack's group on return.

Co-Authored-By: OpenAI GPT-6 <[email protected]>

* fix(cli): wait for node shutdown with a bounded grace period

Join node cleanup after cancellation with a configurable shutdown deadline.
Return an error on timeout without bypassing service joins or store ordering.
Organize BaseService startup into lock-scoped lifecycle phases.

<sub>🤖 Co-authored by [Claudius the Magnificent](https://github.com/lklimek/claudius) AI Agent</sub>

Co-Authored-By: Codex <[email protected]>

* fix(service): cancel the attempt before deferred shutdown hooks

Stop during startup publishes the stop request, releases the lifecycle
lock and only then cancels the attempt context. If OnStart returned in
that window, Start ran OnStop on a still-live context, breaking the
cancellation-before-OnStop contract. finishStop now cancels first;
cancellation is idempotent.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(blocksync): join the synchronizer drain before reactor shutdown completes

On node cancellation the Synchronizer's own stop can win the race and
block in OnStop until in-flight block application returns. The reactor's
Stop call then returned immediately, so reactor Wait could release store
teardown while Apply was still running. The reactor now waits for the
Synchronizer after stopping it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(blocksync): join the synchronizer regardless of the sync flag

poolRoutine clears blockSyncFlag after a Stop that returns early when
the synchronizer's own cancellation-driven stop is still draining, so a
flag-gated join in reactor OnStop could be skipped and reactor Wait
could release store teardown before the consumer finished. OnStop now
stops and waits for any constructed synchronizer; both calls are no-ops
for one that never started. The regression now also runs poolRoutine
through the handover before reactor shutdown.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(privval): make the signer's initial connect request cancellation-aware

SignerListenerEndpoint.OnStart sent its first connection request on an
unbuffered channel unconditionally. With Stop now cancelling OnStart's
context, serviceLoop can exit on ctx.Done before taking the request,
leaving Start blocked forever and OnStop never run. The send now also
selects on ctx.Done and returns nil, so the regular shutdown path still
releases the listener and ping ticker.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(consensus): close the unstarted WAL group in TestWALSearchForEndHeight

OpenGroup detaches the head AutoFile worker from the caller's context,
so the never-started WAL leaked its timer/SIGHUP worker. Register the
group's Close as cleanup and take the leak snapshot at test start so
the check covers the WAL's lifetime.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(service): reject canceled contexts at worker admission

Parent cancellation closes the attempt context before the async watcher
takes the lifecycle lock and publishes stopping. In that window Go still
admitted work, e.g. a consensus handoff that could reach State.Start
during shutdown. Go now also refuses a canceled ctx under the lock.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: OpenAI GPT-6 <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
@lklimek lklimek changed the title fix(service)!: join background work before shutdown completes fix(service)!: join remaining service workers before shutdown completes Oct 23, 2026

@claudbot claudbot Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid lifecycle refactor with genuinely non-tautological tests backing it — nothing here blocks merge. One real regression worth a look: the pprof/Prometheus admin servers lost their shutdown timeout, so a single stalled client can hang node shutdown forever. The rest is documentation drift and teardown-logic duplication that's safe to leave for a fast-follow, not a gate.

4 finding(s) posted: 4 inline, 0 in this body.

🤖 Co-authored by Claudius the Magnificent AI Agent
📊 View full HTML review report

Comment thread node/setup.go Resolved
Comment thread docs/architecture/service-lifecycle.md Resolved
Comment thread UPGRADING.md Resolved
Comment thread node/node.go Resolved
@claudbot claudbot Bot removed the claudius-review Trigger Claudius AI code review on this PR label Oct 23, 2026
@lklimek
lklimek marked this pull request as ready for review October 23, 2026 09:09
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Oct 23, 2026
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final validation — Phase 1 + Phase 2

Verified the supplied findings against head 1ff0319 and confirmed two blocking shutdown defects: stalled ABCI socket I/O and uncancellable light-proxy WebSocket cleanup can prevent the newly introduced joins from completing. The overlapping WebSocket findings are combined below. This was a static review; current build, test, vet, lint, and vulnerability checks pass, while PR Hygiene remains pending.

🔴 2 blocking

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.1-sol (effort low) — The change is large and concurrency-intensive, but the diff changes worker ownership and shutdown ordering rather than consensus rules, cryptography, key handling, peer-facing deserialization, funds movement, or storage migrations.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — tenderdash-consensus-security (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `abci/server/socket_server.go`:
- [BLOCKING] abci/server/socket_server.go:160-164: Close accepted ABCI sockets before joining their I/O workers
  Registering both connection routines with BaseService.Go makes SocketServer.Wait depend on their network operations finishing, but OnStop only cancels each connection context: connsClose stores ccancel at line 114, not a transport closer. When handleResponses is blocked in WriteMessage or bw.Flush and handleRequests is waiting for the next request, neither can observe cancellation or invoke closer. Context cancellation does not interrupt those socket operations, so Wait can now block indefinitely. Register cleanup that cancels the connection and closes its transport before joining the workers. Keep registry removal separate from callbacks invoked under connsMtx, because invoking the existing closer there would recursively acquire that mutex through rmConn. Add a regression covering shutdown with a blocked response write and an outstanding request read.

In `rpc/jsonrpc/server/ws_handler.go`:
- [BLOCKING] rpc/jsonrpc/server/ws_handler.go:292-294: Make light-proxy disconnect cleanup cancellable before joining it
  This synchronous callback is now part of the handler completion that Serve joins. The in-tree light proxy installs an OnDisconnect callback at light/proxy/proxy.go:105-106 that calls p.Client.UnsubscribeAll(context.Background(), remoteAddr). With the real HTTP-backed client, that delegates through wsEvents.UnsubscribeAll to WSClient.Send, whose only exit paths are an unbuffered send and cancellation of the supplied context. The upstream client inherits the proxy lifetime, so its writer can exit on proxy cancellation before disconnect cleanup runs. The background-context send then has no receiver and never returns, even for a downstream session that never subscribed; Serve consequently remains blocked in requests.Wait. Although the unbounded send predates this PR, joining the handler turns it into a shutdown dependency. Fix the callback in the light-proxy owning layer using the proxy lifetime or explicitly bounded cleanup. Also propagate cancellation in light/rpc.Client.UnsubscribeWS and UnsubscribeAllWS, whose background-context sends can similarly strand the newly joined reader. Add a regression using the real HTTP-backed client with the upstream writer already stopped; the current session-worker test does not install this callback.

Comment thread abci/server/socket_server.go Resolved
Comment thread rpc/jsonrpc/server/ws_handler.go Resolved
@github-actions

Copy link
Copy Markdown

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Oct 23, 2026
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Oct 23, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 1 + Phase 2

The lifecycle migration fixes both previously reported shutdown blockers, but a blocking startup-rollback defect remains in the routed ABCI client: successful children are left running when a later child fails to start. Two non-blocking shutdown concerns also remain around holding mutexes across waits and network I/O. Build, test, lint, vet, and security checks are passing at the exact head; PR Hygiene remains pending while waiting for bot reviews.

🔴 1 blocking | 🟡 2 suggestion(s)

1 finding(s) not shown inline (the lines are not part of this PR's diff)

🟡 Suggestion: Signer listener OnStop waits on worker-held mutex across network I/O
privval/signer_listener_endpoint.go:91-105

OnStop takes instanceMtx before calling Close, but pingLoop calls SendRequest while holding the same mutex through WriteMessage and ReadMessage. Those operations use the configured read/write deadline, five seconds by default, so shutdown cannot close the connection or finish OnStop until the in-flight request times out. This conflicts with the BaseService contract that OnStop unblocks managed workers rather than waiting for them, and makes every shutdown unnecessarily dependent on the network deadline. Close or otherwise interrupt the active connection before waiting for instanceMtx, or restructure request serialization so network I/O is not performed while holding the shutdown-critical mutex.

source: muse-spark-1.3-contributor (phase1-reviewer: general)

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.1-sol (effort low) — This is a large, intricate concurrency and shutdown migration, but the described diff changes worker ownership and draining rather than consensus rules, cryptography, key handling, peer-facing deserialization, or storage migrations.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — tenderdash-consensus-security (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `abci/client/routed_client.go`:
- [BLOCKING] abci/client/routed_client.go:132-161: Stop already-started routed clients when a child startup fails
  `OnStart` starts each routed child independently and accumulates errors, but it does not stop children that started successfully when a later child returns an error. `BaseService` does not invoke `OnStop` after a failed `OnStart`; it only cancels the routed client's own context and joins work registered through that service. Consequently, a partial startup failure leaves earlier socket, gRPC, or local clients running with their connections and workers alive. This violates the PR's stated failed-startup cleanup guarantee and is especially visible when node startup rollback waits on the failed routed parent. Track the children started by this attempt and stop and wait for only those children before returning the startup error, while preserving ownership of clients that were already running before this attempt.

In `privval/signer_listener_endpoint.go`:
- [SUGGESTION] privval/signer_listener_endpoint.go:91-105: Signer listener OnStop waits on worker-held mutex across network I/O
  `OnStop` takes `instanceMtx` before calling `Close`, but `pingLoop` calls `SendRequest` while holding the same mutex through `WriteMessage` and `ReadMessage`. Those operations use the configured read/write deadline, five seconds by default, so shutdown cannot close the connection or finish `OnStop` until the in-flight request times out. This conflicts with the `BaseService` contract that `OnStop` unblocks managed workers rather than waiting for them, and makes every shutdown unnecessarily dependent on the network deadline. Close or otherwise interrupt the active connection before waiting for `instanceMtx`, or restructure request serialization so network I/O is not performed while holding the shutdown-critical mutex.

In `internal/p2p/router.go`:
- [SUGGESTION] internal/p2p/router.go:300-306: OpenChannel failure path waits for queue close while holding channel lock
  When `r.Go` rejects the channel worker, this path removes the queue, closes it, and waits for `queue.closed()` while the surrounding `channelMtx` write lock is still held by the deferred unlock. During shutdown, `OnStop` needs the same lock to snapshot channel queues, and concurrent `OpenChannel` calls are also blocked until the queue worker finishes. The queue normally exits quickly after cancellation, but there is no need to hold the map lock during that wait. Remove the failed entry under `channelMtx`, release the lock, and then close and join the queue.

Comment thread abci/client/routed_client.go Resolved
Comment thread internal/p2p/router.go Resolved
@github-actions

Copy link
Copy Markdown

Your move: thepastaclaw requested changes on this head; dismiss the review or push a fix; thepastaclaw left review threads unresolved; resolve them.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed and removed waiting-bots Waiting for the review bots to report on this head labels Oct 23, 2026
@Claudius-Maginificent

Copy link
Copy Markdown
Collaborator

Re-review at b845e6c, suggestion on privval/signer_listener_endpoint.go:91-105 (no inline thread): addressed in b720244. SendRequest holds the endpoint mutex across signer I/O, so Stop used to wait up to the read/write deadline. OnStop now closes the active connection before taking that mutex, using a separately locked mirror of the connection so it doesn't need the I/O lock. Regression: TestListenerStopInterruptsPendingRequest.

🤖 Co-authored by Claudius the Magnificent AI Agent

@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added waiting-bots Waiting for the review bots to report on this head and removed waiting-self-review Waiting for the author to post /self-reviewed labels Oct 23, 2026

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 1 + Phase 2

The lifecycle migration fixes the five prior shutdown findings, but failed node and seed startup still leaves non-service resources open. The rollback joins child services but does not perform the cleanup implemented in OnDrain, so stores, sinks, private-validator resources, and auxiliary workers can remain allocated after Start returns an error. Several CI checks remain in progress; completed build, vet, lint, and application checks are successful.

🔴 1 blocking

Review provenance

Source: reviewer 1: muse-spark-1.3-contributor (agent: phase1-reviewer, role: general); reviewer 2: gpt-6.1-sol (agent: phase2-reviewer, role: general); reviewer 3: gpt-6.1-sol (agent: phase2-reviewer, role: tenderdash-consensus-security); final verifier: gpt-6.1-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.1-sol (effort low) — The change is large and concurrency-intensive, but the diff changes worker ownership and shutdown ordering rather than consensus rules, funds movement, cryptography, key handling, peer-facing deserialization or storage migrations.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh verifier: gpt-6.1-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.1-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.1-sol — tenderdash-consensus-security (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify each finding against the current code and only fix it if needed.

In `node/node.go`:
- [BLOCKING] node/node.go:494-498: Release node-owned resources when startup fails
  This rollback cancels the startup attempt and joins the children started by OnStart, but it never performs the node's non-service teardown. BaseService.drainFailedStart intentionally does not invoke Finalizer.OnDrain after a failed OnStart, so resources released only by nodeImpl.OnDrain—such as shutdownOps resources, the block store, and the state store—remain open when application startup, handshake, event-bus/indexer startup, or reactor startup fails. The seed startup path has the same omission at seed.go:100-105. In an embedded node or retry loop, discarded failed nodes can retain file descriptors, database locks, private-validator resources, and background workers. After all child workers are joined, invoke the shared finalization path for failed starts; ensure the finalizer is not also invoked for the same attempt by normal shutdown.

Comment thread node/node.go Resolved
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Waiting for bot review — thepastaclaw not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 1 + Phase 2

New on this head: At ddeda5c, this round makes signer shutdown interrupt pending socket I/O and connection waits, adds bounded upstream cleanup for rejected light RPC subscriptions, removes a redundant P2P cancellation check, and updates the reconnect comment to cite its follow-up. The first tests (01) run timed out waiting for a block in TestReactorValidatorSetChanges, which uses in-memory transport rather than the changed socket receive loop. All six test shards passed on the same-head rerun; the build, lint, vet, and both end-to-end checks also passed, while PR Hygiene and the review check remain pending.

🟡 3 suggestion(s)

Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.

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: tenderdash-consensus-security); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.2-sol (effort low) — The PR is large and concurrency-heavy, but it changes worker ownership and shutdown ordering rather than consensus rules, funds movement, cryptography, signatures or key handling, peer-facing deserialization, or storage migrations.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (lane failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — tenderdash-consensus-security (completed, effort high); agent phase2-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 `privval/signer_server.go`:
- [SUGGESTION] privval/signer_server.go:52-55: A replacement signer server starts but cannot sign with a reused dialer endpoint
  Impact: An embedder that stops and joins a socket signer server and passes its dialer endpoint to a new server gets a successful `Start`, but the replacement cannot answer signing requests.
  The replacement server discards every connection it successfully dials. Before `0d719e381`, `OnStop` only closed the current socket; the new `interruptConnection` call permanently sets `interrupted` on the supplied endpoint. A fresh `SignerServer` has its own `BaseService`, but its `OnStart` does not check that flag. `ensureConnection` returns success after `SetConnection` closes and clears the new socket through `publishConn`, so `ReadMessage` returns `ErrNoConnection` and the loop dials again without the failed-dial retry delay. Scope interruption to the owning server's lifetime, or document the endpoint as single-use and reject reuse at startup.

In `privval/signer_endpoint.go`:
- [SUGGESTION] privval/signer_endpoint.go:74-75: A signer connection wait can panic on a closed handoff channel during shutdown
  Impact: An embedder using the exported `WaitConnection` can get a process panic instead of `ErrEndpointClosed` when shutdown wins the select and its handoff channel is closed and drained.
  The new shutdown branch can panic before it returns `ErrEndpointClosed`. `WaitConnection` is promoted through `SignerListenerEndpoint` and accepts a caller-supplied channel. In the branch added by `5ffbc94e7`, the nested receive from a closed, drained channel yields a nil `net.Conn`, and the unconditional `Close` panics. The built-in listener does not close its handoff channel, so this is limited to callers supplying their own. Check the receive result before closing the connection.

In `light/rpc/client.go`:
- [SUGGESTION] light/rpc/client.go:701-705: Light RPC can unsubscribe upstream after its Wait returns
  Impact: An embedder that stops and joins the light client during a WebSocket subscribe can still see an unsubscribe sent through its caller-owned upstream after the light client's `Wait` returns.
  The light client's `Wait` can return before the rejected subscription starts rolling back. `SubscribeWS` calls `next.Subscribe` before worker admission; if shutdown then causes `c.Go` to reject the forwarder, the rollback added in `6a4dee448` calls `next.Unsubscribe` with a fresh deadline. There is no registered worker to join, and `OnDrain` skips a caller-owned upstream, so that upstream can still receive the unsubscribe after `Wait` returns. The in-tree WebSocket server joins its reader and therefore covers this call when waiting for server shutdown. Admit the subscription transaction before contacting the upstream, and keep rollback within that admitted lifetime.

Comment thread privval/signer_server.go Resolved
Comment thread privval/signer_endpoint.go Resolved
Comment thread light/rpc/client.go Resolved
Comment thread privval/signer_endpoint.go Resolved
Comment thread rpc/client/http/ws.go Resolved
@github-actions

Copy link
Copy Markdown

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

lklimek and others added 3 commits November 26, 2026 08:48
Squashed net change of fix/base-service-stop up to 90226b4, restacked
linearly on fix/p2p-simple-queue-limits (#1627). The original commits
(including the dev merges) remain reachable from 90226b4.

Conflict resolved in internal/p2p/rqueue.go: keeps #1627's queue loop
(nil-channel send, no polling ticker, priority function, metrics) and this
change's closed() contract (closeCh is closed only after run returns).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
STYLE_GUIDE.md asks to track work in an issue or PR, not a TODO comment.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
On top of #1627, OpenChannel requires a running router and the simple
queue constructor takes metrics and a priority function. Start the router
in the simple queue regression helper and pass the new constructor
arguments in the delivery-callback test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…heck

WaitForShutdown returns when the dispatcher goroutine calls Done, which can
precede the goroutine's exit, so counting goroutines right after the node
stops could still see it (seen on CI in the failed-start case). Poll briefly
instead of asserting once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
lklimek and others added 3 commits November 27, 2026 12:45
Co-Authored-By: Claude Opus 5.5 <[email protected]>

# Conflicts:
#	internal/consensus/block_executor.go
#	internal/consensus/polka_block_delivery_test.go
Merging dev renamed the Unreleased section to v2.0.0, which left this PR's
additions under an already released version.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
lklimek and others added 5 commits November 29, 2026 09:17
Apply the reduced simple queue heap limit to inbound channel queues.
Preserve the existing capacity of outbound peer queues and clear
discarded heap slots after accounting and delivery notification.

Cover both queue limits, mixed-priority overflow in both arrival
orders, and complete draining of the small queue under backpressure.

Co-Authored-By: OpenAI Codex <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Count dequeued envelopes and eviction notifications in both occupancy
tests. Fail at the test deadline if any offer remains unaccounted for.

Co-Authored-By: OpenAI Codex <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Account for the rounded input buffer when checking how many envelopes
can survive an undrained burst.

Co-Authored-By: OpenAI Codex <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Set the simple priority queue heap limit to 32 times the configured
buffer size in both directions. Drop the direction flag from queue
construction and pin the shipped inbound and per-peer outbound limits.

Co-Authored-By: OpenAI Codex <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Dec 2, 2026

Copy link
Copy Markdown

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 1 + Phase 2

New on this head: This head rebases the service-lifecycle migration onto the current development line and adds the simple-priority-queue capacity, eviction, delivery-accounting, and test updates, along with minor test and documentation adjustments. The current head has no failed code checks reported; policy checks and CodeRabbit passed, while PR Hygiene and the PastaClaw review remain pending. The branch still requires conflict resolution against current dev in the queue and removed remote-signer files.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)

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: tenderdash-consensus-security); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.2-sol (effort low) — This is a large and intricate cross-cutting lifecycle change spanning P2P, consensus reactors, ABCI, RPC, mempool, indexing, and node shutdown, but it does not materially change consensus rules, cryptography, peer-facing deserialization, or storage migrations.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — tenderdash-consensus-security (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

Comment thread privval/signer_server.go Resolved
Comment thread privval/signer_endpoint.go Resolved
Comment thread light/rpc/client.go Resolved
lklimek and others added 2 commits December 2, 2026 15:39
The merge resolved internal/p2p/rqueue.go and rqueue_regression_test.go to
dev's #1627 version, but #1515's surviving fix(service)! change makes
Router.OpenChannel require a running router. Dev's regression test does not
start the router, so it fails with "router is not running". Restore #1515's
versions of both files, which start the router and carry the matching simple
queue close semantics.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Waiting for bot review — thepastaclaw reviewed an earlier commit, not yet this one. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@lklimek lklimek left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/self-reviewed

@thepastaclaw thepastaclaw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review — Final validation — Phase 1 + Phase 2

New on this head: This head merges dev after the socket and gRPC remote signer removal and restores the P2P queue’s worker-completion signal without changing its capacity, priorities, or drop accounting. The exact-head build, test groups, end-to-end checks, and lint passed; PastaClaw review and PR Hygiene are still pending.

🔴 0 blocking | 🟡 0 suggestion(s) | 💬 0 nitpick(s)

Approved: nothing here blocks the merge. The non-blocking findings are optional: fix them forward, in this PR or a follow-up, without waiting for another review round.

Follow-up candidates (optional) (1)

New non-blocking observations on code unchanged since the last full review. No inline threads are opened for them and later reviews do not repeat them: fix forward or track separately if they are worth it.

🟡 Suggestion: The lifecycle audit lists remote signer services that no longer ship
Impact: Maintainers tracing validator shutdown after the dev merge are directed to listener and dialer hooks that no longer exist.
docs/architecture/service-lifecycle.md:116

The audit points maintainers to the wrong shutdown path for validators. The dev merge brought in #1647, which removed SignerServer and the socket and gRPC signer endpoints, but the migration overview at line 58 and this table row still list them. node/setup.go now selects FilePV or DashCoreSignerClient, and node/node.go registers the latter’s Close for teardown. Remove the retired signer references from the overview and table, leaving the separate socket and gRPC ABCI coverage intact.

source: gpt-6.2-sol (phase2-reviewer: general, tenderdash-consensus-security)

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: tenderdash-consensus-security); final verifier: gpt-6.2-sol (agent: sol-verifier, role: final-verifier)

  • Triage: normal by gpt-6.2-sol (effort low) — This is a large, cross-cutting lifecycle and concurrency change spanning networking, RPC, node shutdown, and many service implementations, but it does not directly change consensus rules, cryptography, funds movement, peer-facing deserialization, or storage migrations.
  • Phase 1 reviewers: muse-spark-1.3-contributor — general (completed, effort xhigh); agent phase1-reviewer
  • Phase 1 model: muse-spark-1.3-contributor — not quota-gated; passed over gemini-3.8-flash-high (antigravity quota lookup failed), glm-5.3-flash (not used above high effort; tier asks max)
  • New since the last final review (dd25e5bc): 1 suggestion(s) on unchanged code listed as follow-up candidates
  • Fresh verifier: gpt-6.2-sol — final-verifier; agent sol-verifier
  • Phase 2 reviewers: gpt-6.2-sol — general (completed, effort high); agent phase2-reviewer, gpt-6.2-sol — tenderdash-consensus-security (completed, effort high); agent phase2-reviewer
🤖 Prompt for all review comments with AI agents
These findings are from an automated code review. Verify the current code and confirm that no unresolved issues remain.

No unresolved findings remain from the prior review on this head.

@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

Policy satisfied — this can merge.
Full checklist in the description.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority: high High priority — address soon

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants