Skip to content

fix(tier3): bound declarative output pattern checks - #750

Merged
rng1995 merged 12 commits into
NVIDIA:mainfrom
Afloat16:fix/bound-declarative-regex-matching
Nov 23, 2026
Merged

rng1995 merged 12 commits into
NVIDIA:mainfrom
Afloat16:fix/bound-declarative-regex-matching

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A valid declarative output_matches pattern such as ^(a|aa)+$ can spend unbounded time backtracking on a nonmatching answer, preventing grading and later checks from completing.

Run runtime pattern compilation and search in an isolated Python worker with the standard-library re engine. The worker signals ready after interpreter startup, imports, and JSON input. Readiness has a separate ten-second allowance; only then does the per-pattern deadline start, capped by the remaining shared matching budget (defaults: one second per pattern and five seconds shared). The worker reports its compile-and-search duration for shared-budget accounting. A timeout or exhausted matching budget fails the check and keeps it in the score denominator. Invalid-pattern errors reported by the worker and unavailable workers leave the check unscored with an explanation; literal and other check types continue. The ASCII JSON protocol preserves non-ASCII and lone-surrogate error details, and all started children are killed when necessary and reaped.

Keeping Python re preserves its character classes, backreferences, lookarounds and flags. Substituting another regex engine changes existing results for combining marks, zero-width joiners and the U+001C whitespace character.

This change covers runtime output_matches compilation and matching. Preflight validate_declarative_checks compilation is outside this change. These are matching limits, not a five-second wall-clock limit for the entire evaluation. Interpreter startup and JSON transfer add overhead under their separate startup allowance and do not reduce the matching budget.

Current review follow-up

Head 7c38511a0c20afa86b7d731b76c0fc41ea5512ac includes the score and configuration fix in 7e27ee958476582952a03200ebebe89d6c32c093 and a merge of main a3bb7e91a325c92e1d2e05bcd716e1139e3624f2. The merge preserves all PR code, test and documentation blobs and retains both Unreleased changelog entries.

Timeouts and exhausted matching budgets now count as failures. The reported backtracking case with two successful judged items scores 0.6667, compared with 1.0 on the preceding head. The existing verifier environment forwards SKILL_EVAL_OUTPUT_PATTERN_TIMEOUT_SEC and SKILL_EVAL_OUTPUT_PATTERN_BUDGET_SEC into staged Harbor verification. Positive finite settings configure the limits; invalid values use the defaults, and very large finite values are capped at the platform wait limit.

Validation of the fix: 86 declarative/report tests with locked Python 3.13.11 dependencies, 121 host-environment cases, the task.toml forwarding regression, and 57 declarative tests on Python 3.14.6 pass. Four new focused regressions fail against the preceding implementation. Full source/test Ruff, changed-file formatting, diff checks, Fern check, source/archive OSS scans and isolated wheel/sdist builds pass.

The broader five-module run had 922 passes and 41 environment-related failures: missing SOCKS support for inherited proxy settings and provenance fixtures finding the enclosing workspace repository. Seven representative failures reproduce on the preceding head. This is not a full-suite pass.

Current upstream CI

The review on the current head confirms the score and environment-forwarding concerns are addressed, including four runs of all 57 declarative tests.

All five workflows have now run on 7c38511a0c20afa86b7d731b76c0fc41ea5512ac:

Workflow Result
CI Failure in Tier 2 Windows; every other executed job passed, with Tier 2 macOS skipped
Request NVSkills CI Success
Build and publish Tier 1 image Success
DCO Check Success
Security Success

The failed Windows job reports 1 failed, 5,141 passed, 173 skipped. Its test_bounded_harbor_process_failure_reaps_windows_descendants[output] failure is the assertion at tests/test_harbor_runner_status.py:713: the output-windows-child-survived marker exists.

The runner, test file, CI workflow and lockfile match current main ac9fc0ef4999ee5eb86eae27ec3a83c880891c92 and the passing Windows runs on #719 and #728 byte for byte. Main fails the same output-mode test with a different Harbor process-tree cleanup could not be confirmed exception. The marker assertion has not been reproduced on main, so these are not claimed to be identical failures. A rerun of the failed Windows job is the next requested check; upstream CI is not fully green.

Verification

New tests cover Python regex compatibility, an actual backtracking pattern, shared-budget exhaustion, later literal-check execution, deeply nested compilation, worker startup failure and the standalone verifier bundle. Against unchanged production code, the focused baseline run produced 2 failures and 8 passing compatibility controls: the backtracking check exceeded the enclosing five-second process deadline, and the deep pattern raised RecursionError.

The declarative-check, declarative-report-coverage, attempt-verdict and Harbor metrics-truth test modules together passed 199 tests on Python 3.12; the declarative module passed 46 tests on both Python 3.12 and 3.14.

Earlier review follow-up

Commit 387c583bed953403a1fddba66db861f4c19bf3c8 addresses the startup deadline, encoding, and missing-executable findings. The new review cases give 5 failures and 36 passing controls on 06bb05e, then pass after the fix. A real delayed worker proves two ordinary patterns still score when each startup exceeds the matching limit. Additional cases verify startup and matching timeouts reap children, remaining-budget exhaustion is distinguished from a per-pattern timeout, invalid worker messages cannot become matches, and later literal checks still run.

Main 33d49eb2 was previously merged to resolve the real changelog conflict. The entry is under Unreleased, with the published release sections preserved. Full source/test Ruff, changed-file formatting, diff checks, and isolated wheel/sdist builds pass. Full upstream CI still requires its own maintainer approval and results.

  • I am familiar with the Contributing Guidelines
  • Added or updated focused tests
  • Updated documentation for user-visible changes (Unreleased changelog)
  • Ran make lint equivalent: python -m ruff check src tests
  • Full make test did not complete successfully in this environment (see below)
  • Ran make build equivalent: python -m build --installer uv (isolated wheel and sdist)
  • Did not add credentials, private datasets, or proprietary benchmark content

Changed-file formatting and git diff --check passed. The earlier full-suite baseline attempt stopped on unchanged base d2cb138 in test_gitlab_enriched_tier1_applies_the_keyless_job_baselines: its shell fixture hard-codes mktemp -d /tmp/..., while this workspace has no /tmp. That base run reached 456 passed, 2 skipped and 19 deselected before the failure.

Release Impact

  • Updated CHANGELOG.md

Signed-off-by: Afloat <ShuffleMonkey@163.com>
Keep this pull request's code, tests and changelog delta unchanged against
upstream main while resolving only the Unreleased changelog insertion.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
Resolve the Unreleased changelog insertion while preserving exactly
this pull request's code, tests, and release note against current main.

Signed-off-by: Afloat <ShuffleMonkey@163.com>

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution, @Afloat16. Reviewed 06bb05eba97f; no actionable defects found in the changed code.

Focused validation: 35 declarative-check tests passed.

Hosted CI is still awaiting authorization or completion; this is a code-review approval, and does not certify a full hosted CI pass.

@rng1995
rng1995 enabled auto-merge (squash) November 17, 2026 19:00

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Afloat16 for this contribution! I reviewed 06bb05eba9. I reproduced the problem on main, confirmed this change fixes it, checked that the new tests fail on main, and ran the new and related tests on this head (all pass). I left 2 inline comments (2 P3).

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding measured severity to the open thread about the deadline covering interpreter startup, because it changes this from a nit to a blocker for me.

On a 12-core host at load average 35 to 360 (parallel test runs), every ordinary output_matches check in a trial came back None with "the regular expression timed out" and then "budget was exhausted": ten plain literal patterns, 150 plain patterns, seven realistic patterns against a 1 MB answer that main scores in under 125 ms, and ^(a|aa)+$ against 26 a's that main answers False in 24 ms. python -I -c 'import json,re,sys' alone measured 0.26 to 1.45 s there. In a full-suite run at that load, 12 tests in tests/tier3/test_declarative_checks.py failed on this branch, including the pre-existing test_final_response_checks_match_contains_and_regex, which passes on main under the same load; all 35 pass again when the host is quiet. Since None drops the check from the score denominator, host load becomes score noise for ordinary patterns, which is a worse trade than the hang this fixes (confined to pathological patterns and surfaced as a trial error).

