Repository navigation
feat(remote): let phones observe and control runs started elsewhere - #359
Conversation
Contract revision 21 adds the phone-negotiable capabilities runs:observe and runs:control behind feature phone-run-control-v1. Paired phones attach to the run currently open on a chat, even when the Mac desktop, Telegram or the scheduler started it, and can Stop it or answer its approvals and questions through the run-scoped routes. - Server: phone projection strips approval details and offers scopes only when the phone may allow; access is per chat, Bot chats also need bot grants; first responder wins with 409 approval_resolved or question_already_resolved; revoking a device closes its run feeds. - iOS and Android: strict run-event decoders, run-scoped client methods, a foreign-run projection that settles the attach replay before going live, bounded reconnects, and "Answered on Mac" receipts for losers. - Fixture phoneRunEvents pins the shared run stream on every platform. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Caution
The new phone approval path bypasses schedule:write, and native observation/recovery has four reproducible failure modes. These should be addressed before merging.
Reviewed changes: Reviewed the complete server, protocol, iOS, and Android implementation of phone observation and control for runs started elsewhere.
- Authority and Projection: Adds phone-negotiated run grants, per-chat authorization, redacted approvals, and first-responder control through the existing run routes.
- Native Observation: Adds run SSE decoders, foreign-run reducers, attachment/reconnect handling, and integration with Stop, prompt cards, and ambient run status.
- Contracts and Tests: Updates revision 21 fixtures, API documentation, and decoder/client/service coverage; 140 focused TypeScript tests, TypeScript checking, and the full checked-in Android unit suite passed. Isolated behavioral probes reproduced the five inline findings; iOS XCTest execution was unavailable on this Linux runner.
gpt-6.1-sol | 𝕏
- Phone-scoped allow of an automation approval on a foreign run needs schedule:write, matching the phone's own approvals. - Android attaches to a run started elsewhere once a cold-opened chat loads, and a continuously streaming run goes live within a bounded settle deadline instead of waiting for a pause. - iOS and Android restore a prompt whose local answer was not confirmed when a later snapshot still lists it. - iOS and Android keep a finished foreign run's response visible when the terminal transcript read fails, and recover it with a bounded, fenced re-read. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Important
Android's new terminal-recovery path retains the response in memory but still hides it from the transcript when the final read fails.
Reviewed changes: Reviewed 0bae07d4 against the previous Pullfrog review, with the full PR diff as context.
- Enforced Automation Authority. Required
schedule:writefor phone-scoped automation approval allows, while preserving Deny and desktop behavior. - Repaired Android Attachment. Retried observer admission after cold chat loading and bounded replay settlement so continuous output becomes visible with Stop available.
- Restored Prompt Recovery. Cleared local-answer suppression after failed control writes so authoritative snapshots can restore pending approvals and questions without resending writes.
- Added Terminal Read Recovery. Preserved native live buffers and added bounded, ownership-fenced transcript retries; reviewed the new behavioral coverage. All 141 focused server tests, all 318 Android unit tests, and TypeScript checking passed. iOS XCTest execution was unavailable because this Linux runner has no
xcodebuild.
gpt-6.1-sol | 𝕏
| } else if (client != null) { | ||
| // Keep the response the user was watching until the transcript that | ||
| // holds it is accepted. Only the chat is re-read; nothing is resent. | ||
| scheduleForeignRunReconciliation(client) |
There was a problem hiding this comment.
[P2] Render retained output while terminal reconciliation is pending
This branch preserves _liveText, but the Android transcript still renders its live row only when isStreaming is true (AidenChatDetailScreen.kt:130,771). After done/run.ended, the state is terminal, so a failing final chat GET still removes the answer from the screen until a retry succeeds, or indefinitely if the retries exhaust. The new test passes because it checks stored model text rather than whether the response remains rendered.
Technical details
# Retained terminal response is hidden by the Android transcript gate
## Affected sites
- `android/app/src/main/java/sbtbiswas/AidenOnTheGo/features/chat/AidenChatViewModel.kt:2050-2056` keeps the terminal state and retains live output on a failed transcript read.
- `android/app/src/main/java/sbtbiswas/AidenOnTheGo/features/chat/AidenChatDetailScreen.kt:130,770-789` derives `isStreaming` from a nonterminal state and omits the entire `live_stream` item otherwise; live text is collected only inside that item.
- `android/app/src/test/java/sbtbiswas/AidenOnTheGo/AidenChatTest.kt:289-299` verifies retained text and later transcript recovery, but does not exercise the rendering gate.
- `ios/AidenOnTheGo/Features/Remote/AidenChatFeature.swift:4431` already allows rendering a response with nonempty live text after streaming ends.
## Required outcome
- Keep the previously visible foreign response rendered while its authoritative transcript is unavailable, including after the bounded retries are exhausted.
- Remove the retained presentation only after accepted transcript handoff or superseding ownership/removal, without re-enabling Stop for an ended run.
- Cover the rendered response through terminal delivery, a failing transcript read, and successful recovery; assert the handoff leaves one visible answer.
Hermes Review BotConfidence: 5 Engine: SummaryThis PR implements Aiden Remote contract revision 24 (noted as revision 21 in the PR description, but correctly standardized to 24 across the schema, server, Android, iOS, and fixture contracts), allowing mobile clients (iOS and Android) to observe and control Aiden agent runs initiated on the desktop, via Telegram, or by scheduled tasks. Key additions:
The review identified two logic bugs in the iOS implementation where event settle debouncing and capability retry handling diverge from Android, risking spurious Live Activities on finished runs and missed observation when opening a chat during connection setup. Confidence Score: 5/5📁 Important Files Changed
Findings[P2] logic: iOS foreign run settle timer does not debounce incoming replay events
Description: In if foreignRun == nil {
foreignRun = AidenForeignRunProjection(runId: event.runId)
scheduleForeignRunSettle(context: context, generation: generation)
}
If journal replay takes >400ms (e.g. over cellular, high network jitter, or large replay journals), In contrast, Android's Recommendation: if foreignRun == nil {
foreignRun = AidenForeignRunProjection(runId: event.runId)
}
if !foreignRunIsLive {
scheduleForeignRunSettle(context: context, generation: generation)
}In [P2] logic: iOS fails to retry foreign run observation when capabilities or connection settle after load
Description: The method guards on: guard ...
coordinator.server?.canObserveForeignRuns == true,
let installation = coordinator.installationStore.activeInstallation,
installation.hasNegotiatedAccess(to: .runsObserve),
... else { return }If a chat is opened while the client is still connecting, reconnecting, or negotiating capabilities with the Mac server ( Because iOS never re-evaluates foreign run observation, an open chat view will never observe foreign runs even after the connection finishes connecting and capabilities are confirmed. The user is forced to leave the chat and navigate back in to trigger In Android (
Recommendation: 📊 Sequence DiagramsequenceDiagram
autonumber
actor User as Mobile User (Phone)
participant Client as Mobile Client (iOS/Android)
participant Host as Aiden Remote Host (Mac Server)
participant Coordinator as Desktop Run Coordinator
Note over User,Host: Phone opens chat while desktop run is active
Client->>Host: GET /chats/{chatId}/runs/current/events (auth: bearer + runs:observe)
Host-->>Client: HTTP 200 SSE Stream (Replay frames seq 0..N)
loop Replay & Settle Window
Client->>Client: Reduce events into AidenForeignRunProjection
Client->>Client: Reset 400ms settle debounce (max deadline: 1200ms)
end
Note over Client: Replay settles (run not ended) -> Go Live
Client->>User: Display live streaming text, start Live Activity
opt Approval Required
Coordinator->>Host: Tool execution requires confirmation
Host-->>Client: event: approval_required {approvalId, summary, canAllow, scopes}
Client->>User: Render approval card (Once / Always)
User->>Client: Tap "Allow Once"
Client->>Host: POST /runs/{runId}/approvals/{approvalId}/respond {decision: "allow_once"}
alt First Responder (Phone wins)
Host->>Coordinator: Forward resolution
Host-->>Client: HTTP 200 {status: "resolved"}
else Already Answered (Mac or another phone answered first)
Host-->>Client: HTTP 409 Conflict {error: "approval_resolved", responder: "desktop"}
Client->>User: Show receipt ("Answered elsewhere on desktop")
end
end
Coordinator->>Host: Run completes
Host-->>Client: event: run.ended {state: "done"}
Client->>Host: GET /chats/{chatId}/transcript (reconcile canonical transcript)
Host-->>Client: HTTP 200 Complete Transcript
Client->>User: Update transcript UI & dismiss Live Activity
|
very-hermes-bot
left a comment
There was a problem hiding this comment.
Inline review — 4 finding(s) anchored to the diff. See the pinned summary comment for the overview.
| * version 1; the revision is published on `/health` and in the shared fixture. | ||
| */ | ||
| export const AIDEN_REMOTE_CONTRACT_REVISION = 20 as const; | ||
| export const AIDEN_REMOTE_CONTRACT_REVISION = 21 as const; |
There was a problem hiding this comment.
[P1 · logic] Contract revision 21 collides with main where revisions 21 and 22 are already claimed
Confidence: 0.95
The branch claims contract revision 21, but origin/main has already merged PR #349 and PR #352 which claimed revisions 21 and 22 respectively.
Repair: Merge origin/main and bump the contract revision to 23 across protocol definitions, OpenAPI, fixtures, iOS, and Android.
| export const AIDEN_REMOTE_CONTRACT_REVISION = 21 as const; | |
| export const AIDEN_REMOTE_CONTRACT_REVISION = 23 as const; |
| canRespond = canControl, | ||
| hasRequiredWriteCapability = hasWrite, | ||
| hostCanAllow = approval.canAllow, | ||
| canAllow = canControl && approval.canAllow && hasWrite, | ||
| scopes = approval.scopes ?: listOf(AidenApprovalScope.ONCE) | ||
| ) | ||
| } | ||
| _pendingQuestion.value = projection.pendingQuestion?.let { question -> | ||
| AidenPendingQuestion( | ||
| id = question.promptId, | ||
| questions = question.questions, | ||
| expiresAt = question.expiresAt ?: FOREIGN_PROMPT_EXPIRY, | ||
| canRespond = canControl | ||
| ) |
There was a problem hiding this comment.
[P2 · logic] Android approval and question prompts bypass per-chat response capability checks
Confidence: 0.9
presentForeignRun assigns canRespond and canAllow based solely on runs:control without checking capabilities.canRespond (approval:respond) or canRespondToQuestions() (questions:respond).
Repair: Require capabilities.canRespond for approvals, canRespondToQuestions() for questions, and chat:write for canControlForeignRun.
|
|
||
| /** Phones never receive host-only approval facts (contract revision 21). */ | ||
| export function isPhoneRunDevice(device: { type?: string }): boolean { | ||
| return device.type !== undefined && device.type !== "mac" && device.type !== "linux"; |
There was a problem hiding this comment.
[P2 · logic] Omitted device type in isPhoneRunDevice leaks full desktop run projections
Confidence: 0.92
isPhoneRunDevice requires device.type !== undefined, so devices where type is omitted by legacy adapters evaluate to false and receive the full desktop projection rather than the redacted phone projection.
Repair: Remove the device.type !== undefined check so any non-desktop device defaults to the phone projection.
| return device.type !== undefined && device.type !== "mac" && device.type !== "linux"; | |
| return device.type !== "mac" && device.type !== "linux"; |
| if foreignRun == nil { | ||
| foreignRun = AidenForeignRunProjection(runId: event.runId) | ||
| scheduleForeignRunSettle(context: context, generation: generation) | ||
| } |
There was a problem hiding this comment.
[P2 · logic] iOS foreign run settle timer is not debounced across incoming replay events
Confidence: 0.88
scheduleForeignRunSettle is only called on the very first event rather than debounced across all pre-live events, firing at 400ms even if historical replay frames are still streaming.
Repair: Reschedule the settle timer on each received event while foreignRunIsLive is false so the run only transitions to live after a 400ms quiet window.
…ontract revision 24 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
ℹ️ No new issues found in the merge delta. The existing Android terminal-output rendering finding remains open, so this is not an approval.
Reviewed changes: Reviewed 310d0bee against the previous Pullfrog review at 0bae07d4, with the complete current PR diff as context.
- Merged Current Main. Preserved the incoming transcript-window and busy-composer changes alongside foreign-run observation and control.
- Integrated Cold-Load Admission. Kept Android's observer retry after successful latest-transcript acceptance, using the merged window-aware read path.
- Advanced the Contract. Moved phone run control to revision 24 across the server, shared fixture, native test expectations, API documentation and OpenAPI, following main's revision 23.
Validation passed: 176 focused TypeScript tests, 147 focused Android unit tests, and npx tsc --noEmit. iOS XCTest execution was unavailable because this Linux runner has no xcodebuild; exact-head hosted CI was still in progress when inspected.
gpt-6.1-sol | 𝕏
The release toolchain makes the memberwise init private because the parser has private stored properties, so AidenRunSSEParser's minimumEventID call failed the generic-iOS test build. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
ℹ️ No new issues found in the initializer fix. The existing Android terminal-output rendering finding remains open, so this is not an approval.
Reviewed changes: Reviewed f24cb17a against the previous Pullfrog review at 310d0bee, with the complete current PR diff as context.
- Added Explicit Parser Initialization. Made
AidenSSEFrameParserconstruction accessible while preserving the default event-ID floor of1for ordinary streams and the explicit floor of0for run snapshots.
Validation passed: an isolated probe compiled and exercised the production frame parser using Swift 6.4 in Swift 6 mode; npm run test:ios-release passed all 32 Node tests and 20 Ruby tests. Native XCTest execution was unavailable because this Linux runner has no xcodebuild; exact-head iOS build and simulator CI was still running when inspected.
gpt-6.1-sol | 𝕏
very-hermes-bot
left a comment
There was a problem hiding this comment.
Inline review — 1 finding(s) anchored to the diff. See the pinned summary comment for the overview.
| val current = projection ?: return | ||
| if (current.isEnded) return | ||
| reconnects += 1 |
There was a problem hiding this comment.
[P2 · logic] Initial foreign run observation failure halts reconnection loop and reconnect counter is not reset on Android
Confidence: 0.95
If client.currentRunEvents fails before receiving an event, projection is null and line 2252 returns immediately instead of retrying up to MAX_FOREIGN_RUN_RECONNECTS times, and reconnects is never reset to 0 when receiving frames.
Repair: Check if (projection?.isEnded == true) return to allow retries on initial failure, and reset reconnects = 0 inside feed.collect upon receiving an event.

Summary
Paired phones can now observe runs that were started on the Mac desktop, in Telegram or by the scheduler. From the phone they can Stop those runs and answer their approvals and questions.
This is Aiden Remote contract revision 21, behind feature
phone-run-control-v1. It adds two capabilities a phone can negotiate,runs:observeandruns:control. The phone requests them throughPOST /device/capabilitiesonly when the Mac advertises the feature.Server (
main/services/aiden-remote-*)GET /chats/{id}/runs/current/eventsGET /runs/{id}/events, resumed with?afterorLast-Event-IDPOST /runs/{id}/cancelPOST /runs/{id}/approvals/{aid}/respondPOST /runs/{id}/questions/{pid}/respondbot:readto observe andbot:writeto control.details, and it offersscopesonly whencanAllow(phoneMayAllow). No tool arguments or previews reach the phone.approval_resolvedorquestion_already_resolved, with the winning decision or outcome.Protocol
contract.jsonmoves to revision 21 and gains thephoneRunEventsfixture (13 frames for one run).openapi.jsonanddocs/aiden-remote-api-v1.mdare updated to match.iOS and Android
run.startedandrun.ended.run.endedis the only run-level terminal.approval_required/approval_resolvedandquestion_required/question_resolved.task_updateandagents_updateare rejected on run streams.Contract revision note
Open PR #349 also claims revision 21. If #349 merges first, this PR must claim the next free revision before it merges, and update the server, iOS, Android and fixture contracts together, as AGENTS.md requires.
Decisions
bot:readand controlling needsbot:write. Allowing a tool on an automation run also needsschedule:write; otherwise the approval is offered as deny-only.Remaining
Tests
npm run test:aiden-remote: 111 + 686 (685 pass, 1 skip) + 7 + 21, 0 fail.npx tsc --noEmit: clean.AidenRemotePhase0Tests,AidenRemoteClientTestsandAidenChatTestspass.:app:testDebugUnitTest, 36 files and 314 tests, 0 failures. This includes the newAidenForeignRunTestand new run-route tests inAidenRemoteClientTest.🤖 Generated with Claude Code
CI flake (rerun once)
sbtbiswas.AidenOnTheGo(NSMachErrorDomain -308 (ipc/mig) server died); no test case reported a failure.