Repository navigation
fix(matrix): recover providers after disconnected sync stop - #125362
Conversation
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. Reviewed August 19, 2026, 2:25 PM ET / 18:25 UTC. ClawSweeper reviewWhat this changesThe PR unwinds a disconnected Matrix classic-sync keepalive and conditionally evicts a safely retired poisoned shared client so a later provider retry can create a new client. Regression provenancePossible regression — probable (reviewed change; failure trace). No predecessor PR is attributed. Merge readinessKeep open for a Matrix-owner decision: the source-level repair is coherent and the PR supplies production recovery evidence, but it deliberately depends on a private pinned SDK field. Priority: P1 Review scores
Verification
Live VerificationCommand: Result: PASS (completed) Assertions:
How this fits togetherMatrix providers share client generations across monitor and transient leases. On restart, sync shutdown determines whether cursor state can be persisted and whether a subsequent provider retry can acquire a fresh client. flowchart LR
A[Matrix provider restart] --> B[Shared client generation]
B --> C[Classic sync shutdown]
C --> D{Parked disconnected keepalive?}
D -->|yes| E[Unwind captured resolver]
D -->|no or uncertain| F[Wait for stopped event]
E --> G[Retire leases and client]
F --> G
G --> H[Later provider retry]
Decision needed
Why: The code limits the dependency to one pinned version and production evidence supports the behavior, but accepting ownership of a private upstream lifecycle field is a maintainer policy decision. Before merge
Agent review detailsSecurityNone. PR surfaceSource +38, Tests +120. Total +158 across 5 files. View PR surface stats
Review metrics
Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Accept the narrowly version-guarded private SDK action only if a Matrix owner is comfortable owning it on future dependency upgrades, then merge after exact-head checks finish green. Do we have a high-confidence way to reproduce the issue? Yes, from source: current main preserves a quiesce poison in the keyed shared-client state and rethrows it on acquisition; the PR’s regression tests model the resulting failed retry path. Is this the best way to solve the issue? Yes for the reported pinned-SDK behavior: the fix is scoped to the Matrix lifecycle owner, preserves fail-closed cursor handling, and avoids a parallel retry path; accepting the private SDK boundary remains a maintainer choice. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 03a48b5801e3. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rank-up movesOptional improvements that raise the rating; they are not merge blockers.
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (5 earlier review cycles)
|
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
I updated the PR description with the direct, commit-pinned source-contract comparison requested in the latest review:
I also made the evidence scope explicit: this update supplies pinned-SDK source proof only. It does not claim an exact-head live disconnected-recovery trace; the existing production-after trace remains identified as the built |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. |
|
@clawsweeper re-review |
|
🦞🧹 I asked ClawSweeper to review this item again. Re-review progress:
|
|
Land-ready at Maintainer decision: accept the narrowly bounded Proof:
Known proof gap: I did not induce a new authenticated Matrix outage. The PR body already contains redacted production recovery evidence across six accounts and a real Matrix request/reply round trip; focused dependency-backed lifecycle tests and exact-head CI cover the maintainer follow-up. Production delta: |
|
Merged via squash.
|
…#125362) * fix(matrix): recover poisoned sync generations * fix(matrix): compile private sync resolver boundary * fix(matrix): retain incomplete retirement poison --------- Co-authored-by: Benjamin Badejo <[email protected]> Co-authored-by: Josh Lehman <[email protected]>
What Problem This Solves
A Matrix provider that is restarted while
matrix-js-sdkclassic sync is parked in its disconnected keepalive path can become permanently unrecoverable inside the gateway process.The SDK's
SyncApi.stop()fences that path, but version 41.9.0 does not emit a laterSTOPPEDevent there. OpenClaw waited only forSTOPPED, timed out after five seconds, and retained the resultingpoisonErrorin the keyed shared-client state. Every provider auto-restart then synchronously rethrew the old error instead of creating a new Matrix client.On a real six-account deployment, Synapse and nginx recovered, but every OpenClaw Matrix account remained stopped and disconnected until the gateway process was replaced.
Why This Change Was Made
This patch makes shutdown match the exact pinned SDK contract while preserving fail-closed cursor handling:
ERROR/RECONNECTING, capture the actual parked keepalive resolver.SyncApi.stop().STOPPEDonly when the exact captured resolver is still installed; clear and reject it with the SDK's ownSyncApi.stop() was calledreason so the parked SDK task unwinds.STOPPEDwait and five-second fail-closed timeout.quiesceSync()->stopAndPersist()double call idempotent and preventing a timed-out generation from later persisting an untrusted cursor.stopWithoutPersist(), evict it from the shared-client registry infinally. The current caller still receives the original error, but a later provider retry creates a genuinely fresh client instead of reusing cached poison.The exact SDK version assertion remains in place. This does not change Matrix dependencies or relax the timeout for active sync work.
User Impact
Before this change, one disconnected health-monitor restart could strand a Matrix account for the lifetime of the gateway process. Provider auto-restart exhausted all attempts while replaying a stale five-second error in milliseconds.
After this change, the pinned SDK's parked keepalive path quiesces deterministically. Genuine uncertainty still discards the pending cursor and fails closed, but the discarded generation no longer poisons every future provider acquisition.
Evidence
Production account labels below are anonymized consistently as
agent1throughagent6; timestamps, durations, versions, state transitions, and account cardinality are unchanged.Pinned
matrix-js-sdksource contractThis source proof is independent of a live deployment: both sides of the comparison are commit-pinned. The Matrix extension pins
matrix-js-sdkto exactly41.9.0, whosev41.9.0tag resolves to upstream commitab387673152848cf676d264003b17f2e7e780370. The PR head is77f4df4e36dc5aa8d50d9c26c94aa1e2e7b3c3bc.The pinned SDK establishes the failure contract directly:
SyncApiowns the privateconnectionReturnedResolversused by disconnected keepalive.SyncApi.stop()setsrunning = false, aborts the current request, and clearskeepAliveTimer, but it neither settles nor clearsconnectionReturnedResolvers.onSyncError()starts keepalive, publishesRECONNECTINGorERROR, and awaits that resolver-backed promise.startKeepAlives()schedules the timer and creates the resolver. Clearing the timer instop()can therefore leave the awaited promise unsettled, so execution does not reach the SDK's normalSTOPPEDemission.pokeKeepAlive()rejects the resolver with exactlySyncApi.stop() was called, clears it, and returns without emittingSTOPPED.The PR mirrors only that exact terminal action. It asserts SDK version
41.9.0before crossing the private boundary, verifies the object is the classicSyncApi, captures a resolver only from pre-stopERROR/RECONNECTING, callsstop(), then clears and rejects only if the same resolver identity is still installed. If the state is active, no resolver exists, or the resolver was replaced, the existing real-STOPPEDwait and fail-closed cursor discard remain in force. The patch deliberately does not callretryImmediately(), which routes throughstartKeepAlives(0)and can create a replacement resolver.This is intentionally narrow reliance on one private field in one exact SDK version, guarded by both a version assertion and resolver-identity check. A future SDK change fails closed rather than silently using a changed private contract. Whether OpenClaw should carry that bounded private-field dependency remains an explicit maintainer decision.
Evidence scope
The commit-pinned SDK comparison remains independent of deployment state. The first production-after trace below is retained as evidence for built behavior commit
c17e4ff4. A second production-after trace now covers the final PR head77f4df4eapplied to exact integration heade8a5035, which was 299 commits ahead of the cut used for the original PR submission. That newer trace exercises all six production accounts through the disconnected health-restart path and proves recovery without replacing the gateway process.Production before: six accounts remained poisoned after the server recovered
Incident runtime:
2026.8.1, gateway source793669c8f6dd1ea18c8cd8c; the relevant Matrix files were byte-identical between those revisions2026.8.1matrix-js-sdk41.9.01.150.0; nginx1.29.8Initial failure chain on 2026-08-17 (UTC+03:00):
Before the final failed retry cycle, the homeserver path was independently healthy:
Nevertheless, attempt 10/10 for every account replayed the nominal
5000mserror in only 2-5 ms:At 20:49:19, the reachable gateway reported all six configured accounts as enabled/configured but stopped, disconnected, and in health error with
Matrix classic sync did not reach STOPPED within 5000ms. The 2-5 ms rethrows prove cached poison rather than a fresh five-second server timeout.Regression proof
On unmodified
main, the new tests failed at both causal boundaries while the prior 158 owner-suite tests passed:On this branch:
Coverage includes parked
ERRORandRECONNECTING, staleERRORwithout a resolver, activeSYNCING, resolver replacement during stop, double quiescence throughstopAndPersist(), permanent rejection memoization after cursor discard, and fresh acquisition after poisoned retirement.Production after
The exact built head
c17e4ff4e41958327d336e83846f6003a959bbb6was applied to the incident installation with one ordinary managed-gateway restart at 21:04:50. No force restart or repeated restart was used. The old process completed shutdown cleanly in 1.749 seconds. The replacement process then completed the installation's known slow SQLite startup and reported:At 21:10:04, a live gateway status query reported each of the six configured accounts with:
The first post-start syncs included transient nginx 502s, then recovered in-process: all six clients logged
Resuming queue after resumed syncinstead of entering the old cached-poison loop. The gateway also recovered four real pending Matrix deliveries between 21:09:50.337 and 21:09:51.085; the delivery summary was4 recovered, 0 failed, 0 skipped, 0 deferred.Finally, a unique live probe traversed the complete path through an existing two-member room: Matrix user -> homeserver -> recovered OpenClaw
agent5provider -> agent -> Matrix reply. The reply matched the requested probe exactly. The homeserver recorded inbound at 21:14:05.629 and outbound at 21:14:16.162, a 10.533-second round trip (10.652 seconds client-observed). Sanitized correlation hashes: roomc98e15387b9d, inbound event9d3a5bdbcf2c, outbound eventd207b143fabb. The ephemeral client login used for the probe was revoked afterward.No
Matrix classic sync did not reach STOPPED within 5000mserror occurred after the patched process started.Production after: final PR head on exact integration head
e8a5035The final PR head
77f4df4e36dc5aa8d50d9c26c94aa1e2e7b3c3bcwas applied to exact integration heade8a5035ca6bf2604665aad6c54d2c346221bc3a6, which was 299 commits ahead of the cut used for the original PR submission. The running composite revision wasd5f8d87ec72b383b6318d5183c6c33f38bce5316; its two parents are exactlye8a5035and77f4df4e, and both are ancestors of the clean installed worktree.The gateway process started from that composite build at 23:44:36 UTC+03:00 on 2026-08-18. At 01:34 on 2026-08-19, all six production Matrix accounts entered a real disconnected health-monitor restart inside that same gateway process:
This is the exact pinned-SDK terminal branch addressed by the PR: each stopped disconnected generation reached the SDK's own
SyncApi.stop() was calledrejection. Instead of waiting five seconds for aSTOPPEDevent that this branch does not emit, every account acquired a fresh provider generation in 149-445 ms:All six replacement clients then completed fresh Matrix login in-process:
No gateway restart or process replacement occurred during this recovery. From the composite gateway's 23:44:36 start through the post-recovery check, the log contains zero
Matrix classic sync did not reach STOPPED within 5000mserrors and zero Matrixchannel exitedevents.At 02:08:22 UTC+03:00, a fresh live
channels statusquery reported all six configured production accounts with the same healthy terminal state:This newer-base run directly covers both causal boundaries requested in review: parked disconnected sync shutdown completed without the impossible
STOPPEDwait, and each retired generation was followed by fresh client acquisition and a healthy provider rather than a cached-poison rethrow.Safety and Scope
STOPPEDevent or fail closed after five seconds.stopWithoutPersist().