Skip to content

perf(ui): stop read acknowledgement storms during gateway drains - #167020

Merged
steipete merged 1 commit into
mainfrom
steipete/perf-micro-restart-window-retry-storm-20260919
Oct 8, 2026
Merged

steipete merged 1 commit into
mainfrom
steipete/perf-micro-restart-window-retry-storm-20260919

Conversation

@steipete

@steipete steipete commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes automatic Control UI read acknowledgements repeatedly issuing sessions.patch while the Gateway drains for a restart or suspension.

User Impact

Open chats stop flooding a draining Gateway with read acknowledgements. Identity refreshes and secondary chat reads also pause while the Gateway reports unavailable. Existing manual unread markers and optimistic read feedback are preserved.

Why This Change Was Made

An optimistic unread=false publication cleared the acknowledgement guard before the request settled. A rejected patch restored unread=true synchronously, which could send the next patch before the first rejection handler ran. The guard now distinguishes pending work from a confirmed read and applies the server's minimum retry delay with exponential backoff and jitter. Hidden-run acknowledgements use that same guard instead of separate retry handling. Connection changes retire pending acknowledgement state; availability recovery rechecks the visible chat.

Production LOC delta: +27. The growth records previously missing pending-request settlement, retry deadlines, and availability recovery; it replaces the hidden-run retry policy rather than adding a competing path. No schema, protocol, configuration, or dependency changes.

Evidence

  • Baseline regression on Blacksmith Testbox tbx_01m4cxwhg55q8bf7gvvaya0dw4: the real session store's optimistic rollback produced 2 patches instead of 1. The other 29 read-marker tests passed.
  • Initial candidate focused validation on the same lease: node scripts/run-vitest.mjs ui/src/pages/chat/chat-pane.read-marker.test.ts ui/src/lib/sessions/unread.test.ts ui/src/lib/sessions/session-unread-mutations.test.ts ui/src/lib/agents/identity.test.ts --maxWorkers=1 passed (7.77 s wrapper wall time; read-marker file 3.01 s wall, approximately 0.66 s test time).
  • Independent Codex review: scoped clean at P0/P1; no accepted or actionable findings.
  • Linux rig sibling validation: all 377 non-browser test files in ui/src/lib/agents, ui/src/lib/sessions, and ui/src/pages/chat passed with node scripts/run-vitest.mjs <sibling files> --maxWorkers=2: 5,584 tests passed, two existing benchmark cases skipped, 761.64 s wrapper wall time.
  • Full changed gate passed on Blacksmith Testbox tbx_01m4d485g4artqnvn1n2t5yc2n: verified all eight source hashes, staged those exact files in the transport checkout, and ran node scripts/check-changed.mjs --staged --timed (11m 4.658s). All eight test typecheck graphs, UI types, lint, i18n, ratchets, formatting, declaration guard, and dead-export scans passed.
  • Final regression cost on that Testbox: pnpm test ui/src/pages/chat/chat-pane.read-marker.test.ts --maxWorkers=1: 34 tests passed, 6.17s wall time, 0.517s summed test execution (CI test cost).
  • Real Gateway over WebSocket, same runtime artifact for both client versions, synthetic state and 3-second drain windows: missed lifecycle event 1,127 → 3 rejected patches (375.7× fewer); delivered lifecycle event 1,518 → 0. Candidate minimum retry spacing 1,049 ms, honoring the 1,000 ms hint. Public resume and actual process restart/reconnect both persisted the acknowledgement. Built remotely with node --import ./scripts/tsx.mjs scripts/build-all.mts sourcePerformance; the temporary jsdom rig ran with node scripts/run-node-package-bin.mts vitest run --config .local/lane617/rig.vitest.config.ts.
  • The four identity pause cases also failed on the unchanged baseline and passed on the candidate.

This is a request-lifecycle change with no visual changes. Validation uses synthetic state and does not require browser automation.

The first shared-rig gate and runtime build were killed by host-wide memory pressure. The runtime build passed with the supported 6 GiB heap setting; the complete gate passed on the dedicated Testbox. Two replacement leases queued/expired before the final runner became available. An initial Testbox --staged invocation selected no paths because native sync does not copy staging; only the explicitly staged eight-file gate above counts as gate evidence.

Keep automatic read acknowledgements pending through optimistic rollback,
and pace transient retries with the Gateway hint and exponential jitter.
Share that guard with hidden-run acknowledgements and pause automatic
read and identity refresh work during restart or suspension.

Synthetic real-Gateway drain proof reduced rejected patches from 1127 to 3
with a missed lifecycle event, and from 1518 to zero with the event delivered.
Resume and actual process restart/reconnect both preserved acknowledgements.
@clawsweeper

clawsweeper Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui size: M labels Oct 8, 2026
@steipete
steipete marked this pull request as ready for review October 8, 2026 07:17
@steipete
steipete enabled auto-merge (squash) October 8, 2026 07:20
@clawsweeper

clawsweeper Bot commented Oct 8, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge. Reviewed October 8, 2026, 3:24 AM ET / 07:24 UTC.

ClawSweeper review

What this changes

The PR keeps automatic read acknowledgements pending through optimistic rollback, backs off rejected requests, and pauses acknowledgements and identity refreshes during Gateway unavailability.

Example: An open chat encounters a three-second Gateway drain without receiving the lifecycle event

  • Before: The supplied baseline run sends 1,127 rejected read patches.
  • After: The supplied candidate run sends three rejected read patches and respects the 1,000 ms retry hint.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Strong real-transport evidence supports the useful repair, but an introduced reconnect regression prevents merge readiness.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (live_output): The fully inspected body supplies after-fix observations from production chat/session owners using a real WebSocket Gateway with injected drain windows: request storms collapse, retry spacing honors the server hint, and resume plus process restart recover durable acknowledgements. This proves the internal reliability change; it does not clear the separate manual-marker reconnect finding. No stored format or migration contract changes.
Patch quality 🦐 gold shrimp (3/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes
User problem: An open chat repeatedly sends rejected read acknowledgements while the Gateway drains, adding avoidable load during restart or suspension.
Reason: The real-Gateway comparison demonstrates substantial avoidable request traffic, and the repair stays within existing acknowledgement and availability contracts.

Merge readiness

⛔ Needs changes before merge - 3 items remain

This PR addresses a proven request storm, but its reconnect reset can erase a user's manual unread reminder. One focused correction is needed.

Priority: P2
Reviewed head: 8b4e66c8adf8d74ada939d0d104c1703022d2c8a

Before merge

  • Preserve activation-marker history when retiring connection work (P2) - If the user chooses Mark as unread on an already-open chat and the Gateway subsequently reconnects, applyGatewaySnapshot calls this reset on the connection transitions. beginActivation clears activationObserved and activationMarkedUnreadAt, so the next session snapshot adopts the newer manual marker and allows an automatic patch carrying that same marker. The Gateway accepts it and deletes the reminder even though the user never reopened the chat. This contradicts the established contract in fix: preserve unread reminder for open sessions #129386. Retire pending settlement/retry state separately from user activation state, preserving marker history for a same-chat reconnect.
  • Complete next step (P2) - Preserve the current chat's activation-marker history across reconnect while retiring connection-scoped pending acknowledgements.
  • Explain or restore the original intent of ui/src/pages/chat/chat-pane-session.ts: connection reset of activation state - fix: preserve unread reminder for open sessions #129386: Keep a manual unread reminder on an already-open chat until explicit reading or a genuine later activation.

Findings

  • [P2] Preserve activation-marker history when retiring connection work — ui/src/pages/chat/chat-pane-session.ts:65-67

Provenance

  • ui/src/pages/chat/chat-pane-session.ts: connection reset of activation state changes intended behavior without addressing why it exists (fix: preserve unread reminder for open sessions #129386: Keep a manual unread reminder on an already-open chat until explicit reading or a genuine later activation.)
  • ui/src/pages/chat/chat-pane-session.ts: secondary read admission: original intent not found (unknown: Historical git string searches failed on unavailable promisor blobs with HTTP 403; the supplied provenance does not identify the original secondary-read admission change.)

Tests

  • Missing end-to-end proof: The supplied drain and restart proof does not exercise a newer manual unread reminder surviving reconnect of the same continuously presented chat; no tests were executed during this read-only review.
Agent review details

How this fits together

The Control UI acknowledges viewed conversations through the Gateway's session API. Its acknowledgement guard coordinates optimistic unread updates, request settlement, and retries while the Gateway retains authoritative session state.

flowchart TD
  A[Visible chat and session updates] --> B[Gateway availability check]
  B -->|Unavailable| C[Pause automatic requests]
  B -->|Available| D[Read acknowledgement guard]
  D -->|Eligible| E[Gateway session patch]
  E --> F[Optimistic update and authoritative result]
  F --> D
  G[Connection changes] --> D
Loading

Technical review

Best possible solution:

Retire connection-scoped pending requests and retry state while preserving the visible chat's activation-marker history until genuine navigation or presentation changes.

Do we have a high-confidence way to reproduce the issue?

Yes: the supplied baseline regression and real-Gateway drain results establish the request storm. Source also establishes the introduced failure path: mark an already-open chat unread, reconnect without navigating, and let automatic acknowledgement resume.

Is this the best way to solve the issue?

No, not fully: sharing pending settlement and existing backoff is appropriate, but connection retirement must not create a new user activation that clears a manual reminder.

Full review comments:

  • [P2] Preserve activation-marker history when retiring connection work — ui/src/pages/chat/chat-pane-session.ts:65-67
    If the user chooses Mark as unread on an already-open chat and the Gateway subsequently reconnects, applyGatewaySnapshot calls this reset on the connection transitions. beginActivation clears activationObserved and activationMarkedUnreadAt, so the next session snapshot adopts the newer manual marker and allows an automatic patch carrying that same marker. The Gateway accepts it and deletes the reminder even though the user never reopened the chat. This contradicts the established contract in fix: preserve unread reminder for open sessions #129386. Retire pending settlement/retry state separately from user activation state, preserving marker history for a same-chat reconnect.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.96

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 017842386a7f.

Provenance checked

Testing

Proof path: shipped entry point. Added test files: 3.

Security

None.

Evidence

Acceptance criteria:

  • [P1] pnpm test ui/src/pages/chat/chat-pane.read-marker.test.ts --maxWorkers=1.
  • [P1] pnpm test ui/src/lib/sessions/unread.test.ts ui/src/lib/sessions/session-unread-mutations.test.ts --maxWorkers=1.
  • [P1] node scripts/check-changed.mjs --staged --timed.
  • [P1] Verify a continuously presented chat retains a newer manual unread marker through reconnect, while genuine later presentation can clear it and retired settlements cannot alter the new request.

What I checked:

  • Pinned implementation: The introduced diff adds pending-request settlement and retry deadlines, reuses the existing availability/backoff owner, and removes separate hidden-run failure handling. (ui/src/lib/sessions/unread.ts:47, 8b4e66c8adf8)
  • Real transport proof: The fully read PR body reports the production chat/session owners against a real Gateway over WebSocket with synthetic state: missed-event rejected patches fell from 1,127 to 3, delivered-event patches from 1,518 to 0, minimum retry spacing was 1,049 ms for a 1,000 ms hint, and resume plus process restart/reconnect persisted acknowledgements. Captured body source identity: aa793c6f0575796e07b45df9897a3221ea506e296371ff7c0622f618bb1cb9e9; the live REST body matched the supplied evidence. (8b4e66c8adf8)
  • Established manual-unread contract: fix: preserve unread reminder for open sessions #129386 states that Mark as unread remains visible while the current chat stays open and clears on a genuine later activation or explicit Mark as read. Its commit introduced activation-observed marker protection. (ui/src/lib/sessions/unread.ts:43, 44d60a29e666)
  • Introduced reconnect regression: Connection transitions now call resetSessionReadAcknowledgements, which invokes beginActivation and discards the previously observed marker. A still-presented chat therefore adopts a newer manual marker as its activation marker after reconnect and becomes eligible to acknowledge it. (ui/src/pages/chat/chat-pane-session.ts:66, 8b4e66c8adf8)
  • Final unread mutation: The Gateway applies an acknowledgement when expectedMarkedUnreadAt matches the stored marker; applying unread=false deletes markedUnreadAt. Sending the newly adopted marker therefore actually clears the reminder. (src/gateway/server-methods/session-unread-ack.ts:61, 8b4e66c8adf8)
  • Current-main necessity and merge scope: All eight touched files are unchanged between the pinned merge base and fetched current main, so main retains the original acknowledgement implementation. The verified test merge has exactly the recorded base and head parents and retains the reconnect-reset hunk. (ui/src/pages/chat/chat-pane-session.ts:66, 2fde011987d6)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • holgergruenhagen: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • roboclaw-bot: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

PR surface

Source +27, Tests +155, Docs +2. Total +184 across 8 files.

View PR surface stats
Area Files Added Removed Net
Source 4 85 58 +27
Tests 3 163 8 +155
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 8 250 66 +184

Review metrics

Metric Value Why it matters
Production versus test growth production net +27 LOC; tests net +155 LOC Production growth records missing request lifecycle state and consolidates hidden-run handling; test growth primarily protects rollback and availability behavior.

Labels

Label changes:

  • add P2: This is a bounded Control UI request-lifecycle repair with an introduced unread-reminder regression.
  • add merge-risk: 🚨 session-state: The reconnect reset can clear a durable manual unread marker while the same chat remains open.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.

Label justifications:

  • P2: This is a bounded Control UI request-lifecycle repair with an introduced unread-reminder regression.
  • merge-risk: 🚨 session-state: The reconnect reset can clear a durable manual unread marker while the same chat remains open.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦞 diamond lobster and patch quality is 🦐 gold shrimp.
  • proof: sufficient: Contributor real behavior proof is sufficient.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Separate connection retirement from user activation and add a regression showing that a newer manual unread marker survives same-chat reconnect while stale settlements remain retired.

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 need explicit maintainer commands such as @clawsweeper autofix or @clawsweeper automerge.

@steipete
steipete merged commit 06dc2c0 into main Oct 8, 2026
135 of 136 checks passed
@steipete
steipete deleted the steipete/perf-micro-restart-window-retry-storm-20260919 branch October 8, 2026 07:25
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 9, 2026
…nclaw#167020)

Keep automatic read acknowledgements pending through optimistic rollback,
and pace transient retries with the Gateway hint and exponential jitter.
Share that guard with hidden-run acknowledgements and pause automatic
read and identity refresh work during restart or suspension.

Synthetic real-Gateway drain proof reduced rejected patches from 1127 to 3
with a missed lifecycle event, and from 1518 to zero with the event delivered.
Resume and actual process restart/reconnect both preserved acknowledgements.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant