fix: stable device fingerprint so prune finds old sessions - #340
Merged
Merged
Conversation
macOS os.Hostname follows the DHCP name, so the device id changed across network leases. darwin now hashes scutil's LocalHostName. A failed or empty lookup falls back to os.Hostname with one trailing .local removed. Other platforms still use os.Hostname with that same trim, so an existing stable hostname keeps its id. Fingerprint is unchanged.
RebindDevicesByMachineID, in one transaction, moves sessions onto the canonical device from every other devices row with the same non-empty machine_id, then deletes those rows. sessions.device_id is the only local column that references devices.id. An empty machine id matches nothing, and a second call moves nothing.
sync and prune share bindLocalDevice. It upserts the current fingerprint, moves seed local sessions onto it, then collapses stale device rows for this machine. prune does this before listing candidates, so sessions still filed under an older fingerprint are visible without a separate sync.
concepts.md states the hostname and machine-id inputs of the device fingerprint. store.md and cli.md describe RebindDevicesByMachineID beside the seed-id rebind. Canonical session rows record DeviceID as device.IDOnce.
CountOldUnconfirmed counts unpruned sessions on a device whose last activity is before the cutoff and whose pushed_hash is NULL or differs from raw_hash. ListPruneCandidates is unchanged. Addresses R1-01.
SetResolveForTest replaces the cached fingerprint and restores the previous resolver afterwards, in the same style as the resolve override. Addresses R1-03.
When no candidate is confirmed, prune counts older sessions whose pushed_hash is missing or stale and names prosa sync. The --json summary records that count as unconfirmed. Addresses R1-01. The stale-device dry-run pins its machine id through SetResolveForTest. Addresses R1-03.
prune lists sessions a prior sync confirmed. When older sessions still lack that confirmation, the command reports the count. Addresses R1-01.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
prosa prunereported nothing to prune on machines whose macOS hostname changes with the network lease.scutil --get LocalHostName, falling back toos.Hostname()without.local. Linux is unchanged and ids computed from a stable hostname stay the same.devicesrow sharing the canonical device'smachine_idinto it, reassigning sessions and dropping the stale rows.syncandprunebind the local device (upsert plus both rebinds) before any device-scoped read.prunesays so and points toprosa sync; the--jsonsummary carries anunconfirmedcount.Out of scope, tracked separately: the server's push idempotency keys on session id and hash, so an unchanged session does not move to a new server device after a re-login.
Test plan
go build,go vet,gofumpt,go test -race -count=1 ./...,golangci-lint🤖 Generated with Claude Code