Skip to content

feat: give each device a stable identity - #648

Merged
linroid merged 2 commits into
mainfrom
feat/device-identity
Oct 24, 2026
Merged

linroid merged 2 commits into
mainfrom
feat/device-identity

Conversation

@linroid

@linroid linroid commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Part of #422: a device directory on a public server needs to tell devices apart, hide the device itself and recognize devices already added, and Ketch devices had no identity (the apps key them by host and port). This builds only that identity, as designed in multi-instance-downloads §7.1 (task transfer's F7). Pairings, the mDNS boot value and device hues by id are out of scope.

What changes

  • device.json: DeviceStore (config) generates a random UUID on first start and keeps it in device.json beside the task database, created owner-only (rw-------) as a temp file moved into place, like SingleInstance's files. A missing or unreadable file (bad JSON, no or invalid id) is replaced; unknown fields, such as later pairings, are kept. It never goes in config.toml.
  • Where: the config directory on the JVM (defaultDevicePath()), so the desktop app, ketch server and ketch mcp --standalone report one id. Each reads it under the downloads lock. Android keeps it in filesDir, excluded in backup_rules.xml and data_extraction_rules.xml. iOS keeps it in Application Support with isExcludedFromBackup. So a restored phone gets an id of its own.
  • API: KetchStatus.instanceId: String? = null (additive; ABI dump updated) and Ketch(instanceId = ...). RemoteKetch passes it through /api/status, and older servers decode as null.
  • Apps: InstanceFactory.instanceId, also set when another process runs the downloads. RemoteConfig.instanceId is learned on connect in InstanceManager.learnStatus, as os is, and saved. DeviceConnector refuses a device whose probed status reports this device's id (ConnectOutcome.ThisDevice → ConnectProblem.ThisDevice), with the new string translated into every app language.
  • Docs: AGENTS.md (new Device identity section, plus KetchStatus, config, server/CLI and logging tag), docs/api.md and the Docker /config listing.

UI

The Add device form, after typing this device's own shared server by its LAN address. This is a new state: before, the app added its own server as a second device.

Desktop (light) Desktop (dark) Phone

Tests

  • DeviceStoreTest: the id is created once with owner-only permissions and reused; a missing folder is created; empty, malformed or invalid-id files are replaced; a later version's fields are kept; an id that can't be saved is still returned.
  • RemoteConfigTest (old configs decode with no id, ids round-trip), ServerRoutesTest.status_reportsTheEnginesInstanceId, RemoteKetchTest.status_serverOlderThanIdentities_reportsNoInstanceId.
  • DeviceConnectorTest and ConnectFormTest: self-add refused, other ids saved, apps without an id unaffected. InstanceManagerKeepAliveTest: the id is learned and saved, and kept when a device reports none.
  • Passed: :config:jvmTest, :library:core:jvmTest, :library:server:test, :library:remote:jvmTest --tests '*RemoteKetchTest*', :app:shared:jvmTest, :library:api:checkKotlinAbi, compileTestKotlinIosSimulatorArm64 for config, api, core, remote and app:shared, :app:android:compileDirectDebugKotlin, :cli:compileKotlin, :app:desktop:compileKotlin.

Ketch devices had no identity: the apps keyed them by host and port, and
nothing told a device's own server apart from another one. Each device
now generates a random UUID on its first start and keeps it in
device.json beside its task database (owner-only, written to a temp file
and moved into place). The desktop app, ketch server and
ketch mcp --standalone share the config directory and so one id; each
reads it under the downloads lock. Android keeps it in filesDir, left out
of backups and device transfers, and iOS sets isExcludedFromBackup, so a
restored phone gets an id of its own. It never goes in config.toml.

- config: DeviceStore (missing or unreadable files are replaced, unknown
  fields kept), defaultDevicePath(), RemoteConfig.instanceId
