Skip to content

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.

Review fixes: agent tool overlap parity, intent zone, test nits

Rishabh Bajpaic8e2a754e973
diff --git a/app/src/main/java/com/gotcha/notifications/LocalNotificationScheduler.kt b/app/src/main/java/com/gotcha/notifications/LocalNotificationScheduler.kt
index 720b017..110d5ce 100644
--- a/app/src/main/java/com/gotcha/notifications/LocalNotificationScheduler.kt
+++ b/app/src/main/java/com/gotcha/notifications/LocalNotificationScheduler.kt
@@ -100,10 +100,16 @@ class NotificationRescheduleReceiver : BroadcastReceiver() {
// which may advance past (no MISSED record) or re-arm (a repeat)
// occurrences the clock move invalidated.
if (intent.action == Intent.ACTION_TIMEZONE_CHANGED || intent.action == Intent.ACTION_TIME_CHANGED) {
+ // Prefer the zone the broadcast names: the JVM default can
+ // lag it on some phones. Fall back to the default when the
+ // extra is missing or not a zone id.
+ val zone = intent.getStringExtra("time-zone")
+ ?.let { runCatching { ZoneId.of(it) }.getOrNull() }
+ ?: ZoneId.systemDefault()
runCatching {
ScheduledTaskStore(app).rebaseForZoneChange(
System.currentTimeMillis(),
- ZoneId.systemDefault()
+ zone
)
}.onFailure { Log.w(TAG, "Scheduled task rebase failed", it) }
}
diff --git a/app/src/main/java/com/gotcha/scheduled/ScheduledTask.kt b/app/src/main/java/com/gotcha/scheduled/ScheduledTask.kt
index 44b7708..72e196c 100644
--- a/app/src/main/java/com/gotcha/scheduled/ScheduledTask.kt
+++ b/app/src/main/java/com/gotcha/scheduled/ScheduledTask.kt
@@ -159,6 +159,7 @@ fun nextOccurrence(task: ScheduledTask, after: Long, zone: ZoneId): Long? {
val interval = task.repeat.interval.coerceIn(1, ScheduledTask.MAX_INTERVAL).toLong()
val afterLocal = LocalDateTime.ofInstant(Instant.ofEpochMilli(after), zone)
return when (task.repeat.kind) {
+ // Handled above; kept for compiler exhaustiveness.
RepeatKind.NONE -> null
RepeatKind.HOURLY -> {
// Hours are counted in real time, so a summer-time change does not
diff --git a/app/src/main/java/com/gotcha/tools/ScheduledTaskTool.kt b/app/src/main/java/com/gotcha/tools/ScheduledTaskTool.kt
index 67e5d62..36bde4d 100644
--- a/app/src/main/java/com/gotcha/tools/ScheduledTaskTool.kt
+++ b/app/src/main/java/com/gotcha/tools/ScheduledTaskTool.kt
@@ -14,6 +14,7 @@ import com.gotcha.scheduled.ScheduledTask
import com.gotcha.scheduled.ScheduledTaskPlanner
import com.gotcha.scheduled.ScheduledTaskScheduler
import com.gotcha.scheduled.ScheduledTaskStore
+import com.gotcha.scheduled.isWallTimeFuture
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonArray
@@ -94,7 +95,7 @@ class ScheduledTaskTool(
"Invalid 'start' \"$startText\": use the phone's local time as YYYY-MM-DDTHH:MM, e.g. 2026-10-19T08:00."
)
val repeat = parseRepeat(args).getOrElse { return ToolResult.error(it.message.orEmpty()) }
- if (repeat.kind == RepeatKind.NONE && start.atZone(zone()).toInstant().toEpochMilli() <= clock()) {
+ if (repeat.kind == RepeatKind.NONE && !isWallTimeFuture(start, zone(), clock())) {
return ToolResult.error("That time has already passed. Pick a time in the future, or a repeat rule.")
}
if (store.all().count { it.createdByAgent } >= MAX_AGENT_TASKS) {
diff --git a/app/src/main/java/com/gotcha/ui/ScheduledTasksScreen.kt b/app/src/main/java/com/gotcha/ui/ScheduledTasksScreen.kt
index 7c2fb1a..1b83483 100644
--- a/app/src/main/java/com/gotcha/ui/ScheduledTasksScreen.kt
+++ b/app/src/main/java/com/gotcha/ui/ScheduledTasksScreen.kt
@@ -598,7 +598,7 @@ private fun TaskEditor(
(kind == RepeatKind.HOURLY || kind == RepeatKind.DAILY) &&
(every == null || every !in 1..ScheduledTask.MAX_INTERVAL) -> badInterval
kind == RepeatKind.NONE &&
- !isWallTimeFuture(startAt, ZoneId.systemDefault(), Instant.now().toEpochMilli()) -> pastTime
+ !isWallTimeFuture(startAt, ZoneId.systemDefault(), System.currentTimeMillis()) -> pastTime
AttachmentFiles.documentChars(files) > ComposerAttachment.MAX_TOTAL_DOCUMENT_CHARS -> tooMuchText
else -> ""
}
diff --git a/app/src/test/java/com/gotcha/scheduled/ScheduledTaskPlannerTest.kt b/app/src/test/java/com/gotcha/scheduled/ScheduledTaskPlannerTest.kt
index 1c6dd55..2ce93b6 100644
--- a/app/src/test/java/com/gotcha/scheduled/ScheduledTaskPlannerTest.kt
+++ b/app/src/test/java/com/gotcha/scheduled/ScheduledTaskPlannerTest.kt
@@ -323,7 +323,10 @@ class ScheduledTaskPlannerTest {
assertEquals(hourly, ScheduledTaskPlanner.rebasedForZone(hourly, nowInTokyo, tokyo))
val retrying = daily().copy(retryAt = at("2026-10-19T07:30"), retriesUsed = 1)
- val rebased = ScheduledTaskPlanner.rebasedForZone(retrying, at("2026-10-19T07:00"), zone)
+ // Across a real zone shift too: the retry is a real delay, not wall time.
+ val tokyoNow = LocalDateTime.parse("2026-10-19T07:00").atZone(ZoneId.of("Europe/Berlin"))
+ .toInstant().toEpochMilli()
+ val rebased = ScheduledTaskPlanner.rebasedForZone(retrying, tokyoNow, ZoneId.of("Asia/Tokyo"))
assertEquals(at("2026-10-19T07:30"), rebased.retryAt)
assertEquals(1, rebased.retriesUsed)
}
diff --git a/app/src/test/java/com/gotcha/scheduled/ScheduledTaskScheduleTest.kt b/app/src/test/java/com/gotcha/scheduled/ScheduledTaskScheduleTest.kt
index 5d71e91..3b210cf 100644
--- a/app/src/test/java/com/gotcha/scheduled/ScheduledTaskScheduleTest.kt
+++ b/app/src/test/java/com/gotcha/scheduled/ScheduledTaskScheduleTest.kt
@@ -145,6 +145,13 @@ class ScheduledTaskScheduleTest {
}
assertEquals("2026-10-25T02:40", got)
assertTrue(isWallTimeFuture(LocalDateTime.parse("2026-10-25T02:40"), zone, betweenPasses))
+ // Once the second pass has gone too, nothing lies ahead.
+ val afterSecondPass = java.time.ZonedDateTime.of(
+ LocalDateTime.parse("2026-10-25T02:41"),
+ zone
+ ).withLaterOffsetAtOverlap().toInstant().toEpochMilli()
+ assertTrue(!isWallTimeFuture(LocalDateTime.parse("2026-10-25T02:40"), zone, afterSecondPass))
+ assertNull(nextOccurrence(once, afterSecondPass, zone))
}
@Test
diff --git a/app/src/test/java/com/gotcha/scheduled/ScheduledTaskStoreTest.kt b/app/src/test/java/com/gotcha/scheduled/ScheduledTaskStoreTest.kt
index dcd386a..fea5332 100644
--- a/app/src/test/java/com/gotcha/scheduled/ScheduledTaskStoreTest.kt
+++ b/app/src/test/java/com/gotcha/scheduled/ScheduledTaskStoreTest.kt
@@ -5,6 +5,7 @@ import androidx.test.core.app.ApplicationProvider
import com.gotcha.agent.Attachment
import com.gotcha.agent.ComposerAttachment
import org.junit.Assert.assertEquals
+import org.junit.Assert.assertFalse
import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Before
@@ -148,20 +149,11 @@ class ScheduledTaskStoreTest {
val berlin = java.time.ZoneId.of("Europe/Berlin")
val tokyo = java.time.ZoneId.of("Asia/Tokyo")
val armedAt = java.time.LocalDateTime.parse("2026-10-25T09:00").atZone(berlin).toInstant().toEpochMilli()
- store.put(
- task("daily").copy(
- startLocal = "2026-10-25T08:00",
- repeat = Repeat(RepeatKind.DAILY),
- nextRunAt = ScheduledTaskPlanner.armed(
- task("daily").copy(
- startLocal = "2026-10-25T08:00",
- repeat = Repeat(RepeatKind.DAILY)
- ),
- armedAt,
- berlin
- ).nextRunAt
- )
+ val daily = task("daily").copy(
+ startLocal = "2026-10-25T08:00",
+ repeat = Repeat(RepeatKind.DAILY)
)
+ store.put(ScheduledTaskPlanner.armed(daily, armedAt, berlin))
store.put(
task("hourly").copy(
startLocal = "2026-10-25T00:00",
@@ -177,6 +169,6 @@ class ScheduledTaskStoreTest {
)
assertEquals(armedAt + 2 * 60 * 60 * 1000L, store.get("hourly")!!.nextRunAt)
// A second rebase with nothing moved reports false.
- assertTrue(!store.rebaseForZoneChange(sameInstant, tokyo))
+ assertFalse(store.rebaseForZoneChange(sameInstant, tokyo))
}
}
diff --git a/app/src/test/java/com/gotcha/tools/ScheduledTaskToolTest.kt b/app/src/test/java/com/gotcha/tools/ScheduledTaskToolTest.kt
index 910e459..0fc93c2 100644
--- a/app/src/test/java/com/gotcha/tools/ScheduledTaskToolTest.kt
+++ b/app/src/test/java/com/gotcha/tools/ScheduledTaskToolTest.kt
@@ -106,6 +106,27 @@ class ScheduledTaskToolTest {
assertTrue(result.message, result.message.contains("already passed"))
}
+ @Test
+ fun `a one-time task in the repeated hour is accepted at the second pass`() {
+ // Summer time ends in Berlin on 25 Oct 2026. Between the passes the
+ // first 02:40 is gone but the second still lies ahead: the tool must
+ // accept it, like the Settings form does (issue #150).
+ val berlin = ZoneId.of("Europe/Berlin")
+ val betweenPasses = java.time.ZonedDateTime.of(
+ LocalDateTime.parse("2026-10-25T02:37"),
+ berlin
+ ).withLaterOffsetAtOverlap().toInstant().toEpochMilli()
+ val overlapTool = ScheduledTaskTool(
+ context,
+ store,
+ zone = { berlin },
+ clock = { betweenPasses },
+ chatTitle = { null }
+ )
+ val result = overlapTool.prepareCreate(args("""{"name":"n","prompt":"p","start":"2026-10-25T02:40"}"""))
+ assertTrue(result.message, result.success)
+ }
+
@Test
fun `the agent can set up only so many tasks`() {
repeat(ScheduledTaskTool.MAX_AGENT_TASKS) {