Skip to content

fix(zcode): keep Coding Plan credentials and quota tied to the selected account - #24674

Merged
nwparker merged 5 commits into
mainfrom
nwparker/zcode-v2-credentials-1002
Oct 10, 2026
Merged

nwparker merged 5 commits into
mainfrom
nwparker/zcode-v2-credentials-1002

Conversation

@nwparker

@nwparker nwparker commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

ELI5

Orca recognizes the Coding Plan selected in ZCode’s current credential store and keeps displayed quota tied to that account.

What Changed

Read the selected Z.AI or BigModel v2 account without modifying any CLI files. An Orca-saved quota key keeps priority. Broken or unsupported v2 selections cannot fall back to an unrelated legacy account. Recheck credential identity after requests and after other providers finish, so account changes cannot display an old account’s result.

Sign-in controls have been split into a separate PR. Credential writing and rollback remain in the original-author #24964; this PR adds no credential publication or deletion mechanism.

Why

Legacy discovery missed migrated credentials, and cached quota could outlive its account. A bounded, read-only adapter extends the existing quota service without reproducing authentication or altering the CLI’s credential store.

Linked Issue

Includes the separately reviewable lint prerequisite #27326. Merge that first; its identical cleanup is composed here so the final head can pass required checks.

Refs #8476. This covers account discovery and quota, with authentication and model selection owned by the CLI.

