Skip to content

fix(auth): refresh shared OAuth past empty deleted peers - #179205

Merged
steipete merged 5 commits into
mainfrom
fix/oauth-fence-skips-unrelated-deleted-peer
Oct 21, 2026
Merged

steipete merged 5 commits into
mainfrom
fix/oauth-fence-skips-unrelated-deleted-peer

Conversation

@steipete

@steipete steipete commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #178908

What Problem This Solves

Fixes shared OAuth refresh failing before provider I/O when a deleted agent's retained auth store is empty.

User Impact

Surviving agents can refresh shared OAuth credentials without reopening irrelevant historical stores for writes. Matching generations remain blocked by completed deletion; unreadable stores and changed captured identities still fail closed. No configuration or migration is required.

Why This Change Was Made

The peer writer checked the refresh generation after requesting write admission, so the deletion journal rejected even an empty store. Read through the existing asynchronous auth reader first and skip definitely unrelated generations. Pin candidate reads to discovery's physical identity so rediscovery can read a replacement while stale captures remain rejected. Possible matches retain the unchanged writer transaction and its generation, identity, deletion, and live-authority checks.

Thanks to @WG-Mojo for narrowing the report to an empty retained store and documenting the admission-order defect.

Evidence

  • Confirmed the defect through source and history on main snapshot c393a44166054c464ca220c7d03df19944f0745a. The pretransaction worker filter introduced in perf(auth-profiles): offload peer settlement and catalog reads #166183 still ran after write-execution capture.
  • On head f3f9b52cc80eeb6ab8b07d14aaa12565c4f1581a, the auth test job passed. Both preserves refresh safety with a retained completed-deletion store cases passed: empty in 1.13s and matching in 1.45s. The existing settles a replaced peer database discovered after provider refresh regression passed in 2.02s. These check provider invocation, surviving credential settlement, preserved historical auth/journal state, and replacement identity handling.
  • Changed-file oxlint and oxfmt passed. Fresh committed-branch Codex P2 autoreview is scoped-clean, with no actionable findings. The proposed write-admission recheck was assessed and resolved; the existing profile locks, generation guards, and settlement rescans remain intact.
  • Core CI completed with 38 passing jobs. check-test-types-core-2 and the aggregate gate remain red due to an inherited CI-planner type error: TS2345 at test/scripts/ci-changed-node-test-plan.test.ts:813,891, where CompactNodeTestShard lacks configs. The exact diagnostics also fail in scheduled main run 39563487228, job 119100317831.
  • Separate CodeQL, OpenGrep, and Critical Quality checks failed on GitHub installation API rate limits during reporting or setup. Scanner validation remains incomplete. Exact-head ClawSweeper re-review was requested; its status is tracked there.
  • PR CI is the test gate per maintainer policy. Local tests/typechecks and live proof were intentionally skipped.
  • Simplification kept the change within the existing candidate and reader owners. Exact diff: production +25/-4 (net +21), tests +63/-0, docs +5/-1. The production growth supplies the missing pre-admission read and captured-identity input while preserving writer revalidation.

Read historical auth candidates before write admission so empty retained stores cannot block shared OAuth refresh. Possible matches retain all transactional generation, identity, and deletion checks.

Add empty and matching completed-deletion manager regressions. Fixes #178908.
@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

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

ClawSweeper review in progress

ClawSweeper is reviewing this revision. This supersedes any previous blocked status.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 21, 2026 07:14
@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation agents Agent runtime and tooling size: S labels Oct 21, 2026
@github-actions

github-actions Bot commented Oct 21, 2026 •

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: 3da44cecc0c429c7e7ea4c92bf792ec2d806f575
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/agents/auth-profiles/candidate-stores.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/agents/auth-profiles/sqlite-read.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.

@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: 245964158a

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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-21T08:55:35.283487Z 3da44ce New commits
ℹ️ 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" 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.

@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 21, 2026
Honor the candidate identity in the existing asynchronous auth reader so rediscovered replacement databases do not reuse stale observed identities. Preserve direct identity checks and unchanged write authority.

Seed the retained matching-peer fixture before shared inheritance removes the local copy; assert its persisted contents before deletion.
@steipete

Copy link
Copy Markdown
Contributor Author

Updated head: f3f9b52cc80eeb6ab8b07d14aaa12565c4f1581a.

The first CI run exposed a matching-peer fixture that was being inherited rather than retained, plus a stale observed identity when rediscovering a replacement peer database. Both are repaired. Candidate reads now use discovery's captured identity; stale captures still fail closed and writer authority is unchanged. Changed-file lint/format and a fresh committed-branch P2 autoreview pass.

Exact-head CI is running the regression and sibling suites. PR CI is the test gate per explicit maintainer policy; local tests/typechecks and live proof are intentionally skipped. The PR body contains the current evidence and prior CI failures.

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 21, 2026
@clawsweeper

