Skip to content

audit: remove dead private helpers and unused imports (nightly) - #490

Merged
haiyuan-eng-google merged 2 commits into
GoogleCloudPlatform:mainfrom
caohy1988:audit/dead-unused-cleanup-20260921
Sep 21, 2026
Merged

haiyuan-eng-google merged 2 commits into
GoogleCloudPlatform:mainfrom
caohy1988:audit/dead-unused-cleanup-20260921

Conversation

@caohy1988

@caohy1988 caohy1988 commented Sep 21, 2026 •

Copy link
Copy Markdown
Collaborator

Nightly audit, one theme: delete code in src/bigquery_agent_analytics that nothing references. No behavior change, no public API change. 7 source files, 59 lines deleted, 0 added.

Baseline: 614826bb3515a1d4226ad7b456aa2273f93c3f5c (main, v0.5.3)

What was dead

File Removed
ontology_schema_compiler.py _compile_entity_schema, _compile_relationship_schema, and the ResolvedEntity / ResolvedRelationship imports only they used
ontology_runtime.py _first_string_value
_streaming_evaluation.py, system_evaluator.py from bigquery_agent_analytics import udf_kernels
client.py from .categorical_evaluator import CATEGORICAL_AI_GENERATE_QUERY
insights.py from dataclasses import field as dc_field
trace.py import functools

How it was proven unused

  1. uvx vulture src --min-confidence 60 produced the candidate list.
  2. Each candidate was checked with a repo-wide grep -rnI <symbol> . --exclude-dir=.git (src, tests, examples, scripts, docs, plugins):
    • _compile_entity_schema, _compile_relationship_schema, _first_string_value: the only hit is the def line. compile_output_schema builds the schemas inline; the runtime uses _all_string_values.
    • udf_kernels: no udf_kernels. use in either module (one comment mention in system_evaluator.py), and grep -rnE "(system_evaluator|_streaming_evaluation)\.udf_kernels" finds no test patching it through those modules.
    • CATEGORICAL_AI_GENERATE_QUERY: never read in client.py; tests import it from categorical_evaluator.
    • dc_field: no use. functools: only a docstring mentions functools.wraps.
  3. After the change, vulture src --min-confidence 80 reports only the three items deliberately kept (below).

Deliberately kept

  • performance_evaluator.py import of _extract_json_from_text: a re-export asserted by tests/test_pr123_performance_regressions.py.
  • Typer callbacks / entry points (_bqaa_callback, _export_callback, _root, _materialize_window_entry), evaluators.__getattr__, and the pydantic validator _validate_column_entries: framework hooks, vulture false positives.
  • PerformanceEvaluator._llm_judge_evaluate: has no caller, but it is evaluator behavior rather than a leaf helper, so it is left for a separate reviewed change.
  • Unused parameters app_name and memo: required by interface signatures.

Repo hygiene (second commit, ce13d9b)

  • Removed all checked-in intent.md / plan.md / spec.md working notes: the docs/audit/2026-09-21-dead-unused/ set added earlier in this PR, plus six that were already on main (intent/pr486-not-found-names/, examples/okf_bqaa_adapter/). Nothing references them; tests/examples/test_okf_bqaa_adapter.py and test_okf_attested_computation.py still pass (137 passed).
  • .gitignore: ignore those three basenames at any depth.
  • ci.yml Format check: new first step fails if any file with one of those basenames exists in the checkout. Verified locally: passes on this tree, fails when a spec.md is planted.

Tests

Same commands as .github/workflows/ci.yml, Python 3.12, fresh venv:

pip install -e ".[dev,streamlit]"
pytest --tb=short -q
# 5334 passed, 66 skipped, 21 warnings in 222.27s

isort --check <7 touched files>   # clean
pyink --check <7 touched files>   # 7 files would be left unchanged

The 66 skips are pre-existing live/optional-dependency tests. After the full run, the only further edit was removing one stray blank line that isort flagged in system_evaluator.py; tests/test_system_evaluator.py, test_ontology_schema_compiler.py and test_ontology_runtime.py were re-run afterwards (175 passed).

🤖 Generated with Claude Code

Delete three unreferenced private helpers (_compile_entity_schema,
_compile_relationship_schema, _first_string_value) and seven unused
imports flagged by vulture and confirmed with a repo-wide grep.
No behavior or public API change.

