Repository navigation
Conversation
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]>
…r exports Co-authored-by: obviyus <[email protected]>
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]>
|
🦞👀 Pull request received. I will update this pull request when review starts. ClawSweeper review completeClawSweeper finished reviewing this revision. The review result is being finalized. |
|
|
Codex review: needs maintainer review before merge. What this changesThis PR prevents foreign-owned OAuth refreshes and moves affected credential edits and embedded commands onto existing state owners. Example: Run openclaw infer audio transcribe beside a Gateway with an OAuth token valid for another 4.5 minutes.
Review scores
ProductKind: Bug fix · Worth it: Yes · Fix scope: Complete Merge readiness✅ Ready for maintainer review Keep open: this maintainer-authored PR repairs a confirmed shared-credential ownership bug, and review found no actionable introduced defect. Priority: P1 Before mergeNone. FindingsNone. Agent review detailsHow this fits togetherCLI inference and embedded commands resolve OAuth credentials through the auth-profile manager, which supplies access tokens and coordinates refresh persistence with canonical state ownership. flowchart TD
A[Local CLI command] --> B[OAuth manager]
B --> C[Credential scope and state owner]
C --> D[Use valid token]
C --> E[Refuse foreign owned refresh]
C --> F[Refresh under existing owner]
D --> G[Provider request]
F --> G
Technical reviewBest possible solution: Keep refresh admission 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? Fetched-main source permits the reported outside refresh, and the supplied CLI/Gateway comparisons demonstrate matching failures; this read-only review ran no target code. Is this the best way to solve the issue? The patch repairs the writer boundary, preserves intentional Gateway cache behavior, and replaces competing command-specific custody paths with the existing owner. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning medium; reviewed against 64fd44bdaae8. Provenance checked
TestingProof path: shipped entry point. SecurityNone. EvidenceWhat I checked:
Likely related people:
PR surfaceSource -73, Tests -365, Docs +5. Total -433 across 30 files. Added test files: 0. View PR surface stats
Preflight sourceSource unknown. Source comparison at the observed PR snapshot only. Completion is self-reported; body, policy, tests, execution, and report bytes are not verified. LabelsLabel changes: No label changes. Label justifications:
Rating scale6/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. WorkflowClawSweeper edits this one comment on every review. Comment Reviewed November 13, 2026, 9:02 AM ET / 14:02 UTC. |
What Problem This Solves
Fixes: Gateway turns fail with
No credentials found for profile "<provider>:<account>"after a local CLI command (for exampleinfer audio transcribe,infer tts convertorinfer model auth login) refreshes or stores a shared OAuth sign-in while the Gateway runs.User Impact
While a Gateway runs, it is the only process that refreshes or stores shared OAuth sign-ins. Gateway turns keep working after local CLI commands.
A local command beside a running Gateway uses a still-valid token as is. If the token has expired, the command refuses before it changes anything, and it tells you to run the command through the Gateway or stop the Gateway first:
infer model auth loginnow runs themodels auth loginpath (routed through the Gateway when one runs).infer model auth logoutrefuses while a Gateway runs, the same asmodels auth logout.agent --local,agent exec --state-dir,tui --localandmodels status --probeshow one shared offline-only refusal instead of four different ones.With no Gateway running, nothing changes.
Why This Change Was Made
The rule "outside writers route through the Gateway or hold exclusive offline custody" (worker access) was enforced separately in each command, and each command that missed it broke the Gateway's sign-in. A read-only command can write credentials only by refreshing an OAuth sign-in, so this PR enforces ownership once, in the OAuth manager, before the refresh queue, claim or any write. Explicit credential edits reuse the existing
models authowner. Embedded runs userunWithLocalStateOwner, and the duplicateacquireEmbeddedStateLockowner is removed. There is no Gateway method, protocol, config or schema change, and nothing changes on the Gateway side.Production diff (without tests and docs): +251 / −324, net −73. This includes moving
settleOAuthRefreshPeerClaimsUnderLockunchanged fromoauth-manager.tstooauth-store.tsto respect the file line cap.Caller map, deleted code, accepted edge cases
Caller map
infer model run(default /--local)infer image/audio/video/web/embedding, localtts convertinfer model auth loginmodels auth loginowner (routes)infer model auth logoutmodels authowner (refuses)agent --local,agent exec --state-dir,tui --local,models status --proberunWithLocalStateOwner(refuses)models auth *,mcpcredential commands,memoryrunWithLocalStateOwner(unchanged)Deleted
src/infra/embedded-state-lock.ts:acquireEmbeddedStateLock. The signal bridge moved toprocess-signal-bridge.ts.formatActiveGatewayLocalRefusal,formatActiveGatewayExecRefusal,formatActiveGatewayTuiRefusal,formatActiveGatewayModelsProbeRefusal).infer model auth logoutimplementation (runModelAuthLogout) and the direct login call.Production diff (excluding tests and docs): +251 / −324, net −73 (includes moving
settleOAuthRefreshPeerClaimsUnderLockunchanged fromoauth-manager.tstooauth-store.tsto respect the line cap).Accepted edge cases
models status --probebatch now reports after its in-flight probes settle, because ownership must outlive them.Evidence
Regression 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 duplicatedrunWithLocalStateOwner's own suite were removed).E2E. Each case uses its own isolated scratch Gateway (one at a time, with its own state dir and port) and 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. The later commit 31e76d5 changes only the redirected-scope lookup; the stand-ininfer image describecases were run again on the final head 31e76d5 (same tree as the a5935f0 build) and gave the same results. "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.infer model runup valid / expiredinfer image describeup validinfer image describeup expiredNo API key foundinfer audio transcribeup validNo credentials found for profile)infer audio transcribeup expiredinfer tts convertup validNo credentials found for profile)infer tts convertup expiredinfer model auth loginupmodels auth login(refuses a non-Gateway method)infer model auth logoutupmodels authrefusal, nothing removedagent --local+models status --probeuprunWithLocalStateOwnerrefusalagent --local, probe)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 withNo 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.Final head, stand-in provider,
infer image describe:Notes:
infer audio transcribewith an expired, Gateway-owned sign-in reportsNo audio transcription provider is configured or readyinstead of the ownership message, because the sharedhasAvailableAuthForProviderprobe 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 closedshows in Gateway logs on bothmainand 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.