Garry's Opinionated OpenClaw/Hermes Agent Brain
TypeScript
ci(native-locks): the data-safety step stops before the job timeout, so a stall keeps its log
garrytan01cced85835a
diff --git a/.github/workflows/native-locks.yml b/.github/workflows/native-locks.ymlindex c93e97823b..9747acf79b 100644--- a/.github/workflows/native-locks.yml+++ b/.github/workflows/native-locks.yml@@ -73,6 +73,10 @@ jobs:# Named exception: PR scope reduction, covered by scope=full runs (docs/TESTING.md#event-parity).exclude: ${{ fromJSON(inputs.scope == 'full' && '[]' || inputs.scope == 'primary' && '[{"bun":"1.4.0"}]' || '[{"bun":"1.4.0"},{"target":"linux-arm64-glibc"},{"target":"darwin-arm64"},{"target":"darwin-x64"},{"target":"win32-x64"},{"target":"win32-arm64"}]') }}steps:+ # The data-safety step stops its suites before this job's timeout: a timeout cancel keeps no log.+ - name: Record the job deadline+ shell: bash+ run: echo "GBRAIN_JOB_DEADLINE=$(( $(date +%s) + 15 * 60 ))" >> "$GITHUB_ENV"- uses: actions/checkout@11d5960a326750d5838078e36cf38b85af677262- uses: oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6with:@@ -113,23 +117,44 @@ jobs:GBRAIN_NATIVE_SUITE_BOUND_S: ${{ fromJSON('{"linux-x64-glibc":"180","linux-arm64-glibc":"150","darwin-arm64":"120","darwin-x64":"180","win32-x64":"540","win32-arm64":"390"}')[matrix.target] }}# A file still running at its target's bound is stuck: its process table and, on macOS,# a native stack sample go to the log before it is killed, because a job the timeout- # cancels keeps no log at all.+ # cancels keeps no log at all. Six suites at their bounds outlast the job (two darwin-x64+ # cells ran into the timeout with no log, #7303 and #7238), so every suite also stops+ # 90 s before the job deadline, and no diagnostic or kill can hold the step.run: |status=0bound_s="$GBRAIN_NATIVE_SUITE_BOUND_S"case "$bound_s" in ''|*[!0-9]*) echo "::error::GBRAIN_NATIVE_SUITE_BOUND_S is not set for this target"; exit 1 ;; esac+ case "${GBRAIN_JOB_DEADLINE:-}" in ''|*[!0-9]*) echo "::error::GBRAIN_JOB_DEADLINE is not set (the job's first step records it)"; exit 1 ;; esac+ stop_at=$((GBRAIN_JOB_DEADLINE - 90))+ within() {+ "$@" &+ local helper=$!+ for _ in $(seq 1 20); do+ if ! kill -0 "$helper" 2>/dev/null; then wait "$helper"; return; fi+ sleep 1+ done+ kill -KILL "$helper" 2>/dev/null+ echo "($1 was still running after 20 s and was stopped)"+ }bounded() {+ local left=$((stop_at - $(date +%s)))+ if [ "$left" -le 0 ]; then echo "::error::$1 not run: the job timeout is near"; return 1; fi+ local limit=$((left < bound_s ? left : bound_s))bun --no-env-file test --timeout=180000 "$1" &pid=$!- for _ in $(seq 1 "$bound_s"); do+ for _ in $(seq 1 "$limit"); doif ! kill -0 "$pid" 2>/dev/null; then wait "$pid"; return $?; fisleep 1done- echo "::error::$1 was still running after $bound_s s, this target's bound (its slowest suite's measured p99 plus margin); process table and stack sample follow, then it is killed"- ps -A -o pid,ppid,stat,etime,command 2>/dev/null || ps -ef- if command -v sample >/dev/null 2>&1; then sample "$pid" 3 2>&1 | head -200; fi+ echo "::error::$1 was still running after $limit s, this target's bound (its slowest suite's measured p99 plus margin) or the time left before the job timeout; process table and stack sample follow, then it is killed"+ within ps -A -o pid,ppid,stat,etime,command 2>/dev/null || within ps -ef+ if command -v sample >/dev/null 2>&1; then within sample "$pid" 3 2>&1 | head -200; fikill -TERM "$pid" 2>/dev/null; sleep 5; kill -KILL "$pid" 2>/dev/null- wait "$pid" 2>/dev/null+ for _ in $(seq 1 10); do+ if ! kill -0 "$pid" 2>/dev/null; then wait "$pid" 2>/dev/null; return 1; fi+ sleep 1+ done+ echo "::error::$1 is still running after SIGKILL: $(within ps -o pid,stat,wchan,command -p "$pid")"return 1}bounded test/persistence-publication-native.serial.test.ts || status=1diff --git a/test/scripts/data-safety-native-workflow.test.ts b/test/scripts/data-safety-native-workflow.test.tsindex a59d523918..b7bd6be426 100644--- a/test/scripts/data-safety-native-workflow.test.ts+++ b/test/scripts/data-safety-native-workflow.test.ts@@ -176,19 +176,59 @@ describe('data-safety native CI coverage', () => {const result = Bun.spawnSync(['bash', '-e', '-o', 'pipefail', '-c', `bun() { if [[ "$4" == "$GBRAIN_TEST_STUCK_SUITE" ]]; then exec sleep 600; fi; printf '%s\\n' "$4"; }${step.run}- `], { env: { PATH: process.env.PATH ?? '', GBRAIN_TEST_STUCK_SUITE: stuck, GBRAIN_NATIVE_SUITE_BOUND_S: '2' }, timeout: 60_000 });+ `], { env: { GBRAIN_JOB_DEADLINE: String(Math.floor(Date.now() / 1000) + 3600), PATH: process.env.PATH ?? '', GBRAIN_TEST_STUCK_SUITE: stuck, GBRAIN_NATIVE_SUITE_BOUND_S: '2' }, timeout: 60_000 });expect(result.exitCode).toBe(1);const stdout = result.stdout.toString();expect(stdout).toContain(`::error::${stuck} was still running after 2 s, this target's bound`);expect(stdout.trim().split('\n').filter(line => line.startsWith('test/'))).toEqual(suites.filter(suite => suite !== stuck));});+ test('a stall in every suite still ends the step, with its diagnostics, before the job timeout cancels the log', () => {+ // Two darwin-x64 cells (#7303 on Bun 1.4.0, #7238 on Bun 1.4.3) ran this step into the 15-minute job timeout and kept+ // no log: six suites at a 180 s bound each outlast the job, so the bound's own process table and sample were lost.+ const step = workflow.jobs.native.steps.find(entry => entry.name === 'Verify native data-safety contracts')!;+ const started = performance.now();+ const result = Bun.spawnSync(['bash', '-e', '-o', 'pipefail', '-c', `+ bun() { exec sleep 600; }+ ${step.run}+ `], { env: { PATH: process.env.PATH ?? '', GBRAIN_NATIVE_SUITE_BOUND_S: '3', GBRAIN_JOB_DEADLINE: String(Math.floor(Date.now() / 1000) + 90 + 5) }, timeout: 120_000 });+ const seconds = (performance.now() - started) / 1000;+ const stdout = result.stdout.toString();+ expect(result.exitCode).toBe(1);+ expect(stdout).toContain(`::error::${suites[0]} was still running after 3 s, this target's bound`);+ expect(stdout).toContain(`::error::${suites.at(-1)} not run: the job timeout is near`);+ expect(seconds).toBeLessThan(40);+ }, 130_000);++ test('a suite that outlives SIGKILL is reported and does not hold the step', () => {+ const step = workflow.jobs.native.steps.find(entry => entry.name === 'Verify native data-safety contracts')!;+ const stuck = suites[1]!;+ const started = performance.now();+ const result = Bun.spawnSync(['bash', '-e', '-o', 'pipefail', '-c', `+ bun() { if [[ "$4" == "$GBRAIN_TEST_STUCK_SUITE" ]]; then exec sleep 40 >/dev/null 2>&1; fi; printf '%s\\n' "$4"; }+ kill() { case "$1" in -TERM|-KILL) return 0 ;; *) command kill "$@" ;; esac; }+ ${step.run}+ `], { env: { PATH: process.env.PATH ?? '', GBRAIN_TEST_STUCK_SUITE: stuck, GBRAIN_NATIVE_SUITE_BOUND_S: '2', GBRAIN_JOB_DEADLINE: String(Math.floor(Date.now() / 1000) + 3600) }, timeout: 90_000 });+ const stdout = result.stdout.toString();+ expect(result.exitCode).toBe(1);+ expect(stdout).toContain(`::error::${stuck} is still running after SIGKILL`);+ expect((performance.now() - started) / 1000).toBeLessThan(35);+ expect(stdout.trim().split('\n').filter(line => line.startsWith('test/'))).toEqual(suites.filter(suite => suite !== stuck));+ }, 100_000);++ test('the native job records its deadline from its own timeout before any other step', () => {+ const job = workflow.jobs.native as unknown as { steps: Step[]; 'timeout-minutes': number };+ expect(job.steps[0]!.name).toBe('Record the job deadline');+ expect(job.steps[0]!.shell).toBe('bash');+ expect(job.steps[0]!.run!.trim()).toBe(`echo "GBRAIN_JOB_DEADLINE=$(( $(date +%s) + ${job['timeout-minutes']} * 60 ))" >> "$GITHUB_ENV"`);+ });+for (const failed of ['', ...suites]) test(`every native safety suite runs and failures remain fatal (${failed || 'all pass'})`, () => {const step = workflow.jobs.native.steps.find(entry => entry.name === 'Verify native data-safety contracts')!;const result = Bun.spawnSync(['bash', '-e', '-o', 'pipefail', '-c', `bun() { printf '%s\\n' "$4"; [[ "$4" != "$GBRAIN_TEST_FAILED_SUITE" ]]; }${step.run}- `], { env: { PATH: process.env.PATH ?? '', GBRAIN_TEST_FAILED_SUITE: failed, GBRAIN_NATIVE_SUITE_BOUND_S: '60' } });+ `], { env: { GBRAIN_JOB_DEADLINE: String(Math.floor(Date.now() / 1000) + 3600), PATH: process.env.PATH ?? '', GBRAIN_TEST_FAILED_SUITE: failed, GBRAIN_NATIVE_SUITE_BOUND_S: '60' } });expect(result.exitCode).toBe(failed ? 1 : 0);expect(result.stdout.toString().trim().split('\n')).toEqual(suites);});