Skip to content

perf(gateway): pace typing requests with prepared sharing facts - #158552

Merged
steipete merged 4 commits into
mainfrom
perf/l37-typing-projection
Sep 26, 2026
Merged

steipete merged 4 commits into
mainfrom
perf/l37-typing-projection

Conversation

@steipete

@steipete steipete commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Typing in the Control UI repeatedly blocks the Gateway main thread on session reads, even when nobody else can receive the preview.

User Impact

Draft previews retain the latest text while typing requests are paced to the existing 250 ms preview cadence. Stop requests cancel queued UI previews immediately. Delayed Gateway emissions recheck the live connection, session generation, and current sharing authority.

Why This Change Was Made

Typing now consumes the existing session projection and prepared sharing owner instead of resolving session targets twice through synchronous SQLite. Undeliverable attempts retain their throttle window, and prepared event authorization no longer allocates unused legacy lookup maps. Authorized incognito typing keeps the existing transient exact-read path.

Related: #158497 already contains the identical client-presence lookup cleanup, so that change is left with the presence PR. No protocol, configuration, or database schema changes.

Evidence

  • Registered handleGatewayRequest microbenchmark, 50 independent lone-viewer sessions, 30 interleaved A/B pairs after 10 warmups, Node v26.9.0. Fresh attempts: median wall 15.521 → 2.053 ms, main-thread CPU 13.305 → 1.823 ms (86.3% less). Retained throttle: wall 19.446 → 1.721 ms, CPU 13.365 → 1.332 ms (90.0% less).
  • Main-thread SQLite statements: 400 → 0 per 50 requests, or 8 → 0 per input, in both scenarios. All 12,200 requests succeeded and recorded activity; zero events were emitted. Socket transport and activity publication are outside this component benchmark.
  • Standalone proof imports the unchanged UI typing owner through tsx with narrow dependency fixtures and a deterministic clock: 10 → 5 RPCs for ten inputs at 100 ms intervals, verified A/B/A/B. Latest trailing text, immediate stop/new burst, connection/session/role invalidation, lifecycle cleanup, and Unicode clipping pass (3.842 s process wall, 89.7 ms owner import/assertions). This is an owner-boundary proof, not composer DOM/WebSocket integration.
  • Deterministic registered-RPC lifecycle proof: 14 baseline/current scenarios, 30 successful requests using real SQLite mutations, projection, sharing policy, presence, and typing state. Latest trailing delivery and cancellation after disconnect, client invalidation, lost authority, withdrawn sharing, new session ID, and same-ID lifecycle replacement pass. The original implementation reproduces five failures; sharing/new-ID cases are preservation controls. 123.367 s process wall, including imports/hydration; assertions take 108.4 ms. The first attempt correctly rejected a numeric lifecycle-revision fixture; the corrected fixture uses the contract's string type.
  • Initial lane Vitest attempts did not produce test verdicts (superseded by the landing validation below). node scripts/run-vitest.mjs run --config test/vitest/vitest.gateway-methods.config.ts src/gateway/server-methods/session-typing-state.test.ts src/gateway/server-methods/sessions-typing.test.ts src/gateway/server-methods/sessions-suggestions.test.ts src/gateway/server-methods/sessions-suggestions.visibility.test.ts --maxWorkers=1 --reporter=verbose hit the repository's 120-second no-output watchdog (150.17 s wall, exit 143). The UI owner config with ui/src/pages/chat/chat-pane-typing.test.ts --maxWorkers=1 did likewise (148.63 s wall, exit 143) after a Lit warning. Earlier aggregate/owner attempts built worker-test caches and were canceled without verdicts. These remain explicit Vitest validation gaps; no assertion or timeout was weakened.
  • Production: +183/−84, net +99 lines. Tests/support: +302/−150, net +152 lines. The increase funds the bounded UI trailing-request timer and the connection/session/sharing checks; redundant typing-state fields and repeated role checks were removed. Documentation: net zero lines.
  • Deslop completed; independent Codex review is scoped-clean through P2, with no accepted/actionable findings.
  • Changed-lane validation attempted on Blacksmith Testbox tbx_01m3djxhdjzsc6813837598nsw (run). The default-base attempt stopped on an unrelated assertion ratchet because the shared local origin/main ref was stale. Repeating node scripts/check-changed.mjs --base bfabd8e3f7b77cf01cb792becc019ac557c9cac1 failed during Blacksmith source sync before checks executed (outer five-minute stall guard, then native two-minute sync timeout). The box is stopped. Full changed-lane lint/typechecking remains a hosted-CI validation gap.

Landing validation

Hosted CI run 36209775208 exposed four deterministic failures in the delayed-refresh table in sessions-typing.test.ts. The first case retained the process-wide typing throttle; subsequent cases reused the same session key while resetting the fake clock, so their initial broadcast was incorrectly throttled. The fixture now clears the existing typing-state owner before and after each case, cancelling its pending timers before restoring real timers. Production behavior and all assertions remain unchanged.

The full pre-fix typing file reproduced the same four failures locally (13 passed, 4 failed; 811.59 s process wall on the I/O-saturated host). After the fixture repair, node scripts/run-vitest.mjs src/gateway/server-methods/sessions-typing.test.ts src/gateway/server-methods/session-typing-state.test.ts --maxWorkers=1 passed all 26 tests in both files (505.53 s process wall; Vitest 470.93 s). Hosted failing shard duration was 137.56 s across 64 files. This extends existing lifecycle coverage and adds no test cases or production seams. Formatting and whitespace checks pass; independent Codex review of the repair is scoped-clean through P2. Subsequent hosted CI found the separate fixture issue below.

The next exact-head run 36211649369 exposed the positive incognito typing case in sessions-suggestions.visibility.test.ts. This was a second fixture defect: the file eagerly imported the handlers before the shared presence mock registered. A local reproduction failed identically (146.05 s process wall); temporary diagnostic evidence showed two configured fixture viewers but an empty presence set in the real typing owner. The handler import now follows shared mock registration. The diagnostic was removed, and neither product code nor assertions changed.

node scripts/run-vitest.mjs src/gateway/server-methods/sessions-suggestions.visibility.test.ts src/gateway/server-methods/sessions-suggestions.test.ts --maxWorkers=1 now passes all 27 tests (188.00 s process wall; Vitest 154.66 s). The failing hosted shard took 164.74 s across 57 files. The existing positive incognito assertion is the regression; no new tests or production seams were added. Formatting and whitespace checks pass. Independent Codex review of this fixture repair is scoped-clean through P2. A later CI run exposed the remaining direct-caller fixture below. A two-client Control UI/WebSocket demonstration remains unrun; existing boundary and registered-request proof is described above.

Run 36213463084 then reached server-request-context.presence.test.ts, whose direct typing call still used an uninitialized session projection. The other direct typing callers already prepared their test context. This fixture now awaits the existing test-owned session-read initializer once before typing, preserving the handler's production startup requirement and the activity/presence assertions. The unchanged case reproduced locally with the same startup error (60.15 s process wall).

node scripts/run-vitest.mjs src/gateway/server-request-context.presence.test.ts --maxWorkers=1 passes all 10 tests after the repair (44.73 s process wall; Vitest 37.29 s). The failing hosted child shard took 89.11 s across 46 files. Formatting and whitespace checks pass. The existing typing/presence integration case is the regression; no new test cases were added. Independent Codex review of this fixture repair is scoped-clean through P2. Final exact-head hosted CI is green for bfe8ce1f01ad95fc23c0821940349c530525e46e: run 36214896942, verified by the repository CI watcher. The three fixture repairs preserve all production code and assertions; 63 focused tests pass across their owning files.

@clawsweeper

clawsweeper Bot commented Sep 26, 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 gateway Gateway runtime size: L labels Sep 26, 2026
@steipete
steipete marked this pull request as ready for review September 26, 2026 01:50
@clawsweeper clawsweeper Bot added 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. labels Sep 26, 2026
@clawsweeper

clawsweeper Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 25, 2026, 11:56 PM ET / September 26, 2026, 03:56 UTC (Revision 3).

ClawSweeper review

What this changes

The branch paces Control UI draft-preview requests and uses prepared Gateway session-sharing facts when deciding whether to broadcast typing updates.

Merge readiness

✅ Ready for maintainer review

Keep open. Current main still uses the older typing path, and the merged presence work does not supply this PR’s distinct typing improvements. The introduced patch has no supported blocking finding.

Priority: P2
Reviewed head: bfe8ce1f01ad95fc23c0821940349c530525e46e

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) The patch has meaningful boundary proof and green exact-head CI, with a two-client presentation capture still available to strengthen confidence.
Proof confidence 🐚 platinum hermit (4/6) Not applicable: The recorded author association is MEMBER, so the external-contributor proof gate does not apply. The PR body reports registered Gateway RPC and UI-owner terminal traces covering pacing and revocation with real SQLite; a two-client WebSocket/UI capture remains unrun. No stored-data contract changes.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The recorded author association is MEMBER, so the external-contributor proof gate does not apply. The PR body reports registered Gateway RPC and UI-owner terminal traces covering pacing and revocation with real SQLite; a two-client WebSocket/UI capture remains unrun. No stored-data contract changes.
Evidence reviewed 8 items Introduced Gateway path: The pinned introduction changes session.typing to read prepared session facts and recheck connection, session generation, role, and sharing authority before broadcast.
Introduced UI pacing: The UI retains the latest queued preview, cancels it on Stop or cleanup, and checks the connection and selected session before a delayed request.
Final recipient boundary: The broadcaster requires a session subscription for typing and applies recipient session visibility checks before sending.
Findings None None.
Security None None.

