Repository navigation
fix(secrets): publish the durable auth order on a running gateway refresh - #135847
Conversation
…resh A successful models.authStatus refresh loaded the freshly persisted auth order from SQLite, but activation replaced the candidate's order, lastGood, usageStats and inheritance flag with the gateway's own live snapshot. When the write came from a separate CLI process, that live snapshot was exactly the stale pre-write order, so routing kept the old order until restart. Prepared snapshots now record the runtime auth snapshot generation observed before their auth stores were loaded. Activation keeps live bookkeeping only for stores that changed after that point, so genuinely concurrent in-process mutations still win while a fresh durable candidate replaces the stale live order. Fixes openclaw#135734
|
🦞👀 Pull request received. I will update this pull request when review starts. |
|
Codex review: needs maintainer review before merge. Reviewed September 1, 2026, 11:17 PM ET / September 2, 2026, 03:17 UTC. ClawSweeper reviewWhat this changesThe PR changes auth-runtime snapshot activation so a running Gateway adopts an externally persisted provider-order change unless newer in-process bookkeeping exists. Merge readinessKeep this focused fix open: current main still overwrites the freshly loaded durable auth order with stale live bookkeeping, and the introduced generation guard repairs that owner-boundary failure while retaining post-preparation live mutations. Priority: P1 Review scores
Verification
How this fits togetherA CLI auth-order write persists provider selection order in the SQLite auth store, then asks the running Gateway to refresh its in-memory secrets runtime. The snapshot activation layer decides whether durable state or newer live bookkeeping becomes the next runtime state. flowchart LR
A[CLI auth-order write] --> B[SQLite auth store]
B --> C[Gateway refresh request]
C --> D[Prepare auth snapshot]
D --> E[Activation merge]
E --> F[Live provider routing]
Before merge
Agent review detailsSecurityNone. PR surfaceSource +34, Tests +49. Total +83 across 5 files. View PR surface stats
Review metrics
Root-cause clusterRelationship: Members:
Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything. Merge-risk optionsMaintainer options:
Technical reviewBest possible solution: Retain the activation-boundary generation check and merge after exact-head validation; the watermark is the smallest shared fact that distinguishes a stale live snapshot from a genuinely concurrent in-process update without changing configuration or SQLite schemas. Do we have a high-confidence way to reproduce the issue? Yes, source provides a high-confidence reproduction path: persist an order from another process, request the Gateway refresh, and observe that current-main activation copies the old live order over the newly loaded durable candidate. Is this the best way to solve the issue? Yes. The fault is at the single snapshot activation merge shared by Gateway-driven refreshes, and the generation guard preserves the established concurrent-mutation behavior instead of adding a CLI- or protocol-specific workaround. AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against 77a24659740f. LabelsLabel changes:
Label justifications:
EvidenceWhat I checked:
Likely related people:
Rating scale
Overall follows the weaker of proof and patch quality. Workflow
|
|
Land-ready at Proof
Validation
Production LOC: +38/-1 (net +37) | Tests: +78/-8 (net +70). ClawSweeper rank-up move: retained the activation generation receipt and made it required across every internal producer. The production growth is the owner receipt that distinguishes stale live state from a real concurrent mutation; no configuration, schema, protocol, or fallback path was added. Proof gap: synthetic credentials were used, so no external provider request was sent. The real CLI, WebSocket Gateway method, SQLite store, activation owner, and shutdown path were exercised. |
|
Thanks @yetval! Proof: A separate real CLI changed the SQLite profile order while a real Gateway was running. Current main kept the old live order after two successful refresh requests. The landed head published the new order on the first refresh and retained it on the second.
Landed: c505a0b Source: 4ff38d7 |
What Problem This Solves
openclaw models auth order setpersists the requested order and asks a running Gateway to refresh throughmodels.authStatus { refresh: true }. Before this fix, the refresh could report success while the Gateway kept routing with its old in-memory order until restart.Fixes #135734.
Why This Change Was Made
Root cause
mergeLiveAuthStoreBookkeepingalways preferred same-owner live bookkeeping during activation. A separate CLI process cannot update the Gateway's process-local snapshot, so this rule replaced the freshly loaded SQLite order with the stale live order.The faulty merge came from #105289. #119946 later connected auth-order writes to the refresh path and made the stale merge user-visible on this command.
Fix
Prepared secrets snapshots now record the process-local auth snapshot generation before reading auth stores. Activation publishes the prepared order, last-good pointer, usage data, and inheritance state when that exact store did not change after preparation. A later in-process mutation advances the store generation and still wins.
The generation receipt is required for every internal snapshot. There is no fallback to the stale merge behavior. Rollback uses the same generation rule, so it retains durable bookkeeping loaded by the candidate and any newer live mutation.
User Impact
Operators can change provider profile priority while the Gateway is running. A successful refresh now makes routing use the durable order without a restart, while a real concurrent in-process update still wins.
Evidence
07cac7a3b6644e3dadef56cf3f4dc08372e330d9: a real separate CLI changed durable order froma,btob,a; both the CLI-triggered refresh and an explicit real Gateway refresh succeeded; live order stayeda,b.4ff38d7dc8da7d8e5e753ca59fcfac2bbfe194f3: the same real CLI and running-Gateway path changed durable and live order tob,a; a second explicit refresh kept them aligned.node scripts/run-vitest.mjs src/secrets/runtime-state.test.ts: 63 passed.Test audit
Risk
Production grows by 37 net lines. The added state is one lifecycle generation receipt required to distinguish stale live state from a real concurrent live mutation. It does not add configuration, schema, protocol, or fallback behavior.