Unreferenced legacy shims in wrapper: route_to_legacy() and register_legacy_reply() (with stale docstring)
Summary
Two small legacy helper functions in the wrapper have zero references anywhere (CLI dispatch, tests, public __all__, or external entry points). Both have been superseded by canonical paths that are actually wired in. One carries a stale docstring that actively misdescribes current behaviour. This is dead-code / legacy-drift cleanup — no user-facing capability is affected.
Current behaviour
1. cli/legacy.py::route_to_legacy() — unreferenced; docstring is stale.
# src/praisonai/praisonai/cli/legacy.py:1-39
"""
Legacy compatibility shim for PraisonAI CLI.
Provides route_to_legacy() for dispatching to the original argparse-based
PraisonAI class. Used by __main__.py as a fallback for direct prompts, ...
"""
def route_to_legacy(argv):
from praisonai.cli.main import PraisonAI
original_argv = sys.argv
sys.argv = ["praisonai"] + list(argv)
try:
praison = PraisonAI()
result = praison.main()
return 0 if result is None else (1 if result is False else 0)
except SystemExit as e:
return e.code if isinstance(e.code, int) else 0
finally:
sys.argv = original_argv
The docstring claims __main__.py uses this as its fallback, but __main__.py has its own canonical implementation and never calls route_to_legacy:
# src/praisonai/praisonai/__main__.py:124-138 (the real, wired-in path)
def _run_legacy(argv):
from praisonai.cli.main import PraisonAI
...
praison = PraisonAI()
result = praison.main()
...
Reference check (whole wrapper) returns only the definition + docstring mentions:
$ grep -rn "route_to_legacy" src/praisonai/praisonai --include=*.py
cli/legacy.py:4: ...docstring...
cli/legacy.py:15: def route_to_legacy(argv):
2. integration/_legacy_handlers.py::register_legacy_reply() — unreferenced.
# src/praisonai/praisonai/integration/_legacy_handlers.py
def register_legacy_reply(aiui, *, agent_name: str = "PraisonAI"):
"""Register callback-only reply handler when ``PRAISONAI_HOST_LEGACY=1``."""
@aiui.reply
async def legacy_reply(message: str, session_id: str = "default"):
from praisonaiagents import Agent
agent = Agent(name=agent_name, instructions="You are a helpful assistant.", llm="gpt-4o-mini")
return agent.run(message)
The bundled UI apps implement their own inline @aiui.reply handler gated on is_legacy_host() and never import this helper:
# src/praisonai/praisonai/ui_chat/default_app.py:16,53 (and ui_bot/default_app.py:12,49)
from praisonai.integration.host_app import configure_host, create_host_app, is_legacy_host
...
if is_legacy_host():
@aiui.reply
async def ... # inline, does not call register_legacy_reply
Reference check returns only the definition:
$ grep -rn "register_legacy_reply\|_legacy_handlers" src/praisonai/praisonai --include=*.py
integration/_legacy_handlers.py:6: def register_legacy_reply(...)
Why it matters
- Maintenance / user confusion:
route_to_legacy's docstring asserts it is the dispatch fallback used by__main__.py, which is false — a reader tracing CLI routing is sent to dead code. - Duplication / drift: both functions duplicate behaviour that the canonical wired-in paths (
__main__._run_legacy, the inlineis_legacy_host()reply handlers) already provide.
Category
Dead code / Legacy drift
Capability preserved
- CLI dispatch for prompts, YAML files, and deprecated flags is unchanged (handled by
__main__._run_legacy). PRAISONAI_HOST_LEGACYcallback-only host mode is unchanged (handled by the inlineis_legacy_host()handlers in the UI apps).- The backward-compatible entry point
cli/legacy.py::main_with_legacy_support()and theis_legacy_host()feature flag are kept.
Proposed approach
Remove dead code only:
- Delete
route_to_legacy()fromcli/legacy.pyand correct the module docstring to describe its actual remaining role (themain_with_legacy_support()entry point delegating to__main__.main). - Delete the unreferenced
integration/_legacy_handlers.py(or justregister_legacy_reply()if the module is retained).
If preferred, defer with a one-cycle deprecation shim instead of immediate deletion, since these are importable module-level symbols.
Resolution sketch
# cli/legacy.py — After
"""Backward-compatible entry point for PraisonAI CLI.
All command dispatch lives in __main__.py (Typer auto-discovery + legacy fallback).
This module is retained only for the main_with_legacy_support() console entry point.
"""
def main_with_legacy_support():
from praisonai.__main__ import main
main()
# route_to_legacy() removed — superseded by __main__._run_legacy()
Layer placement
- Primary layer: wrapper (
cli/legacy.py,integration/_legacy_handlers.py) - Touches core/tools/plugins: none
- 3-way surface (CLI + YAML + Python): preserved
Severity
Low — small dead-code/clarity cleanup; no runtime or capability impact.
Validation
- Whole-wrapper grep confirms zero references to
route_to_legacy,register_legacy_reply, and_legacy_handlersbeyond their own definitions. - Canonical replacements confirmed wired in:
__main__._run_legacy(CLI fallback) and the inlineis_legacy_host()reply handlers inui_chat/ui_botdefault apps. - Not in any public
__all__; not referenced in tests.
Keep unchanged
cli/legacy.py::main_with_legacy_support()(backward-compatible entry point).integration/host_app.py::is_legacy_host()and thePRAISONAI_HOST_LEGACYcallback-only host mode.__main__._run_legacyand the entire legacy argparse path incli/main.py.
Claude finished @MervinPraison's task —— View job • claude/issue-1951-20260613-1155 • Create PR ➔
Dead code removal completed ✅
Successfully removed unreferenced legacy shims as requested in the issue.
Todo List:
- [x] Read AGENTS.md for architecture guidelines
- [x] Verify current state of mentioned files
- [x] Confirm functions are unreferenced via grep search
- [x] Remove
route_to_legacy()from cli/legacy.py - [x] Update cli/legacy.py module docstring
- [x] Remove unreferenced code from integration/_legacy_handlers.py
- [x] Run tests to ensure no regressions
- [x] Commit and push changes
- [x] Create pull request
Changes Made:
-
Removed
route_to_legacy()function fromsrc/praisonai/praisonai/cli/legacy.py- Function was unreferenced and duplicated functionality in
__main__._run_legacy() - The stale docstring claiming
__main__.pyused this function was misleading
- Function was unreferenced and duplicated functionality in
-
Updated
cli/legacy.pymodule docstring to accurately reflect its current purpose:- Now describes that all command dispatch is in
__main__.py - Makes clear this module only provides the
main_with_legacy_support()entry point
- Now describes that all command dispatch is in
-
Removed entire
integration/_legacy_handlers.pyfile containing:register_legacy_reply()function that was never imported or used- UI apps implement their own inline
@aiui.replyhandlers instead
Verification:
- ✅ Grep confirmed no references to these functions beyond their definitions
- ✅ Backward-compatible entry point
main_with_legacy_support()preserved - ✅ All actual legacy functionality (CLI dispatch, UI legacy mode) remains intact
- ✅ No user-facing capabilities affected
Hi maintainers 👋
I was looking at this issue as a potential first contribution, and I verified the current main branch: neither route_to_legacy() nor register_legacy_reply() exist in the codebase anymore.
A whole-repo grep for both function names returns zero matches. It looks like these legacy shims were removed during earlier dead-code cleanup (likely the orphaned-module removals in #1994 / #2053), so the issue is effectively resolved — just never closed.
PR #2067 was opened against this issue but was closed without merging; the removal appears to have landed through other cleanup PRs instead.
Suggesting this issue can be closed as resolved. Happy to help verify if there's anything I missed!