oliver-zehentleitner / maity

tests: measure the shared test slots and cut the queue

Sign in to report

tsk-deaaanqsq5e2 Review

Reviews and coders queue for the shared heavy test slots on vm-aigents01 (run_slot.sh): smoke, e2e, hub-sqlite (~60 min), PostgreSQL. With 8+ reviewers that queue is now the slowest step in every review round (2026-11-17).

  1. Measure: for one day of slot use, which suite holds a slot how long, how often, and for whom. Report it as a table on this card.
  2. Propose, ranked by time saved:
  • faster suites: test parallelism such as pytest-xdist where tests are isolated, a shared Postgres template database, skipping a suite a diff cannot affect;
  • more slots: RAM/CPU per slot on the VM;
  • reviewers reusing CI's result on the same head instead of re-running a suite.
  1. Build the top item that needs no infra change. An infra change (VM size, slot count) goes to the lead first.

No change to what CI requires.

Notes

  1. Lotse · Nov 17, 2026, 18:27 UTC

    #1936 description of record for head 25418ca918bbba2bdd91633b55be9938391f8a2a, part 1 of 2 (GitHub body is stale):

    Card: tsk-deaaanqsq5e2, step 1 of the plan the lead approved: a log of slot use, so that one day of the shared run slots can be measured (which run holds a slot how long, how often, for whom).

    What

    tools/run_slot.sh appends a start line, and once the command's process is gone an end line, for every run that gets a slot to log in the run-slot directory (~/.local/state/maity/run-slots/log by default):

    • a start line, written right before the exec: UTC time, slot, pid, seconds waited, who (MAITY_RUN_NAME, else $USER), and the program and its first argument (cmd=pytest -n, cmd=make smoke). Fields are cut at 64 (who) and 200 (cmd) characters; tabs and line breaks become spaces. The slot's .who file names the run the same way.
    • an end line from a watcher the script starts before its exec: UTC time, slot, pid, seconds held. The watcher checks every second whether the pid is gone. It is started twice removed (no child of the command), without fd 7 and without the run's stdin, stdout or stderr. It runs in a session of its own (setsid, from util-linux like flock) and ignores INT, HUP and TERM, so a supervisor cancelling the command's process group does not take it along. Without setsid it only ignores those signals.

    The exec, fd 7, the pid and the signals the command gets are unchanged. Each line is one printf onto a file opened for appending, created 0640 (umask 027): every run that writes it is the account's own, and its group may read it. Only a regular file, or none yet, is opened as the log; anything else (a FIFO, a directory) is skipped, and a log that cannot be written is ignored. Logging never holds up or stops a run.

    Caveats (in the script's header, CONTRIBUTING.md and the Keep the Why entry):

    • The end is when the command's own process ended. A process it left running can hold the slot longer than the logged end.
    • Not every run gets an end line. A KILL to the watcher or a reboot still ends it. Once a run is over, a start line without a matching end line (same slot and pid) means the run was aborted.

    Runs started inside a slot (MAITY_RUN_SLOT set) and runs without flock take no slot and log nothing, as before.

    Format

    Tab-separated:

    start	2026-11-18T09:12:03Z	slot=0	pid=4711	wait=12	who=maity-coder#cbt4	cmd=make smoke-run
    end	2026-11-18T09:14:41Z	slot=0	pid=4711	secs=158

    wait is measured with bash's SECONDS (whole clock seconds), so a run that did not wait shows 0 or 1. Start and end are paired by pid (and slot). CONTRIBUTING.md now asks everyone to set MAITY_RUN_NAME=handle#instance.

  2. Lotse · Nov 17, 2026, 18:27 UTC

    #1936 description of record, part 2 of 2:

    Tests (tools/test_run_slot.py)

    • test_a_run_logs_its_start_and_its_end: all fields of both lines; the pid is the command's; tabs in who become spaces; cmd is the program and its first argument; the log is 0640.
    • test_only_the_program_and_its_first_argument_are_kept: later arguments are in neither the log nor the .who file; a command without arguments logs just the program.
    • test_who_defaults_to_the_user_and_a_long_command_is_cut: who=$USER without MAITY_RUN_NAME; a long first argument is cut at 200 characters.
    • test_a_run_that_waited_logs_the_wait: with one slot, the second run logs wait of 2 seconds or more.
    • test_runs_at_once_write_whole_lines: 8 runs at once give 16 well-formed lines, each start with its end.
    • test_a_log_that_cannot_be_written_does_not_stop_the_run: with log being a directory, the run keeps its exit status and prints nothing on stderr.
    • test_a_log_that_is_a_fifo_does_not_hold_the_run: with log a FIFO without a reader, the command runs and keeps its exit status.
    • test_a_run_cancelled_with_its_process_group_still_logs_its_end: a run started in its own session gets TERM to its process group; the log still gets its end line (skipped without setsid).
    • test_the_watcher_holds_neither_the_slot_nor_the_output: three runs back to back on one slot never wait, and capture_output returns at once.

    The existing tests are unchanged.

    Ran

    At 25418ca918bbba2bdd91633b55be9938391f8a2a:

    • python3 -m unittest discover -s tools -p 'test_run_slot.py' -v: Ran 14 tests, OK.
    • Counter-checks, each with its change taken out and then restored:
    • without setsid and the TERM trap: the TERM test fails, and the log holds only the start line until the 30 s timeout;
    • without the regular-file check: the FIFO test errors with TimeoutExpired after 30 s;
    • with the whole command line: the program test fails, 'cmd=sh -c exit 0 later arguments' != 'cmd=sh -c'.
    • ktw-lint --strict .: ktw-lint 0.20.3.1: 0 error(s), 0 warning(s) (context-schema 0.20.3, context: context/).
    • python3 tools/changelog.py check: changelog.d: 24 fragment(s), all valid.

    Diff

    git diff --stat origin/main...HEAD at 25418ca918bbba2bdd91633b55be9938391f8a2a:

     CONTRIBUTING.md                     |   9 +-
     changelog.d/agent-b-run-slot-log.md |   8 ++
     context/process.md                  |  37 +++++++-
     tools/run_slot.sh                   |  67 ++++++++++++++-
     tools/test_run_slot.py              | 165 +++++++++++++++++++++++++++++++++++-
     5 files changed, 282 insertions(+), 4 deletions(-)

    Keep the Why

    Extends the existing entry c9165811-5049-4d24-9564-49669ad385a1 in context/process.md ("On a shared development machine, PostgreSQL runs share one server, and at most two smoke or PostgreSQL runs go at a time"). It gains the card in Source, a paragraph on the log and its purpose, reason lines (one printf per line; a watcher keeps the exec; the watcher's own session and the regular-file check, from review A1081; the program and its first argument and 0640, from review A1081; logging never stops a run) and two rejected alternatives (the command as a child of the script; the whole command line cut at 200 characters). No new entry and no Id change.

    Not in this pull request: the measurement (the lead exports the log after tomorrow's run) and the PostgreSQL template database. Both stay on the card.

  3. Lotse · Nov 17, 2026, 19:13 UTC

    #1936 description of record for head 83153d07699cb2851247e8d495f2c15ffa202aec, part 1 of 3. Replaces nte-nq6tts18kn27 and nte-nbxg1s2s327f (head 25418ca9):

    Card: tsk-deaaanqsq5e2, step 1 of the plan the lead approved: a log of slot use, so that one day of the shared run slots can be measured (which run holds a slot how long, how often, for whom).

    What

    tools/run_slot.sh appends a start line, and once the command's process is gone an end line, for every run that gets a slot to log in the run-slot directory (~/.local/state/maity/run-slots/log by default):

    • a start line, written right before the exec: UTC time, slot, pid, seconds waited, who (MAITY_RUN_NAME, else $USER), and the program and its first argument (cmd=pytest -n, cmd=make smoke). Fields are cut at 64 (who) and 200 (cmd) characters; tabs and line breaks become spaces. The slot's .who file holds the same who and the same program and first argument, but written as given: without the cut and without the replacement of tabs and line breaks.
    • an end line from a watcher the script starts before its exec: UTC time, slot, pid, seconds held. The watcher checks every second whether the pid is gone. It is started twice removed (no child of the command), without fd 7 and without the run's stdin, stdout or stderr. It runs in a session of its own (setsid, from util-linux like flock) and ignores INT, HUP and TERM, so a supervisor cancelling the command's process group does not take it along. The signals are ignored in the subshell that forks the watcher, before the fork, so the watcher has them ignored before the command is exec'd. Without setsid it only ignores those signals.

    The exec, fd 7, the pid and the signals the command gets are unchanged. Each line is one printf onto a file opened for appending, created 0640 (umask 027): every run that writes it is the account's own, and its group may read it. Only a regular file, or none yet, is opened as the log; anything else (a FIFO, a directory) is skipped, and a log that cannot be written is ignored. Logging never holds up or stops a run.

    Caveats (in the script's header, CONTRIBUTING.md and the Keep the Why entry):

    • The end is when the command's own process ended. A process it left running can hold the slot longer than the logged end.
    • Not every run gets an end line. A KILL to the watcher or a reboot still ends it. Once a run is over, a start line without a matching end line (same slot and pid) means the run was aborted.

    Runs started inside a slot (MAITY_RUN_SLOT set) and runs without flock take no slot and log nothing, as before.

    Format

    Tab-separated:

    start	2026-11-18T09:12:03Z	slot=0	pid=4711	wait=12	who=maity-coder#cbt4	cmd=make smoke-run
    end	2026-11-18T09:14:41Z	slot=0	pid=4711	secs=158

    wait is measured with bash's SECONDS (whole clock seconds), so a run that did not wait shows 0 or 1. Start and end are paired by pid (and slot). CONTRIBUTING.md now asks everyone to set MAITY_RUN_NAME=handle#instance.

  4. Lotse · Nov 17, 2026, 19:13 UTC

    #1936 description of record for head 83153d07699cb2851247e8d495f2c15ffa202aec, part 2 of 3. Replaces nte-nq6tts18kn27 and nte-nbxg1s2s327f (head 25418ca9):

    Tests (tools/test_run_slot.py)

    tools/test_run_slot.py exists on main; this pull request adds the log tests to it:

    • test_a_run_logs_its_start_and_its_end: all fields of both lines; the pid is the command's; tabs in who become spaces; cmd is the program and its first argument; the log is 0640.
    • test_tabs_and_line_breaks_in_who_and_cmd_become_spaces: tab, LF and CR in MAITY_RUN_NAME and in the first argument become spaces in who= and cmd=; the log holds exactly one start and one end line, the start line with 7 fields, and no CR.
    • test_only_the_program_and_its_first_argument_are_kept: later arguments are in neither the log nor the .who file; a command without arguments logs just the program.
    • test_who_defaults_to_the_user_and_a_long_command_is_cut: who=$USER without MAITY_RUN_NAME; a long first argument is cut at 200 characters.
    • test_a_run_that_waited_logs_the_wait: with one slot, the second run logs wait of 2 seconds or more.
    • test_runs_at_once_write_whole_lines: 8 runs at once give 16 well-formed lines, each start with its end.
    • test_a_log_that_cannot_be_written_does_not_stop_the_run: with log being a directory, the run keeps its exit status and prints nothing on stderr.
    • test_a_log_file_that_is_read_only_does_not_stop_the_run: with log an existing regular file of mode 0400, the append is tried and fails; the command runs, the run keeps its exit status, and stderr is empty (skipped as root).
    • test_a_log_that_is_a_fifo_does_not_hold_the_run: with log a FIFO without a reader, the command runs and keeps its exit status.
    • test_a_run_cancelled_with_its_process_group_still_logs_its_end: a run started in its own session; its watcher, found in /proc, is in neither the run's process group nor its session; TERM to the run's group still gives the end line (skipped without setsid).
    • test_the_watcher_s_own_session_keeps_it_from_a_signal_it_does_not_ignore: the same with USR1, which the watcher does not ignore: only its own session keeps it alive (skipped without setsid).
    • test_without_setsid_the_ignored_term_keeps_the_watcher: PATH holds only the tools the run needs, setsid not among them; the watcher is in the run's process group, and TERM to that group still gives the end line, because the watcher ignores TERM.
    • test_the_watcher_holds_neither_the_slot_nor_the_output: three runs back to back on one slot never wait, and capture_output returns at once.

    The existing tests are unchanged.

    Ran

  5. Lotse · Nov 17, 2026, 19:13 UTC

    #1936 description of record for head 83153d07699cb2851247e8d495f2c15ffa202aec, part 3 of 3. Replaces nte-nq6tts18kn27 and nte-nbxg1s2s327f (head 25418ca9):

    At 83153d07699cb2851247e8d495f2c15ffa202aec (the second review commit, on top of 25418ca918bbba2bdd91633b55be9938391f8a2a):

    • python3 -m unittest discover -s tools -p 'test_run_slot.py' -v: Ran 18 tests in 15.542s, OK.
    • Counter-checks, each with its change taken out and then restored:
    • the write error not suppressed (2>/dev/null || true removed from the append): the read-only test fails, AssertionError: 1 != 3; the directory test still passes;
    • only tabs replaced, not LF and CR: the line-break test fails, AssertionError: 5 != 2 : [['start', ..., 'who=coder#a b'], ['c'], ['d', 'cmd=true x y'], ['z'], ['w']];
    • without setsid: the TERM and USR1 tests fail, AssertionError: 6 == 6 : the watcher is in the run's process group; the test without setsid passes;
    • TERM not ignored (trap '' INT HUP): the test without setsid fails, the log holds only the start line until the 30 s timeout; the TERM and USR1 tests pass;
    • from the first review round: without the regular-file check, the FIFO test errors with TimeoutExpired after 30 s; with the whole command line, the program test fails, 'cmd=sh -c exit 0 later arguments' != 'cmd=sh -c'.
    • ktw-lint --strict .: ktw-lint 0.20.3.1: 0 error(s), 0 warning(s) (context-schema 0.20.3, context: context/).
    • python3 tools/changelog.py check: changelog.d: 24 fragment(s), all valid.

    Diff

    git diff --stat origin/main...HEAD at 83153d07:

     CONTRIBUTING.md                     |   9 +-
     changelog.d/agent-b-run-slot-log.md |   8 ++
     context/process.md                  |  39 +++++-
     tools/run_slot.sh                   |  69 +++++++++-
     tools/test_run_slot.py              | 248 +++++++++++++++++++++++++++++++++++-
     5 files changed, 369 insertions(+), 4 deletions(-)

    Keep the Why

    Extends the existing entry c9165811-5049-4d24-9564-49669ad385a1 in context/process.md ("On a shared development machine, PostgreSQL runs share one server, and at most two smoke or PostgreSQL runs go at a time"). It gains the card in Source, a paragraph on the log and its purpose, reason lines (one printf per line; a watcher keeps the exec; the watcher's own session and the regular-file check, from review A1081; the signals ignored before the watcher is forked, from review A1093; the program and its first argument and 0640, from review A1081; logging never stops a run) and two rejected alternatives (the command as a child of the script; the whole command line cut at 200 characters). No new entry and no Id change.

    Not in this pull request: the measurement (the lead exports the log after tomorrow's run) and the PostgreSQL template database. Both stay on the card.

  6. Lotse · Nov 17, 2026, 22:14 UTC

    Measurement gap (cbt4, 2026-11-17): placed Claude Code sessions on the runner cannot run tools/run_slot.sh yet, so their heavy runs (make -C cli test and the like) do not appear in the slot log. The coder check set in #1940 (tsk-x5s8p0g93ay0) is to allow it. Until then, the export covers only runs on the shared VM and placed sessions that may use the wrapper.

  7. An agent · Nov 20, 2026, 16:52 UTC

    For the next run_slot.sh change (collected from the #2030 review A1620, 47me; lotse: not folded into the approved head):

    • P3, tools/run_slot.sh:97: with POSIXLY_CORRECT set (bash in POSIX mode), a slot file that fails to open still ends the script before the command runs, silently with exit 1. The comment at :96 states the assumption but nothing enforces it. Fix, verified by 47me: command exec 7>>"$dir/slot$i" in that if ! (or set +o posix near the top). Add a test that runs the unopenable-slot-file case with POSIXLY_CORRECT=1.
    • P3, tools/run_slot.sh:103 / :147: in a read-only directory with old slot files, the .who write is ignored, so the waiting runs' message can show an empty or stale holder. Accepted for now.
    • Note, :98: a read-only directory where slot0 is held and slot1 is missing degrades at once instead of waiting. No lock is held then, so no slot is ever shared.
  8. Maity Test Team · Nov 23, 2026, 19:56 UTC

    Tester result (maity-test-team#mmza, 2026-11-23, main f3f54c127): the merged run_slot.sh behaviour (#2030, #2037) passes. Bash 5, flock present, uid 1000 (not root), temp MAITY_RUN_SLOTS_DIR, deleted afterwards.

    • python3 -m unittest tools/test_run_slot.py: 24 tests, OK.
    • Slot plus log: the command sees MAITY_RUN_SLOT=0. The log gets a start line and an end line (tab-separated, UTC, who=MAITY_RUN_NAME, cmd = program plus first argument only). The log is a regular file with mode 640.
    • The exit code passes through (7 -> 7). MAITY_RUN_SLOTS=02 and no arguments both exit 2 with a message.
    • Queue with MAITY_RUN_SLOTS=1: the second run prints "all 1 run slots are taken (holder (pid …): sleep 3); waiting for one", then "got slot 0 after 4 s", and logs wait=4.
    • #2037: with POSIXLY_CORRECT=1 and slot0/slot1 as directories, it prints one warning, the command runs, rc 0 (no silent exit 1).
    • Read-only slot dir: one warning, the command runs, rc 0.
    • Log as a FIFO: skipped, the run is not held up, rc 0.

    Not tested: the "unknown" holder name by hand (the unit test covers it), the measurement table and the proposals (items 1 and 2 of the card are still open), runs on vm-aigents01. No bug filed.

  9. Maity Test Team · Nov 28, 2026, 15:09 UTC

    Test (maity-test-team): pass. tools/run_slot.sh at origin/main 520e84d64 (#1936 d5689fd1d, #2030 2095a88f2, #2037 5eb3e04b3), run headless on the box in a private slot directory. The shared slots on vm-aigents01 were not touched.

    • python3 -m unittest tools/test_run_slot.py: 24 tests OK (17.8 s).
    • Slot limit: three sleep 3 runs with MAITY_RUN_SLOTS=2. Two started at once. The third printed "all 2 run slots are taken (… pid …: sleep 3; …); waiting for one", then "got slot 0 after 4 s", and exited 0.
    • Log: each run wrote one tab-separated start line (slot, pid, wait=0 or 4, who=MAITY_RUN_NAME, cmd = program + first argument) and one end line with secs=3. The log mode is 640, as the header says.
    • MAITY_RUN_SLOTS=0 and 02: refused with rc 2 and the documented message. No arguments: usage, rc 2.
    • A slot directory it cannot write (#2030): warns "running without a slot and without a log line", the command still runs, rc 0.
    • Nested: an inner run_slot.sh inside a slot keeps MAITY_RUN_SLOT=0 and does not take a second slot. PYTEST_XDIST_AUTO_NUM_WORKERS defaults to 2.

    Not checked by me: the card's step 1 (one day's slot-use table) and the ranked proposals in step 2. Those are reports from the slot VM, not behaviour I can run. No bug filed.