flexitracker 0.5.1__tar.gz → 0.5.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {flexitracker-0.5.1 → flexitracker-0.5.2}/PKG-INFO +1 -1
- {flexitracker-0.5.1 → flexitracker-0.5.2}/src/flexitracker/idle.py +30 -16
- flexitracker-0.5.2/tools/wts_lock_diagnostic.py +127 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/.gitignore +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/LICENSE +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/README.md +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/install/README.md +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/install/flexitracker.service +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/pyinstaller_entry.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/pyproject.toml +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/src/flexitracker/__init__.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/src/flexitracker/__main__.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/src/flexitracker/_backend.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/src/flexitracker/cli.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/src/flexitracker/config.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/src/flexitracker/core.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/src/flexitracker/logging_setup.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/src/flexitracker/login.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/src/flexitracker/outbox.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/src/flexitracker/sender.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/src/flexitracker/state_machine.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/src/flexitracker/version.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/test_cli.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/test_config.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/test_conformance.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/test_idle.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/test_logging_setup.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/test_login.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/test_outbox.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/test_sender_body.py +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/01-activation-debounced-backdated.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/02-idle-backdated-to-last-input.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/03-short-break-absorbed.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/04-brief-activity-debounced.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/05-sustained-return-backdated.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/06-heartbeats-while-active.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/07-recover-after-sudden-shutdown.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/08-locked-session-goes-idle.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/09-recover-anchors-later-evidence.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/10-suspend-longer-closes-span.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/11-suspend-with-immediate-wake.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/12-suspend-shorter-absorbed.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/13-backwards-clock-watermark.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/14-small-forward-clock-absorbed.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/15-recover-from-active-matches-loop.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/16-explicit-close-no-double-close.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/17-freshness-independent-of-poll.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/18-short-reading-pause.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/19-presence-must-be-sustained.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/20-gap-kills-pending-return.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/21-idle-backdating-exact.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/22-min-inactivity-exact-boundary.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/23-large-timestamps.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/24-all-kinds-lowercase.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/25-heartbeat-does-not-clamp-idle-backdate.json +0 -0
- {flexitracker-0.5.1 → flexitracker-0.5.2}/uv.lock +0 -0
|
@@ -120,17 +120,31 @@ class _LASTINPUTINFO(ctypes.Structure):
|
|
|
120
120
|
|
|
121
121
|
# WTSQuerySessionInformationW(..., WTSSessionInfoEx, ...) fills a WTSINFOEXW:
|
|
122
122
|
# DWORD Level; // offset 0 — union variant selector (1 == Level1)
|
|
123
|
-
#
|
|
124
|
-
#
|
|
125
|
-
#
|
|
126
|
-
#
|
|
123
|
+
# <4 bytes padding> // offset 4 — see below
|
|
124
|
+
# union { WTSINFOEX_LEVEL1_W L1; // offset 8
|
|
125
|
+
# ULONG SessionId; // +0 (offset 8)
|
|
126
|
+
# WTS_CONNECTSTATE_CLASS State; // +4 (offset 12; C enum, 4 bytes)
|
|
127
|
+
# LONG SessionFlags; // +8 (offset 16; WTS_SESSIONSTATE_LOCK=0 / _UNLOCK=1 / _UNKNOWN=-1)
|
|
127
128
|
# ... (session addresses, latency — unused, and version-sensitive) ...
|
|
128
129
|
# }
|
|
130
|
+
# The padding is NOT in Microsoft's field list (which just shows Level then
|
|
131
|
+
# the union) — it exists because WTSINFOEX_LEVEL1_W contains several 8-byte
|
|
132
|
+
# LARGE_INTEGER fields further down (LogonTime etc.), which gives the whole
|
|
133
|
+
# struct — and the union wrapping it — 8-byte alignment on a 64-bit process,
|
|
134
|
+
# pushing the union from offset 4 to offset 8. A first version of this code
|
|
135
|
+
# used offset 12 for SessionFlags, reasoned from the field list without
|
|
136
|
+
# accounting for this, and it landed on SessionState instead (0 = WTSActive
|
|
137
|
+
# for a normal local console session — which numerically collides with
|
|
138
|
+
# WTS_SESSIONSTATE_LOCK, so it read "locked" 100% of the time in production;
|
|
139
|
+
# see CLAUDE.md). Offset 16 was confirmed empirically — not just reasoned —
|
|
140
|
+
# via `tools/wts_lock_diagnostic.py`: [8] exactly matched an independently
|
|
141
|
+
# fetched WTSGetActiveConsoleSessionId() (proving SessionId's real offset),
|
|
142
|
+
# and [16] was the one that actually flipped 1↔0 on real lock/unlock.
|
|
129
143
|
# Reading just these two ints by fixed offset (rather than modeling the full,
|
|
130
144
|
# larger union) mirrors the same trick already used for X11's
|
|
131
|
-
# XScreenSaverInfo above
|
|
145
|
+
# XScreenSaverInfo above.
|
|
132
146
|
_WTS_LEVEL_OFFSET = 0
|
|
133
|
-
_WTS_SESSION_FLAGS_OFFSET =
|
|
147
|
+
_WTS_SESSION_FLAGS_OFFSET = 16
|
|
134
148
|
WTS_SESSIONSTATE_LOCK = 0
|
|
135
149
|
WTS_CURRENT_SERVER_HANDLE = 0
|
|
136
150
|
WTS_CURRENT_SESSION = -1 # cast to DWORD below; WTS_CURRENT_SESSION is (DWORD)-1
|
|
@@ -173,16 +187,16 @@ class WindowsIdle:
|
|
|
173
187
|
def __init__(self) -> None:
|
|
174
188
|
self._user32 = ctypes.windll.user32 # type: ignore[attr-defined]
|
|
175
189
|
self._kernel32 = ctypes.windll.kernel32 # type: ignore[attr-defined]
|
|
176
|
-
# windows_session_locked() (WTSQuerySessionInformationW/WTSSessionInfoEx
|
|
177
|
-
#
|
|
178
|
-
#
|
|
179
|
-
#
|
|
180
|
-
#
|
|
181
|
-
#
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
190
|
+
# windows_session_locked() (WTSQuerySessionInformationW/WTSSessionInfoEx)
|
|
191
|
+
# was disabled in v0.5.1 after shipping an unverified struct offset
|
|
192
|
+
# that read "locked" permanently in production (see CLAUDE.md). The
|
|
193
|
+
# corrected offset (16, not 12) is now confirmed by direct
|
|
194
|
+
# measurement on real hardware, not just reasoning — see the offset
|
|
195
|
+
# comment above and `tools/wts_lock_diagnostic.py`. Re-enabled.
|
|
196
|
+
try:
|
|
197
|
+
self._wtsapi32 = ctypes.windll.wtsapi32 # type: ignore[attr-defined]
|
|
198
|
+
except OSError:
|
|
199
|
+
self._wtsapi32 = None # lock detection unavailable; idle_ms-only, as before
|
|
186
200
|
|
|
187
201
|
def sample(self) -> Sample:
|
|
188
202
|
info = _LASTINPUTINFO()
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"""Diagnostic that found the TRUE byte offset of SessionFlags (lock state)
|
|
2
|
+
inside the WTSINFOEXW buffer returned by WTSQuerySessionInformationW. Windows
|
|
3
|
+
only. Standalone -- does not import `flexitracker`, deliberately, so it
|
|
4
|
+
can't share whatever bug it's used to find.
|
|
5
|
+
|
|
6
|
+
RESOLVED (2026-09-29): offset 16, not the originally-shipped 12. Confirmed
|
|
7
|
+
by real output from this tool, two ways at once: [8] exactly matched an
|
|
8
|
+
independently fetched WTSGetActiveConsoleSessionId() every sample (pinning
|
|
9
|
+
SessionId's real offset), and [16] was the one that actually flipped 1<->0
|
|
10
|
+
in lockstep with real Win+L lock/unlock, matching the documented
|
|
11
|
+
WTS_SESSIONSTATE_UNLOCK=1 / _LOCK=0. [12] (the original offset) sat at a
|
|
12
|
+
constant 0 throughout -- SessionState (WTSActive), not SessionFlags. Fixed
|
|
13
|
+
in `idle.py`; kept here for the next time this class of bug needs
|
|
14
|
+
re-verifying, on a different Windows build or architecture.
|
|
15
|
+
|
|
16
|
+
The first run of this script also needed a fix of its own:
|
|
17
|
+
WTSGetActiveConsoleSessionId is exported by Kernel32.dll, not Wtsapi32.dll,
|
|
18
|
+
despite the WTS-prefixed name -- calling it on the wtsapi32 handle raised
|
|
19
|
+
`AttributeError: function 'WTSGetActiveConsoleSessionId' not found`. That
|
|
20
|
+
bug was confirmed NOT present in the production code (`idle.py` only calls
|
|
21
|
+
WTSQuerySessionInformationW/WTSFreeMemory on wtsapi32, both genuinely
|
|
22
|
+
exported there, and GetLastInputInfo/GetTickCount on the correct
|
|
23
|
+
user32/kernel32) -- it only existed here, in this script, and is fixed
|
|
24
|
+
below.
|
|
25
|
+
|
|
26
|
+
Why this exists: `windows_session_locked()` in `flexitracker/idle.py` used
|
|
27
|
+
offset 12 (reasoned from the documented struct field order, assuming no
|
|
28
|
+
padding). In production it always read "locked" -- see CLAUDE.md. The
|
|
29
|
+
explanation, worked out from Microsoft's own struct definitions and then
|
|
30
|
+
confirmed by this script's actual output: WTSINFOEX_LEVEL1_W contains
|
|
31
|
+
several 8-byte LARGE_INTEGER fields, which gives the whole struct (and the
|
|
32
|
+
union wrapping it) 8-byte alignment, pushing the union 4 bytes later than
|
|
33
|
+
offset 12 assumed -- landing on SessionState (usually 0 = WTSActive)
|
|
34
|
+
instead of SessionFlags, and 0 also happens to mean WTS_SESSIONSTATE_LOCK.
|
|
35
|
+
Reasoning alone wasn't trusted a second time after the first offset guess
|
|
36
|
+
shipped wrong -- this script measured it instead.
|
|
37
|
+
|
|
38
|
+
Usage (from daemon-py/):
|
|
39
|
+
uv run tools/wts_lock_diagnostic.py [poll_seconds] [total_seconds]
|
|
40
|
+
|
|
41
|
+
Run it, then deliberately lock (Win+L) and unlock the screen a few times
|
|
42
|
+
while it's running (default: every 2s for 3 minutes -- plenty of time for a
|
|
43
|
+
few lock/unlock cycles). Send back the full output.
|
|
44
|
+
|
|
45
|
+
How to read it:
|
|
46
|
+
- `console_session_id` is fetched independently (WTSGetActiveConsoleSessionId)
|
|
47
|
+
and is NOT the value we're trying to find -- it's a known-correct anchor.
|
|
48
|
+
Whichever [offset]=value in the dump EXACTLY MATCHES it is the real
|
|
49
|
+
SessionId field. SessionState is 4 bytes after that, SessionFlags 4
|
|
50
|
+
bytes after that -- this pins down the whole layout without having to
|
|
51
|
+
trust anyone's reasoning about padding, including the note above.
|
|
52
|
+
- Independently, whichever offset's value changes exactly when you lock
|
|
53
|
+
vs. unlock is SessionFlags by direct observation, regardless of the
|
|
54
|
+
SessionId cross-check. The two should agree; if they don't, trust the
|
|
55
|
+
lock/unlock toggle -- it's the more direct measurement.
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
from __future__ import annotations
|
|
59
|
+
|
|
60
|
+
import sys
|
|
61
|
+
import time
|
|
62
|
+
|
|
63
|
+
WTS_CURRENT_SERVER_HANDLE = 0
|
|
64
|
+
WTS_CURRENT_SESSION = 0xFFFFFFFF
|
|
65
|
+
WTS_SESSION_INFO_EX = 25
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def dump_once(wtsapi32, kernel32, ctypes) -> None:
|
|
69
|
+
buf = ctypes.c_void_p()
|
|
70
|
+
length = ctypes.c_uint()
|
|
71
|
+
ok = wtsapi32.WTSQuerySessionInformationW(
|
|
72
|
+
WTS_CURRENT_SERVER_HANDLE,
|
|
73
|
+
ctypes.c_uint(WTS_CURRENT_SESSION),
|
|
74
|
+
WTS_SESSION_INFO_EX,
|
|
75
|
+
ctypes.byref(buf),
|
|
76
|
+
ctypes.byref(length),
|
|
77
|
+
)
|
|
78
|
+
ts = time.strftime("%Y-%m-%d %H:%M:%S")
|
|
79
|
+
if not ok or not buf.value:
|
|
80
|
+
print(f"{ts} WTSQuerySessionInformationW FAILED (ok={ok}, len={length.value})")
|
|
81
|
+
return
|
|
82
|
+
try:
|
|
83
|
+
# WTSGetActiveConsoleSessionId is exported by Kernel32.dll, not
|
|
84
|
+
# Wtsapi32.dll, despite the WTS-prefixed name -- calling it on the
|
|
85
|
+
# wtsapi32 handle raised AttributeError the first time this ran.
|
|
86
|
+
console_session_id = kernel32.WTSGetActiveConsoleSessionId()
|
|
87
|
+
n = min(length.value, 64)
|
|
88
|
+
raw = ctypes.string_at(buf.value, n)
|
|
89
|
+
hex_str = " ".join(f"{b:02x}" for b in raw)
|
|
90
|
+
print(f"{ts} console_session_id={console_session_id} length={length.value} bytes={hex_str}")
|
|
91
|
+
# Decode straight from the byte buffer already dumped above, rather
|
|
92
|
+
# than a second ctypes.cast over raw pointer arithmetic on buf.value
|
|
93
|
+
# -- one less thing that could be wrong in a script whose whole job
|
|
94
|
+
# is to be a trustworthy ground truth.
|
|
95
|
+
fields = [
|
|
96
|
+
f"[{off:2d}]={int.from_bytes(raw[off:off + 4], 'little', signed=True)}"
|
|
97
|
+
for off in range(0, n - 3, 4)
|
|
98
|
+
]
|
|
99
|
+
print(" " + " ".join(fields))
|
|
100
|
+
finally:
|
|
101
|
+
wtsapi32.WTSFreeMemory(buf)
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
def main() -> None:
|
|
105
|
+
if sys.platform != "win32":
|
|
106
|
+
raise SystemExit("This diagnostic only runs on Windows.")
|
|
107
|
+
|
|
108
|
+
import ctypes # local: importing this on non-Windows is fine, but
|
|
109
|
+
|
|
110
|
+
wtsapi32 = ctypes.windll.wtsapi32 # these two lines are Windows-only
|
|
111
|
+
kernel32 = ctypes.windll.kernel32
|
|
112
|
+
kernel32.WTSGetActiveConsoleSessionId.restype = ctypes.c_uint32
|
|
113
|
+
|
|
114
|
+
interval = float(sys.argv[1]) if len(sys.argv) > 1 else 2.0
|
|
115
|
+
total = float(sys.argv[2]) if len(sys.argv) > 2 else 180.0
|
|
116
|
+
print(f"Polling every {interval}s for {total}s.")
|
|
117
|
+
print("Lock (Win+L) and unlock the screen a few times while this runs, then")
|
|
118
|
+
print("send back the full output (or at least the rows around each toggle).")
|
|
119
|
+
print()
|
|
120
|
+
deadline = time.monotonic() + total
|
|
121
|
+
while time.monotonic() < deadline:
|
|
122
|
+
dump_once(wtsapi32, kernel32, ctypes)
|
|
123
|
+
time.sleep(interval)
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
if __name__ == "__main__":
|
|
127
|
+
main()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/01-activation-debounced-backdated.json
RENAMED
|
File without changes
|
{flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/02-idle-backdated-to-last-input.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/07-recover-after-sudden-shutdown.json
RENAMED
|
File without changes
|
|
File without changes
|
{flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/09-recover-anchors-later-evidence.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/14-small-forward-clock-absorbed.json
RENAMED
|
File without changes
|
{flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/15-recover-from-active-matches-loop.json
RENAMED
|
File without changes
|
{flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/16-explicit-close-no-double-close.json
RENAMED
|
File without changes
|
{flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/17-freshness-independent-of-poll.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{flexitracker-0.5.1 → flexitracker-0.5.2}/tests/vectors/22-min-inactivity-exact-boundary.json
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|