Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions android/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Aiden On The Go for Android. Earlier Android changes are recorded in the pull re

## Unreleased

- **2026-11-24 — One before-effect refusal list, matching iOS.** Resume, Open work, Peers, Routine models, Watches and the generated avatar now share one list of refusals that prove a change never ran: the same 31 codes as iOS and `recognizedBeforeEffectCodes` in `protocol/aiden-remote/v1/fixtures/mutation-failure-ambiguity.json`. A first `409 revision_conflict` on any of them clears the pending attempt instead of keeping it as uncertain, as do `already_exists` and the handle, approval, question, memory, proposal, hand-off, access-request and plan-expiry refusals. An attempt whose earlier try was already unknown still stays uncertain whatever a later response says. Fork, Continue in a new chat and New worktree now follow the same cached-rejection-ledger rule as messages and run-now: a structured `5xx`, `408` or `429` keeps the request's key for the retry instead of spending it. No Remote wire or revision change.
- **2026-11-18 — Pairing with a server; Terminal theme control removed.** The pairing steps now say that on a server, `aiden serve` shows the code in its terminal, or `aiden remote pair lan` prints one, as iOS already did. The app no longer accepts the retired `appearance.terminalTheme` chat control, which no host has sent since the interactive CLI was retired on 2026-10-30. No Remote wire or revision change.

- **2026-11-11 — Continue in a new chat (Remote revision 64; written as 63, re-claimed at merge on 2026-11-17).** When a host offering `chat:continue-in-new-chat` refuses a send because the chat's workspace folder is missing and says the chat can continue elsewhere, the error gains **Continue in a new chat**. A sheet lists the host's other workspaces (never the chat's own, archived ones or any folder path); picking one forks the whole chat into that workspace with the host's `continueIn` request and opens the new chat, leaving the original as it was. Failures show the host's message; a destination whose folder is missing too keeps the action so another workspace can be picked. Without the host's offer, or on older hosts, the refusal looks as before. Bot contract-test revision assertions now expect 63.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import sbtbiswas.AidenOnTheGo.R
import sbtbiswas.AidenOnTheGo.features.scheduled.aidenScheduledRunFailureIsAmbiguous
import sbtbiswas.AidenOnTheGo.features.remote.AidenRemoteCoordinator
import sbtbiswas.AidenOnTheGo.features.shared.AidenModelPickerField
import sbtbiswas.AidenOnTheGo.features.shared.AidenModelRoute
import sbtbiswas.AidenOnTheGo.models.*
import sbtbiswas.AidenOnTheGo.protocol.AidenRemoteFailureClassification
import sbtbiswas.AidenOnTheGo.protocol.AidenRemoteFailurePolicy
import sbtbiswas.AidenOnTheGo.ui.theme.AidenPrimaryButton
import sbtbiswas.AidenOnTheGo.ui.theme.AidenTheme
import sbtbiswas.AidenOnTheGo.ui.theme.AidenUi
Expand Down Expand Up @@ -171,7 +172,7 @@ class AidenBotCreateAttempts(
*/
fun failed(attempt: AidenBotCreateAttempt, error: Throwable) {
if (error is AidenBotChatActivityUnreachable) return
uncertain = if (aidenScheduledRunFailureIsAmbiguous(error)) attempt else null
uncertain = if (AidenRemoteFailureClassification.isAmbiguous(error, AidenRemoteFailurePolicy.CACHED_REJECTION_LEDGER)) attempt else null
}

/** The Mac made [attempt]'s Bot: another Create with the same answers is another Bot. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ import sbtbiswas.AidenOnTheGo.models.AidenBotSummary
import sbtbiswas.AidenOnTheGo.models.AidenBotSemanticAvatar
import sbtbiswas.AidenOnTheGo.networking.AidenRemoteClient
import sbtbiswas.AidenOnTheGo.persistence.AidenBotCache
import sbtbiswas.AidenOnTheGo.protocol.AidenRemoteFailureClassification
import sbtbiswas.AidenOnTheGo.protocol.AidenRemoteFailurePolicy
import sbtbiswas.AidenOnTheGo.ui.theme.AidenActivityDot
import java.io.ByteArrayOutputStream
import java.security.MessageDigest
import java.util.Base64
import java.util.UUID
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.compose.ui.res.stringResource
import sbtbiswas.AidenOnTheGo.R
Expand All @@ -61,7 +64,11 @@ fun aidenBotAvatarExpectedRevision(bot: AidenBotDetail): String =
bot.avatar.asset?.assetRevision ?: bot.revision

fun aidenBotAvatarMutationFailureIsAmbiguous(error: Throwable): Boolean {
return error !is AidenBotGeneratedAvatarError.Unavailable
if (error is AidenBotGeneratedAvatarError.Unavailable) return false
return AidenRemoteFailureClassification.isAmbiguous(
error,
AidenRemoteFailurePolicy.BEFORE_EFFECT_REFUSAL
Comment thread
sambitcreate marked this conversation as resolved.
Resolved
)
}

object AidenBotGeneratedAvatarNormalizer {
Expand Down Expand Up @@ -172,6 +179,18 @@ class AidenBotGeneratedAvatarModel(
/** The last photo the Mac took, kept until a refreshed Bot that carries it is seen. */
@Volatile private var committed: CommittedAvatar? = null

private class UploadAttempt(val botId: String, val revision: String, val data: ByteArray, val key: UUID) {
fun isFor(botId: String, revision: String, data: ByteArray): Boolean =
this.botId == botId && this.revision == revision && this.data.contentEquals(data)
}

/**
* An upload whose outcome is unknown. Sending the same photo to the same Bot revision again
* reuses its `Idempotency-Key`, so the Mac replays what it did rather than taking the photo a
* second time. A reply, or a refusal that proves nothing was written, ends it.
*/
@Volatile private var uncertainUpload: UploadAttempt? = null

/**
* The If-Match for the next avatar change. A photo the Mac took whose Bot could not be re-read
* still moved the avatar revision on, so a page holding the older Bot sends the committed one.
Expand Down Expand Up @@ -231,10 +250,16 @@ class AidenBotGeneratedAvatarModel(
}

_phase.value = AidenBotGeneratedAvatarPhase.UPLOADING
val earlier = uncertainUpload?.takeIf { it.isFor(botId, revision, data) }
// Once an attempt is uncertain, no later refusal can prove the first try did nothing.
val retried = earlier != null
val attempt = earlier ?: UploadAttempt(botId, revision, data, UUID.randomUUID())
uncertainUpload = attempt
try {
val base64Data = Base64.getEncoder().encodeToString(data)
val upload = AidenBotAvatarUpload(data = base64Data)
val asset = client.putBotAvatar(botId, revision, upload)
val asset = client.putBotAvatar(botId, revision, upload, attempt.key)
if (uncertainUpload === attempt) uncertainUpload = null
committed = CommittedAvatar(botId, revision, asset.assetRevision)
botCache?.putAvatar(botId, asset.assetRevision, data)
// A pick made during the upload owns the phase and the candidate now.
Expand All @@ -257,6 +282,7 @@ class AidenBotGeneratedAvatarModel(
} catch (e: CancellationException) {
throw e
} catch (e: Exception) {
if (!retried && !aidenBotAvatarMutationFailureIsAmbiguous(e) && uncertainUpload === attempt) uncertainUpload = null
if (mine == selection) {
_phase.value = AidenBotGeneratedAvatarPhase.FAILED
_errorMessage.value = e.message ?: "Avatar upload failed"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import kotlinx.coroutines.flow.update
import kotlinx.serialization.Serializable
import sbtbiswas.AidenOnTheGo.models.*
import sbtbiswas.AidenOnTheGo.persistence.AidenBotWatchJournal
import sbtbiswas.AidenOnTheGo.protocol.AidenRemoteClientException
import sbtbiswas.AidenOnTheGo.protocol.AidenRemoteFailurePolicy
import java.util.UUID

interface AidenBotOpenWorkTransport {
Expand Down Expand Up @@ -58,7 +58,7 @@ class AidenBotOpenWorkController(private val transport: AidenBotOpenWorkTranspor
check(journal.replace(persisted, encoded)) { "Another window changed the saved request" }
persisted = encoded
true
} catch (_: Exception) { _state.update { it.copy(problem = AidenOpenWorkProblem.STORAGE) }; false }
} catch (_: Exception) { storageBlocked = true; _state.update { it.copy(problem = AidenOpenWorkProblem.STORAGE) }; false }
private fun settle(snapshot: AidenOpenWorkSnapshot): Boolean {
val attempt = _state.value.pending ?: return false
val mutation = attempt.mutation
Expand Down Expand Up @@ -131,7 +131,9 @@ class AidenBotOpenWorkController(private val transport: AidenBotOpenWorkTranspor
if (_state.value.pending != null || !canWrite() || now() >= option.expiresAt || _state.value.snapshot?.undo?.contains(option) != true || hasPendingStop(option.itemId)) return
perform(AidenOpenWorkAttempt(AidenOpenWorkMutation(uuid(),AidenOpenWorkAction.UNDO,option.expectedRevision,undoOf=option.mutationId),now()))
}
fun retryAllowed(): Boolean = _state.value.pending?.let { it.mutation.action.isStop || now() - it.startedAt in 0 until 23 * 60 * 60 * 1000L } == true
fun retryAllowed(): Boolean = _state.value.pending?.let {
AidenDurablePendingMutation.isRetryAllowed(it.startedAt, now(), exempt = it.mutation.action.isStop)
} == true
suspend fun retry() {
val pending = _state.value.pending ?: return
if (!retryAllowed()) { _state.update { it.copy(problem = AidenOpenWorkProblem.EXPIRED) }; return }
Expand Down Expand Up @@ -170,10 +172,23 @@ class AidenBotOpenWorkController(private val transport: AidenBotOpenWorkTranspor
}
} catch (e: CancellationException) { _state.update { it.copy(problem = AidenOpenWorkProblem.UNCERTAIN) }; throw e }
catch (e: Exception) {
val server = e as? AidenRemoteClientException.Server
val definite = server?.statusCode in listOf(400,401,403,404,409,422)
if (!previous && definite && persist(pending=null)) _state.update { it.copy(pending=null) }
_state.update { it.copy(problem = if (it.pending != null) AidenOpenWorkProblem.UNCERTAIN else AidenOpenWorkProblem.FAILED) }
val settlement = AidenDurablePendingMutation.settleFailure(
error = e,
previouslyUnknown = previous,
policy = AidenRemoteFailurePolicy.BEFORE_EFFECT_REFUSAL
)
val definite = settlement == AidenDurableFailureSettlement.CLEAR_DEFINITE
val cleared = definite && persist(pending = null)
if (cleared) _state.update { it.copy(pending = null) }
_state.update {
it.copy(
problem = when {
storageBlocked || (definite && !cleared) -> AidenOpenWorkProblem.STORAGE
it.pending != null -> AidenOpenWorkProblem.UNCERTAIN
else -> AidenOpenWorkProblem.FAILED
}
)
}
} finally { _state.update { it.copy(busy=false) } }
load()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import kotlinx.coroutines.flow.*
import kotlinx.serialization.Serializable
import sbtbiswas.AidenOnTheGo.models.*
import sbtbiswas.AidenOnTheGo.persistence.AidenBotWatchJournal
import sbtbiswas.AidenOnTheGo.protocol.AidenRemoteFailurePolicy
import java.util.UUID

interface AidenBotPeersTransport {
Expand Down Expand Up @@ -94,7 +95,7 @@ class AidenBotPeersController(val botId:String,private val transport:AidenBotPee
start(AidenPeerMutation(AidenPeerAction.REVOKE,botId,uuid(),revision,pairId=pair.id,pairRevision=pair.revision))
}
private suspend fun start(request:AidenPeerMutation){val attempt=AidenPeerAttempt(request,now());if(retain(_state.value.copy(pending=attempt)))send(attempt,false)}
fun retryAllowed()=_state.value.pending?.let{now()-it.startedAt in 0 until RETRY_MS}==true
fun retryAllowed()=_state.value.pending?.let{AidenDurablePendingMutation.isRetryAllowed(it.startedAt,now())}==true
suspend fun retry(){val p=_state.value.pending ?: return;if(!retryAllowed()){_state.update{it.copy(problem=AidenRoutineControlProblem.EXPIRED)};return};send(p,true)}
private suspend fun send(p:AidenPeerAttempt,unknown:Boolean){
if(!current() || !canRead() || !canWrite() || storageBlocked || _state.value.busy)return
Expand All @@ -105,7 +106,7 @@ class AidenBotPeersController(val botId:String,private val transport:AidenBotPee
if(r.ok){check(r.mutationId==p.request.mutationId);retain(settled(requireNotNull(r.snapshot),p.request.action==AidenPeerAction.DESCRIBE))}
else {r.snapshot?.let(::apply);if(_state.value.pending!=null){val keep=unknown || r.code==AidenPeerError.UNAVAILABLE;retain(_state.value.copy(pending=if(keep)p else null,needsReview=_state.value.needsReview || r.code==AidenPeerError.CONFLICT,problem=if(keep)AidenRoutineControlProblem.UNCERTAIN else AidenRoutineControlProblem.FAILED,message=r.error))}}
}catch(e:CancellationException){if(current())_state.update{it.copy(problem=AidenRoutineControlProblem.UNCERTAIN)};throw e}
catch(e:Exception){if(current()){val keep=unknown || aidenBotResumeFailureIsAmbiguous(e);retain(_state.value.copy(pending=if(keep)p else null,problem=if(keep)AidenRoutineControlProblem.UNCERTAIN else AidenRoutineControlProblem.FAILED))}}
catch(e:Exception){if(current()){val keep=AidenDurablePendingMutation.settleFailure(e,unknown,AidenRemoteFailurePolicy.BEFORE_EFFECT_REFUSAL)==AidenDurableFailureSettlement.RETAIN_UNCERTAIN;retain(_state.value.copy(pending=if(keep)p else null,problem=if(keep)AidenRoutineControlProblem.UNCERTAIN else AidenRoutineControlProblem.FAILED))}}
finally{if(current())_state.update{it.copy(busy=false)}}
}
suspend fun openExchange(id:String){
Expand All @@ -124,7 +125,7 @@ class AidenBotPeersController(val botId:String,private val transport:AidenBotPee
if(unknown && !retainStop(p))return
val g=++generation;_state.update{it.copy(busy=true,loading=false,problem=null,message=null)}
try {
if(now()-p.startedAt !in 0 until RETRY_MS) {
if(!AidenDurablePendingMutation.isRetryAllowed(p.startedAt,now())) {
val row=transport.detail(p.request.exchangeId)
if(!current() || !canReadExchanges() || !canWrite() || g!=generation)return
applyDetail(row)
Expand All @@ -134,9 +135,9 @@ class AidenBotPeersController(val botId:String,private val transport:AidenBotPee
val r=transport.stop(p.request);if(!current() || !canReadExchanges())return
r.exchange?.let{check(it.belongsTo(botId) && it.id==p.request.exchangeId)}
if(r.ok){check(r.mutationId==p.request.mutationId);applyDetail(requireNotNull(r.exchange));if(_state.value.pendingStop!=null)_state.update{it.copy(problem=AidenRoutineControlProblem.UNCERTAIN,message="Stop is pending. Check again for the host’s acknowledgement.")}}
else {r.exchange?.let(::applyDetail);if(_state.value.pendingStop!=null){val keep=unknown || r.code==AidenPeerError.UNAVAILABLE;if(!keep)retainStop(null);_state.update{it.copy(problem=if(keep)AidenRoutineControlProblem.UNCERTAIN else AidenRoutineControlProblem.FAILED,message=r.error)}}}
else {r.exchange?.let(::applyDetail);if(_state.value.pendingStop!=null){val keep=unknown || r.code==AidenPeerError.UNAVAILABLE;if(!keep)retainStop(null);_state.update{it.copy(problem=if(storageBlocked)AidenRoutineControlProblem.STORAGE else if(keep)AidenRoutineControlProblem.UNCERTAIN else AidenRoutineControlProblem.FAILED,message=r.error)}}}
}catch(e:CancellationException){if(current())_state.update{it.copy(problem=AidenRoutineControlProblem.UNCERTAIN)};throw e}
catch(e:Exception){if(current()){val keep=unknown || aidenBotResumeFailureIsAmbiguous(e);if(!keep)retainStop(null);_state.update{it.copy(problem=if(keep)AidenRoutineControlProblem.UNCERTAIN else AidenRoutineControlProblem.FAILED)}}}
catch(e:Exception){if(current()){val keep=AidenDurablePendingMutation.settleFailure(e,unknown,AidenRemoteFailurePolicy.BEFORE_EFFECT_REFUSAL)==AidenDurableFailureSettlement.RETAIN_UNCERTAIN;if(!keep)retainStop(null);_state.update{it.copy(problem=if(storageBlocked)AidenRoutineControlProblem.STORAGE else if(keep)AidenRoutineControlProblem.UNCERTAIN else AidenRoutineControlProblem.FAILED)}}}
finally{if(current())_state.update{it.copy(busy=false)}}
}
suspend fun showEvidence(kind:AidenOpenWorkEvidenceKind){
Expand All @@ -148,7 +149,7 @@ class AidenBotPeersController(val botId:String,private val transport:AidenBotPee
}
fun closeEvidence(){generation++;_state.update{it.copy(evidence=null,loading=false)}}
companion object {
const val RETRY_MS=23*60*60*1000L
const val RETRY_MS=AidenDurablePendingMutation.RETRY_WINDOW_MS
fun stopMessage(receipt:AidenPeerStopReceipt)=when(receipt.state){AidenPeerStopState.STOPPED->"The host acknowledged Stop. Earlier effects may remain.";AidenPeerStopState.NOT_RUNNING->"The linked work is no longer running.";AidenPeerStopState.BLOCKED->"Stop was refused. The work remains unfinished.";else->"Stop is pending. Check again for the host’s acknowledgement."}
}
}
Loading
Loading