Skip to content

fix: persist RPC download secret across client restarts#189

Merged
AmintaCCCP merged 1 commit into
mainfrom
fix/rpc-secret-persistence
Jun 2, 2026
Merged

fix: persist RPC download secret across client restarts#189
AmintaCCCP merged 1 commit into
mainfrom
fix/rpc-secret-persistence

Conversation

@AmintaCCCP

@AmintaCCCP AmintaCCCP commented Jun 2, 2026

Copy link
Copy Markdown
Owner

Problem

Settings → Network → Remote Download 中的密钥(aria2 --rpc-secret)在重启客户端后消失。

根因: Zustand store 的 partialize 明确排除了 secret 字段,mergePersistedState 也未恢复它,导致密钥仅存在于内存中,重启即丢失。

Fix

secret 纳入 Zustand 持久化(IndexedDB),确保重启后恢复:

  • useAppStore.tspartialize 包含 secretmergePersistedState 恢复 secret
  • NetworkPanel.tsxhasStoredSecret 从持久化的 secret 初始化

各模式验证

模式 修复前 修复后
单客户端 ❌ 密钥丢失 ✅ 持久化到 IndexedDB
客户端+后端 ✅ 后端存储 ✅ 后端+本地双份
Web 端 ❌ 密钥丢失 ✅ 持久化到 IndexedDB
Web+后端 ✅ 后端存储 ✅ 后端+本地双份

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • RPC download secrets now persist across app restarts instead of resetting.
    • Fixed initialization of the RPC secret input UI to correctly display whether a secret has been previously stored.

The RPC download secret (aria2 --rpc-secret) was excluded from Zustand
persistence, causing it to disappear after every client restart in
client-only and web-only modes.

- Include secret in Zustand partialize to persist to IndexedDB
- Restore secret in mergePersistedState hydration logic
- Initialize hasStoredSecret from persisted secret on mount

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR updates the RPC download secret handling to persist across application restarts. The store now includes secret in its persisted state, and the NetworkPanel UI initializes its stored-secret indicator from the restored value instead of always starting false.

Changes

RPC Secret Persistence

Layer / File(s) Summary
Store persistence and hydration
src/store/useAppStore.ts
During state hydration, rpcDownloadConfig.secret is restored from persisted storage. In Zustand partialize, secret is now included in the persisted rpcDownloadConfig object alongside enabled, host, and port.
UI initialization from persisted state
src/components/settings/NetworkPanel.tsx
hasStoredSecret initial state now reflects whether rpcDownloadConfig.secret is present, instead of always starting as false.

Possibly related PRs

  • AmintaCCCP/GithubStarsManager#186: Originally implemented the RPC download feature including rpcDownloadConfig and NetworkPanel UI; this PR now persists the secret field that was previously memory-only.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A rabbit hops with glee so bright, ✨
The secret's saved through day and night,
No more lost when the app restarts—
Persistence wins all hearts! 🐰💾

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: persist RPC download secret across client restarts' directly and concisely describes the main change: persisting the RPC secret to survive restarts, which is confirmed by both file summaries and PR objectives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/rpc-secret-persistence

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 and usage tips.

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

🧹 Nitpick comments (1)
src/store/useAppStore.ts (1)

558-570: ⚡ Quick win

Add a round-trip regression test for rpcDownloadConfig.secret.

This fix depends on both normalization and partialize staying in sync. A small store test that persists and rehydrates rpcDownloadConfig.secret would make the web/local-only restart path much harder to regress again.

Also applies to: 1542-1547

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/store/useAppStore.ts` around lines 558 - 570, Add a round-trip regression
test that verifies rpcDownloadConfig.secret is persisted and rehydrated
unchanged: create a test that sets useAppStore().rpcDownloadConfig.secret to a
non-empty string, forces the store to persist (or serializes via the same
persistence/partialize logic used in the app), then rehydrate/deserialize into a
fresh store instance and assert the secret value matches; ensure the test covers
both normalization logic in the rpcDownloadConfig initializer (the object
returned in the IIFE) and the persistence partialize/rehydration path so future
changes to rpcDownloadConfig or partialize (also present in the other
occurrence) will break the test if they diverge.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/store/useAppStore.ts`:
- Around line 558-570: Add a round-trip regression test that verifies
rpcDownloadConfig.secret is persisted and rehydrated unchanged: create a test
that sets useAppStore().rpcDownloadConfig.secret to a non-empty string, forces
the store to persist (or serializes via the same persistence/partialize logic
used in the app), then rehydrate/deserialize into a fresh store instance and
assert the secret value matches; ensure the test covers both normalization logic
in the rpcDownloadConfig initializer (the object returned in the IIFE) and the
persistence partialize/rehydration path so future changes to rpcDownloadConfig
or partialize (also present in the other occurrence) will break the test if they
diverge.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: ff11ed5a-5d58-4e5c-8d21-f2aaba6783b8

📥 Commits

Reviewing files that changed from the base of the PR and between deb2848 and 9bc6a69.

📒 Files selected for processing (2)
  • src/components/settings/NetworkPanel.tsx
  • src/store/useAppStore.ts

@AmintaCCCP AmintaCCCP merged commit a6f7677 into main Jun 2, 2026
5 checks passed
@AmintaCCCP AmintaCCCP deleted the fix/rpc-secret-persistence branch June 2, 2026 09:14
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