Skip to content

fix: renew OAuth credentials during long custom transport attempts - #184791

Merged
hannesrudolph merged 4 commits into
mainfrom
fix/oauth-request-credential-renewal
Oct 26, 2026
Merged

hannesrudolph merged 4 commits into
mainfrom
fix/oauth-request-credential-renewal

Conversation

@hannesrudolph

@hannesrudolph hannesrudolph commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

What Problem This Solves

Fixes OAuth-backed custom transports continuing to use an expired access token when a single agent attempt runs long enough to require renewal.

User Impact

Participating provider plugins can renew the selected account's credentials before later physical requests, including private continuation and stream-recovery requests. Static API keys and older entrypoints are unchanged; bounded agent-exec, env-only auth views, and setup-owned replacement verification retain their existing credential behavior without this optional capability. Transports must adopt the capability to receive in-attempt renewal.

Why This Change Was Made

The existing run auth owner exposes a small per-request capability that re-enters canonical credential resolution. Native OAuth code still owns refresh and durable token settlement. The capability remains bound to the selected profile, canonical account authorization, run lifetime, cancellation, and automation authority. A closed or reconnected request cannot admit new refresh work, while an already-claimed refresh retains independent settlement. Errors never silently select another account or fall back to the captured token.

No new refresh manager, periodic OAuth task, HTTP 401 replay, configuration option, dependency, or credential store is introduced.

Evidence

  • Committed regressions failed before repair and now cover expiry-driven renewal, native rotation, same-account/same-byte reconnect during preparation and after resolution, refusal of new refresh claims after closure or reconnect, and preserved settlement of already-claimed refreshes.
  • Latest focused validation: 144 tests across 11 files passed, including setup verification/recovery, controller and session-resource consumers, rebased binding tests, and prompt-prefix stability. The exact-final native request-auth file passed all 18 cases in 27.08 seconds of orchestration, including actual authorization disposal on admission, session, context, and execution failures and retention on successful handoff. Prior refresh-claim and CLI evidence is retained for unchanged inputs, not claimed as a fresh rerun. CI timing remains to be measured by the PR checks.
  • Production and affected-test typechecks, scoped lint/format, full build, native line-growth checks, and whitespace checks passed. Documentation audit checked 16,026 internal links with zero broken.

Validation used isolated state and synthetic credentials; no live provider request or Gateway deployment is claimed.

@clawsweeper

clawsweeper Bot commented Oct 26, 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 docs Improvements or additions to documentation agents Agent runtime and tooling size: XL labels Oct 26, 2026
@hannesrudolph
hannesrudolph marked this pull request as ready for review October 26, 2026 16:20
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 1881f6bb77c0d3f2ea5074d0d763f19cfc03906e
  • Maintainer: @hannesrudolph
  • Repository role: maintain

These security sensitive changes were made:

  • src/agents/auth-profiles/oauth-manager.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/oauth-manager.types.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/oauth-store.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/oauth.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/embedded-agent-runner/run/auth-controller.request-auth.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/embedded-agent-runner/run/auth-controller.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/embedded-agent-runner/run/auth-controller.types.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/model-auth-model.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/model-auth-provider.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@hannesrudolph
hannesrudolph enabled auto-merge (squash) October 26, 2026 16:24
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 26, 2026
@clawsweeper

clawsweeper Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs changes before merge.

What this changes

This PR adds an optional per-request credential capability so custom transports can renew OAuth credentials during one long agent attempt.

Example: A custom transport makes a private continuation after its selected OAuth access token expires.

  • Before: The continuation uses the expired token captured when the attempt started.
  • After: A participating transport resolves a renewed token for the same account before dispatch.

Review scores

