Repository navigation
fix(linux): don't stop the watcher when its terminal has gone away - #176
officialasishkumar wants to merge 1 commit into
Conversation
get_window_class() had a leftover print("") on the fallback taken when a
window has no WM_CLASS, or vanished before it could be queried (BadWindow).
aw-qt starts the watcher with inherited stdio, so once the terminal aw-qt was
launched from is closed, stdout is a hung-up tty and that write raises
OSError: [Errno 5] Input/output error. heartbeat_loop treats OSError as fatal,
so the first such window permanently stops window tracking, which can be long
after startup.
Remove the print. The warning logged on the next line already records this
branch, and log handlers tolerate a broken stream, so the fallback now reaches
the parent window lookup and tracking continues.
Add tests that run both fallback paths with a stdout that raises EIO.
Fixes ActivityWatch/activitywatch#1147
Codex Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
[Medium impact] The PR appears safe to merge. SummaryRemoves the stray stdout write from
Reviews (1) · Last reviewed commit: "fix(linux): don't stop the watcher when ..." · Reviewed by Greptile |
|
I verified the failure path independently, because a one-line deletion fix is only worth taking if the deleted line is really what raises.
What is needed to merge: maintainer approval to run the workflow on this fork head. Two notes that are not blockers:
|
aw-watcher-windowstops for good on Linux once the terminalaw-qtwas started from has been closed, as soon as it next polls a window with noWM_CLASS, or one that has just vanished. The tray keeps running, but window tracking ends.get_window_class()had a leftoverprint("")on that fallback path.aw-qtstarts modules with inherited stdio, so after the terminal closes, stdout is a hung-up tty and the write raisesOSError: [Errno 5] Input/output error.heartbeat_looptreatsOSErroras fatal, so the watcher exits.This matches the logs in ActivityWatch/activitywatch#1147. The
BadWindowwarning is logged, the traceback points at theprintline (xlib.py:120in that release), and the "Code made an unclear branch" warning right after it never appears.Fix
Removed the
print. The next line already logs this branch, and logging handlers don't raise when their stream is broken, so the fallback goes on to the parent window lookup. No other code on the Linux polling path writes to stdout.This is separate from ActivityWatch/aw-qt#135, which repairs output that is already disconnected when
aw-qtstarts. It doesn't cover a terminal that closes later, which is the case here.Testing
tests/test_xlib.py, which runs both fallback paths (parent lookup and vanished window) with a stdout that raisesEIO. Both tests fail on master withOSError: [Errno 5]and pass with the fix.get_window_class()with stdout on an actual hung-up pty (master end closed) and fake windows. On master it raisesOSError(5, 'Input/output error'); with the fix it returns the parent's class.pytest tests(192 passed, 14 skipped) andmypy aw_watcher_window/ --ignore-missing-importspass on Linux with Python 3.11.Not tested against a live X server:
BadWindowdepends on a race, so the tests use fake windows. I also couldn't confirm on the reporters' machines that their terminals had closed.Fixes ActivityWatch/activitywatch#1147