Skip to content

refactor(gateway): simplify presence and profile request paths - #159130

Merged
steipete merged 2 commits into
mainfrom
perf/d3-presence-identity-deslop
Sep 26, 2026
Merged

steipete merged 2 commits into
mainfrom
perf/d3-presence-identity-deslop

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

The performance campaign left small amounts of redundant control flow and copied test behavior in Gateway presence, account identity requests, and profile avatar responses.

User Impact

No user-visible behavior changes. Presence publication, typing pacing, authorization, avatar freshness, HTTP caching, and error responses retain their existing contracts.

Why This Change Was Made

Remove timer-presence guards because Node defines clearTimeout(undefined) as a no-op; compare absent viewer declarations as the empty sets they already represent; inline an error callback left behind by the account-request async conversion; and let the avatar response helper own the identical cache policy previously repeated at three callers. Condense two repeated Gravatar comments while preserving their disclosure and timeout rationale.

The avatar HTTP suite no longer mocks the ETag formatter with a copy of its implementation. Its unchanged literal ETag assertions now exercise the production formatter. No tests or assertions were removed.

This is a small, honest consolidation. Pairing metadata allowlists and commit receipts, publication windows, typing authority checks, reconnect/roster jitter, and the distinct identity/avatar cache lifecycles stay intact. Larger apparent consolidations either crossed different contracts or touched files owned by open PRs; none of those files is changed here.

Evidence

Production: +25 / -67, net -42 LOC. Tests and test support: +0 / -7, net -7 LOC.

All 151 tests across 8 files pass on both the original base and the candidate using one Blacksmith Testbox, tbx_01m3fhp7nt1c6pdrdbyz2rv88a (run). Candidate source bytes were verified before execution.

Focused proof Baseline wall Candidate wall
Avatar HTTP suite, 29 tests, --maxWorkers=1 19.72 s 20.98 s
Seven owner/sibling suites, 122 tests 68.61 s 69.81 s

These are cold verification costs, including compiled-worker preparation, not a speedup claim. The changed test file adds no cases, assertions, timers, or test-only production seams. Hosted PR CI timing is pending.

node scripts/run-vitest.mjs src/gateway/user-profiles-http.test.ts --maxWorkers=1
node scripts/run-vitest.mjs \
  src/gateway/server-methods/session-typing-state.test.ts \
  src/gateway/session-viewer-presence.test.ts \
  src/gateway/server-methods/sessions-typing.test.ts \
  src/gateway/server-request-context.presence.test.ts \
  src/gateway/server-methods/users-auth-connect.test.ts \
  src/gateway/user-profiles-http.auth.test.ts \
  src/gateway/user-profiles-http.gravatar.test.ts

node scripts/check-changed.mjs -- <the five changed paths> passed on the same Testbox in 1,302.05 s, including production typecheck, all 25 test typecheck groups, changed-file lint, dead-export checks, and contract guards. Formatting and git diff --check passed. Deslop and test-audit are complete; independent Codex pre-commit and branch autoreviews are clean through P2. The committed tree exactly matches the validated candidate. The Testbox is stopped and its temporary source mirror removed.

The initial comparison setup failed before running tests: a borrowed root dependency link omitted a plugin-owned dependency, and a later Testbox sync replaced the carrier Git metadata supporting that temporary worktree. The completed comparison used a fresh, fully installed baseline and ran both revisions in one invocation. No product-code change was needed for either setup failure.

@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 gateway Gateway runtime size: S labels Sep 26, 2026
@steipete
steipete marked this pull request as ready for review September 26, 2026 19:42
@github-actions

github-actions Bot commented Sep 26, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components. This comment is informational because the PR author has repository Maintain or Admin access.

  • Current SHA: afcf26d9093138ae512126c2bed1e16978796d86
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/gateway/server-methods/users-auth-connect.ts: Controls Gateway authentication, pairing, or caller permissions. Check identity validation, scope checks, and revocation.

Carefully review these changes before merging.

@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. 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 26, 2026, 4:10 PM ET / 20:10 UTC.

ClawSweeper review

What this changes

The branch simplifies Gateway typing cleanup, viewer presence comparisons, account-connect error handling, and avatar response caching, while removing a test mock of the production ETag formatter.

Merge readiness

✅ Ready for maintainer review

Keep this coherent cleanup open. Current main retains the redundant paths, and review of the introduced changes and their callers found no actionable regression.

Priority: P3
Reviewed head: afcf26d9093138ae512126c2bed1e16978796d86

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, behavior-preserving patch has relevant comparative validation and no identified correctness or security defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The maintainer-authored refactor is exempt from contributor real-behavior proof. Its changed Gateway paths have comparative focused test evidence in the PR body, and the diff changes no stored-data contract.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The maintainer-authored refactor is exempt from contributor real-behavior proof. Its changed Gateway paths have comparative focused test evidence in the PR body, and the diff changes no stored-data contract.
Evidence reviewed 8 items Introduced patch: The pinned main-to-head diff changes five Gateway source and test files. The verified test merge has the pinned main and PR head as its parents and yields the same file set against main.
Account authority boundary: The changed wrapper still prepares the same scoped account action before invoking the service; the authority owner checks the live connection, profile identity, role, and scope.
Avatar response contract: Uploaded, host, and Gravatar hits all use the same response helper; it applies the prior success cache policy to both 200 and 304 responses, while misses retain no-store.
Findings None None.
Security None None.

How this fits together

The Gateway handles WebSocket presence and account requests and authenticated HTTP avatar requests. These paths produce live session indicators, account responses, and profile images for the Control UI.

flowchart LR
A[Viewer and typing requests] --> B[Presence and typing state]
B --> C[Control UI indicators]
D[Account requests] --> E[Authorization and replies]
E --> F[Account results]
G[Avatar HTTP requests] --> H[Avatar selection and cache headers]
H --> C
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -42, Tests -7. Total -49 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 4 25 67 -42
Tests 1 0 7 -7
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 25 74 -49

Review metrics

None.

Technical review

Best possible solution:

Keep these simplifications with their existing Gateway owners while preserving live account authorization and the distinct avatar success and miss cache policies.

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

Not applicable: the PR addresses redundant control flow rather than a reported behavior defect; its body reports comparative base and candidate tests.

Is this the best way to solve the issue?

Yes: the consolidation stays within the existing Gateway owners and preserves the traced authorization, presence publication, and HTTP cache contracts.

AGENTS.md: found and applied where relevant.

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

Labels

Label changes:

  • add P3: This is a bounded internal cleanup with no claimed user-visible behavior change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The maintainer-authored refactor is exempt from contributor real-behavior proof. Its changed Gateway paths have comparative focused test evidence in the PR body, and the diff changes no stored-data contract.

Label justifications:

  • P3: This is a bounded internal cleanup with no claimed user-visible behavior change.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool 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 maintainer-authored refactor is exempt from contributor real-behavior proof. Its changed Gateway paths have comparative focused test evidence in the PR body, and the diff changes no stored-data contract.

Evidence

What I checked:

  • Introduced patch: The pinned main-to-head diff changes five Gateway source and test files. The verified test merge has the pinned main and PR head as its parents and yields the same file set against main. (afcf26d90931)
  • Account authority boundary: The changed wrapper still prepares the same scoped account action before invoking the service; the authority owner checks the live connection, profile identity, role, and scope. (src/gateway/server-methods/users-model-account-access.ts:94, afcf26d90931)
  • Avatar response contract: Uploaded, host, and Gravatar hits all use the same response helper; it applies the prior success cache policy to both 200 and 304 responses, while misses retain no-store. (src/gateway/user-profiles-http.ts:249, afcf26d90931)
  • Production ETag assertion: With the copied formatter mock removed, literal HTTP ETag assertions exercise the formatter exported by the profile owner. (src/gateway/user-profiles-http.test.ts:132, afcf26d90931)
  • Current-main necessity: Current main still has the separate viewer-key comparator and absent-declaration branch that this PR consolidates, so the central cleanup has not landed there. (src/gateway/session-viewer-presence.ts:24, c0e6951d6f02)
  • Focused validation reported: The PR body reports 151 passing tests across eight files on both base and candidate, plus a passed changed-file check on a Testbox. This review did not execute those checks. (afcf26d90931)

Likely related people:

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

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.

@steipete
steipete merged commit fb3d7c3 into main Sep 26, 2026
200 checks passed
@steipete
steipete deleted the perf/d3-presence-identity-deslop branch September 26, 2026 20:20
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gateway Gateway runtime P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed 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