Skip to content

chore: delete dead and unimportable code, and test that every module imports - #4360

Merged
kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:claude/delete-dead-code
Sep 26, 2026
Merged

kovtcharov-amd merged 1 commit into
amd:mainfrom
kovtcharov:claude/delete-dead-code

Conversation

@kovtcharov

Copy link
Copy Markdown
Contributor

About 6,700 lines of code had no caller. One file couldn't even be imported, yet CLAUDE.md still listed it as "Shell integration". The dead code kept stale behaviour looking alive, like rag/demo.py printing gaia rag commands that don't exist, and it cost reviewers time. This PR deletes six of the items from #4243. It also adds a test that imports every module under src/gaia, so an unimportable file now fails CI instead of lingering. The test fails on current main: it flags shell/prompt.py and the three uncollected mic scripts.

Left for a maintainer decision:

docs/plans/cpp-framework-parity.md still calls the C++ plan resolver dead code to resolve. I left it alone because #3812 deletes that file.

🔍 Technical details
  • Deleted: src/gaia/shell/, rag/demo.py, rag/app.py + rag_main export, audio/tests/*.py, eval/longthread_quality.py + its test and fixture, hub/agents/email/node/, Agent::resolvePlanParameters (+ decl, + now-unused <regex> include).
  • Two rag_app tests in test_rag_index_status.py went with rag/app.py. The chat/talk/file-monitor index-status tests stay.
  • thread_fold keeps its own coverage in hub/agents/email/python/tests/test_thread_fold*.py.
  • The import test's allowlist is keyed on the missing package (mcp, reportlab), not the module. An allowlisted module still fails if it breaks another way, and a second test checks each allowlisted package is an optional extra in setup.py, not a base dependency. Loose .py files outside a package are loaded by path, so broken relative imports fail too.
  • A CI-equivalent venv (.[api] + the unit job's test deps) flags only mcp and reportlab today, and the sweep takes ~7 s cold. No module does an unguarded platform-only import at top level, so the Windows smoke lane should match. That lane is not verified locally.
  • No open PR modifies a deleted file. fix(rag): keep the RAG cache in ~/.gaia/cache/rag and clear only its files #4260 edits the chat agent's app.py, not src/gaia/rag/app.py.

Test plan

  • pytest tests/unit/test_import_all_modules.py: fails on origin/main (shell/prompt.py + 3 mic scripts). It also fails with prompt_toolkit installed (broken relative import) and with an __init__.py added (gaia.shell.commands missing). Passes on this branch in both the full dev venv and a .[api]-only venv.
  • pytest tests/unit/test_rag_index_status.py tests/unit/test_packaging.py tests/unit/test_model_comparison.py tests/unit/email tests/unit/rag tests/test_rag.py: 296 passed, 9 skipped
  • pytest tests/unit (.[api] venv): 14422 passed. The 23 failures (test_cli_smoke, test_uninstall_command, test_lemonade_asr) also fail on origin/main in the same env.
  • C++: cmake -S cpp -G Ninja && cmake --build builds clean, and tests_mock passes 1002/1002
  • black, isort, pylint (CI flags) on the changed Python files
  • Windows and macOS unit smoke lanes pass (CI)

Part of #4243

…imports

Six pieces of code had no caller, and one could not even be imported, yet
CLAUDE.md still advertised it as "Shell integration". About 6,700 lines go:

- src/gaia/shell/prompt.py: imports modules that never existed, no
  __init__.py, and prompt_toolkit is not a dependency.
- src/gaia/rag/demo.py and rag/app.py (plus the unused rag_main export):
  they printed and implemented `gaia rag` commands that no CLI entry wires up.
- src/gaia/audio/tests/: manual mic scripts that pytest never collects; the
  audio README now points at the whisper_asr.py streaming check instead.
- src/gaia/eval/longthread_quality.py with its test and 220 KB fixture: only
  its own test used it; thread_fold keeps its dedicated email-agent tests.
- hub/agents/email/node/: an orphaned SDK copy pinned to schema 2.2 against
  the live 2.14.
- Agent::resolvePlanParameters in the C++ core: private and never called.

tests/unit/test_import_all_modules.py imports every module under src/gaia in
a child interpreter. A module may fail only because an optional extra
(allowlisted by package name) is missing, so an unimportable file like
shell/prompt.py fails CI instead of lingering.

Part of amd#4243
@github-actions github-actions Bot added devops DevOps/infrastructure changes rag RAG system changes audio Audio (ASR/TTS) changes eval Evaluation framework changes tests Test changes performance Performance-critical changes cpp labels Sep 25, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Approve with suggestions

This deletes ~6,700 lines that nothing called and adds a test that imports every module under src/gaia, so an unimportable file fails CI instead of sitting there looking alive. I traced each deleted surface and found no remaining caller, no packaging entry, and no published consumer — the removals are safe, and the new guard is a genuinely good addition.

Nothing blocking. Four small things worth a look: the import sweep also reaches into the OEM staging folder where integrators are told to drop their own agent, so a downstream fork's code gets executed by GAIA's unit test; the setup.py allowlist check matches the extras group name rather than the requirement itself, making it weaker than its error message claims; the sweep's fixed timeout leaves thin headroom on the macOS/Windows lanes you haven't verified (they're non-blocking, so this is a heads-up, not a gate); and two skill docs still advertise the long-thread ground-truth fixture this PR removes.

Real-world evidence

N/A — no evidence bundle was produced for this run, and the diff changes no runnable surface: it deletes uncalled code, removes one unreferenced export, and adds a unit test. My verdict rests on static verification, which for a deletion PR is the relevant check. What I confirmed myself: no reference anywhere to rag_main, gaia.rag.app, gaia.rag.demo, gaia.shell, longthread_quality, the audio test scripts, or the deleted Node package; the removed npm package name is not published on the registry; gaia.shell was never in setup.py's package list, so it never shipped; the C++ symbol has no remaining references and its include is genuinely unused; and the README's corrected whisper_asr.py invocation matches that file's actual arguments. I could not execute the new sweep here (the runner has no GAIA dependencies installed), so its runtime behaviour rests on your test plan.

🔍 Technical details

🟢 Minor

1. Import sweep reaches the OEM agent staging directory (tests/unit/test_import_all_modules.py:45)

src/gaia/apps/webui/build/bundled-agents/example-agent/agent.py is the only loose (non-package) file in the tree, and it is loaded and executed by path. That directory is documented as the drop-in point where an integrator replaces the example with their own agent.py (see its README.md and the custom-installer playbook), so a downstream fork ends up executing third-party agent code inside GAIA's unit test — and failing it if that agent needs a dependency they didn't install. It's also build staging, not part of the gaia package.

skip = {"node_modules", "__pycache__", "build", "dist"}

2. test_allowlisted_imports_are_optional_extras matches the extras key, not the requirement (tests/unit/test_import_all_modules.py:122)

For mcp the regex matches "mcp": [ (the extras group name, setup.py:227), not "mcp>=2.0.0,<3.0" (setup.py:231). Deleting the actual requirement would leave the test green while its message says the dist "is not declared in any setup.py extra". Excluding a " followed by : fixes it without touching the base-dependency half:

        requirement = re.compile(rf'"{re.escape(dist)}(?=[<>=!~;\[ ]|"\s*[,\]])', re.I)

Checked against the current setup.py: it drops the "mcp": [ group-key match, still matches "mcp>=2.0.0,<3.0" and all three reportlab declarations, and the install_requires half of the test is unaffected.

3. Sweep timeout headroom on the unverified lanes (tests/unit/test_import_all_modules.py:90)

The macOS and Windows smoke jobs run pytest tests/unit/ -x --timeout=60, so a cold runner has roughly 10 s of slack over the 50 s subprocess timeout before the sweep truncates the whole lane at this test. Both jobs are continue-on-error: true, so this can't block a merge — but it's the one test-plan item you left unchecked, so worth watching on the first CI run. Related: a subprocess.TimeoutExpired propagates raw rather than through the friendly import sweep crashed assert, which makes the failure harder to read when it does happen.

4. Two skill docs still list the deleted longthread_ fixture

.claude/skills/adding-eval-scorecard/SKILL.md:71 and .claude/skills/porting-agent-to-hub/SKILL.md:100 both enumerate longthread_ as one of the per-task email ground truths in tests/fixtures/email/. This PR deletes longthread_ground_truth.json, so an agent following either skill will look for a file that no longer exists. CLAUDE.md's "a functional change must update EVERY doc that describes it" applies. Dropping the name from both lists is enough:

— ground truth is **task-specific** (`action_items_`, `briefing_`, `drafting_`,
`followups_`), and the CLI's `--ground-truth` default points at a

Notes, not findings

  • rag_main was a public export. Removing it from gaia.rag.__all__ is technically an SDK surface removal, but it pointed at the entry point of a gaia rag CLI that does not exist (no such subparser in cli.py) and it appears in no doc. Not worth a deprecation cycle; a changelog line would be generous.
  • The long-thread corpus deletion checks out. longthread_quality.py shipped with no live-runner hook and no gate manifest, pending the consolidated eval pass in plan(email): Milestone 40 (v0.22.0) closeout — what's left to ship #1319 — and both plan(email): Milestone 40 (v0.22.0) closeout — what's left to ship #1319 and feat(email): long-thread handling via iterative summarization to fit the context budget #1889 are now closed, so the wiring is never coming. The fold behaviour itself keeps direct coverage in test_thread_fold.py (latest message verbatim, overflow prevented, deterministic input-dependent fake), so no unique behavioural coverage is lost — only the three hand-authored adversarial cases, which remain in git history.
  • @amd-gaia/node-agent-email was never published (registry returns 404), and nothing in the tree references it, so deleting it strands no consumer. The shipping package is the separately-named @amd-gaia/agent-email.

Strengths

  • The sweep's design choices are the non-obvious right ones and the docstring explains each: a child interpreter so module-level side effects never touch the pytest process, GAIA_HOME/GAIA_DAEMON_HOME redirected at a tmpdir (both are real env vars the code honours), BaseException so a module calling sys.exit() is caught rather than silently ending the run, and loose files loaded by path so broken relative imports surface instead of hiding.
  • Keying the allowlist on the missing package rather than the module means an allowlisted module still fails for any other reason — and pairing it with a second test that the allowlisted dist is an optional extra and not a base dependency closes the loop that would otherwise let a broken base install get waved through.
  • The deletions are genuinely scope-clean: each one carries its dependents with it (rag/app.py with its two tests and the rag_main export, longthread_quality.py with its test and fixture, the C++ method with its declaration and its now-unused <regex> include), and CLAUDE.md's tree listing was updated in the same commit rather than left to drift.
  • The PR description does the reviewer's work for them: it states what was deliberately not deleted and why, names the one stale doc reference it is knowingly leaving to another PR, and confirms no open PR touches a deleted file.

@kovtcharov-amd

Copy link
Copy Markdown
Collaborator

Verified and merging. I re-ran the deletion safety check independently rather than taking the description on trust: merged current main into the branch locally (clean, no conflicts) and searched the merged tree for every deleted surface — rag_main, gaia.rag.app, gaia.rag.demo, gaia.shell, longthread, resolvePlanParameters, the Node email package. The only surviving mentions are two stale plan docs that #3812 removes, exactly as you said. setup.py never listed the deleted packages and no console script points at them, so nothing shipped breaks.

Both red checks are stale-base artifacts, not regressions. Test Eval Tool (Windows) failed because the branch predates main's _MAX_HISTORY_PAIRS → _MAX_PAIRS move; on the merged tree tests/test_eval.py is 153/153. Unit Tests (Windows smoke) is the toctou symlink test, which continue-on-error: true makes non-blocking and which main has since fixed.

Two of the earlier review's minor points are still open — worth a follow-up, not a reason to hold this:

🔍 Technical details
  • Merged onto ce0e97f1a. Clean. tests/unit/test_rag_index_status.py tests/unit/test_packaging.py tests/unit/test_model_comparison.py tests/unit/rag tests/test_rag.py: 190 passed. tests/test_eval.py: 153 passed. black/isort clean on the changed Python files.
  • std::regex has no other use in cpp/src/agent.cpp, so dropping the include is safe.
  • Still open (finding 1): skip = {"node_modules", "__pycache__"} at tests/unit/test_import_all_modules.py:45 does not exclude build, and src/gaia/apps/webui/build/bundled-agents/example-agent/agent.py is tracked in git (.gitignore:147-149 un-ignores it deliberately). So the sweep does load the OEM drop-in file by path, and a downstream integrator who replaces it with their own agent has that agent executed by GAIA's unit test.
  • Still open (finding 2): requirement = re.compile(rf'"{re.escape(dist)}(?=[<>=!~;\[ "])') at :122 includes " in the lookahead class, so "mcp": [ — the extras group key at setup.py:227 — still satisfies it. The test passes without the actual "mcp>=2.0.0,<3.0" requirement being present, which is weaker than its failure message claims.
  • One environment note for contributors: the sweep reports gaia/mcp/agent_mcp_server.py as broken on a machine with mcp 1.x installed, because MCPServer is a 2.x API and the allowlist keys on mcp being absent, not stale. setup.py pins mcp>=2.0.0,<3.0, so this is a local-env skew rather than a code fault — but the assertion text ("Fix the import, or delete the module") points the reader the wrong way.

@kovtcharov-amd
kovtcharov-amd added this pull request to the merge queue Sep 26, 2026
Merged via the queue into amd:main with commit 8e012ed Sep 26, 2026
51 of 53 checks passed
@kovtcharov-amd
kovtcharov-amd deleted the claude/delete-dead-code branch September 26, 2026 05:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

audio Audio (ASR/TTS) changes cpp devops DevOps/infrastructure changes eval Evaluation framework changes performance Performance-critical changes rag RAG system changes tests Test changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants