Repository navigation
perf(gateway): avoid repeated Access identity lookups on reload - #179571
Merged
Merged
Conversation
Contributor
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review in progressClawSweeper is reviewing this revision. This supersedes any previous blocked status. |
steipete
marked this pull request as ready for review
October 21, 2026 15:03
steipete
force-pushed
the
steipete/coldload-trusted-proxy-identity-network
branch
from
October 21, 2026 15:13
b3c50ab to
f5e5e9c
Compare
Contributor
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
steipete
force-pushed
the
steipete/coldload-trusted-proxy-identity-network
branch
from
October 21, 2026 15:36
f5e5e9c to
5278e60
Compare
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).
This was referenced Oct 25, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_grantswhile 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
expand 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_grantsand 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-entryhandoff, 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). Baseline303b8ff0aeb0ee7cd23e3fdc57644ab3dc0f26bf; candidateb3c50ab26531ee0a5540d9caa1b48c481af2e2f7. 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.
Outbound attribution
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 authenticatedsession-entryhandoff 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, runrun_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 replayrun_3e2928783ef64ef760e897658b7316c8passed all 30 OIDC tests and lint for the production owner and both touched test files. Independent review is clean through P2. Formatting andgit diff --checkpass.For the changed tests,
pnpm test <file> --maxWorkers=1took 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-changedis not wholly green: its unrelated max-lines and test-root budget failures also reproduce on untouched main1c3771ef93f8e2656cdff9208a41b72dae1ffb38. The max-lines checker rejects existing suppressions inui/src/pages/chat/components/chat-message.test.tsx,ui/src/pages/config/config-page-state.ts, andui/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_progressstatus 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_grantshistogram. 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-identityresult, never an authorization decision. What can be stale, and for how long: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.exp, 5 minutes). A new sign-in produces a new assertion and therefore a new cache key.get-identityaccepted 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 finiteexpare never cached; failures are evicted immediately (concurrent identical lookups share one in-flight request).