Skip to content

Conversation

@jucor
Copy link
Collaborator

@jucor jucor commented Jan 7, 2026

Here's some clean up of dead code: using Claude Code Opus 4.5 to clean up behind Claude Code Sonnet 3.7 from last year ;-)
There are probably still code paths that are unused, and I have not removed the markdown files created during the python port last year -- they'll still serve until we're fully sure of the codebase, I think.

Summary

Systematic cleanup of dead/unused code from the delphi/ folder (ported from Clojure ~1 year ago). Removed 730 net lines of dead code across 6 commits, with all tests passing.

Key Changes

Removed (1,162 lines)

  • Legacy poller/system architecture:
    • polismath/__main__.py (150 lines) - Legacy entry point
    • polismath/system.py (208 lines) - Legacy system manager
    • polismath/poller.py (507 lines) - PostgreSQL continuous polling
    • polismath/components/server.py (297 lines) - Legacy FastAPI server

Removed (6 unused imports)

  • squareform from pca_kmeans_rep/corr.py
  • weighted_mean, weighted_means from pca_kmeans_rep/clusters.py
  • JSON, QueuePool from database/postgres.py and scripts/job_poller.py

Documentation

  • Updated RUNNING_THE_SYSTEM.md (removed SystemManager references)
  • All markdown files kept in docs/ (not archived)
  • Added comprehensive cleanup report

⚠️ False Positive (Corrected)

Initially deleted polismath/utils/general.py (263 lines) due to faulty grep verification, but this file had 4 active imports in production code. It has been restored and tests now pass.

Root cause: Grep was likely run from wrong directory. Network issues prevented running tests before initial commit.

Verification

Tests Pass ✅

211 passed, 7 skipped, 2 xfailed

Legacy System Gone

grep -r "from polismath.system\|from polismath.poller" --include="*.py" .
# No matches (except in archived docs and cleanup report)

Entry Points Preserved

Current Delphi entry point (run_delphi:main) and all other entry points remain functional:

  • run-delphi (Docker/Makefile main entry point)
  • run-math-pipeline
  • run-umap-pipeline
  • calculate-extremity
  • calculate-priorities
  • reset-conversation
  • create-datamapplot

Note: The delphi CLI script is old and not fully working; Docker uses run_delphi.

Impact

12 files changed, 497 insertions(+), 1201 deletions(-)
Net: -704 lines

Future Work

Vulture analysis identified 92 additional items (mostly 60% confidence) for future cleanup:

  • 12 high-confidence (90%+) unused imports (~12 lines, low risk)
  • Various potentially unused classes/functions requiring domain expert review

Documentation

Full details in delphi/docs/DEAD_CODE_CLEANUP_REPORT.md including:

  • Methodology (Vulture static analysis + grep verification)
  • Complete commit timeline
  • Lessons learned and process improvements
  • Reproducibility instructions

Commits: cebd9d2b6 through 645894d38
Base: edge
Tests: ✅ All passing

jucor and others added 6 commits January 5, 2026 19:23
Remove dead code that was replaced by scripts/job_poller.py + DynamoDB job queue:
- polismath/__main__.py (legacy entry point)
- polismath/system.py (legacy System/SystemManager)
- polismath/poller.py (legacy Poller/PollerManager)
- polismath/components/server.py (legacy Server/ServerManager)

Updated __init__.py files to remove imports of deleted modules.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
  - Remove polismath/utils/general.py (unused utility functions - 263 lines)
  - Remove unused squareform import from corr.py
  - Archive outdated docs to docs/archive/:
    - conversion_plan.md (conversion complete)
    - NEXT_STEPS.md (outdated)
    - project_structure.md (proposed, not actual)
- Update RUNNING_THE_SYSTEM.md: remove SystemManager references, add current CLI usage
- Archive architecture_overview.md (describes Clojure, not Python)
- Archive summary.md (references deleted poller/server/system components)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Detailed documentation of the dead code identification and removal process,
including actual vulture output (98 findings) and recommendations for future cleanup.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit corrects a critical false positive from the dead code cleanup:

1. RESTORED: polismath/utils/general.py (263 lines)
   - Was incorrectly marked as dead code
   - Actually has 4 active imports in production code:
     * postgres.py: postgres_vote_to_delphi()
     * run_math_pipeline.py: postgres_vote_to_delphi()
     * repness.py: AGREE, DISAGREE constants
     * clusters.py: (import existed but unused - see below)

2. REMOVED: Unused imports (5 total)
   - clusters.py: weighted_mean, weighted_means
   - postgres.py: JSON, QueuePool
   - job_poller.py: JSON, QueuePool

3. ADDED: docs/DEAD_CODE_CLEANUP_REPORT_CORRECTED.md
   - Documents the false positive
   - Provides root cause analysis
   - Recommends process improvements

Tests verified: 211 passed, 7 skipped, 2 xfailed

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Merge DEAD_CODE_CLEANUP_REPORT.md and DEAD_CODE_CLEANUP_REPORT_CORRECTED.md
into a single comprehensive report documenting the entire cleanup series.

Changes:
- Combined both reports into unified DEAD_CODE_CLEANUP_REPORT.md
- Documents false positive (general.py) and correction
- Clarifies entry point is run_delphi (not delphi CLI)
- Shows net impact: -730 lines from edge branch
- All documentation files kept in docs/ (not archived)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
jucor and others added 2 commits January 7, 2026 15:20
Add complete output from Vulture dead code analyzer (147 findings):
- 90%+ confidence: ~15 unused imports
- 60%+ confidence: ~132 potentially unused functions/classes/methods

This provides the raw data referenced in DEAD_CODE_CLEANUP_REPORT.md
for future dead code cleanup efforts.

Command used:
vulture . --min-confidence 60 --exclude ".git,__pycache__,*.pyc,.venv,tests"

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Remove all 90%+ confidence unused imports identified by Vulture:

Files modified (10):
- polismath/benchmarks/bench_repness.py (3 imports)
- polismath/components/config.py (Set)
- polismath/conversation/conversation.py (Set)
- polismath/conversation/manager.py (Set)
- polismath/database/postgres.py (Set)
- polismath/utils/general.py (itertools, Set)
- scripts/delphi_cli.py (Text, rprint)
- umap_narrative/801_narrative_report_batch.py (csv, io)
- umap_narrative/polismath_commentgraph/core/clustering.py (hdbscan, delayed, Parallel)
- umap_narrative/polismath_commentgraph/utils/storage.py (QueuePool)

All imports verified as unused by:
1. Vulture static analysis (90% confidence)
2. Manual grep verification
3. Test suite (45 tests passed)

This addresses the high-priority cleanup items from vulture_analysis_output.txt.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@jucor jucor marked this pull request as ready for review January 7, 2026 19:30
@jucor jucor requested a review from ballPointPenguin January 8, 2026 17:34
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.

1 participant