Baseline: 614826b
Tests: pytest --tb=short -q -> 5334 passed, 66 skipped

@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.

APPROVE — Astra (Codex), blind review.

Reviewed head 0c70bd8fa8e0ec44ba7b2b617379e32db220e0d3 against baseline 614826bb3515a1d4226ad7b456aa2273f93c3f5c, using GitHub diff and repository files only. No other reviews, peer comments, or vault notes were read.

No actionable findings; no P0/P1 blockers.

  • Baseline reference searches find only the definitions of _compile_entity_schema, _compile_relationship_schema, and _first_string_value. The active compiler builds schemas inline, and runtime annotation accessors retain _all_string_values.
  • AST/reference checks confirm the deleted imports have no executable uses beyond annotations on the deleted helpers. No consumers of the removed module bindings, wildcard imports from the affected modules, or matching patch targets were found. The categorical constant and resolved types remain available from their defining modules; package exports remain intact.
  • udf_kernels contains functions and constant data, with no registration side effects requiring the removed imports. The protected _extract_json_from_text re-export remains intact.
  • Existing tests cover schema compilation, runtime annotations, evaluator behavior, and streaming imports. Tests and CI configuration are unchanged; CI uses the documented dev/streamlit install and full pytest command.

Validation limit: this was a GitHub-file review, with no local checkout or test execution. The documented 5,334 passed / 66 skipped result is author-reported, not independently rerun or verified here.

Submitted as COMMENT because the authenticated account owns this PR. The review verdict is APPROVE. This review does not authorize a 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.

APPROVE (posted as COMMENTED — self-review cannot APPROVE) — blind diff/files review at tip 0c70bd8.

Correctness: all 7 src deletions are import-only or underscore-private helpers with no in-file code use at tip (verified: no ResolvedEntity/ResolvedRelationship/compile* refs left in ontology_schema_compiler.py; no _first_string_value in ontology_runtime.py with _all_string_values callers intact; only a docstring mentions functools in trace.py; only comment mentions of udf_kernels remain in system_evaluator.py and none in _streaming_evaluation.py; zero CATEGORICAL_AI_GENERATE_QUERY refs in client.py; zero dc_field refs in insights.py). Diff is purely deletions, so no behavior change.

API: removed helpers are underscore-private. Removed aliases (client.CATEGORICAL_AI_GENERATE_QUERY, system_evaluator/_streaming_evaluation.udf_kernels) are not in package init exports at tip; canonical paths (categorical_evaluator, bigquery_agent_analytics.udf_kernels) are untouched. No public API break.

Coverage/security: no new code paths, inputs, or secrets; deletions only. Residual risk is limited to dynamic/string references or external deep-imports of the removed aliases, which the spec's repo-wide grep scope addresses; nothing in the diff contradicts it. No P0/P1 findings. No nits.

Remove the docs/audit SDLC notes added earlier in this PR, plus the six
pre-existing intent.md / plan.md / spec.md files on main
(intent/pr486-not-found-names, examples/okf_bqaa_adapter) so the new
check can pass. Nothing references them.

- .gitignore: ignore intent.md, plan.md, spec.md at any depth.
- ci.yml Format check: fail if any such file exists in the checkout.

Source dead-code / unused-import deletions are unchanged.
@caohy1988

Copy link
Copy Markdown
Collaborator Author

APPROVE (posted as COMMENTED — own-account cannot APPROVE via API; verdict is APPROVE, no REQUEST_CHANGES; no P0/P1).

Blind GitHub-only review of tip ce13d9b against baseline 614826b. Diff/files read via GitHub raw + API only; no peer reviews read. I am Muse; Fable is OFF review for this PR.

Correctness of dead-code removal (verified in-file @baseline vs @tip):

  • ontology_schema_compiler.py: _compile_entity_schema/_compile_relationship_schema def-only at baseline (lines 95/108), zero in-file callers; compile_output_schema builds node_props/edge schemas inline at tip. Removed ResolvedEntity/ResolvedRelationship imports; ResolvedGraph + Optional still used at tip. Clean.
  • ontology_runtime.py: _first_string_value def-only at baseline (line 1162); _all_string_values retained with live caller (notation_for, tip line ~1084). Optional[] still used heavily. Clean.
  • trace.py: functools import removed; only remaining mention is docstring line 2027 (functools.wraps). No code use. Correct.
  • insights.py: dc_field import removed; zero uses at baseline. Clean.
  • client.py: CATEGORICAL_AI_GENERATE_QUERY import-only at baseline (line 75); neighbors (build_ai_generate_query etc.) retained at tip. Clean.
  • _streaming_evaluation.py / system_evaluator.py: udf_kernels imports removed; remaining hits at tip are comment-only (system_evaluator.py lines ~311/315). Clean.
  • No init/all/public-symbol changes in diff; deletions are underscore-private or plain imports. Accidental API-break risk low. Limitation: repo-wide grep/re-export check (tests patching .udf_kernels, module. reads) not independently re-runnable from blind GitHub fetch; in-file evidence + private naming + comment-only residuals support the spec table.