The suggestions in that thread (arm the deadline only after the worker signals ready, or one worker per evaluate_declarative_checks call) would address it; at minimum the per-check limit needs to be seconds, not 1 s, with the budget sized to match. Separately, sys.executable can be None, and subprocess.run([None, ...]) raises TypeError out of the evaluation instead of the handled "worker could not be started" path.

Use a bounded ready handshake and ASCII JSON results, charge only compile
and match time, and reap workers after startup or matching failures.
Merge current main and place the release note under Unreleased.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
auto-merge was automatically disabled November 18, 2026 04:11

Head branch was pushed to by a user without write access

Keep both release-note entries and preserve the existing PR implementation and regression tests.

Signed-off-by: Afloat <ShuffleMonkey@163.com>

@rng1995 rng1995 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Afloat16 for this contribution and for addressing the earlier review! I re-checked 20b059cae8: all 2 earlier comments are resolved in the code, the tests pass, and I found nothing new. Approving.

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed on this head: interpreter startup now sits behind its own 10 s ready wait and only the worker's compile-and-match time counts against the 1 s deadline, a missing sys.executable is handled, and stuck workers are reaped. The declarative-check tests passed 46 of 46 in every run here, including under heavy host load where the previous version dropped checks. One policy note, not blocking: a pattern that times out still yields no verdict rather than a failure, same as before. Thanks, this is ready from my side.

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing from running this together with the other Tier 3 changes through the staged verifier, and I think it needs a decision before merge. A pattern that main evaluates in about one to two seconds and correctly marks as not matching (the check fails, behavior_check 0.67 for that case) now hits the 1 s deadline, is reported as timed out, and is dropped from the score, so behavior_check becomes 1.0. Reproduced twice at moderate host load with a 36-character input against a pattern of the form (a|aa)+ anchored at both ends. That means a slow but legitimate failing check can now raise a skill's score instead of lowering it. I would rather a timed-out pattern count as a failed check (or at least stay in the denominator), and have the deadline configurable, than have it vanish from the score. Happy to discuss if you see it differently.

Count pattern timeouts and exhausted matching budgets as failed checks. Expose positive finite matching limits through the existing verifier environment and retain unscored worker startup and invalid-pattern errors.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
Resolve only the competing changelog insertion. Preserve the reviewed pull request implementation, tests, and documentation unchanged while retaining upstream updates.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
@Afloat16

Copy link
Copy Markdown
Contributor Author

Changed in 7e27ee9, included in current head 7c38511. Timeouts and exhausted matching budgets now produce a failed check and remain in the behavior_check denominator. A direct backtracking reproduction with two otherwise successful judged items gives 1.0 on the preceding head and 0.6667 with this fix. Invalid-pattern errors reported by a worker and worker startup failures retain their unavailable semantics.

The existing verifier environment now forwards SKILL_EVAL_OUTPUT_PATTERN_TIMEOUT_SEC and SKILL_EVAL_OUTPUT_PATTERN_BUDGET_SEC (defaults 1 s and 5 s). Positive finite settings configure both limits; invalid values use the defaults, and very large finite values are bounded to the platform wait limit. Tests cover actual ready-worker deadlines, exhausted budgets, score denominators, staged-worker behavior and host-to-Harbor environment forwarding.

Validation: 86 declarative/report tests with locked Python 3.13.11 dependencies; 121 host-environment cases and the task.toml forwarding regression; all 57 declarative tests on Python 3.14.6. Four focused regressions fail against the previous implementation. Ruff, formatting, diff checks, Fern check, source/archive OSS scans and isolated wheel/sdist builds pass. The main merge keeps all PR code/test/docs blobs unchanged. The new workflows are awaiting maintainer approval.

@chrisknvidia chrisknvidia left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed on the current head: the slow failing pattern now comes back as a failed check and stays in the denominator (behavior_check 0.6667 here, the same as main, where the previous head gave 1.0), both calling evaluate_declarative_checks directly and through the staged verifier, while an invalid pattern or a worker that cannot start is still left unscored. The two new environment variables reach the staged verifier (with a 10 s deadline the same pattern evaluates to a plain no-match) and invalid values fall back to the defaults. The declarative-check tests passed 57 of 57 in four runs here. Thanks, this addresses my concern; ready from my side once CI has run.

@Afloat16

Copy link
Copy Markdown
Contributor Author

Thanks for the four 57/57 declarative-test runs and for checking the score and environment forwarding.

CI has now run on 7c38511a0c20afa86b7d731b76c0fc41ea5512ac. The four other workflows passed, and every executed CI job passed except Tier 2 Windows (the Tier 2 macOS job was skipped).

The Windows job reports 1 failed, 5,141 passed, 173 skipped. The failure is test_bounded_harbor_process_failure_reaps_windows_descendants[output] at tests/test_harbor_runner_status.py:713: assert not child_marker.exists() fails because the output-windows-child-survived marker exists.

The runner, test file, CI workflow and dependency lockfile are byte-identical to current main ac9fc0ef4999ee5eb86eae27ec3a83c880891c92 and to #719 / #728, whose Windows jobs passed. Current main also fails the same output-mode test, but with Harbor process-tree cleanup could not be confirmed; that is a different failure from this marker assertion. I have not found a path from this PR's regex-matching or verifier-environment changes to the failing process-tree check, and the logs do not establish the marker's timing.

Could you rerun just the failed Tier 2 Windows job on this head?

Signed-off-by: Afloat <ShuffleMonkey@163.com>
Signed-off-by: Afloat <ShuffleMonkey@163.com>
Synchronize with NVIDIA/SkillEvaluator main f867b7f.
Retain this PR's entry under Unreleased and preserve published release history.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
@rng1995

rng1995 commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator

Thanks @Afloat16 for this contribution! This PR now conflicts with main in CHANGELOG.md only (main has moved on and released since it was opened), and Allow edits by maintainers is turned off for this PR, so we cannot update the branch for you. Could you please:

  1. Turn on Allow edits by maintainers for this PR, so maintainers can push merge fixes directly.
  2. Merge the latest main into your branch and resolve the CHANGELOG.md conflict, keeping main's entries exactly as they are and your entry under ## Unreleased.

While re-running the tests under load, test_backtracking_pattern_has_a_shared_deadline_and_other_checks_continue failed once: its child interpreter run has a 5 s subprocess timeout and took 4.6 s on a loaded host, although every pattern deadline under test is 0.05 s. Raising that outer bound (we used 60 s, which only guards against a hang) avoids the flake.

Once that is done we will re-check and merge. Thanks again!

Synchronize with NVIDIA/SkillEvaluator main 4327960.
Keep upstream release history unchanged and this PR note under Unreleased.
Raise only the subprocess hang guard from 5 to 60 seconds; keep pattern and shared deadlines at 0.05 seconds.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
@Afloat16

Copy link
Copy Markdown
Contributor Author

Updated in 6298f1f, merging main 4327960b90 and retaining both the published release history and this PR’s Unreleased note. The subprocess hang guard is now 60 seconds; the actual pattern and shared deadlines remain 0.05 seconds.

The focused declarative/environment-forwarding selection passes 159 tests. Full source/test Ruff, changed-file formatting and whitespace checks pass. A broader three-module run had 773 passes, 43 failures and 1 deselection: workspace Git-root/provenance-key containment failures and five host SOCKS/httpx setup failures. A representative provenance failure also reproduces on unchanged main, so a full-suite pass is not claimed.

The branch is mergeable. New-head Actions runs are action_required pending maintainer approval; ready for your re-check once those can run.

@rng1995
rng1995 enabled auto-merge (squash) November 23, 2026 03:48
Synchronize with NVIDIA/SkillEvaluator main e11e13a.
Preserve released history and this PR's existing implementation and tests.

Signed-off-by: Afloat <ShuffleMonkey@163.com>
auto-merge was automatically disabled November 23, 2026 10:42

Head branch was pushed to by a user without write access

@rng1995
rng1995 merged commit a6d9818 into NVIDIA:main Nov 23, 2026
23 checks passed
@chrisknvidia chrisknvidia mentioned this pull request Nov 23, 2026
6 of 7 tasks
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.

3 participants