Skip to content

fix(channels): scope wizard credentials to the selected account - #110969

Merged
steipete merged 3 commits into
mainfrom
fix/channels-add-account-overwrite
Jul 18, 2026
Merged

steipete merged 3 commits into
mainfrom
fix/channels-add-account-overwrite

Conversation

@steipete

Copy link
Copy Markdown
Contributor

What Problem This Solves

Fixes #79553. When an operator with an existing channel account selected "Add a new account" in the channel setup wizard, plugins using the accounts schema (observed with the WeCom plugin; the same class applies to any legacy accounts-schema plugin) pre-filled credentials from the existing account and — after answering "No" to "already configured. Keep it?" — overwrote the existing accounts.main credentials instead of writing the new account. That is silent configuration corruption of a working account.

Why This Change Was Made

Root cause: buildChannelSetupWizardAdapterFromSetupWizard selected an accountId but passed unscoped config to the plugin setup callbacks. Legacy accounts-schema callbacks that ignore accountId resolve credentials through defaultAccount, which still pointed at the existing account — so both the "already configured" inspection and the credential writes hit the wrong account.

The fix scopes the wizard run at the owning boundary (src/channels/plugins/setup-wizard.ts): before invoking plugin callbacks it promotes any legacy root-level credentials into the accounts map, points defaultAccount at the selected account for the duration of the callbacks (immutably — no shared-state mutation), and restores the operator's original defaultAccount on the returned config. An existing-but-empty accounts: {} map is treated as account-scoped too, so lingering root credentials are migrated rather than left stale. botId/secret were added to the generic single-account promotion keys. Telegram's adapter already patches account-aware and is unchanged.

User Impact

  • "Add a new account" no longer overwrites or pre-fills from the existing account; new credentials land only under the new account id.
  • Replacing credentials on a selected existing account touches only that account; other accounts stay byte-identical.
  • Mixed legacy shapes (root credentials with named or empty accounts maps) are migrated into the accounts map instead of leaving stale root secrets behind.
  • No config schema changes, no new flags.

Evidence

  • Regression suite src/channels/plugins/setup-wizard.test.ts (new, 6 tests): no-prefill/no-overwrite on add-new, mixed-root promotion, selected-account-only replacement, named default account, first named account, empty-accounts-map migration. All pass.
  • Sibling suites setup-helpers.test.ts + helpers.test.ts: 12 tests pass.
  • Autoreview (codex gpt-5.6-sol, xhigh): clean, "patch is correct (0.87)". An earlier autoreview pass surfaced the empty-accounts-map edge; it is fixed and covered by the regression suite.
  • git diff --check clean; branch rebased onto current origin/main.

@openclaw-barnacle openclaw-barnacle Bot added size: M maintainer Maintainer-authored PR labels Jul 18, 2026
@clawsweeper

clawsweeper Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

ClawSweeper status: review started.

I am starting a fresh review of this pull request: fix(channels): scope wizard credentials to the selected account This is item 1/1 in the current shard. Shard 0/1.

This placeholder means the worker is alive and reading the current context. I will edit this same comment with the actual review when the claws are done clicking.

Crustacean status: shell secured, claws on keyboard, evidence pebbles being sorted.

@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: 27f4c13617

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

}

return { cfg: next, accountId };
return { cfg: accountScope.restore(next), accountId };

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.

P1 Badge Preserve defaults written by top-level setup wizards

When a declarative wizard intentionally writes defaultAccount during setup, this unconditional restore deletes it if the field was absent before setup. Nostr provides a concrete regression: extensions/nostr/src/setup-adapter.ts:10-14 writes the selected non-default account, and extensions/nostr/src/channel.test.ts:335-347 expects an override of work to persist as defaultAccount; the new scope snapshots undefined, then restore removes the value written by the callback. As a result, Nostr setup with a named account loses its routing identity after returning, so restoration must distinguish its temporary assignment from a callback's intentional update or be limited to account-map plugins.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 18, 2026
@clawsweeper

clawsweeper Bot commented Jul 18, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 18, 2026, 5:44 PM ET / 21:44 UTC.

Summary
The PR scopes generic channel setup-wizard callbacks to the selected account, expands legacy single-account credential promotion, and adds multi-account wizard regression tests.

PR surface: Source +71, Tests +365. Total +436 across 3 files.

Reproducibility: yes. from source: configure Nostr with a named account such as work while no prior defaultAccount exists; its setup callback writes work, then the proposed restore removes that value. This review did not execute the wizard.

Review metrics: none identified.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦐 gold shrimp
Result: blocked until real behavior proof from a real setup is added.

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

Rank-up moves:

  • [P1] Preserve an adapter-written final defaultAccount and add the direct Nostr named-account regression.
  • [P1] Add redacted after-fix evidence from a real multi-account wizard run, including the resulting selected-account configuration.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR reports unit and sibling test results, but no redacted after-fix run of a real multi-account wizard setup; add terminal or configuration evidence that shows both the original and selected accounts after completion. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Risk before merge

  • [P1] The new callback scope can silently discard an intentional defaultAccount written during named-account setup, changing post-wizard routing identity for adapters such as Nostr.
  • [P1] The branch changes credential and account-selection behavior but supplies only test evidence; a redacted real multi-account wizard run is still needed before merge.

Maintainer options:

  1. Preserve callback-owned default selection (recommended)
    Adjust the scope restoration so an adapter that deliberately writes defaultAccount retains that final value, then add direct Nostr named-account regression coverage.

Next step before merge

  • [P1] A concrete code fix exists, but the protected maintainer label requires explicit maintainer handling rather than automated repair routing.

Security
Cleared: The patch does not add dependencies, execution paths, permissions, or secret exposure; the concern is configuration correctness rather than a security-boundary regression.

Review findings

  • [P1] Preserve a wizard-written default account — src/channels/plugins/setup-wizard.ts:84
Review details

Best possible solution:

Keep temporary callback scoping for legacy account-map plugins, but restore only the temporary default-account override without overwriting a callback’s explicit final defaultAccount; cover the Nostr named-account path and show a redacted real wizard result.

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

Yes, from source: configure Nostr with a named account such as work while no prior defaultAccount exists; its setup callback writes work, then the proposed restore removes that value. This review did not execute the wizard.

Is this the best way to solve the issue?

No. Temporary selected-account scoping is a reasonable boundary for the reported overwrite, but unconditional restoration is not the narrowest safe solution because it overwrites intentional callback output.

Full review comments:

  • [P1] Preserve a wizard-written default account — src/channels/plugins/setup-wizard.ts:84
    The new scope restore resets defaultAccount to its pre-wizard value even when the callback intentionally changed it. Nostr named-account setup writes the selected account as the default; when there was no previous value, this code deletes that result and leaves the configured account without its expected routing identity. Preserve callback-owned changes while removing only the temporary scope override.
    Confidence: 0.98

Overall correctness: patch is incorrect
Overall confidence: 0.98

AGENTS.md: found and applied where relevant.

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

Label changes

Label changes:

  • add P1: The patch can break a named channel-account setup flow by removing the selected account’s routing default after successful configuration.
  • add merge-risk: 🚨 compatibility: The shared wizard now rewrites and restores persisted channel defaultAccount behavior across legacy setup adapters.
  • add merge-risk: 🚨 auth-provider: The affected wizard path writes account-scoped channel credentials and can leave the configured account selection inconsistent after setup.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR reports unit and sibling test results, but no redacted after-fix run of a real multi-account wizard setup; add terminal or configuration evidence that shows both the original and selected accounts after completion. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.

Label justifications:

  • P1: The patch can break a named channel-account setup flow by removing the selected account’s routing default after successful configuration.
  • merge-risk: 🚨 compatibility: The shared wizard now rewrites and restores persisted channel defaultAccount behavior across legacy setup adapters.
  • merge-risk: 🚨 auth-provider: The affected wizard path writes account-scoped channel credentials and can leave the configured account selection inconsistent after setup.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR reports unit and sibling test results, but no redacted after-fix run of a real multi-account wizard setup; add terminal or configuration evidence that shows both the original and selected accounts after completion. After adding proof, update the PR body; ClawSweeper should re-review automatically. If it does not, the PR author or someone with repository write access can comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +71, Tests +365. Total +436 across 3 files.

View PR surface stats
Area Files Added Removed Net
Source 2 74 3 +71
Tests 1 365 0 +365
Docs 0 0 0 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 3 439 3 +436

What I checked:

  • Concrete prior review finding: The supplied review discussion identifies that the new restoration logic deletes a defaultAccount written by a declarative wizard when the original field was absent; this affects named-account Nostr setup rather than the credential-overwrite case being fixed. (src/channels/plugins/setup-wizard.ts:84, 2994450ebdd8)
  • Existing Nostr setup contract: The linked review evidence identifies Nostr’s setup adapter as intentionally setting the selected named account as defaultAccount, with an existing test expecting work to persist after setup. (extensions/nostr/src/setup-adapter.ts:10, fa9ae68c3423)
  • Linked bug remains the canonical user report: The PR explicitly targets the still-open report describing cross-account credential overwrite during add-account setup; the proposed branch is a candidate fix, not a reason to close that report before merge. (src/channels/plugins/setup-wizard.ts:1, 2994450ebdd8)
  • Real-behavior evidence gap: The PR body reports regression/unit suites and autoreview, but does not provide an after-fix run from a real multi-account wizard setup. (src/channels/plugins/setup-wizard.test.ts:1, 2994450ebdd8)

Likely related people:

  • steipete: The supplied commit history attributes the proposed shared wizard-scope implementation and its regression coverage to this contributor; broader current-main ownership could not be established from the available read-only inspection. (role: recent channel setup contributor; confidence: low; commits: 5e245442a733, 27f4c13617de, 2994450ebdd8; files: src/channels/plugins/setup-wizard.ts, src/channels/plugins/setup-wizard.test.ts, src/channels/plugins/setup-promotion-keys.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.

@steipete
steipete merged commit a21385a into main Jul 18, 2026
225 of 230 checks passed
@steipete
steipete deleted the fix/channels-add-account-overwrite branch July 18, 2026 22:21
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 19, 2026
…claw#110969)

* fix(channels): scope wizard credentials to selected account

* fix(channels): migrate empty accounts map in wizard scope guard

* test(channels): guard resolved account id in empty-map regression
zooqueen pushed a commit to zooqueen/openclaw that referenced this pull request Sep 11, 2026
…claw#110969)

* fix(channels): scope wizard credentials to selected account

* fix(channels): migrate empty accounts map in wizard scope guard

* test(channels): guard resolved account id in empty-map regression
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintainer Maintainer-authored PR merge-risk: 🚨 auth-provider 🚨 May break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. size: M status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Wizard cross-overwrites credentials in multi-account plugins when "Add a new account" is selected

1 participant