How this fits together

The Control UI sends typing requests for the selected session to the Gateway. The Gateway checks session and sharing authority, then sends eligible previews to subscribed collaborators.

flowchart LR
  A[Chat composer input] --> B[Control UI request pacing]
  B --> C[Gateway typing request]
  C --> D[Session and sharing facts]
  D --> E[Live authority check]
  E --> F[Recipient filtering]
  F --> G[Collaborator preview]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +99, Tests +158, Docs 0. Total +257 across 12 files.

View PR surface stats
Area Files Added Removed Net
Source 4 183 84 +99
Tests 7 309 151 +158
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 12 493 236 +257

Review metrics

Metric Value Why it matters
Main-thread SQLite 8 → 0 statements per typing input in the reported benchmark The registered-handler measurement addresses the repeated Gateway work this PR targets.
Code balance production net +99 lines; tests and support net +152 lines The PR attributes production growth to bounded request pacing and live-authority checks.

Mantis proof suggestion

A two-client Control UI chat capture would directly show the preview behavior left open by the boundary traces. A maintainer can ask Mantis to capture proof by posting this exact PR comment:

@openclaw-mantis verify in two Control UI chat clients that rapid typing shows the latest paced collaborator preview, Stop removes it immediately, and withdrawn sharing prevents later previews; return redacted interaction evidence.

Technical review

Best possible solution:

Keep live caller and session checks at the Gateway broadcast boundary, with recipient filtering owning disclosure and UI pacing scoped to the current connection.

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

Yes. Current main still sends typing requests without UI pacing, and its Gateway handler uses synchronous target resolution; the PR supplies a registered-handler benchmark, though this review did not execute it.

Is this the best way to solve the issue?

Yes. The branch reuses the existing session projection and sharing owner, adds no storage or protocol contract, and checks authority again before broadcast.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 15a0f34487b5.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P2: Shared-session typing performance is a bounded user-facing improvement without evidence of an urgent outage.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The recorded author association is MEMBER, so the external-contributor proof gate does not apply. The PR body reports registered Gateway RPC and UI-owner terminal traces covering pacing and revocation with real SQLite; a two-client WebSocket/UI capture remains unrun. No stored-data contract changes.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • RoboClaw: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • Shakker: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rank-up moves

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

  • Capture a redacted two-client Control UI or WebSocket interaction showing the latest paced preview, immediate Stop, and no later preview after sharing is withdrawn.

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
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.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-26T01:58:52.379Z sha 0872add :: needs changes before merge. :: none
  • reviewed 2026-09-26T03:09:00.883Z sha 9eef4e3 :: needs maintainer review before merge. :: none

Clear the existing typing-state owner at each fixture boundary, including its pending timers before restoring real timers. Reusing the session key and resetting the clock otherwise makes the later delayed-refresh cases inherit the first case throttle window.
The positive incognito typing case loaded the real presence provider before the shared mock registered. Load the handler after mock initialization so the existing assertion reaches delivery with its two synthetic viewers.
Initialize the existing test-owned session read context before the direct typing handler call. Production startup already owns this projection; the presence fixture must satisfy the same requirement.
@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. labels Sep 26, 2026
@steipete
steipete merged commit 1e6224b into main Sep 26, 2026
242 checks passed
@steipete
steipete deleted the perf/l37-typing-projection branch September 26, 2026 04:01
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 26, 2026
…claw#158552)

* perf(gateway): pace typing requests with prepared sharing facts

* test(gateway): reset typing state between handler tests

Clear the existing typing-state owner at each fixture boundary, including its pending timers before restoring real timers. Reusing the session key and resetting the clock otherwise makes the later delayed-refresh cases inherit the first case throttle window.

* test(gateway): register suggestion mocks before loading handlers

The positive incognito typing case loaded the real presence provider before the shared mock registered. Load the handler after mock initialization so the existing assertion reaches delivery with its two synthetic viewers.

* test(gateway): prepare typing projection in presence fixture

Initialize the existing test-owned session read context before the direct typing handler call. Production startup already owns this projection; the presence fixture must satisfy the same requirement.
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 gateway Gateway runtime P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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