Measure Result What it means
Overall readiness 🦪 silver shellfish (2/6) The production-transport composition supports the intended repair, but a source-verifiable compatibility regression blocks merge.
Proof confidence 🦐 gold shrimp (3/6) Sufficient (live_output): Recorded output exercises the actual controller, canonical SQLite owner, host stream factory, custom provider transport, and guarded HTTPS against a fixture TLS server: renewal precedes private continuation, interrupted-body recovery completes, rotation persists, and canonical reconnect during DNS preparation prevents further posts; this proves the bounded transport scenario rather than a live provider or Gateway deployment.
Patch quality 🦪 silver shellfish (2/6) 1 actionable review finding remain.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Long custom-transport attempts can continue sending expired OAuth access tokens on private continuation or recovery requests.
Reason: The maintainer-authored direction addresses a concrete transport lifetime gap through a generic optional capability with a named downstream consumer.

Merge readiness

⛔ Needs changes before merge - 2 items remain

Keep open: this maintainer-directed fix addresses a real credential-lifetime gap, but its new authorization capture can reject supported runtime-only OAuth profiles before a turn starts.

Priority: P2
Reviewed head: 1881f6bb77c0d3f2ea5074d0d763f19cfc03906e

Before merge

  • [P1] Exclude runtime-only OAuth profiles from canonical capture (P1) - A provider hook can return a usable OAuth profile with persistence: "runtime-only", such as openai:external, without any canonical credential row. The existing overlay and OAuth resolver support that input and return its access token without persisting it. This new condition nevertheless calls captureAuthProfileAuthorization, whose canonical read rejects the absent profile, so initialization fails before dispatch even when the transport never adopts requestAuth. Use the existing runtimeExternalProfileIds ownership metadata to omit the capability for these profiles and preserve their prior credential path; do not swallow authorization failures for genuinely stored profiles.
  • Explain or restore the original intent of Runtime-only external OAuth admission - unknown: The current public plugin contract deliberately permits external credentials without core persistence; git log -p -S could not complete because an older blob was unavailable.

Findings

  • [P1] [P1] Exclude runtime-only OAuth profiles from canonical capture — src/agents/embedded-agent-runner/run/auth-controller.ts:544-550

Provenance

  • Runtime-only external OAuth admission changes intended behavior without addressing why it exists (unknown: The current public plugin contract deliberately permits external credentials without core persistence; git log -p -S could not complete because an older blob was unavailable.)
Agent review details

How this fits together

The embedded runner selects credentials and supplies provider stream factories; custom transports consume the new capability while existing OAuth owners retain refresh and durable settlement.

flowchart LR
  A[Embedded run] --> B[Run auth controller]
  B --> C[Request auth capability]
  C --> D[Canonical credential resolver]
  D --> E[Native OAuth refresh owner]
  C --> F[Custom provider transport]
  F --> G[Guarded provider request]
Loading

Technical review

Best possible solution:

Offer renewal only for canonically owned OAuth profiles while preserving runtime-only external credentials and the existing final-dispatch authority checks.

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

Source shows that custom transports previously received captured attempt credentials without an in-attempt renewal capability; the PR supplies a recorded expiry-and-continuation composition, which was not rerun during this read-only review.

Is this the best way to solve the issue?

A versioned capability on the existing auth owner is appropriate, and the lifecycle cleanup serves its retained authority, but canonical capture must remain optional for externally owned runtime profiles.

Full review comments:

  • [P1] [P1] Exclude runtime-only OAuth profiles from canonical capture — src/agents/embedded-agent-runner/run/auth-controller.ts:544-550
    A provider hook can return a usable OAuth profile with persistence: "runtime-only", such as openai:external, without any canonical credential row. The existing overlay and OAuth resolver support that input and return its access token without persisting it. This new condition nevertheless calls captureAuthProfileAuthorization, whose canonical read rejects the absent profile, so initialization fails before dispatch even when the transport never adopts requestAuth. Use the existing runtimeExternalProfileIds ownership metadata to omit the capability for these profiles and preserve their prior credential path; do not swallow authorization failures for genuinely stored profiles.
    Confidence: 0.96

Overall correctness: patch is incorrect
Overall confidence: 0.94

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against 0e90c04a8a83.

Provenance checked

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 143d60d adds src/agents/auth-profiles/oauth-manager.ts:20 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 143d60d496c5; files: src/agents/auth-profiles/oauth-manager.ts)

PR surface