Credit: Luchong / @parkavenue9639 (#24618 and #24964) and GuanBear (#23520). Verified coauthor credit is retained. The original author’s safety commits remain in #24964, which should be reviewed and merged separately.

Visual Proof

Synthetic credentials, disposable profiles, hidden Electron renderers, and a stubbed quota endpoint. No personal login or paid request.

Before on main 8452fc33153, the same v2 account is not recognized:

Before

After on the reduced read-only branch:

Selected account

A saved Orca key retains priority:

Saved key priority

Testing

  • Inspected fresh hidden Accounts captures.
  • Automated regression tests added and run.

108 focused tests passed, plus an added read-only contract that repeats discovery 25 times and confirms all encrypted source files and bytes stay unchanged. Coverage includes encrypted/plaintext formats, root overrides, unsupported accounts, in-flight account switches, saved-key priority, bounded regular-file reads, and test-profile isolation.

A separate four-case compatibility probe generated fixtures with the production CLI cipher: both plan sites, custom and fallback secrets, and account identities containing spaces, URI characters, and Unicode. All decoded correctly; source bytes were unchanged; zero provider requests.

pnpm tc, changed-code quality, normal commit hooks, the Electron build, and the reduced hidden Accounts regression pass on macOS arm64. The new read-only credential/account contract matrix passes on macOS, Linux, and Windows at final head 9b24926d1b9b. Platform verification. Broader hosted checks are still running; previous combined-head checks are not claimed as proof of this head. All four proposed PRs also merge without conflicts; the composed result passes 360 focused tests including the lint prerequisite, typecheck, quality, and all three rebuilt hidden Electron flows.

Review

Existing execution-host ownership, saved-key storage, known HTTPS quota endpoints, folder workspaces, and mixed-version wire compatibility remain intact. No new required remote field, stream opcode, authentication flow, or agent-status store.

Agent skill upstream boundary

  • Not applicable; no upstream skill-installer material copied.

Notes

Risk reduction: read-only discovery and quota ownership are isolated from sign-in UI and credential publication. Low merge risk once this head’s hosted checks pass. Real provider authentication, native WSL/SSH sessions, and custom provider formats have not been exercised; unsupported formats fail closed.

Checklist

  • Small, focused read-only change.
  • Before/after, mechanism, and reuse explained.
  • Visual proof attached.
  • Correctness, security, and bounded reads reviewed.
  • Cross-platform, SSH, folder, and backward compatibility considered.
  • Local typecheck, focused tests, quality, and build pass; CI covers broader checks.

@nwparker
nwparker marked this pull request as ready for review October 2, 2026 11:49
@nwparker
nwparker requested a review from brennanb2025 as a code owner October 2, 2026 11:49

@pullfrog pullfrog 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.

✅ No new issues found.

Reviewed changes

Re-reviewed the delta from e22d5a5 to f5ead0e — the hosted-CI fixture repair. Both touched files are test-only; no production code changed.

  • Added a zcodePlanCredentials.getStatus stub to the AccountsPane lifetime fixture returning { apiKeyConfigured: false, zcodeCliConfigured: false, apiKeyProtection: null }, which matches ZcodePlanCredentialsStatus in src/shared/zcode-plan-sites.ts:27.
  • Added 'zcodePlanCredentials' to the expected web preload API inventory, in the exact position production composes it (src/renderer/src/web/web-preload-api.ts:111).

The substantive adapter, renderer setup section, i18n and fixtures are unchanged since the prior reviewed head (e22d5a5a05).

Pullfrog  | View workflow run | Using deepseek-v4.1-flash (free via Pullfrog for OSS) | 𝕏

@nwparker
nwparker changed the base branch from nwparker/glm-plan-accounts-1002 to main October 3, 2026 04:25
@coderabbitai

coderabbitai Bot commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough
📝 Walkthrough

Walkthrough

The changes add GLM Coding Plan credential discovery for Z.AI and BigModel, secure desktop key storage, and IPC operations to read, save, and clear credentials. Rate-limit refresh now uses plan or Zcode CLI credentials and discards results that no longer match the active credentials. Accounts settings display plan usage and provide credential and CLI setup controls. Web settings scope the plan site to the active environment. The changes also update macOS Electron test-environment isolation.




































































Priority: ➖ Normal

Merge Risk: 🟡 Moderate · up to bb346

A failed key replacement can leave the new credential readable by others with disk access. Remove the failed plaintext replacement before merging.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to bb346

Selected-account validation and restricted request destinations limit exposure. However, a rejected plaintext key replacement can leave the attempted credential on disk if permission enforcement and restoration fail. The risk is conditional on the device configuration and filesystem access, rather than an established remote attack.

Retained concerns

  • Medium · security · inferred: The restricted-plaintext save transition is not failure-atomic. The writer renames the attempted credential into place even when staged restriction fails. If replacing an existing envelope and restoration then throws before its rename, the store catches that exception and rejects the save without removing the newly published plaintext. On a Windows filesystem with permissive inherited access and unsuccessful ACL enforcement, another permitted principal could read that key despite the reported save failure. Encryption and ordinary successful restoration limit this conditional exposure.
Security review details

Security Blast Radius

  • inferred — The identified storage exposure concerns one execution user's saved Coding Plan key. Exploitation requires access permitted by the affected filesystem and failed restriction enforcement; downstream authority is bounded by that key's provider permissions, which were not enumerated. No cross-tenant or fleet-wide reachability was established.

Security Findings and Attack Paths

  • inferred — The static failure path is plaintext replacement, unsuccessful restriction, publication, then failed restoration before replacement of the published file. A principal with inherited read access could recover the attempted key. This is an inferred architecture concern, not a demonstrated exploit or a promotion of the deferred verification candidate. Tests cover ordinary removal and successful restoration.

Trust Boundaries and Controls

  • observed — Credential path overrides come from the execution process's environment, not from the shown desktop save API. The IPC handlers validate key content but do not themselves inspect sender identity. Browser tests assert rejected key mutation and host-owned site behavior; those tests alone do not establish complete production caller authorization.

Resilience and Maintainability Implications

  • observed — The macOS E2E isolation helper forces login-shell disabling and prevents launch overlays from replacing that setting. The existing shell wrapper honors disabling by using the direct shell path. The available base comparison changes the test helper, not the production wrapper.

Hardening Proposals

  • proposed — Make plaintext persistence fail closed before publication: require confirmed staged restriction before rename and define cleanup or recovery that preserves the invariant across restoration failure and interruption. Failure-injection coverage should distinguish a rejected save from a successfully restored prior credential.





















Pre-merge checks | Passed 4 | Inconclusive 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 7.58% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 66 functions across 50 files. (25 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Title check Passed The title clearly summarizes the main change: keeping Coding Plan credentials and quota associated with the selected account.
Description check Passed The description includes all required sections, explains the user-facing change and rationale, identifies linked issues, provides visual proof, documents testing and platform coverage, and completes t…

Full details: Docstring Coverage

Explanation

Docstring coverage is 7.58% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 66 functions across 50 files. (25 skipped: 12 unsupported, 13 over the file limit.)


✨ Finishing Touches 💡 2
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR












⚔️ Resolve merge conflicts 💡
  • Resolve merge conflict in branch nwparker/zcode-v2-credentials-1002























  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c56c86c8-8803-4e1a-b4fa-1341cda1ef69
📥 Commits

Reviewing files that changed from the base of the PR and between b032867 and bb34682.

📒 Files selected for processing (75)
  • src/main/ipc/register-core-handlers/register-core-handlers.test.ts
  • src/main/ipc/register-core-handlers/register-core-handlers.ts
  • src/main/ipc/zcode-plan-credentials.test.ts
  • src/main/ipc/zcode-plan-credentials.ts
  • src/main/rate-limits/service-zcode-usage.test.ts
  • src/main/rate-limits/service/service-account-refresh.ts
  • src/main/rate-limits/service/service-configuration.ts
  • src/main/rate-limits/service/service-fetch-policy.ts
  • src/main/rate-limits/service/service-fetch-targets.ts
  • src/main/rate-limits/service/service-full-cycle-application.ts
  • src/main/rate-limits/service/service-full-cycle-preparation.ts
  • src/main/rate-limits/service/service-state.ts
  • src/main/rate-limits/service/service-types.ts
  • src/main/rate-limits/zcode-usage-credentials.ts
  • src/main/rate-limits/zcode-usage-fetcher.test.ts
  • src/main/rate-limits/zcode-usage-fetcher.ts
  • src/main/runtime/runtime-client-settings.ts
  • src/main/runtime/runtime-store-contract.ts
  • src/main/startup/main-process-account-services.ts
  • src/main/zcode/fixtures/v2-upstream/bigmodel/credentials.json
  • src/main/zcode/fixtures/v2-upstream/bigmodel/provider_config.json
  • src/main/zcode/fixtures/v2-upstream/fallback-host/credentials.json
  • src/main/zcode/fixtures/v2-upstream/fallback-host/provider_config.json
  • src/main/zcode/fixtures/v2-upstream/provenance.json
  • src/main/zcode/fixtures/v2-upstream/zai-other/credentials.json
  • src/main/zcode/fixtures/v2-upstream/zai-other/provider_config.json
  • src/main/zcode/fixtures/v2-upstream/zai/credentials.json
  • src/main/zcode/fixtures/v2-upstream/zai/provider_config.json
  • src/main/zcode/zcode-plan-api-key-store.test.ts
  • src/main/zcode/zcode-plan-api-key-store.ts
  • src/main/zcode/zcode-v2-personal-overlay-raw-json.test.ts
  • src/main/zcode/zcode-v2-personal-overlay.ts
  • src/main/zcode/zcode-v2-plan-credentials.test.ts
  • src/main/zcode/zcode-v2-plan-credentials.ts
  • src/preload/api-types.ts
  • src/preload/api/agent-account-api.ts
  • src/preload/api/zcode-plan-credentials-bridge.ts
  • src/preload/index.ts
  • src/renderer/src/components/settings/AccountsPane.section-lifetime.test.tsx
  • src/renderer/src/components/settings/AccountsPane.tsx
  • src/renderer/src/components/settings/ZcodeCliSetupSection.test.tsx
  • src/renderer/src/components/settings/ZcodeCliSetupSection.tsx
  • src/renderer/src/components/settings/ZcodePlanAccountsSection.test.tsx
  • src/renderer/src/components/settings/ZcodePlanAccountsSection.tsx
  • src/renderer/src/components/settings/accounts-search.test.ts
  • src/renderer/src/components/settings/accounts-search.ts
  • src/renderer/src/components/settings/use-zcode-plan-credentials.test.tsx
  • src/renderer/src/components/settings/use-zcode-plan-credentials.ts
  • src/renderer/src/components/settings/zcode-plan-usage-windows.tsx
  • src/renderer/src/components/status-bar/status-bar-provider-visibility.test.ts
  • src/renderer/src/components/status-bar/status-bar-provider-visibility.ts
  • src/renderer/src/components/status-bar/usage-provider-settings-target.test.ts
  • src/renderer/src/components/status-bar/usage-provider-settings-target.ts
  • src/renderer/src/components/status-bar/use-status-bar-controller.ts
  • src/renderer/src/i18n/en-runtime-required.json
  • src/renderer/src/i18n/locales/en.json
  • src/renderer/src/i18n/locales/zh.json
  • src/renderer/src/web/preload-api/web-agent-accounts-api.ts
  • src/renderer/src/web/preload-api/web-preferences-store.ts
  • src/renderer/src/web/preload-api/web-runtime-session.ts
  • src/renderer/src/web/preload-api/web-zcode-plan-site.ts
  • src/renderer/src/web/web-preload-api-composition.test.ts
  • src/renderer/src/web/web-preload-api.ts
  • src/renderer/src/web/web-zcode-plan-settings.test.ts
  • src/shared/default-global-settings.ts
  • src/shared/global-settings-types.ts
  • src/shared/node-bounded-file-reader-sync.test.ts
  • src/shared/node-bounded-file-reader.ts
  • src/shared/orca-workspace-layout.ts
  • src/shared/rate-limit-state-factory.ts
  • src/shared/rate-limit-types.ts
  • src/shared/rpc-contract/client-settings-params.ts
  • src/shared/zcode-plan-sites.ts
  • tests/e2e/helpers/electron-home-isolation.ts
  • tests/e2e/helpers/electron-home-isolation.unit.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

@nwparker
nwparker marked this pull request as draft October 4, 2026 06:57
@nwparker nwparker changed the title fix(zcode): recognize the selected v2 Coding Plan credentials fix(zcode): keep Coding Plan credentials and quota tied to the selected account Oct 4, 2026
@nwparker
nwparker marked this pull request as ready for review October 10, 2026 05:06
@nwparker

Copy link
Copy Markdown
Contributor Author

Final reviewed head: 7ffac6535aed101b3fee2689b4de415086fa14a8.

Recommend merge after #24964. All hosted PR Checks now pass, including all five Node test shards, Linux Electron Accounts regression, relay integration, and both packaging jobs. Local verification adds 209 focused tests, typecheck, changed-code quality, and rendered macOS proof. No provider authentication or paid quota request was performed; the remaining platform/authentication limits are in the body.

This branch includes the original #24964 author's commits, so that safety fix can merge in its original PR first. The quota/account feature remains focused on the existing provider rather than a second GLM store or status-bar entry.

Co-authored-by: Luchong <lu740528977@gmail.com>
Co-authored-by: GuanBear <guanbear@users.noreply.github.com>
@nwparker
nwparker force-pushed the nwparker/zcode-v2-credentials-1002 branch from 7ffac65 to 3f0e8a9 Compare October 10, 2026 22:18
@nwparker nwparker added the enhancement New feature or request label Oct 10, 2026
@nwparker nwparker removed the enhancement New feature or request label Oct 10, 2026
@nwparker
nwparker merged commit 7dfcef4 into main Oct 10, 2026
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant