Skip to content

fix(jsonschema_bench): add per-sample validation timeout to prevent eval hangs#3923

Open
hancheolcho wants to merge 1 commit into
EleutherAI:mainfrom
hancheolcho:fix/jsonschema-bench-validation-timeout
Open

fix(jsonschema_bench): add per-sample validation timeout to prevent eval hangs#3923
hancheolcho wants to merge 1 commit into
EleutherAI:mainfrom
hancheolcho:fix/jsonschema-bench-validation-timeout

Conversation

@hancheolcho

@hancheolcho hancheolcho commented Jul 10, 2026

Copy link
Copy Markdown

Summary

jsonschema_bench can hang an entire evaluation indefinitely during scoring. schema_compliance() validates each prediction with an unbounded call to schema_conform_with_format_checker (jsonschema Draft202012Validator + FormatChecker). A single pathological schema/instance — e.g. a deeply-recursive $ref, or a format regex with catastrophic backtracking — spins the CPU forever, so the scoring phase never returns. Generation completes, but the process then sits at ~100% CPU with no progress and no error/traceback.

Fix

Wrap the per-sample validation in a wall-clock SIGALRM timeout (_run_with_timeout). On timeout the sample is treated as non-compliant (return False) — the same outcome the existing except Exception branch already produces for un-processable schemas — instead of hanging.

  • Per-sample budget defaults to 40s, overridable via the JSONSCHEMA_BENCH_TIMEOUT_S environment variable.
  • If SIGALRM is unavailable (non-main thread, or an unsupported platform), validation runs unguarded, so behavior never regresses to a crash.
  • The change is confined to lm_eval/tasks/jsonschema_bench/metrics.py; samples that already validate within the budget are scored exactly as before.

Notes

  • No change to scores for samples that validate within the time budget.
  • Only the jsonschema_bench task is affected.

…val hangs

schema_compliance() validates each prediction with an unbounded call to
schema_conform_with_format_checker (jsonschema Draft202012Validator +
FormatChecker). A single pathological schema/instance (deeply-recursive $ref,
or a format regex with catastrophic backtracking) spins the CPU indefinitely,
so the scoring phase never returns and the whole evaluation hangs with no error.

Wrap the per-sample validation in a wall-clock SIGALRM timeout. On timeout the
sample is treated as non-compliant (returns False), matching how the existing
except-branch already handles un-processable schemas, instead of hanging.
Budget defaults to 40s and is overridable via JSONSCHEMA_BENCH_TIMEOUT_S. If
SIGALRM is unavailable (non-main thread / unsupported platform) validation runs
unguarded so behavior never regresses to a crash.
@CLAassistant

CLAassistant commented Jul 10, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

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