fix(runtime): use cached OAuth when static Authorization resolves empty #506
<!-- 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 -->
<!-- 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
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>
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.
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
@clawsweeper re-review. The PR author or someone with repository write access can request it.Findings
None.
Tests
<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:
src/runtime/cached-auth.ts:27, 21624e8cc823)src/cli/list-command.ts:414, 21624e8cc823)src/runtime/cached-auth.ts:29, 087853cc3875)src/runtime/transport.ts, 7f1e9a8ce0b9)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:
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.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 -->
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).
0.17.0: HTTP 401, exit code 1, no tools listed.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.
steipete
koinzhang
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.