Skip to content

perf(gateway): avoid repeated Access identity lookups on reload - #179571

Merged
steipete merged 3 commits into
mainfrom
steipete/coldload-trusted-proxy-identity-network
Oct 21, 2026
Merged

steipete merged 3 commits into
mainfrom
steipete/coldload-trusted-proxy-identity-network

Conversation

@steipete

@steipete steipete commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

A signed-in reload of a dashboard deep link repeats Cloudflare Access identity lookups during document preparation and WebSocket admission. Existing cold-load evidence recorded a 679 ms document TTFB; recent document-stage attribution placed 25–250 ms in auth_grants while other stages were near the smallest bucket.

User Impact

Repeated requests with the same verified assertion avoid outbound identity round trips. New assertions still verify with Access, and GitHub refresh/failure handling remains unchanged.

Why This Change Was Made

The identity owner now coalesces and retains successful Access lookups under a SHA-256 key containing the complete signed assertion, normalized principal, and OIDC configuration. Entries are bounded to 200 and expire at the earlier of the assertion's exp and five minutes. Missing/expired/invalid expiry claims retain the existing uncached behavior. Failures are evicted. Current proxy admission and profile roles remain request-owned.

The HTTP profile is needed for role ceilings and plugin frame grants; role-aware WebSocket admission also needs it. Connections without role/access policies already defer enrichment. Moving a verified binding ahead of GitHub refresh would change non-retryable failure and attribution semantics, so this patch leaves that ordering intact.

Evidence

Predeclared gate: 11 interleaved baseline/candidate pairs on one quiet AWS instance, 100 ms mocked latency per Access/GitHub call. Warm document auth_grants and WebSocket connect-to-hello must improve in at least 9/11 pairs with negative median paired deltas. No additional outbound calls or authorization changes.

The real Gateway fixture exercises the app document handler, authenticated dashboard session-entry handoff, and WebSocket connect. The unmodified owner fails the regression because a warmed document still performs an Access lookup. Mocked endpoints only; no live account or identity services are used.

Measured on AWS lease cbx_611ffdc1d9dc (c7a.4xlarge, 16 CPUs, Node 24.19.0). Baseline 303b8ff0aeb0ee7cd23e3fdc57644ab3dc0f26bf; candidate b3c50ab26531ee0a5540d9caa1b48c481af2e2f7. One warm-up pair excluded, then 11 serial interleaved pairs, each with 100 ms mocked Access/GitHub latency. The only production difference is the identity owner; both variants use the same committed transport fixture.

Both primary metrics improve in 11/11 pairs, exceeding the declared 9/11 gate. Cold first-use has overlapping IQRs and a +3.36 ms median paired delta, below the regression threshold; its outbound work is identical.

Metric (ms) Baseline median [Q1, Q3] Candidate median [Q1, Q3] Median paired delta Improved pairs
Warm document auth_grants 106.42 [105.69, 109.27] 4.52 [4.43, 4.83] -101.47 11/11
Connect frame → hello 161.10 [159.92, 161.79] 57.93 [56.72, 59.08] -102.97 11/11
Authenticated dashboard handoff 412.91 [411.04, 416.73] 209.15 [205.70, 229.20] -200.87 11/11
Cold document auth_grants 992.67 [991.98, 998.37] 995.05 [978.94, 1001.33] 3.36 5/11
Pair Document delta (ms) Hello delta (ms) Handoff delta (ms)
1 -101.47 -102.97 -166.61
2 -109.37 -105.52 -200.87
3 -81.61 -148.15 -200.21
4 -101.93 -100.63 -213.17
5 -101.36 -103.65 -210.18
6 -102.24 -103.46 -205.42
7 -101.30 -117.79 -232.95
8 -108.74 -99.91 -174.54
9 -101.12 -80.66 -194.67
10 -101.47 -101.52 -201.97
11 -107.00 -92.78 -147.71

Outbound attribution

Request Baseline Access / GitHub calls Candidate Access / GitHub calls
First identity resolution 1 / 1 1 / 1
Warm app document 1 / 0 0 / 0
Authenticated dashboard handoff 2 / 0 0 / 0
WebSocket connect 1 / 0 0 / 0

The handoff performs authorization and bootstrap preparation separately. Both now consume the same verified assertion result. An expired GitHub metadata entry still refreshes through the existing owner and keeps its existing failure behavior.

Reproduce one sample with OPENCLAW_IDENTITY_NETWORK_BENCH_MS=100 node scripts/run-vitest.mjs src/gateway/server.auth.identity-network.test.ts --maxWorkers=1. The fixture times from the actual connect frame send, excluding device setup. The first app document primes the identity; the warm document and authenticated session-entry handoff use the same assertion. No browser rendering claim is made.

