Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.
fix: ensure finish_task prevents execution of subsequent batched tool calls and update documentation
Rishabh Bajpai6838408aa15a
diff --git a/app/src/main/java/com/gotcha/agent/AgentEngine.kt b/app/src/main/java/com/gotcha/agent/AgentEngine.ktindex f620da1..b30d4fb 100644--- a/app/src/main/java/com/gotcha/agent/AgentEngine.kt+++ b/app/src/main/java/com/gotcha/agent/AgentEngine.kt@@ -496,6 +496,11 @@ class AgentEngine(content = JsonPrimitive("Reported to the user. The turn ends here."),toolCallId = call.id)+ // finish_task is a terminal signal: any sibling tool calls+ // past it would still execute their side effects, then sit+ // unread in history while the engine returns on finishSummary.+ // Break out so the user sees only what finish_task reported.+ break} else if (result.success && result.message.startsWith("CONFIRM_UNINSTALL:")) {handleUninstallConfirm(call, result)} else if (result.success && result.message.startsWith("CONFIRM_DELETE_ALARM:")) {diff --git a/app/src/main/java/com/gotcha/tools/ToolExecutor.kt b/app/src/main/java/com/gotcha/tools/ToolExecutor.ktindex a1d78f0..5bc06e1 100644--- a/app/src/main/java/com/gotcha/tools/ToolExecutor.kt+++ b/app/src/main/java/com/gotcha/tools/ToolExecutor.kt@@ -522,7 +522,10 @@ class ToolExecutor(val owners = com.gotcha.connectors.ConnectorCatalog.ownersOf(name).joinToString(" or ") { it.displayName }val suffix = if (owners.isBlank()) {- "The connector it needs is not set up."+ // Defensive fallback: today every hidden tool is owned by either a connector+ // or a capability, so this branch is unreachable. Keep a generic message in+ // case a future catalog change leaves a hidden tool with no owner.+ "It is currently unavailable."} else {"It needs $owners, which is not connected or is switched off."}diff --git a/app/src/main/java/com/gotcha/ui/SettingsScreen.kt b/app/src/main/java/com/gotcha/ui/SettingsScreen.ktindex 38a477c..030bfe0 100644--- a/app/src/main/java/com/gotcha/ui/SettingsScreen.kt+++ b/app/src/main/java/com/gotcha/ui/SettingsScreen.kt@@ -1546,6 +1546,9 @@ fun SettingsScreen()}+ // Centered rather than bottom-aligned: under the keyboard area BottomCenter+ // reads as a stray toast instead of feedback attached to the field that+ // triggered the test (PR #60 review).OverlayMessage(message = overlay, modifier = Modifier.align(Alignment.Center))} // Box}@@ -1767,14 +1770,6 @@ private fun TtsVoicePicker(val defaultVoiceLabel = selectedModelObj?.defaultVoice?: voicesList.firstOrNull()?.id?: "the provider's default"- android.util.Log.d(- "TtsVoicePicker",- "render: selectedModel='$selectedModel', " +- "availableModels.size=${availableModels.size}, " +- "matched=${selectedModelObj?.id ?: "<none>"}, " +- "matchedVoices.size=${selectedModelObj?.voices?.size ?: 0}, " +- "voicesList.size=${voicesList.size}, selectedVoice='$selectedVoice'"- )ExposedDropdownMenuBox(expanded = expanded,onExpandedChange = onExpandedChangediff --git a/app/src/test/java/com/gotcha/agent/AgentLoopTest.kt b/app/src/test/java/com/gotcha/agent/AgentLoopTest.ktindex 3fef58e..95a57ea 100644--- a/app/src/test/java/com/gotcha/agent/AgentLoopTest.kt+++ b/app/src/test/java/com/gotcha/agent/AgentLoopTest.kt@@ -207,6 +207,68 @@ class AgentLoopTest {)}+ /**+ * `finish_task` is a terminal signal: any sibling tool calls the model bundles+ * with it must NOT execute, otherwise the user only hears the summary while a+ * side effect (file write, sub-agent launch, anything else) runs silently.+ */+ @Test+ fun `tool calls batched after finish_task are skipped`() = runTest {+ val sideEffect = File(workDir, "should-not-exist.txt")+ server.enqueue(+ MockResponse().setBody(+ """+ {"choices":[{"message":{"role":"assistant","tool_calls":[+ {"id":"call_finish","type":"function","function":{"name":"finish_task",+ "arguments":"{\"summary\":\"All done.\"}"}},+ {"id":"call_write","type":"function","function":{"name":"write_file",+ "arguments":"{\"path\":\"${sideEffect.absolutePath}\",\"content\":\"sneaky\"}"}}+ ]}}]}+ """.trimIndent()+ )+ )++ engine.run(AgentMode.OPERATOR)++ assertEquals(1, server.requestCount)+ assertEquals("All done.", events.assistantReplies.lastOrNull())+ assertFalse(+ "tool calls ordered after finish_task must not run",+ sideEffect.exists()+ )+ }++ /**+ * The mirror image: a tool call placed BEFORE `finish_task` in the same batch+ * must still run, so the loop persists the effect the user asked for and the+ * summary describes what actually happened.+ */+ @Test+ fun `tool calls batched before finish_task still run`() = runTest {+ val kept = File(workDir, "kept.txt")+ server.enqueue(+ MockResponse().setBody(+ """+ {"choices":[{"message":{"role":"assistant","tool_calls":[+ {"id":"call_write","type":"function","function":{"name":"write_file",+ "arguments":"{\"path\":\"${kept.absolutePath}\",\"content\":\"kept\"}"}},+ {"id":"call_finish","type":"function","function":{"name":"finish_task",+ "arguments":"{\"summary\":\"Wrote it.\"}"}}+ ]}}]}+ """.trimIndent()+ )+ )++ engine.run(AgentMode.OPERATOR)++ assertEquals(1, server.requestCount)+ assertEquals("Wrote it.", events.assistantReplies.lastOrNull())+ assertTrue(+ "tool calls ordered before finish_task must still run",+ kept.isFile && kept.readText() == "kept"+ )+ }+/*** The issue #20 loop: the model delegates, gets a prose report back, cannot see* the screen the sub-agent left behind, and delegates a reworded copy of the