GeezerVison is showing github.com — Merge pull request #97 from anomalyco/port-reasoning · anomalyco/opencode-android@532cf2b
File treeExpand file treeCollapse file tree Open diff view settings drawer/src/test/kotlin/ai/opencode/feature/drawer session/src/test/kotlin/ai/opencode/feature/session
main/kotlin/ai/opencode/server test/kotlin/ai/opencode/server
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: docs/parity/server.md +2-2Lines changed: 2 additions & 2 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -17,7 +17,7 @@ Status values: `todo`, `partial: <what is missing>`, `done`, `n/a: <reason and w | 17 | 17 | | `OpenCodeClient+Capabilities.swift` | `model/PendingRequests.kt` (MCP/account/OAuth models), `live/Payloads.kt`, `live/LiveCatalog.kt` | done | `pathComponent` percent-encodes like `urlPathAllowed − "/"`; OAuth `url` is a `java.net.URI` R3 audit: routes, methods, timeouts (20/30/15 s), idempotency (OAuth start/complete `.unsafe`, MCP connect `.unsafe`/disconnect `.idempotent`), status/method mapping and copy checked. Fixed: skills sorted with numeric-aware `naturalCompare` (`localizedStandardCompare`), not a plain collator. R3 second audit: the three capability reads keep failures as values and throw in `mcp`, `skill`, `integration` order like Swift's `async let` tuple (a later read's earlier failure no longer cancels and wins). | | 18 | 18 | | `OpenCodeClient+Catalog.swift` | `live/LiveCatalog.kt` | done | Same routes, timeouts (20/15/30/60 s), idempotency; model catalog shared through `OpenCodeReadCache` R3 audit: `location[directory]` on skill/agent/command/find/model reads, find `query`/`type=file`/`limit`, `{path}`-or-string entries, command body (nil fields omitted, `.send`), switch bodies `.idempotent`, catalog cache key and swallowed `/api/model/default` failure checked; no divergence. Ported ahead of the next sync (88915116): a cold catalog reads the list and the default at once; a failed list cancels the default. | | 19 | 19 | | `OpenCodeClient+Connection.swift` | `live/LiveConnection.kt` | done | `/api/info` probe (`.once`, connection-probe evidence), pairing redemption races every redeem origin, first success cancels the rest; same failure copy R3 audit: `/api/info` `StatusPayload` probe, redeem (15 s, `.unsafe`, `.once`, no redirects, probe evidence, device name), alternates (trim `/`, drop loopback/invalid, dedupe), 401/404/last failure copy, plugin status checked; no divergence. 1ddd36b2: `pairNotificationPreview` posts `{input:{callbackURL,ref,publicKey}}` to `/api/rpc/mobile-notifications/pair` on the first HTTPS candidate only (3 s, idempotent, `.once`, no redirects) and returns `output.publicKey`; no HTTPS address throws before sending. Sync 3cea48b2 (9c94975e, bf0dbcb7): the health probe decodes `ServerInfoPayload`, waits 3.5 s (`ServerLinkStore.probeTimeout`), follows no redirects, and refuses a different server at the address (`identifies`). **Android differs from iOS (#62901):** redemption also saves the code's own addresses as `preferredURLs`. | | 20 | | -| `OpenCodeClient+Events.swift` | `OpenCodeServerEvent.kt`, `EventBatcher.kt`, `live/LiveEvents.kt` | done | Hand-rolled `data:` line reader over OkHttp (as iOS parses `bytes.lines`), 16 MiB frame cap, `_tag` failure frames, same handled-type set and event mapping, 128-event buffer → `EventStreamOverflow`. `EventBatcher` (75 ms on the `Clock` dependency, 256-event caps) is a plain object; `MarkdownStreamClient.prepare` and `AgentActivityLedger.record` become `EventBatcherHooks` (installed by transcript/session) R3 audit: envelope (`type`/`_tag`, handled set, lenient `data`, lenient inbox `item`), every event mapping, `Tool failed` default, buffer overflow log (`stream`, notice), 401/HTTP/ended copy, flush-before-finish checked. Fixed: SSE diagnostics now mark `sse_stalled` after ≥ 30 s between lines and when a stream ends on a timeout, and count line bytes as UTF-8, as iOS does. Synced to f657969b: `sessionMoved` (no folder → `messageInvalidated`), `sessionArchiveChanged`, `isToolLifecycleEvent`, `superseded` interrupts don't end the run, lenient `location`, own `session.viewed` echoes dropped through `SelfViewReceipts`. 390f157d: `EventBatcher.BUFFER_CAPACITY` 128, `capacity`/`isFocused`; under pressure (≤ half the buffer free, reading < 1 s old) an unfocused session's text/reasoning/tool-input deltas are shed, with the iOS pressure-eased/overflow log lines. `emit` returns `EventEmission` (Enqueued(remaining)/Dropped/Terminated); `subscribeEvents` counts queued events to report what's left. Sync 3cea48b2 (9c94975e, bf0dbcb7, 477a3ca5): `EventStreamWatchdog` (4.5 s to open, 45 s from the last line, on `NetworkRetry.clock` or the live clock) ends a stream as timed out (`sse_watchdog`); `PoolResetWatch` ends it as interrupted when the pools reset; each line notes stream activity. The stream watchdog runs on Dispatchers.Default, so its live-clock deadlines are real seconds even when a test collects the stream on a virtual-time dispatcher (CI flake in NewMessagesReceiptTests). Sync 03adf07a (a099f459, 6a9a30c7): every line notes stream activity for the server (`noteStreamActivity(server)`), and the stream notes its end (`noteStreamEnded`) on close, on failure and on cancellation, so `ServerLink` knows which address has a live stream. iOS #323: a delta carries its part's `accumulatedText` when the connection saw the part start; only focused sessions prepare Markdown; up to 32 offscreen accumulators, 512 KiB of UTF-8 per offscreen part; a discarded prefix sends no deltas until `TextEnded`; more than 1,024 unfinished parts (discarded included) ends the stream with `EventStreamOverflow` through `onOverflow` (iOS `finish(throwing:)`). Android evicts the oldest started accumulator; iOS evicts by sorted ID. Android differs on purpose: `model.updated` and `provider.updated` decode to `ModelsChanged`, `agent.updated` to `AgentsChanged` (the server changes its catalogs as plugins finish loading, after config edits, installs and logins); a `ModelsChanged` forgets the server's cached model catalogs (`OpenCodeReadCache.forgetModelCatalogs`) before it is delivered. Sync 911ab132 (72a78460): live tool input, output and metadata are bounded like REST (`OpenCodeToolBounds`); reasoning frames still carry their text. | | | 20 | +| `OpenCodeClient+Events.swift` | `OpenCodeServerEvent.kt`, `EventBatcher.kt`, `live/LiveEvents.kt` | done | Hand-rolled `data:` line reader over OkHttp (as iOS parses `bytes.lines`), 16 MiB frame cap, `_tag` failure frames, same handled-type set and event mapping, 128-event buffer → `EventStreamOverflow`. `EventBatcher` (75 ms on the `Clock` dependency, 256-event caps) is a plain object; `MarkdownStreamClient.prepare` and `AgentActivityLedger.record` become `EventBatcherHooks` (installed by transcript/session) R3 audit: envelope (`type`/`_tag`, handled set, lenient `data`, lenient inbox `item`), every event mapping, `Tool failed` default, buffer overflow log (`stream`, notice), 401/HTTP/ended copy, flush-before-finish checked. Fixed: SSE diagnostics now mark `sse_stalled` after ≥ 30 s between lines and when a stream ends on a timeout, and count line bytes as UTF-8, as iOS does. Synced to f657969b: `sessionMoved` (no folder → `messageInvalidated`), `sessionArchiveChanged`, `isToolLifecycleEvent`, `superseded` interrupts don't end the run, lenient `location`, own `session.viewed` echoes dropped through `SelfViewReceipts`. 390f157d: `EventBatcher.BUFFER_CAPACITY` 128, `capacity`/`isFocused`; under pressure (≤ half the buffer free, reading < 1 s old) an unfocused session's text/reasoning/tool-input deltas are shed, with the iOS pressure-eased/overflow log lines. `emit` returns `EventEmission` (Enqueued(remaining)/Dropped/Terminated); `subscribeEvents` counts queued events to report what's left. Sync 3cea48b2 (9c94975e, bf0dbcb7, 477a3ca5): `EventStreamWatchdog` (4.5 s to open, 45 s from the last line, on `NetworkRetry.clock` or the live clock) ends a stream as timed out (`sse_watchdog`); `PoolResetWatch` ends it as interrupted when the pools reset; each line notes stream activity. The stream watchdog runs on Dispatchers.Default, so its live-clock deadlines are real seconds even when a test collects the stream on a virtual-time dispatcher (CI flake in NewMessagesReceiptTests). Sync 03adf07a (a099f459, 6a9a30c7): every line notes stream activity for the server (`noteStreamActivity(server)`), and the stream notes its end (`noteStreamEnded`) on close, on failure and on cancellation, so `ServerLink` knows which address has a live stream. iOS #323: a delta carries its part's `accumulatedText` when the connection saw the part start; only focused sessions prepare Markdown; up to 32 offscreen accumulators, 512 KiB of UTF-8 per offscreen part; a discarded prefix sends no deltas until `TextEnded`; more than 1,024 unfinished parts (discarded included) ends the stream with `EventStreamOverflow` through `onOverflow` (iOS `finish(throwing:)`). Android evicts the oldest started accumulator; iOS evicts by sorted ID. Android differs on purpose: `model.updated` and `provider.updated` decode to `ModelsChanged`, `agent.updated` to `AgentsChanged` (the server changes its catalogs as plugins finish loading, after config edits, installs and logins); a `ModelsChanged` forgets the server's cached model catalogs (`OpenCodeReadCache.forgetModelCatalogs`) before it is delivered. Sync 911ab132 (72a78460): live tool input, output and metadata are bounded like REST (`OpenCodeToolBounds`); reasoning frames drop their text: `ReasoningDelta`/`ReasoningEnded` carry message and ordinal, so coalesced deltas no longer concatenate text. | | 21 | 21 | | `OpenCodeClient+Family.swift` | `live/LiveFamily.kt` | done | Home snapshot (3 parallel reads), active ancestry (batches of 6, permits of 2), family BFS (6 at a time, cap 100, in-order commit), running-descendant search (24 lookups) R3 audit: home snapshot query (`parentID=null`, `desc`, `50`), root parent caching, ancestry batches/permits, family BFS commit order and cap, 24-lookup descendant search, `Untitled session` (now `SessionTitle.placeholder` in `serverTitle`), ms→`Instant`, copy and the `network` notice checked; no divergence. R3 second audit: home snapshot reads (projects, sessions, active) and the family walk's active read keep failures as values and throw in Swift's `async let` order (projects first; the walk's own error before the active read's) instead of the first to fail cancelling the rest. Synced to f657969b: home snapshot asks for `archived=false` and drops archived roots. Sync p244 (iOS e8e7cc13..da365285): the home snapshot decodes `SessionsPayload` and keeps its `nextCursor`. | | 22 | 22 | | `OpenCodeClient+Files.swift` | `live/LiveFiles.kt` | done | Upload: `/api/info` tmp → `/api/experimental/fs/write`, `.send` policy, progress about once per percent (≥ 64 KB). Markdown images return validated bytes (≤ 25 MB) via `MarkdownImageCache` (byte LRU, 32 MB); no bitmap decode here. Directory listing resolves/normalises paths, hidden last, numeric-aware order R3 audit: Markdown image key/data-URL limits/server-read correlation and contact, upload path, `/api/info` 404 → unsupported, `.send` policy, 120 s idle timeout, bare-404 check, 401 copy, `Upload:` notice (no URL), listing copy (non-401) and resolution checked. Fixed: one collator per sort instead of one per comparison in `naturalCompare`. R3 second audit: `decodeBase64` (data-URL images, inline files, tool images) rejects unpadded input like Foundation's `Data(base64Encoded:)`. Sync 3cea48b2 (9c94975e, bf0dbcb7): markdown images load on `resolve`; uploads route each attempt and forget the address after a transport error. Sync 03adf07a (6a9a30c7): uploads and markdown image loads take the send time first; an unsent request forgets the address, any other transport failure goes through `requestFailed(server, url, sentAt)`, which keeps an address whose stream spoke after the request went. | | 23 | 23 | | `OpenCodeClient+Models.swift` | `model/Models.kt`, `model/Project.kt` | done | `OpenCodeSession.updatedAt` is `Instant` (ms epoch double → nanos kept). `OpenCodeDelivery.symbolName` (SF Symbols) n/a R3 audit: short-name prefixes/tier words, variant labels/order, `SessionActivity`, shell status fallback checked; no divergence. Title fallback (Ryan-approved product change, iOS draft PR `feat/session-title-fallback`): the stored title is `serverTitle` (JSON key `title`), plus `firstPrompt`; `title` is computed by `SessionTitle.display`. Synced to f657969b: `OpenCodeProject.isHomeFolder`, `OpenCodeSession.archivedMilliseconds`/`isArchived`. Sync to fc25a553 (64fec72d): `List<OpenCodeModel>.model(ref)` matches the catalogue key only (no API-id fallback), so an alias keeps its own entry. Sync p244 (iOS e8e7cc13..da365285): `OpenCodeHomeSnapshot.nextCursor`, `OpenCodeSessionPage`, `OpenCodeSessionPageRequest` (`Search`/`After`). Sync 03adf07a (c8b93a9d): `Hashable` for the parsed-row cache key is n/a: Kotlin data classes already hash structurally. | | @@ -89,7 +89,7 @@ fixtures: `server/src/testFixtures` (`WireFixture`, `ServerTestIsolation`, and ` | 89 | 89 | | --- | --- | --- | --- | | 90 | 90 | | `OpenCodeClientDecodingTests.swift` | `OpenCodeClientDecodingTests.kt` | 38 of 39 | `aFailedRunShowsItsStepsErrorOnceNotTheIdleRepeat` → `:feature:transcript` (`TranscriptEntry`); voice/transcript halves of `completeHomeSnapshotResolves…`, `aRetryingStepCountsDown…`, `decodesCompactionStatesLikeTheTUI` → their modules. `liveServerReadContract`/`liveServerTransferDiagnostics` opt-in (`OPENCODE_LIVE_*`); read contract verified against session-lab | | 91 | 91 | | `OpenCodeClientFamilyTests.swift` | `OpenCodeClientFamilyTests.kt` | 11 | — | | 92 | | -| `OpenCodeEventDecodingTests.swift` | `OpenCodeEventDecodingTests.kt` | 10 (incl. `liveToolPayloadsAreBoundedLikeTheSettledRead`) | `reasoningFramesDecodeWithoutTheirText` (reasoning frames still carry their text) | | | 92 | +| `OpenCodeEventDecodingTests.swift` | `OpenCodeEventDecodingTests.kt` | 11 (incl. `liveToolPayloadsAreBoundedLikeTheSettledRead` and `reasoningFramesDecodeWithoutTheirText`) | — | | 93 | 93 | | `NewMessagesReceiptTests.swift` | `NewMessagesReceiptTests.kt`, `feature/drawer/src/test/.../NewMessagesReceiptTests.kt` | 4 of 4 (`aReceiptInFlightAcrossAConnectStillSwallowsItsEcho`, `receiptsMatchOnceExpireAfterTheirGraceAndStayPerServer` here; the 2 `HomeFeature` tests `aFailedReceiptLeavesADesktopReadAtTheSameIdleToClearNew`, `aReconnectDropsAnAnsweredReceiptSoTheNextReadClearsNew` in `:feature:drawer`) | done. The drawer half drives `SessionTapped` against a `WireFixture` (`/view` 500 or 204, one-event stream), in real time, as the fixture answers on OkHttp's threads | | 94 | 94 | | `WireRequestTests.swift` | `WireRequestTests.kt` | 22 (incl. `aSendToAFolderThatIsGoneSaysSo`, `movingASessionPostsItsNewFolderOnce`) | `restoringACallbackWithoutItsDeviceKeyMintsANewCapability`, `oldOrForeignNotificationCapabilitiesNeverReachAPrompt` (1ddd36b2, `SessionNotifications`) → `:feature:system` `notifications/WireRequestTests.kt` Ported ahead of the next sync (88915116): `modelCatalogReadsTheListAndDefaultTogether`; the cold-boot test compares routes sorted. Android adds `homeAttentionAsksHotDirectoriesAtOnce` for 417e5b4c (iOS has no test for it). | | 95 | 95 | | `FirstComputerPairingTests.swift` | `FirstComputerPairingTests.kt` | 1 (`homeFoldersAreNotProjects`) | the `AppFeature` pairing tests → `:app`, starter prompts → `:feature:session` | | |
Collapse file Copy file name to clipboardExpand all lines: feature/drawer/src/test/kotlin/ai/opencode/feature/drawer/EventStreamPressureTests.kt +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -84,7 +84,7 @@ class EventStreamPressureTests { | 84 | 84 | batch( | 85 | 85 | "ses_other", | 86 | 86 | OpenCodeLiveContentEvent.TextDelta("msg_other", 0, delta), | 87 | | - OpenCodeLiveContentEvent.ReasoningDelta("msg_other", 1, delta), | | 87 | + OpenCodeLiveContentEvent.ReasoningDelta("msg_other", 1), | 88 | 88 | OpenCodeLiveContentEvent.ToolInputDelta("msg_other", "call_1", delta), | 89 | 89 | ) | 90 | 90 | } | |
Collapse file Copy file name to clipboardExpand all lines: feature/session/src/test/kotlin/ai/opencode/feature/session/AgentRevealAndOrbModelTests.kt +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -490,7 +490,7 @@ class AgentRevealAndOrbModelTests { | 490 | 490 | val subagent = SubagentActivity(sessionID = id, phase = SubagentActivity.Phase.running) | 491 | 491 | // Its execution started before the stream connected: only content arrives. | 492 | 492 | AgentActivityLedger.shared.record( | 493 | | - OpenCodeServerEvent.ContentBatch(sessionID = id, events = listOf(OpenCodeLiveContentEvent.ReasoningDelta(messageID = "m", ordinal = 0, delta = "…"))), | | 493 | + OpenCodeServerEvent.ContentBatch(sessionID = id, events = listOf(OpenCodeLiveContentEvent.ReasoningDelta(messageID = "m", ordinal = 0))), | 494 | 494 | now, | 495 | 495 | ) | 496 | 496 | assertEquals(AgentActivity.thinking, subagent.activity(now + 1)) | |
Collapse file Copy file name to clipboardExpand all lines: feature/session/src/test/kotlin/ai/opencode/feature/session/NewMessagesTests.kt +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -561,7 +561,7 @@ class NewMessagesTests { | 561 | 561 | val store = h.store(state) { | 562 | 562 | this[Clock] = TestClock() | 563 | 563 | } | 564 | | - store.send(Action.ContentBatch(sessionID = "ses_away", events = listOf(OpenCodeLiveContentEvent.ReasoningDelta(messageID = "msg_a", ordinal = 0, delta = "x")))) { | | 564 | + store.send(Action.ContentBatch(sessionID = "ses_away", events = listOf(OpenCodeLiveContentEvent.ReasoningDelta(messageID = "msg_a", ordinal = 0)))) { | 565 | 565 | it.copy( | 566 | 566 | isExternallyActive = true, streamIsHealthy = true, streamSupportsProjection = true, | 567 | 567 | workingRun = WorkingRun(counter = 1, startID = 1, key = "ses_away", sawStart = true, startTurn = "u1", baseline = "msg_a-tool-q1"), | |
Collapse file Copy file name to clipboardExpand all lines: server/src/main/kotlin/ai/opencode/server/OpenCodeServerEvent.kt +3-4Lines changed: 3 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -100,8 +100,8 @@ sealed interface OpenCodeLiveContentEvent { | 100 | 100 | ) : OpenCodeLiveContentEvent | 101 | 101 | data class TextEnded(override val messageID: String, val ordinal: Int, val text: String) : OpenCodeLiveContentEvent | 102 | 102 | data class ReasoningStarted(override val messageID: String, val ordinal: Int) : OpenCodeLiveContentEvent | 103 | | - data class ReasoningDelta(override val messageID: String, val ordinal: Int, val delta: String) : OpenCodeLiveContentEvent | 104 | | - data class ReasoningEnded(override val messageID: String, val ordinal: Int, val text: String) : OpenCodeLiveContentEvent | | 103 | + data class ReasoningDelta(override val messageID: String, val ordinal: Int) : OpenCodeLiveContentEvent | | 104 | + data class ReasoningEnded(override val messageID: String, val ordinal: Int) : OpenCodeLiveContentEvent | 105 | 105 | data class ToolInputStarted(override val messageID: String, val toolID: String, val name: String) : OpenCodeLiveContentEvent | 106 | 106 | data class ToolInputDelta(override val messageID: String, val toolID: String, val delta: String) : OpenCodeLiveContentEvent | 107 | 107 | data class ToolInputEnded(override val messageID: String, val toolID: String, val text: String) : OpenCodeLiveContentEvent | @@ -156,8 +156,7 @@ sealed interface OpenCodeLiveContentEvent { | 156 | 156 | this is TextDelta && next is TextDelta && accumulatedText == null && next.accumulatedText == null && | 157 | 157 | messageID == next.messageID && ordinal == next.ordinal -> | 158 | 158 | TextDelta(messageID, ordinal, delta + next.delta) | 159 | | - this is ReasoningDelta && next is ReasoningDelta && messageID == next.messageID && ordinal == next.ordinal -> | 160 | | - ReasoningDelta(messageID, ordinal, delta + next.delta) | | 159 | + this is ReasoningDelta && next is ReasoningDelta && messageID == next.messageID && ordinal == next.ordinal -> this | 161 | 160 | this is ToolInputDelta && next is ToolInputDelta && messageID == next.messageID && toolID == next.toolID -> | 162 | 161 | ToolInputDelta(messageID, toolID, delta + next.delta) | 163 | 162 | else -> null | |
Collapse file Copy file name to clipboardExpand all lines: server/src/main/kotlin/ai/opencode/server/live/LiveEvents.kt +2-8Lines changed: 2 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -574,14 +574,8 @@ private fun serverEvent(type: String, data: EventPayload?): OpenCodeServerEvent? | 574 | 574 | ordinalContent { id, ordinal -> OpenCodeLiveContentEvent.TextEnded(id, ordinal, text) } | 575 | 575 | } | 576 | 576 | "session.reasoning.started" -> ordinalContent(OpenCodeLiveContentEvent::ReasoningStarted) | 577 | | - "session.reasoning.delta" -> { | 578 | | - val delta = data?.delta ?: return null | 579 | | - ordinalContent { id, ordinal -> OpenCodeLiveContentEvent.ReasoningDelta(id, ordinal, delta) } | 580 | | - } | 581 | | - "session.reasoning.ended" -> { | 582 | | - val text = data?.text ?: return null | 583 | | - ordinalContent { id, ordinal -> OpenCodeLiveContentEvent.ReasoningEnded(id, ordinal, text) } | 584 | | - } | | 577 | + "session.reasoning.delta" -> ordinalContent(OpenCodeLiveContentEvent::ReasoningDelta) | | 578 | + "session.reasoning.ended" -> ordinalContent(OpenCodeLiveContentEvent::ReasoningEnded) | 585 | 579 | "session.tool.input.started" -> { | 586 | 580 | val name = data?.name ?: return null | 587 | 581 | toolContent { messageID, toolID, _ -> OpenCodeLiveContentEvent.ToolInputStarted(messageID, toolID, name) } | |
|