Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
0ad94f4
fix(mobile): preserve stream recovery and optimistic send ownership
sambitcreate Sep 22, 2026
53499c7
fix(mobile): fence recovery handoffs and terminal publications
sambitcreate Sep 22, 2026
7e3c559
docs: record held-I/O recovery regression evidence
sambitcreate Sep 22, 2026
c022807
fix(ios): fence accepted transcript cache writes
sambitcreate Sep 22, 2026
11003b1
fix(ios): honor rejected transcript writes at callers
sambitcreate Sep 22, 2026
bf5ddba
fix(ios): fence stream companions and propagate removal
sambitcreate Sep 22, 2026
3b61471
fix(ios): couple chat deletion to consumer lifetime
sambitcreate Sep 22, 2026
f959469
fix(ios): fence all chat cache writes across deletion
sambitcreate Sep 22, 2026
d573672
test(bots): handle stdin closure after native rejection
sambitcreate Sep 22, 2026
c22c083
fix(ios): finish draft and attachment lifetime cleanup
sambitcreate Sep 22, 2026
683f92d
Assert capacity denial against its own filesystem observation
sambitcreate Sep 22, 2026
0cba92f
test(worktrees): allow large finite capacity observations
sambitcreate Sep 22, 2026
057dc75
fix(ios): complete deletion metadata and upload cleanup fences
sambitcreate Sep 22, 2026
d3e34e6
fix(ios): retain completed uploads through deletion cleanup
sambitcreate Sep 22, 2026
ff777f5
Fence cleanup-era cache writes while preserving unrelated metadata
sambitcreate Sep 22, 2026
62fa352
fix(ios): retain incoming cursor for absent partial summary cache
sambitcreate Sep 23, 2026
af3b42b
Merge PR #217: fix native stream replay and optimistic send recovery
sambitcreate Sep 23, 2026
4944599
WIP: native ownership integration (merge #217 onto 0.43.0 main)
sambitcreate Sep 23, 2026
11ff969
Fix native integration cache ordering and confirmed run controls
sambitcreate Sep 23, 2026
4be1d95
Allow simulator verification and preserve deletion fences in list merges
sambitcreate Sep 23, 2026
5951566
Merge origin/main into feature/native-ownership-integration
sambitcreate Sep 26, 2026
372fb2d
Merge origin/main into feature/native-ownership-integration
sambitcreate Sep 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
139 changes: 139 additions & 0 deletions .memory/mobile-stream-recovery.md

Large diffs are not rendered by default.

21 changes: 21 additions & 0 deletions .papercuts/troubleshooting.md
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,27 @@ The repository TypeScript library target does not include Array.at; use slice(-1
- 2026-09-22 / PR #195: pinned cua-driver 0.8.3 snapshot tokens and identical AX trees cannot prove document continuity. Do not substitute URLs/titles or invent an advertised capability. Disabled form-fill admission/mutation pending an upstream atomic document-bound write contract; retained local scorer groundwork and cleanup only. Strict removal also needs retained teardown errors because ordinary controller close intentionally suppresses cleanup failures.
## AGENTS refresh — 2026-09-22
The existing native read-html operation reads bounded UTF-8 regular files descriptor-relatively; extension/HTML validation lives in its UI caller, allowing AGENTS.md reuse without a new native protocol. Keep first-turn refresh separate from Pi prepareNextTurn (only subsequent logical turns), and add a provider-dispatch scope fence without mutating in-flight/retry bodies. Preserve the onboarding workspace queue/steering disclosure when adding AGENTS copy.
## 2026-09-22 — native recovery verification

- The initial isolated checkout was behind main; fetched `c8c09e0d2` before coding. The local Hermex study checkout also lacked the cited commits; verified/fetched upstream HEAD `aa7830b28a071769c2d26bc08949e38e09f4b388` into Git objects for read-only comparison.
- Effective task policy still requires workspace-write escalations for shared `.git` metadata, Gradle cache and Xcode/CoreDevice despite the coordinator's global full-access preference; reused authorized commands without changing permissions.
- Cursor-zero HTTP requests omit both `after` and Last-Event-ID; the first regression assertion was corrected to match that existing wire behavior. Original ViewModel then fails four enhanced regressions and the fixed implementation passes.
- Physical iPhone 13 Pro is shared and locked (`com.apple.dt.deviceprep Code=-3: Unlock Sambit’s iPhone to Continue` from the preceding coordinated run). Generic unsigned build-for-testing is compilation evidence only. No simulator or device-unlock bypass.

- PR #217 Pullfrog exposed three missing held-I/O scenarios after green initial CI. Added explicit cache/status/HTTP barriers instead of timing-only sleeps; native transcript generation now advances for terminal authority too. Follow-up Android old-head experiment fails exactly the held-load case; final 177-test run passes. The shared URLProtocol fixture withholds terminal delivery until the intended GET is captured, preventing it from accidentally holding the final reconciliation request.

- 2026-09-22 mobile recovery: synchronous Swift actor disk writes do not imply FIFO queued-call ordering. Reserve ordering tokens before the actor hop and reject stale tokens inside persistence; a held GET test alone cannot prove already-admitted write ordering. Verify disk through a reopened cache after deliberately reversed write delivery.

- 2026-09-22 PR217: gh run view --log-failed refuses logs while sibling jobs run; direct gh api jobs/{id}/logs with --allow-escape-sequences retrieves completed-job logs. Rerun also rejected until workflow completion. Local focused ESLint lacks @eslint/js in this checkout; focused Node harness tests remain runnable after building native helper.

## 2026-09-23 native integration repair
- Preserved integration compiles but chat tests expose independent list-token, premature Stop, approval fallback, and draft/recovery interleavings; compilation alone missed these regressions.
- Physical devices are offline; asked for simulator exception because ios/AGENTS.md prohibits it despite the simulator-based handoff.
- Android full JVM execution exposed a reproducible terminal-settlement timeout; isolated reproduction is being inspected before treating it as runner flakiness.
- The preserved worktree had no Node dependencies; install its lockfile dependencies before running the integrated worktree test.
- Android held-load recovery timeout concealed a fixture contract error: default JSON serialization emitted forbidden `reasoning: null`; omit null optional fields to match the public host projection, then the full chat class passes.
- Direct worktree test execution needs `build:worktree-remover` and `build:worktree-file-io` first; missing native helpers caused ENOENT before the prerequisite builds and rerun.
- First authorized simulator run caught the detail overlay admitting a re-created chat for metadata reserved during its deletion cleanup. Apply the existing per-chat deletion floor to overlay rows too; preserve the pending-era regression's expected exclusion.
## 2026-09-24 — origin/main merge into feature/linux-desktop-support

- The lane38 linux external-editor memory describes the original 5-editor bounded support; the branch later expanded to a union model (21 executables, Flatpak fallback, `file-manager` id). Merge resolution kept the union model and ported main's `zeditor` alias plus PATH hardening (absolute roots only, regular-file check, PATH-major ordering) that linux's variant lacked.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ fun AidenChatDetailScreen(
val connectionState by coordinator.connectionState.collectAsState()
val chat by viewModel.chat.collectAsState()
val streamState by viewModel.streamState.collectAsState()
val hasActiveStream by viewModel.hasActiveStream.collectAsState()
val isStreaming = streamState != null && !streamState!!.isTerminal
val liveText by viewModel.liveText.collectAsState()
val reasoning by viewModel.reasoning.collectAsState()
Expand Down Expand Up @@ -490,7 +491,7 @@ fun AidenChatDetailScreen(
},
onStop = { viewModel.cancelTurn() },
canStop = viewModel.canControlCurrentRun && !isStopping,
canSend = viewModel.canSend,
canSend = viewModel.canSend && !hasActiveStream,
isStreaming = isStreaming,
isVoiceListening = voiceInput.isListening,
isVoiceBusy = voiceInput.isBusy,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.debounce
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.launch
import kotlinx.coroutines.isActive
import kotlinx.coroutines.withContext
Expand Down Expand Up @@ -125,7 +126,15 @@ class AidenChatViewModel(
val draft: StateFlow<String> = _draft.asStateFlow()

private var draftSession: AidenChatDraftStore.Session? = null
private val _hasActiveStream = MutableStateFlow(false)
val hasActiveStream: StateFlow<Boolean> = _hasActiveStream.asStateFlow()
private var activeStreamId: String? = null
set(value) {
field = value
_hasActiveStream.value = value != null
}
private var transcriptGeneration = 0L
private var recoveryWarning: String? = null
private var streamJob: Job? = null
private var titleRefreshJob: Job? = null
private var terminalReconciliationJob: Job? = null
Expand Down Expand Up @@ -175,7 +184,7 @@ class AidenChatViewModel(
} == true

val canSend: Boolean
get() = !isReadOnlyPresentation && isConnected && !_isStarting.value &&
get() = !isReadOnlyPresentation && isConnected && !_isStarting.value && activeStreamId == null &&
(_streamState.value == null || _streamState.value!!.isTerminal) &&
(_draft.value.trim().isNotEmpty() || _pendingAttachments.value.isNotEmpty())

Expand Down Expand Up @@ -649,14 +658,17 @@ class AidenChatViewModel(
}

fun loadChat() {
if (_isStarting.value) return
val generation = transcriptGeneration
val client = activeClient() ?: return
viewModelScope.launch {
_isLoading.value = true
try {
val remote = client.chat(chatId)
if (generation != transcriptGeneration || _isStarting.value || activeClient() !== client) return@launch
acceptRemoteChat(remote)
} catch (e: Exception) {
if (e !is CancellationException) {
if (e !is CancellationException && generation == transcriptGeneration && !_isStarting.value && activeClient() === client) {
_presentedError.value = e.localizedMessage
}
} finally {
Expand Down Expand Up @@ -698,7 +710,9 @@ class AidenChatViewModel(
chatCache.removeActiveStream(currentInstanceId, chatId, ifStreamId = activeStream.streamId)
return
}
startStreaming(activeStream)
// The cached cursor has no matching durable partial buffers. Reconstruct
// the cold view from the journal; warm reconnects retain their local cursor.
startStreaming(activeStream.copy(lastSequence = 0))
}

fun send() {
Expand Down Expand Up @@ -742,6 +756,9 @@ class AidenChatViewModel(
createdAt = now
)

transcriptGeneration++
titleRefreshJob?.cancel()
titleRefreshJob = null
_isStarting.value = true
_presentedError.value = null
_draft.value = ""
Expand Down Expand Up @@ -796,6 +813,8 @@ class AidenChatViewModel(
}
} finally {
_isStarting.value = false
transcriptGeneration++
if (activeClient() === client && _chat.value?.isTitlePending == true) schedulePendingTitleRefresh()
}
}
}
Expand Down Expand Up @@ -912,9 +931,22 @@ class AidenChatViewModel(
}
}

private fun showRecoveryWarning(message: String?) {
_presentedError.value = message
recoveryWarning = message
}

private fun clearRecoveryWarning() {
if (recoveryWarning != null && _presentedError.value == recoveryWarning) _presentedError.value = null
recoveryWarning = null
}

private fun startStreaming(originalStream: AidenChatCache.ActiveStream) {
val client = activeClient() ?: return
activeStreamId = originalStream.streamId
if (_streamState.value == null) _streamState.value = AidenStreamState.RECONCILING
terminalReconciliationJob?.cancel()
terminalReconciliationJob = null
streamJob?.cancel()
streamJob = viewModelScope.launch {
var stream = originalStream
Expand All @@ -923,25 +955,25 @@ class AidenChatViewModel(

while (activeStreamId == stream.streamId) {
try {
client.openStream(chatId, stream.streamId, lastEventId = stream.lastSequence).collect { event ->
if (activeStreamId != stream.streamId) return@collect
if (event.streamId != stream.streamId) return@collect
if (event.sequence <= stream.lastSequence) return@collect
if (event.sequence != stream.lastSequence + 1) {
reconcileChat()
}
val terminal = client.openStream(chatId, stream.streamId, lastEventId = stream.lastSequence).firstOrNull { event ->
if (activeStreamId != stream.streamId) return@firstOrNull true
if (event.streamId != stream.streamId) return@firstOrNull false
clearRecoveryWarning()
if (event.sequence <= stream.lastSequence) return@firstOrNull false
if (event.sequence != stream.lastSequence + 1) reconcileChat()
apply(event)
if (activeStreamId != stream.streamId) return@collect
// A terminal frame ends transport even if the authoritative
// transcript fetch failed and needs independent retries.
if (event.terminal || activeStreamId != stream.streamId) return@firstOrNull true
stream.lastSequence = event.sequence
if (event.terminal) return@collect
if (instanceId.isNotEmpty()) {
chatCache.saveActiveStream(stream, instanceId, chatId)
}
false
}
if (terminal != null || activeStreamId != stream.streamId) return@launch

val status = client.streamStatus(chatId, stream.streamId)
if (activeStreamId != stream.streamId) return@launch
retryAttempt = 0
clearRecoveryWarning()
apply(status, stream.streamId)
if (status.state.isTerminal) {
if (terminalReplayGate.shouldReplay(status.state)) continue
Expand All @@ -954,6 +986,8 @@ class AidenChatViewModel(
try {
val status = client.streamStatus(chatId, stream.streamId)
if (activeStreamId != stream.streamId) return@launch
retryAttempt = 0
clearRecoveryWarning()
apply(status, stream.streamId)
if (status.state.isTerminal) {
if (terminalReplayGate.shouldReplay(status.state)) continue
Expand All @@ -966,7 +1000,7 @@ class AidenChatViewModel(
if (AidenTerminalReconciliation.isDefinitiveMissingStream(inner)) {
if (reconcileMissingStream(stream)) return@launch
}
_presentedError.value = inner.localizedMessage
showRecoveryWarning(inner.localizedMessage)
val retryDelay = AidenTerminalReconciliation.retryDelayMilliseconds(retryAttempt)
retryAttempt++
delay(retryDelay)
Expand Down Expand Up @@ -1237,20 +1271,25 @@ class AidenChatViewModel(
}

private suspend fun reconcileChat(): Boolean {
if (_isStarting.value) return false
val generation = transcriptGeneration
val client = activeClient() ?: return false
return try {
val remote = client.chat(chatId)
if (generation != transcriptGeneration || _isStarting.value || activeClient() !== client) return false
acceptRemoteChat(remote)
clearRecoveryWarning()
true
} catch (e: Exception) {
if (e !is CancellationException) {
_presentedError.value = e.localizedMessage
if (e !is CancellationException && generation == transcriptGeneration && !_isStarting.value && activeClient() === client) {
showRecoveryWarning(e.localizedMessage)
}
false
}
}

private fun acceptRemoteChat(remote: AidenChat, scheduleTitleRefresh: Boolean = true) {
if (_isStarting.value) return
_chat.value = remote
resolveModelSelection()
if (instanceId.isNotEmpty()) {
Expand All @@ -1268,7 +1307,10 @@ class AidenChatViewModel(
for (delayMs in AidenChatTitleReconciliation.retryMilliseconds) {
try {
delay(delayMs)
if (_isStarting.value) continue
val generation = transcriptGeneration
val remote = client.chat(chatId)
if (generation != transcriptGeneration || _isStarting.value || activeClient() !== client) continue
acceptRemoteChat(remote, scheduleTitleRefresh = false)
if (!remote.isTitlePending) return@launch
} catch (e: Exception) {
Expand All @@ -1280,6 +1322,7 @@ class AidenChatViewModel(

private suspend fun finishStream(expectedStreamId: String) {
if (activeStreamId != expectedStreamId) return
transcriptGeneration++
if (!reconcileChat()) {
scheduleTerminalReconciliation(expectedStreamId)
return
Expand All @@ -1289,7 +1332,13 @@ class AidenChatViewModel(

private fun clearFinishedStream(expectedStreamId: String) {
if (activeStreamId == expectedStreamId) {
transcriptGeneration++
activeStreamId = null
_liveText.value = ""
_reasoning.value = ""
_tools.value = emptyList()
_activityTimeline.value = null
_pendingApproval.value = null
if (instanceId.isNotEmpty()) {
chatCache.removeActiveStream(instanceId, chatId, ifStreamId = expectedStreamId)
}
Expand All @@ -1298,6 +1347,7 @@ class AidenChatViewModel(

private suspend fun reconcileMissingStream(stream: AidenChatCache.ActiveStream): Boolean {
if (activeStreamId != stream.streamId) return false
transcriptGeneration++
if (!reconcileChat()) return false
if (activeStreamId != stream.streamId) return false
val currentChat = _chat.value ?: return false
Expand All @@ -1320,6 +1370,7 @@ class AidenChatViewModel(
val delayMs = AidenTerminalReconciliation.retryDelayMilliseconds(attempt)
delay(delayMs)
if (activeStreamId != expectedStreamId) return@launch
transcriptGeneration++
if (reconcileChat()) {
clearFinishedStream(expectedStreamId)
return@launch
Expand Down
Loading