Skip to content

refactor(mcp): load OAuth only when credentials are needed - #147884

Merged
steipete merged 1 commit into
mainfrom
codex/r21-publish-mcp-demand
Sep 14, 2026
Merged

steipete merged 1 commit into
mainfrom
codex/r21-publish-mcp-demand

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

MCP setup and configuration paths eagerly load OAuth execution code even when no OAuth credential operation is needed.

User Impact

No intended user-visible behavior change. Requester sign-in, bearer projection, and credential cleanup retain their existing behavior. No configuration changes or migrations are required.

Why This Change Was Made

Load OAuth dependencies after transport and authentication eligibility checks, and only when configuration changes require credential cleanup.

Requester preparation captures the authorization callback so execution still starts authorization immediately after the existing validation, preserving requester isolation and retirement behavior.

Evidence

Local validation below used the same five file post-images before their mechanical replay onto current main. Current-head CI is separate.

  • 16 focused cases passed: three import-boundary cases, six bearer-projection cases, and seven configuration-mutation cases. Original eager imports failed the corresponding boundary controls.
  • Reused 15 unchanged earlier cases: two requester-connect cases and 13 selected reload, retirement, and crossed-publication cases.
  • Full build passed. Catalog readiness and 12 normal/live feature turns passed: eight code-mode turns, two tool-search turns, and two web search/fetch turns, with stable source/artifact identities and clean shutdown. These runs did not configure an MCP server or perform an OAuth login; MCP credential behavior is covered by the focused tests.
  • One startup comparison reduced loaded MCP SDK scripts from five to two and excluded the OAuth/client-auth implementation. Shared-auth and SDK types remain loaded. Post-GC heap was effectively unchanged and RSS was slightly higher; no memory reduction is claimed.

@clawsweeper

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

@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Sep 14, 2026
@steipete
steipete marked this pull request as ready for review September 14, 2026 04:25
@steipete
steipete requested a review from a team as a code owner September 14, 2026 04:25
@clawsweeper clawsweeper Bot added P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. 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 14, 2026
@clawsweeper

clawsweeper Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge. Reviewed September 14, 2026, 12:32 AM ET / 04:32 UTC.

ClawSweeper review

What this changes

Defers loading MCP OAuth code until credential operations are needed, while preserving requester sign-in timing and credential cleanup.

Merge readiness

✅ Ready for maintainer review

Keep open: this remains a useful, focused refactor, and no introduced correctness defect was found. Current main retains the eager imports; the protected maintainer label also excludes automatic closure.

Priority: P3
Reviewed head: d3011955b603ece3311a3fcbf8899dc84f1ebce8

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused, maintainable refactor with useful boundary coverage and no identified blocking defect.
Proof confidence 🌊 off-meta tidepool Not applicable: The external-contributor gate does not apply to this maintainer-authored internal refactor. The reported startup comparison addresses deferred loading; the unrelated feature turns do not prove OAuth login, which the body explicitly leaves to focused coverage. No material authority change requires additional final-effect proof.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Not applicable Not applicable: The external-contributor gate does not apply to this maintainer-authored internal refactor. The reported startup comparison addresses deferred loading; the unrelated feature turns do not prove OAuth login, which the body explicitly leaves to focused coverage. No material authority change requires additional final-effect proof.
Evidence reviewed 7 items Verified introduced changes: The pinned merge-base-to-head diff changes import timing and callback preparation without changing identity inputs, authorization results, or cleanup selection. Endpoint drift was excluded from PR ownership.
Requester lifecycle remains intact: The runtime wrapper checks the server's live connect fingerprint before invoking the prepared callback. The callback starts authorization without a new intervening import await; existing reload coverage rejects retained callbacks after retirement.
Cleanup and persisted contracts are preserved: Unchanged URL and identity mode still skip cleanup; requester-to-shared changes still clear requester rows only; other replacements clear server credentials. Dynamic loading remains inside the existing mutation lifecycle, with no schema, key, default, or configuration migration change.
Findings None None.
Security None None.

How this fits together

OpenClaw’s MCP integration turns configured external servers into agent tools. These paths prepare requester sign-in, supply bearer credentials, and clean up credentials when server configuration changes.

flowchart TD
  A[MCP server configuration] --> B[Transport and authentication checks]
  B --> C[No credential operation]
  B --> D[Load OAuth on demand]
  D --> E[Requester sign-in or bearer lookup]
  D --> F[Credential cleanup]
  E --> G[Authenticated agent tools]
Loading

Before merge

None.

Agent review details

Security

None.

PR surface

Source -4, Tests +18. Total +14 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 3 47 51 -4
Tests 2 19 1 +18
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 66 52 +14

Review metrics

None.

Technical review

Best possible solution:

Keep OAuth loading at credential-demand boundaries while retaining the existing identity, retirement, and cleanup owners.

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

Not applicable as a user-facing bug reproduction: current source establishes eager OAuth imports, and the PR reports a before/after startup comparison; this read-only review did not execute runtime code.

Is this the best way to solve the issue?

Yes. Moving imports behind existing eligibility checks is a narrow solution that preserves the credential owner and avoids introducing competing configuration or authentication paths.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 23ed4ec291f2.

Labels

Label changes:

  • add P3: This is bounded internal loading cleanup with no intended user-visible behavior or configuration change.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🌊 off-meta tidepool and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Not applicable: The external-contributor gate does not apply to this maintainer-authored internal refactor. The reported startup comparison addresses deferred loading; the unrelated feature turns do not prove OAuth login, which the body explicitly leaves to focused coverage. No material authority change requires additional final-effect proof.

Label justifications:

  • P3: This is bounded internal loading cleanup with no intended user-visible behavior or configuration change.
  • 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 external-contributor gate does not apply to this maintainer-authored internal refactor. The reported startup comparison addresses deferred loading; the unrelated feature turns do not prove OAuth login, which the body explicitly leaves to focused coverage. No material authority change requires additional final-effect proof.

Evidence

What I checked:

  • Verified introduced changes: The pinned merge-base-to-head diff changes import timing and callback preparation without changing identity inputs, authorization results, or cleanup selection. Endpoint drift was excluded from PR ownership. (src/agents/agent-bundle-mcp-requester-connect.ts:108, d3011955b603)
  • Requester lifecycle remains intact: The runtime wrapper checks the server's live connect fingerprint before invoking the prepared callback. The callback starts authorization without a new intervening import await; existing reload coverage rejects retained callbacks after retirement. (src/agents/agent-bundle-mcp-runtime.ts:353, d3011955b603)
  • Cleanup and persisted contracts are preserved: Unchanged URL and identity mode still skip cleanup; requester-to-shared changes still clear requester rows only; other replacements clear server credentials. Dynamic loading remains inside the existing mutation lifecycle, with no schema, key, default, or configuration migration change. (src/agents/mcp-config-mutation.ts:33, d3011955b603)
  • Current main and release still use eager imports: Inspection against fetched main 23ed4ec shows the same production delta. The supplied latest release, v2026.9.4, also statically imports the OAuth identity and runtime in bearer projection; no implemented-on-main closure is supported. (src/agents/mcp-auth-profile.ts:15, 3a9d69db306c)
  • Focused validation and proof scope: The captured PR body reports 16 focused cases, 15 reused cases, a full build, and a startup comparison reducing loaded MCP SDK scripts from five to two. It explicitly states that the general feature turns performed no MCP login and claims no memory reduction. Source inspection confirms meaningful import-boundary and immediate-authorization assertions. This review ran no tests or builds; git diff --check passed. (src/agents/agent-bundle-mcp-manager.requester-connect.test.ts:129, d3011955b603)
  • Relevant merged history: Current-main history identifies prior lazy-loading work by Peter Steinberger and requester OAuth work by Ayaan Zaidi. GitHub verified the corresponding merged PRs at fix(mcp): keep metadata and cleanup from eagerly loading runtimes #133028 and feat(mcp): per-requester OAuth for MCP servers #122166. Exact-line blame and historical patch inspection encountered unavailable objects with HTTP 403, so routing carries no verified introduction attribution. (src/agents/mcp-auth-profile.ts, 23ed4ec291f2)

Likely related people:

  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • obviyus: 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.

@steipete
steipete merged commit 3588d39 into main Sep 14, 2026
259 checks passed
@steipete
steipete deleted the codex/r21-publish-mcp-demand branch September 14, 2026 06:54
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

vincentkoc added a commit to nvtoroy/openclaw that referenced this pull request Sep 14, 2026
* commit '4ddb9ed21245eaca9f243e555a5ec070aaaf0dad': (113 commits)
  fix: avoid Gateway stalls when renaming sessions (openclaw#147869)
  refactor(plugins): reuse worker optional-method validation (openclaw#147925)
  refactor(infra): remove unreachable firewall diagnostic fallback (openclaw#147882)
  fix(ui): open attached automations from session hovercards (openclaw#147749)
  refactor(reply): share usage-bar numeric coercion (openclaw#147863)
  fix(doctor): report warnings for keyed agent configs (openclaw#123058)
  perf(plugins): reuse complete registry comparisons (openclaw#147893)
  fix(workboard): await lifecycle sweep completion in tests (openclaw#147950)
  fix: reduce stalls when browsing large session inventories (openclaw#147911)
  refactor(onboard): share custom model definition (openclaw#147915)
  feat(ios): collapse completed chat work above replies (openclaw#148002)
  fix(voice-call): retain state runtime for deferred streams (openclaw#147689)
  test(qa): compare Telegram entities semantically (openclaw#147752)
  fix(plugins): preserve runtime scope for deferred CLI actions (openclaw#147688)
  test(qa): keep Slack progress marker visible (openclaw#147748)
  test(qa): finish channel picker prompts (openclaw#147730)
  test(tui): handle auth restriction prompt (openclaw#147729)
  fix(qa): retain onboarding prompts across redraw bursts (openclaw#147687)
  fix(qa): seed Teams ambiguous timeout deterministically (openclaw#147686)
  refactor(mcp): load OAuth only when credentials are needed (openclaw#147884)
  ...
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling maintainer Maintainer-authored PR P3 Low-priority cleanup, docs, polish, ergonomics, or speculative work. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: S 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