Skip to content

fix: save download settings changed over the REST API - #644

Merged
linroid merged 2 commits into
mainfrom
fix/persist-remote-download-config
Oct 24, 2026
Merged

linroid merged 2 commits into
mainfrom
fix/persist-remote-download-config

Conversation

@linroid

@linroid linroid commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Summary

PUT /api/config only applied a change in memory: ketch server never wrote its config.toml, and a desktop or Android app sharing its engine never saved a phone's change to its own config.toml or its Settings. Download and Speed settings changed from another device were lost on that device's restart, and the apps said "Saved on X until it restarts".

  • Server: KetchServer(onConfigChanged = …). PUT /api/config runs one request at a time and calls the hook once DestinationGuard and updateConfig accepted the body; a failed save answers 500 config_not_saved (the change still applies until a restart). Servers with the hook add config.persisted (KetchFeatures.CONFIG_PERSISTED, not in ALL) to /api/status.
  • ketch server: ServerConfigFile saves to [download] of the --config file, else the default one (created when missing, e.g. Docker's /config/config.toml). Only the fields a change sets to a new value are written over what the file holds then, so values from flags, KETCH_* variables and defaults stay out of it and hand edits are kept. A field a flag or variable sets is saved too, with a warning, since that flag or variable wins at the next start. An unreadable file is never overwritten; the next change retries the failed fields.
  • Apps: local servers get a LocalServerContext whose onConfigChanged is InstanceManager.sharedConfigChanged (the desktop's LocalApiServer too, for ketch mcp and friends). AppState registers a handler that runs InstanceSettingsController.acceptShared: saved through AppSettingsController.saveDownload with savedSpeedLimit, so a Slow lane never becomes the standing cap, and shown on the Settings page, unless an edit made there was accepted since. Without a handler (app UI closed), the manager saves [download] straight to the store.
  • UI: the Downloads and Speed pages of a device listing config.persisted say "Saved on X." (translated); older servers keep "until it restarts". The Network page's "Resets when X restarts" stays, as interface selection is runtime-only by design.
  • Docs: AGENTS.md (Live Configuration, Daemon Server, ketch server), cli/README.md (new "Settings clients change"), Docker (en, zh-CN), API and developer docs.

Note: saving rewrites config.toml through FileConfigStore, so comments from --generate-config are dropped on the first save, as the apps already do.

Snapshots (remote NAS device)

Before After
before downloads after downloads
before speed after speed

Testing

  • :library:server:test: hook called with what the instance applied, not called when updateConfig or DestinationGuard rejects, config_not_saved keeps the change applied, config.persisted only with a hook
  • :cli:test: ServerConfigFileTest (changed field only, other sections, hooks and Windows backslashes kept; missing file created without env values; edits kept; unreadable file left alone and retried; pinned field names)
  • :app:shared:jvmTest (all), :app:desktop:test, :app:shared:compileTestKotlinIosSimulatorArm64, :app:shared:compileKotlinWasmJs, :app:android:compileDirectDebugKotlin, :library:api:updateKotlinAbi

PUT /api/config only applied a change in memory, so settings a phone changed
on a `ketch server` or on a desktop or Android app sharing its engine were
lost when that device restarted, and the apps said "until it restarts".

KetchServer takes an onConfigChanged hook, which PUT /api/config calls, one
request at a time, once DestinationGuard and updateConfig accepted the body;
a failed save answers 500 config_not_saved. Servers with the hook list
config.persisted (KetchFeatures.CONFIG_PERSISTED).

- ketch server saves the [download] fields a change sets over what its
  config.toml holds (ServerConfigFile), creating the file when missing, so
  values from flags, KETCH_* variables and defaults stay out of it; fields
  those set are saved with a warning, as they win at the next start.
- The apps' shared servers and the desktop's LocalApiServer save through
  InstanceManager.sharedConfigChanged, which hands the change to the app's
  settings (InstanceSettingsController.acceptShared): saved with the
  standing speed cap, never a Slow lane, and shown on the Settings page.
- The Downloads and Speed pages of a device listing config.persisted say
  its changes are saved there; older servers keep the old notice.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review 🔄 Running since 2026-10-24T02:57:09.932503Z 99ac0ea PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@claude

claude Bot commented Oct 24, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

Temporary folders are in /tmp on Linux, which createTestServer allows, so the
folder the test expected the server to refuse was allowed there.
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

 2 213 files  + 5   2 241 suites  +5   57m 39s ⏱️ -22s
15 457 tests +27  15 189 ✅ +27  268 💤 ±0  0 ❌ ±0 
18 824 runs  +27  18 556 ✅ +27  268 💤 ±0  0 ❌ ±0 

Results for commit 30e6122. ± Comparison against base commit 18d1de8.

This pull request removes 1 and adds 28 tests. Note that renamed tests count towards both.
com.linroid.ketch.app.snapshot.SettingsDeviceSnapshots ‑ remote_devicePages_saveOnTheDeviceUntilItRestarts[jvm]
com.linroid.ketch.app.InstanceSettingsControllerTest ‑ acceptShared_editTheInstanceTookMeanwhile_keepsTheEdit[jvm]
com.linroid.ketch.app.InstanceSettingsControllerTest ‑ acceptShared_savesTheStandingCapAndShowsTheSettings[jvm]
com.linroid.ketch.app.desktop.LocalApiServerTest ‑ connect_startsTheServerWithTheSaveHookTheEngineCameWith
com.linroid.ketch.app.snapshot.SettingsDeviceSnapshots ‑ remote_devicePages_saveOnTheDevice[jvm]
com.linroid.ketch.app.state.AppStateSharedConfigTest ‑ clientChange_isSavedAndShownOnTheDevicePage[jvm]
com.linroid.ketch.app.state.AppStateSharedConfigTest ‑ clientChange_withoutTheApp_isSavedAsItIs[jvm]
com.linroid.ketch.app.ui.settings.RemoteSettingsNoticesTest ‑ downloadsRemoteNotice_olderOrUnreportedServer_saysUntilItRestarts[jvm]
com.linroid.ketch.app.ui.settings.RemoteSettingsNoticesTest ‑ downloadsRemoteNotice_serverSaves_saysSaved[jvm]
com.linroid.ketch.app.ui.settings.RemoteSettingsNoticesTest ‑ speedRemoteNotice_followsWhetherTheServerSaves[jvm]
com.linroid.ketch.cli.ServerConfigFileTest ‑ pinnedDownloadFields_flagsWinAndBlankVariablesDoNotCount
…
This pull request removes 1 skipped test and adds 1 skipped test. Note that renamed tests count towards both.
com.linroid.ketch.app.snapshot.SettingsDeviceSnapshots ‑ remote_devicePages_saveOnTheDeviceUntilItRestarts[jvm]
com.linroid.ketch.app.snapshot.SettingsDeviceSnapshots ‑ remote_devicePages_saveOnTheDevice[jvm]

@linroid
linroid merged commit ed5ab31 into main Oct 24, 2026
14 checks passed
@linroid
linroid deleted the fix/persist-remote-download-config branch October 24, 2026 06:58
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