fix(agent): the agent survives Steam session starts, stops and restarts (#2503)

* fix(agent): session starts and stops leave the agent's own processes running

* feat(agent): droiddeckctl ships with the app and the brief explains the Steam session
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-11 23:46:48 -05:00
1 parent 7da27d4ff4
commit 1882520cac
6 files changed
+58 -22

No files matched your search

@@ -11,6 +11,9 @@ object OrphanReaper {
fun release(pid: Int) { kept.remove(pid) }
/** Kept processes and everything they started, which session cleanups must leave running. */
fun spared(): Set<Int> = descendants(kept)
fun hasOtherProcesses(): Boolean = hasOtherProcesses(
File("/proc").list()?.mapNotNull { it.toIntOrNull() }, android.os.Process.myPid(),
) { pid ->
@@ -30,7 +33,7 @@ object OrphanReaper {
fun reap(reason: String, matching: (String) -> Boolean = { true }): Int {
val me = android.os.Process.myPid()
val uid = android.os.Process.myUid()
val spared = descendants(kept)
val spared = spared()
var killed = 0
File("/proc").listFiles()?.forEach { entry ->
val pid = entry.name.toIntOrNull() ?: return@forEach
@@ -1606,10 +1606,11 @@ class SessionService : Service() {
val me = android.os.Process.myPid()
val rootfs = try { File(filesDir, "linuxfs").canonicalPath } catch (e: Exception) { return } + "/"
val procs = File("/proc").listFiles { f -> f.name.all { it.isDigit() } } ?: return
val spared = OrphanReaper.spared()
var killed = 0
for (proc in procs) {
val pid = proc.name.toIntOrNull() ?: continue
if (pid == me) continue
if (pid == me || pid in spared) continue
val exe = try { File(proc, "exe").canonicalPath } catch (e: Exception) { continue }
if (!exe.startsWith(rootfs)) continue
android.os.Process.killProcess(pid)
@@ -1621,10 +1622,11 @@ class SessionService : Service() {
private fun killStragglers() {
val me = android.os.Process.myPid()
val procs = File("/proc").listFiles { f -> f.name.all { it.isDigit() } } ?: return
val spared = OrphanReaper.spared()
var killed = 0
for (proc in procs) {
val pid = proc.name.toIntOrNull() ?: continue
if (pid == me) continue
if (pid == me || pid in spared) continue
val cmdline = try {
File(proc, "cmdline").readBytes().toString(Charsets.UTF_8).replace('\u0000', ' ')
} catch (e: Exception) {