clawsweeper Bot commented Oct 21, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR skips unrelated historical OAuth generations before write admission and binds candidate reads to their discovered database identity.

Example: The surviving main agent refreshes openai:default while deleted-peer retains an empty auth store and completed deletion journal.

  • Before: Write admission rejects deleted-peer before checking its credentials, preventing the surviving agent's refresh.
  • After: The empty store is skipped; a retained matching generation still blocks refresh before provider I/O.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Focused, useful repair with no actionable findings; confidence rests on source review and production-owner harness coverage rather than shipped-entry evidence.
Proof confidence 🦐 gold shrimp (3/6) Ordinary shipped-entry proof is exempt for this maintainer-authored PR; the supplied manager/SQLite harness covers allowed refresh, completed-deletion refusal before the provider callback, and unchanged historical state, with existing replacement and stale-capture coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: An empty historical database belonging to a deleted agent prevents surviving agents from refreshing shared OAuth credentials.
Reason: The maintainer-authored direction restores documented empty-store behavior without weakening matching-generation deletion refusal.

Merge readiness

✅ Ready for maintainer review

Keep this maintainer-authored PR open: it addresses a source-confirmed OAuth refresh failure, and review found no introduced correctness or security defect.

Priority: P1
Reviewed head: 3da44cecc0c429c7e7ea4c92bf792ec2d806f575

Before merge

None.

Findings

None.

Tests

  • Missing end-to-end proof: No shipped Gateway expired-token rotation or current-main red run of these exact PR tests is supplied; available coverage exercises the real manager and SQLite boundary with injected provider I/O.
Agent review details

How this fits together

The auth-profile owner coordinates OAuth refresh across shared and historical agent databases, consuming persisted credentials and deletion authority and producing fenced peers, provider refresh requests, and settled credentials.

flowchart TD
  A[OAuth manager] --> B[Discover historical stores]
  B --> C[Identity-bound credential read]
  C --> D[Skip unrelated generation]
  C --> E[Matching generation writer admission]
  E --> F[Transactional fence and deletion checks]
  F --> G[Provider refresh and settlement]
Loading

Technical review

Best possible solution:

Keep the identity-bound pre-admission filter and unchanged transactional writer checks.

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

Current-main discovery, premature write admission, and completed-deletion refusal establish the empty-store failure path; this read-only review executed no reproduction.

Is this the best way to solve the issue?

This is the smallest complete repair using existing owners: read the captured candidate before admission, skip definite mismatches, and retain writer-side verification for possible matches.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • Historical-peer generation filtering keeps the original intent (2fe7995: Move peer operations to existing workers while retaining physical identity, generation comparisons, locks, and settlement custody.)
  • Prepared asynchronous auth reads keeps the original intent (1d4202d: Read persisted auth profiles outside the Gateway event loop while retaining source admission through cleanup.)
  • Retained filesystem identity and row caching changes intended behavior with a stated reason (3ccacf7: Retain process-owned filesystem and credential facts to avoid repeated hot-path work; this PR narrowly bypasses cached identity for discovered candidates to handle replacement rediscovery.)
  • Empty historical-store refresh contract keeps the original intent (43c68c3: Allow catalog refresh through its existing native writer while retaining historical-peer fencing and settlement.)

Testing

Proof path: in-process harness.

Security

None.

Evidence

What I checked:

  • Verified introduced change: The pinned introduced diff adds the pre-admission generation read, candidate identity input, two deletion-boundary regression cases, and corresponding documentation. (src/agents/auth-profiles/candidate-stores.ts:210, 3da44cecc0c4)
  • Current-main defect remains: Fetched main still delegates directly to the candidate writer before inspecting the generation; completed-deletion admission rejects the deleted identity even when its credential store is empty. (src/agents/auth-profiles/candidate-stores.ts:210, c13eaeedc6c1)
  • Reporter narrowed the actionable case: WG-Mojo identified the empty retained store and reported before/after manager regressions on a locally repaired release lineage; the later installed probe used fresh sign-in and explicitly did not prove expired-token rotation.
  • Matching deleted generations remain refused: The added real-manager/SQLite cases verify successful surviving credential settlement for an empty deleted peer and zero provider callbacks for a matching deleted peer, preserving historical contents and the completed deletion journal. (src/agents/auth-profiles/oauth.concurrent-agents.test.ts:77, 3da44cecc0c4)
  • Maintainer disposition verified against owners: The maintainer declined an additional write-admission recheck at fix(auth): refresh shared OAuth past empty deleted peers #179205 (comment); source confirms shared OAuth profile locks, fenced-generation replacement refusal, and post-provider peer rediscovery. (src/agents/auth-profiles/upsert-with-lock.ts:250, 3da44cecc0c4)
  • Focused CI evidence and inspection limit: The linked auth job succeeded on f3f9b52, and its production/test files are unchanged at the reviewed head; raw job logs redirected to a blocked storage host, so individual test output was not independently inspected. (f3f9b52cc80e)

PR surface

Source +21, Tests +63, Docs +4. Total +88 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 25 4 +21
Tests 1 63 0 +63
Docs 1 5 1 +4
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 93 5 +88

Review metrics

Metric Value Why it matters
Production versus regression coverage Production +25/-4; tests +63/-0 The production growth supplies the missing pre-admission read and captured identity; the two test cases protect distinct success and deletion-refusal outcomes.

Root-cause cluster

Relationship: fixed_by_candidate
Canonical: #178908
Summary: This PR implements the linked report's narrowed empty retained-store admission repair.

Members:

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

Labels

Label changes:

  • add P1: The linked report describes failed real-user fallback requests, and current source independently confirms the admission ordering that blocks shared OAuth refresh.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

Label justifications:

  • P1: The linked report describes failed real-user fallback requests, and current source independently confirms the admission ordering that blocks shared OAuth refresh.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.

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 21, 2026, 4:19 AM ET / 08:19 UTC.

@steipete
steipete merged commit c08aa6d into main Oct 21, 2026
126 checks passed
@steipete
steipete deleted the fix/oauth-fence-skips-unrelated-deleted-peer branch October 21, 2026 08:57
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Oct 22, 2026
…9205)

* fix(auth): allow refresh past unrelated deleted peers

Read historical auth candidates before write admission so empty retained stores cannot block shared OAuth refresh. Possible matches retain all transactional generation, identity, and deletion checks.

Add empty and matching completed-deletion manager regressions. Fixes openclaw#178908.

* fix(auth): bind peer reads to discovered file identity

Honor the candidate identity in the existing asynchronous auth reader so rediscovered replacement databases do not reuse stale observed identities. Preserve direct identity checks and unchanged write authority.

Seed the retained matching-peer fixture before shared inheritance removes the local copy; assert its persisted contents before deletion.
RomneyDa pushed a commit that referenced this pull request Oct 26, 2026
* fix(auth): allow refresh past unrelated deleted peers

Read historical auth candidates before write admission so empty retained stores cannot block shared OAuth refresh. Possible matches retain all transactional generation, identity, and deletion checks.

Add empty and matching completed-deletion manager regressions. Fixes #178908.

* fix(auth): bind peer reads to discovered file identity

Honor the candidate identity in the existing asynchronous auth reader so rediscovered replacement databases do not reuse stale observed identities. Preserve direct identity checks and unchanged write authority.

Seed the retained matching-peer fixture before shared inheritance removes the local copy; assert its persisted contents before deletion.

Release adaptation: the baseline auth row reader has no cached file-state path, so
the discovered candidate identity simply overrides the inspected identity. The
regression uses the baseline's inline OAuth fixtures instead of main's
coordination fixture.

(cherry picked from commit c08aa6d)
tideclaw-bot added a commit that referenced this pull request Nov 4, 2026
Adapt 21 audited fixes to release-native ownership and recovery.
Retain strict temporary environment isolation and provider-only cooldowns.

Original-source provenance and contributor credit:
#179144 5a97c90 — Peter Steinberger <[email protected]>
#180280 442c2f7 — Jason (Json) <[email protected]>
#178596 63f386b — Braden Guliano <[email protected]>
#181804 d75915e — Peter Steinberger <[email protected]>
#181140 b4031b2 — Peter Steinberger <[email protected]>
#182207 b8fae65 — Peter Steinberger <[email protected]>
#180792 d2c70dd — Peter Steinberger <[email protected]>
#179205 c08aa6d — Peter Steinberger <[email protected]>
#179997 f178dd9 — mali <[email protected]>
#181270 e204484 — Peter Steinberger <[email protected]>
#179031 855b0aa — Peter Steinberger <[email protected]>
#179726 3d51d00 — Peter Steinberger <[email protected]>
#179249 b617d97 — Josh Avant <[email protected]>
#182385 bb13bcd — Peter Steinberger <[email protected]>
#182615 411bac2 — Peter Steinberger <[email protected]>
#181300 765c2f1 — Peter Steinberger <[email protected]>
#179549 09ba994 — Peter Steinberger <[email protected]>
#179445 ac5587b — Peter Steinberger <[email protected]>
#181127 25dde25 — Josh Lehman <[email protected]>
#173209 ebccf57 — Peter Steinberger <[email protected]>
#175289 e579f09 — Peter Steinberger <[email protected]>

Proof: targeted owner/regression tests; Qwen15 and catalog pool13 pass.
Final integrated lint/type/format pass remains pending under user direction.

Co-authored-by: RomneyDa <[email protected]>
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 P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. security-sensitive-changed 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.

[Bug]: Shared OAuth refresh reopens a completed-deletion agent database while fencing historical peers

1 participant