Skip to content

fix(mobile): foreground the app once per Android app action intent - #11568

Merged
iscekic merged 2 commits into
mainfrom
drain/kilo-action-single-foreground
Nov 18, 2026
Merged

iscekic merged 2 commits into
mainfrom
drain/kilo-action-single-foreground

Conversation

@iscekic

@iscekic iscekic commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Evidence

Evidence: demonstrated — the doubled foreground was reproduced on the Android emulator against a build of the merge base, and the fix was observed on a build of this branch through the same scenario.

  • Merge base, cold start-agent intent (adb shell am start -a com.kilocode.kiloapp.action.START_AGENT with one intent): two MainActivity launcher starts in the ActivityTaskManager records, 4 ms apart, for that single request.
  • This branch at its current head, same cold intent: exactly one MainActivity launcher start.
  • Warm start-agent from the home screen on a freshly launched app task: one launcher start, and the app's own screen is in the foreground afterwards. One repeat that Android delivered to the app's existing task reported no launcher start and still foregrounded the app; no run started the launcher activity twice.
  • Cold open-session while the JS runtime was not yet up: one launcher start (the buffered payload still foregrounds the app).
  • Warm open-session with the JS dispatcher registered: zero launcher starts (a dispatched non-start action only finishes the entry-point activity).

The merge-base and head runs used the same adb commands on the same emulator, with a clean logcat buffer per scenario and the launcher-activity start line counted in each buffer. The emulator kept the default display density.

Change

KiloActionActivity.handle() called showInApp() from two independent branches: one for isStartAgent(intent), and one when AppActionDispatcher.dispatch(payload) returned false because the JS dispatcher had not registered yet and the payload was buffered. A start-agent request that arrived while the process was cold hit both branches and started the launcher activity twice.

The fix resolves the intent once and foregrounds at most once:

  • KiloActionContract.resolve(intent) now returns a Resolved value carrying the contract slug and the JSON payload, replacing the separate payload() and isStartAgent() lookups that each re-resolved the slug (slugOf) for the same intent.
  • handle() holds the dispatch result in a local value and calls showInApp() once, when the resolved slug is start-agent or when the dispatcher buffered the payload. Behavior is otherwise unchanged: a warm start-agent still opens the app, a buffered payload still opens it, and a dispatched non-start action only finishes.

The shared JS contract remains the owner of the slugs; the native side still maps its action strings and URL dialect through the existing SLUG_BY_ACTION table. The one source-reading test assertion that named the old call shape was updated; no other test text changed.

Verification

  • pnpm exec vitest run modules/kilo-app-actions/ in apps/mobile: 4 files, 254 tests pass.
  • :kilo-app-actions:compileDebugKotlin succeeds; the debug dev-client APK of the branch installs and runs on the emulator.
  • The emulator scenario set above was captured with adb logcat ActivityTaskManager start records, with the app driven through the dev client and Metro serving the workspace bundle.

Production prerequisites

None.

@iscekic iscekic added drain Work item from the findings drain janitor:maintainability Maintainability finding from the janitor labels Nov 18, 2026
@iscekic

iscekic commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

bot: Emulator verification of the single-foreground behavior. The cold start-agent intent was exercised on a build of the merge base and on a build of this branch, with the same adb scenario. Logcat ActivityTaskManager records: the base build showed two launcher-activity starts for one intent; this branch shows one. The screenshot shows the app running on the emulator after the verified warm open-session scenario, where a dispatched non-start action foregrounds nothing.

Base (merge base): two MainActivity starts, 5 ms apart:

START u0 {act=...START_AGENT ...} result code=0
START u0 {act=android.intent.action.MAIN cat=[LAUNCHER] cmp=com.kilocode.kiloapp/.MainActivity} result code=0
START u0 {act=android.intent.action.MAIN cat=[LAUNCHER] cmp=com.kilocode.kiloapp/.MainActivity} result code=3

Head (this branch): one MainActivity start:

START u0 {act=...START_AGENT ...} result code=0
START u0 {act=android.intent.action.MAIN cat=[LAUNCHER] cmp=com.kilocode.kiloapp/.MainActivity} result code=0

