Skip to content

fix(auth): clean OAuth contention diagnostics - #101573

Merged
steipete merged 3 commits into
mainfrom
codex/replay-83383-oauth-contention
Jul 7, 2026
Merged

steipete merged 3 commits into
mainfrom
codex/replay-83383-oauth-contention

Conversation

@steipete

@steipete steipete commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

What Problem This Solves

OAuth refresh lock contention currently crosses two error-wrapping layers. The manager flattens the nested file-lock cause into its message, then the profile resolver surfaces the manager error itself and adds another OAuth token refresh failed prefix. Operators can therefore see a duplicated failure prefix plus an internal local lock path and file lock timeout detail.

This is a focused, current-main replay of #83383. The original branch is conflicting and cannot be updated by maintainers.

Why This Change Was Made

  • Keep the canonical contention message as the user-facing manager cause without flattening its nested file-lock cause.
  • Retain code: "refresh_contention" and lockPath on the structured manager error for programmatic handling.
  • Route contention through the same sanitized cause path as other refresh failures in the profile resolver, avoiding the second prefix.
  • Preserve the current OAuthRefreshFailureError provider, profile, and reason classification added after the original PR was written.
  • Add the regression to the existing OpenAI refresh-fallback integration suite rather than carrying over the stale branch's broad test-harness rewrites.

Contributor credit is preserved in the commit and changelog. The production diff is net-negative in lines.

User Impact

When another OpenClaw process already holds an OpenAI OAuth refresh lock, the operator now sees one actionable refresh_contention failure. Local lock paths and the underlying file-lock timeout stay out of the user-facing message, while structured contention metadata remains available to code.

No config, storage, provider-routing, credential, or authorization behavior changes.

Evidence

  • Blacksmith Testbox tbx_01kwy25q40ew4jxxbb54v1kmm0: pnpm test src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts src/agents/auth-profiles/oauth-manager.test.ts src/agents/auth-profiles/oauth-lock-timeout-classification.test.ts — 3 files / 47 tests passed on the final formatted diff.
  • Same Testbox: pnpm check:changed — core, coreTests, and docs lanes passed, including production/test typechecks, lint with 0 warnings/errors, policy guards, and cycle checks.
  • Same Testbox: scoped pnpm format:check passed for all four changed files.
  • Fresh .agents/skills/autoreview/scripts/autoreview --mode local: clean, no accepted/actionable findings; overall correctness 0.91.
  • git diff --check passed.
  • Resolver-level regression proves one outer refresh prefix, one contention message, no lock path or file-lock text, preserved provider/profile classification, and preserved structured contention code/path.

Source-blind live CLI proof was not claimed: the public auth CLI has no disposable command that creates an expired OAuth profile and holds its canonical refresh lock, and using a real provider credential is unnecessary for this deterministic diagnostic path.

Related

@steipete
steipete requested a review from a team as a code owner July 7, 2026 10:43
@openclaw-barnacle openclaw-barnacle Bot added agents Agent runtime and tooling size: S maintainer Maintainer-authored PR labels Jul 7, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 975b50a6f4

ℹ️ About Codex in GitHub

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread CHANGELOG.md

### Fixes

