Skip to content

fix(github): speed up repeated publication account discovery - #149372

Merged
steipete merged 2 commits into
mainfrom
steipete/perf-github-options-token-cache-20260915
Sep 16, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/perf-github-options-token-cache-20260915

Conversation

@steipete

@steipete steipete commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

What Problem This Solves

Publish PR account discovery repeatedly launches GitHub CLI on a busy Gateway, delaying Control UI responses. On team.openclaw.ai on September 15, sessions.github.options ran 1,328 times from 15 connections in one hour: p50 4,279 ms, p90 6,637 ms, maximum 13,312 ms, and 5,948 seconds of aggregate request time. Each spawn from the 5.7 GB Gateway also blocked its main thread for about 52 ms in fork().

Related: #136223, which cached successful GitHub credential verification but left native token discovery live on every request.

User Impact

Repeated account-options requests reuse the host's successful native GitHub credential lookup for 60 seconds, including concurrent requests. Host gh auth login/logout/switch changes may take up to that TTL to appear in read/options results. Actual publication still obtains a live native credential; environment tokens, managed credentials, caller permissions, and session access keep their live checks.

Why This Change Was Made

The options handler actually used publication preparation, so changing only the read-identity helper would miss the hotspot. Options now requests account facts through a dedicated read preparation backed by the same native-token cache as prepareGitHubReadIdentity; it receives no publication environment. Publication preparation retains the uncached native reader.

The cache is bounded to 32 successful entries, keyed by a hash of the full effective command environment, working directory, and absence-proof mode. It coalesces concurrent reads, expires after 60 seconds to match the existing verification TTL, and clears with verification-cache shutdown plus profile installation, rotation, retirement, removal, and personal disconnect. Pending old reads cannot repopulate a cleared cache. Failed token reads and anonymous-absence proofs remain uncached.

No configuration, schema, managed-identity authentication, OAuth protocol, subscription mechanics, or UI presentation changes.

Evidence

The candidate was rebased without conflicts onto main containing #149477 (476fa7a270e), which resolves the alias-fixture dependency failures. Both lane commits remain patch-identical. Earlier unrelated main lint failures were fixed by #149349 and #149423. The fresh pushed head is 305406c5d8c8e84bb7155117dbca0221ff4031eb; exact-head CI run 35046847413 passed, and the PR was merged as 1396e2b557b9.

  • Regression first: both the identity preparation and real options handler tests failed on the original production code with expected "vi.fn()" to be called once, but got 2 times. Both pass on the new head, including another native lookup after invalidation.
  • node scripts/run-vitest.mjs test/scripts/pr-wrappers.test.ts — all 92 tests passed, including all 12 alias-delegation and refusal cases (421.43 seconds).
  • node scripts/run-vitest.mjs src/agents/github-read-identity.test.ts src/agents/github-tool-identity.test.ts src/agents/github-managed-credential.test.ts src/agents/github-oauth-client.test.ts src/gateway/server-methods/sessions-github-read.test.ts src/gateway/server-methods/sessions-github.test.ts src/gateway/github-oauth-lifecycle.test.ts src/gateway/server-methods/board.github-actions.test.ts src/gateway/session-utils-store-lookup.test.ts src/gateway/github-publication-legacy-options.test.ts src/gateway/github-personal-publication.test.ts src/gateway/github-personal-publication-outcomes.test.ts — all 373 tests across 12 files passed (233.14 seconds).
  • node scripts/check-changed.mjs — passed, including core/test typechecks, targeted lint, unchanged ratchets, and zero runtime import cycles.
  • git diff --check — passed.
  • Independent Codex autoreview of the rebased diff: scoped-clean through P2, with zero findings.
  • Both documentation pages passed docs validation and describe the native-account detection delay.
  • Coverage includes TTL expiry, 15 concurrent native preparations, invalidation while a lookup is pending, different command environments, immediate environment-token changes, publication reading live while the read cache is warm, managed-profile isolation, and live caller authority. Delayed-native-read fixtures explicitly invalidate their cache before waiting on a fresh lookup; session and recovery fixtures use the options preparer.

Historical before/after measurements from the scoped regression harness: read identity 12.30 s / 2.74 GB peak RSS before, 14.21 s / 2.99 GB after; options handler 23.06 s / 2.81 GB before, 19.60 s / 2.75 GB after. These import-heavy mocked runs measure harness cost. They do not establish production latency or memory improvement.

The supplied production latency establishes the problem; the regressions prove eliminated repeated native spawns. The live Gateway was not modified or restarted. Failed native token lookups remain live, and an expired-cache request still pays the native command cost.

Warm request trace before this change

Citations below use the pre-change base 56fa637fbef619f752702ecd687688cf1620b0a7.

  1. Options admission and response prepares current caller/session read authority. Authorization already shares store discovery within the request and rereads live session/access facts before delivery.
  2. Shared preparation requests OAuth refresh and calls publication identity preparation. Native/unconfigured refresh returns from config alone; a managed OAuth identity reads its record and refreshes only when needed.
  3. Native credential lookup checks environment tokens, otherwise spawns gh auth token --hostname github.com once per options request. This options path does not request anonymous proof, call gh auth status, or run the git config status probe.
  4. Credential verification normally hits the existing successful 60-second token-keyed cache; misses make GET https://api.github.com/user. Warm healthy requests therefore still spawn even when they make no GitHub network request.
  5. Eligible personal status reads the caller's connection and rechecks its generation around managed-profile preparation. That path performs private-file metadata checks, protected reads, YAML parsing, and cached verification, with no subprocess.
  6. Receipt dispatch queries repository/worktree receipts scoped to session, agent, and personal owner when applicable. Session lookup requests exact-key reads, not full-store payload loads. These live-authority reads remain unchanged.

No other unconditional per-call spawn or full-store payload read was found. Fixed/shared session.store discovery can scan keys to find an agent; authorization already request-scopes that discovery, while receipt readers perform their own discovery. Propagating discovery context into receipt interfaces is left outside this measured native-token fix.

@clawsweeper

clawsweeper Bot commented Sep 15, 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.

@steipete
steipete marked this pull request as ready for review September 15, 2026 19:33
@steipete
steipete requested a review from a team as a code owner September 15, 2026 19:33
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime agents Agent runtime and tooling size: M maintainer Maintainer-authored PR labels Sep 15, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. 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 15, 2026
@clawsweeper

clawsweeper Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 15, 2026, 10:19 PM ET / September 16, 2026, 02:19 UTC (Revision 8).

ClawSweeper review

What this changes

Caches successful native GitHub credential lookups for account discovery and authenticated reads for 60 seconds, while keeping publication credential reads live.

Merge readiness

⛔ Blocked before merge - 1 item remains

This remains a useful follow-up to the earlier credential-verification optimization: current main still launches native credential discovery repeatedly. No actionable introduced defect was found, and the maintainer-authored proposal explicitly documents its bounded account-switch delay.

Priority: P2
Reviewed head: 305406c5d8c8e84bb7155117dbca0221ff4031eb

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused implementation with relevant regression coverage and an explicit freshness tradeoff; production performance improvement remains unmeasured.
Proof confidence 🌊 off-meta tidepool Not applicable: The supplied repository state identifies a maintainer-authored PR, so the external-contributor proof gate does not apply. Its options-handler and identity tests exercise the changed owner with mocked CLI/network boundaries; production measurements establish the original hotspot, not an observed after-fix speedup. No additional unresolved forbidden-caller path was identified.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The supplied repository state identifies a maintainer-authored PR, so the external-contributor proof gate does not apply. Its options-handler and identity tests exercise the changed owner with mocked CLI/network boundaries; production measurements establish the original hotspot, not an observed after-fix speedup. No additional unresolved forbidden-caller path was identified.
Evidence reviewed 8 items Introduced cache and invalidation: The cache stores only successful native token lookups, separates effective environments and working directories, coalesces concurrent requests, and prevents old pending lookups from refilling the current cache after invalidation.
Publication and read boundaries: Publication preparation retains the uncached reader; options return only account facts. Read preparation preserves caller admission and current identity selection checks. The GitHub Actions owner gates both fetch initiation and result delivery through that read authority.
Actual request wiring and live authorization: The options handler uses the new account-only preparation and rereads current session access before responding. Its authorization owner checks connection liveness, current role permissions, personal ownership, and session identity independently of the credential cache.
Findings None None.
Security None None.

How this fits together

The Gateway resolves GitHub identities for publication account choices and authenticated repository reads. This cache reduces repeated GitHub CLI launches without supplying cached credentials to publication preparation.

flowchart TD
  A[Account options and repository reads] --> B[Current caller and identity checks]
  B --> C{Credential source}
  C --> D[Native lookup cache]
  C --> E[Live environment or managed credential]
  D --> F[Verified account and authorized reads]
  E --> F
  G[Publication request] --> H[Fresh native credential and account check]
Loading

Before merge

  • Resolve merge risk (P1) - Host logout or account switching can leave authenticated reads using the previous native credential for up to the cache TTL; publication can reject an account choice displayed during that interval.
