#!/bin/bash #SBATCH --job-name=r5_gate_backup #SBATCH --partition=ZEN4 #SBATCH --qos=nu-zen4 #SBATCH --gres=none #SBATCH --cpus-per-task=1 #SBATCH --mem=1G #SBATCH --time=00:10:00 #SBATCH --begin=2026-11-24T17:00:05 #SBATCH --output=/path/to/TURKIC_OCR_DATA/logs/%x_%j.out # R5 backup writer of the test-pass gate file (clarification J10, records/R5/RULE/j12_v3_4_clarifications_3.txt). # --begin is cluster local time (+05): 17:00:05 there is 12:00:05 UTC on 24 Nov 2026. # eval_vlm_test.py, score.py, LINEDET and REF only check that the gate file exists, so this script checks the clock # itself and never writes before 12:00:00 UTC, whenever Slurm happens to start it. # Exclusive create (noclobber): a gate file already written by hand is left alone, because # eval_vlm_test.py records the gate file's sha256 in every meta and a rewrite would break those records. # GATE_TEST_DIR and GATE_OPEN_UTC exist only for the dry tests in DATA/tmp; the real jobs set neither. # GATE_MAX_WAIT (seconds, default 120): the second real copy is submitted hours early without --begin and sleeps # until 12:00:00 UTC, so that a full ZEN4 queue at noon cannot delay the gate. set -u D=${GATE_TEST_DIR:-/path/to/TURKIC_OCR_DATA/outputs/r5} OPEN=$(date -u -d "${GATE_OPEN_UTC:-2026-11-24T12:00:00Z}" +%s) || { echo "bad open time; nothing written"; exit 2; } NOW=$(date -u +%s) if [ "$NOW" -lt "$OPEN" ]; then W=$((OPEN - NOW)) if [ "$W" -gt "${GATE_MAX_WAIT:-120}" ]; then echo "$(date -u +%FT%TZ) refused: $W s before the opening time; nothing written" exit 1 fi sleep $((W + 1)) fi if [ "$(date -u +%s)" -lt "$OPEN" ]; then echo "$(date -u +%FT%TZ) refused: clock still before the opening time; nothing written" exit 1 fi T=$(date -u +%FT%TZ) set -o noclobber for P in "$D/RULE/test_pass_started.txt" "$D/linedet/test_pass_started.txt" "$D/ref/test_pass_started.txt"; do if [ -e "$P" ]; then echo "$T exists, left alone: $P :: $(head -c 300 "$P")" elif printf 'R5 test pass started %s (UTC). Written by the backup gate job %s on %s (clarification J10, records/R5/RULE/j12_v3_4_clarifications_3.txt; gate of J9, records/R5/RULE/j11_v3_4_clarifications_2.txt).\n' \ "$T" "${SLURM_JOB_ID:-none}" "$(hostname -s)" > "$P"; then echo "$T written: $P sha256 $(sha256sum "$P" | cut -c1-64)" else echo "$T not written (created by another writer at the same moment): $P" fi done