Skip to content

refactor: share object dispatch and field classification - #535

Merged
sromoam merged 2 commits into
awslabs:devfrom
lj1166:refactor/516-share-field-classification
Nov 12, 2026
Merged

sromoam merged 2 commits into
awslabs:devfrom
lj1166:refactor/516-share-field-classification

Conversation

@lj1166

@lj1166 lj1166 commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Issue Reference

Closes #516. Claimed in #516 (comment).

Description of Changes

Dict pairs and plain Pydantic model pairs now share CASE 4/5 in the dispatcher. The StructuredModel branch still runs first. The merged branch uses the already-resolved comparator and preserves the existing object-pair gate.

Primitive and structured field comparisons share a private TP/FD classifier. It returns a fresh metrics dictionary on each call and preserves the original threshold and clipping rules. Public signatures, output shape, and existing tests are unchanged. Removed the duplicate import and replaced the scoped history/TODO comments with the current rules.

Two source files changed: +27 / -134 lines. No dependency, lockfile, test, or public documentation changes.

Testing

Compared against clean dev at cf90773855035fa7ac3d8bd0932dbea3367dc151.

  • Linux (WSL Ubuntu 24.04, Python 3.12.3), uv sync --frozen dependencies. Full python -m pytest -q -o addopts=--tb=short on both trees: 4091 passed, 13 skipped, 1 xfailed, no failures. Confirmed inspect.getfile(stickler) pointed to the corresponding head/baseline checkout before each run.
  • Windows (Python 3.12.16, UTF-8 mode), the same full suite on both trees: 4085 passed, 6 failed, 13 skipped, 1 xfailed. All six failures are unchanged deep-nesting timeout tests calling POSIX signal.SIGALRM, which Windows lacks.
  • The five issue-listed focused modules: 335 passed on Windows with UTF-8 mode. Includes the configuration-lookup count guard.
  • Ruff passes on both changed files. Full ruff check . reports the same 16 existing diagnostics on baseline and head (notebook imports/unused f-string prefixes and the LLM example import); diagnostic output is identical.
  • git diff --check passed. No existing test was edited, as requested for this behavior-preserving refactor.

Optional BERT/Strands live-provider extras were not installed locally; skipped tests are not counted as executed.

Checklist

  • Branch based on dev; PR targets dev.
  • Existing tests left unchanged; full Linux suite passes on both trees.
  • Code self-reviewed against the issue's ordering, lookup, fresh-dictionary, and public-signature constraints.
  • No changelog entry: no user-visible behavior change.
  • Upstream CI (pending after PR creation).

Additional Notes

AI assistance: OpenAI Codex (GPT-6 Astra) for source analysis, implementation, and validation. No independent fresh-context review is claimed.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Closes awslabs#516

Signed-off-by: luojie <16602829831@163.com>
Signed-off-by: luojie <16602829831@163.com>
@sromoam
sromoam removed their request for review November 4, 2026 16:26

@vawsgit vawsgit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ LGTM!

Verified at head 212967c, merged with current dev 58f2dd3, with stickler imported from that checkout's src:

  • Behaviour is unchanged. I generated 3,000 random ground-truth and prediction pairs. They covered nested models at two levels, lists of models and scalars, Optional scalars, Dict[str, Any] with default and ExactComparator, plain BaseModels and lists of them, Union[Cat, Dog], Any, None vs empty, and both clip_under_threshold settings. Each pair's full compare_with output (confusion matrix, non-matches, field comparisons), evaluator_format=True output, compare() and the warnings hash to the same value on dev and on this PR: 39c77db8…a186b. An instrumented run confirmed that every changed path is reached: the object-pair gate in both directions, the Cat/Dog refusals, and TP / clipped FD / unclipped FD in both classifiers.
  • Branch order holds. A model-vs-model pair still takes CASE 3, a mixed pair reaches the merged branch, and a dict paired with a BaseModel falls through to the mismatch branch. No new configuration lookup is added, and TestTheFieldConfigurationIsLookedUpOnce passes.
  • Full suite on the merge: 4127 passed, 3 skipped, 1 xfailed with the llm, bert and dev extras. Mutations are caught: swapping the clip rule in _classify fails 31 tests, and dropping the BaseModel arm fails 36.
  • Every "Done when" item in #516 is met, and no test was edited. Ruff is clean. No conflict with dev.

Non-blocking (low):

  • Stale references: configuration_helper.py:375, 442, 506, 560 and comparison_helper.py:35, 96 still say "CASE 4 and CASE 5" or "CASE 5". The can_compare_object_pair docstring still counts "FIVE readers", where there are now four.
  • comparison_dispatcher.py:236 cites #135 for "the comparator decides coercion", but #135 is about ANLSTree vs ComparisonEngine.
  • No test pins the #516 rule that _classify returns a new dict on every call. Returning shared dicts passes all tests.

@github-actions

Copy link
Copy Markdown

Security Scan Results

ASH Security Scan Report

  • Report generated: 2026-11-12T19:47:42+00:00
  • Time since scan: 2 minutes

Scan Metadata

  • Project: ASH
  • Scan executed: 2026-11-12T19:44:47+00:00
  • ASH version: 3.1.2

Summary

Scanner Results

