← Back to Pull requests

fix(runtime): use cached OAuth when static Authorization resolves empty #506

Merged
koinzhang merged 3 files (292 lines) on Nov 14, 2026 05:14 UTC
View on GitHub
koinzhang koinzhang commented on Nov 13, 2026 14:51 UTC
Author

When a configured Authorization value resolves to an empty value or a scheme-only Bearer header, listing tools now uses the cached OAuth token. Resolve placeholders with the same environment semantics as HTTP transport, retain valid static credentials, and remove unusable Authorization header variants before adding the cached credential. Required placeholders still fail before cache access.

Fixes #505.

Thanks @koinzhang.

Validation: the contributor regression tests reproduced 15 failure(s) against current-main source. The integrated candidate passes pnpm check and pnpm test on AWS Crabbox with Node 24 and Bun 1.4.4. Independent Codex review through P2 is clean. Cross-platform exact-head CI is required before merge.

Built-CLI HTTP proof with an isolated vault and synthetic credentials: main lists successfully without the static header but exits 1/status auth with the empty header; this candidate exits 0/status ok in both cases. No live provider, user cache or business tool is used.

Diff: 292 lines (+286 / -6) across 3 files Reviewer: steipete Review duration: 862m
All Vouch review confidence checks passed
Residual risk 0.23 = Change Risk (0.63) × (1 − Review Confidence (0.64)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.63 · 292 lines diff across 3 files
0.63
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.60 · 4 substantive comment(s)
0.60
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
63%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.340
Sensitive Paths sensitive_paths
0.063
Real PR Conversation Timeline
5 items
clawsweeper[bot] clawsweeper[bot] commented on Nov 13, 2026 14:51 UTC
Bot

<!-- clawsweeper-pr-ack:opened item=506 -->
🦞👀
ClawSweeper picked this up.

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

<!-- clawsweeper-review-progress:start -->

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.
<!-- clawsweeper-review-progress:end -->

chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Nov 13, 2026 14:51 UTC
Bot

<!-- codex-pull-request-review-summary -->
<!-- codex-review-state:v1 {"code_review":{"commit_sha":"12e52d60bcb03978a0ff4c850271caedb92ef577","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} -->

<details>
<summary><strong>Codex Review Summary</strong>: ✅ Completed</summary>

This comment shows the latest Codex review activity on this pull request.

| Review | Status | Commit | Review trigger |
| --- | --- | --- | --- |
| 📝 Code Review | ✅ Completed <relative-time datetime="2026-11-14T05:04:05.439673Z">2026-11-14T05:04:05.439673Z</relative-time> | 12e52d6 | New commits |

<details> <summary>ℹ️ About Codex in GitHub</summary>
<br/>

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review

  • Mark a draft as ready

  • Comment "@codex review" or "@codex security review".
  • Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

    </details>

    </details>

    clawsweeper[bot] clawsweeper[bot] commented on Nov 13, 2026 15:05 UTC
    Bot

    Codex review: needs real behavior proof before merge.

    What this changes

    Use cached OAuth credentials when resolved static Authorization headers contain no credential, while preserving usable static authentication.

    Example: Run mcporter list example with Authorization: Bearer ${EXAMPLE_TOKEN:-}, EXAMPLE_TOKEN unset, and a valid cached OAuth token.

  • Before: The empty Bearer header bypasses the cache and listing returns 401.

  • After: The cached token replaces the empty header so authenticated listing can succeed.
  • Review scores

    | Measure | Result | What it means |
    |---|---|---|
    | Overall readiness | 🧂 unranked krab (1/6) | The focused patch appears correct on inspection, but mocked validation does not satisfy the required real-behavior proof gate. |
    | Proof confidence | 🧂 unranked krab (1/6) | Real behavior proof is necessary before merge. See [Before merge](#before-merge). |
    | Patch quality | 🐚 platinum hermit (4/6) | No actionable review findings were identified. |

    Product

    Kind: Bug fix · Worth it: Yes · Fix scope: Complete
    User problem: Non-interactive listing reports authentication required despite a valid cached OAuth token when an optional static token resolves empty.
    Reason: This restores authenticated MCP discovery within the repository's compatibility goal while retaining usable static credentials.

    Merge readiness

    ⛔ Blocked before merge - 1 item remains

    Keep open: this PR addresses a confirmed current-main credential-selection bug, and source review found no introduced correctness or security defect.

    Priority: P2
    Reviewed head: 087853cc387512789b31cf333304db67e76ea43d

    Before merge

  • Add real behavior proof - Cached-auth selection is exercised through createClientContext with mocked token lookup and Client.connect; the body and discussion provide no shipped CLI execution against a real credential cache showing successful listing after this fix, including fresh and upgraded state; the contributor should attach terminal output, logs, or a recording and redact IPs, API keys, phone numbers, and non-public endpoints. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Findings

    None.

    Tests

  • Missing end-to-end proof: Supply redacted CLI output or a terminal recording showing authenticated listing with an empty resolved Authorization and a real cache, including fresh setup and upgrade from 0.17.0 with existing settings and credentials retained.
  • <details>
    <summary><strong>Agent review details</strong></summary>

    How this fits together

    CLI listing enters the shared runtime, which selects credentials from configured headers and the OAuth cache before constructing HTTP or SSE transports.

    flowchart TD
      A[CLI list] --> B[Shared runtime]
      B --> C[Resolve configured headers]
      C --> D[Select static or cached credential]
      E[OAuth cache] --> D
      D --> F[HTTP or SSE transport]
      F --> G[MCP tool list]
    

    Technical review

    Best possible solution:

    Keep credential selection in cached-auth, using the existing header resolver and preserving valid static credentials and required-placeholder errors.

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

    Current-main source establishes the cache bypass for the reported empty-fallback header, supported by the linked report's 0.17.0 failure and workaround; no target code or tests were run during this review.

    Is this the best way to solve the issue?

    The repair addresses the credential-selection cause in the shared owner and reuses transport header semantics without adding configuration, dependencies, or a competing auth path.

    AGENTS.md: found and applied where relevant.

    Codex review notes: model internal, reasoning medium; reviewed against 21624e8cc823.

    Provenance checked

  • Static credential precedence and cached-token selection changes intended behavior with a stated reason (7f1e9a8ce0b941c8506a7a10bdb78a45cb2ac9d5: Refreshable-bearer support preserved explicitly configured HTTP Authorization; earlier cached-auth work enabled non-interactive listing.)

  • Runtime helper ownership keeps the original intent (https://github.com/openclaw/mcporter/pull/249: The merged refactor extracted cached-auth and HTTP transport internals without changing public behavior.)

  • Active OAuth Authorization handling keeps the original intent (https://github.com/openclaw/mcporter/pull/123: Prevent imported static Authorization headers from overriding dynamically obtained OAuth tokens.)

  • Vault refusal handling keeps the original intent (90bb83f934cb68f5faf463461388135a20597293: Expose vault policy failures rather than swallowing them and starting an unusable interactive flow.)
  • Testing

    Proof path: unit tests only.

    Security

    None.

    Evidence

    What I checked:

  • Current-main bug: The default branch remains at the pinned base; cached-auth returns on Authorization key presence before consulting the cache or resolving header placeholders. (src/runtime/cached-auth.ts:27, 21624e8cc823)

  • Affected shipped caller: CLI listing explicitly enables cached auth while disabling interactive authorization. (src/cli/list-command.ts:414, 21624e8cc823)

  • Verified introduced repair: The patch uses the transport's existing header resolver and environment semantics, preserves usable static credentials, and removes unusable Authorization case variants before injecting the cached token. (src/runtime/cached-auth.ts:29, 087853cc3875)

  • Reported release and workaround: https://github.com/openclaw/mcporter/issues/505 reports the failure on Homebrew 0.17.0 on macOS arm64 and successful listing after removing the empty Authorization header with the same cache.

  • Feature history: The refreshable-bearer commit added the key-only early return in runtime/transport.ts; the later modularization carried it into cached-auth.ts. Earlier cached-auth behavior used the name applyCachedOAuthHeaderIfAvailable. (src/runtime/transport.ts, 7f1e9a8ce0b9)

  • Validation boundary: The full PR body reports focused tests, check, and test passing, but expressly excludes a live OAuth server or user credential cache; added tests mock cache reads and Client.connect and inspect transport request options. (tests/runtime-transport.test.ts:1046, 087853cc3875)
  • Preflight source

    Source unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified.

    Review metrics

    | Metric | Value | Why it matters |
    |---|---|---|
    | Patch scope | Production +38/-6; tests +246/-0; changelog +2/-0 | The production change stays within cached-auth; transport-level tests cover credential values, casing, environment resolution, and preserved authentication paths. |

    Root-cause cluster

    Relationship: fixed_by_candidate
    Canonical: https://github.com/openclaw/mcporter/issues/505
    Summary: This PR directly repairs the empty-credential cache bypass documented in the linked issue; searches found no merged replacement owning this exact repair.

    Members:

  • canonical: https://github.com/openclaw/mcporter/issues/505 - The report supplies the affected configuration, release, failure, workaround, and matching source path.
  • Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

    Labels

    Label changes:

  • add P2: A specific HTTP configuration prevents authenticated tool discovery despite an available cached token, with a documented configuration workaround.

  • add rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.

  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.
  • Label justifications:

  • P2: A specific HTTP configuration prevents authenticated tool discovery despite an available cached token, with a documented configuration workaround.

  • rating: 🧂 unranked krab: Overall readiness is 🧂 unranked krab; proof is 🧂 unranked krab and patch quality is 🐚 platinum hermit.

  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.
  • Rating scale

    6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

    Workflow

    ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

    </details>

    _Reviewed November 13, 2026, 10:04 AM ET / 15:04 UTC._

    <!-- clawsweeper-verdict:needs-human item=506 sha=087853cc387512789b31cf333304db67e76ea43d confidence=high updated_at=2026-11-13T15:02:35Z reviewed_at=2026-11-13T15:04:36.754Z lease_owner=github-run-43448408342-1 lease_comment_id=6856758042 source_revision=de191ca3d75c07a2ad883fad5013fd3f83f8341afb9e0e06f3786678678a19e5 hold=proof findings=0 -->
    <!-- clawsweeper-review-state:blocked item=506 sha=087853cc387512789b31cf333304db67e76ea43d v=1 -->

    <!-- clawsweeper-review-version item=506 reviewed_at=2026-11-13T15:04:36.754Z sha=087853cc387512789b31cf333304db67e76ea43d source_revision=de191ca3d75c07a2ad883fad5013fd3f83f8341afb9e0e06f3786678678a19e5 lease_owner=github-run-43448408342-1 lease_comment_id=6856758042 v=1 -->

    <!-- clawsweeper-review item=506 -->

    koinzhang koinzhang commented on Nov 13, 2026 16:50 UTC
    Author

    Verified the packaged CLI locally on macOS against a real OAuth-protected HTTP MCP server, using an existing, unexpired OAuth cache. No mocked token reader or connection was used.

    Built commit 087853cc387512789b31cf333304db67e76ea43d and installed its npm package into an isolated prefix without replacing the global installation. The patched package still reports version 0.17.0, so the commit identifies the tested build.

    The configured Authorization header uses Bearer ${TOKEN:-} (variable name anonymized), with the variable unset. Both versions used the same existing configuration and credential cache. Tested list <server> --json --no-oauth --timeout 30000 --exit-code (server name redacted).

  • Released 0.17.0: HTTP 401, exit code 1, no tools listed.

  • Patched build: status ok, exit code 0, 4 tools listed.
  • The credential file checksum was unchanged before and after testing. No interactive OAuth login or business tool invocation occurred.

    This verifies switching from the released CLI to the patched package while retaining configuration and credentials. A fresh installation followed by a new OAuth login has not been tested. This was not an in-place Homebrew upgrade.

    Internal endpoints, service/tool names, local paths, credentials, and raw logs are intentionally omitted.

    Reviewers
    Assignees
    koinzhang koinzhang
    Labels
    risk: low confidence: 63.8% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 63.1% (MEDIUM) · Higher = larger blast radius
    63.1%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 63.8% · Lower = rushed or shallow review
    63.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.8% · Safe to merge
    22.8%