Repository navigation
fix(gateway): stop presence rows accumulating on reconnect - #175352
Conversation
Retain one recently offline row per device or instance while keeping live connections separate for watched-session state. Preserve five-minute expiry, node keying, and protocol shapes. Related: #175315
|
🦞👀 Pull request received. I will update this pull request when review starts. |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Keep the hello publication tests on distinct signed devices so their disconnect expectations match the live-sibling presence contract.
|
@clawsweeper re-review |
|
🦞👀 Re-review progress:
|
|
Codex review: needs maintainer review before merge. What this changesThis PR removes obsolete offline operator presence rows while preserving independent live tabs and one recently offline row per identity. Example: Two signed Control UI identities each reconnect five times in the supplied synthetic Gateway measurement.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep this PR open: it fixes verified reconnect accumulation still present on pinned main, follows the maintainer-approved presence contract, and introduces no actionable correctness or security finding; exact-head CI remains pending. Priority: P2 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherGateway connection setup and disconnect cleanup update the shared in-memory presence owner, whose snapshots feed hello responses, presence RPCs, and recipient-filtered events. flowchart LR
A[Signed operator connections] --> B[Gateway connection lifecycle]
B --> C[Shared presence owner]
D[Node connections and beacons] --> C
C --> E[Recipient filtering]
E --> F[Hello RPC and presence events]
Technical reviewBest possible solution: Land the shared-owner reconciliation through the normal exact-head CI gates while retaining live-tab isolation and recent offline metadata. Do we have a high-confidence way to reproduce the issue? Pinned main creates a new operator row for each connection and retains disconnected rows until expiry; the supplied Gateway measurement corroborates this path, although this review executed no target code. Is this the best way to solve the issue? Reconciliation at the shared presence owner addresses obsolete rows at their producer without merging live tabs, adding state ownership, or changing the wire shape. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 8f9605da47cb. Provenance checked
TestingProof path: in-process harness. SecurityNone. EvidenceWhat I checked:
PR surfaceSource +32, Tests +137, Docs +9. Total +178 across 6 files. Added test files: 1. View PR surface stats
Review metrics
LabelsLabel changes:
Label justifications:
Rating scale6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed October 17, 2026, 4:54 AM ET / 08:54 UTC. |
|
Merged via squash auto-merge.
|
…175424) The legacy Memory Core fixture installed its runtime capability without the loaded plugin record needed to resolve memory-core/search-api.js. Include that existing public-surface metadata so the real legacy response path also works when global bundled discovery is disabled. Response and authority assertions are unchanged. PR #175199 explicitly says "No shipped methods are removed" and retains third-party managers' synchronous fallback. PR #175352 defines "live connection rows plus at most one recent offline row per operator identity". These sockets share a signed device. On disconnect, a live sibling intentionally causes the closed row to disappear. Assert that removal in the emitted presence snapshot instead of waiting for an offline row. Preserve the per-connection replace-set, narration isolation, invalid input and presence-version checks, with unchanged deadlines. Both assigned hourly failures were reproduced before the fixture repairs. The full affected-file Node run with bundled discovery disabled passed 40/41 cases, including all memory authority cases and the repaired viewer case. Its unchanged session-scoped chat-delivery case timed out and failed cleanup; that case passed alone in the normal environment (186.24 s). This additional failure is recorded, not treated as a clean full-file run. Both targeted test type graphs and type-aware lint/format pass. P0-P2 autoreview found no findings.
…175352) Presence no longer accumulates a row for every reconnect of the same device; live tabs keep their own rows and at most one recently-offline row per device remains until the TTL, shrinking hello and presence events. Keep node keying, the five-minute TTL, the 200-row cap, and per-tab watched-session facts unchanged. Cover signed Control UI reconnects at the real WebSocket boundary and lifecycle/expiry at the presence owner. Give independent hello-order browser fixtures distinct signed identities so their disconnect assertions exercise separate devices.
…penclaw#175424) The legacy Memory Core fixture installed its runtime capability without the loaded plugin record needed to resolve memory-core/search-api.js. Include that existing public-surface metadata so the real legacy response path also works when global bundled discovery is disabled. Response and authority assertions are unchanged. PR openclaw#175199 explicitly says "No shipped methods are removed" and retains third-party managers' synchronous fallback. PR openclaw#175352 defines "live connection rows plus at most one recent offline row per operator identity". These sockets share a signed device. On disconnect, a live sibling intentionally causes the closed row to disappear. Assert that removal in the emitted presence snapshot instead of waiting for an offline row. Preserve the per-connection replace-set, narration isolation, invalid input and presence-version checks, with unchanged deadlines. Both assigned hourly failures were reproduced before the fixture repairs. The full affected-file Node run with bundled discovery disabled passed 40/41 cases, including all memory authority cases and the repaired viewer case. Its unchanged session-scoped chat-delivery case timed out and failed cleanup; that case passed alone in the normal environment (186.24 s). This additional failure is recorded, not treated as a clean full-file run. Both targeted test type graphs and type-aware lint/format pass. P0-P2 autoreview found no findings.
What Problem This Solves
Fixes growing hello and presence-event snapshots when a signed Control UI device repeatedly reconnects. The workload reported in #175315 reached the 200-row cap and roughly 120 KB per hello because disconnected connection rows accumulated for five minutes.
User Impact
Repeated reconnects no longer grow the presence roster. Live tabs still have independent watched-session and connection facts, while the last disconnected connection retains recent device metadata until the existing five-minute TTL. The 200-entry cap, Gateway self row, node keying, protocol shape, and clients are unchanged.
Why This Change Was Made
Operator rows intentionally use
connId(src/gateway/server/ws-connection/connect-session.ts:181–184) so simultaneous tabs cannot overwrite each other's watched sessions. Close handling marks the old rowdisconnectand refreshes its timestamp (src/gateway/server/connection.ts:462–466), so a reconnect previously created another row rather than replacing it. The shared owner only removed them during read-time five-minute expiry or oldest-first capacity eviction (src/infra/system-presence.ts:261–279; constants at lines 30–31).The maintainer's explicit contract decision is live connection rows plus at most one recent offline row per operator identity. Identity is device ID, then client instance ID, then connection ID. This removes reconnect accumulation while preserving per-tab facts and recently-offline metadata used by the Devices inventory. The presence owner now discards matching offline rows on connect; on close it removes the row if a live sibling remains, otherwise retains only that final offline row. Both presence docs now state this contract consistently.
The implementation adds 32 production lines, reuses the existing map, and reconciles only connect/disconnect mutations. The retained tests add 138 lines for the owner lifecycle and actual WebSocket boundary; the large diagnostic was removed after measurement. The pr-simplify pass found no separate state owner or redundant production path to retain. No new registry, cache, protocol field, or client implementation was introduced.
Evidence
A real in-process Gateway and reusable paired/signed Control UI identities reproduced the original growth. Both measurements used two identities, five reconnects each, and startup settlement plus ten seconds. At the final reconnect:
Before, each reconnect added one row; after, every reconnect remained at three rows. The same real-path measurement verified two simultaneous tabs with distinct watched sessions, independent disconnect cleanup, two retained offline rows after both identities disconnected, and zero retained peer rows after TTL expiry. These are small synthetic-fixture byte measurements, not production latency claims.
The committed coverage is smaller: one fake-clock owner regression and one real WebSocket test with one signed identity and two reconnects, without the diagnostic warm-up sleep or large loop. The owner regression failed on the old implementation at reconnect replacement and passed after the fix. All 32 focused tests passed across five files. The owner regression takes 5 ms and its full file 0.81 s; the WebSocket regression takes 14.81 s, including the real Gateway lifecycle. The combined cold command took 197.35 s, mostly worker compilation/imports. CI results are recorded below. Oxfmt, assertion safety, the line-cap ratchet, and an isolated Codex review at P0–P2 passed.
pnpm tsgo:core, the fullpnpm tsgo:core:test, and repository type-aware oxlint on all touched TypeScript files passed. Lint initially could not load the existing Solid lint workspace dependency; installing@openclaw/solid-lintfrom the frozen lockfile resolved that setup gap without changing any dependency manifest or lockfile.The initial exact-head CI run (
39018255708, heade8883090d4b1) exposed two deterministic timeouts inserver.auth.hello-order.test.ts. Its independent browser fixtures shared the default signed device identity, so the approved live-sibling contract correctly removed the disconnect row they awaited. Each browser now receives its own signed identity; all four existing hello-order assertions pass unchanged. The local command took 28.68 s (24.77 s Vitest; individual tests 1.98–4.80 s). Formatting, type-aware lint, test typechecking, and an isolated P0–P2 Codex review pass. This is a PR-caused fixture mismatch, not an inherited failure or an infrastructure retry. Final exact-head CI run39018833014passed on4b13fb77de5610f0cb139c7016addd7c6ef68cda: 36 jobs succeeded and 26 planner-skipped jobs, with no failures. Both requiredopenclaw/ci-gateentries passed. ClawSweeper re-review reported no findings on that head. The native squash auto-merge landed as0e83b8203baf1207fff2b31a95fa66102a4c0502after the normal gates passed; no rebase, infrastructure retry, inherited-failure exception, or admin bypass was used.Related: #175315