The table below shows findings by scanner, with status based on severity thresholds and dependencies:

  • Severity levels:
    • Suppressed (S): Findings that have been explicitly suppressed and don't affect scanner status
    • Critical (C): Highest severity findings that require immediate attention
    • High (H): Serious findings that should be addressed soon
    • Medium (M): Moderate risk findings
    • Low (L): Lower risk findings
    • Info (I): Informational findings with minimal risk
  • Duration (Time): Time taken by the scanner to complete its execution
  • Actionable: Number of findings at or above the threshold severity level that require attention
  • Result:
    • PASSED = No findings at or above threshold
    • FAILED = Findings at or above threshold
    • MISSING = Required dependencies not available
    • SKIPPED = Scanner explicitly disabled
    • ERROR = Scanner execution error
  • Threshold: The minimum severity level that will cause a scanner to fail
    • Thresholds: ALL, LOW, MEDIUM, HIGH, CRITICAL
    • Source: Values in parentheses indicate where the threshold is set:
      • global (global_settings section in the ASH_CONFIG used)
      • config (scanner config section in the ASH_CONFIG used)
      • scanner (default configuration in the plugin, if explicitly set)
  • Statistics calculation:
    • All statistics are calculated from the final aggregated SARIF report
    • Suppressed findings are counted separately and do not contribute to actionable findings
    • Scanner status is determined by comparing actionable findings to the threshold
Scanner Suppressed Critical High Medium Low Info Actionable Result Threshold
bandit 0 6 0 0 6632 0 6 FAILED MEDIUM (global)
cdk-nag 0 0 0 0 0 0 0 PASSED MEDIUM (global)
cfn-nag 0 0 0 0 0 0 0 MISSING MEDIUM (global)
checkov 0 0 0 0 0 0 0 PASSED MEDIUM (global)
detect-secrets 0 1 0 0 0 0 1 SKIPPED MEDIUM (global)
grype 0 0 0 0 0 0 0 MISSING MEDIUM (global)
npm-audit 0 0 0 0 0 0 0 PASSED MEDIUM (global)
opengrep 0 0 0 0 0 0 0 MISSING MEDIUM (global)
semgrep 3 0 0 0 0 0 0 PASSED MEDIUM (global)
syft 0 0 0 0 0 0 0 MISSING MEDIUM (global)

Top 4 Hotspots

Files with the highest number of security findings:

Finding Count File Location
2 tests/comparators/test_anls_leaf_semantics.py
2 .ash/ash_output/converted/jupyter/examples__notebooks__Strands_Evals_FCC_Live_Agent__ipynb-converted.py
2 tests/structured_object_evaluator/test_rollup_node_semantics.py
1 tests/test_readme_examples.py

Detailed Findings

Show 7 actionable findings

Finding 1: SECRET-HEX-HIGH-ENTROPY-STRING

  • Severity: HIGH
  • Scanner: detect-secrets
  • Rule ID: SECRET-HEX-HIGH-ENTROPY-STRING
  • Location: tests/comparators/test_anls_leaf_semantics.py:89

Description:
Secret of type 'Hex High Entropy String' detected in file 'tests/comparators/test_anls_leaf_semantics.py' at line 89

Code Snippet:

Secret of type Hex High Entropy String detected

Finding 2: B310

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B310
  • Location: .ash/ash_output/converted/jupyter/examples__notebooks__Strands_Evals_FCC_Live_Agent__ipynb-converted.py:83-85

Description:
Audit url open for permitted schemes. Allowing use of file:/ or custom schemes is often unexpected.

Code Snippet:

)
with urllib.request.urlopen(url, timeout=60) as resp:
    rows = [item["row"] for item in json.load(resp)["rows"]]

Finding 3: B108

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B108
  • Location: tests/comparators/test_anls_leaf_semantics.py:210-212

Description:
Probable insecure usage of temp file/directory.

Code Snippet:

uuid.UUID(int=1),
            pathlib.Path("/tmp/x"),
            b"bytes",

Finding 4: B307

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B307
  • Location: tests/structured_object_evaluator/test_rollup_node_semantics.py:1363-1369

Description:
Use of possibly insecure function - consider using safer ast.literal_eval.

Code Snippet:

def published_label(node: dict, section: str, object_lists: set) -> str:
            counts_objects = eval(  # noqa: S307
                cond.group(1),
                {},
                {"data": node, "section": section, "OBJECT_LISTS": object_lists},
            )
            return eval(unit.group(1), {}, {"counts_objects": counts_objects})  # noqa: S307

Finding 5: B307

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B307
  • Location: tests/structured_object_evaluator/test_rollup_node_semantics.py:1368-1370

Description:
Use of possibly insecure function - consider using safer ast.literal_eval.

Code Snippet:

)
            return eval(unit.group(1), {}, {"counts_objects": counts_objects})  # noqa: S307

Finding 6: B102

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B102
  • Location: tests/test_readme_examples.py:55-57

Description:
Use of exec detected.

Code Snippet:

with contextlib.redirect_stdout(out):
        exec(code, namespace)
    prints = [line for line in code.splitlines() if line.startswith("print(")]

Finding 7: B310

  • Severity: HIGH
  • Scanner: bandit
  • Rule ID: B310
  • Location: .ash/ash_output/converted/jupyter/examples__notebooks__Strands_Evals_FCC_Live_Agent__ipynb-converted.py:83-85

Description:
Audit url open for permitted schemes. Allowing use of file:/ or custom schemes is often unexpected.

Code Snippet:

)
with urllib.request.urlopen(url, timeout=60) as resp:
    rows = [item["row"] for item in json.load(resp)["rows"]]

Report generated by Automated Security Helper (ASH) at 2026-11-12T19:47:43+00:00

@sromoam
sromoam merged commit a8e019d into awslabs:dev Nov 12, 2026
10 checks passed
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.

Merge the identical dispatcher branches for dict and plain-model pairs, and share FieldComparator's TP/FD classification

4 participants