Drive the composer's stop control and IME action from one derivation

While a turn was in flight the trailing composer button became the stop
control, but the text field's keyboard send action still checked only
canSend, so a prompt could be sent from the IME during a run even though
the visible control had become stop.

Add ChatFormat.composerAction(thread) -> ComposerAction.Send/Stop as the
single pure derivation and read it from both the trailing button and the
keyboard action, so the two controls can no longer disagree.
ChatFormatTest.composerControlIsStopWhileARunIsInFlightAndSendOtherwise
covers Send when idle and Stop while running. android/ only; no new
dependency.
This commit is contained in:
2026-10-16 16:26:16 +01:00
parent 609721d53b
commit 305714c30f
4 changed files with 54 additions and 5 deletions
+27
View File
@@ -2764,6 +2764,33 @@ Evidence (macOS, JDK 17, Gradle 9.7.1 `--offline`,
returned `HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
`Content-Length: 18240566`, and a streamed `GET | shasum -a 256` matched.
### Follow-up: one tested composer action (16 Oct 2026, run 143)
The stop control was still chosen by an inline `if (thread.running)` in the
composer, and the text field's keyboard send action only checked `canSend`, so a
prompt could still be sent from the IME while a turn was in flight even though the
visible control had become stop. `ChatFormat.composerAction(thread)`
(`ComposerAction.Send`/`Stop`) is now the single pure derivation the trailing
button and the keyboard action both read, so the two controls can no longer
disagree; `ChatFormatTest.composerControlIsStopWhileARunIsInFlightAndSendOtherwise`
covers it. `android/` only; no new dependency.
- Re-verified: `gradle :app:assembleDebug :app:testDebugUnitTest --offline` →
`BUILD SUCCESSFUL`, **266 tests, 0 failures** (the new composer-action case).
- **APK publish.** `app/build/outputs/apk/debug/app-debug.apk` (18,249,033 bytes,
sha256 `a9ce0cc8829513ee37fa5abaafa765307d5574f7cbd2b9cf0bc32392d0c1461e`) copied
to `~/.local/share/pipelines/data/artifacts/143/1/pipelines-debug-wip-609721d.apk`.
`curl -I http://10.0.0.249:8080/artifacts/143/1/pipelines-debug-wip-609721d.apk`
returned `HTTP/1.1 200 OK`, `Content-Type: application/vnd.android.package-archive`,
`Content-Length: 18249033`; a streamed `GET | shasum -a 256` matched.
- Not driven on a device in this pass: the constraint that the stop control be
exercised on an emulator only conflicts with this run's device note that only the
operator's Pixel (adb serial `58281FDCG000JF`) is available and no emulator may be
run, so the evidence here is the unit tests and the build rather than a fresh
screenshot. The earlier `emulator-5556` captures
(`.stop_check/stop_control_running.png`, `.stop_check/stop_control_stopped.png`)
still show the running/stopped control states.
Not verified in this pass: the live brokered server (separate lane), streaming
against real OpenCode, and attachments — unchanged from the passes above.
@@ -100,6 +100,18 @@ internal fun sessionStatusLabel(session: ChatSession, runningLocally: Boolean):
else -> "Idle"
}
/** Which action the composer's single primary control offers for a chat. */
enum class ComposerAction { Send, Stop }
/**
* The composer's primary control: while a turn is in flight the send control
* becomes the stop control (interrupt), otherwise it sends the draft. One
* derivation drives both the trailing button and the keyboard's send action, so
* a running turn can never be sent to from the other control.
*/
internal fun composerAction(thread: ChatThread): ComposerAction =
if (thread.running) ComposerAction.Stop else ComposerAction.Send
/**
* One line of a derived unified diff. [CONTEXT] lines are unchanged, [ADD] came
* from the edit's `newString` and [REMOVE] from its `oldString`.
@@ -983,6 +983,7 @@ private fun ChatComposer(
onSend: () -> Unit,
onStop: () -> Unit,
) {
val action = composerAction(thread)
Surface(color = MaterialTheme.colorScheme.surfaceContainer) {
Column(Modifier.fillMaxWidth().padding(CHAT_GUTTER)) {
if (thread.readOnly) {
@@ -1001,17 +1002,18 @@ private fun ChatComposer(
placeholder = { Text("Message the agent…") },
minLines = 1,
maxLines = 6,
keyboardActions = KeyboardActions(onSend = { if (thread.canSend) onSend() }),
keyboardActions = KeyboardActions(
onSend = { if (action == ComposerAction.Send && thread.canSend) onSend() },
),
modifier = Modifier.weight(1f),
)
if (thread.running) {
when (action) {
// While a turn is in flight the send control becomes the stop
// control, so it must interrupt rather than send the draft.
IconButton(onClick = onStop) {
ComposerAction.Stop -> IconButton(onClick = onStop) {
Icon(Icons.Default.Stop, contentDescription = "Stop", tint = MaterialTheme.colorScheme.error)
}
} else {
IconButton(onClick = onSend, enabled = thread.canSend) {
ComposerAction.Send -> IconButton(onClick = onSend, enabled = thread.canSend) {
Icon(Icons.AutoMirrored.Filled.Send, contentDescription = "Send")
}
}
@@ -74,6 +74,14 @@ class ChatFormatTest {
assertEquals("Idle", sessionStatusLabel(ChatSession(id = "s"), runningLocally = false))
}
@Test
fun composerControlIsStopWhileARunIsInFlightAndSendOtherwise() {
// While a turn is in flight the send control becomes the stop control:
// the phone's composer offers the interrupt, never a second send.
assertEquals(ComposerAction.Stop, composerAction(ChatThread(sessionId = "s", running = true)))
assertEquals(ComposerAction.Send, composerAction(ChatThread(sessionId = "s")))
}
@Test
fun toolEditDiffMarksOnlyChangedLinesAndCountsThem() {
val input = JsonObject(