feat: detect Steam sign-out during login, stop cascading crashes after a missing game window
Root-caused 3 consecutive real cron failures (one q4h, two daily, all 2026-09-20) to Steam itself sitting signed out on its own account sign-in dialog -- not a Blue Archive client issue, and not something any amount of retrying/relaunching the game can fix. login._steam_needs_sign_in (new detector.read_text_white_on_dark, since the dialog's own light-on-dark text is the opposite OCR polarity this project usually assumes) recognizes that exact state and turns the generic "game window never appeared" warning into a specific, actionable one instead of requiring a fresh screenshot investigation every time it recurs. ba_daily.py's _run_sequence now checks driver.window_exists() after every task (except the last, and except exit_game) and aborts the whole run immediately with one clear message if the window is gone, instead of letting every remaining task independently rediscover this via its own doomed pre-task retry cycle before crashing two tasks deep in a stack trace. Still propagates as a real FAILED exit code -- this project deliberately never swallows a genuine crash. Confirmed live: reproduced the original failure via a real ./ba_cron_run.sh q4h run while Steam was still genuinely signed out, then verified the new diagnostic fired correctly and the sequence aborted immediately. After the user signed back into Steam, ran the actual daily recovery preset end-to-end (all 17 tasks, ~24 minutes, exit 0) to catch up the account's daily claims. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
parent
6a800f731b
commit
19e39ec8b2
@ -1692,6 +1692,27 @@ LOGIN_UPDATE_DIALOG_TEXT_RECT = (600, 420, 1320, 465)
|
||||
LOGIN_UPDATE_DIALOG_KEYWORD = "ダウンロード"
|
||||
LOGIN_UPDATE_OK_BUTTON = (1040, 851)
|
||||
|
||||
# Steam's OWN account sign-in dialog -- not a Blue Archive client screen at
|
||||
# all. Real incident, 2026-09-20: three consecutive real cron runs (one
|
||||
# q4h, two daily) all failed identically with "game window never appeared
|
||||
# after launch" -- root-caused by a live screenshot showing Steam itself
|
||||
# sitting on its own username/password + QR-code sign-in dialog the entire
|
||||
# time, meaning it had been signed out and every launch attempt opened
|
||||
# Steam but could never reach the point of starting BlueArchive.exe at all.
|
||||
# No amount of retrying/relaunching the GAME can get past this -- it
|
||||
# needs a real person to sign in, so `login._steam_needs_sign_in` uses this
|
||||
# purely as a diagnostic aid, to turn a generic "never appeared" warning
|
||||
# into an actionable one instead of requiring a fresh screenshot
|
||||
# investigation every time it recurs. Rect crops the "SIGN IN WITH ACCOUNT
|
||||
# NAME" label specifically (confirmed live via a saved screenshot from the
|
||||
# actual incident, scratchpad/stuck_launch_check.png at the time) --
|
||||
# light-blue-on-dark-navy, the opposite polarity of this project's usual
|
||||
# OCR assumption, read via detector.read_text_white_on_dark. Confirmed live
|
||||
# the label's own grayscale luminance tops out at 126, well under that
|
||||
# function's default 150 threshold, so this passes a lower one explicitly.
|
||||
LOGIN_STEAM_SIGNIN_TEXT_RECT = (640, 490, 960, 520)
|
||||
LOGIN_STEAM_SIGNIN_OCR_THRESHOLD = 90
|
||||
|
||||
# Battle Pass (バトルパス) -- ported from baas-reference's
|
||||
# module/collect_pass_reward.py. See ba_auto/tasks/battle_pass.py's module
|
||||
# docstring for the full reference-mapping writeup; constants below were
|
||||
|
||||
@ -289,6 +289,35 @@ def read_int_white_on_dark(region, psm=7):
|
||||
return int(digits) if digits else None
|
||||
|
||||
|
||||
def read_text_white_on_dark(region, whitelist=None, psm=7, lang="eng", threshold=150):
|
||||
"""General-text equivalent of read_int_white_on_dark, for light-on-dark
|
||||
UI outside this project's own game client -- e.g. a genuine Steam
|
||||
client dialog (confirmed live 2026-09-20: three consecutive real cron
|
||||
failures traced back to Steam itself being signed out, sitting on its
|
||||
own account sign-in screen instead of ever launching the game --
|
||||
login.py's `_steam_needs_sign_in` uses this to recognize that specific
|
||||
state and give a diagnostic message that says so, instead of a generic
|
||||
"game window never appeared").
|
||||
|
||||
`threshold` defaults to the same 150 read_int_white_on_dark already
|
||||
uses, but is adjustable here since not every light-on-dark UI is
|
||||
equally bright -- Steam's own "SIGN IN WITH ACCOUNT NAME" label topped
|
||||
out at grayscale 126 in a live capture, well under 150, and needed a
|
||||
lower threshold (confirmed live: 70-100 all read it cleanly) to
|
||||
binarize into anything at all rather than a blank crop.
|
||||
"""
|
||||
x1, y1, x2, y2 = region
|
||||
img = driver.read_screenshot(OCR_SHOT_PATH)
|
||||
crop = img[y1:y2, x1:x2]
|
||||
gray = cv2.cvtColor(crop, cv2.COLOR_BGR2GRAY)
|
||||
_, thresh = cv2.threshold(gray, threshold, 255, cv2.THRESH_BINARY_INV)
|
||||
upscaled = cv2.resize(thresh, None, fx=OCR_UPSCALE, fy=OCR_UPSCALE, interpolation=cv2.INTER_CUBIC)
|
||||
tess_config = f"--psm {psm}"
|
||||
if whitelist:
|
||||
tess_config += f" -c tessedit_char_whitelist={whitelist}"
|
||||
return pytesseract.image_to_string(upscaled, lang=lang, config=tess_config).strip()
|
||||
|
||||
|
||||
def read_int(region, psm=7):
|
||||
"""Local equivalent of the reference's recognize_int."""
|
||||
digits = "".join(ch for ch in read_text(region, whitelist="0123456789", psm=psm) if ch.isdigit())
|
||||
|
||||
File diff suppressed because one or more lines are too long
@ -337,6 +337,22 @@ def _loading_buffer_visible(driver, config):
|
||||
return all(_color_matches(c, config.LOGIN_LOADING_BUFFER_RGB, config.LOGIN_LOADING_BUFFER_TOLERANCE) for c in colors)
|
||||
|
||||
|
||||
def _steam_needs_sign_in(driver, config):
|
||||
"""Positive OCR check for Steam's OWN account sign-in dialog -- not a
|
||||
Blue Archive client screen at all (see config.py's
|
||||
LOGIN_STEAM_SIGNIN_* comment for the full real-incident writeup). Only
|
||||
meaningful to call after the game window has already failed to appear
|
||||
at all -- this is a diagnostic aid to explain WHY, not a state this
|
||||
flow can do anything about (it needs a real person to sign in), so
|
||||
`run()` only checks it once, right before giving up entirely.
|
||||
"""
|
||||
text = detector.read_text_white_on_dark(
|
||||
config.LOGIN_STEAM_SIGNIN_TEXT_RECT,
|
||||
threshold=config.LOGIN_STEAM_SIGNIN_OCR_THRESHOLD,
|
||||
)
|
||||
return "SIGN IN" in text.upper()
|
||||
|
||||
|
||||
def _update_dialog_open(driver, config):
|
||||
"""Positive OCR check for the pending-update/additional-data download
|
||||
notice (see config.py's LOGIN_UPDATE_DIALOG_* comment for the full
|
||||
@ -499,6 +515,9 @@ def _recover(driver, config):
|
||||
driver.wait(2)
|
||||
driver.launch_game()
|
||||
if not _wait_for_window(driver, config):
|
||||
if _steam_needs_sign_in(driver, config):
|
||||
print("[login] warning: Steam itself is showing its own account sign-in screen after relaunch -- signed out, needs a real person to log in; cannot proceed automatically")
|
||||
else:
|
||||
print("[login] warning: game window did not reappear after relaunch")
|
||||
return False
|
||||
if not driver.window_exists():
|
||||
@ -517,6 +536,9 @@ def run(driver, config):
|
||||
print("[login] game window not found -- launching")
|
||||
driver.launch_game()
|
||||
if not _wait_for_window(driver, config):
|
||||
if _steam_needs_sign_in(driver, config):
|
||||
print("[login] warning: Steam itself is showing its own account sign-in screen -- signed out, needs a real person to log in (password or the Steam Mobile app QR code); cannot proceed automatically")
|
||||
else:
|
||||
print("[login] warning: game window never appeared after launch -- giving up")
|
||||
return
|
||||
if not driver.window_exists():
|
||||
|
||||
35
ba_daily.py
35
ba_daily.py
@ -246,8 +246,41 @@ def _run_task(name):
|
||||
|
||||
|
||||
def _run_sequence(names):
|
||||
for name in names:
|
||||
# Real incident, 2026-09-20: three consecutive cron runs (one q4h, two
|
||||
# daily) all failed the same way -- login.py's own launch attempt gave
|
||||
# up cleanly (game window never appeared -- traced to Steam itself
|
||||
# being signed out, see login.py's _steam_needs_sign_in), but that
|
||||
# warning alone doesn't stop the sequence, so the very NEXT task still
|
||||
# ran, paid for its own full PRE_TASK_HOME_RETRIES retry cycle (~15s
|
||||
# of doomed waiting), and only then crashed with an uncaught
|
||||
# RuntimeError from driver.focus_game() -- the first task genuinely
|
||||
# able to raise, since login.py's own window_exists()/launch_game()
|
||||
# calls are the only ones in this codebase that tolerate a missing
|
||||
# window. That crash DID correctly propagate as a real cron FAILED
|
||||
# exit code (this project deliberately never swallows a real crash --
|
||||
# see _run_task's own docstring), so nothing was silently hidden, but
|
||||
# every task after the one that happened to crash first never got a
|
||||
# chance to even try, and the log buried the real cause two tasks deep
|
||||
# behind a stack trace instead of surfacing it immediately.
|
||||
#
|
||||
# Checking window_exists() after every task closes this gap for ANY
|
||||
# cause the window can disappear (not just this one incident) --
|
||||
# login's own launch failing, or the game crashing mid-sequence later
|
||||
# on -- and turns the same eventual crash into one immediate, clear
|
||||
# line instead of a slow doomed retry-then-traceback. Skipped for the
|
||||
# last task and for exit_game specifically, since exit_game closing the
|
||||
# window is its own intended success, not a failure to report.
|
||||
last_index = len(names) - 1
|
||||
for i, name in enumerate(names):
|
||||
_run_task(name)
|
||||
if i == last_index or name == "exit_game":
|
||||
continue
|
||||
if not driver.window_exists():
|
||||
raise RuntimeError(
|
||||
f"[{name}] game window does not exist after this task -- aborting the rest of this run "
|
||||
"rather than letting every remaining task independently fail the same way "
|
||||
"(check nik-gpu manually -- Steam may need signing in, or the game may have crashed)"
|
||||
)
|
||||
print("All done.")
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user