Amend (Haiyuan ask) — satisfied:

  • Tip tree (1138 blobs via git/trees API) contains zero basenames intent.md/plan.md/spec.md. The 6 deleted note files (examples/okf_bqaa_adapter/{intent,plan,spec}.md, intent/pr486-not-found-names/{intent,plan,spec}.md) match the request to drop committed SDLC notes; src deletions kept (7 files, all import/helper removals intact).
  • .gitignore appends bare basenames intent.md/plan.md/spec.md (matches at any depth per gitignore semantics) with comment pointing at CI enforcement. Implements request exactly.
  • Format-check lint runs pre-install (before setup-python/pip), hermetic (find + sh only, no network/secrets), least-privilege job (contents: read). find . -path ./.git -prune covers the checkout .git. Ordering avoids venv/node_modules noise.

Security: deletions only; no new exec/network/creds. CI step echoes found paths + ::error, no secret handling.

Non-blocking nit (not P0/P1, capped): examples/okf_bqaa_adapter/README.md:95 at tip still says "See intent.md, spec.md, plan.md" — dangling pointer to the just-deleted notes. Suggest rewording to drop the sentence or point outside the repo. Leave to follow-up.

Not re-run here (blind review scope): relying on CI for isort/pyink + full pytest gate per spec/plan. Dual LGTM is not 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.

APPROVE — Astra (Codex), independent blind review of ce13d9b45f246fe8191fda96652198b6e8498254 against 614826bb3515a1d4226ad7b456aa2273f93c3f5c, including the amendment since 0c70bd8.

No P0/P1 findings. The dead-code removals are safe on the repository evidence reviewed: the three private helpers have only their definitions at baseline, the removed bindings have no remaining uses or import consumers, and AST comparison confirms all surviving implementation is unchanged across the seven source files. I found no public API-contract or security regression. The existing performance-evaluator re-export remains intact.

The amendment preserves all 59 source-line deletions, removes all nine intent/plan/spec documents present at the prior tip, and leaves no prohibited basename in the current GitHub tree. The basename ignore rules work at root and nested paths. The dependency-free lint runs immediately after checkout in Format check. One non-blocking P3 edge case is recorded inline: symlinks bypass its regular-file filter.

Validation: GitHub Format check, all Python 3.10–3.14 test jobs, and Build package passed. The Python 3.12 CI log reports 5,220 passed, 80 skipped. I independently exercised the exact GitHub lint command with isolated empty/root/nested/.git fixtures and checked the ignore patterns with Git; the regular-file cases behaved correctly. The full SDK suite was not rerun locally.

Review evidence came from GitHub diff/files, GitHub-sourced snapshots held in memory, and CI results. No other reviews, peer comments, vault notes, or local checkout contents were read. This is a review decision only; no merge.

Comment thread .github/workflows/ci.yml

- name: Reject SDLC working notes (intent.md / plan.md / spec.md)
run: |
found="$(find . -path ./.git -prune -o -type f \( -name intent.md -o -name plan.md -o -name spec.md \) -print)"

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.

[P3, non-blocking] Include tracked symlinks in the basename guard

find ... -type f skips symlinks, so a tracked spec.md -> notes.txt passes this step even though the prohibited basename exists in the Git tree. I reproduced this with a Git index containing mode 120000 for spec.md; the exact lint command exited 0. A force-added symlink also bypasses the new ignore rules.

For complete basename enforcement, inspect tracked paths (for example, git ls-files -z) or include symlinks in the find predicate. No prohibited entries exist at this tip; this is a low-priority gap in future enforcement.

@haiyuan-eng-google
haiyuan-eng-google merged commit e30415b into GoogleCloudPlatform:main Sep 21, 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