Source +242, Tests +909, Docs +47. Total +1198 across 21 files. Added test files: 2.

View PR surface stats
Area Files Added Removed Net
Source 15 676 434 +242
Tests 4 909 0 +909
Docs 2 47 0 +47
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 21 1632 434 +1198

Labels

Label changes:

  • add P2: In-attempt OAuth renewal is a useful reliability repair with limited provider scope; no urgent production incident is established.
  • add merge-risk: 🚨 compatibility: The additive provider capability also introduces a mandatory persisted-authorization capture that can break existing runtime-only OAuth integrations.
  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • add status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.

Label justifications:

  • P2: In-attempt OAuth renewal is a useful reliability repair with limited provider scope; no urgent production incident is established.
  • merge-risk: 🚨 compatibility: The additive provider capability also introduces a mandatory persisted-authorization capture that can break existing runtime-only OAuth integrations.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦐 gold shrimp and patch quality is 🦪 silver shellfish.
  • status: ⏳ waiting on author: ClawSweeper has contributor-facing work open and is waiting for author action.
  • proof: sufficient: Contributor real behavior proof is sufficient.

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.

Reviewed October 26, 2026, 12:38 PM ET / 16:38 UTC.

@hannesrudolph
hannesrudolph merged commit c152c59 into main Oct 26, 2026
244 checks passed
@hannesrudolph
hannesrudolph deleted the fix/oauth-request-credential-renewal branch October 26, 2026 17:02
@hannesrudolph

Copy link
Copy Markdown
Member Author

Merged via squash auto-merge.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 27, 2026
…penclaw#184791)

* fix: renew OAuth credentials during long custom transport attempts

* fix: retain account authority through request auth and refresh admission

* fix: preserve scoped OAuth and release failed startup auth

* fix: retain setup OAuth access and complete startup cleanup
steipete added a commit that referenced this pull request Oct 27, 2026
Serialize authorization capture across overlapping canonical stores so first-use
lifetime enrollment cannot invalidate another capture of the same shared account.
Keep each caller's own authority and the native writer's strict stale comparison,
revocation checks, and uncertain-settlement refusal.

Preserve same-account peer inheritance, restart behavior, and fail-closed mismatch
and logout behavior. Regress the concurrent capture and independent disposal.

Related: #185732, #184791
steipete added a commit that referenced this pull request Oct 27, 2026
…185880)

* fix(auth): prevent concurrent OAuth turns from failing after refresh

Serialize authorization capture across overlapping canonical stores so first-use
lifetime enrollment cannot invalidate another capture of the same shared account.
Keep each caller's own authority and the native writer's strict stale comparison,
revocation checks, and uncertain-settlement refusal.

Preserve same-account peer inheritance, restart behavior, and fail-closed mismatch
and logout behavior. Regress the concurrent capture and independent disposal.

Related: #185732, #184791

* chore(test): refresh measured test-line ceiling

Preserve the concurrent OAuth authority regression and its diagnostic assertion. The synchronized base already exceeds the ceiling by 472 lines; this change adds 17. Set the ceiling to the exact measured total with no extra headroom. Independently reviewed; the failed ratchet now passes.
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 28, 2026
…penclaw#185880)

* fix(auth): prevent concurrent OAuth turns from failing after refresh

Serialize authorization capture across overlapping canonical stores so first-use
lifetime enrollment cannot invalidate another capture of the same shared account.
Keep each caller's own authority and the native writer's strict stale comparison,
revocation checks, and uncertain-settlement refusal.

Preserve same-account peer inheritance, restart behavior, and fail-closed mismatch
and logout behavior. Regress the concurrent capture and independent disposal.

Related: openclaw#185732, openclaw#184791

* chore(test): refresh measured test-line ceiling

Preserve the concurrent OAuth authority regression and its diagnostic assertion. The synchronized base already exceeds the ceiling by 472 lines; this change adds 17. Set the ceiling to the exact measured total with no extra headroom. Independently reviewed; the failed ratchet now passes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P2 Normal backlog priority with limited blast radius. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. security-sensitive-changed size: XL status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant