fix(session): read the compressed client back when it is in front of a running game (#2600)

* fix(session): read the compressed client back when it is in front of a running game

* fix(session): keep the client compressed while focus is unknown

A missing or unreadable focus.json no longer counts as the client in front
of the game, so the readback timer starts only on a confirmed focus change.

* fix(session): invalidate focus snapshots after collection failures

* fix(session): retry focus snapshot publication
This commit is contained in:
MaxsTechReview authored and GitHub committed 2026-11-17 11:20:29 -05:00
1 parent 8e49dfe190
commit 8c8cae85cf
6 files changed
+221 -17

No files matched your search

@@ -391,18 +391,26 @@ class FocusWatcher(threading.Thread):
x.close()
except (OSError, AgentError) as e:
log("focus snapshot failed: %s" % e)
self.publish({})
time.sleep(2)
continue
if tag_game_windows(snap):
self.changed.set()
continue
body = {k: v for k, v in snap.items() if k != "t"}
if body == self.last:
continue
self.last = body
self.seq += 1
snap["seq"] = self.seq
write_json(self.path, snap)
self.publish(snap)
def publish(self, snap):
body = {k: v for k, v in snap.items() if k != "t"}
if body == self.last:
return
try:
write_json(self.path, dict(snap, seq=self.seq + 1))
except OSError as e:
log("focus publication failed: %s" % e)
self.changed.set()
return
self.seq += 1
self.last = body
def listen(self):
while True:
@@ -1104,7 +1104,7 @@ case $mode in
local id
id=$(sed -n 's/.*"focusedApp"[[:space:]]*:[[:space:]]*\([0-9][0-9]*\).*/\1/p' \
"$BL_LAUNCH_DIR/agent/focus.json" 2>/dev/null | head -1)
[ -n "$id" ] || return "${1:-1}"
[ -n "$id" ] || return "${1:-2}"
case " ${_bl_apps-} " in
*" $id "*) return 0 ;;
esac
@@ -1122,7 +1122,7 @@ case $mode in
}
_bl_since=-1 _bl_since_apps= _bl_packed=-1 _bl_measured=-1 _bl_unpack=0 _bl_capped=-1 _bl_backoff=30
_bl_pressure_at=-1 _bl_pressure_backoff=30 _bl_tier_at=-1 _bl_tier_backoff=30 _bl_tier_pushed=0 _bl_tier_back=0 _bl_tier_targets=() _bl_tier_swaps=() _bl_tier_starts=()
_bl_client_pending=0 _bl_client_reserve=0 _bl_client_targets=()
_bl_client_pending=0 _bl_client_reserve=0 _bl_client_targets=() _bl_away=
_bl_sample_at= _bl_sample_available=0 _bl_sample_gpu=0 _bl_sample_unevictable=0 _bl_sample_shmem=0
while kill -0 $$ 2>/dev/null; do
bl_zram_scan
@@ -1155,7 +1155,10 @@ case $mode in
_bl_preserved_growth=$_bl_growth _bl_preserved_fall=$_bl_fall
bl_session_pressure
bl_client_pressure_finish
if [ "$_bl_game" = 1 ] && bl_game_focused; then
_bl_focus=1
[ "$_bl_game" = 1 ] && { bl_game_focused && _bl_focus=0 || _bl_focus=$?; }
if [ "$_bl_game" = 1 ] && [ "$_bl_focus" = 0 ]; then
_bl_away=
if [ "$_bl_since" -lt 0 ] || [ "$_bl_since_apps" != "$_bl_apps" ]; then
_bl_since=$SECONDS _bl_since_apps=$_bl_apps
fi
@@ -1165,15 +1168,31 @@ case $mode in
_bl_packed=$SECONDS
fi
elif [ "$_bl_game" != 1 ]; then
_bl_away=
if [ "$_bl_packed" -ge 0 ]; then
_bl_unpack=1
fi
_bl_since=-1 _bl_packed=-1 _bl_tier_at=-1 _bl_tier_backoff=30 _bl_tier_pushed=0 _bl_tier_targets=() _bl_tier_swaps=() _bl_tier_starts=()
else
_bl_since=-1
if [ "$_bl_focus" = 1 ]; then
[ -n "${_bl_away-}" ] || _bl_away=$SECONDS
else
_bl_away=
fi
if [ "$_bl_packed" -ge 0 ]; then
_bl_unpack=1
fi
fi
if [ "$_bl_unpack" = 1 ] && [ "$_bl_game" = 0 ] && ! bl_over_cap && bl_client_can_readback; then
bl_zram_send 0 "memory recovered, reading the client back" client
if [ "$_bl_unpack" = 1 ] &&
{ [ "$_bl_game" = 0 ] || { [ "${_bl_ram_cap:-0}" = 0 ] && [ -n "${_bl_away-}" ] && [ $((SECONDS - _bl_away)) -ge 5 ]; }; } &&
! bl_over_cap && bl_client_can_readback; then
if [ "$_bl_game" = 0 ]; then
bl_zram_send 0 "memory recovered, reading the client back" client
else
bl_zram_send 0 "the client is in front of the game, reading it back" client
_bl_packed=-1
fi
_bl_unpack=0
fi
bl_watch_nap