Skip to content

fix(auth): only the running Gateway refreshes shared OAuth sign-ins - #198214

Merged
obviyus merged 5 commits into
mainfrom
fix/credential-refresh-owner
Nov 13, 2026
Merged

obviyus merged 5 commits into
mainfrom
fix/credential-refresh-owner

Conversation

@obviyus

@obviyus obviyus commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

The rule "outside writers route through the Gateway or hold exclusive offline custody" (worker access) was enforced per command. Every command that forgot it could refresh a shared OAuth sign-in beside a running Gateway and store the new token. The Gateway keeps reading its own copy, its next refresh claim loses, and every later turn on that profile fails with No credentials found for profile "<provider>:<account>" until the Gateway restarts.

Unguarded today: infer image/audio/video/web/embedding, local infer tts convert, infer model auth login/logout. agent --local, agent exec --state-dir, tui --local and models status --probe had a second, duplicate owner (acquireEmbeddedStateLock) with four separate refusal messages.

Fix: one owner

The OAuth refresh is the choke point. A read-only command can only write credentials by refreshing an OAuth sign-in. resolveOAuthAccessBesideStateOwner (called once from the OAuth manager, before the refresh queue, claim or any write) decides:

  • This process owns the state (the Gateway itself, or a runWithLocalStateOwner holder), or no Gateway runs: unchanged.

  • A Gateway (or another state holder) owns it, and the token is still valid: use it as is, no refresh. The Gateway refreshes on its next turn.

  • A Gateway owns it, and the token has expired (or the provider rejected it): refuse before any write:

    The <provider> sign-in "<profile>" needs a refresh, but the Gateway (pid N, port P) owns the shared credentials and only it may refresh them. No credential was changed. Run this through the Gateway, retry after its next turn refreshes the sign-in, or stop the Gateway through its service owner and rerun this command.
    

No Gateway method, protocol, config or schema change. Nothing changes on the Gateway side (no freshness probes, no cache retirement).

Explicit credential edits reuse the models auth owner.

  • infer model auth login runs the models auth login path: with a Gateway running, the sign-in runs through models.authLogin.
  • infer model auth logout uses the models auth state owner (refuses while a Gateway runs) and the shared removeModelAuthCredentials owner. This also forgets the provider's saved catalog rows, which the private copy skipped.

Embedded runs use the one state owner. agent --local, agent exec --state-dir, tui --local and models status --probe take custody through runWithLocalStateOwner and share its refusal text (... This command is offline-only. <online alternative> To run offline, stop the Gateway ...). agent exec --state-dir keeps its retained custody after uncertain runtime cleanup through retainAfterUncertainCleanup. infer model run keeps its #198141 routing.

Caller map

CLI path Writes while a Gateway runs Covered by
infer model run (default / --local) refresh #198141 routing / refusal (unchanged)
infer image/audio/video/web/embedding, local tts convert refresh refresh owner
infer model auth login sign-in models auth login owner (routes)
infer model auth logout profile removal models auth owner (refuses)
agent --local, agent exec --state-dir, tui --local, models status --probe refresh + all state runWithLocalStateOwner (refuses)
models auth *, mcp credential commands, memory as before runWithLocalStateOwner (unchanged)
any other local refresh (plugins, tools) refresh refresh owner

Deleted

  • src/infra/embedded-state-lock.ts: acquireEmbeddedStateLock. The signal bridge moved to process-signal-bridge.ts.
  • The four per-command refusal formatters (formatActiveGatewayLocalRefusal, formatActiveGatewayExecRefusal, formatActiveGatewayTuiRefusal, formatActiveGatewayModelsProbeRefusal).
  • The private infer model auth logout implementation (runModelAuthLogout) and the direct login call.

Production diff (excluding tests and docs): +251 / −324, net −73 (includes moving settleOAuthRefreshPeerClaimsUnderLock unchanged from oauth-manager.ts to oauth-store.ts to respect the line cap).

Accepted edge cases

  • A failed models status --probe batch now reports after its in-flight probes settle, because ownership must outlive them.
  • Usage bookkeeping (cooldown and last-used stats) from a local command is not a credential refresh and is not gated here.

Tests (red on main, green here)

  • src/agents/auth-profiles/oauth-manager.test.ts › credentials owned by a running Gateway › uses a still-valid sign-in without refreshing it. On main the CLI refreshes the in-window token.
  • … › refuses to refresh an expired sign-in before any write. On main the refresh runs and stores.
  • … › refuses for the retained credential scope of a redirected run. Without the scope fix, owner discovery reads the process env and the refresh runs.
  • src/cli/capability-cli/model.state-owner.test.ts › refuses infer model auth logout while the Gateway owns the shared credentials. On main logout enters local agent admission.

Updated: agent-via-gateway, agent-exec.state-lock, agent-exec.auth, tui, list.probe, list.probe.cleanup, database-port-admission (ownership assertions now use the shared owner; tests that duplicated runWithLocalStateOwner's own suite were removed).

E2E

Isolated scratch Gateway per case (one at a time, own state dir and port), real agent turns, two OAuth sign-ins: a stand-in OAuth provider (local mock token endpoint) and a real hosted OAuth provider. main = 8ebe740 build, fix = PR build (a1045f3; later commits change only the redirected-scope lookup and tests). "Writer" = the process that stored a refreshed credential (from the credential row's writer record). "upvalid" = token valid for ~4.5 min; "upexpired" = token expired, Gateway up; "down" = no Gateway. Each up case runs 8–10 Gateway turns around the command.

Case main: command main: writer main: later turns fix: command fix: writer fix: later turns
infer model run up valid / expired via Gateway, OK Gateway 10/10, 8/8 via Gateway, OK Gateway 10/10, 8/8
infer image describe up valid local, OK Gateway 10/10 local, OK, no refresh Gateway 10/10
infer image describe up expired No API key found Gateway 8/8 ownership refusal, nothing written Gateway 8/8
infer audio transcribe up valid local, OK, refreshed a valid token CLI 9/10 (No credentials found for profile) local, OK, no refresh Gateway 10/10
infer audio transcribe up expired local, OK, refreshed CLI 8/8 refused, nothing written (see note) Gateway 8/8
infer tts convert up valid local, OK, refreshed a valid token CLI 9/10 (No credentials found for profile) local, OK, no refresh Gateway 10/10
infer tts convert up expired local, OK, refreshed CLI 8/8 ownership refusal, nothing written Gateway 8/8
infer model auth login up local sign-in, stored CLI 10/10 routed to models auth login (refuses a non-Gateway method) Gateway 10/10
infer model auth logout up removed beside the Gateway – 10/10 (Gateway re-stored the profile) models auth refusal, nothing removed Gateway 10/10
agent --local + models status --probe up 2 separate refusals Gateway 10/10 shared runWithLocalStateOwner refusal Gateway 10/10
every command with no Gateway (model run, image, audio, tts, login, logout, agent --local, probe) OK, refreshes locally CLI – OK, refreshes locally CLI –

Summary: on main, the CLI is a second credential writer beside a running Gateway in audio, tts and login, and the next Gateway turn fails with No credentials found for profile. On this branch the Gateway is the only writer whenever it runs, and no Gateway turn fails. Offline behavior is unchanged.

Notes:

  • infer audio transcribe with an expired, Gateway-owned sign-in reports No audio transcription provider is configured or ready instead of the ownership message, because the shared hasAvailableAuthForProvider probe maps every auth error to "not available". Nothing is written. Follow-up, not in this PR (the probe has six other callers).
  • auth-triggered model runtime refresh failed: Plugin invocation scope is closed shows in Gateway logs on both main and this branch. It is not caused by this change and did not fail any turn.

Data compatibility: no schema, stored credential shape, config or protocol change. The same stored sign-ins (copied from a real install) load and work before and after.

A local CLI command beside a running Gateway could refresh a shared OAuth
token and store it. The Gateway kept reading its stale copy, and every later
turn failed with "No credentials found for profile". Each command had to
opt in to the state-owner check, and several did not (`infer image/audio/
video/web/embedding`, local `tts convert`, `infer model auth login/logout`).

Enforce ownership once, at the OAuth refresh: a process that does not own
the state uses a still-valid token as is and refuses an expired one before
any write, naming the Gateway. With no Gateway, refresh runs locally as
before.

`infer model auth login/logout` now use the `models auth` state owner and
credential removal. `agent --local`, `agent exec --state-dir`, `tui --local`
and `models status --probe` take state ownership through
`runWithLocalStateOwner`; the duplicate embedded state lock and its four
refusal messages are removed.

Co-authored-by: obviyus <[email protected]>
@clawsweeper

clawsweeper Bot commented Nov 13, 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 cli CLI command changes commands Command implementations agents Agent runtime and tooling size: XL labels Nov 13, 2026
@obviyus
obviyus marked this pull request as ready for review November 13, 2026 10:18
@github-actions

github-actions Bot commented Nov 13, 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: a5935f01b0185dfe7fe7e2f5571b8a74c4db9c0f
  • Maintainer: @obviyus
  • Repository role: admin

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-refresh-failure.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.

Carefully review these changes before merging.

@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. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Nov 13, 2026
@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: needs maintainer review before merge.

What this changes

This PR prevents local OAuth refreshes beside a running Gateway and consolidates credential edits and embedded commands under existing state owners.

Example: Run openclaw infer audio transcribe while the Gateway owns an OAuth sign-in with about 4.5 minutes remaining.

  • Before: The CLI can refresh the token, leaving later Gateway turns failing with No credentials found for profile.
  • After: The CLI uses the still-valid token without refreshing it, and subsequent Gateway turns continue working.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A useful ownership repair supported by production-entry-point results and focused regressions, with no new actionable finding.
Proof confidence 🐚 platinum hermit (4/6) Sufficient (live_output): The supplied built-CLI and isolated-Gateway report exercises near-expiry and expired OAuth credentials, online refusal, offline refresh, login/logout ownership, and successful subsequent agent turns; later effective changes correct retained-scope discovery and its regression 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: A local inference command can leave a running Gateway unable to use an otherwise valid OAuth sign-in until restart.
Reason: The maintainer-selected direction restores the documented single-writer contract using existing owners, with a bounded refusal tradeoff.

Merge readiness

✅ Ready for maintainer review

This PR addresses a confirmed shared-credential ownership bug; the earlier findings are resolved, and no new actionable defect was found.

Priority: P1
Reviewed head: a5935f01b0185dfe7fe7e2f5571b8a74c4db9c0f

Before merge

None.

Findings

None.

Agent review details

How this fits together

CLI inference and agent commands resolve credentials through the OAuth manager, which returns usable access tokens or refreshes persisted credentials under the selected state owner.

flowchart TD
  A[Local CLI command] --> B[OAuth manager]
  B --> C[Credential scope and state owner]
  C --> D[Use valid token without refresh]
  C --> E[Refuse foreign owned refresh]
  C --> F[Owner refresh and persistence]
  D --> G[Provider request]
  F --> G
Loading

Technical review

Best possible solution:

Keep refresh ownership in the OAuth manager and reuse the existing state and credential-removal owners for affected commands.

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

Current-main source exposes the unguarded refresh path, and the supplied CLI/Gateway comparisons report matching failures; this read-only review did not execute the reproduction.

Is this the best way to solve the issue?

The change repairs the credential writer boundary, preserves intentional Gateway cache behavior, and removes competing command-specific ownership implementations.

AGENTS.md: found and applied where relevant.

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

Provenance checked

  • OAuth lifecycle and refresh scheduling changes intended behavior with a stated reason (5f2e77a: Centralize canonical OAuth lifecycle ownership rather than letting runtime integrations maintain competing auth authorities.)
  • Embedded command state custody keeps the original intent (0850790: Prevent embedded CLI writers from mutating canonical state beside a running Gateway and retain custody through cleanup.)
  • Native process signal handling keeps the original intent (2cd23b6: Use actual process signals and native state ownership instead of private production injection plumbing.)
  • Inference credential-edit commands changes intended behavior with a stated reason (97c031a: Expose provider authentication through the inference CLI; the PR explains replacing its private mutation paths with the coordinated models-auth owners.)

Testing

Proof path: shipped entry point.

Security

None.

Evidence

What I checked:

Likely related people:

  • Peter Steinberger: Raw commit 1b08795 adds src/cli/local-state-owner.ts:36 relative to its recorded parents. This identifies author metadata, not feature responsibility or a PR merger. (role: source-line author; confidence: high; commits: 1b08795ae494; files: src/cli/local-state-owner.ts)

PR surface

Source -73, Tests -365, Docs +5. Total -433 across 30 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 15 251 324 -73
Tests 12 125 490 -365
Docs 3 5 0 +5
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 30 381 814 -433

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.

Labels

Label changes:

  • add proof: sufficient: Contributor real behavior proof is sufficient.
  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • remove rating: 🧂 unranked krab: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.

Label justifications:

  • P1: Local OAuth refreshes can leave real Gateway agent turns failing repeatedly until restart.
  • merge-risk: 🚨 auth-provider: The patch changes shared OAuth refresh admission and sign-in routing; the maintainer explicitly accepts refusal of expired credentials owned by another process.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🐚 platinum hermit and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR.
  • 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.

History

Review history (2 earlier review cycles)
  • reviewed 2026-11-13T10:36:49.357Z sha 29f82eb :: needs changes before merge. :: [P1] Check the retained credential scope when discovering its owner | [P2] Migrate the existing logout tests to the shared removal owner
  • reviewed 2026-11-13T11:48:59.067Z sha 31e76d5 :: blocked before merge. :: none

Reviewed November 13, 2026, 7:33 AM ET / 12:33 UTC (Revision 3).

@clawsweeper clawsweeper Bot removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Nov 13, 2026
An exec run redirects its own state directory while it keeps the original
credential scope. Discover the state owner from that scope, so a refresh of
credentials a running Gateway owns is still refused.

Co-authored-by: obviyus <[email protected]>
@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

@clawsweeper re-review

@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. labels Nov 13, 2026
@clawsweeper

clawsweeper Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
Exact review queued.

Re-review progress:

@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. proof: sufficient ClawSweeper judged the real behavior proof convincing. 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. and removed rating: 🧂 unranked krab Not merge-ready due to missing proof or serious correctness/safety concerns. 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 Nov 13, 2026
@obviyus

obviyus commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator Author

Maintainer override: the only red jobs are checks-ui-e2e (2/3) and the openclaw/ci-gate aggregate it feeds. The failing test is ui/src/e2e/home-readonly.real-gateway.e2e.test.ts › "Read-only Home real Gateway", which this PR does not touch. The same test fails on main itself: scheduled CI run https://github.com/openclaw/openclaw/actions/runs/43433551091 (job https://github.com/openclaw/openclaw/actions/runs/43433551091/job/131913462868, head b9f1e62). Exact-head E2E is in the PR body, and the hosted ClawSweeper review is ready on this head.

@obviyus
obviyus merged commit 3577724 into main Nov 13, 2026
284 of 289 checks passed
@obviyus
obviyus deleted the fix/credential-refresh-owner branch November 13, 2026 14:00
roboclaw-bot added a commit that referenced this pull request Nov 13, 2026
Peer settlement moved into oauth-store in #198214, leaving the helper
without an external consumer. Remove only its unused export; preserve
the internal call and all credential settlement behavior.

Co-authored-by: obviyus <[email protected]>
Co-authored-by: steipete <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 14, 2026
…penclaw#198214)

## Problem

The rule "outside writers route through the Gateway or hold exclusive offline custody" ([worker access](https://docs.openclaw.ai/reference/database-schemas/worker-access)) was enforced per command. Every command that forgot it could refresh a shared OAuth sign-in beside a running Gateway and store the new token. The Gateway keeps reading its own copy, its next refresh claim loses, and every later turn on that profile fails with `No credentials found for profile "<provider>:<account>"` until the Gateway restarts.

Unguarded today: `infer image/audio/video/web/embedding`, local `infer tts convert`, `infer model auth login/logout`. `agent --local`, `agent exec --state-dir`, `tui --local` and `models status --probe` had a second, duplicate owner (`acquireEmbeddedStateLock`) with four separate refusal messages.

## Fix: one owner

**The OAuth refresh is the choke point.** A read-only command can only write credentials by refreshing an OAuth sign-in. `resolveOAuthAccessBesideStateOwner` (called once from the OAuth manager, before the refresh queue, claim or any write) decides:

- This process owns the state (the Gateway itself, or a `runWithLocalStateOwner` holder), or no Gateway runs: unchanged.
- A Gateway (or another state holder) owns it, and the token is still valid: use it as is, no refresh. The Gateway refreshes on its next turn.
- A Gateway owns it, and the token has expired (or the provider rejected it): refuse before any write:

  ```
  The <provider> sign-in "<profile>" needs a refresh, but the Gateway (pid N, port P) owns the shared credentials and only it may refresh them. No credential was changed. Run this through the Gateway, retry after its next turn refreshes the sign-in, or stop the Gateway through its service owner and rerun this command.
  ```

No Gateway method, protocol, config or schema change. Nothing changes on the Gateway side (no freshness probes, no cache retirement).

**Explicit credential edits reuse the `models auth` owner.**
- `infer model auth login` runs the `models auth login` path: with a Gateway running, the sign-in runs through `models.authLogin`.
- `infer model auth logout` uses the `models auth` state owner (refuses while a Gateway runs) and the shared `removeModelAuthCredentials` owner. This also forgets the provider's saved catalog rows, which the private copy skipped.

**Embedded runs use the one state owner.** `agent --local`, `agent exec --state-dir`, `tui --local` and `models status --probe` take custody through `runWithLocalStateOwner` and share its refusal text (`... This command is offline-only. <online alternative> To run offline, stop the Gateway ...`). `agent exec --state-dir` keeps its retained custody after uncertain runtime cleanup through `retainAfterUncertainCleanup`. `infer model run` keeps its openclaw#198141 routing.

## Caller map

| CLI path | Writes while a Gateway runs | Covered by |
|---|---|---|
| `infer model run` (default / `--local`) | refresh | openclaw#198141 routing / refusal (unchanged) |
| `infer image/audio/video/web/embedding`, local `tts convert` | refresh | refresh owner |
| `infer model auth login` | sign-in | `models auth login` owner (routes) |
| `infer model auth logout` | profile removal | `models auth` owner (refuses) |
| `agent --local`, `agent exec --state-dir`, `tui --local`, `models status --probe` | refresh + all state | `runWithLocalStateOwner` (refuses) |
| `models auth *`, `mcp` credential commands, `memory` | as before | `runWithLocalStateOwner` (unchanged) |
| any other local refresh (plugins, tools) | refresh | refresh owner |

## Deleted

- `src/infra/embedded-state-lock.ts`: `acquireEmbeddedStateLock`. The signal bridge moved to `process-signal-bridge.ts`.
- The four per-command refusal formatters (`formatActiveGatewayLocalRefusal`, `formatActiveGatewayExecRefusal`, `formatActiveGatewayTuiRefusal`, `formatActiveGatewayModelsProbeRefusal`).
- The private `infer model auth logout` implementation (`runModelAuthLogout`) and the direct login call.

Production diff (excluding tests and docs): **+251 / −324, net −73** (includes moving `settleOAuthRefreshPeerClaimsUnderLock` unchanged from `oauth-manager.ts` to `oauth-store.ts` to respect the line cap).

## Accepted edge cases

- A failed `models status --probe` batch now reports after its in-flight probes settle, because ownership must outlive them.
- Usage bookkeeping (cooldown and last-used stats) from a local command is not a credential refresh and is not gated here.

## Tests (red on `main`, green here)

- `src/agents/auth-profiles/oauth-manager.test.ts` › `credentials owned by a running Gateway` › `uses a still-valid sign-in without refreshing it`. On main the CLI refreshes the in-window token.
- … › `refuses to refresh an expired sign-in before any write`. On main the refresh runs and stores.
- … › `refuses for the retained credential scope of a redirected run`. Without the scope fix, owner discovery reads the process env and the refresh runs.
- `src/cli/capability-cli/model.state-owner.test.ts` › `refuses infer model auth logout while the Gateway owns the shared credentials`. On main logout enters local agent admission.

Updated: `agent-via-gateway`, `agent-exec.state-lock`, `agent-exec.auth`, `tui`, `list.probe`, `list.probe.cleanup`, `database-port-admission` (ownership assertions now use the shared owner; tests that duplicated `runWithLocalStateOwner`'s own suite were removed).

## E2E

Isolated scratch Gateway per case (one at a time, own state dir and port), real agent turns, two OAuth sign-ins: a stand-in OAuth provider (local mock token endpoint) and a real hosted OAuth provider. `main` = 92217cc build, `fix` = PR build (a1045f3; later commits change only the redirected-scope lookup and tests). "Writer" = the process that stored a refreshed credential (from the credential row's writer record). "upvalid" = token valid for ~4.5 min; "upexpired" = token expired, Gateway up; "down" = no Gateway. Each up case runs 8–10 Gateway turns around the command.

| Case | main: command | main: writer | main: later turns | fix: command | fix: writer | fix: later turns |
|---|---|---|---|---|---|---|
| `infer model run` up valid / expired | via Gateway, OK | Gateway | 10/10, 8/8 | via Gateway, OK | Gateway | 10/10, 8/8 |
| `infer image describe` up valid | local, OK | Gateway | 10/10 | local, OK, no refresh | Gateway | 10/10 |
| `infer image describe` up expired | `No API key found` | Gateway | 8/8 | ownership refusal, nothing written | Gateway | 8/8 |
| `infer audio transcribe` up valid | local, OK, **refreshed a valid token** | **CLI** | **9/10** (`No credentials found for profile`) | local, OK, no refresh | Gateway | 10/10 |
| `infer audio transcribe` up expired | local, OK, refreshed | **CLI** | 8/8 | refused, nothing written (see note) | Gateway | 8/8 |
| `infer tts convert` up valid | local, OK, **refreshed a valid token** | **CLI** | **9/10** (`No credentials found for profile`) | local, OK, no refresh | Gateway | 10/10 |
| `infer tts convert` up expired | local, OK, refreshed | **CLI** | 8/8 | ownership refusal, nothing written | Gateway | 8/8 |
| `infer model auth login` up | local sign-in, stored | **CLI** | 10/10 | routed to `models auth login` (refuses a non-Gateway method) | Gateway | 10/10 |
| `infer model auth logout` up | removed beside the Gateway | – | 10/10 (Gateway re-stored the profile) | `models auth` refusal, nothing removed | Gateway | 10/10 |
| `agent --local` + `models status --probe` up | 2 separate refusals | Gateway | 10/10 | shared `runWithLocalStateOwner` refusal | Gateway | 10/10 |
| every command with no Gateway (model run, image, audio, tts, login, logout, `agent --local`, probe) | OK, refreshes locally | CLI | – | OK, refreshes locally | CLI | – |

Summary: on `main`, the CLI is a second credential writer beside a running Gateway in audio, tts and login, and the next Gateway turn fails with `No credentials found for profile`. On this branch the Gateway is the only writer whenever it runs, and no Gateway turn fails. Offline behavior is unchanged.

Notes:
- `infer audio transcribe` with an expired, Gateway-owned sign-in reports `No audio transcription provider is configured or ready` instead of the ownership message, because the shared `hasAvailableAuthForProvider` probe maps every auth error to "not available". Nothing is written. Follow-up, not in this PR (the probe has six other callers).
- `auth-triggered model runtime refresh failed: Plugin invocation scope is closed` shows in Gateway logs on both `main` and this branch. It is not caused by this change and did not fail any turn.

Data compatibility: no schema, stored credential shape, config or protocol change. The same stored sign-ins (copied from a real install) load and work before and after.

Co-authored-by: Ayaan Zaidi <[email protected]>
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Nov 14, 2026
Peer settlement moved into oauth-store in openclaw#198214, leaving the helper
without an external consumer. Remove only its unused export; preserve
the internal call and all credential settlement behavior.

Co-authored-by: obviyus <[email protected]>
Co-authored-by: steipete <[email protected]>
maplel pushed a commit to maplel/openclaw that referenced this pull request Nov 24, 2026
…94251)

fix(infer): stop video runs on Ctrl+C

`openclaw infer video` dropped its execution context, and with it the cancel signal, so Ctrl+C left the provider request open until the CLI was force-killed about 2 seconds later. The existing execution context is now passed through, as audio already does. Uninterrupted runs are unchanged.

Evidence: built CLI with a real MP4 against a slow local video-provider fixture, twice per ref. Main needed SIGKILL after about 2,090 ms; with this change the CLI exits with 130 in under 100 ms and the HTTP request closes within 1.1 ms. Uninterrupted output and request bodies are identical. Details: openclaw#194251 (comment).

Thanks @Alix-007.

Co-authored-by: Ayaan Zaidi <[email protected]>

(cherry picked from commit 3af1447)

Release adaptation: Forward video execution signal/assertCurrent and move existing guarded fetch/process scope to shared file owner. Retain baseline audio CLI and filesystem resolution: excluded HOLD audio/path migration not imported. Only13-line cancel regression, no fixture refactor.

Follow-up dispositions: 577dd00 fix: send infer audio/video --model files only to the requested model (openclaw#190287); bcb47e8 feat(google): add Nano Banana 2.1 image model as the default (openclaw#200468); 6f5d3b3 fix: local path commands pick a neighboring file when a symlinked folder is followed by `..` (openclaw#200031); 3577724 fix(auth): only the running Gateway refreshes shared OAuth sign-ins (openclaw#198214); 81daea9 fix(cli): run infer model run through the Gateway that owns state (openclaw#198141); 22b1aac fix(media): cancel interrupted attachment downloads (openclaw#194399); e43ec1e fix(infer): cancel interrupted image descriptions (openclaw#194391)

Validation: Baseline canceled-video assertion fails with16controls passing; candidate17/17passes,194251-green.log. Existing audio cancellation and workspace/cleanup behavior retained. Real MP4/CLI interrupt proof remains upstream-attributed, not locally rerun.

Co-authored-by: RomneyDa <[email protected]>
(cherry picked from commit 853a96335df6193815789ebcc02d38af11123fcf)
(cherry picked from commit 2ea2570de7f13823a8174590bfddfbfabdbcd915)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agents Agent runtime and tooling cli CLI command changes commands Command implementations docs Improvements or additions to documentation merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. security-sensitive-changed size: XL 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