Skip to content

feat(cron): run the u19proc cron wrappers from uv behind U19_CRON_ENV - #210

Draft
vrrigs wants to merge 2 commits into
masterfrom
tabedzki/feat/cron-uv-env
Draft

vrrigs wants to merge 2 commits into
masterfrom
tabedzki/feat/cron-uv-env

Conversation

@vrrigs

@vrrigs vrrigs commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

🤖 AI text below 🤖

Refs #206. The issue stays open after this merges: it is done when the switch is turned on on u19proc, which is blocked on the new VM (#54).

What it does

All 13 call_*.sh cron wrappers now source one shared script, u19_pipeline/cron_env.sh. It sources u19prod's ~/.bashrc and ~/.bash_profile, picks the Python environment from U19_CRON_ENV, and cds into the checkout. Each wrapper keeps only its own git pull line (if it had one) and its u19_cron_python <script> lines.

U19_CRON_ENV wrapper does
unset, empty or conda (default) conda activate U19-pipeline_python_env3 and python <script>: the same commands, in the same order and from the same directories, as on master
uv after the wrapper's pull: uv sync --locked --extra pipeline --no-dev (once per wrapper), then .venv/bin/python <script> with .venv/bin first on PATH
anything else error naming the value, exit 2, nothing pulled or run

With uv, a failed sync exits 1 before any script runs, and a missing uv (exit 127) or missing .venv (exit 1, prints the build command) stops the wrapper before it pulls. The wrappers don't build .venv themselves. That's a one-time manual step, so a missing env shows up in the cron log instead of a multi-GB download inside a cron job.

Merging changes nothing in production. Nobody sets U19_CRON_ENV on u19proc today, so every wrapper stays on conda.

Turn on: U19_CRON_ENV=uv source …/call_x.sh on a crontab line (inside the quotes under flock -c), or export U19_CRON_ENV=uv in u19prod's ~/.bash_profile for all of them. Turn off: delete that prefix or line. u19_pipeline/automatic_job/cron_uv_env.md covers the checks to run first (glibc, uv on cron's PATH) and the one-time .venv build. crontab_example shows both forms.

Choices

  • An environment variable, not a dj_local_conf.json key (unlike spock_ephys_env). The switch has to be read before any Python runs, and you can set it per crontab line, which is the rollout the issue asks for (one alert first, then the handler).
  • One extras set for every wrapper (--extra pipeline --no-dev). All wrappers share one .venv, and uv sync is exact, so a wrapper syncing other extras would remove packages the next one needs. The union of what the 13 scripts import is the base deps plus pipeline: the handler, the pupillometry handlers and populate_missing_syncbehavior_ephys.py import element-array-ephys, element-calcium-imaging, element-interface, paramiko, scp, psutil and bitstring. requests and matplotlib come in through the base deps (blosc2 and datajoint). The pupillometry handler imports deeplabcut only inside the function that runs on spock. pipeline brings the CUDA build of torch (several GB), which u19proc doesn't need at import time (suite2p is imported lazily). A smaller install is possible later with --no-install-package, but this PR doesn't try it.
  • The sync runs after the pull, so .venv matches the uv.lock that was just pulled.
  • Concurrent wrappers: uv takes an exclusive lock on the project and on .venv/.lock during a sync. Two concurrent uv sync runs on spock (uv 0.13.0) showed the second one Waiting to acquire exclusive lock for .venv at .venv/.lock. uv doesn't wait for scripts already running from .venv, so a pull that changes uv.lock can replace packages under a running script. That is written down in the doc and not handled further.
  • .venv/bin goes first on PATH, because the job handler starts nohup python scp_transfers.py … itself (u19_pipeline/utils/scp_transfers.py).
  • The setup in cron_env.sh runs at the sourced file's top level, not in a function, so .bashrc, .bash_profile and conda activate run in the same scope as before. The crontab sources the wrappers from cron's /bin/sh (bash in POSIX mode), and the tests run them that way as well as with bash <wrapper>.
  • U19_CRON_HOME / U19_CRON_REPO replace the u19prod home and checkout paths for the tests. They default to the production paths.
  • Shebangs are now on line 1 in the 12 wrappers that had blank lines before them. The crontab sources them, so this changes nothing there. File modes are unchanged.

Found on the way

  • call_cronjob_old_log_deletion.sh runs cronjob_olg_log_deletion.py ("olg"), but the file is cronjob_old_log_deletion.py. It has been that way since the wrapper was added. I kept the command as it is: fixing it would start old-log deletion on u19proc at merge time. It needs its own issue.
  • The locked wheels for Python 3.13 need glibc ≥ 2.28 on the new VM (torch, torchvision, h5py and imagecodecs only ship manylinux_2_28), so RHEL/Rocky 8 or newer. This is in the doc.

Tests

tests/test_cron_env.py, committed before the implementation:

  • static checks: every call_*.sh sources cron_env.sh, and none activates conda, sources rc files, cds, or runs python / .venv itself. cron_env.sh is the only conda activate in u19_pipeline/**/*.sh. The list of wrappers must match the table in the test.
  • behaviour: every wrapper runs with stub conda, uv, git and python on a PATH that holds nothing else, and fake home/checkout dirs. Covered cases: default / empty / conda give the same commands as master; uv syncs then runs the .venv python; the switch works from the crontab line and from the profile; an unknown value, a failed sync, a missing uv and a missing .venv each stop the wrapper before any script runs; exit statuses pass through; tech_alert syncs once and, under conda, runs all three scripts even if one fails.

Runs on spock (CPU slurm jobs):

  • the test commit (7f26e30) alone: 144 failed, 1 passed (the wrapper-list check, which doesn't depend on the implementation). The old wrappers fail on the hardcoded /home/u19prod…/.bashrc.
  • this branch: the full suite, 951 passed, 1 skipped.
  • I also ran each master wrapper (with the paths replaced) and each new wrapper against the same stubs, both ways of starting them. The stub call logs, stdout and stderr were identical for all 13.

Not run: anything on u19proc, a real uv sync --extra pipeline of this checkout, or the real scripts from uv.

The 13 call_*.sh wrappers must source u19_pipeline/cron_env.sh and leave
picking the Python environment to it. Runs each wrapper against stub conda,
uv, git and python: by default (or U19_CRON_ENV=conda) it does what it did
on master; with U19_CRON_ENV=uv it syncs the checkout's .venv after the pull
and runs the .venv python; an unknown value, a missing uv or .venv, or a
failed sync stops it before any script runs.

Refs #206

Assisted-by: ClaudeCode:claude-opus-5-5
Every call_*.sh now sources u19_pipeline/cron_env.sh, which sources
u19prod's .bashrc and .bash_profile, picks the environment and cds into
the checkout. The wrapper keeps its own git pull (if it had one) and runs
its scripts with u19_cron_python.

- U19_CRON_ENV unset, empty or "conda" (default): conda activate
  U19-pipeline_python_env3 and python, the same commands as before.
- U19_CRON_ENV=uv: after the wrapper's pull, uv sync --locked --extra
  pipeline --no-dev (once per wrapper), then .venv/bin/python with .venv/bin
  first on PATH. A failed sync, a missing uv or .venv, or an unknown value
  stops the wrapper before any script runs.

cron_uv_env.md says how to build .venv once on u19proc and switch each
crontab line; the switch stays off until the new u19proc VM (#54).

Refs #206

Assisted-by: ClaudeCode:claude-opus-5-5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants