Repository navigation
improve(github): publication options load without re-verifying GitHub credentials on every session switch - #136223
Conversation
… per request `sessions.github.options` fires on every session switch, reconnect, and auth change, and production logs showed it above 1s for ~110 requests/day. Each call probed `api.github.com/user` twice (shared and personal credential), spawned `gh auth token` when `tools.github` is unconfigured, and ran session store discovery twice, materializing every `session_nodes` row before `.some()`. - `verifyGitHubCredential` now owns a bounded, token-keyed verification cache (60s TTL, 32 entries, positive results only, shared in-flight probes). Rotation changes the key and disconnect removes the token, so only remote revocation waits for the TTL. The GitHub OAuth lifecycle clears it on stop. - Options, status, and personal publish reads share one request-scoped store discovery cache; session rows and every `assertCurrent` authority check are still re-read live. - `readSessionEntryKeys` became the lazy `iterateSessionEntryKeys`, so fixed-store discovery stops at the first matching row. - The personal publish branch no longer pays for the shared path's session load. Warm `sessions.github.options` drops from ~275ms per request (two probes) to ~10ms; discovery per options read on a 2000-row fixed store 13.8ms -> 1.6ms.
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed September 2, 2026, 6:21 AM ET / 10:21 UTC. ClawSweeper reviewWhat this changesThe PR caches successful GitHub credential verification for 60 seconds and reuses session-store discovery within a GitHub publication request to speed Publish PR options. Merge readiness✅ Ready for maintainer review Keep open for normal maintainer handling: current main still performs the uncached verification path, while the member-authored PR has a bounded, owner-local optimization with no introduced correctness or security defect found. Priority: P2 Review scores
Verification
How this fits togetherControl UI publication requests ask the Gateway to resolve a GitHub identity and session ownership before returning options or executing a Publish PR action. This change avoids repeated remote credential checks and repeated store discovery while retaining live session and connection authorization checks. flowchart LR
A[Control UI session switch] --> B[Gateway publication request]
B --> C[Credential verification]
B --> D[Session store discovery]
C --> E[Publication options]
D --> E
E --> F[Publish PR action]
Before mergeNone. Agent review detailsSecurityNone. PR surfaceSource +69, Tests +398. Total +467 across 21 files. View PR surface stats
Review metrics
Technical reviewBest possible solution: Land the bounded verifier cache and request-scoped discovery reuse after ordinary exact-head CI and maintainer review, keeping the existing live session and connection assertions unchanged. Do we have a high-confidence way to reproduce the issue? Not applicable: this is a performance improvement rather than a report of broken output; the PR body supplies an isolated live Gateway measurement of the changed options path. Is this the best way to solve the issue? Yes. The cache sits at the credential-verification owner, and discovery reuse stays request-scoped while session rows and action authorization are reread live. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 37340e90d963. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
HistoryReview history (1 earlier review cycle)
|
…token cases The managed-credential and board Actions suites reuse one token literal across cases with different verification responses, so the new verification cache handed later cases an earlier case's account. Reset it per case, and expire it explicitly where a test needs the second probe to run.
|
Merged via squash.
|
… credentials on every session switch (openclaw#136223) * perf(github): cache credential verification and share store discovery per request `sessions.github.options` fires on every session switch, reconnect, and auth change, and production logs showed it above 1s for ~110 requests/day. Each call probed `api.github.com/user` twice (shared and personal credential), spawned `gh auth token` when `tools.github` is unconfigured, and ran session store discovery twice, materializing every `session_nodes` row before `.some()`. - `verifyGitHubCredential` now owns a bounded, token-keyed verification cache (60s TTL, 32 entries, positive results only, shared in-flight probes). Rotation changes the key and disconnect removes the token, so only remote revocation waits for the TTL. The GitHub OAuth lifecycle clears it on stop. - Options, status, and personal publish reads share one request-scoped store discovery cache; session rows and every `assertCurrent` authority check are still re-read live. - `readSessionEntryKeys` became the lazy `iterateSessionEntryKeys`, so fixed-store discovery stops at the first matching row. - The personal publish branch no longer pays for the shared path's session load. Warm `sessions.github.options` drops from ~275ms per request (two probes) to ~10ms; discovery per options read on a 2000-row fixed store 13.8ms -> 1.6ms. * test(github): reset the credential verification cache between reused-token cases The managed-credential and board Actions suites reuse one token literal across cases with different verification responses, so the new verification cache handed later cases an earlier case's account. Reset it per case, and expire it explicitly where a test needs the second probe to run.
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.
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.
* 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 #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.
…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.
What Problem This Solves
Resolves a problem where opening a session, reconnecting, or changing sign-in state in the Control UI made the Publish PR row's
sessions.github.optionsread take more than a second. Production logs show ~110 such slow reads per day. Every call re-verified the shared GitHub credential againstapi.github.com, re-verified the personal credential a second time, spawnedgh auth tokenwhentools.githubis unconfigured, and ran session store discovery twice, validating everysession_nodesrow before a.some().Why This Change Was Made
verifyGitHubCredentialnow owns a bounded, token-keyed verification cache (60s TTL, 32 entries, positive results only, concurrent probes for one token share a fetch). Invalidation is structural: rotation changes the key, disconnect or profile retirement yields no token before any lookup, and the GitHub OAuth lifecycle clears the cache on stop. Only a revocation performed on github.com waits for the TTL. Options, status, and personal publish reads share one request-scoped store discovery cache while session rows and everyassertCurrentauthority check are still re-read live.readSessionEntryKeysbecame the lazyiterateSessionEntryKeys, so fixed-store discovery stops at the first matching row. The personal publish branch no longer pays for the shared path's session load.Non-goals: the native
gh auth tokenread stays live per request because reading the token is what detects a host account change; no config, protocol, or schema surface was added.User Impact
The account chooser beside Publish PR loads immediately after the first verification instead of waiting on two GitHub round trips per session switch. Operators with a configured System or agent GitHub profile see warm
sessions.github.optionsreads drop from hundreds of milliseconds to single-digit milliseconds. Operators on the unconfigured hostghidentity still pay thegh auth tokenkeyring spawn (370-800 ms on macOS), which is now the dominant remaining cost and is left as a named follow-up.Evidence
Live dev gateway (isolated
OPENCLAW_STATE_DIR, port 18999,--ws-log full), realapi.github.comcalls with the host GitHub token, six sequentialsessions.github.optionsrequests. Server-side durations from the gateway log:tools.githubmanaged profile (system-configured)gh(system-detected)gh auth tokenspawn;gh auth tokenalone measures 0.37-0.80 s)Scratch benchmark (mocked 250 ms fetch, 2000-row fixed SQLite store), same harness run against pre-fix production files and the fix:
prepareGitHubPublicationIdentity/userfetches across 3 requestsloadGatewaySessionEntryReadOnlyreads (one options request)resolveExistingAgentSessionStoreTargetsSync, fixed storeRegression tests shown failing pre-fix (
expected "fetch" to be called once, but got 2 times;expected undefined to be an instance of Map). Fault-injection coverage: revoked token after TTL, unavailable token recovering on the next call, rotation bypassing the cache, disconnected profile without a probe, in-flight probe not repopulating a cleared cache, bounded eviction. Live-authority closures untouched (github-personal-authorization.test.tsasserts the same discovery Map across live re-reads).Local gates: focused Vitest (649 tests across 15 files + 25 in the data-version suite),
node scripts/check-changed.mjsgreen, Codex autoreview scoped-clean.Production LOC: +129/-60 (net +69; +48 is the cache itself, the rest is discovery plumbing). Tests: +318/-22 plus one new 100-line suite.