Skip to content

improve(github): publication options load without re-verifying GitHub credentials on every session switch - #136223

Merged
steipete merged 2 commits into
mainfrom
steipete/zen-dubinsky-2696cf
Sep 2, 2026
Merged

steipete merged 2 commits into
mainfrom
steipete/zen-dubinsky-2696cf

Conversation

@steipete

@steipete steipete commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

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.options read take more than a second. Production logs show ~110 such slow reads per day. Every call re-verified the shared GitHub credential against api.github.com, re-verified the personal credential a second time, spawned gh auth token when tools.github is unconfigured, and ran session store discovery twice, validating every session_nodes row before a .some().

Why This Change Was Made

verifyGitHubCredential now 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 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.

Non-goals: the native gh auth token read 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.options reads drop from hundreds of milliseconds to single-digit milliseconds. Operators on the unconfigured host gh identity still pay the gh auth token keyring 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), real api.github.com calls with the host GitHub token, six sequential sessions.github.options requests. Server-side durations from the gateway log:

Identity Cold Warm (5 subsequent calls)
tools.github managed profile (system-configured) 578 ms 4 ms each
unconfigured host gh (system-detected) 755 ms 342-605 ms (all gh auth token spawn; gh auth token alone 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:

Measure Before After
warm prepareGitHubPublicationIdentity ~275 ms ~10 ms
/user fetches across 3 requests 3 1
two loadGatewaySessionEntryReadOnly reads (one options request) 13.8 ms 1.6 ms
resolveExistingAgentSessionStoreTargetsSync, fixed store 2.6 ms 0.8 ms

Regression 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.ts asserts 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.mjs green, 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.

… 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.
@clawsweeper

clawsweeper Bot commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

@steipete
steipete marked this pull request as ready for review September 2, 2026 09:38
@steipete
steipete requested a review from a team as a code owner September 2, 2026 09:38
@openclaw-barnacle openclaw-barnacle Bot added gateway Gateway runtime agents Agent runtime and tooling size: L maintainer Maintainer-authored PR labels Sep 2, 2026
@clawsweeper clawsweeper Bot added P2 Normal backlog priority with limited blast radius. 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 2, 2026
@clawsweeper

clawsweeper Bot commented Sep 2, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 2, 2026, 6:21 AM ET / 10:21 UTC.

ClawSweeper review

What this changes

The 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
Reviewed head: 6a3de88eb01fbde7efb8c4772eb0d1832ab970de

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, well-covered performance repair with credible real-path measurements and no actionable defect found.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (logs): The PR body maps the changed verifier and Gateway options path to six sequential requests against an isolated development Gateway using real api.github.com calls, reporting a cold managed-profile read of 578 ms and five 4 ms warm reads.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (logs): The PR body maps the changed verifier and Gateway options path to six sequential requests against an isolated development Gateway using real api.github.com calls, reporting a cold managed-profile read of 578 ms and five 4 ms warm reads.
Evidence reviewed 6 items Introduced credential-cache owner: The verifier hashes the token, returns only unexpired successful results, and bounds the cache to 32 entries; failed verification is not cached.
Live authorization remains at the action boundary: Personal publication still captures a direct connection closure and rereads the session before the action; the request handler invokes assertCurrent after the asynchronous personal request.
Session discovery is request-scoped: The options reader allocates one discovery map, passes it to both reads, and still performs a fresh session-entry read when currentSession is called.
Findings None None.
Security None None.

How this fits together

Control 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]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source +69, Tests +398. Total +467 across 21 files.

View PR surface stats
Area Files Added Removed Net
Source 9 129 60 +69
Tests 12 420 22 +398
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 549 82 +467

Review metrics

Metric Value Why it matters
Production versus test delta production +129/-60; tests and test support +418/-20 The net production growth is the bounded cache and request-scoped discovery plumbing; the larger test delta exercises expiry, invalidation, token rotation, and live rereads.

Technical review

Best 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.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient. The PR body maps the changed verifier and Gateway options path to six sequential requests against an isolated development Gateway using real api.github.com calls, reporting a cold managed-profile read of 578 ms and five 4 ms warm reads.

Label justifications:

  • P2: This improves a repeatedly slow publication-options path without evidence of an outage, data loss, or authorization bypass.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The PR body maps the changed verifier and Gateway options path to six sequential requests against an isolated development Gateway using real api.github.com calls, reporting a cold managed-profile read of 578 ms and five 4 ms warm reads.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR body maps the changed verifier and Gateway options path to six sequential requests against an isolated development Gateway using real api.github.com calls, reporting a cold managed-profile read of 578 ms and five 4 ms warm reads.

Evidence

What I checked:

Likely related people:

  • steipete: 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.

History

Review history (1 earlier review cycle)
  • reviewed 2026-09-02T09:47:04.508Z sha 56f0772 :: needs maintainer review before merge. :: none

…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.
@clawsweeper clawsweeper Bot added the proof: sufficient ClawSweeper judged the real behavior proof convincing. label Sep 2, 2026
@steipete
steipete merged commit b35d2be into main Sep 2, 2026
491 of 493 checks passed
@steipete
steipete deleted the steipete/zen-dubinsky-2696cf branch September 2, 2026 11:02
@steipete

steipete commented Sep 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 3, 2026
… 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.
steipete added a commit that referenced this pull request Sep 15, 2026
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.
steipete added a commit that referenced this pull request Sep 16, 2026
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.
steipete added a commit that referenced this pull request Sep 16, 2026
* 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.
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 gateway Gateway runtime maintainer Maintainer-authored PR P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: L 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