Skip to content
Merged
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
4 changes: 2 additions & 2 deletions docs/parity/server.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Status values: `todo`, `partial: <what is missing>`, `done`, `n/a: <reason and w
| `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). |
| `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. |
| `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`. |
| `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. |
| `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. |
| `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`. |
| `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. |
| `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. |
Expand Down Expand Up @@ -89,7 +89,7 @@ fixtures: `server/src/testFixtures` (`WireFixture`, `ServerTestIsolation`, and `
| --- | --- | --- | --- |
| `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 |
| `OpenCodeClientFamilyTests.swift` | `OpenCodeClientFamilyTests.kt` | 11 | — |
| `OpenCodeEventDecodingTests.swift` | `OpenCodeEventDecodingTests.kt` | 10 (incl. `liveToolPayloadsAreBoundedLikeTheSettledRead`) | `reasoningFramesDecodeWithoutTheirText` (reasoning frames still carry their text) |
| `OpenCodeEventDecodingTests.swift` | `OpenCodeEventDecodingTests.kt` | 11 (incl. `liveToolPayloadsAreBoundedLikeTheSettledRead` and `reasoningFramesDecodeWithoutTheirText`) | — |
| `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 |
| `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). |
| `FirstComputerPairingTests.swift` | `FirstComputerPairingTests.kt` | 1 (`homeFoldersAreNotProjects`) | the `AppFeature` pairing tests → `:app`, starter prompts → `:feature:session` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class EventStreamPressureTests {
batch(
"ses_other",
OpenCodeLiveContentEvent.TextDelta("msg_other", 0, delta),
OpenCodeLiveContentEvent.ReasoningDelta("msg_other", 1, delta),
OpenCodeLiveContentEvent.ReasoningDelta("msg_other", 1),
OpenCodeLiveContentEvent.ToolInputDelta("msg_other", "call_1", delta),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ class AgentRevealAndOrbModelTests {
val subagent = SubagentActivity(sessionID = id, phase = SubagentActivity.Phase.running)
// Its execution started before the stream connected: only content arrives.
AgentActivityLedger.shared.record(
OpenCodeServerEvent.ContentBatch(sessionID = id, events = listOf(OpenCodeLiveContentEvent.ReasoningDelta(messageID = "m", ordinal = 0, delta = "…"))),
OpenCodeServerEvent.ContentBatch(sessionID = id, events = listOf(OpenCodeLiveContentEvent.ReasoningDelta(messageID = "m", ordinal = 0))),
now,
)
assertEquals(AgentActivity.thinking, subagent.activity(now + 1))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ class NewMessagesTests {
val store = h.store(state) {
this[Clock] = TestClock()
}
store.send(Action.ContentBatch(sessionID = "ses_away", events = listOf(OpenCodeLiveContentEvent.ReasoningDelta(messageID = "msg_a", ordinal = 0, delta = "x")))) {
store.send(Action.ContentBatch(sessionID = "ses_away", events = listOf(OpenCodeLiveContentEvent.ReasoningDelta(messageID = "msg_a", ordinal = 0)))) {
it.copy(
isExternallyActive = true, streamIsHealthy = true, streamSupportsProjection = true,
workingRun = WorkingRun(counter = 1, startID = 1, key = "ses_away", sawStart = true, startTurn = "u1", baseline = "msg_a-tool-q1"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ sealed interface OpenCodeLiveContentEvent {
) : OpenCodeLiveContentEvent
data class TextEnded(override val messageID: String, val ordinal: Int, val text: String) : OpenCodeLiveContentEvent
data class ReasoningStarted(override val messageID: String, val ordinal: Int) : OpenCodeLiveContentEvent
data class ReasoningDelta(override val messageID: String, val ordinal: Int, val delta: String) : OpenCodeLiveContentEvent
data class ReasoningEnded(override val messageID: String, val ordinal: Int, val text: String) : OpenCodeLiveContentEvent
data class ReasoningDelta(override val messageID: String, val ordinal: Int) : OpenCodeLiveContentEvent
data class ReasoningEnded(override val messageID: String, val ordinal: Int) : OpenCodeLiveContentEvent
data class ToolInputStarted(override val messageID: String, val toolID: String, val name: String) : OpenCodeLiveContentEvent
data class ToolInputDelta(override val messageID: String, val toolID: String, val delta: String) : OpenCodeLiveContentEvent
data class ToolInputEnded(override val messageID: String, val toolID: String, val text: String) : OpenCodeLiveContentEvent
Expand Down Expand Up @@ -156,8 +156,7 @@ sealed interface OpenCodeLiveContentEvent {
this is TextDelta && next is TextDelta && accumulatedText == null && next.accumulatedText == null &&
messageID == next.messageID && ordinal == next.ordinal ->
TextDelta(messageID, ordinal, delta + next.delta)
this is ReasoningDelta && next is ReasoningDelta && messageID == next.messageID && ordinal == next.ordinal ->
ReasoningDelta(messageID, ordinal, delta + next.delta)
this is ReasoningDelta && next is ReasoningDelta && messageID == next.messageID && ordinal == next.ordinal -> this
this is ToolInputDelta && next is ToolInputDelta && messageID == next.messageID && toolID == next.toolID ->
ToolInputDelta(messageID, toolID, delta + next.delta)
else -> null
Expand Down
10 changes: 2 additions & 8 deletions server/src/main/kotlin/ai/opencode/server/live/LiveEvents.kt
Original file line number Diff line number Diff line change
Expand Up @@ -574,14 +574,8 @@ private fun serverEvent(type: String, data: EventPayload?): OpenCodeServerEvent?
ordinalContent { id, ordinal -> OpenCodeLiveContentEvent.TextEnded(id, ordinal, text) }
}
"session.reasoning.started" -> ordinalContent(OpenCodeLiveContentEvent::ReasoningStarted)
"session.reasoning.delta" -> {
val delta = data?.delta ?: return null
ordinalContent { id, ordinal -> OpenCodeLiveContentEvent.ReasoningDelta(id, ordinal, delta) }
}
"session.reasoning.ended" -> {
val text = data?.text ?: return null
ordinalContent { id, ordinal -> OpenCodeLiveContentEvent.ReasoningEnded(id, ordinal, text) }
}
"session.reasoning.delta" -> ordinalContent(OpenCodeLiveContentEvent::ReasoningDelta)
"session.reasoning.ended" -> ordinalContent(OpenCodeLiveContentEvent::ReasoningEnded)
"session.tool.input.started" -> {
val name = data?.name ?: return null
toolContent { messageID, toolID, _ -> OpenCodeLiveContentEvent.ToolInputStarted(messageID, toolID, name) }
Expand Down
Loading
Loading