- api/core: KetchStatus.instanceId (null from older servers) and
  Ketch(instanceId = ...); RemoteKetch passes it through /api/status
- apps: InstanceFactory.instanceId, RemoteConfig.instanceId learned on
  connect and saved, and the Add device form refuses a device reporting
  this device's id ("<address> is this device")
@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-24T07:21:53.027353Z 8e5afee 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.

# Conflicts:
#	AGENTS.md
#	app/android/src/main/kotlin/com/linroid/ketch/app/android/KetchService.kt
#	app/desktop/src/main/kotlin/com/linroid/ketch/app/desktop/main.kt
#	app/shared/src/commonTest/kotlin/com/linroid/ketch/app/FakeInstanceFactory.kt
#	app/shared/src/iosMain/kotlin/com/linroid/ketch/app/MainViewController.kt
#	cli/src/main/kotlin/com/linroid/ketch/cli/Main.kt
#	library/core/src/commonMain/kotlin/com/linroid/ketch/core/Ketch.kt
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

 2 234 files  + 1   2 262 suites  +1   58m 7s ⏱️ + 2m 38s
15 633 tests +22  15 361 ✅ +21  272 💤 +1  0 ❌ ±0 
19 012 runs  +22  18 740 ✅ +21  272 💤 +1  0 ❌ ±0 

Results for commit 5b512ce. ± Comparison against base commit 3d1cf0f.

This pull request removes 4 and adds 26 tests. Note that renamed tests count towards both.
com.linroid.ketch.config.RemoteConfigTest ‑ decode_remoteSavedBeforeNamesWatchingAndSystems_isUnnamedWatchedAndUnknown[jvm]
com.linroid.ketch.config.RemoteConfigTest ‑ encode_namedUnwatchedRemote_readsBackTheSame[jvm]
iosSimulatorArm64Test.com.linroid.ketch.config.RemoteConfigTest ‑ decode_remoteSavedBeforeNamesWatchingAndSystems_isUnnamedWatchedAndUnknown[iosSimulatorArm64]
iosSimulatorArm64Test.com.linroid.ketch.config.RemoteConfigTest ‑ encode_namedUnwatchedRemote_readsBackTheSame[iosSimulatorArm64]
com.linroid.ketch.app.instance.InstanceManagerKeepAliveTest ‑ connect_deviceReportingItsIdentity_savesIt[jvm]
com.linroid.ketch.app.instance.InstanceManagerKeepAliveTest ‑ connect_deviceReportingNoIdentity_keepsTheOneSaved[jvm]
com.linroid.ketch.app.snapshot.ConnectSnapshots ‑ addDevice_ownSharedServer_saysItIsThisDevice[jvm]
com.linroid.ketch.app.ui.connect.ConnectFormTest ‑ connect_ownSharedServer_keepsTheFormSayingItIsThisDevice[jvm]
com.linroid.ketch.app.ui.connect.DeviceConnectorTest ‑ connect_appWithoutIdentity_addsADeviceWhateverItReports[jvm]
com.linroid.ketch.app.ui.connect.DeviceConnectorTest ‑ connect_deviceReportingAnotherIdentity_addsItWithThatIdentity[jvm]
com.linroid.ketch.app.ui.connect.DeviceConnectorTest ‑ connect_deviceReportingThisDevicesIdentity_addsNothing[jvm]
com.linroid.ketch.config.DeviceStoreTest ‑ instanceId_cannotBeSaved_returnsANewIdEachTime[jvm]
com.linroid.ketch.config.DeviceStoreTest ‑ instanceId_fileOfLaterVersion_keepsItsIdAndFields[jvm]
com.linroid.ketch.config.DeviceStoreTest ‑ instanceId_missingDirectory_createsIt[jvm]
…

@linroid
linroid merged commit 00e5ee2 into main Oct 24, 2026
14 checks passed
@linroid
linroid deleted the feat/device-identity branch October 24, 2026 08:19
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