Repository navigation
test+doc: harden ForwardIfCurrent dispatch-under-lock invariant (#1010) - #1022
Conversation
|
Codex review: needs real behavior proof before merge. Reviewed July 18, 2026, 5:56 PM ET / 21:56 UTC. Summary Reproducibility: yes. at source level: the added focused tests invoke the captured clients' status event path and assert stale-client suppression plus current-client forwarding. A current-head inspectable run has not been supplied for this review. Review metrics: 2 noteworthy metrics.
Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Proof guidance:
Risk before merge
Maintainer options:
Next step before merge
Security Review detailsBest possible solution: Keep the focused regression tests and documentation, then attach a redacted current-head terminal or live-output capture that visibly runs the focused event-path checks and shows the retired-client suppression and current-client forwarding assertions passing. Do we have a high-confidence way to reproduce the issue? Yes, at source level: the added focused tests invoke the captured clients' status event path and assert stale-client suppression plus current-client forwarding. A current-head inspectable run has not been supplied for this review. Is this the best way to solve the issue? Yes, conditionally: focused event-path regression tests and an invariant comment are a maintainable way to preserve the existing design, provided the PR adds direct current-head behavior proof rather than relying only on reported suite totals. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against ee4817d2c2e7. Label changesLabel justifications:
Evidence reviewedWhat I checked:
Likely related people:
What the crustacean ranks mean
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. How this review workflow works
Review history (2 earlier review cycles) |
PR #1022 was amended at
Validation after amendment:
This replaces the earlier tests that only proved client replacement/nulling and overclaimed direct forwarding coverage. |
Exercises the real ForwardIfCurrent event path by invoking WebSocketClientBase.RaiseStatusChanged via reflection on captured WindowsNodeClient instances. This proves: - Reconnect: StatusChanged on retired client A is suppressed by the generation check; events on current client B are forwarded. - Disconnect: StatusChanged on a retired client is suppressed after disconnect (generation mismatch + null _client). - Reentrancy safety: a StatusChanged subscriber can read IsConnected/PairingStatus/Mode/Client without blocking, observing consistent values from inside the _clientLifecycleLock scope. Documents the lock ordering invariant at ForwardIfCurrent: this lock is outermost; subscriber-owned locks must not re-enter connector lifecycle operations. Ref: #1010 (hazard 2) Co-authored-by: Copilot App <[email protected]> Copilot-Session: 102b1f54-0707-4f84-9f7f-dc254b38de70
700d98c to
3e09e56
Compare
Summary
Tests and documentation hardening for the
NodeConnector.ForwardIfCurrentdispatch-under-lock invariant (issue #1010 hazard 2). No production code behavior is changed.After thorough investigation of all lock ordering paths, subscriber behavior, and reentrancy scenarios, the conclusion is that
ForwardIfCurrent's current design is correct: it holds_clientLifecycleLockduring validation+dispatch to prevent a TOCTOU race where a retired client could publish events after replacement. All subscribers are fast (µs synchronous preambles with fire-and-forget async dispatch), lock ordering is consistent with no reverse acquisitions, and no deadlock or reentrancy corruption is possible.Changes
Tests (
NodeConnectorTests.cs)Three tests exercise the real
ForwardIfCurrentevent path using a reflection helper that invokesWebSocketClientBase.RaiseStatusChangedon capturedWindowsNodeClientinstances:Reconnect_SuppressesStatusFromRetiredClient— After reconnect, firesStatusChangedon retired client A → suppressed (generation mismatch). Then fires on current client B → forwarded. Proves both the negative and positive contract.Disconnect_RetiresClient_SuppressesForwarding— After disconnect, firesStatusChangedon the retired client → suppressed (generation mismatch + null_client).CurrentClientStatusHandler_CanReadConnectorProperties_WithoutBlocking— FiresStatusChangedon the current client throughForwardIfCurrent. Subscriber readsIsConnected,PairingStatus,Mode,Clientand asserts exact values — proving no blocking and consistent state.Documentation (
NodeConnector.cs)Enhanced the
ForwardIfCurrentcomment to document:_connectSemaphore(async) →_clientLifecycleLock(monitor, outermost among monitors) → subscriber-owned locksValidation
build.ps1Baseline disposition
ReadmeValidationTestsfailures are a pre-existing worktree environment issue (OPENCLAW_REPO_ROOTnot set), not caused by this diff. Tests pass withOPENCLAW_REPO_ROOTset.Review
Rubber-duck review identified and addressed:
_connectSemaphore → _clientLifecycleLockorderingEventHandleroverload coverage — follow-up: sameForwardIfCurrentlogic, low riskRef: #1010