by adom
Drive your whole Google Workspace from the terminal, run by your AI. Read Gmail, write Google Docs, build Google Sheets and Google Slides, search Google Drive, manage Google Calendar and Google Tasks, and post to Google Chat, plus any Google API and a zero-setup personal Gmail.
master
Drew Owens
v0.8.29: consent wait no longer spins at 100% CPU when the gateway socket closes
ba198ec
"""Regression: the gateway consent wait spun at ~100% CPU for days when the socket hit EOF (2026-11)."""
import socket, threading, time, sys, resource, importlib.machinery, importlib.util
import os
path = sys.argv[1] if len(sys.argv) > 1 else os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "bin", "adom-google")
loader = importlib.machinery.SourceFileLoader("ag", path)
spec = importlib.util.spec_from_loader("ag", loader); ag = importlib.util.module_from_spec(spec); loader.exec_module(ag)
def server(mode, port_box):
s = socket.socket(); s.bind(("127.0.0.1", 0)); s.listen(1); port_box.append(s.getsockname()[1])
c, _ = s.accept(); c.recv(4096)
c.sendall(b"HTTP/1.1 101 Switching Protocols\r\nUpgrade: websocket\r\nConnection: Upgrade\r\n\r\n")
if mode == "eof":
c.settimeout(0.5)
try: c.recv(4096)
except Exception: pass
c.shutdown(socket.SHUT_WR); time.sleep(5); c.close() # FIN, no close frame
else:
time.sleep(10); c.close() # silent
for mode, to in (("eof", 30), ("silent", 3)):
box = []; t = threading.Thread(target=server, args=(mode, box), daemon=True); t.start()
while not box: time.sleep(0.01)
c0 = resource.getrusage(resource.RUSAGE_SELF).ru_utime; w0 = time.time()
try:
ag._minimal_ws_roundtrip(f"ws://127.0.0.1:{box[0]}/", [{"type": "hi"}], {"done"}, timeout=to)
print(mode, "UNEXPECTED return"); sys.exit(1)
except Exception as e:
wall = time.time()-w0; cpu = resource.getrusage(resource.RUSAGE_SELF).ru_utime-c0
print(f"{mode}: raised {e!r} after {wall:.2f}s wall, {cpu:.2f}s cpu")
assert cpu < 1.0, f"{mode}: busy-looped ({cpu:.1f}s cpu)"
assert wall < to + 2, f"{mode}: ignored the deadline ({wall:.1f}s)"
print("OK: websocket wait exits on EOF and on deadline without spinning")