Skip to content

fix(gateway): stop presence rows accumulating on reconnect - #175352

Merged
steipete merged 2 commits into
mainfrom
steipete/presence-churn
Oct 17, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/presence-churn

Conversation

@steipete

@steipete steipete commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

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 row disconnect and 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:

Measurement Before After
Hello presence rows, including Gateway 13 3
Hello presence bytes 7,633 1,583
Complete hello payload bytes 23,220 17,172
Next presence-event rows 13 3
Next event's presence bytes 7,633 1,583

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 full pnpm 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-lint from the frozen lockfile resolved that setup gap without changing any dependency manifest or lockfile.

The initial exact-head CI run (39018255708, head e8883090d4b1) exposed two deterministic timeouts in server.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 run 39018833014 passed on 4b13fb77de5610f0cb139c7016addd7c6ef68cda: 36 jobs succeeded and 26 planner-skipped jobs, with no failures. Both required openclaw/ci-gate entries passed. ClawSweeper re-review reported no findings on that head. The native squash auto-merge landed as 0e83b8203baf1207fff2b31a95fa66102a4c0502 after the normal gates passed; no rebase, infrastructure retry, inherited-failure exception, or admin bypass was used.

Related: #175315

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
@clawsweeper

clawsweeper Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-17T08:43:19.445082Z e888309 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S labels Oct 17, 2026
Keep the hello publication tests on distinct signed devices so their disconnect expectations match the live-sibling presence contract.
@steipete

Copy link
Copy Markdown
Contributor Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 17, 2026
@steipete
steipete enabled auto-merge (squash) October 17, 2026 08:55
@clawsweeper

clawsweeper Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This 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.

  • Before: Hello and presence-event snapshots contain 13 rows including the Gateway, with 7,633 bytes of presence data.
  • After: Both snapshots remain at 3 rows including the Gateway, with 1,583 bytes of presence data.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) The focused patch has no actionable findings and useful boundary regressions; supplied behavior evidence comes from an in-process Gateway harness, with broad exact-head CI still running.
Proof confidence 🦐 gold shrimp (3/6) This maintainer-authored PR is outside the ordinary contributor proof gate; its supplied real in-process Gateway measurement exercises signed reconnects through hello and presence events, reports stable row counts, and covers simultaneous tabs and expiry.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Repeated Control UI reconnects accumulate stale presence rows, enlarging bootstrap and event payloads and consuming roster capacity.
Reason: The maintainer-authored direction explicitly preserves live-tab facts and recently offline device metadata while removing measured reconnect accumulation.

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
Reviewed head: 4b13fb77de5610f0cb139c7016addd7c6ef68cda

Before merge

None.

Findings

None.

Agent review details

How this fits together

Gateway 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]
Loading

Technical review

Best 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

  • Offline operator-row retention changes intended behavior with a stated reason (6a05d60: The early stable-instance deduplication contract prevented reconnect duplicates while retaining five-minute best-effort presence; later per-connection rows preserve distinct watched-session facts.)
  • Pending hello publication keeps the original intent (ae602ac: Pending rows remain private until their own hello delivery succeeds, preventing failed connections from being published as connected.)
  • Hello-order browser fixtures keeps the original intent (f2e6e22: The tests protect hello-before-presence ordering and failed-hello cleanup; distinct signed identities preserve those assertions under the approved sibling-retention contract.)
  • Protocol presence documentation changes intended behavior with a stated reason (9466d07: The protocol split carried forward device-keyed wording; this PR aligns the reference with existing per-connection operator rows and the approved offline-retention change.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Pinned introduced change: The introduced patch reconciles operator rows only during connect and disconnect mutations, using the existing map and excluding node-role rows. (src/infra/system-presence.ts:219, 4b13fb77de56)
  • Current main retains the accumulation path: Pinned main stores each connection row without sibling reconciliation and removes old rows only through snapshot expiry or capacity eviction. (src/infra/system-presence.ts:208, 8f9605da47cb)
  • Production connection boundary: Operators use connection IDs as presence keys, nodes retain device-based keys, and disconnect cleanup marks the exact connection row offline before publishing. (src/gateway/server/ws-connection/connect-session.ts:181, 4b13fb77de56)
  • Approved retention contract and supplied measurement: The maintainer-authored body explicitly selects live connection rows plus one recent offline row per operator identity and reports real in-process Gateway measurements covering reconnects, simultaneous tabs, disconnect cleanup, and expiry. (4b13fb77de56)
  • Distinct predecessor: perf(gateway): omit unused health details from Control UI hello #175315 measured presence accumulation while reducing unused hello health data; its merged change explicitly left presence unchanged. (6052c9a788df)
  • Preserved hello publication boundary: The earlier pending-row change prevents publication before successful hello delivery; this PR retains that mechanism and gives independent hello-order browser fixtures distinct signed identities without weakening their assertions. (src/gateway/server.auth.hello-order.test.ts:60, ae602ac11e99)

PR surface

Source +32, Tests +137, Docs +9. Total +178 across 6 files. Added test files: 1.

View PR surface stats
Area Files Added Removed Net
Source 1 32 0 +32
Tests 3 138 1 +137
Docs 2 13 4 +9
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 6 183 5 +178

Review metrics

Metric Value Why it matters
Production versus test LOC Production +32/-0; tests +138/-1 The bounded production addition reuses the existing owner; tests cover lifecycle invariants, wire snapshots, and independent browser identities.

Labels

Label changes:

  • add P2: Reconnect churn unnecessarily enlarges presence snapshots and consumes the bounded roster, without evidence of an unusable core workflow.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P2: Reconnect churn unnecessarily enlarges presence snapshots and consumes the bounded roster, without evidence of an unusable core workflow.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Rating scale

6/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.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 17, 2026, 4:54 AM ET / 08:54 UTC.

@steipete
steipete merged commit 0e83b82 into main Oct 17, 2026
127 of 128 checks passed
@steipete
steipete deleted the steipete/presence-churn branch October 17, 2026 09:11
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash auto-merge.

steipete added a commit that referenced this pull request Oct 17, 2026
…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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
…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.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 18, 2026
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. size: S status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant