Repository navigation
Description
Split out of #1010 (residual hazard 2 of 3), per the maintainer status update there. Verified present on current main @ ee4817d. Filed so the accept/fix/defer decision is explicit and tracked rather than buried in the umbrella (per the review note there).
The hazard
src/OpenClaw.Connection/NodeConnector.cs — both ForwardIfCurrent overloads (L224, L240) invoke subscriber delegates inside lock (_clientLifecycleLock):
// Validation and dispatch stay atomic so a retired client cannot publish after its
// replacement. Subscribers must remain synchronous and must not block on connector
// lifecycle work while this lock is held.
private void ForwardIfCurrent<T>(object? sender, long generation, T args, EventHandler<T>? handler)
{
lock (_clientLifecycleLock)
{
if (Interlocked.Read(ref _clientGeneration) == generation &&
ReferenceEquals(sender, _client))
{
handler?.Invoke(this, args);
}
}
}Every lifecycle operation takes the same _clientLifecycleLock (L110, L136, L181, L187, L214, L258, L272, L304), so event dispatch and lifecycle transitions are mutually exclusive:
- A slow subscriber (
StatusChanged,PairingStatusChanged,TransportConnected,ConnectionFailure,DeviceTokenReceived) stalls everyConnect/Dispose/DisconnectIfCurrentfor its duration. - A subscriber that blocks on another thread which is itself doing lifecycle work deadlocks (handler waits on thread T; T waits on
_clientLifecycleLock). - Same-thread re-entry (a handler calling back into lifecycle methods) is silently permitted by
Monitorreentrancy and mutates generation state mid-dispatch.
Handlers are fast today, and the constraint is now documented at the call site (L221–223) — but it's enforced by comment, not by structure.
Why this isn't a mechanical snapshot-and-raise
The lock currently buys a real ordering guarantee: validation + dispatch are atomic, so a retired client can never publish after its replacement. Naively moving handler?.Invoke outside the lock reopens that publish-after-retire window. A fix needs to preserve the guarantee — e.g. a per-generation dispatch queue drained before retirement completes, or validate-under-lock + invoke-outside with a completion barrier on retire. That design tension is why this stayed a tracked hazard in #1010 rather than a quick fix.
Deterministic reproduction (base-red / head-green)
No timing dependence needed — gate the interleaving explicitly:
- Stall repro: subscribe a handler that blocks on a
ManualResetEventSlim; deliver an event through the current client; from another thread callDisconnectIfCurrent(orDispose).- Base (red): the lifecycle call cannot complete until the handler's gate opens.
- Fixed (green): the lifecycle call completes promptly while the handler is still running.
- Ordering guarantee (must stay green in both): after
Dispose/generation retirement returns, no subscriber invocation from the retired client is observed — retirement acts as a barrier for in-flight dispatch.
Acceptance criteria
- Lifecycle operations no longer block on subscriber execution (repro 1 flips red → green).
- The publish-after-retire guarantee holds under the new dispatch scheme (repro 2 green before and after), with the mechanism documented at the call site.
- Alternatively, if the maintainers' verdict is that the documented synchronous-subscriber contract is the intended final state, close this as accepted-by-design — the point of the split is that the decision is explicit.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Projects
- StatusShow more project fieldsChannels
Activity
clawsweeper commentedon Jul 18, 2026
Codex review: keeping this open for maintainer follow-up; there is still a little grit to resolve. Reviewed July 18, 2026, 5:35 PM ET / 21:35 UTC.
Summary
Keep this issue open. It was filed on July 18, 2026 against the stated current-main SHA with a concrete lock-held callback path and a deterministic reproduction design; resolving it requires an explicit choice between preserving the synchronous callback contract or introducing a retirement-safe out-of-lock dispatch protocol.
Reproducibility: yes. at source level: block a current-client event handler on a gate, invoke
DisconnectIfCurrentor disposal from another thread, and observe whether the lifecycle call waits for that handler. The supplied report also defines the required post-retirement no-publication assertion, but this review did not execute the repro.Root-cause cluster
Relationship:
canonicalCanonical: #1020
Summary: This is the focused canonical tracker for one residual
NodeConnectordispatch hazard split from a broader, now-closed concurrency report.Members:
partial_overlap: Concurrency: SessionsUpdated snapshot aliases live state, and node-setup cancel logs a spurious failure + retry (+3 minor hazards) #1010 - The closed umbrella tracked several independent concurrency findings and explicitly listed this lock-held subscriber-dispatch hazard as residual work; the current issue narrows that one concern.Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.
Next step
A maintainer must choose the intended event/lifecycle contract before a repair worker can safely select a dispatch mechanism.
Maintainer decision needed
NodeConnectorretain its documented synchronous-under-lock subscriber contract, or should maintainers sponsor a retirement-safe out-of-lock dispatch design that prevents lifecycle stalls?Review details
Best possible solution:
Adopt a small, tested dispatch/retirement protocol that lets lifecycle transitions complete independently of subscriber execution while making retirement a barrier for all events from the retired generation; document that invariant at the dispatch seam.
Do we have a high-confidence way to reproduce the issue?
Yes, at source level: block a current-client event handler on a gate, invoke
DisconnectIfCurrentor disposal from another thread, and observe whether the lifecycle call waits for that handler. The supplied report also defines the required post-retirement no-publication assertion, but this review did not execute the repro.Is this the best way to solve the issue?
Unclear until maintainers choose the event-contract direction. A naive snapshot-and-raise change is not sufficient because it can violate the existing retirement barrier; a completion-aware dispatch design is the narrow maintainable fix if the synchronous contract is not accepted.
AGENTS.md: found and applied where relevant.
Remaining risk / open question:
_clientLifecycleLockwithout a completion/retirement barrier can let an already-retired client publish after replacement.Codex review notes: model internal, reasoning high; reviewed against ee4817d2c2e7.
Label changes
Label changes:
P2: The reported core connection lifecycle stall has bounded current impact because subscribers are presently fast, but it can block connect, disconnect, and disposal when the contract is violated.impact:other: This is a concrete connection-lifecycle responsiveness and reentrancy hazard that does not fit the more specific owned impact classes.issue-rating: 🐚 platinum hermit: Current issue advisory state selects this label.clawsweeper:needs-live-repro: Current issue advisory state selects this label.clawsweeper:no-new-fix-pr: Current issue advisory state selects this label.clawsweeper:needs-maintainer-review: Current issue advisory state selects this label.clawsweeper:needs-product-decision: Current issue advisory state selects this label.Label justifications:
P2: The reported core connection lifecycle stall has bounded current impact because subscribers are presently fast, but it can block connect, disconnect, and disposal when the contract is violated.impact:other: This is a concrete connection-lifecycle responsiveness and reentrancy hazard that does not fit the more specific owned impact classes.Evidence reviewed
What I checked:
ForwardIfCurrentoverloads inNodeConnector.csas validating generation/current-client identity and invoking the handler inside_clientLifecycleLock; the item states this was verified at current mainee4817d2c2e7b509474d0979aa746a762448cd0c. (src/OpenClaw.Connection/NodeConnector.cs:224, ee4817d2c2e7)src/OpenClaw.Connection/NodeConnector.cs:224, ee4817d2c2e7)AGENTS.mdrequires focused regression coverage and the required build/shared/tray validation for any eventual connection-path change; it also directs node/MCP-related work toward real behavior proof where applicable. (AGENTS.md:1, ee4817d2c2e7)Likely related people:
src/OpenClaw.Connection/NodeConnector.cs)How this review workflow works
@clawsweeper re-reviewcomments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.@clawsweeper re-reviewor@clawsweeper re-runon an open PR or issue to request a fresh review only.@clawsweeper reviewto request a fresh review only.@clawsweeper autofix,@clawsweeper automerge,@clawsweeper fix ci, or@clawsweeper address review.@clawsweeper explainto ask for more context, or@clawsweeper stopto stop active automation.steipete commentedon Jul 19, 2026
Resolved on main by #1022 at 15ed439.
That merge selected the report's explicit synchronous-callback option: validation and dispatch remain atomic under the lifecycle lock, with the fast/nonblocking subscriber contract documented. Regression coverage proves retired-client events are suppressed after reconnect and disconnect, while current-client handlers can read connector properties consistently. The full Windows build, 14 focused connection tests, 2,901 shared tests, and 1,823 tray tests passed. Closing this design report as decided and documented on main.