Agent review details

Security

None.

PR surface

Source +93, Tests +155, Docs +5. Total +253 across 15 files.

View PR surface stats
Area Files Added Removed Net
Source 7 100 7 +93
Tests 6 169 14 +155
Docs 2 6 1 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 15 275 22 +253

Review metrics

Metric Value Why it matters
Credential freshness 60-second native-read TTL; 32 successful entries This bounds the intentional account-discovery delay and retained cache size.
Production versus test growth Production net +93 lines; tests and test support net +155 lines Production growth implements the measured native-spawn hotspot, its options-path cutover, and lifecycle invalidation.

Merge-risk options

Maintainer options:

  1. Retain the documented discovery delay (recommended)
    Accept the proposal's bounded native-account staleness while preserving fresh publication credentials and independent caller checks.

Technical review

Best possible solution:

Keep native discovery caching bounded and lifecycle-owned, preserve live publication and caller authorization, and retain the documented account-switch tradeoff.

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

Yes, source establishes that consecutive options requests without an environment or managed credential repeatedly launch native token discovery; the body also supplies production latency measurements. This review did not execute that path.

Is this the best way to solve the issue?

Yes, the patch reaches the measured handler and reuses the existing identity owner while keeping publication fresh; its native-account freshness tradeoff is explicit.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 78052a3386b3.

Labels

Label justifications:

  • P2: Addresses measured publication account-discovery latency without an established core outage.
  • merge-risk: 🚨 auth-provider: Native account changes become visible to read and options consumers only after cache expiry or invalidation.
  • 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 supplied repository state identifies a maintainer-authored PR, so the external-contributor proof gate does not apply. Its options-handler and identity tests exercise the changed owner with mocked CLI/network boundaries; production measurements establish the original hotspot, not an observed after-fix speedup. No additional unresolved forbidden-caller path was identified.

Evidence

What I checked:

Likely related people:

  • unknown: The claimed source-line change could not be verified from bounded local history. (role: source history unknown; 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.

History

Review history (7 earlier review cycles)
  • reviewed 2026-09-15T19:58:16.646Z sha 583ce9a92799851fab87b16634a420731862ac3b :: blocked before merge. :: none
  • reviewed 2026-09-15T20:57:36.772Z sha 3885ab3 :: blocked before merge. :: none
  • reviewed 2026-09-15T21:23:25.566Z sha 3885ab3 :: blocked before merge. :: none
  • reviewed 2026-09-15T22:58:22.678Z sha be2c4214480db099192cca81c3e65617331ccf57 :: blocked before merge. :: none
  • reviewed 2026-09-16T00:21:26.454Z sha be2c4214480db099192cca81c3e65617331ccf57 :: blocked before merge. :: none
  • reviewed 2026-09-16T00:32:09.365Z sha be2c4214480db099192cca81c3e65617331ccf57 :: blocked before merge. :: none
  • reviewed 2026-09-16T01:12:15.963Z sha be2c4214480db099192cca81c3e65617331ccf57 :: blocked before merge. :: none

Repeated publication account discovery spawns gh auth token even when
GitHub verification is already cached. Reuse successful native reads for
60 seconds across read preparations and options requests, with OAuth and
profile lifecycle invalidation. Keep publication credential reads live.

Follow up on #136223. Host login, logout, and account switching may take
up to the read-cache TTL to appear in account options.
Bind the session ownership and publication recovery fixtures to the
read/options preparer while preserving their existing owner and account
assertions after the options handler cutover.
@steipete
steipete force-pushed the steipete/perf-github-options-token-cache-20260915 branch from be2c421 to 305406c Compare September 16, 2026 02:08
@steipete
steipete merged commit 1396e2b into main Sep 16, 2026
194 checks passed
@steipete
steipete deleted the steipete/perf-github-options-token-cache-20260915 branch September 16, 2026 04:04
@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 16, 2026
…w#149372)

* perf(github): cache native credentials for read options

Repeated publication account discovery spawns gh auth token even when
GitHub verification is already cached. Reuse successful native reads for
60 seconds across read preparations and options requests, with OAuth and
profile lifecycle invalidation. Keep publication credential reads live.

Follow up on openclaw#136223. Host login, logout, and account switching may take
up to the read-cache TTL to appear in account options.

* test(github): update publication options identity fixtures

Bind the session ownership and publication recovery fixtures to the
read/options preparer while preserving their existing owner and account
assertions after the options handler cutover.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. P2 Normal backlog priority with limited blast radius. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M 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