Skip to content

refactor: remove dead code and simplify duplicates - #224

Merged
QueryPlanner merged 3 commits into
mainfrom
claude/codebase-cleanup-refactor-d6de22
Nov 29, 2026
Merged

QueryPlanner merged 3 commits into
mainfrom
claude/codebase-cleanup-refactor-d6de22

Conversation

@QueryPlanner

Copy link
Copy Markdown
Owner

What

Removes production-dead code and simplifies duplicated code across the
codebase, with no feature removed and no intended behavior change. Net
change: 50 files, +1,591 / −3,355 lines (about −1,760).

The PR has two commits so each kind of change can be reviewed on its own:

  1. refactor: remove production-dead code (−1,004 lines, mostly tests)
  2. refactor: simplify code without behavior change (−760 lines)

Why

A scan found no unreachable modules: every file under src/ is imported
from blacki.server or blacki.agent. The dead weight was in functions
only tests called, and in copy-pasted blocks that had drifted into many
files. Removing both makes the code smaller and easier to change.

How

  • Deleted functions with no production caller, and their tests:
    • AdkRuntime.run_user_turn_streaming and StreamChunk
    • TelegramApiClient.get_me, send_message_draft, get_my_commands
    • escape_markdown, create_telegram_bot
    • SqlStorage._execute_many, _fetch_val, close_connection
    • SqliteWorkoutStorage.update_exercise, delete_exercise
    • GoogleHealthService.summary_for_tool, inference_profile_from_mapping
    • the Exa and Brave *_api_key_available helpers, ModelCapabilitiesResolver
  • Kept test-support helpers and framework hooks that look unused but are
    called by name (ADK callbacks, FastAPI routes, dashboard getattr
    dispatch, test reset helpers, miniapp store wrappers).
  • Simplified each area by merging duplicated helpers, for example:
    • Telegram: background-task spawning, session locators, the
      describe_tool if-chain replaced by lookup tables (checked identical
      over 12,516 name/argument combinations)
    • Dashboard and mini app: read-only SQLite setup, latency and cost
      summaries, the compiler's 55 err + raise pairs replaced by bail()
    • Health, calories, workouts: transaction and JSON-decode helpers,
      Health API error handling, meal-export identity checks
    • Gmail, models, runtime, server, declarative DB, browser takeover: a
      shared lazy HTTP client, a shared WHERE builder, confirmation parsing
  • Left unchanged on purpose: log message text (runbooks search for it),
    tool names, parameters, and docstrings (ADK builds tool schemas from
    them), prompts, skills, SQL schemas and queries, env var names, HTTP
    routes and response shapes, and Telegram user-facing text.
  • No new noqa, type: ignore, or pragma: no cover. Existing ones that
    moved with merged code went from 11 to 6.

Tests

  • uv run ruff format (no changes)
  • uv run ruff check
  • uv run mypy .
  • uv run pytest --cov=src: 2,822 passed, 1 skipped, 100.00% coverage
  • Test edits: deleted tests of removed code; deduplicated mini app
    route and compiler test setup. No surviving assertion changed.
  • Untested browser JavaScript reads dashboard and mini app JSON. The
    response shapes are meant to be unchanged, but a quick manual look
    at the dashboard and mini app after deploy is worth doing.

🤖 Generated with Claude Code

QueryPlanner and others added 2 commits November 29, 2026 16:41
- Drop the unused ADK streaming turn and its StreamChunk type
- Drop unused Telegram API methods and escape_markdown
- Drop unused storage, workout, health, and search helpers
- Delete the tests that only exercised the removed code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- Merge duplicated helpers in telegram, dashboard, and miniapp
- Share transaction, decode, and error helpers in health storage
- Share HTTP client and validation helpers in Gmail and OAuth
- Replace the describe_tool if-chain with lookup tables
- Deduplicate miniapp route and compiler test setup
- Keep log text, tool schemas, routes, and SQL unchanged

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copy link
Copy Markdown
Owner Author

I found two dashboard regressions in this refactor.

  • [P2] Preserve the fallback for unparseable session versions. Python can raise ValueError when a stored version suffix exceeds its integer conversion limit. The removed handler treated that session ID as unversioned. With the same local SQLite fixture, the overview, users, and sessions views returned 200 on the base commit and 503 on this branch. Restore the fallback so the dashboard can still read the remaining data. Session version parser
  • [P2] Filter trace detail without retaining unrelated spans. _trace_spans() builds a list for the entire scan before get_trace() filters it to one trace. Fetching one trace from a local fixture with 10,000 spans increased peak Python allocations from 16.6 MiB to 28.5 MiB. Yield spans as they are parsed so the detail view retains only matching spans. Trace detail query

Ruff, mypy, and 619 focused tests passed. The full coverage run had the same Mini App server failures on both commits because the local environment denied loopback socket binding.

- Treat oversized session version suffixes as unversioned again
- Stream trace spans so trace detail keeps only matching spans
- Cover the oversized version suffix in the dashboard tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@QueryPlanner
QueryPlanner merged commit 245ddc4 into main Nov 29, 2026
3 checks passed
@QueryPlanner
QueryPlanner deleted the claude/codebase-cleanup-refactor-d6de22 branch November 29, 2026 15:37
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