- **OAuth refresh contention diagnostics:** keep local lock paths out of user-facing refresh failures and avoid duplicate failure prefixes while preserving structured provider and profile classification. (#83383) Thanks @vincentkoc.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Remove the normal-fix changelog entry

The root AGENTS.md says CHANGELOG.md is release-only and should not be edited for normal PRs or direct main fixes; release-note context belongs in the PR body, squash message, or direct commit text. Since this auth diagnostic fix is not a release-generation change, adding an Unreleased entry here creates maintainer-owned release-note drift/duplicate generation work, so please drop this line and keep the credit/context in the commit/PR metadata instead.

Useful? React with 👍 / 👎.

@clawsweeper

clawsweeper Bot commented Jul 7, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 7, 2026, 7:03 AM ET / 11:03 UTC.

Summary
This PR updates OAuth refresh contention error formatting in the manager/resolver, adds an OpenAI refresh-fallback regression test, and adds a root changelog entry.

PR surface: Source -1, Tests +38, Docs +1. Total +38 across 4 files.

Reproducibility: yes. Source inspection of current main shows refresh_contention can be formatted through the manager cause chain and then rewrapped by the resolver; the added regression models that deterministic path without live OAuth credentials.

Review metrics: 1 noteworthy metric.

  • Release-owned notes: 1 changelog entry added. Root CHANGELOG.md is release-owned, so this normal fix should carry release context outside the changelog until release generation runs.

Root-cause cluster
Relationship: canonical
Canonical: #101573
Summary: This PR is the current focused replacement for the older OAuth contention diagnostics draft; earlier auth redaction and refresh-lock work are related context rather than the canonical remaining work.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🐚 platinum hermit
Proof: 🌊 off-meta tidepool
Patch quality: 🐚 platinum hermit
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • Remove the root CHANGELOG.md entry and keep release-note context in the PR body or commit metadata.

Risk before merge

  • [P1] OAuth refresh error wrapping is an auth-provider diagnostic surface; final head should preserve structured refresh_contention code/lockPath and OAuthRefreshFailureError provider/profile classification.
  • [P1] The added root CHANGELOG.md line should be removed before merge so release generation remains the single changelog owner.

Maintainer options:

  1. Drop release note, keep auth proof (recommended)
    Remove only the added root changelog entry, keep the manager/resolver diagnostic cleanup and regression assertions, then rely on exact-head validation before merge.
  2. Pause for auth contract review
    If maintainers want different structured cause semantics for refresh_contention, pause this PR and decide that auth diagnostic contract before merging.
Copy recommended automerge instruction
@clawsweeper automerge

Special instructions:
Remove the new CHANGELOG.md entry for the OAuth refresh contention diagnostic fix; leave the release-note context in the PR body or commit metadata, and do not change the auth runtime or test behavior.

Next step before merge

  • [P1] A narrow automated repair can remove the release-owned changelog line without touching the auth runtime or regression test.

Security
Cleared: No supply-chain or security-boundary expansion was found; the runtime change reduces local path exposure and does not modify secret storage, dependencies, workflows, or permissions.

Review findings

  • [P3] Remove the release-owned changelog entry — CHANGELOG.md:26
Review details

Best possible solution:

Land the focused auth diagnostic cleanup after dropping the changelog line and preserving the final-head regression for one prefix, no lock path, and structured contention metadata.

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

Yes. Source inspection of current main shows refresh_contention can be formatted through the manager cause chain and then rewrapped by the resolver; the added regression models that deterministic path without live OAuth credentials.

Is this the best way to solve the issue?

Mostly yes. The manager/resolver diagnostic layer is the narrow maintainable fix and this branch is smaller than the older draft, but the changelog edit is not part of the best merge shape.

Full review comments:

  • [P3] Remove the release-owned changelog entry — CHANGELOG.md:26
    Root AGENTS.md makes CHANGELOG.md release-owned for normal fixes. This PR already carries release-note context in the body and commit metadata, so adding an Unreleased line would create duplicate release-generation work; drop this line before merge.
    Confidence: 0.95

Overall correctness: patch is correct
Overall confidence: 0.88

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 16348ddec3ad.

Label changes

Label changes:

  • add P2: This is a normal-priority OAuth diagnostic/redaction bug fix with limited blast radius but real operator-facing auth impact.
  • add merge-risk: 🚨 auth-provider: The PR changes OAuth refresh error wrapping and must preserve structured contention metadata plus provider/profile classification.
  • 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 proof gate is not applied to this in-repo maintainer-labeled PR; the body provides deterministic Testbox and regression-test output, but no live OAuth credential run was claimed.

Label justifications:

  • P2: This is a normal-priority OAuth diagnostic/redaction bug fix with limited blast radius but real operator-facing auth impact.
  • merge-risk: 🚨 auth-provider: The PR changes OAuth refresh error wrapping and must preserve structured contention metadata plus provider/profile classification.
  • 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 proof gate is not applied to this in-repo maintainer-labeled PR; the body provides deterministic Testbox and regression-test output, but no live OAuth credential run was claimed.
Evidence reviewed

PR surface:

Source -1, Tests +38, Docs +1. Total +38 across 4 files.

View PR surface stats
Area Files Added Removed Net
Source 2 9 10 -1
Tests 1 39 1 +38
Docs 1 1 0 +1
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 49 11 +38

Acceptance criteria:

  • [P1] git diff --check origin/main...HEAD.
  • [P1] git diff --name-only origin/main...HEAD.

What I checked:

  • Repository policy applied: Root AGENTS.md was read fully; it says root CHANGELOG.md is release-only for normal PRs, and release-note context belongs in PR body, squash message, or direct commit text. (AGENTS.md:238, 16348ddec3ad)
  • Actionable PR defect: The PR head adds one normal-fix Unreleased changelog entry for the OAuth contention diagnostic change. (CHANGELOG.md:26, 5991c572d390)
  • Current-main behavior: Current main formats the refresh_contention error from the full params.cause and stores a redacted delegated cause, which is the manager-side diagnostic path this PR narrows. (src/agents/auth-profiles/oauth-manager.ts:80, 16348ddec3ad)
  • Current-main cause flattening: Current main's raw error formatter walks Error.cause chains into surfaced text, so nested file-lock timeout details can be included in manager messages. (src/agents/auth-profiles/oauth-manager.ts:188, 16348ddec3ad)
  • Current-main resolver wrapping: Current main special-cases refresh_contention by extracting the manager error message and wrapping it in another OAuthRefreshFailureError prefix. (src/agents/auth-profiles/oauth.ts:452, 16348ddec3ad)
  • PR source fix: The PR keeps the file-lock cause off the surfaced user-facing cause for refresh_contention while preserving structured fields on OAuthManagerRefreshError. (src/agents/auth-profiles/oauth-manager.ts:80, 5991c572d390)

Likely related people:

  • vincentkoc: Auth refresh redaction in merged PR 82670 touched OAuthManagerRefreshError, and open PR 83383 is the earlier draft for this same contention diagnostic cleanup. (role: recent area contributor and original diagnostic author; confidence: high; commits: 05123db93cf7, d754e783bc69; files: src/agents/auth-profiles/oauth-manager.ts, src/agents/auth-profiles/oauth-manager.test.ts, src/agents/auth-profiles/oauth.ts)
  • visionik: Merged PR 67876 introduced the cross-agent OAuth refresh serialization and refresh-lock surface that produces refresh_contention diagnostics. (role: introduced related behavior; confidence: medium; commits: 8e79080bef7d; files: src/agents/auth-profiles/oauth.ts, src/agents/auth-profiles/paths.ts)
  • Dallin Romney: PR 89181 added the current OAuthRefreshFailureError provider/reason classification path that this diagnostic cleanup must preserve. (role: recent adjacent owner; confidence: medium; commits: 50b69e16dc0d; files: src/agents/auth-profiles/oauth-refresh-failure.ts, src/agents/auth-profiles/oauth.ts, src/agents/auth-profiles/oauth-manager.ts)
  • steipete: Current-main blame and merged PR 82117 show recent work on the OpenAI/Codex OAuth refresh fallback and the same auth-profile files, beyond authoring this PR. (role: recent area contributor; confidence: high; commits: b3d9bef38d5d, c9c4226a23a3; files: src/agents/auth-profiles/oauth-manager.ts, src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts, src/agents/auth-profiles/oauth.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@clawsweeper clawsweeper Bot added 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. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 7, 2026
@steipete

steipete commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Land-ready on exact head 5991c572d390da4c4301cafd7ee5343666faff53.

Verification:

  • Blacksmith Testbox tbx_01kwy25q40ew4jxxbb54v1kmm0: pnpm test src/agents/auth-profiles/oauth.openai-codex-refresh-fallback.test.ts src/agents/auth-profiles/oauth-manager.test.ts src/agents/auth-profiles/oauth-lock-timeout-classification.test.ts — 3 files / 47 tests passed.
  • Blacksmith Testbox: pnpm check:changed passed the selected core, core-tests, and docs lanes, including production/test typechecks, lint, policy guards, and cycle checks.
  • Scoped pnpm format:check and git diff --check passed.
  • Fresh autoreview: no accepted/actionable findings.
  • Hosted exact-head CI passed: CI 28860968886, security 28860968883, and the infrastructure-retried OpenGrep scan 28860968888.
  • Native maintainer gate passed: OPENCLAW_ALLOW_ROOT_CHANGELOG_PR=1 OPENCLAW_TESTBOX=1 scripts/pr prepare-run 101573.

The replay preserves structured refresh_contention classification while keeping the nested file-lock path out of the public diagnostic and avoiding duplicate OAuth failure prefixes. No source-blind live CLI claim is made: the public CLI has no disposable expired-OAuth plus held-lock fixture, so the deterministic manager/resolver integration test is the behavioral proof for this diagnostic-only path.

@steipete
steipete merged commit 4627631 into main Jul 7, 2026
131 of 136 checks passed
@steipete
steipete deleted the codex/replay-83383-oauth-contention branch July 7, 2026 11:08
@steipete

steipete commented Jul 7, 2026

Copy link
Copy Markdown
Contributor Author

Merged via squash.

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 merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. P2 Normal backlog priority with limited blast radius. 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