Route the stop control's interrupt through one tested builder

Extract the single chat_interrupt frame into ChatProtocol.interruptRequest and
have PipelinesRepository.chatInterrupt send it, so production and its unit test
share the one wire shape instead of the repository building it inline.

Add chatInterruptRequestCarriesTheRunningSession, which asserts the frame the
stop control sends is chat_interrupt carrying the running session's id (and no
chat prompt/reply) and that it survives the client's JSON round-trip.
Document the slice and its emulator-5556 evidence in android/README.md.
This commit is contained in:
2026-10-16 15:31:04 +01:00
parent e2f306b8bd
commit 78d5bd38fc
4 changed files with 80 additions and 1 deletions
+49
View File
@@ -2717,3 +2717,52 @@ Not verified in this pass: the live brokered server (separate lane), streaming
against real OpenCode, and attachments — unchanged from the passes above.
`:app:lintDebug` still cannot run here (the Gradle JVM's `25.0.4.1` version
string is rejected by AGP 8.7.2 lint), unchanged from the slices above.
## Stopping a running turn (16 Oct 2026)
The composer already swapped its send control for a red `Icons.stop` while a turn
ran and `AppViewModel.stopChat` already sent `chat_interrupt`; the slice was
missing the proof the task asks for — a unit test pinning the interrupt frame —
so this pass adds that seam and the on-device capture. `android/` only; no new
dependency (still just the declared `material-icons-extended`), no Pipelines
server/Go/installer/Docker file touched, no run started from the app, and
`emulator-5556` only (lane A's `emulator-5554` was never addressed).
- **One interrupt frame.** `ChatProtocol.interruptRequest(sessionId)` builds the
single `chat_interrupt` frame (a `ChatQuery` carrying the session id);
`PipelinesRepository.chatInterrupt` sends it, so the wire shape is no longer
constructed inline where only production can see it.
- **The stopped state is honest.** On a successful interrupt the thread settles
(`running = false`, no error) and the composer's send control returns; only a
failing call (or a server-pushed error frame) sets the conversation's error, so
a stop the server accepted is never shown as a failure.
Evidence (macOS, JDK 17, Gradle 9.7.1 `--offline`,
`ANDROID_HOME=/Users/alan/Library/Android/sdk`):
- `gradle :app:assembleDebug :app:testDebugUnitTest --offline` → `BUILD
SUCCESSFUL`; the JUnit XML totals **255 tests, 0 failures, 0 errors, 0
skipped** (new `chatInterruptRequestCarriesTheRunningSession`, which asserts the
frame the stop control sends is `chat_interrupt` for the running session and
survives the client's JSON round-trip).
- The debug APK was installed on `emulator-5556` only and driven against
`.stop_check/chat_stub_hold.py` (a stdlib `/connect` WebSocket double that holds
the turn open until `chat_interrupt`; test scaffolding, not the app) with
`uiautomator dump`/`input tap`; captures validated with
`android/scripts/capture_png.sh -s emulator-5556`:
`stop_control_running.png` shows the running turn (`Working… · 11s`) with the
composer's send control replaced by the red stop control (bottom-right, in thumb
reach) and the top-bar stop action; `stop_control_stopped.png` shows the same
chat after the stop was pressed — the indicator gone, the send control back, and
no error text (the server acknowledged the interrupt). The stub log recorded
exactly one `chat_interrupt`. `adb -s emulator-5556 logcat -d` held 0
`FATAL EXCEPTION` and 0 `E AndroidRuntime` during the sweep.
- **APK publish.** `app-debug.apk` (18,240,566 bytes, sha256
`56abfb2c59a9c09fabbe32d7de4f0164cdc852cece4b7df3655dd0c233256248`) copied to
`~/.local/share/pipelines/data/artifacts/135/1/pipelines-debug-wip-e2f306b.apk`;
`curl -I http://10.0.0.249:8080/artifacts/135/1/pipelines-debug-wip-e2f306b.apk`
returned `HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
`Content-Length: 18240566`, and a streamed `GET | shasum -a 256` matched.
Not verified in this pass: the live brokered server (separate lane), streaming
against real OpenCode, and attachments — unchanged from the passes above.
@@ -8,6 +8,7 @@ import kotlinx.serialization.json.JsonElement
import net.awan.pipelines.data.protocol.ChatCreateRequest
import net.awan.pipelines.data.protocol.ChatMessage
import net.awan.pipelines.data.protocol.ChatPromptRequest
import net.awan.pipelines.data.protocol.ChatProtocol
import net.awan.pipelines.data.protocol.ChatQuery
import net.awan.pipelines.data.protocol.ChatReplyRequest
import net.awan.pipelines.data.protocol.ChatSession
@@ -174,7 +175,7 @@ class PipelinesRepository(
suspend fun chatInterrupt(sessionId: String) {
if (sessionId.isBlank()) throw ProtocolException("Select a chat session first.")
client.call(Message(type = Protocol.CHAT_INTERRUPT, chatQuery = ChatQuery(sessionId = sessionId)))
client.call(ChatProtocol.interruptRequest(sessionId))
}
suspend fun chatReply(sessionId: String, requestId: String, decision: String, message: String = "") {
@@ -195,4 +195,12 @@ object ChatProtocol {
TOOL_STREAMING, TOOL_RUNNING -> true
else -> false
}
/**
* The `chat_interrupt` frame the composer's stop control sends: the server
* aborts the in-flight turn for [sessionId]. Built here (not inline in the
* repository) so production and its unit test share the one wire shape.
*/
fun interruptRequest(sessionId: String): Message =
Message(type = Protocol.CHAT_INTERRUPT, chatQuery = ChatQuery(sessionId = sessionId))
}
@@ -202,6 +202,27 @@ class ChatProtocolTest {
assertEquals(ChatProtocol.DECISION_ONCE, decodedReply.chatReply!!.decision)
}
/**
* The stop control's interrupt request: pressing it while a turn is in flight
* must send a `chat_interrupt` carrying the running session's id and nothing
* else, and the frame must survive the wire round-trip the client performs.
* Uses the same [ChatProtocol.interruptRequest] builder the repository sends,
* so this test cannot drift from the production frame.
*/
@Test
fun chatInterruptRequestCarriesTheRunningSession() {
val request = ChatProtocol.interruptRequest("ses_1")
assertEquals(Protocol.CHAT_INTERRUPT, request.type)
assertEquals("ses_1", request.chatQuery!!.sessionId)
val encoded = PipelinesJson.encodeToString(Message.serializer(), request.copy(id = "android-9"))
val decoded = PipelinesJson.decodeFromString(Message.serializer(), encoded)
assertEquals(Protocol.CHAT_INTERRUPT, decoded.type)
assertEquals("ses_1", decoded.chatQuery!!.sessionId)
assertNull(decoded.chatPrompt)
assertNull(decoded.chatReply)
}
/** A non-chat envelope leaves every chat field null, so the two never cross-talk. */
@Test
fun nonChatEnvelopeHasNoChatPayload() {