Skip to content

audit: drop dead utils imports from system_evaluator (nightly) - #496

Merged
haiyuan-eng-google merged 1 commit into
GoogleCloudPlatform:mainfrom
caohy1988:audit/deadcode-20260926
Sep 28, 2026
Merged

haiyuan-eng-google merged 1 commit into
GoogleCloudPlatform:mainfrom
caohy1988:audit/deadcode-20260926

Conversation

@caohy1988

Copy link
Copy Markdown
Collaborator

What was removed

Two unreferenced imports from src/bigquery_agent_analytics/system_evaluator.py (pure 3-line deletion, no logic touched):

  • from .utils import _parse_json_from_text (was line 40)
  • from .utils import strip_markdown_fences (was line 41)

Follow-up to #490, which removed the udf_kernels import from this same file but missed these two.

rg evidence per symbol

Both flagged by ruff check --select F401; confirmed dead repo-wide:

  • grep -n "_parse_json_from_text\|strip_markdown_fences" src/bigquery_agent_analytics/system_evaluator.py → only the two import lines (count = 2, no other use in the file).
  • No __all__ in system_evaluator.py; no system_evaluator import * anywhere.
  • No sys.modules alias for system_evaluator (only performance_evaluator has one, via trace_evaluator.py).
  • No dotted-path refs (system_evaluator._parse_json_from_text / system_evaluator.strip_markdown_fences) in any .py/.md/.ipynb/.rst/.txt.
  • No mock.patch/getattr targets on these paths in tests/ or src/; no test asserts their presence on the system_evaluator namespace (the legacy-compat test only pins SessionScore/EvaluationReport/SESSION_SUMMARY_QUERY identity).
  • strip_markdown_fences is not mentioned in SDK.md/docs//README.md; no pyproject entry point touches these symbols.
  • Canonical homes preserved: utils.strip_markdown_fences, utils._parse_json_from_text, plus the evaluators.py compat re-export (strip_markdown_fences in evaluators.__all__).

Explicitly NOT removed: the identical-looking bindings in performance_evaluator.py are load-bearing — trace_evaluator.py does sys.modules[__name__] = performance_evaluator and test_trace_shim_preserves_public_and_private_exports asserts getattr identity for _extract_json_from_text, _parse_json_from_text, and strip_markdown_fences on that namespace.

Also scanned and rejected (not dead): vulture 100%-confidence hits memory_service.py:1034 app_name (ADK BaseMemoryService.search_memory override signature) and trace.py:1057 memo (__deepcopy__ protocol signature).

Tests run

  • Focused (before and after): pytest tests/test_system_evaluator.py tests/test_evaluators.py tests/test_pr123_legacy_regressions.py tests/test_pr123_performance_regressions.py → 144 passed both times.
  • Full suite after: 5342 passed, 65 skipped. The 6 failures + 5 collection errors (grafana pidfile, real-browser configurator, pr16 memory-service, opentelemetry/streamlit/plotly imports) reproduce identically on the unmodified baseline via git stash — pre-existing environment issues, zero regressions from this change.
  • ruff check --select F401 on the touched file: clean. isort --check-only and pyink --check (25.12, < 26 per CI): clean.

No behavior or public API change. Ready for review (Astra + Fable).

Remove two unreferenced imports (_parse_json_from_text,
strip_markdown_fences) flagged by ruff F401 and confirmed with a
repo-wide grep: the only occurrences in system_evaluator.py are the
import lines; no __all__, star-import, sys.modules alias, dotted-path,
docs, notebook, entry-point, or mock.patch reference remains.

The identical-looking bindings in performance_evaluator.py are
intentionally kept: trace_evaluator.py aliases that module and
test_trace_shim_preserves_public_and_private_exports pins the
namespace. Canonical homes (utils.*) and the evaluators.py compat
re-export are untouched. No behavior or public API change.

Baseline: a51c39a
Tests: focused 144 passed; full suite 5342 passed, 65 skipped
(6 failed + 5 collection errors are pre-existing env issues,
identical on baseline).

@caohy1988 caohy1988 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Verdict: APPROVE

Independent blind review by Astra (Codex), on caohy1988's behalf. Reviewed tip 2e2d0eeadc351470d920639f266b43aad2d5dc00 against base a51c39a2dfaa6d863a0e16597f7b1b191b86effb. This is a COMMENT review.

Findings

  • P0: None.
  • P1: None.
  • P2: None. No fixes requested.

Evidence

  • The only change deletes the two imports at src/bigquery_agent_analytics/system_evaluator.py:40–41 (base), plus a blank line. An AST comparison confirms everything else is identical. GitHub's file contents match the local file byte-for-byte.
  • Independent repository-wide rg searches found neither helper used through system_evaluator: no direct import, dotted reference, wildcard import, patch target, getattr dependency, documentation reference, or entry point. This module has no __all__, dynamic export hook, or sys.modules alias. In the base file, each helper appears only on its removed import line.
  • Canonical definitions remain at utils.py:22 and :42. Compatibility imports and the public strip_markdown_fences export remain at evaluators.py:27–47. The performance/trace namespace compatibility is preserved, including the identities asserted at tests/test_pr123_performance_regressions.py:350–374.
  • The one-file cleanup is appropriately scoped. No obvious additional dead code in the touched module needs inclusion. No behavior regression or supported API break found.

Validation

Local Python 3.13.5:

PYTHONDONTWRITEBYTECODE=1 python3 -m pytest -p no:cacheprovider \
  tests/test_system_evaluator.py tests/test_evaluators.py \
  tests/test_pr123_legacy_regressions.py \
  tests/test_pr123_performance_regressions.py --tb=short -q
144 passed, 2 deprecation warnings in 3.95s

These tests directly exercise the touched module: tests/test_system_evaluator.py:31–51. Legacy shared-symbol identities and wildcard exports are checked at tests/test_pr123_legacy_regressions.py:72–80.

Touched-file checks passed: pyink --check (25.12.0, <26), isort --check-only (8.0.0), and ruff check --no-cache (0.11.2). git diff --check passed; worktree remains clean. The full suite was not rerun locally.

CI is green: Python 3.10–3.14, format, browser smoke, and package build passed. CLA, change detection, and scan-pr passed; four conditional zizmor jobs were skipped. No pending or failed checks at final verification.

Blindness: no vault files, shared peer artifacts, or existing PR #496 reviews/comments were read. Sources were the allowed PR descriptions/diffs/files, CI status, and this worktree. The allowed #490 diff included historical #486 review references; no PR #496 peer-review material was encountered. No branch modifications, push, or merge.

@caohy1988 caohy1988 left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Verdict: APPROVE

Blind review (Fable / Claude, on caohy1988's behalf) of tip 2e2d0ee vs base a51c39a, done in a fresh worktree without reading other reviews. I re-verified every dead-ness claim myself with rg; the 3-line deletion is correct, scoped, and behavior-neutral. Nothing blocking. Posted as COMMENT per the dual-review protocol.

P0 — none

P1 — none

P2 — non-blocking, all outside the diff

  1. src/bigquery_agent_analytics/performance_evaluator.py:59 and :61 are shim-only imports with no in-code marker. _extract_json_from_text (:59) and strip_markdown_fences (:61) have zero body uses (only _parse_json_from_text at :60 is actually called, at :1024/:1125/:1174), so ruff check --select F401 still flags both, and ruff --fix would delete exactly those two lines and break tests/test_pr123_performance_regressions.py:350 (test_trace_shim_preserves_public_and_private_exports, names pinned at :369-371 through the trace_evaluator.py:25 sys.modules alias). This PR's description records why they are kept, but the next nightly will only see the linter output. Suggested fix (2 lines; fine to ride in this PR or the next one), mirroring the existing convention at src/bigquery_agent_analytics/runtime_spec.py:59:

    from bigquery_agent_analytics.utils import _extract_json_from_text  # noqa: F401 – re-exported via trace_evaluator shim; pinned by test_trace_shim_preserves_public_and_private_exports
    from bigquery_agent_analytics.utils import strip_markdown_fences  # noqa: F401 – same

    Nit: the commit message's "identical-looking bindings in performance_evaluator.py are intentionally kept" slightly over-states; :60 is a real use, only :59/:61 are shim-only.

  2. Same-class leftovers the same tool finds (candidates for the next nightly, not this PR). ruff check --select F401 src/bigquery_agent_analytics/ at HEAD, ignoring __init__.py re-export blocks and try/except availability probes, still lists ~21 auto-fixable hits, e.g. feedback.py:34-36 (dataclass, field, json), feedback.py:691 (google.cloud.bigquery), insights.py:40/42/45 (asyncio, dataclass, json), eval_validator.py:36 (field), ai_ml_integration.py:62 (timedelta), cli.py:197 (ResolvedGraph), ontology_materializer.py:79 (ResolvedProperty), extractor_compilation/diagnostics.py:75 and ontology_models.py:42 (Any), extractor_compilation/measurement.py:52 (CompileResult). Each needs the same namespace check this PR did. Two I checked are load-bearing and must not be auto-fixed: ontology_models.py:169-172 (Extracted* re-exports consumed by tests/test_extracted_models.py:22-25) and performance_evaluator.py:59/61 (item 1). client.py:86 (_AI_GENERATE_JUDGE_BATCH_QUERY_TEMPLATE as AI_GENERATE_JUDGE_BATCH_QUERY) is undecided: there is no in-repo consumer of client.AI_GENERATE_JUDGE_BATCH_QUERY (tests import it from evaluators, tests/test_system_evaluator.py:24), but it is an un-underscored name on the client namespace, so triage it as a possible compat alias rather than a mechanical delete.

  3. No CI gate for unused imports. .github/workflows/ci.yml:53-59 (Format check) installs only pyink + isort and runs autoformat.sh + git diff --exit-code; no workflow runs ruff/pyflakes/vulture, which is how #490 missed these two lines in the very block it edited. Once item 2 is cleaned, consider adding ruff check --select F401 src/ to the Format job with [tool.ruff.lint.per-file-ignores] "__init__.py" = ["F401"] in pyproject.toml, so this is the last manual sweep. Separate PR is fine.

  4. Docs, pre-existing drift, FYI only. SDK.md:2672 lists system_evaluator.py under "Standalone modules (no internal imports)"; this PR makes that true again (baseline had the two .utils imports). SDK.md:2685 "insights.py → system_evaluator" is stale independent of this PR (insights.py:52 imports from .evaluators).

What I verified

  • Dead-ness (rg, all file types, whole repo): no system_evaluator._parse_json_from_text / .strip_markdown_fences; no from …system_evaluator import of either name; no __all__ in the file; no import * of the module; no sys.modules alias for system_evaluator (only trace_evaluator.py:25 → performance_evaluator); no mock.patch / getattr targets; nothing in docs/, SDK.md, README.md, examples/, scripts/, plugins/, notebooks, or [project.scripts]. docs/design.md:1429 defines the helper generically without attributing it to this module. Module importers pull only CodeEvaluator / EvaluationReport / SessionScore / SystemEvaluator / SESSION_SUMMARY_QUERY (client.py:117-120, aggregate_grader.py:53, evaluators.py:27-31, __init__.py:109-112; tests/test_pr123_legacy_regressions.py:74-78 getattr's only the three report/SQL names; test_evaluators.py:26, test_system_evaluator.py:31-32, test_sdk_client.py:1048, test_pr123_client_regressions.py:32).
  • In-file: no json / re / fence / parse code anywhere in system_evaluator.py (every hit is docstring prose); every remaining import is used; ruff check --select F clean at HEAD; baseline a51c39a trips exactly the two F401s at old lines 40-41. git log -S shows both imports arrived in f5e03bd (#123) with no call site ever, so they were dead since birth; #490's hunk removed udf_kernels from the same block and left them.
  • Canonical homes / compat intact: utils.py:22 and :42 definitions; evaluators.py:32-33 re-export from .utils with strip_markdown_fences in __all__ (:47), asserted by test_pr123_legacy_regressions.py:80; performance_evaluator.py:59-61 untouched. Public surface of bigquery_agent_analytics and evaluators is unchanged; the only observable delta is hasattr(system_evaluator, <name>) flipping to False for two never-documented helpers with zero consumers.
  • Tests (local, this worktree, HEAD, Python 3.13.5): pytest tests/test_system_evaluator.py tests/test_evaluators.py tests/test_pr123_legacy_regressions.py tests/test_pr123_performance_regressions.py tests/test_pr123_client_regressions.py tests/test_categorical_evaluator.py → 331 passed, 0 failed. Env note only: the shared .venv has a stale bigquery_agent_analytics-0.2.3.dist-info with no METADATA (makes _telemetry._read_version() raise TypeError) and lacks pytest_asyncio (54 async collection failures); both are pre-existing and identical on baseline, worked around with a /tmp dist-info shim + /tmp plugin target, no repo files touched.
  • Format / lint: ruff check --select F401 clean; isort --check-only (google profile) clean; pyink --check clean on both 24.8.0 (pyink<26, as CI pins) and 25.12.0.
  • CI: run 36235576070 — Format check, Test (3.10 / 3.11 / 3.12 / 3.13 / 3.14), Build package, Configurator browser smoke, scan-pr, cla/google all pass; zizmor jobs skipped by path filter.
  • Scope: one file, 3 deletions, no unrelated changes; no CHANGELOG entry needed, matching the #490 precedent for no-behavior-change audit PRs.
@haiyuan-eng-google
haiyuan-eng-google merged commit a2a1d90 into GoogleCloudPlatform:main Sep 28, 2026
15 checks passed
caohy1988 added a commit that referenced this pull request Sep 29, 2026
List every incidental name #490/#496 removed and where each lives
now, fix the permission repair to `chmod go-w`, scope the log-dir
symlink rule to logs outside the state directory, and qualify the
tracing checks' platform fallbacks.
haiyuan-eng-google pushed a commit that referenced this pull request Sep 29, 2026
…st (#501)

* chore(release): 0.5.4 — compaction_windows view, smoke-test unpickling allowlist

Bump the version to 0.5.4 and cut the CHANGELOG for the ten PRs merged
since v0.5.3 (#490–#497, #499, #500). [Unreleased] is left empty; the
#494 entry moves into [0.5.4].

* docs(changelog): tighten 0.5.4 compatibility notes

List every incidental name #490/#496 removed and where each lives
now, fix the permission repair to `chmod go-w`, scope the log-dir
symlink rule to logs outside the state directory, and qualify the
tracing checks' platform fallbacks.

* chore(release): date 0.5.4 for 2026-09-29
haiyuan-eng-google pushed a commit that referenced this pull request Oct 1, 2026
Import-line deletions only; no logic, signature or public API change.
Every removed name is flagged by `ruff check --select F401` and has no
reference anywhere in the tracked tree: no from-import, attribute
access, mock.patch / monkeypatch / getattr target, or mention in docs,
notebooks, deploy/ or producers/. None of the touched modules defines
__all__, is star-imported, or is aliased through sys.modules.

Removed:
- ai_ml_integration.py: datetime.timedelta
- cli.py: function-local resolved_spec.ResolvedGraph in
  _load_spec_from_args
- eval_validator.py: dataclasses.field
- extractor_compilation/diagnostics.py: typing.Any
- extractor_compilation/measurement.py: .compiler.CompileResult (the
  package __init__ still imports .compiler first)
- feedback.py: dataclasses.dataclass, dataclasses.field, json, and a
  function-local google.cloud.bigquery import
- insights.py: asyncio, dataclasses.dataclass, json
- ontology_materializer.py: resolved_spec.ResolvedProperty
- ontology_models.py: typing.Any
- ttl_importer.py: rdflib.XSD (the remaining rdflib imports still gate
  _RDFLIB_AVAILABLE)
- bigquery_ontology/graph_ddl_compiler.py: binding_models.PropertyBinding

Kept on purpose although ruff flags them:
- performance_evaluator.py utils imports: re-exported through the
  trace_evaluator shim and asserted by
  test_trace_shim_preserves_public_and_private_exports
- ontology_models.py extracted_models imports: re-exports
- client.py AI_GENERATE_JUDGE_BATCH_QUERY: compat alias from #123,
  named in docs/design.md
- package __init__ re-exports

Follow-up to #490 and #496. vulture did not report these because it
counts a name as used when any other module uses it; ruff F401 checks
each file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants