Repository navigation
Deepen listening-sync policy into the core (and let it own device_id) - #19
Merged
Merged
Conversation
2026-09-27T14:05:34Z, host tracewake. Uncommitted work at the time of failure is included in this commit.
The core now owns the sync threshold, the payload, the synced high-water mark, the 401 rule and the device id. BeginListeningSync answers with a PushListening effect carrying exactly what to send; ListeningSyncSucceeded marks exactly that as synced. ResetListeningData takes the new device id so rotation and zeroing land in one persisted write. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Each shell keeps its HTTP client and lifecycle triggers, and now asks the core whether to sync (BeginListeningSync), PUTs exactly the PushListening it gets back, and settles it. The threshold, the re-entrancy guard, the 401 rule and device-id storage/rotation are gone from the shells. Legacy stored device ids are passed once as the restore fallback so existing server slots carry over. ADR-0001 decisions 5 and 6 are amended to match. Co-Authored-By: Claude Opus 5.5 <[email protected]>
- Core: a reset marks an in-flight PUT as superseded instead of forgetting it, so its ack can't settle a newer sync for the rotated slot. - Android: persist writes run one at a time in dispatch order, so a tick's write can't land after (and undo) the reset write. - Windows: write via temp file + rename, and log failures. - ADR wording fixes. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2026-09-27T16:25:12Z, host tracewake. Uncommitted work at the time of failure is included in this commit.
JacobStephens2
marked this pull request as draft
September 27, 2026 16:25
This was referenced Sep 27, 2026
Co-Authored-By: Claude Opus 5.5 <[email protected]>
The per-snapshot BeginListeningSync dispatch could replace a pending StartPlayback in the conflating effects StateFlow before PlaybackController applied it. Publish only handler-bound effects. Also: name InFlight::Sent's field, align the web sign-out copy with the other shells, and group the listening-sync tests under their headers. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
Listening-sync policy moves into the core, and transport stays in the shells. The shell decides when it can talk (signed in, lifecycle). The core decides whether there is anything to say, and what. ADR-0001 decisions 5 and 6 are amended in place.
In CI,
setup-androidno longer installs the legacytoolspackage. cmdline-tools 16 removed it, which broke Android setup onmaintoo. Separate commit.sequenceDiagram participant Shell participant Core participant Server Shell->>Core: BeginListeningSync { reason: threshold | flush | refresh } Core-->>Shell: PushListening { deviceId, deviceTotalMs } (or nothing) Shell->>Server: PUT /listening (exactly that) alt ok Shell->>Core: ListeningSyncSucceeded { serverTotalMs } Note over Core: syncedThrough := what was sent else error Shell->>Core: ListeningSyncFailed { unauthorized } Core-->>Shell: ClearSession (if 401) endShell code before and after (the same in all four):
device_id, inside the listening blob that already round-trips. On restore, a shell passes its old stored id asfallbackDeviceId, so existing server slots carry over. The core only adopts that id if the blob has none.effectsStateFlow. Sync and persist effects reach their callers directly. Otherwise the per-snapshotBeginListeningSynccould replace a pendingStartPlaybackbeforePlaybackControllerapplied it.FlushandRefreshare not new behaviour. They name triggers the shells already had: backgrounding and sign-in.Evidence
Before: on
main,crates/cascade-core/tests/listening_sync.rsdoesn't compile because the protocol doesn't exist. Each shell had its own untested copy of the threshold, the re-entrancy guard,syncedThroughMsand device-id rotation. The Android CI job failed insetup-androidonmain(run 36332937323) before compiling anything.After:
cargo test --workspacepasses, with 39 core unit tests, 18 listening-sync tests and 10 property tests.cargo clippy --workspace --all-targetsis clean. All three shell CI builds pass on this branch: Android, Apple and Windows. That includes the first compile of the Kotlin, Swift and C# ports.Web:
tscwasn't run this round, because the machine has no local TypeScript install. The last web change is one status string.None of the shells has its own tests. The Android effect-stream fix is checked only by the compile.
Merge Danger
Door: two-way, mostly.
The listening blob gains a
deviceIdfield. Older builds ignore unknown fields, so they still read it. Shells now only read the old device-id key and no longer update it. That means rolling back after a user has deleted their data would bring back the pre-delete id. The pushed total would be the zeroed one, so this can't resurrect deleted time.Blast Radius: sync
Listening sync on all four shells, and sign-out on a 401. On Android, playback effect delivery is also affected. Timers and settings are not. A shell that fails to settle a PUT would stop syncing until restart, since the core allows only one PUT in flight. All four shells settle on every path, including exceptions and cancellation.
Unaddressed findings
Standards
begin_sync -> Option<(String, u64)>): it's internal to the ledger, and the wire typePushListeningalready names the pair.ClearSession): kept on purpose. The issue asks for "one definition of … the 401 rule" in the core.SyncReasonConverter): it follows the existingTimerKindConverterpattern. On net8, the attribute form ofJsonStringEnumConvertercan't take a camelCase policy.ListeningLedgerholds the in-flight state): kept together on purpose. A reset has to supersede the in-flight PUT atomically with the slot change.syncedThroughMs): removing it is a server API change outside this issue. The comment now says nothing reads it.resetListeningData(uuid)calls per shell): each is one line, and extracting them wouldn't be clearer.SendvsDispatch):Sendalready existed onmainand is called by the views. Renaming it is churn outside this issue.InFlightre-exported from the crate root): it is the type of the publicListeningLedger::in_flightfield, and sibling types are re-exported the same way.pushListeningand the others keep the first. The core emits at most one, so the result is the same.clearSessionmatch rather than a helper. It's used once.Throwableon purpose, so that even anErrorsettles the in-flight sync.Spec
GREATEST. Clearing the key has its own failure mode: if the adopt-write fails, the device loses its slot and double-counts.Flush/Refresh/ClearSession,dispatchreturning effects: this is what the shells already did, and it's the minimum needed to read the core's answer synchronously.syncdispatches and then callsapply(), so checking fromapply()would recurse. Only ticks add unsynced time. A failed sync retries on the next tick, on flush (backgrounding) or on refresh (sign-in).maintoo. Closing it means making the delete wait for the in-flight sync, which is a separate change to how delete works.setup-androidfix: kept, as a separate commit. Without it, Android CI can't run at all, and this branch is the first compile of the Kotlin port.Closes #18
🤖 Generated with Claude Code