Repository navigation
perf(android): lifecycle-aware streaming and R8 release shrinking - #332
Conversation
…, EXT-23) Build stores and the Remote coordinator once per process instead of per Activity, so rotation no longer leaks a coordinator, its collectors, and a pinned OkHttp client. The coordinator reuses one OkHttp client per trust anchor across reconnects. Replace the single remembered screen with a saveable back stack that survives recreation and process death, pops one screen per system back (with predictive-back progress), keeps per-entry UI state, and never replays a deep link or voice launch on recreation. In-screen back targets (workspace directory and detail, git diff, open file, scheduled task, dirty bot editor) now handle system back like their toolbar buttons. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n (EXT-24) Composer keystrokes now coalesce into one draft write per 500 ms quiet period, flushed on pause, on leaving the chat, and when the ViewModel is cleared. Sequence tokens keep a send clear or a late flush from overwriting a newer keystroke. Remote chat acceptance and turn receipts, which fsync the chat and summaries, run on the IO dispatcher and re-check the transcript generation before applying. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-25) Text and reasoning deltas append to StringBuilders and publish at most one snapshot per 33 ms frame instead of copying the whole transcript per token. Pending text is flushed before any timeline, status or terminal event so offsets never point past the published text. Step-id, drive prefix, whitespace and code-block patterns compile once, and the chronological projection and code-block matches are remembered per input. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
debounce(400) never emitted while tokens kept arriving, so the ongoing notification froze during long replies. A throttle-latest operator now posts the latest state at most once per second, and terminal or approval states post immediately. Progress updates set onlyAlertOnce so a replaced notification does not re-alert. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The JVM test source set now uses protocol/aiden-remote/v1/fixtures as a resource directory, so the byte-identical copies of contract.json and manual-pairing-vector.json under app/src/test/resources are removed and cannot drift from the canonical fixtures. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…d deps (EXT-27) Release builds now minify and shrink resources with app keep rules for serializable models and OkHttp's optional TLS providers; the unsigned release APK drops from 38.9 MB to 24.7 MB. versionCode is derived from versionName (major*1e6 + minor*1e3 + patch), which CI can set with -PaidenVersionName. navigation3 ui/runtime, lifecycle-viewmodel-navigation3 and play-services-code-scanner had no call sites and are removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Chat persistence now hops to the IO dispatcher, so a cleared ViewModel can still resume a cancelled continuation on Main. The model-preference suite now joins the ViewModel jobs before resetMain, as AidenChatTest does. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ipt models (EXT-28) All 97 collectAsState() calls become collectAsStateWithLifecycle(), so stopped screens no longer collect streaming state in the background. Val-only transcript models (messages, attachments, steps, timelines, chronological rows) are @immutable so Compose can skip rows by equality. AidenChat and AidenLiveTool keep var fields and are left unannotated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Important
Two reproduced persistence regressions need fixing before merge: consumed drafts can return after teardown, and delayed IO completion can roll the displayed transcript back.
Reviewed changes Full review of the Android lifecycle, persistence, streaming, notification, navigation, and release-build changes.
- Application Lifetime App-scoped stores/coordinator and reuse of the pinned OkHttp client across reconnection and Activity recreation.
- Navigation Saveable back stack, pending deep-link restoration, predictive Back, and nested screen Back handlers.
- Persistence Debounced draft writes, lifecycle flushing, and IO-dispatched chat admission and turn receipts.
- Streaming and Notifications Buffered text/reasoning, cached transcript projections, notification throttling, alert-once behavior, and reconnect jitter.
- State and Builds Lifecycle-aware collection, immutable transcript value models, R8/resource shrinking, derived version codes, unused dependency removal, and canonical protocol fixtures.
Validation: all 307 existing Android JVM tests passed; instrumented-test Kotlin compilation passed. Two additional scratch behavioral tests reproduced the findings below without modifying repository sources. Navigation instrumentation and minified-device execution were not performed; release assembly was stopped while R8 was still running, and lintDebug returned Tool 'shell' timed out after 120000ms.
gpt-6.1-sol | 𝕏
| fun writeSoon(text: String) { | ||
| val write = reserveWrite(text) | ||
| scope.launch { write() } |
There was a problem hiding this comment.
[P2] Keep queued draft consumption flushable during teardown
reserveWrite clears pending before the IO job executes, so flush() cannot drain this queued write. If the Activity finishes after a committed Queue/Steer receipt but before that job runs, onCleared() flushes nothing and cancels the job, leaving the already-consumed input on disk to reappear on the next launch.
Technical details
# Consumed drafts survive cancellation of a queued clear
## Affected sites
- `AidenDebouncedDraftWriter.kt:54-56,64-70` reserves the value without retaining it as flushable work.
- `AidenChatViewModel.kt:1823-1827` consumes a committed run-input draft through `writeSoon`.
- `AidenChatViewModel.kt:694-703` calls `flush()` and then cancels the writer scope.
## Reproduction
- Persist a nonempty draft with `writeNow`.
- Call `writeSoon("")`, then `flush()` and cancel the scope before its queued coroutine starts.
- Run queued tasks. The persisted value remains nonempty.
- The scratch `queuedDraftClearIsLostDuringTeardown` test fails with expected empty text versus the original committed input.
## Required outcome
- Teardown must persist the newest accepted draft value, including an asynchronous consumption/clear that has not started yet.
- Preserve sequence ordering so this cannot overwrite edits accepted afterward.
- Extend behavioral coverage for consumption followed immediately by teardown, not only debounced keystrokes.
## Reproduction artifacts
- Test source: https://uploads.pullfrog.com/agent-uploads/22746175-ce1d-4302-99b3-3476288ec392/Review332Test.kt
- External-source Gradle init: https://uploads.pullfrog.com/agent-uploads/48869329-8940-4906-a7c3-664af3e6ab2b/review332.gradle| // A send or newer reconcile may have started while the cache was on disk. | ||
| if (_isStarting.value || generation != transcriptGeneration || activeClient() !== client) return false | ||
| _chat.value = admitted |
There was a problem hiding this comment.
[P2] Prevent older IO completions from republishing stale transcripts
Moving admission to IO separates the captured admitted snapshot from its publication, but ordinary successful refreshes do not advance transcriptGeneration. An older acceptance can capture snapshot A, resume after another acceptance has already published newer snapshot B, and pass this guard, rolling the visible transcript back to A even though the cache retains B.
Technical details
# Cache authority is not preserved across IO-to-Main publication
## Affected sites
- `AidenChatViewModel.kt:2028-2036` captures the cache winner on IO and later publishes that captured object on Main.
- `loadChat`, `reconcileChat`, and pending-title refresh all enter this acceptance path; overlapping accepts can share the same generation and client.
## Reproduction
- Using the real ViewModel and MockWebServer, load response A and hold its IO-to-Main dispatch after cache admission.
- Start another load, admit response B with a newer request token, and let it publish.
- Release A's continuation.
- The scratch `olderIoContinuationCannotReplaceNewerTranscript` test observes `cache.admittedChat(...).revision == "newer"` but `model.chat.value.revision == "older"`.
- Before this change, synchronous Main-thread admission/read/publication could not interleave this way.
## Required outcome
- UI publication must remain ordered with successful acceptance and must not publish a snapshot superseded during the dispatcher hop.
- Preserve the existing admitted-winner behavior when disk persistence fails or an older cache write is rejected.
- Add overlap coverage at the ViewModel publication boundary, including title/reconcile callers, rather than only testing cache write ordering.
## Reproduction artifacts
- Test source: https://uploads.pullfrog.com/agent-uploads/22746175-ce1d-4302-99b3-3476288ec392/Review332Test.kt
- External-source Gradle init: https://uploads.pullfrog.com/agent-uploads/48869329-8940-4906-a7c3-664af3e6ab2b/review332.gradle…hat' into feat/multi-host-pr9-acceptance Resolve android/app/src/test/resources/contract.json by deleting it, as main (#332) did: the Android JVM tests now read protocol/aiden-remote/v1/fixtures/contract.json, which keeps this stack's additions. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Summary
protocol/(EXT-34).Before release
-PaidenVersionName.Test plan
Part of the October optimization pass. Finding IDs refer to
docs/performance/optimization-audit-2026-10-03.md(#320). The branch's.memory/note has per-finding rationale.🤖 Generated with Claude Code