Focused local proof: 30 OIDC/profile cases pass; the real Gateway HTTP/WebSocket fixture passes. The original owner fails the new transport regression because warm document lookup count is 1 instead of 0. Coverage includes wrong principal, different/expired assertions, OIDC claim/config mismatch, in-flight policy changes, role revocation, and failure retry. Existing GitHub outage/fallback tests are retained. Fresh independent review is clean through P2.

Validation

Final candidate: 5278e601d6b150cec8505bcff2cb921052b1a80b. The measured revision above predates a diagnostic type assertion and lint-only corrections; the cache behavior is unchanged. The branch was rebased without conflicts before the final push.

AWS lease cbx_611ffdc1d9dc, run run_a3268293ec04f33284c1dadc09a9db58: all 130 focused tests passed across the transport fixture (1), OIDC/profile cases (30), GitHub identity (31), identity authority (1), HTTP authorization (25), and Control UI auth (42).

AWS lease cbx_870ab6aad8bc: the corrected transport fixture and targeted gateway-server TypeScript check passed. Final replay run_3e2928783ef64ef760e897658b7316c8 passed all 30 OIDC tests and lint for the production owner and both touched test files. Independent review is clean through P2. Formatting and git diff --check pass.

For the changed tests, pnpm test <file> --maxWorkers=1 took 19.55 s for the transport fixture and 28.29 s for OIDC on the warm measurement lease. Cold compiler preparation increased the later transport replay to 64.33 s and final OIDC replay to 52.77 s; these are validation costs, not performance measurements.

check-changed is not wholly green: its unrelated max-lines and test-root budget failures also reproduce on untouched main 1c3771ef93f8e2656cdff9208a41b72dae1ffb38. The max-lines checker rejects existing suppressions in ui/src/pages/chat/components/chat-message.test.tsx, ui/src/pages/config/config-page-state.ts, and ui/src/pages/sessions/sessions-page-state.ts. Main's core boundary checker reports 722 agents-root, 730 gateway-root, 749 infra, and 725 plugins-platform test roots against its 720 budget. These files and shard definitions are outside this patch. The candidate's diagnostic type error and two lint errors found during validation were fixed and rechecked.

Exact-head CI run 39627178135 completed successfully, including both selected UI e2e shards, lint, types, and PostgreSQL conformance. The dependency and security-sensitive review guards passed; GitHub's code review completed on the final head with no findings. A transient security-guard failure while its authority check reevaluated cleared without a code change or CI rerun. GitHub's job API retained an inconsistent in_progress status for PostgreSQL conformance (1/3); its final log confirms 256 tests in 39 files passed and successful cleanup at 15:57:39 UTC, before the parent workflow completed successfully. Both AWS leases are released and no fixture Gateway remains running.

The live check after the lead deploys is the document auth_grants histogram. No live deployment was performed; this PR is ready for lead review and must not be merged by this lane.

Production delta: +55 / -4 lines (+51 net). This replaces unconditional per-request lookup with one bounded, assertion-specific owner; positive growth is the expiry, scope-isolation, coalescing, and failure-eviction contract. No schema or config changes. No UI source changes.

Security boundary: revocation latency

This caches only the Cloudflare Access get-identity result, never an authorization decision. What can be stale, and for how long:

  • Access session revoked / user removed from the Access policy: no change. Cloudflare Access enforces this at its edge, so requests with the revoked session never reach the Gateway.
  • User removed from gateway.auth.trustedProxy.allowUsers, role or scope changes: no change. Proxy admission, required headers, allowUsers, roles/scopes, device approval and plugin frame grants are still evaluated per request.
  • GitHub account/org/team changes: no change. The GitHub identity metadata cache (15 min, ETag-revalidated) predates this patch and is unchanged.
  • Access identity fields for the same, still-valid assertion (e.g. an IdP/OIDC claim edited while the user keeps the same signed session): may be stale for at most min(assertion exp, 5 minutes). A new sign-in produces a new assertion and therefore a new cache key.
  • Validation before reuse: an entry exists only for an assertion that Access get-identity accepted and whose principal and OIDC trust configuration matched; the key is SHA-256 over the complete signed assertion, the normalized principal and the OIDC policy. Assertions without a finite exp are never cached; failures are evicted immediately (concurrent identical lookups share one in-flight request).

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: M labels Oct 21, 2026
@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. labels Oct 21, 2026
@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@steipete steipete changed the title experiment(control-ui): reuse verified Access identity [do not merge] perf(gateway): avoid repeated Access identity lookups on reload Oct 21, 2026
@steipete
steipete marked this pull request as ready for review October 21, 2026 15:03
@steipete
steipete force-pushed the steipete/coldload-trusted-proxy-identity-network branch from b3c50ab to f5e5e9c Compare October 21, 2026 15:13
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 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-21T15:55:09.525537Z 5278e60 New commits
ℹ️ 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:feature Preliminary submission classification; full source review pending. 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 21, 2026
@steipete
steipete force-pushed the steipete/coldload-trusted-proxy-identity-network branch from f5e5e9c to 5278e60 Compare October 21, 2026 15:36
@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. and removed clawsweeper:intake:feature Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. labels Oct 21, 2026
@steipete
steipete merged commit a03aec7 into main Oct 21, 2026
153 of 154 checks passed
@steipete
steipete deleted the steipete/coldload-trusted-proxy-identity-network branch October 21, 2026 16:07
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 22, 2026
openclaw#179571)