App running on the emulator after the verified warm open-session scenario

@kilo-code-bot

kilo-code-bot Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

The follow-up commit only rewrites the Resolved KDoc so it now names resolve() as the null-returning call, which matches the non-null payload field and closes the prior suggestion; the single-foreground logic itself is unchanged from the previously reviewed commit.

Assumptions: [INFERENCE] Kotlin compilation and the emulator evidence in the PR body were not re-run; this incremental review covers the one changed hunk (KiloActionActivity.kt doc comment) plus a targeted check that no prior finding remains.

Files Reviewed (2 files)
  • apps/mobile/modules/kilo-app-actions/android/src/main/java/expo/modules/kiloappactions/KiloActionActivity.kt
  • apps/mobile/modules/kilo-app-actions/android-app-actions.test.ts (unchanged in this commit; prior review found no issues)
Previous Review Summary (commit cea7ffc)

Current summary above is authoritative. Previous snapshots are kept for context only.

Previous review (commit cea7ffc)

Status: 1 Issue Found | Recommendation: Merge

Executive Summary

The single-foreground fix is correct: resolve() reuses one slug lookup and handle() foregrounds at most once, with only a stale KDoc sentence left on the new Resolved type.

Assumptions: [INFERENCE] Kotlin compilation and the emulator evidence come from the PR body; I did not build or run code. The intent ?: return null smart cast at KiloActionActivity.kt:77 is assumed valid on that same evidence.

Overview

Severity Count
CRITICAL 0
WARNING 0
SUGGESTION 1
Issue Details (click to expand)

SUGGESTION

File Line Issue
apps/mobile/modules/kilo-app-actions/android/src/main/java/expo/modules/kiloappactions/KiloActionActivity.kt 64 KDoc says payload is null when the intent names no action, but Resolved.payload is a non-null String and the null case moved to resolve()
Files Reviewed (2 files)
  • apps/mobile/modules/kilo-app-actions/android/src/main/java/expo/modules/kiloappactions/KiloActionActivity.kt - 1 issue
  • apps/mobile/modules/kilo-app-actions/android-app-actions.test.ts - 0 issues

Fix these issues in Kilo Cloud


Reviewed by deepseek-flash-latest · Input: 37K · Output: 2.8K · Cached: 284.2K

Review guidance: REVIEW.md from base branch main

@iscekic iscekic added the merge:bot Bot-owned review; merge when ready once readiness passes and a review approves. label Nov 18, 2026
@iscekic iscekic added merge:blocked:kilobot-not-ready Review bot has not recommended merge at this head merge:bot Bot-owned review; merge when ready once readiness passes and a review approves. and removed merge:bot Bot-owned review; merge when ready once readiness passes and a review approves. merge:blocked:kilobot-not-ready Review bot has not recommended merge at this head labels Nov 18, 2026
@iscekic

iscekic commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator Author

bot: Re-ran the app-action intent scenarios on the current head of this branch, after the review round moved the head. Merge base and head were measured with the same commands on the same emulator, with a clean logcat buffer per scenario.

  • Merge base, one cold start-agent intent: two launcher-activity starts in the ActivityTaskManager records.
  • Head, the same intent: one launcher-activity start.
  • Head, cold open-session with the JS runtime not yet up: one launcher-activity start, so the buffered payload still foregrounds the app.
  • Head, warm start-agent from the home screen on a freshly launched app task: one launcher-activity start, and the app's own screen is in the foreground afterwards.
  • One repeat of the warm scenario reported no launcher-activity start because Android delivered the intent to the app's existing task and brought it forward without creating the entry point; the app was in the foreground either way. No run started the launcher activity twice.

The attached capture is the app's own signed-out screen after the warm start-agent intent.

@iscekic
iscekic added this pull request to the merge queue Nov 18, 2026
Merged via the queue into main with commit dd0a19b Nov 18, 2026
64 checks passed
@iscekic
iscekic deleted the drain/kilo-action-single-foreground branch November 18, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

drain Work item from the findings drain janitor:maintainability Maintainability finding from the janitor merge:bot Bot-owned review; merge when ready once readiness passes and a review approves.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants