Open bug report

manage.py watch re-reads and regex-scans Codex's 2.5 MB extension.js every 5 s even when the result is 'unsupported' (about 5% CPU steady on every Linux workspace)

John Lauer ·

adom/codex 0.1.38 (runtime manage.py watch) · Codex extension openai.chatgpt 26.1111.21308 (linux-x64) · code-server 4.124.2 · Linux Hydrogen 1.0.756-4 workspaces (Ubuntu 24.04 nspawn), hl-ubuntu and m5-ubuntu

What I saw. manage.py watch uses CPU all the time on every Linux Hydrogen workspace, for nothing:

Box Elapsed CPU time Average
hl-ubuntu 11 h 31 min 28 min 33 s about 4%
m5-ubuntu 13 h 21 min about 42 min 5.3% (ps)

On m5-ubuntu, top was also reported at about 90% at a glance. That's either a spike during a round or a newer spin, and it needs a 15 s sample to tell (see the end).

Why (measured on hl-ubuntu). Every 5 s, watch() runs reconcile() and Guard.check(). One reconcile() costs 0.31 s of CPU (resource.getrusage, run as adom inside the workspace), which works out to about 6% steady:

  • patch() reads the whole 2.5 MB minified out/extension.js and runs the backreferencing regex (?P<w>[\w$]+)\.html=await this\.getWebviewContent\((?P=w)\),... over all of it.
  • It does this before checking JS_BEGIN in text, and even when the answer can't change. On 26.1111.21308 the answer is always state: unsupported, "Renderer startup changed upstream; renderer left intact", and the tour hook is "unsupported" too.
  • It also globs and reads every webview/assets/*.css and writes status.json each round.

Ask.

  1. Remember each extension folder's result by (path, mtime of package.json and of the entry file). Only re-read and re-scan a folder when it changes. An unchanged Codex then costs a stat() per round instead of 2.5 MB of regex.
  2. Skip the regex entirely once a build is known unsupported (same key), and write status.json only when the result changes.
  3. Optionally, a longer round when nothing changed (30 to 60 s). Codex updates are rare, and the guard's own checks are already rate-limited by REFRESH_S and ENGINE_REFRESH_S.

To tell the m5-ubuntu 90% apart from the 5% average, one sample from the box is enough: top -b -d 5 -n 3 -p <watch pid>, plus the last 30 lines of ~/.local/state/adom/codex-integration/watch.log.

1 Reply

John Lauer ·

New measurement, Debian 13 (M5 VM, Linux Hydrogen 1.0.756-16, adom/codex 0.1.41): with four AI tabs idle for 120 s, 17 python3/adom-codex processes started, about one every 7 s. Two of them were manage.py ensure-watch and one was runtime.py -c. adom-vscode and Hydrogen start none of them: adom-vscode 1.1.131's own counters and an strace of the extension host both show 0 spawns.

Where they come from in 0.1.41:

  1. Integration.cron(True) installs * * * * * python3 .../manage.py ensure-watch (every minute), plus @reboot.
  2. Integration.watch() loops reconcile() + guard() + time.sleep(5) for as long as the workspace runs. Guard.check() can run the Codex binary (--version, app-server generate-json-schema), code-server --install-extension/--uninstall-extension, and the notify tool.

Suggested event-driven shape (the same rule John set for adom-vscode in DIR-151517-1919, "no loops that sit there watching"):

  • Watch with inotify instead of polling: ~/.local/share/code-server/extensions for a new or removed openai.chatgpt-* folder, and User/settings.json for chatgpt.cliExecutable. Debounce 1 s, then reconcile and guard once.
  • Cache the Codex binary's --version by the binary's path and mtime: no spawn while it is unchanged.
  • Keep only @reboot ensure-watch (or a systemd user path unit), not the every-minute cron.

Linux Hydrogen's reporter (DIR-151544-17518) can retest on hl-ubuntu once a build is out.

Log in to reply.