Team runs trusted-proxy auth behind Cloudflare Access (cloudflareAccessOidc). Every authenticated HTTP request that needs the user profile (the Control UI document's auth_grants stage) and every role-aware WebSocket connect called Access /cdn-cgi/access/get-identity over the network, uncached. Live after openclaw#179449: document auth_grants p50 ~80 ms (25-250 ms) while every other document stage was ~2.5 ms; WS connect took 160-320 ms.

Coalesce and retain successful Access identity lookups per assertion: the key is SHA-256 over the complete signed assertion, the normalized principal and the OIDC trust configuration; entries are bounded (200) and expire at min(assertion exp, 5 minutes); assertions without a finite exp are never cached; failures are evicted immediately. Proxy admission, allowUsers, roles/scopes, device approval and plugin frame grants remain per request; the GitHub identity refresh behavior is unchanged.

Security boundary (detailed in the PR): Access session revocation is enforced at the Cloudflare edge and authorization stays per request, so the only new staleness is Access identity fields for the same still-valid assertion, bounded by min(exp, 5 min).

Evidence (AWS c7a.4xlarge, 11 pairs, 100 ms mocked latency per Access/GitHub call): warm document auth_grants 106.42 -> 4.52 ms, WS connect -> hello 161.10 -> 57.93 ms, dashboard handoff 412.91 -> 209.15 ms, all 11/11; cold first use within noise.

Runtime +51 LOC. 130 focused tests (wrong principal, different/expired assertions, OIDC claim/config mismatch, in-flight policy changes, role revocation, failure retry), real Gateway HTTP/WS fixture; exact-head CI green.
steipete added a commit that referenced this pull request Oct 24, 2026
The cold-load bench's only handshake profile predated the Cloudflare Access identity cache (#179571): it simulated a 220 ms connect reply and 195 ms resolve/describe, while live Team now answers connect in about 25-90 ms at night. Lever rankings derived from it over-weighted the hello window.

Add named latency profiles in one resolver (scripts/lib/control-ui-bench-latency.ts): `default` (unchanged), `legacy-handshake` (the previous L179 scenario, kept for comparisons) and `live-fast` (per-method first-reply floors derived from timing-only medians of six night-time Team reloads: connect 41, chat.startup 220, sessions.messages.subscribe 183, sessions.resolve 216, board.get 189, ...). Explicit --method-latency-ms overrides still apply on top. The warm-reload probe now records challenge delivery so open -> challenge -> connect can be separated. These are browser delivery floors including queueing, not isolated server timings; defaults are unchanged.

Tooling and docs only (+114), product runtime 0. Resolver tests pass. The red checks-ui-e2e shard is the four sidebar-complete-roster.e2e.test.ts cases, which fail the same way on pinned main 7b71c23 (fix in progress separately).
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 24, 2026
…w#182092)

The cold-load bench's only handshake profile predated the Cloudflare Access identity cache (openclaw#179571): it simulated a 220 ms connect reply and 195 ms resolve/describe, while live Team now answers connect in about 25-90 ms at night. Lever rankings derived from it over-weighted the hello window.

Add named latency profiles in one resolver (scripts/lib/control-ui-bench-latency.ts): `default` (unchanged), `legacy-handshake` (the previous L179 scenario, kept for comparisons) and `live-fast` (per-method first-reply floors derived from timing-only medians of six night-time Team reloads: connect 41, chat.startup 220, sessions.messages.subscribe 183, sessions.resolve 216, board.get 189, ...). Explicit --method-latency-ms overrides still apply on top. The warm-reload probe now records challenge delivery so open -> challenge -> connect can be separated. These are browser delivery floors including queueing, not isolated server timings; defaults are unchanged.

Tooling and docs only (+114), product runtime 0. Resolver tests pass. The red checks-ui-e2e shard is the four sidebar-complete-roster.e2e.test.ts cases, which fail the same way on pinned main d88fc94 (fix in progress separately).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:intake:bug Preliminary submission classification; full source review pending. docs Improvements or additions to documentation gateway Gateway runtime size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant